Preliminary steps
Change $
from separator to quote
augroup mytargets
autocmd!
autocmd User targets#mappings#user call targets#mappings#extend({
\ '$':{'quote': [{'d': '\$'}]},
\ })
augroup END
I do not know how to make this change filetype-specific. If someone knows this, feel free to adjust this section
vimtex
user
Since the OP has added the tag plugin-vimtex
, I assume that the text objects i$
and a$
are defined by vimtex
. To have consistent experience you should unmap them to use i$
and a$
from targets.vim
. To do this add following lines to ~/vim/after/ftplugin/tex.vim
:
" Unmap vimtex versions of i$ and a$ to use versions of targets.vim:
xunmap <buffer> i$
ounmap <buffer> i$
xunmap <buffer> a$
ounmap <buffer> a$
Now we can combine:
z[
/z]
+ in$
,il$
, ...
To illustrate how this works, consider the line from the OP
We have two equations $<CURSOR>E=mc^2$ and $<JUMP HERE>F=ma$.
Return to normal mode when in the first equation and then press
z[in$
to jump at the beginning of the next equation and switch into insert mode.
You have many variations at your disposal:
z]
+ in$
jump to the end within the next equation
z]
+ il$
jump to the end within the previous equation
z]
+ 2in$
jump to the end within the 2nd next equation
- ...
Unfortunately, at the moment staying in normal mode is not supported by vim-ninja-feet
(see issue 3 'Make it work in Normal mode' on github).
Relevant excerpts from the docs:
vim-ninja-feet:
z[{motion} Enter |Insert| mode at the beginning of {motion}. For
|characterwise| motions, this is like pressing `i`;
for |linewise| motions, this is like pressing `O`.
z]{motion} Enter |Insert| mode at the end of {motion}. For
|characterwise| motions, this is like pressing `a`;
for |linewise| motions, this is like pressing `o`.
targets.vim
provides many text objects and many variations of them, please consult the webpage and the full documentation. I just add the beginning of the section about the quote text objects:
QUOTE TEXT OBJECTS *targets-quote-text-objects*
These text objects are similar to the built in text objects such as |i'|.
Supported trigger characters:
' (work on single quotes)
" (work on double quotes)
` (work on back ticks)
These quote text objects try to be smarter than the default ones. They count
the quotation marks from the beginning of the line to decide which of these
are the beginning of a quote and which ones are the end.
If you type `ci"` on the `,` in the example below, it will automatically skip
and change `world` instead of changing `,` between `hello` and `world`.
join("hello", "world") ~
└─────┘ └─────┘ proper quotes
└──┘ false quotes
Quote text objects work over multiple lines and support |targets-quote-seek|.
Following features of targets.vim are in particular relevant in this context:
/\$[^$]*\$
$ and $
, which is obviously not the desired jump target...lookahead
, I don't know vim-regex much, it didn't work.