Best VIM Editor Advanced Tips Linux

VIM EDITOR Advanced Tips Linux

 

Open multiple files in a single window:

Enter into Execution mode by pressing keys “SHIFT+:

:vsp  <GIVE THE FULLPATH OF FILE YOU WANT TO OPEN>

 

To Delete the entire content of a file opened using VI Editor:

Enter into Execution mode by pressing keys “SHIFT+:

:%d
OR

:1,$d

To delete content on the right side of the cursor in present line:

 d$

To delete the content on the left side of the cursor i.e, to beginning  in present line:

:d0
[d(ZERO)]

To delete the content from the right side of the cursor to end of file:

:dG

To delete all the lines above the present line:

Enter into Execution mode by pressing keys “SHIFT+:

:1,.d

Open Multiple Files using VI Editor:

vi -o file1 file2 file3

vi -p file1 file2 file3 [This is opens files in tabs]

for switching between files use the following:

Ctrl+w OR

:bf            # Go to first file.
:bl            # Go to last file
:bn            # Go to next file.
:bp            # Go to previous file.
:bw            # Close file.

Delete first n characters in a  file

:%s/^.\{n}/

Substitute n with number of characters you want to delete.

Comment all lines that match a particular string

:g/pattern/s/^/#

Assuming “#” is used for commenting the lines, you can change if it is different for you.

Open a file into a particular line

vi +n file

Replace “n” with line number

Will add more tips in future ….

Advertisements

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