Skip to content

07. vim_gvim commands

Gopalsuthar2308 edited this page Aug 20, 2022 · 4 revisions

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 h moves cursor left
2 j moves cursor down
3 k move cursor up
4 l move cursor right
5 gj move cursor down (multi-line text)
6 gk move cursor up (multi-line text)
7 H move to top of screen
8 M move to middle of screen
9 L move to bottom of screen
10 w jump forwards to the start of a word
11 W jump forwards to the start of a word (words can contain punctuation)
12 e jump forwards to the end of a word
13 E jump forwards to the end of a word (words can contain punctuation)
14 b jump backwards to the start of a word
15 B jump backwards to the start of a word (words can contain punctuation)
16 0 jump to the start of the line
17 $ jump to the end of the line
18 gg go to the first line of the document
19 G go to the last line of the document
20 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 yw yank (copy) the characters of the word from the cursor position to the start of the next word
4 yiw yank (copy) word under the cursor
5 yaw yank (copy) word under the cursor and the space after or before it
6 y$/Y yank (copy) to end of line
7 p put (paste) the clipboard after cursor
8 P put (paste) before cursor
9 gp put (paste) the clipboard after cursor and leave cursor after the new text
10 gP put (paste) before cursor and leave cursor after the new text
11 dd delete (cut) a line
12 2dd delete (cut) 2 lines
13 dw delete (cut) the characters of the word from the cursor position to the start of the next word
14 diw delete (cut) word under the cursor
15 d$/D delete (cut) to the end of the line
16 x delete (cut) character
                         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 ea insert (append) at the end of the word
8 Esc exit insert mode
                         Tabular column.3. Insert command cheat sheet

4) Global:

Sr No. Vim commands Description
1 :h[elp] keyword open help for keyword
2 :sav[eas] file save file as
3 :clo[se] close current pane
4 :ter[minal] open a terminal window
5 K open man page for word under the cursor
                         Tabular column.4. Global command cheat sheet

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/cat-command

Clone this wiki locally