How do I delete first word of each line in Vim?
How about a pattern on each line?
:%s,^[^ ]*,,
From the beginning of the line match anything, but not a space and replace with none.
I would use something like the following:
:%s/^\w+\s+//
The regular expression will match one or more "word" characters starting at the beginning of the line followed by at least one whitespace character. It will remove the word and any following whitespace. If a line can contain only a single word -- and you still want it removed -- you could use alternation to match either whitespace or the end of line.
:%s/^\w+(\s+|$)//
First word (where word is defined as no whitespace)
:%s/^\s*[^ ]* //g
Delete pattern:
:%s/< insert pattern here >//g
:normal to the rescue:
:%norm dw
It basically replays the arguments as if you were typing them in normal ('non-edit') mode.
From :help :
:norm[al][!] {commands}
Execute Normal mode commands {commands}.
This makes it possible to execute Normal mode commands typed on the command-line. {commands} is executed like it is typed.
What about this?
:%!cut -s -d' ' -f2-
Although this is an old question, if someone else is looking to do this you could do use visual block.
- press ctrl+v
- select all the lines you would want to edit
- now use arrow keys to select the entire word
- press 'x'
That would delete the first word in all the lines. This method is especially very handy to edit log files