Note: If you’re decent at vim and want your mind blown, check out Advanced Vim.
I’ve compiled a list of essential vim commands that I use every day. I then give a few instructions on how to making vim as great as it should be, because it’s painful without configuration.
w
- jump by start of words (punctuation considered words)W
- jump by words (spaces separate words)e
- jump to end of words (punctuation considered words)E
- jump to end of words (no punctuation)b
- jump backward by words (punctuation considered words)B
- jump backward by words (no punctuation)0
- (zero) start of line^
- first non-blank character of line (same as 0w)$
- end of lineCtrl+d
- move down half a pageCtrl+u
- move up half a page}
- go forward by paragraph (the next blank line){
- go backward by paragraph (the next blank line)gg
- go to the top of the pageG
- go the bottom of the page: [num] [enter]
- Go To that line in the documentf [char]
- Move to the next char on the current line after the cursorF [char]
- Move to the next char on the current line before the cursort [char]
- Move to before the next char on the current line after the cursorT [char]
- Move to before the next char on the current line before the cursor;
(semicolon) to go to the next searched item, and ,
(comma) to go the the previous searched itemi
- start insert mode at cursorI
- insert at the beginning of the linea
- append after the cursorA
- append at the end of the lineo
- open (append) blank line below current line (no need to press return)O
- open blank line above current linecc
- change (replace) an entire linec [movement command]
- change (replace) from the cursor to the move-to point.ce
changes from the cursor to the end of the cursor wordr [char]
- replace a single character with the specified char (does not use insert mode)d
- delete
d
- [movement command] deletes from the cursor to the move-to point.de
deletes from the cursor to the end of the current worddd
- delete the current lineJ
- join line below to the current onev
- starts visual mode
y
, d
, or c
)V
- starts linewise visual modeCtrl+v
- start visual block modeEsc
- exit visual modeO
- move to Other corner of blocko
- move to other end of marked areaType any of these while some text is selected to apply the action
y
- yank (copy) marked textd
- delete marked textc
- delete the marked text and go into insert mode (like c does above)yy
- yank (copy) a linep
- put (paste) the clipboard after cursorP
- put (paste) before cursordd
- delete (cut) a linex
- delete (cut) current characterX
- delete previous character (like backspace):w
- write (save) the file, but don't exit:wq
- write (save) and quit:q
- quit (fails if anything has changed):q!
- quit and throw away changes/pattern
- search for pattern?pattern
- search backward for patternn
- repeat search in same directionN
- repeat search in opposite direction:%s/old/new/g
- replace all old with new throughout file (gn is better though):%s/old/new/gc
- replace all old with new throughout file with confirmations:e filename
- Edit a file:tabe
- make a new tabgt
- go to the next tabgT
- go to the previous tab:vsp
- vertically split windowsctrl+ws
- Split windows horizontallyctrl+wv
- Split windows verticallyctrl+ww
- switch between windowsctrl+wq
- Quit a windowMarks allow you to jump to designated points in your code.
m{a-z}
- Set mark {a-z} at cursor position ‘{a-z}
- move the cursor to the start of the line where the mark was set‘’
- go back to the previous jump locationu
- undoCtrl+r
- redo.
- repeat last commandVim is quite unpleasant out of the box. For example, typeing :w
for every file save is awkward and copying and pasting to the system clipboard does not work. But a few changes will get you much closer to the editor of your dreams.
[space]w
for write, instead of :w [enter]
)[space]w
to save a file)
nano .vimrc
ctrl+x
, y
, [enter]
to save[space]w
in normal mode to save a file.[space]p
should paste from the system clipboard (outside of vim).
vim --version
and see if +clipboard
exists. If it says -clipboard
, you will not be able to copy from outside of vim.brew install vim
.
$ mv /usr/bin/vim /usr/bin/vimold
vim --version
now with +clipboard
Vintageous is great, but I suggest you change a few settings to make it better.
~/.config/sublime-text-3/Packages/Vintageous
, or similar. Then check out the "custom" branch.
User/Preferences.sublime-settings
) to include:
"caret_style": "solid"
ctrl+r
in vim means "redo". But there is a handy ctrl+r shortcut in sublime that gives an "outline" of a file. I remapped it to alt+r by putting this in the User keymap
{ "keys": ["alt+r"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
Now you should be able to restart sublime and have a great vim environment! Sweet Dude.
I don’t personally use these yet, but I’ve heard other people do!
:wqa
- Write and quit all open tabs (thanks Brian Zick)