vim vim vim vim vim hacks text substitution useful :

 Search:
1)/searchtext
2)/\csearchtext                     ;for-case insensitive search

Also, \c can appear anywhere in the pattern, so if you type a pattern and then decide you wanted a case-insensitive search, just add a   \c   at the end.




You can set the ic option in Vim before the search:
:set ic
To go back to case-sensitive searches use:
:set noic
ic is shorthand for ignorecase

Substitute all occurrences of a text with another text in the whole file==
Syntax of the text substitution inside vim editor:

:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
--------------------------------------------------------
:%s/old-text/new-text/g

Following are three possible flags.

    [c] =Confirm each substitution.
    [g] =Replace all occurrences in the line.
    [i] =Ignore case for the pattern.
-----------------------------------------------------
her her Hiss iHis
her her is good
mood is her her odis
His
try cry fry fryedHis
-------------------------
:4s/\<His\>/test/g
---------output----------

her her Hiss iHis
her her is good
mood is her her odis
test
try cry fry fryedHis

:2,19s/\<test1\>/mountain/g

=====================================
her her Hiss iHis
her her is good
mood is her her odis
test
try cry fry fryedHis
~                                                                                                                        
:1,5s/\<her\>/nepal/g

Output>>
nepal nepal Hiss iHis
nepal nepal is good
mood is nepal nepal odis
test
try cry fry fryedHis
~
~
6 substitutions on 3 lines

No comments:

Post a Comment