One of beautiful thing about vim
is that you can learn something even after using 5+ years. Even though usual vim learning curve characterized like below:
This is the command I've been looking for a long time. I accidentally saw it on one of the ThePrimeagen.
Entrée
Let's assume that I'm on the line 5 and want to update "_cache_update_cache"
on the line 30, to "_cache_update_current"
.
...
...
class UpdateCacheMiddleware(MiddlewareMixin):
"""
Response-phase cache middleware that updates the cache if the response is
cacheable.
Must be used as part of the two-part update/fetch cache middleware.
UpdateCacheMiddleware must be the first piece of middleware in MIDDLEWARE
so that it'll get called last during the response phase.
"""
def __init__(self, get_response):
super().__init__(get_response)
self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
self.page_timeout = None
self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
@property
def cache(self):
return caches[self.cache_alias]
def _should_update_cache(self, request, response):
return hasattr(request, "_cache_update_cache") and request._cache_update_cache
...
What I was doing: press 25jf"ci"
on Normal
mode, which means:
-
25j
: down 25 line -
f"
: find the first occurrence of"
-
ci"
: change inside of"
and then write _cache_update_current
.
The annoying part is you have to press additional f"
every time. For a normal user it probably means nothing, but for a vim
user it means a lot, since "Real Vim ninjas count every keystroke"1
Therefore I was using a macro
and key binding
for this. Until now.
Trick
The trick is just press ci"
; you don't have to press additional f"
(for an unknown reason it works which shouldn't). So our above command is just 25jci"
now.
And it works with usual text objects like {, [, *, '
etc.
All done!
Top comments (0)