keyboard shortcuts - Vim: refined paragraph jumping for tex files -
i'd change behaviour of { , } in vim tex files.
in tex files paragraphs typically separated 1 or more blank lines.
the cursor should placed nroff macros (e.g. .sh) on first line of paragraph not on separating blank line. afaik, adjusting :set paragraphs not allow (see here).
noteworthy corner cases be: \indent, \noindent, \paragraph{}, \subparagraph{} , more. unfortunately, comprehensive solution complicated, see https://tex.stackexchange.com/q/13085/in-how-many-ways-can-you-create-a-paragraph-in-latex.
but don't need this. when use \paragraph{} add blank line before it.
so question should limited blank lines , placing cursor on next non-blank line.
remarks:
- mappings should not touch search history.
jumplistshould modified (same behaviour{,}).
this question motivated plugin limelight.vim junegunn.
one way be:
nnoremap g} :call search('^$\n\s*\zs\s')<cr> nnoremap g{ :call search('^$\n\s*\zs\s', 'b')<cr> remaining issues:
- an improvement treat closed folds (e.g. folded sections plugin
vimtex) single paragraph. - respect
'foldopen'setting block (same behaviour{,})
resolves first issue well. - it not possible go beginning of file.
improved mappings
nnoremap <silent> g} \ :let old = @/ \ <bar>/^$\n\s*\zs\s<cr> \ <bar>:nohlsearch \ <bar>call histdel('/', -1) \ <bar>let @/ = old<cr> nnoremap <silent> g{ \ :let old = @/ \ <bar>?\(^$\n\s*\zs\s\)\<bar>\%^<cr> \ <bar>:nohlsearch \ <bar>call histdel('/', -1) \ <bar>let @/ = old<cr> - do not pollute search history
- by setting
:set 'foldopen'containingblock,search(default anyway) same behaviour{,}regarding folds jumplistmodified: usingctrl-i,ctrl-ocycles through these well. (:h jumplist)- allows going beginning of file
remaining issues ii:
hlsearchswitched off. if user wants keep current search , wants see them highlighted, mapping must improved further. flickering occur.
notes
- allows jumping first paragraph last
g{, last firstg}(not same behaviour{,}) dg}not work (operator +g}/g{). in case preferd}anyway.
Comments
Post a Comment