Gvim Commands Set
Below is the list of most frequently used Gvim/Vim commands, also below table describes the basic Gvim/Vim commands, Commands to replace string’s and shortcuts to use Gvim/Vim.
You can Practice the below commands in web browser based online vi editor.
Comand
|
Description
|
i
|
Insert
|
r
|
replace
|
:w
|
Write/Save the file
|
:q
|
Quit the file
|
:wq
|
Write/Save then quit
|
😡
|
Write/Save then quite
|
:w!
|
Overwrite
|
:q!
|
Quit
|
u
|
Undo
|
:E
|
Open File explorer
|
.
|
To repeat the previous action
|
^
|
Indicates starting of line
|
$
|
Indicates end of line
|
:set nu
|
To set line number, Enable line number view
|
:set nonu
|
Hides line number, Disable line no view
|
yy
|
Copy the line
|
p
|
Paste the copied line
|
3yy
|
To copy 3 lines
|
3p
|
Paste the copied lines 3 times
|
:30 or :n
|
To move cursor to 30th line and to move
nth line (n is numeric ) |
gg
|
To move cursor to beginning of page, that is line
number 1 |
G
|
To move cursor to last line of page
|
H
|
To move cursor to the top line of screen
|
M
|
To move cursor to the middle line of screen
|
L
|
To move cursor to the last line of screen
|
1G
|
To move cursor to the first line of file
|
dw
|
To delete the word from place of cursor to till next
word |
:sp file1
|
Split the screen horizontally and open file1
|
:vsp file1
|
Split the screen vertically and open file1
|
(ctrl)+ww
|
To move cursor from one file to other file in split window
|
:e
|
To re-load the opened file
|
*
|
search a word:
place cursor on any word to be searched and press *
To find
next occurrence press n To find previous occurrence press N |
:g//d
|
This will deletes the lines which contains previous
searched pattern |
:g!//d
|
This will deletes the other lines which doesn’t
contains previous searched pattern |
“ctrl+v”
then “down” or “up” then “I” then “pattern1” then “esc” |
Visual Mode:
Pattern (Adding any text) will be added at the place of
selection. |
gf
|
open the file name under cursor:
Place a cursor on file path and press gf.
|
Ctrl+w+f
|
split window and open a file:
place a cursor on file path and press Ctrl+w+f
|
ctrl+p
|
Auto fill.
While typing ctrl+p will shows the auto fill word’s
|
ctrl+x+f
|
Auto fill the path.
While typing any
path, ctrl+x+f auto fills the path |
:%s/flower/rose/gc
|
Replace the string flower by rose.
g –
indicates global c-conditional replacement, asks for replacement
|
:%s/^/rose/gc
|
add rose in beginning of all the line
|
ctrl+a
|
Increment
number. Place
cursor on any number and press “ctrl+a”, then the number will be incremented by 1. |
ctrl+x
|
Decrements
number. Place
cursor on any number and press “ctrl+x”, then the number will be decremented by 1. |
Vimrc:
The vimrc file contains configuration settings to initialize when vim starts.
Create .vimrc file in home location and add below code.You can add some more features if required.
——————————— code starts here —————————-
set nu
set autoindent
set showmatch
set ignorecase
set nu
set autoindent
set showmatch
set ignorecase
——————————— code ends here —————————-
Description for above code,
set nu — Display line numbers
set autoindent — Set Auto Indentation during text entry
set showmatch — Show Matching ( or { when ) or } is entered
set ignorecase — Set Ignore Case during searches