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.
  • jumplist should 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' containing block , search (default anyway) same behaviour { , } regarding folds
  • jumplist modified: using ctrl-i , ctrl-o cycles through these well. (:h jumplist)
  • allows going beginning of file

remaining issues ii:

  • hlsearch switched 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 first g} (not same behaviour { , })
  • dg} not work (operator + g}/g{). in case prefer d} anyway.

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -