vi Commands Cheat Sheet

In Prompts, vi

As a beginner in the world of programming, you might have heard of the text editor called “vi” or “vim”. Vi is a powerful text editor that is widely used by programmers and system administrators. It is a command-line tool that allows you to create, edit, and manipulate text files. However, for beginners, the vi commands can be quite intimidating. That’s why we have created this cheat sheet to help you get started with vi commands.

Vi commands are divided into two modes: command mode and insert mode. In command mode, you can navigate through the text, delete, copy, paste, and perform other operations. In insert mode, you can insert text into the file. To switch between the two modes, press the “Esc” key.

Here are some of the most commonly used vi commands:

1. Moving the cursor:
– h: move left
– j: move down
– k: move up
– l: move right
– 0: move to the beginning of the line
– $: move to the end of the line
– gg: move to the beginning of the file
– G: move to the end of the file

2. Editing text:
– i: switch to insert mode
– x: delete the character under the cursor
– dd: delete the current line
– yy: copy the current line
– p: paste the copied or deleted text after the cursor
– u: undo the last command
– Ctrl + r: redo the last command

3. Searching for text:
– /: search forward for a pattern
– ?: search backward for a pattern
– n: move to the next occurrence of the pattern
– N: move to the previous occurrence of the pattern

4. Saving and quitting:
– :w: save the file
– :q: quit the file
– :wq: save and quit the file
– :q!: quit the file without saving

These are just a few of the many vi commands that you can use. As you become more familiar with vi, you will discover more commands that can help you become more efficient in your work.

In conclusion, vi is a powerful text editor that can help you create and edit text files quickly and efficiently. By learning the basic vi commands, you can become more productive and efficient in your work. We hope that this cheat sheet will help you get started with vi commands and make your programming journey a little bit easier.

Cheat Sheet

NavigationhMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right
0Move cursor to beginning of line
$Move cursor to end of line
ggMove cursor to beginning of file
GMove cursor to end of file
EditingiInsert mode
aAppend mode
oInsert new line below cursor
OInsert new line above cursor
xDelete character under cursor
ddDelete line
yyCopy line
pPaste copied line
uUndo last change
Ctrl + rRedo last change
Search and Replace/patternSearch for pattern
?patternSearch backwards for pattern
nMove to next search result
NMove to previous search result
:%s/old/new/gReplace all occurrences of old with new
:%s/old/new/gcReplace all occurrences of old with new with confirmation
Saving and Quitting:wSave changes
:wqSave changes and quit
:q!Quit without saving changes
:wq!Save changes and quit forcefully
Modes:Command mode
iInsert mode
vVisual mode
EscReturn to command mode
Ctrl + vVisual block mode
:!Execute shell command
:set numberShow line numbers
:set nonumberHide line numbers