Vim is one of the most popular text editors in Linux. If you haven’t used yet, these are the basic commands to start.
Table of Contents
- Opening a file with Vim, inserting text, saving and close
- Moving through file
- Selecting text
- Deleting text
- Undo, copy, cut and paste
- More commands
Opening a file with Vim, inserting text, saving and close
- Open a file or directory (from a terminal).
vim text.txt vim .
- Open a file or directory (inside Vim):
:e text.txt :e .
- Inside Vim, type
iand press Enter to enter “insert mode”. Then you can edit the file.
- To save changes, first exit “insert mode” by pressing Escape. Then, type
:w(and press Enter) to save changes.
- Close Vim typing
:qand pressing Enter. You can save changes and close the file at once by typing
:wq. If you want to close without saving changes, type
Moving through file
- You can use keyboard arrows or
hfor left and
- You can move the cursor to the top of the file with
- To the end of the file with
- To the beginning of the current line with
- To the end of the current line with
- You can search inside a file typing
/and the word (and pressing Enter). Then, you can move to the next ocurrence with
nor the previous with
- You can go to the first ocurrence with
ggnor to the last ocurrence with
- To select, type
vto enter “visual mode” (first press Escape to exit “insert mode” if you were in it) and use arrows or k,j,h,l to select the text.
- Delete a text selection simply by typing
- You can delete the current line by typing
- You can delete a word with
Undo, copy, cut and paste
- To undo, type
- To redo: Ctrl + r.
- To copy a selection, type
- To copy the current line, type
- To cut a selection, type
- To paste, type
- Split window horizontally: Ctrl + ws
- Split window vertically: Ctrl + wv
- Change to the right window: Ctrl + wl
- Change to left window: Ctrl + wh
- Change to the window above: Ctrl + wk
- Change to the window below: Ctrl + wj
Ato go to the end of the line and enter “insert mode”.
oto create a new line below current line and enter “insert mode”.
cwto delete current word and enter “insert mode”.