I often want to perform a search on a phrase that does not conform to word boundaries, change the matched text and repeat over a buffer.
really_long_var_name = 'bar'
...
if (really_long_var_name == 'bar')
end
Let’s change really_long_var_name
to shorter_var_name
I’d like to search for really_long
, do something like ciw shorter
on the first result, and then hit n.
to repeat the action on future matches. Unfortunately ciw
doesn’t work because w
captures the entire really_long_var_name
rather than just the part we want to change. The most obvious solution is a bit cumbersome: :s/really_long/shorter/gc
. Let’s see about writing a vimscript for cir
(or maybe &?) or change in result
.
Solution: use this snippet to turn the search result into a text object referred to by “s”. Now cs
becomes “change selection” and is repeatable with commands like n.
as in “Move to next result and repeat the previous command”
- Via an add-on
- Although I didn’t install the add-on. Instead I will try the keystroke to show/hide the bookmarks sidebar
Command b
.
- Fastest Search Add-on
- I’m a little wary of willy-nilly installing add-ons so I’m going to punt on this for now.
- For each of these topics I’d like a unique anchor such as
[Vim: do something faster](/2014-05-16-environment-improvements-2#vim-do-something-faster)
.
- The anchor is based on the link body so I want to be able to create the the anchor by writing this:
[Vim: do something interesting](/2014-05-16-environment-improvements-2#fn-infer)
-
- Then I preprocess the markdown file with a simple script.
-