Random vim notes
This is just a dump of vim tricks that I have found useful. They are taken from multiple sources.
- Move the screen
Ctrl
+e
- Move the screen up. Cursor doesn’t moveCtrl
+y
- Move the screen down. Cursor doesn’t moveCtrl
+u
- Move cursor and screen up 1/2 pageCtrl
+d
- Move cursor and screen down 1/2 pagezt
- Move the current line to the top of the screenzb
- Move the current line to the bottom of the screen
- Open recent files
- Hit
Ctrl-o-o
. Keep hitting it until you get the file you want :browse oldfiles
Esc
File number
Enter
:browse oldfiles
gives a list of last 100 files you have opened in vim
- Hit
- Code Indentation
V}>
-V}
selects a block (paragraph) and>
applies indentation
- Reformat text
- Select the text
- Press
gq
- Disable search highlighting temporarily
:nohlsearch
or simply:noh
- Press
n
/N
to continue previous search
- Comment out multiple lines
- For entire file:
:%s/^/#/g
- For a particular range, say from line 10 to 20:
:10,20s/^/#
- To uncomment:
:%s/^#//g
- For entire file:
- Deleting lines
S
- Delete the entire line and switch to insert modeC
- Delete the rest of the line and switch to insert modedd
- Delete the entire line, and stay in normal mode
- Deleting words
dw
- Delete rest of the word including the space after that. Stay in normal mode after the operationcw
- Delete rest of the word excluding the space after that. Switch to normal mode after the operation
- Switch case
~
- Change the case of current charactergUw
- Change the rest of the word to uppercaseguw
- Change the rest of the word to lowercasegUU
- Change the current line to uppercaseguu
- Change the current line to lowercase
- Redo
Ctrl
R
to redo the last action4
Ctrl
R
to redo the last 4 actions (I haven’t tried this)