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)
<<how to avoid obliterating window layout |
Applying substitutes to a visual block >>
Additional Notes
|