Wikia

Vim Tips Wiki

Changes: Navigate to the next open fold

Edit

Back to page

(Move categories to tip template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 4: Line 4:
 
|previous=1193
 
|previous=1193
 
|next=1195
 
|next=1195
|created=April 3, 2006
+
|created=2006
 
|complexity=basic
 
|complexity=basic
 
|author=Ethan Mallove
 
|author=Ethan Mallove
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
I think it makes more sense for <tt>]z</tt> and <tt>[z</tt> to navigate to the next/previous open fold, so I added the following to my vimrc:
+
I think it makes more sense for <code>]z</code> and <code>[z</code> to navigate to the next/previous open fold, so I added the following to my vimrc:
   
 
<pre>
 
<pre>

Latest revision as of 06:12, July 13, 2012

Tip 1194 Printable Monobook Previous Next

created 2006 · complexity basic · author Ethan Mallove · version 6.0


I think it makes more sense for ]z and [z to navigate to the next/previous open fold, so I added the following to my vimrc:

function! GoToOpenFold(direction)
  let start = line('.')
  if (a:direction == "next")
    while (foldclosed(start) != -1)
      let start = start + 1
    endwhile
  else
    while (foldclosed(start) != -1)
      let start = start - 1
    endwhile
  endif
  call cursor(start, 0)
endfunction
nmap ]z :cal GoToOpenFold("next")
nmap [z :cal GoToOpenFold("prev")

CommentsEdit

Add the normal command "zj/zk" if you'd prefer to have the mapping jump out of the current open fold and into the next open fold.

" set ]z and [z go to find open folds
function! GoToOpenFold(direction)
  if (a:direction == "next")
    normal zj
    let start = line('.')
    while foldclosed(start) != -1
      let start = start + 1
    endwhile
  else
    normal zk
    let start = line('.')
    while foldclosed(start) != -1
      let start = start - 1
    endwhile
  endif
  call cursor(start, 0)
endfunction

Around Wikia's network

Random Wiki