07. vim_gvim commands - muneeb-mbytes/linux_course GitHub Wiki

Steps to open the file using vim command:

Note:- vim and gvim both are similar but gvim is GUI version of vim editor.

Step-1:- Run the following command from terminal.

command:- vim example.txt (general format:- vim filename.extension)

vim1

                                            Figure.1. Creating vim file

Step-2:- vi editor window will open and it will looks like picture given below.

vim2

                                            Figure.2. vim editor window

Step-3:- go to insert mode by pressing i from the keyboard.

vim3

                                            Figure.3. vim editor in insert mode

Step-4:- write the contents into the file in insert mode and press esc key then type :wq for saving the contents in file and quit.

Note:- in esc mode by typing :q! command file closed without saving the contents.

vim4

                                            Figure.4. Content in file and save  

vim/gvim commands cheat sheet:

1) cursor movement:

Sr No. Vim commands Description
1 M move to middle of screen
2 L move to bottom of screen
3 0 jump to the start of the line
4 $ jump to the end of the line
5 gg go to the first line of the document
6 G go to the last line of the document
7 zz center cursor on screen
                       Tabular column.1. vim/gvim command cheat sheet

2) cut and paste:

Sr No. Vim commands Description
1 yy yank (copy) a line
2 2yy yank (copy) 2 lines
3 p put (paste) the clipboard after cursor
4 P put (paste) before cursor
5 gp put (paste) the clipboard after cursor and leave cursor after the new text
6 gP put (paste) before cursor and leave cursor after the new text
7 dd delete (cut) a line
8 2dd delete (cut) 2 lines
                         Tabular column.2. cut and paste command cheat sheet

3) Insert mode - inserting / appending the text:

Sr No. Vim commands Description
1 i insert before the cursor
2 I insert at the beginning of the line
3 a insert (append) after the cursor
4 A insert (append) at the end of the line
5 o append (open) a new line below the current line
6 O append (open) a new line above the current line
7 Esc exit insert mode
                         Tabular column.3. Insert command cheat sheet

4) Replacing the word in line

command:- %s/word_to_be_replaced/replaced_word

eg:- %s/hello/hi

in above example hello word will be replaced by hi in file.


vim --help

Using the vim --help command user came to know vim command available options with it's description.


To learn cat command : https://github.com/muneeb-mbytes/linux_course/wiki/08.-cat-command