Trying to remove the first column of a document.

12,158

Solution 1

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.

Solution 2

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.

Solution 3

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//
Share:
12,158
ziiweb
Author by

ziiweb

Ziiweb is a web agency on creating websites and web applications. We also offer marketing online services (SEO/PPC) to promote your business through search engines and social networks. We always bet for the last and best web technologies: HTML5, CSS3, jQuery, PHP5 and symfony (all releases).

Updated on August 24, 2022

Comments

  • ziiweb
    ziiweb over 1 year

    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?

  • akira
    akira about 13 years
    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 .. :)
  • Warren Rumak
    Warren Rumak over 8 years
    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.
  • z atef
    z atef over 5 years
    %s/^[^\t]*\t// worked fro me. It deleted the first column in a tab-del-file.