Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a specific Column in VIM/gvim with out using Visual Block mode

Tags:

vim

Sample Input File

+--------------------+---------+---------
|           Name     |   S1    |    S2
+--------------------+---------+---------
|           A        | -4.703  | -2.378  
|           B        | -3283.2 | -3204.5 
|           C        |  8779   |  7302   
|           D        |  22078  |  18018  
+--------------------+---------+---------

It is required to remove the S1 Column, i.e

Desired Output

+--------------------+---------
|           Name     |   S2    
+--------------------+---------
|           A        | -2.378    
|           B        | -3205.5  
|           C        |  7302      
|           D        |  18018    
+--------------------+---------

Can anyone help with this

thanks

like image 988
user1228191 Avatar asked May 09 '12 11:05

user1228191


1 Answers

Look, ma: no visual (block) mode !

My pragmatic approach wins would be: look for column anchors (-+-)

/-+-

Now, the column deletion is as simple as

d<C-v>N

(delete, block-wise, to the next occurrence of the column anchor from the end of the document).

Job done.


Fancy options

To account for multiple columns, you'd like to be precise about which column to match

This needs a little extra oomph

0f+
:exec '/\%' . col('.') . 'v\v[+|]'Enter
NC-vN
t+d

To see more about this \%22v way to select a virtual column, see

  • Support in vim for specific types of comments
like image 130
sehe Avatar answered Sep 24 '22 20:09

sehe