Is there any way to make vim treat bash variables (anything prefixed with a $
, really) as distinct words? For instance, with the following lines:
"name $suffix.ext"
"name$suffix.ext"
with the cursor somewhere in $suffix
, the motion diw should leave me with "name .ext"
and "name.ext"
, respectively.
My primary reason for wanting this is to enable me to use some mappings I have for wrapping words in quotes/parens/etc with bash variables. I'm okay with changing the mapping as long as it still works with normal words, but I would prefer not to have to make this a syntax-specific mapping (but if there's no easy way around that, I can deal with it). (Here's one of the quote wrapping mappings I referenced: nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
)
Initially, I thought I could do this with set iskeyword
, but I could only make that work for cases such as name $suffix.ext
, and it then makes performance for name$suffix.ext
cases worse, in my opinion.
My other thoughts were along the lines of getting vim to recognize $
and [any word separator]
as either
- a matching pair (like
{
and}
( this seems like too much potential for bad side effects)) - or a "tag" (i.e., like html/xml tags that dit) recognizes (never messed with those, so I wasn't sure where to begin there)