sponsor Vim development Vim logo Vim Book Ad

basic Tip #62: Applying substitutes to a visual block

 tip karma   Rating 8/4, Viewed by 1599 

created:   March 28, 2001 8:22      complexity:   basic
author:   Chip Campbell      as of Vim:   5.7

If you'd like to apply a substitute, or even any ex command, to a visual-block
selected text region (ctrl-v and move), then you'll want Stefan Roemer's
http://www.erols.com/astronaut/vim/vimscript/vis.vim .  Just source it in,
and then press ":B".  On the command line you'll see

:'<,'>BCtrl-V

Just continue with the substitute or whatever...

:'<,'>B s/abc/ABC/g

and the substitute will be applied to just that block of text!

Example: Ctrl-V Select..........|......Type
..................just the central....|......:B s/abc/ABC/g
..................four "abc"s..............|
..................----------------....|...-------------
..................abcabcabcabc............|......abcabcabcabc
..................abcabcabcabc............|......abcABCABCabc
..................abcabcabcabc............|......abcABCABCabc
..................abcabcabcabc............|......abcabcabcabc
(dots inserted to retain tabular format)

 rate this tip  Life Changing Helpful Unfulfilling 

<<how to avoid obliterating window layout | Applying substitutes to a visual block >>

Additional Notes

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
    stats
Sponsored by Web Concept Group Inc. SourceForge.net Logo