Vim Tips Wiki
(Corrected Formatting)
(allow for jumping to indented sections)
Tag: Visual edit
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{Tip
 
 
|id=489
 
|id=489
  +
|previous=488
|title=Section jump in Latex
 
  +
|next=490
|created=June 19, 2003 12:51
+
|created=June 19, 2003
 
|complexity=basic
 
|complexity=basic
|author=Aditya Mahajan
+
|author=
|version=6.0
+
|version=
|rating=17/8
+
|rating=
  +
|category1=LaTeX
|text=
 
  +
|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)
 
 
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
 
 
}}
 
}}
 
This is a small mapping that can be used for jumping sections in a latex file.
   
  +
<pre>
== Comments ==
 
 
map <silent> ]s :/\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
Here is an excerpt from my tex ftplugin, where section jumping works with
 
 
map <silent> [s :?\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
count. The search() function is used rather than // command to avoid the
 
  +
</pre>
wrap-arounds and end-of-file messages. Also, if you want to keep the
 
original search pattern, just comment out the "let --AT--/ = pat" line.
 
Hope this helps,
 
Pavol
 
 
 
 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
" section jumping
 
noremap &lt;buffer&gt; &lt;silent&gt; ]] :&lt;c-u&gt;call TexJump2Section( v:count1, '' )&lt;cr&gt;
 
noremap &lt;buffer&gt; &lt;silent&gt; [[ :&lt;c-u&gt;call TexJump2Section( v:count1, 'b' )&lt;cr&gt;
 
function! TexJump2Section( cnt, dir )
 
let i = 0
 
let pat = '^\\\(part\|chapter\|\(sub\)*section\|paragraph\)\&gt;\|\%$\|\%^'
 
let flags = 'W' . a:dir
 
while i &lt; a:cnt &amp;&amp; search( pat, flags ) &gt; 0
 
let i = i+1
 
endwhile
 
let --AT--/ = pat
 
endfunction
 
   
  +
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.
   
  +
<pre>
juhas--AT--seas.upenn.edu
 
 
" section jumping
, June 19, 2003 14:17
 
 
noremap <buffer> <silent> ]] :<c-u>call TexJump2Section( v:count1, '' )<CR>
----
 
 
noremap <buffer> <silent> [[ :<c-u>call TexJump2Section( v:count1, 'b' )<CR>
<!-- parsed by vimtips.py in 0.479892 seconds-->
 
 
function! TexJump2Section( cnt, dir )
 
let i = 0
 
let pat = '^\s*\\\(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
  +
</pre>

Latest revision as of 10:56, 30 June 2014

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 = '^\s*\\\(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