Input |
Action |
CTRL+U |
Page up 1/2 |
CTRL+D |
Page dw 1/2 |
<< |
Unindent (normal mode) |
>> |
Indent (normal mode) |
. |
Repeat last |
2dw |
Delete 2 words |
dd |
Delete line |
yy |
Copy line |
p |
Paste |
* |
Jump to next occurrence of word under cursor |
# |
Jump to previous occurrence of word under cursor |
How to search around in normal mode?
Input |
Action |
/<word> |
Search for a word in normal mode |
/\<word>\> |
Search for a word with whitespace around it (otherwise substring search) |
n |
Jump to next occurrence of it |
p |
Jump to previous occurrence of it |
- To search backwards, use
?
instead of /
.
- To search case-insensitive, use
/\c
with escaped c
- To search case-sensitive, use
/\C
with escaped C
- Use arrow keys after
/
or ?
to navigate search history
How to both search and replace in normal mode?
Input |
Action |
:100,200s/a/b |
Replace a with b between lines 100 and 200 |
:%/a/b |
Replace a with b across all lines |
:%/a/b/g |
Same, but applies globally (not just first occurrence) |
100,200/\<a>/b/gic |
Word + Case-insensitive + Commit + Global |
- Use
g
at the end to search globally
- Use
gi
to apply with case insensitivity
- Use
gI
to apply with case sensitivity
- Use
gic
to apply globally and commit it
Input |
Action |
:set nu |
Enable line numbers |
:set ai |
Enable auto-indent (using previous line indentation) |
:set si |
Enable smart indent (using syntax) |
:colorscheme |
Change colorscheme. Get options with CTRL+D |
:set shiftwidth=N |
Set indent size to N spaces |
:set list |
Show whitespace |
:set expandtab |
Use spaces instead of tabs |
:set hlsearch |
Enable search result highlighting |
:set incsearch |
Enable incremental highlighting |
:set scrollbind |
Enable parallel scrolling (auto) |
My personal ~/.vimrc
file at this moment
syntax on
filetype indent on
"Personal run-command file
:set nu
:set ai
:set shiftwidth=2
:set hlsearch
:set incsearch
:colorscheme wildcharm
:set background=light
:set splitright
:set complete+=kspell
:set completeopt=menuone,longest
:set shortmess+=c
:set encoding=utf-8
:set colorcolumn=80
:set backspace=indent,eol,start
"Adjust scrolling behaviour
map <C-U> 6<C-Y>
map <C-D> 6<C-E>
"Re-assign arrow keys to NOP (also in insert)
nnoremap <Up> <Nop>
nnoremap <Down> <Nop>
nnoremap <Left> <Nop>
nnoremap <Right> <Nop>
"Re-assign enter key when autocomplete menu shown
inoremap <expr> <CR> pumvisible() ? '<C-p><C-y>' : '<CR>'
"Filetype sensitive tab directives
autocmd Filetype python setlocal expandtab tabstop=4 sw=4 sts=4
autocmd Filetype c setlocal expandtab tabstop=2 sw=2 sts=2
"Autocorrection directives
abbr ture true
abbr flase false
"Tabbing keybind
nnoremap <C-n> :tabnext<CR>
"Lookup rebind for ctags
nnoremap @ g]
"Custom Zoom-in/Zoom-out toggle function
nnoremap <nowait><expr><silent> <Space><Space>
\ <SID>toggleZoom() ? "200\<C-W>>200\<C-W>+" : "\<C-W>="
let s:_toggle_zoom=0
function! s:toggleZoom() abort
let s:_toggle_zoom = s:_toggle_zoom ? 0 : 1
return s:_toggle_zoom
endfunction
"Language support
let g:lsc_auto_map = v:true
let g:lsc_server_commands = {
\ 'c': 'clangd',
\ 'go': {
\ "command": "gopls serve",
\ "log_level": -1,
\ "suppress_stderr": v:true,
\ },
\ 'typescript': 'typescript-language-server --stdio'
\}
"Calendar support
let g:calendar_weeknm = 1
let g:calendar_number_of_months = 3
"Plugin manager (vim-plug): Check status with :PlugStatus
call plug#begin('~/.vim/plugged')
Plug 'https://github.com/vim-scripts/AutoComplPop', { 'tag': '2.14.1' }
Plug 'https://github.com/natebosch/vim-lsc.git', { 'tag': 'v0.3.1' }
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'jceb/vim-orgmode'
Plug 'tpope/vim-speeddating'
call plug#end()
"Check whether any plugins are missing
function! WarnInvalidPlugs()
if plug#n_valid_plugs()
let s:msg="Not all Plugs functional! Check: PlugStatus"
let s:size=len(s:msg) + 4
call popup_notification(s:msg, #{line: 2, col: (&columns - s:size)/2})
endif
endfunction
autocmd VimEnter * :call WarnInvalidPlugs()
"Fzf Settings
let g:fzf_vim = {}
let g:fzf_vim.preview_window_options = ['--style', 'minimal']
"Binding to open Fzf files
noremap <C-F> :Files<CR>
Input |
Action |
CTRL+V |
Enter visual block mode |
SHIFT+I |
Insert to the left of the selection. ESC to apply |
c |
Change selection |
d |
Delete selection |
r |
Replace entire selection with next typed character |
$ |
Select until EOL |
A |
Append text to selection |
SHIFT+R |
Replace-mode so changes in place |
Input |
Action |
:buffers |
See current buffered content |
:ls |
List all buffers (current marked with %a ) |
:bp |
Go to previous buffer |
:bn |
Go to next buffer |
:b<N> |
Go to buffer at index N |
:bd |
Delete current buffer |
:e! |
Restore current file to last saved |
CTRL+o |
Jump to previous buffer |
Ctrl+i |
Jump to next buffer |
Input |
Action |
:sp |
Split current window (top/bottom) |
:vsp |
Split current window (left/right) |
CTRL+W S |
Split current window horizontally |
CTRL+W V |
Split current window vertically |
CTRL+Q |
Close window |
:vsp <filename> |
Open filename in new window |
CTRL+W X |
Swap windows |
:set splitright |
Always open new window on right side |
CTRL+W R |
Rotate current windows |
CTRL+W T/B |
Go to Top or Bottom window |
CTRL+W H/J/K/L |
Navigate windows |
:resize <N> |
Adjust length by N |
:vertical resize <N> |
Adjust width by N |
CTRL+W = |
Make windows equal size |
CTRL+W _ |
Expand to max height |
`CTRL+W |
` |
CTRL+W o |
Fullscreen current window |
:ba |
Show all buffers |
Input |
Action |
:tabe <filename> |
Edit filename in new tab |
:tabn |
Go to tab on the right |
:tabp |
Go to previous tab |
:tabnew |
Open new empty tab |
:tabm <0> |
Move tab to far left |
:tab ball |
Open all buffers in tabs |
Input |
Action |
vim <directory> |
Open VIM manager |
/<pattern>/ |
Auto-highlight directory entry matching pattern. Hit ENTER to goto |
s |
Change sort mode |
d |
Delete file selected |
o |
Open file selected |
v |
Open selected file in vertical split window |
:let g:netrw altv=1 |
Open split to the right always |
:Vex |
Show the vertical explorer window |
I |
Toggle the banner |
i |
Show file information |
Input |
Action |
vimdiff <a> <b> |
Open VIM diff tool with horizontal stacking |
vimdiff -o <a> <b> |
Open VIM diff tool with vertical stacking |
vim -d <a> <b> |
Alternative way to open with horizontal stacking |
]c |
Go to next difference |
[c |
Go to previous difference |
:diffget |
For the present seelcted file and change, grab the opposing change |
:diffupdate |
Rescan a file after a change (to undo the change basically if you didn't write) |
:diffput |
Put the change on the left file to the right file for the given change |
CTRL+WW |
Switch the files being compared Left <-> Right |
:zo |
Unfold collapsed text under the cursor |
:zc |
Fold the text under the cursor |
:zr |
Unfold everything |
:zm |
Fold everything |
-
Indent the whole file (using autoindent):
a. gg
: Goto top of file
b. v
: Goto visual mode
c. G
: Select until end of file
d. =
: Apply auto indentation
-
Indent function (in visual mode):
a. Navigate to just after the opening brace {
b. v
: Enter visual mode
c. Type }
To select up-to the closing brace
d. Type =
to apply the formatting within the block
-
Lookup (normal mode): Assumes you have Exuberant ctags installed
a. Jump to definition under cursor: @
b. Preview: :pts
, jump next :tn
, jump last :tp
Here are a few handy things I'd like to know how to do still:
- Auto-align a bunch of text together (starting from next word)
- Auto-format a markdown table if selected (probably pipe to another program to format)