Homepage › Forums › Articles › Operating Systems › Linux › VIM Editor-Part III
Tagged: vim
This topic was published by Saptarshi Nag and viewed 1963 times since "". The last page revision was "".
- AuthorPosts
Continuing from previous lessons....
Replacement Commands:-
Sometimes it's need to replace a particular word with another text in a file.It can be made "globally" or "specifically",the respective terms are better understood in the following example:
Suppose there is a text:
[code]Hello guys,this is Saptarshi Nag
I want to say you "hello world"[/code]
Now one wants to replace "hello" with "hi" globally,that is it will be-
[code]Hi guys,this is Saptarshi Nag
I want to say you "hi world"[/code]
Again one wants to replace the only one "hello" with "hi" like this
[code]Hi guys,this is Saptarshi Nag
I want to say you "hello world"[/code]
Now both are possible through last line mode.
For global replacement type the following in last-line mode:
[code]%s/text/replacement/g[/code] [g stands for global]
So in the first example it will be:
[code]%s/hello/hi/g[/code]
But for specific replacement,we have to use the following:
[code]%s/text/replacement/gc[/code] [gc stands for global with confirmation]
Here for every replacement system wants to know if user wants to replace text or not.If yes,press 'y' else 'n'.
Therefore the second example can be done with:
[code]%s/hello/hi/gc[/code]
Now apply it yourself
Check out DCJTech's official Facebook page - https://dcjtech.info/members/saptarshi/
- AuthorPosts