Overcoming Basic VIM Frustrations



When you first open the VIM editor, you are in the command mode of the editor. The command mode is where you type in awesome VIM commands to manipulate text.

Insertion mode is just where you can type text normally. (Like in windows notepad) To get into insertion mode, type i (abbreviation for insert). To get into command mode, press the Esc key.

If you're ever not sure which mode you're in, just press the Esc key and you'll be in command mode for sure.

The following commands are executed in command mode.


Copy & Paste
Press v. (To enter visual mode so you can highlight stuff)
Use the arrow keys (or h,j,k,l,w,b,$) to higlight
Press y to yank, p to paste. (shift-p to open up a line above and paste)
Copy a word yw
Copy a line yy
Copy from cursor to end of line y$

Copy & Paste (with Registers)
Press v. (To enter visual mode so you can highlight stuff)
Use the arrow keys (or h,j,k,l,w,b,$) to higlight
Type "ay to yank into register a.
Type "ap to paste from register a.

Deleting
Press v. (To enter visual mode so you can highlight stuff)
Use the arrow keys (or h,j,k,l,w,b,$) to higlight and press d
Delete character x
Delete word dw
Delete word and insert text cw
Delete line dd
Delete to end of line D
Delete 2 lines d2d

Indenting
Press v and then arrow keys (or h,j,k,l,w,$) to highlight lines of text.
Type > or < to indent right or left.
(if you want to indent more, type 2> or 3>.
(if you want to change your indenting/tabbing to use spaces and not tabs, type :set et
(if you want to set auto-indenting, type :set ai)

Insert Text
Insert at cursor i
Insert after cursor a (useful when at the end of a line)
Open a line below cursor and insert o
Open a line above cursor and insert shift-o

Moving Around
Go up k
Go down j
Go left h
Go right l
Go right a word w
Go left a word b
Go to beginning of file gg
Go to end of file G
Go to beginning of non-whitespace part of line ^
Go to end of line $
Go 22 lines down 22j
Go right 5 words 5w
Quit
Type :q to quit the VIM editor.

Save
Type :w to write to the file.

Search & Replace
Search / (after the slash put whatever you want to find and press the enter key)

Find next n
Find previous N

Turn off highlighting (after a search)  :noh

Find next instance of a word that your text cursor is over *

Search from current line to end of file :,$s/search/replace/gc (the gc means global and confirm)

Shell (Exit temporarily to a shell)  :sh
To come back to VIM from the shell type exit

Split Window Editing
Type :sp followed by the filename.

Go to window above ctrl-w-k
Go to window below ctrl-w-j
Maximize window size ctrl-w _  (the underscore is NOT pressed at the same time as the ctrl-w)
Make all windows equal size ctrl-w =  (the equals sign is NOT pressed at the same time as the ctrl-w)

Tab Settings
(to set the tab-size, type :set ts=2 (or whatever number you want)
(also, for tabbing-size, set shiftwidth (>) by typing :set sw=2Navigation

Undo & Redo
Undo  u
Redo  ctrl-r

View Directory & Files (File explorer)
Type  :S  (the S is uppercase)

This will split the window and open up a file explorer. Use the enter key to select directories or open files.