Vim is a powerfull text editor for *nix. Vim (Vi Improved) is the improved version of the famous vi editor.
vim-tiny is installed by default on most *nix distributions. However, it has limited features and I recommend that you install vim complete as follows:
$ sudo aptitude install vim
There are several modes in Vim:
- Interactive: This is the default mode. You can cancel the last action, copy and paste, ...
- Insert: This is the mode that enables to add text. To enter this mode, press the key.
- Visual: This mode enables to select text, cut, copy, paste, ... To enter this mode, press the key.
- Command: In this mode, you can quit vim and save a file but also to launch commands.
Open, Save, Quit
Open a file
To open a file, do as follows:
$ vim fileToOpenOr from vim directly (from interactive mode), press where <file> is the file to open.
- To save modifications without leaving vim, press .
- To save and quit vim, press .
- To quit without saving eventual changes, press to ensure you're not in a mode (e.g. edition) and then press .
- To save and quit, press or .
- To move in a file, you can use the arrow keys or use (left), (down), (up), (right).
- To go at the beginning of a line, press
- To go at the end of a line, press
- To jump from words to words, press
- To jump to the beginning of a file, press
- To jump to the end of a file, press
- To go to a specific line, press or where <n> is the line number. For example, to go to line 134, press and then .
- To delete a character from the interactive mode, press or to delete 5 characters
- To delete a character from the edit mode, press .
- To delete an entire line from the interactive mode, press . To delete 3 lines, press .
- To delete a word from the interactive mode, place your cursor on the first letter of the word to delete and press . To delete 4 words, press .
- To delete all content from the cursor to the beginning of the line, press .
- To delete all content from the cursor to the end of the line, press .
Cut, Copy, Paste
From the visual mode
- First enter the visual mode by pressing from the interactive mode.
- Select a text with the arrow keys.
- Press to copy a selection
- Press to cut a selection
- Press to paste the content
From the interactive mode
- To cut, use the key (see the different combination above to cut a word, a line or part of a line).
- To copy, use the
- copies the entire line
- copies the word where the cursor is placed
- other possible combination (e.g. will copy 2 words)
- To paste, use the key. Notice that will paste the content 3 times
Undo and redo
- To cancel the last modification, press (undo).
- To redo, press
Search and replace
- To search for a string, press where string is the text to search and then press .
- To jump to the next occurence, press .
- To look backwards, press .
Search and replaceThere are several ways to search and replace. Ensure you are in the interactive mode (press ) and choose one of the below options.
- replace oldtext with newtext only for the first occurence on the line where the cursor is placed
- replace oldtext with newtext for all occurences on the line where the cursor is placed
- replace all occurences between line <m> and line <n>
- replace all occurences in the whole file