How to delete the last word from each line in vim?

vim

Solution

Use the following regex (in ex mode):

%s/\s*\w\+\s*$//

This tells it to find optional whitespace, followed by one or more word characters, followed by optional whitespace, followed by end of line—then replace it with nothing.

Problem

Please let me know, How I can remove the last word from each line using vim commands? Before : ``` abcdef 123 xyz 1256 qwert 2 asdf 159 ``` after : ``` abcdef xyz qwert asdf ``` Similarly please let me know how to remove the second word from each line using vim command?

Original source

Related problems