search

Loading
Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Friday, July 12, 2013

How to save using vim editor with sudo privilege

Some times we will start editing the configuration files or the files which need root privilege in vi/vim and once we are about to save it, we will understand that we haven't edited it with sudo privilege.

It may be almost impossible to think quitting the editor without saving (:q!) and start it all over agin.

Friday, March 9, 2012

How to find the number of occurance of a character or word in a file

Some times we need to find how many times a character or a word has repeated in file. For this we can use vim. Vim is extremely powerful tool and learning some cool tricks in vim will always help you beat the heat.

So for example, i want to find how many times the word linux comes a file which is full words and lines. Imagine if the file has more than 1000 lines finding manually it will be just waste of time if you know the simple command in the vim.


We can use grep -c linux test.txt, but it will only show the number of lines where the word linux comes.
That's why we are using the vim and the below command.