Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove everything but the first column in VIM

Tags:

vim

editing

I have a text file and I want to remove every word except the first word on every line and I have no idea how to do this.

So, if I have:

one two three
four five
six

I want to remain with:

one
four
six

Got any ideas?

like image 876
Casteurr Avatar asked Dec 15 '12 10:12

Casteurr


People also ask

How do I delete a second column in Vim?

Start visual-block by Ctrl+v . Select second column (e.g. by pressing: W , G ). Delete it by pressing d .

How do I delete everything in Vim?

To delete all line you can use either the % symbol that represents all lines or the 1,$ range: Press the Esc key to go to normal mode. Type %d and hit Enter to delete all the lines.

How do you select all and delete all Vim?

Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it.


1 Answers

If the lines don't start with whitespace, you could replace ' .*' (which matches everything after the first word) with an empty string:

:%s/ .*//g
like image 200
l4mpi Avatar answered Oct 01 '22 06:10

l4mpi