To open files with Vim, use the following command: vim file. To open multiple files as split windows, type: $ vim -0 file1 file2. To open a file from the Vim command-line, use the following: :efile II Auto complete is supported by pressing TAB.
To save the changes to the currently opened file, press ESC to switch to the command mode from the editing mode, then type :w and press ENTER. To exit Vim after saving a file, type :wq. To just quit without saving, use :q! To save the current file as a new file, use the command line.
Manipulating files
Cut, copy and paste are essential features of any text editor. To cut the current word, place the cursor at the starting character of the word and use 'cw'. To cut the current line, use 'cc' in the command mode. To copy the current word, place the cursor at the starting letter and use 'yw', while to copy an entire line, use 'yy'. To paste content, place the cursor at the position where the contents of the buffer need to be placed, and press 'p'.
To remove a word, place the cursor at the starting letter of the word, and press 'dw', while to remove a line, press 'dd', and to remove a character, press 'x'. To undo the previous action, press 'u', while to redo an action, 'Ctrl + r'. To repeat a previously performed task, press ': To list the available undo tasks, ':undolist'.
To search, substitute and replace
To search for a word/sentence while in the command mode, type Iword and press ENTER, where 'word' is the word you're searching for. To repeat the search
in the forward direction, press n, while to reverse the direction of the search, press?
To replace a part of the text, use:%s/word_pattern/replacement_text/ - replaces the first word of every line
•:%s/word_pattern/replacement_text/ - global replacement of t,he word
•:%s/word_pattern/replacement_text/ gc - replacement with interactive Yes/No confirmation %s represents the entire text in the file. It is also possible to use a range of lines for replacement. In case we want to use a replacement only between the lines 1 and 25, the above command can be used.