Wednesday 10 July 2019

Common vi Commands

List of commonly used vi commands

Command              Does the following function

Insert Text
a                              Inserts text after the cursor
A                             Inserts text at the end of the current line
I                               Inserts text at the beginning of the current line
i                               Inserts text before the cursor

Delete Text
D                             Deletes up to the end of the current line
dd                           Deletes the current line
dG                          Deletes from the current line to the end of the file
dw                          Deletes the current word where the cursor presently resides
x                              Deletes the character on which the cursor rests

Change Text
C                             Changes up to the end of the current line
cc                            Changes the current line
J                              Joins the current line with the next one
rx                            Replaces the character under the cursor with x
                                (where x is any character)

Search Text       
/string                  Searches forward for a string
?string                  Searches backward for a string

Scroll Text
Ctrl+D                   Scrolls forward by half a screen
Ctrl+U                   Scrolls backward by half a creen
Ctrl+L                    Redraws/refresh the screen

Cut and Paste Text
yy                           Yanks(copies)current line to an unnamed buffer
P                             Puts the yanked line above the current line
p                             Puts the yanked line below the current line

Move Cursor     
h                              Moves one character to the left
j                               Moves one line down
k                              Moves one line up
L                              Moves to the end of the screen
l                               Moves one character to the right
w                             Moves to the beginning of the following word
b                              Moves to the beginning of the previous word

Colon commands
:!command           Executes a shell command
:q                            Quits the editor
:q!                           Quits without saving changes
:r filename             Reads the file and inserts it after the current line
:w filename           Writes a buffer to the file
:wq                         Saves changes and exits

More
u                             Undoes the last command
Esc                          Ends input mode and enters visual command mode
U                             Undoes resent changes to the current line

Learn more:- Vim Cheat Sheet

No comments:

Post a Comment