Running vim command while opening files

November 19th, 2006 mysurface Posted in sed, Text Manipulation, vi, vim | Hits: 34791 | 3 Comments »

Refers back to Open file to edit with vim at desire line, here is another short tips of vim.

You can execute the vim command, while opening files with vim with option -c. While I wanna replace a string from a huge file, first I need to check whether I can do it with sed or not. That means my replace string must be unique, so that it won’t affect others line thatI might not want to replace.

The simple way is to use vim, open the file and search by specifying


and pressing “n” for next.

But you can do it while opening the file, it will open the file and consequently execute the command.

vim huge.txt -c "/my-keyword"

Search and replace can be done like this too,

sudo vim /etc/apt/sources.list -c ":%s/dapper/edgy/g" -c ":x"

instead of

sudo sed -e 's/dapper/edgy/g' -i /etc/apt/sources.list

P.S. “:x” is equivalent to “:wq”.

3 Responses to “Running vim command while opening files”

  1. Arsenal fans vs Man united Fans 2011 1-2 thats the best part we are waiting for in premier league dont you think so

  2. I’m still learning of your stuff, and im attempting to reach my personal objectives. We totally enjoy reading all thats written in your web website.Maintain the guidelines arriving. I loved it!

  3. reneolivierrepoeticbliss wordpress com tag sexual suppliant

Leave a Reply