-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jump to next/previos math zone #1810
Comments
This sounds like a good idea. I think a simple solution is to search for |
Glad you like it. If you can guide me, I can try to implement it and send a pull request. I have a little knowledge about vimscript. |
Alright, I saw how function! vimtex#motion#math(begin, backwards, visual) abort " {{{1
let l:count = v:count1
if a:visual
normal! gv
endif
" search either for $, $$, \[, \] or math environments like \begin{equation}\end{equation}
" Have to also figure out if give $ or $$ is the beginning of the math environment or the end.
let l:re = g:vimtex#re#not_comment . (a:begin ? '\$\{1,2}\|\\begin\s*\{' : '\$\{1,2}\|\\end\s*\{')
let l:flags = 'W' . (a:backwards ? 'b' : '')
for l:_ in range(l:count)
in_math_region = false
while not in_math_region then
in_math_region = check_math_region()
" get current position and check we are in a math region, implement this.
call search(l:re, l:flags)
endwhile
endfor
endfunction
Let me know what you think about it. |
I know they're not loved a lot, but you should add Anyway, awesome idea, thanks! |
Sorry, closed the issue by mistake.
Yes sure, I was not aware of it. Let @lervag have a look at it and then I will try to implement it. |
Some minor changes, still pseudocode: function! vimtex#motion#math(begin, backwards, visual) abort " {{{1
" Save cursor position first (and restore it on errors)
let l:curpos_saved = vimtex#pos#get_cursor()
let l:count = v:count1
if a:visual
normal! gv
endif
" Search for $, $$, \[, \(, \begin
" Use syntax to determine if we are inside math region
let l:re = g:vimtex#re#not_comment . '%(\${1,2}|\\\[|\\\(|\\begin\s*\{)'
let l:flags = 'W' . (a:backwards ? 'b' : '')
for l:_ in range(l:count)
" Ensure we are not going into infinite loop
let l:iter = 0
while l:iter <= 5
let l:iter += 1
call search(l:re, l:flags)
let l:pos = vimtex#pos#get_cursor()
if vimtex#syntax#in_mathzone(l:pos)
break
endif
endwhile
endfor
" Restore cursor position if fail
call vimtex#pos#set_cursor(l:curpos_saved)
endfunction Notes:
Let me know if you find the vimtex code/apis confusing, I'll be glad to help you make a PR for this! |
@lervag Thanks for the feedback. I have started working on it, and I will let you know if I need help. |
@lervag I have added the first version. Code here. What works:
What can be changed slightly:
What does not work:
Let me know what you think if it. |
Thanks to your notes, I have updated the code to take care of the |
Thanks! I very much appreciate the effort! It would be much easier for me to consider your code if you could open a pull request. Then we could 1) close this issue, 2) continue the discussions in the PR, and 3) do code review, suggestions and such "in the open". |
This issue is now solved from #1818. |
vimtex has mappings for jumping forward and backward to different elements like environments, comments etc. (
[m [/
and family). Would it be possible to have a similar mapping to jump to next math element?For example in the following text:
]n
(or any other keybinding) should go to$\alpha + \beta = \gamma$
, then$$e^{i\pi} + 1 = 0,$$
and then finally to theequation
environment.The text was updated successfully, but these errors were encountered: