>

Move in line

Keys Function
0/HOME/| jump to the beginning of line
^/== jump to the first non-blank character of line
_ jump to the first non-blank character of current line
g_ jump to the last non-blank character of current line
$/END jump to the end of line
- jump to the first non-blank character of previous line
+/ move to first non-blank character of next line
* search forward for the word
# search backward for the current word
w move to the beging of the next word
W move to the next space-separated word
b move to the begin of the current word. (B for space separated only)
e move to the end of the current word. (E for space separated only)
ge move the the end of previous word (not supported in Vintage mode of Sublime Text)
gE move the the end of previous space separated word (not supported in Vintage mode of Sublime Text)
number + | move to the nth character of current line
f jump to the next occurring char of the current line, use ; and , to repeat forward/backward
F jump to the previous occurring char of the current line, use ; and , to repeat forward/backward
t jump to one position before the next occurring char of the current line, use ; and , to repeat forward/backward
T jump to one position before the previous occurring char of the current line, and ; and , to repeat forward/backward
Ctrl-g print where I am in the file

Move vertically

Keys Function
gg, G move to the begin/end of the file
H move to the top of file
M move to the middle file
L move to the end file
[[ jump to the beging of the current file
]] jump to the end of the current file
{ jump to the previous blank line
} jump to the next blank line

Move in block

Keys Function
[{ jump to the previous {
[} jump to the next }
[( jump to the previous (
[) jump to the next )
[/ jump to the begining of comment block
]/ jump to the end of comment block
gd jump to the declaration of local variable
gD jump to the declaration of global variable (search from the begining of the file)

Move in page

Keys Function
/ down/up half page
/ forward/backward full page

Move in matching braces

Keys Function
% hop between the matching {}, () or [] of the line, or between C-style comment: /* */, or matching #if, #ifdef, #else, #elif, #endif.

Note:
If showmatch option is enabled, the cursor will briefly jump to the matching brace when you insert one.

1
2
:set showmatch
:set matchtime=3

Move in Marks

Keys Function
m {a-z} Marks current position as {a-z}
‘ {a-z} Move to position {a-z}
‘’ Move to previous position

Move to old positions

Keys Description
Ctrl + o jump back to the previous (older) position
Ctrl + i jump back to the next (newer) position
g; jump to previous edited position.
gi jump to previous edited position and enter into Insert Mode.
`. jump to the last edited cursor position
`` jump to the previous cursor position
‘. jump to the last edited line begining
‘’ jump to the previous line begining

Move in selections

Keys Description
o when we use v to select a block, we can use o to o to hop between the begin and end of the selection

Move in Insert Mode

Keys Function key mapping
Alt + ; move to the line end inoremap ; A
Alt + , move to the line begin inoremap , I
Ctrl + / comment current line inoremap I//

explanations
For some reason, vim registers as (you can see it in insert mode using ). It can be the terminal or a historical design thing that terminal apps have to suffer.

And Gvim doesn’t even try to recognize . Sees it as single /.

Screen movement

Keys Function
zz, z- center the screen on the cursor
zt, z-Enter top the screen on the cursor (the line will at the top of the screen)
zb bottom the screen on the cursor (the line will at the bottom of the screen)
Ctrl-y Moves screen up one line
Ctrl-e Moves screen down one line
Ctrl-u Moves screen up ½ page
Ctrl-d Moves screen down ½ page
Ctrl-b Moves screen up one page
Ctrl-f Moves screen down one page

Leave some lines above the top or below the bottom.

:set scroll=10
:set scrolljump=5
:set scrolloff=3

Movement in Visual Mode

o/O Hop between begin and end of the selection.

Selection in Visual Mode

  • v select any range
  • V select entire line
  • Ctrl-v select columns
  • gv select previous selected block

Operations on selected text Visual Mode

After selecting the text, try d to delete, or y to copy, or :s/match/replace/, or :center, or !sort, or…

  • Select all text in (), {}, [], <>, ‘’, “”, etc. block, vi<(>, ( could be any of those characters.
  • Especially, for () and {}, we can use vib and viB to select text in these blocks if our cursor is in the block.
  • If cursor is just on ( or ), v% will select text between and also ( and )
  • vap selects the entire paragraph
  • ggVG selects the entire file
  • v {select} x/d delete selected text
  • v {select} X/D delete selected lines
  • Delete Selected Block: v d.
  • Delete Selected Block and then Insert from here: v di. A much quicker way of doing this is vc

Especially, if you are going to change the text between (), {}, [] <>, ‘’, “”, it is more straightforward to just do ci<(> , here ( can be any of the above characters. No need to select first if you are going to replace it.

Summary of Visual Mode Selection:

vi(, vi[, vi{, vi”, vi’, viw: all these will not include
va(, va[, va{, va”, va’, vaw: all these will include

What is meta key?
The Meta key is a modifier key on certain keyboards where it is labeled “META”, On keyboards that lack a physical Meta key (or keys), its functionality may be invokable by other keys such as the Alt key, the Windows key, etc.

If no Meta key function is available, some software will accept alternate keybindings using, for example, the Esc key as a prefix key (as, for example, inEmacs).

How to type a meta key?
Start by viewing the key code your terminal is sending to vim:

$ sed -n l
^[[1;9D

In the above example, i ran the sed command and pressed Alt + Left.
The ^[[1;9D is the escaped sequence being sent to vim, so we can user that for our mapping.

e.g. Add this to .vimrc map <Esc>[1;9D :tabn<CR>

Now we can cycle through vim tabs by using Alt + Left. BTW, in cygwin ALT+Left output is \033[1;3D$, here \033 is , and we need to remove the ‘$’