Vim Tips Wiki
Register
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 13: Line 13:
 
When working with Python and other languages which do not use braces, it is useful to be able to jump to and from lines which have the same indentation as the line you are currently on. The following mappings in your [[vimrc]] will help:
 
When working with Python and other languages which do not use braces, it is useful to be able to jump to and from lines which have the same indentation as the line you are currently on. The following mappings in your [[vimrc]] will help:
 
<pre>
 
<pre>
βˆ’
nnoremap <M-,> :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%<' . line('.') . 'l\S', 'be')<CR>
+
nnoremap <M-,> k:call search('^'. matchstr(getline(line('.')+1), '\(\s*\)') .'\S', 'b')<CR>^
βˆ’
nnoremap <M-.> :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%>' . line('.') . 'l\S', 'e')<CR>
+
nnoremap <M-.> :call search('^'. matchstr(getline(line('.')), '\(\s*\)') .'\S')<CR>^
 
</pre>
 
</pre>
   
βˆ’
With these mappings, in normal mode, press <code>Alt-,</code> to find the previous line with the same indent as the current line, or press <code>Alt-.</code> to find the next such line. These mappings should work in gvim, but you may need to choose different keys if working with Vim in a terminal.
+
With these mappings, in normal mode, press Alt-<code><</code> to find the previous line with the same indent as the current line, or press Alt-<code>></code> to find the next such line. These mappings should work in gvim, but you may need to choose different keys if working with Vim in a terminal.
   
 
----
 
----
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)