Vim
Standard
Enclose a word, using single quotes.
:ciw ‘’
P
List all the active buffers.
:ls
Navigation
k
: UPj
: DOWNh
: LEFTl
: RIGHTw
: NEXT WORDb
: PREVIOUS WORDe
: NEXT WORD ENDge
: PREVIOUS WORD ENDgg
: TOPG
: BOTTOM0
: LINE START$
: LINE END^
: LINE START NON BLANKg_
: LINE END NON BLANK(
: MOVE ONE SENTENCE UP)
: MOVE ONE SENTENCE DOWN{
: MOVE ONE PARAGRAPH UP}
: MOVE ONE PARAGRAPH DOWN- ``: TOGGLE BETWEEN LAST TWO VISITED PLACES
- `.: NAVIGATE TO THE LAST EDITED PLACE
%
: NAVIGATE TO THE MATCHING BRACE
Scroll
CTRL-u
: HALF A PAGE UPCTRL-d
: HALF A PAGE DOWNCTRL-b
: FULL PAGE UPCTRL-f
: FULL PAGE DOWN
Finding and jumping to a character
f
: FINDF
: FIND REVERSEt
: FIND NEXTT
: FIND PREVIOUS
Entering into insert mode from normal mode
i
: INSERT (Places the cursor before the current position)a
: INSERT (Places the cursor after the current position)A
: INSERT LINE AFTER (Places the cursor at the end of the line)I
: INSERT LINE BEFORE (Places the cursor at the beginning of the line)o
: INSERT LINE AFTER (Places the cursor at the end of the line)O
: INSERT LINE BEFORE (Places the cursor at the beginning of the line)- ’s’: REPLACE THE CURRENT LETTER AND ENTER INTO INSERT MODE
- ‘S’: REPLACE THE CURRENT WORD AND ENTER INTO INSERT MODE
- ‘C’: REPLACE THE CURRENT LINE AND ENTER INTO INSERT MODE
- ‘c’: REPLACE AND ENTER INTO INSERT MODE
Copy
yy
: COPY THE CURRENT LINEy
: COPY BASED ON THE MOTIONyi{
: To copy text within {}ya{
: To copy text including {}yiw
: To copy text within a word"ayw
: To copy a word in a register
Search and replace
Undo
u
: UNDOCtrl-r
: REDO
Delete
x
: DELETE THE CURRENT LETTERd
: DELETE BASED ON THE MOTIONdw
: DELETE THE CURRENT WORDdd
: DELETE THE CURRENT LINED
: DELETE FROM CURRENT POSITION TO END OF THE LINEdi{
: To delete text within {da{
: To delete text including {diw
: To delete text within a worddis
: To delete text within a sentencedip
: To delete text within a paragraph
Search
/
: SEARCH?
: SEARCH REVERSEn
: SEARCH NEXTN
: SEARCH PREVIOUS*
: SEARCH CURRENT WORD FORWARD#
: SEARCH CURRENT WORD BACKWARD
Marks
Marks in vim are like bookmarks. We can mark a place in a file and later jump to that place. In order to mark a place, we use m followed by the letter of the alphabete which would stored in register. in order to jump to that place, we use ` followed by the letter of the alphabete which would stored in register.
Upper case letters are used as global marks and lower case letters are used as local marks.
To see the list of all the marks in vim, we use :marks
command.
Folds
za
: OPEN/CLOSE FOLDzM
: CLOSE ALL FOLDSzR
: OPEN ALL FOLDS
Focus
zz
: CENTER THE CURSOR
Indentation
==
: CORRECT THE INDENTATION- Select visually the entire block that needs to be indended followed by
=
>
: INCREASE THE INDENTATION<
: DECREASE THE INDENTATION
Block mode
This mode is useful when you want to select multiple lines or words in visual mode.
v
: VISUALV
: LINE VISUAL<CTRL-V>
: BLOCK VISUAL
Edit multiple lines in visual mode
- After entering Block visual mode, make selection following by
Ctrl-i
. Edit the first occurance and exit the insert mode. This would apply the same change to all the selected lines.
Join lines
J
: JOIN LINES
Manipulate case
~
: TOGGLE CASE OF THE CHARACTER UNDER THE CURSORgUw
: UPPERCASE CASE OF THE WORD UNDER THE CURSORguw
: LOWERCASE CASE OF THE WORD UNDER THE CURSORg~w
: TOGGLE CASE OF THE WORD UNDER THE CURSORgUU
: UPPERCASE CASE OF THE LINE UNDER THE CURSORguu
: LOWERCASE CASE OF THE LINE UNDER THE CURSOR
Number manipulation
- Increment the number under the cursor by pressing
Ctrl-a
keys - Decrement the number under the cursor by pressing
Ctrl-x
keys
Sort
- To sort lines in the file use the command
:sort
- To sort lines in reverse order use the command
:sort!
- To sort lines and keep unique lines in the file use the command
:sort u
read a file or command output in the file
Use the command :read
followed by the name of the file or the command.
Macro
If we want to record an action and apply it later, we can use macros.
Use q
to start recording followed by an alphabet key (i.e. register) and @
, followed by the same alphabet key to apply the macro.
To stop recording, use
q` again.
List value copied in each register.
Custom
Enclose value with $char
- Use v (visual mode) to make the selection.
- Press “S” to activate the vim-surround plugin
- Press $char to surround the selected text with $char