Vim Cheat Sheet

Linux is a great OS and ships with a lot of text editors. But in my opinion one of them is special, VIM. If you use VIM for the first time, it’ll be very annoying because there are so much keys and little tricks you have to know. I use VIM for about one and a half year and I still have to search for some keys and little tricks. So I decided to make a little cheat sheet. I will update this cheat sheet from time to time.

Change modus
Undo and Redo
Movement
Copy, Paste and delete
Search and Replace
Tabs
Marks
Abbreviations
More features

Change Modus:

Command     Modus     Action
------------------------------------------------------
<ESC>       Input     Change to command mode
i           Command   Change to input mode

Undo and Redo:

Command     Modus     Action
------------------------------------------------------
<Ctrl>r     Command   Redo
u           Command   Undo

Movement:

Command     Modus     Action
------------------------------------------------------
gg          Command   Go to the top of file (1st line)
#gg         Command   Go to line #
GG          Command   Go to the end of file (last line)
^           Command   Go to the beginning of line
$           Command   Go to the end of the line

Copy, Paste and delete:

Command     Modus     Action
------------------------------------------------------
yy          Command   Copy current line
y$          Command   Copy the rest of the line
                      (character under cursor included)
dd          Command   Cut current line
d$          Command   Cut the rest of the line
                      (character under cursor included)
#dd         Command   Cut # lines (replace # with any number)

r           Command   Replace character under cursor
x           Command   Delete character under cursor

p           Command   Paste the content of the buffer to the
                      right of the cursor
P           Command   Paste the content of the buffer to the
                      left of the cursor

Search and Replace:

Command           Modus    Action
------------------------------------------------------
/STRING           Command  Search forward for STRING
?STRING           Command  Search backwards for STRING
:L1,L2 s/s1/s2/g  Command  Replace every s1 with s2
                           from line L1 up to line L2

Tabs:

Command         Modus    Action
------------------------------------------------------
:tabnew <file>  Command  open <file> in new tab
gt              Command  goto next tab (to the right)
gT              Command  goto previous tab (to the left)
:q              Command  close current tab
:tabmove #      Command  move current tab to position #
                         (first tab is 0)

Marks:

Command         Modus    Action
------------------------------------------------------
:marks          Command  list all marks
:delmarks a     Command  delete mark a
ma              Command  set mark a at current cursor position
'a              Command  jump to line of mark a 
                         (first non-blank character in line)

Abbreviations:

Command                     Modus    Action
------------------------------------------------------
:ab                         Command  list all abbreviations
:ab afk away from keyboard  Command  replaces each afk with
                                     away from keyboard
:abc                        Command  delete all abbreviations
:abclear                    Command  delete all abbreviations

More features:

Show differences of two or more files (diff):
You can use vimdiff or gvimdiff to display the differences of files

$ vimdiff file1 file2 [file 3]
Advertisements

Posted on September 4, 2013, in Cheat Sheet and tagged , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: