Few advance vim commands

December 2, 2008 at 5:39 AM | Posted in Vim editor | 1 Comment

Few important line mode commands

1) :!<cmd_name> – run cmd_name command and return.

2) :1,4 w >> <file_name> – append line 1 to line 4 of current file to file_name

3) :sh – go to shell. To come back back to vi type exit.

.4) :sp - To create more than one view point of same file.

for another file

:sp <file_name>

5)To avoid lot of extra white spaces into code, run the following before pasting the data.

:set paste – Pasting from GUI.

6) :e! – read a current file, discarding changes

:!e <file_name> – Edit file file_name with in vi,

Compiling the code within vi and going to errors

1) !w first save the changes

2) : make to run the “make”

3) :cn go to next error

4) :cp go to previous error

Code folding (escape mode)

zf5j – To fold 5 lines

zfa} – To fold a code block marked by braces {}, put the cursor inside the block and type zfa}.

zo/zO open fold
zc/zC close fold

Multiple clipbords

In visual mode,

to copy type “ay or “by or “cy and for paste “ap “bp “cp etc.

Hyper-Linking to include files:

  • Place cursor over the file name (i.e. #include "fileABC.h")
  • Enter the letter combination: gf
    (go to file)

This will load file fileABC.h into vim.

Select and execute
Run command on selected lines only
:<range>g/<pattern>/<cmd>
runs command <cmd> on all lines in <range> where <pattern>
matches
g! or v works on NOT of above. That is execute <cmd> where
<pattern> doesnt match.

Hello world!

November 21, 2008 at 1:55 PM | Posted in Vim editor | 1 Comment

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.