Wikia

Vim Tips Wiki

Changes: Section jump in Latex

Edit

Back to page

(Remove html character entities)
(Merge the comment into the body of the tip)
Line 5: Line 5:
 
|created=June 19, 2003
 
|created=June 19, 2003
 
|complexity=basic
 
|complexity=basic
|author=Aditya Mahajan
+
|author=
|version=6.0
+
|version=
|rating=17/8
+
|rating=
 
|category1=LaTeX
 
|category1=LaTeX
 
|category2=
 
|category2=
 
}}
 
}}
This is a small mapping that can be used for jumping sections in a latex file (just like ]m and [m for Java methods).
+
This is a small mapping that can be used for jumping sections in a latex file.
   
map <silent> ]s :/\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
+
<pre>
map <silent> [s :?\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
+
map <silent> ]s :/\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
  +
map <silent> [s :?\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
  +
</pre>
   
==Comments==
+
The above commands don't work with a count. The following maps correctly work with a count and also update the pattern.
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.
+
Also, if you want to keep the original search pattern, just comment out the "let @/ = pat" line.
   
 
<pre>
 
<pre>
Line 33: Line 33:
 
endfunction
 
endfunction
 
</pre>
 
</pre>
 
----
 

Revision as of 04:09, November 28, 2011

Tip 489 Printable Monobook Previous Next

created June 19, 2003 · complexity basic · version 


This is a small mapping that can be used for jumping sections in a latex file.

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

The above commands don't work with a count. The following maps correctly work with a count and also update the pattern. Also, if you want to keep the original search pattern, just comment out the "let @/ = pat" line.

" 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

Around Wikia's network

Random Wiki