Introduction
Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as “vi” with most UNIX systems.
Among its features are:
- persistent, multi-level undo tree
- extensive plugin system
- support for hundreds of programming languages and file formats
- powerful search and replace
- integrates with many tools
How to use it.
Modes
There are four modes:
- Normal mode: moving over the editing document with directional keys such h, j, k, and l
- Insert mode: inserting with a key i or appending with a key a
- Visual mode: marking a block starting a key v and then directional keys.
- Command mode: issuing commands after typing in :
Useful commands
- x: delete the character where the cursor is
- r: replace the character where the cursor is
- yy: copy a line where the cursor is
- dd: delete a line where the cursor is
- o: append afer the line where the cursor is
- O: insert before the line where the cursor is
- p: paste the deleted block or yanked block
- .: repeat the previous command
- >: indent the line
- <: unindent the line
- u: undo
- ^R: redo
- ~: toggle cases
Useful movements
- 0: move the cursor at the start of line where the cursor is
- ^: move the cursor to the non-blank start of line where the cursor is
- $: move the cursor at the end of line where the cursor is
- w: move the cursor at the start of next word
- e: move the cursor at the end of previous word
- b: move the cursor at the start of previous word
- gg: move the cursor at the start of the document
- G: move the cursor at the end of the document
- nG: move the cursor to the line number n
- f: move the cursor to the position where a character given after f is
ex)fg means moving the cursor to g character
- t: move the cursor to the position where a character given after t is
ex)fg means moving the cursor to g character
Objects
- w: word
- s: sentence
- p: paragraph
- iw: inner word
- ap: a paragraph
How to give commands
- n COMMANDS: repeate COMMANDS n times
ex) 3j means go down three times
- COMMANDS MOVEMENTS: apply the COMMANDS to the entire block made by the MOVEMENTS
ex) d$ means delete the entire characters from the cursor position to the end of line
- COMMANDS OBJECTS: issuing the COMMANDS to the OBJECTS
ex) d3w means delete three words
Commenting on multiple lines
- mark multiple lines by issuing a command v (visual mode) and using directional keys
- enter the command mode by keying in :
- issue commands norm i# to insert #’s in case of Python
or
- mark multiple lines by issuing a command ^v (visual block mode) and using directional keys
- enter I#
- Keying in ESC two times
ex)
for i in range(10)
j = 2 * i + 3
print(j)
#for i in range(10)
# j = 2 * i + 3
# print(j)
Uncommenting on multiple lines
- mark multiple lines by issuing a command v and using directional keys
- enter the command mode by keying in :
- issue commands norm 1x to delete #’s
or
- mark multiple lines by issuing a command ^v (visual block mode) and using directional keys
- enter I1x
- Keying in ESC two times