Vim - delete everything between tabs

I have a data delimited file. I need to remove 2 columns. So, what commands can I use to remove everything from the current tab to the next tab?

+3
source share
5 answers

To remove columns 4 and 5:

:%s/^\(.\{-}\t\)\{3}\zs.\{-}\t.\{-}\t//

Explanation:

^  => start of line

.\{โˆ’} => as few characters as possible
\( .\{-}\t \)\{3} => three times as few characters as possible followed with a tab

\zs => start of match

With a switch it \vmight be clearer:

:%s/\v^(.{-}\t){3}\zs.{-}\t.{-}\t//
+5
source

I think shift + ctrl + v is what you are looking for.

http://jvi.sourceforge.net/javahelpset/jvi-vis_block.html

+3
source

vim? unix, cut. , , 4- ( 2 3)

cat filename | cut -d"\t" -f1,4- > outputfile
+2

, f t : , d2f<Tab>, . , d2/<Tab>/e<CR> ( d2/\t/e<CR>) , . , : qaqqa01f<Tab>d2t<Tab>j@aq@a:

  • qaq: clear a register ( , a, , - );
  • qa: a;
  • 0: ;
  • 1f<Tab>: Go to the next tab. 1can be omitted here. If you want to delete the first column, omit all movement;
  • d2t<Tab>: delete the second next tab;
  • j: go to the next line;
  • @a: run the macros stored in the register a. It is empty at this moment (because it was cleaned in the 1st paragraph), therefore, nothing was actually done;
  • q: stop recording macros;
  • @a: run the macros stored in the register a. It contains paragraphs 3.-7. and in the 7th element it will work itself.
+2
source
:%s:\t[^\t]\+\t:\t\t:

This removes everything between the two tabs.

NTN

+1
source

Source: https://habr.com/ru/post/1796323/


All Articles