Up / Down / Left / Right
h - move left (←) (not high!)
l - move right (→) (not low!)
j - move up (↑)
k - move down (↓)
H - move to the top of the screen (High)
L - move to the end of the screen (Low)
Move between windows
Ctrl+W then ↑ or ↓ or ← or → - move cursor to next window
Ctrl+W then H or L - move vertical left right
Ctrl+W then J or K - move horizontally up down
Move to last line / first line
:$ - move to last line
:0 - move to the first line
:<num> - move to <number> line
Move in the line
HOME or 0 - move to the beginning of the line
$ or END - move to the end of the line
Switch between tabs
gt - go to next tab
gT - go to previous tab
Ctrl+PgUp - go to previous tab (will conflict with GUI)
Ctrl+PgDown - go to next tab (will conflict with GUI)
Search ignore case
Search with case
Search Next
Search Previous
Search keyword under cursor and Jump
Jump to variable declaration (a.k.a. go declaration)
Jump back to previous cursor
Undo / Redo
Insert new line
Replace
Reload without saving
Forgot to sudo - gain sudo vim access when you are readonly
To delete all lines matching a certain regular expression pattern, use
To do the opposite, i.e. only keep those lines matching the pattern, use
And to only temporarily print matching lines, use
Set mouse enable in .vimrc
set mouse=a #enable
set mouse=c #disable
Set display line number
Get current file path
:echo @%
:echo expand('%:p')
Set Syntax Highlights on bash scripts without shebang
During typing, you want autocomplete
Copy even if you're using set mouse=a
This is actually simple: by accessing register "+" or "*" in Linux
select text using any mode
yank the text to register +
Paste even if you're using set mouse=a
This is actually simple: by accessing register "+" or "*" in Linux
go to insert mode
paste the text from register + (during insert mode)
or you can do this (during command mode)
Find and Replace (Substitute)
Full command
:substitute
Find all occurrence of 'foo' and replace it with 'bar'.
:%s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
:s/foo/bar/g