tags:

views:

389

answers:

5

How can you run AWK in Vim's selection of the search?

My pseudo-code

%s/!awk '{ print $2 }'//d

I am trying to delete the given column in the file.

+1  A: 

if you want to delete something, use :%s/pattern//

pattern can't be a command, it's mostly a regular expression. expressing 2nd field in regular expression is not very easy

if you want to delete 2nd field, you can filter the text through cut utility

:%! cut -d ' ' -f 2 --complement
mykhal
A: 

you could press "0", then press "w" to go to your 2nd column, and do "cw".

+2  A: 

In command mode, press Ctrl-v to go into visual mode, then you can block-select the column using cursor movement keys. You can then yank and put it or delete it or whatever you need using the appropriate vim commands and keystrokes.

Dennis Williamson
This is a great command which I tend to easily forget
Masi
+2  A: 

You do not have to use awk, even if the second column is not a rectangular region. Use a substitution:

:%s/ \w\+ / /

The second column is made up of at least one from word characters (\w\+) separated by blanks. The replacement is one blank. This one is for a selected range of lines:

:'<,'>s/ \w\+ / /
fgm
A: 

You can delete a given column in a file just from vim. In command mode use the following to delete column n:

:%s/\(.\{n-1}\).\{1}\(.*$\)/\1\2/g
skeept