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
Theme | Command | Description |
Navigation | h | Move cursor left |
j | Move cursor down | |
k | Move cursor up | |
l | Move cursor right | |
0 | Move cursor to beginning of line | |
$ | Move cursor to end of line | |
gg | Move cursor to beginning of file | |
G | Move cursor to end of file | |
Editing | i | Insert mode |
a | Append mode | |
o | Insert new line below cursor | |
O | Insert new line above cursor | |
x | Delete character under cursor | |
dd | Delete line | |
yy | Copy line | |
p | Paste copied line | |
u | Undo last change | |
Ctrl + r | Redo last change | |
Search and Replace | /pattern | Search for pattern |
?pattern | Search backwards for pattern | |
n | Move to next search result | |
N | Move to previous search result | |
:%s/old/new/g | Replace all occurrences of old with new | |
:%s/old/new/gc | Replace all occurrences of old with new with confirmation | |
Saving and Quitting | :w | Save changes |
:wq | Save changes and quit | |
:q | Quit | |
:q! | Quit without saving changes | |
:wq! | Save changes and quit forcefully | |
Modes | : | Command mode |
i | Insert mode | |
v | Visual mode | |
Esc | Return to command mode | |
Ctrl + v | Visual block mode | |
:! | Execute shell command | |
:set number | Show line numbers | |
:set nonumber | Hide line numbers |