3

I'm using this command below to remove the first column of a document:

%s/^[^\t]*\zs\t[^\t]*\ze//g 

but it says command not found. Any idea?

Braiam
  • 1
  • 11
  • 47
  • 78
tirenweb
  • 30,963
  • 73
  • 183
  • 303

4 Answers4

14

Here's the quickest way to remove the first column:

  1. Press gg to go to the first character in the document.
  2. Hit Ctrl+V to enter visual block mode.
  3. Hit G (that is, shift-g) to go to the end of the document
  4. Hit x to delete the first column.
Peter
  • 127,331
  • 53
  • 180
  • 211
  • har, i posted that on SU (see cross post) .. but then deleted it because it is unclear if the first char already makes the first column .. :) – akira Feb 05 '11 at 11:47
  • This seems to delete the column with the first character, not necessarily the first column. If you want to delete a column of whitespace, for example, this won't work. – rcreswick Aug 31 '15 at 17:59
4

I like the block selection solution of @Peter, but if you want to use substitution you need this command:

:%s/^.//

Let's analyze why this works:

  • :%s exec a substitution on all the document
  • /^./ select the first character after the start of the line
  • / and replace it with... nothing.
Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54
1

If I understand you correctly, this should do the job:

:%s/^[^\t]//

The command removes all leading characters that are not a tabulator.

Alternatively, if you're editing a tabulator separated values document and want to remove all "columns" before the first tabulator, then this should do it for you:

%s/^[^\t]*\t//
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
0

The below command worked for me:

:%s/^\w*// 
ugo
  • 2,705
  • 2
  • 30
  • 34
acheng
  • 1
  • 1