Showing posts with label Vim editor. Show all posts
Showing posts with label Vim editor. Show all posts

Sunday, January 13, 2013

22 - Comment out all line in the file at once with vim editor

If you want to comment out all (some) lines in your file, you can use the following recipe:

1. press ctrl+v  and select the lines
2. press I for all highlighted lines
3. type # (for shell script) of ! (for .f90 files)
4. press Esc
5. press Esc

Sunday, August 26, 2012

15 - Line by line comparing of two files

If you want to check two different files line by line, you can use the following command:

>  vimdiff  file1   file2

In this way, in vim editor, you can see different colors (pink and red) if these two files are different.
The red color tells you that these files are different in that line.

Sunday, September 4, 2011

6. Delete columns in a file via vim editor

For instans in a special file, you have lots of data which have been sorted by columns like this:

1     2     3     4
5     6     7     8
9    10   11   12
13  14   15   16

Now, we want to keep first and second columns and delete the rest ones.
To do this
1. press Ctrl+v (virtual block mod)
2. press G (to go to the end of the file)
3. press d (to delete highlighted columns)

5. Sum useful commands in vim editor:


Where grep came from (RE being Regular Expression):
:g/RE/p

Delete lines 10 to 20 inclusive:
:10,20d
or with marks a and b:
:'a,'bd

Delete lines that contain pattern:
:g/pattern/d

Delete all empty lines:
:g/^$/d

Delete lines in range that contain pattern:
:20,30/pattern/d
or with marks a and b:
:'a,'b/pattern/d

Substitute all lines for first occurance of pattern:
:%s/pattern/new/
:1,$s/pattern/new/

Substitute all lines for pattern globally (more than once on the line):
:%s/pattern/new/g
:1,$s/pattern/new/g

Find all lines containing pattern and then append -new to the end of each line:
:%s/\(.*pattern.*\)/\1-new/g

Substitute range:
:20,30s/pattern/new/g
with marks a and b:
:'a,'bs/pattern/new/g



More info can be found in these "website1" and "website2".