Nasser Heidari

2009-02-08

VIM Editor

Filed under: Linux — Nasser Heidari @ 20:27

Moving around with cursor:
h key = LEFT, l key = RIGHT, k key = UP, j key = DOWN

e
Move to the end of a word.

w
Move forward to the beginning of a word.

3w
Move forward three words.

b
Move backward to the beginning of a word.

3b
Move backward three words.

$
Move to the end of the line.

0
Move to the beginning of the line.

^
Move to the first non-blank character of the line.

)
Jump forward one sentence.

(
Jump backward one sentence.

}
Jump forward one paragraph.

{
Jump backward one paragraph.

H
Jump to the top of the screen.

M
Jump to the middle of the screen.

L
Jump to the bottom of the screen.

10 or 10
Move 10 pages up.

5 or 5
Move 5 pages down.

G
Jump to end of file.

1G
Jump to beginning of file (same as gg).

50G
Jump to line 50.

‘m
Jump to the beginning of the line of mark m.

`m
Jump to the cursor position of mark m.


Return to the line where the cursor was before the latest jump.
(Two single quotes.)


Return to the cursor position before the latest jump (undo the jump).
(Two back ticks. This is above the Tab key on some keyboards.)

%
Jump to corresponding item, e.g. from an open brace to its matching closing brace.

Saving changes and exit:
in command mode :wq or SHIFT+zz

Inserting / appending text:
Press i or a in command mode and type

Exiting vim editor without saving:
press ESC to get into command mode, enter :q! to exit.

Deleting characters in vim command mode:
delete with x key

Deleting words:
delete word with d operator and w or e motion

Deleting to the end of the line:
delete to the end of the line with d operator and $ motion

Using operators, motions and counts:
beginning of the line 0, end of the line $, end of the 2nd word 2e beginning of the 4th word 4w

Deleting multiple words:
to delete 3 words you would use d3w

Deleting lines:
to delete single line dd, delete n lines ndd

Undo changes:
undo changes with u

Paste command:
paste your cache memory with p command

Replace characters:
rt replace current character with t

Change characters:
ce to change single word, c$ to change to the end of the line

Advanced Navigation:
end of the file G, beginning of the file gg or 1G, to get on line n use nG
instruct vim display file information CTRL+g

Search text with vim:
search forward /, search backward ?, next search n , previous search N

Vim Substitution :
first occurrence single line :s/bash/perl/
all occurrences single line :s/bash/perl/g
first occurrence between line range: :23,100s/bash/perl/
all occurrences between line range: :23,100s/bash/perl/g
first occurrence in whole text: :%s/bash/perl/
all occurrences whole text: :%s/bash/perl/g

Execute external commands on shell from vim:
:!ls will execute ls command on your shell

Writing to files advanced:
:w saves current file without quit, :w bash.sh whites to file bash.sh

Highlight text and save to different file:
highlight text with v operator and save it with :w <yourfile>

Retrieve text from different file:
:r <yourfile> will retrieve content of <yourfile> file

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

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: