A cheat sheet for VIM text editor

A cheat sheet for VIM text editor

If you're a programmer or someone who works with text files frequently, you might be familiar with Vim, a powerful and popular text editor. Vim can be intimidating at first, but once you learn some basic commands, it can greatly improve your productivity and efficiency.

To help you get started with Vim, we've put together a cheat sheet of some of the most useful commands. Feel free to print it out and keep it on your computer as a reference.

VIM CHEAT SHEET

Navigation:
h - move cursor left
j - move cursor down
k - move cursor up
l - move cursor right
0 - move to beginning of line
$ - move to end of line
gg - move to beginning of file
G - move to end of file
:n - move to line n
/word - search for 'word'
n - repeat last search
N - repeat last search in opposite direction
:%s/old/new/g - replace all occurrences of 'old' with 'new'

Editing:
i - insert before cursor
a - insert after cursor
A - insert at end of line
o - insert new line below cursor
O - insert new line above cursor
dd - delete line
dw - delete word
d$ - delete to end of line
d^ - delete to beginning of line
y - yank (copy) text
p - paste text after cursor
P - paste text before cursor
u - undo last change
Ctrl-r - redo last change

Modes:
Esc - command mode
i - insert mode
v - visual mode
V - visual line mode
Ctrl-v - visual block mode

Miscellaneous:
:w - save changes to file
:q - quit Vim
:q! - force quit Vim without saving changes
:wq - save changes and quit Vim
:set number - show line numbers
:set nonumber - hide line numbers
:help - open help menu

One of the most important things to remember when using Vim is that it has different modes. When you first open a file in Vim, you're in command mode, which allows you to move the cursor and execute commands. To enter insert mode, which allows you to add or edit text, press the 'i' key. To return to command mode, press the Esc key.

Visual mode allows you to select text by highlighting it with the cursor. Visual line mode selects entire lines, and visual block mode selects rectangular blocks of text.

To save changes to a file, use the ':w' command. To quit Vim, use ':q'. If you've made changes to a file and want to quit without saving, use ':q!'. To save changes and quit Vim, use ':wq'.

Finally, the ':help' command will open a help menu that provides information on all the available commands in Vim.

We hope this cheat sheet helps you get started with Vim and improves your productivity! If you have any questions or would like to suggest additional commands to include in the cheat sheet, please let us know in the comments.


PS: If you enjoyed this blog post and would like to support my work, please consider buying me a coffee by clicking on the following link: https://smartshock.hashnode.dev/sponsor Your donation will help me continue creating helpful content like this in the future. Thank you for your support!