I'm using the a"
motion rather often in vim; e.g. using ca"
while refactoring a piece of code to replace a hardcoded argument with a variable name. The problem with this approach is that a"
includes leading whitespace if there is no trailing whitespace:
Any trailing white space is included, unless there is none, then leading white space is included.
Thus, when I edit a function call like this:
aFunction(arg1, "toBeReplaced", arg3) #original
aFunction(arg1, replacedArg, arg3) #refactored
I have to manually re-insert the space before replacedArg
as ca"
deletes it.
Is there any similar motion that does not include this white space, or is there anything else I can use instead of ca"
that saves me from having to type an extra space?
Notes:
cf"
does what I want as long as the string doesn't contain any escaped quotes, but requires me to have the cursor at the beginning of the string. I'd like something I can use from anywhere within the string, and?"<Enter>cf"
is rather awkward to type.- It's less about the single
<Space>
keystroke and more about the fact that I often initially forget to include the space, costing me at least four extra keystrokes (bi<Space><Esc>
) and breaking my focus. Thus the length of the replacement command is not as important, as long as it deletes only the text between the given chars and then enters insert mode.
?"<Enter>
to search for a quote backward on a line, you can useF"
.F
is the same asf
but searches to the left. The answers below look better for your question, butF
is a useful command on its own.