I’ve compiled a list of essential Vim commands that I use every day. I have then given a few instructions on how to make Vim as great as it should be, because it’s painful without configuration.
h
j
k
l
- Arrow keysw
/ b
- Next/previous wordW
/ B
- Next/previous word (space separated)e
/ ge
- Next/previous end of word0
/ $
- Start/End of line^
- First non-blank character of line (same as 0w
)i
/ a
- Start insert mode at/after cursorI
/ A
- Start insert mode at the beginning/end of the lineo
/ O
- Add blank line below/above current lineEsc
or Ctrl+[
- Exit insert moded
- Deletedd
- Delete linec
- Delete, then start insert modecc
- Delete line, then start insert moded
- Deletes from the cursor to the movement locationc
- Deletes from the cursor to the movement location, then starts insert modey
- Copy from the cursor to the movement location>
- Indent one level<
- Unindent one leveld$
deletes from the cursor to the end of the line.v
- Start visual modeV
- Start linewise visual modeCtrl+v
- Start visual block modeEsc
or Ctrl+[
- Exit visual modeyy
- Yank (copy) a linep
- Paste after cursorP
- Paste before cursordd
- Delete (cut) a linex
- Delete (cut) current characterX
- Delete (cut) previous characterd
/ c
- By default, these copy the deleted text:w
- Write (save) the file, but don’t quit: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 confirmationsu
- UndoCtrl+r
- RedoCtrl+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 documentctrl+e / ctrl+y
- Scroll down/up one linef [char]
- Move forward to the given charF [char]
- Move backward to the given chart [char]
- Move forward to before the given charT [char]
- Move backward to before the given char;
/ ,
- Repeat search forwards/backwardsJ
- Join line below to the current oner [char]
- Replace a single character with the specified char (does not use Insert mode)O
- Move to other corner of blocko
- Move to other end of marked area: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 windowm{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 locationdef (arg1, arg2, arg3)
, where your cursor is somewhere in the middle of the parenthesis.di(
deletes everything between the parenthesis. That says “change everything inside the nearest parenthesis”. Without text objects, you would need to do T(dt)
..
- Repeat last commandCtrl+r + 0
in insert mode inserts the last yanked text (or in command mode)gv
- reselect (select last selected block of text, from visual mode)%
- jumps between matching ()
or {}
Vim is quite unpleasant out of the box. It’s an arcane experience:
:w
to save is cumbersomeIt does have a significant strength though: your fingers can stay on the main keyboard keys to do most editing actions. This is faster and more ergonomic. I find that the toughest part about VIM is guiding people towards getting the benefits of VIM without the drawbacks. Here are some ideas on how to go about this.
For all the given limitations, you’ll need to find a solution. You can either solve the issues one by one, or you can use a reference .vimrc settings file that fix most of the issues out-of-the-box.
"+y
copy a selection to the system clipboard"+p
paste from the system clipboardvim --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 Text 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": "@"} },
I don’t personally use these yet, but I’ve heard other people do!
:qa
- Quit all open buffers:wa
- Write all open buffers:wqa
- Write and quit all open buffers