" Maps the % to jump back and forth indentations in Python, almost like jumping " between brackets in C and Java. " This might or might not work. " Antti Kuntsi for the ViM community " fun! MoveBackwards(linenum, delta) let linenum=a:linenum while (getline(linenum)=~"^\s*#") let linenum=linenum-a:delta endwhile return linenum endfun fun! FindIndentChange(delta) let linenum=nextnonblank(line(".")) let cind=indent(linenum) if (cind==-1) return -1 endif while indent(linenum)==cind let linenum=linenum+a:delta while nextnonblank(linenum)!=linenum || getline(linenum)=~"^\s*#" let linenum=linenum+a:delta if (linenum>=line("$")) return MoveBackwards(line("$"), a:delta) endif endwhile endwhile return MoveBackwards(linenum, a:delta) endfun fun! FindIndentReduce(delta) let linenum=nextnonblank(line(".")) let cind=indent(linenum) if (cind==-1) return -1 endif while indent(linenum)>=cind let linenum=linenum+a:delta while nextnonblank(linenum)!=linenum || getline(linenum)=~"^\s*#" let linenum=linenum+a:delta if (linenum>=line("$")) return MoveBackwards(line("$"), a:delta) endif endwhile endwhile return MoveBackwards(linenum-a:delta, a:delta) endfun fun! IndentJump() let change_line=FindIndentChange(1) if (change_line<0) return endif let changed_indent=indent(change_line) let new_line=line(".") let current_indent=indent(new_line) if (changed_indent>current_indent) let bytenmbr = line2byte(change_line) execute bytenmbr . "goto" let new_line=FindIndentReduce(1) else let new_line=FindIndentReduce(-1)-1 endif if (new_line<0) return endif let bytenmbr = line2byte(prevnonblank(new_line)) execute bytenmbr . "goto" execute "normal _" endfun au BufEnter *.py noremap % :call IndentJump() au BufLeave *.py unmap %