Tip #479: Replace with NO Typing
tip karma |
Rating 0/14, Viewed by 2726
|
created: |
|
May 23, 2003 10:45 |
|
complexity: |
|
intermediate |
author: |
|
johnmaxa |
|
as of Vim: |
|
5.7 |
Often I replace one word with another. This is much faster than the substitute command and requires no typing.
For example, to change badName(...) to goodName(...) (with the mappings below):
1. Put the cursor anywhere on goodName and type: gy
2. Move the cursor to badName and type: gp
That's it!
If there are more than one badNames, type *N before typing go, then n gp to change the next one.
I mapped go to put a space after the word, but someone clever might be able to combine them.
Here is how I mapped the commands:
"replace word with register b WITH SPACE AFTER word
noremap go lb"bPldwi <Esc>hbye
"replace word with reg b WITHOUT SPACE after word
"(lb so no move to previous word, but gives error at end of line)
noremap gp lb"bPldwhbyw
"copy this word to register b for replacing with go and gp
noremap gy lb"bye
<<Copy the search results into clipboard |
editing files on an ftp server listening on a non-standard port >>
Additional Notes
|