sponsor Vim development Vim logo Vim Book Ad

basic Tip #489: Section jump in Latex

 tip karma   Rating 13/7, Viewed by 830 

created:   June 19, 2003 12:51      complexity:   basic
author:   Aditya Mahajan      as of Vim:   6.0

This is a small mapping that can be used for jumping sections in a latex file (just like ]m and [m for Java methods)

map <silent> ]s :/\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
map <silent> [s :?\\\(sub\)\{,2}section\s*{<CR> :noh<CR>

I want to extend it to recognize something like 2]s to move two sections forward. How to do it.

Aditya

 rate this tip  Life Changing Helpful Unfulfilling 

<<vimrc setting for wider vim diff window (gVim) | Paste vim registers in search or colon command-line instead of using the system clipboard >>

Additional Notes

juhas at seas.upenn.edu, June 19, 2003 14:17
Here is an excerpt from my tex ftplugin, where section jumping works with
count.  The search() function is used rather than // command to avoid the
wrap-arounds and end-of-file messages.  Also, if you want to keep the
original search pattern, just comment out the "let @/ = pat" line.
Hope this helps,
Pavol



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" section jumping
noremap <buffer> <silent> ]] :<c-u>call TexJump2Section( v:count1, '' )<cr>
noremap <buffer> <silent> [[ :<c-u>call TexJump2Section( v:count1, 'b' )<cr>
function! TexJump2Section( cnt, dir )
    let i = 0
    let pat = '^\\\(part\|chapter\|\(sub\)*section\|paragraph\)\>\|\%$\|\%^'
    let flags = 'W' . a:dir
    while  i < a:cnt && search( pat, flags ) > 0
        let i = i+1
    endwhile
    let @/ = pat
endfunction
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo