Running vim command while opening files
November 19th, 2006 mysurface Posted in Text Manipulation, sed, vi, vim | Hits: 7293 |
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
/my-keyword
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”.
Live Chat!









Leave a Reply