VIM is a powerful and popular text editor that runs on the command line. Using vim you will navigate around on screen with keyboard instead of a mouse . It has a steep learning curve, but it can greatly improve your productivity once you master it. Here are some basic VIM commands to help you get started:
Frequently used commands :
i – insert before the cursor
Esc – exit insert mode
: number – show line number
/pattern – search for pattern
n – repeat search in same direction
$ – move cursor to end of line
GG – move cursor to bottom of page
gg – move cursor to top of page
yy – yank (copy) a line
- p – put (paste) the clipboard after the cursor
:q – quit (fails if there are unsaved changes)
:wq or : x or ZZ – write (save) and quit
:w – write (save) the file, but don’t exit
commands to move the cursor:
- h – move cursor left
- j – move cursor down
- k – move cursor up
- l – move cursor right
- gj – move cursor down (multi-line text)
- gk – move cursor up (multi-line text)
- H – move to top of screen
- M – move to middle of screen
- L – move to bottom of screen
- w – jump forwards to the start of a word
- W – jump forwards to the start of a word (words can contain punctuation)
- e – jump forwards to the end of a word
- E – jump forwards to the end of a word (words can contain punctuation)
- b – jump backwards to the start of a word
- B – jump backwards to the start of a word (words can contain punctuation)
commands for Editing
- r – replace a single character.
- R – replace more than one character, until ESC is pressed.
- J – join line below to the current one with one space in between
- gJ – join line below to the current one without space in between
- cc – change (replace) entire line
- c$ or C – change (replace) to the end of the line
- ciw – change (replace) entire word
- cw or ce – change (replace) to the end of the word
- s – delete character and substitute text
- S – delete line and substitute text (same as cc)
- xp – transpose two letters (delete and paste)
- u – undo
- U – restore (undo) last changed line
- Ctrl + r – redo
- . – repeat last command
commands for saving and exiting
- :w – write (save) the file, but don’t exit
- :w !sudo tee % – write out the current file using sudo
- :wq or : x or ZZ – write (save) and quit
- :q – quit (fails if there are unsaved changes)
- :q! or ZQ – quit and throw away unsaved changes
- :wqa – write (save) and quit on all tabs
command for search and replace
- /pattern – search for pattern
- ?pattern – search backward for pattern
- n – repeat search in same direction
- N – repeat search in opposite direction
commands for cut and paste
- yy – yank (copy) a line
- 2yy – yank (copy) 2 lines
- yw – yank (copy) the characters of the word from the cursor position to the start of the next word
- yiw – yank (copy) word under the cursor
- y$ or Y – yank (copy) to end of line
- p – put (paste) the clipboard after cursor
- P – put (paste) before cursor
- dd – delete (cut) a line
Visual commands
- > – shift text right
- < – shift text left
- y – yank (copy) marked text
- d – delete marked text
- ~ – switch case
- u – change marked text to lowercase
- U – change marked text to uppercase