Vim is an open source text editor that runs on Linux, MacOSX, Windows and many other operating systems. If I had to describe it in just one word, then the first thing I can think of would be “powerful”. Vim supports syntax highlighting for really almost any format and has got many other extras.
But “powerful” also describes the learning curve, because Vim can be fully controlled via the keyboard. There are tons of commands and shortcuts you can learn. But however, if you once learned how to handle Vim it is a wonderful tool. Just the fact that Vim can actually be found on nearly any Linux system, no matter where and under what distribution you are currently working, is a good reason to learn at least the basics of how to operate Vim. Therefore I wrote this mini-reference for Vim with the most necessary commands to start off using Vim.
Vim – the basics
Vim can be started with the command “vi” or “vim”. If you want to open a file, write it’s name simple behind the vim command.
When Vim has started, you are in normal mode. There are three modes in Vim: normal mode, insert mode and command mode. If you want to write “freely”, like you’re used to with other text editors, you have to switch to insert mode. Nevertheless the normal mode also allows special operations for editing the file.
i – switch to insert mode
Shift+a – moves the cursor to the end of the line and switches into insert mode
Esc – leave insert mode
x – deletes the character under the cursor
r + any character – replace the character under the cursor with the given character
d d – deletes the current line
Shift+g – moves the cursor to the end of file
[key]:[/key] – opens the command mode (hereinafter directly integrated in the instructions)
:w – saves the file
:sav filename.extension- saves the file under the name filename.extension
:q – quits Vim
:q! – closes Vim also if changes have not been saved
:wq – saves the file and then closes Vim
Tipps & Tricks
copy & pastev – changes to the visual mode
Move the cursor to select the desired area.
y – copies marked area
Use the cursor to select the point where you want to insert the copied text
p – pastes copied text
cut & paste
Cut and paste works almost like copying and pasting.
Just use d instead of y if you want to cut instead of copy
Help / Command overview
:help – displays the Vim help including many commands
:q – closes the Vim help