useful vi commands for Linux beginners
1) To open two files in single window of vi editor
a) vi a.c
b) give the following command in vi editor to open b.c file
:sp b.c
c) Now vi editor contain two files in each half screen. TO switch
between two files use ctrl+ww.
2)Replacing a text
a) vi a.c
b) In a.c file, replace printf with printk using follwing command
:%s/printf/printk
This will replace only first occurrence of printf in each line.
:%s/printf/printk/g
The above command will replace all printf words in entire
file with printk.
:%s/printf/printk/gc
The above command will ask confirmation.
:s/printf/printk
This commamnd will replace in current line.
3)setting auto indentation:
In home directory create .exrc file add the following commands
:set nu
:set cindent
:set cindent will do indentation in C
4) To open a man page of a system call from vi editor
a) vi a.c
put the cursor at system call and press shift+k
5) commands:
G : to goto endline in vi
X : delete the character
J : To join two lines
DW : Delete the Word
/str : search down for string
?str : search up for string
1) To open two files in single window of vi editor
a) vi a.c
b) give the following command in vi editor to open b.c file
:sp b.c
c) Now vi editor contain two files in each half screen. TO switch
between two files use ctrl+ww.
2)Replacing a text
a) vi a.c
b) In a.c file, replace printf with printk using follwing command
:%s/printf/printk
This will replace only first occurrence of printf in each line.
:%s/printf/printk/g
The above command will replace all printf words in entire
file with printk.
:%s/printf/printk/gc
The above command will ask confirmation.
:s/printf/printk
This commamnd will replace in current line.
3)setting auto indentation:
In home directory create .exrc file add the following commands
:set nu
:set cindent
:set cindent will do indentation in C
4) To open a man page of a system call from vi editor
a) vi a.c
put the cursor at system call and press shift+k
5) commands:
G : to goto endline in vi
X : delete the character
J : To join two lines
DW : Delete the Word
/str : search down for string
?str : search up for string
Comments