Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0a1d4e
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
This is a mirror of http://www.vim.org/scripts/script.php?script_id=3724 | ||
|
||
indent-motion is a Vim plugin which maps `<Leader>[` and `<Leader>]` in normal, visual, and operator-pending modes to move to the beginning and end (respectively) of your current indentation-delimited block (`<Leader>` refers to your current user-defined "mapleader", which is `\` by default). | ||
|
||
For example (using JavaScript): | ||
|
||
function foo(a, b, c) { | ||
var x = 1; | ||
var y = 2; | ||
if (x == y) { | ||
alert("This will never happen!"); | ||
++y; | ||
} | ||
} | ||
|
||
In the above snippet, if the cursor is positioned on the `var x = 1;` line, then `<Leader>]` will move the cursor to the next-to-last line (closing brace of the conditional block) and `<Leader>[` will move it back to the original location. If the cursor is positioned on the `alert` call, then `<Leader>]` will move down 1 line to `++y;`. | ||
|
||
If one of the mappings is executed on an empty line (containing no characters, not even whitespace), then the assumed indentation will be that of the next non-empty line, where "next" is in the direction of the requested motion. | ||
|
||
Currently, the mappings are not configurable, but this can easily be changed upon request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function! s:next_line(l, up) | ||
let nl = a:l + (a:up ? -1 : 1) | ||
if nl < 1 || nl > line('$') | ||
throw 'buf_bound' | ||
endif | ||
return nl | ||
endfunction | ||
|
||
function! <SID>to_indent_end(up, vis) | ||
|
||
let ln = line('.') | ||
if indent(ln) == 0 && getline(ln) =~ '^$' | ||
while getline(ln) =~ '^$' | ||
try | ||
let ln = s:next_line(ln, a:up) | ||
catch 'buf_bound' | ||
break | ||
endtry | ||
endwhile | ||
endif | ||
let orig_ind = indent(ln) | ||
try | ||
let ln = s:next_line(line('.'), a:up) | ||
catch 'buf_bound' | ||
return | ||
endtry | ||
if a:vis | ||
normal! gv | ||
endif | ||
while indent(ln) >= orig_ind || getline(ln) =~ '^$' | ||
execute 'normal! ' . (a:up ? 'k' : 'j') | ||
try | ||
let ln = s:next_line(ln, a:up) | ||
catch 'buf_bound' | ||
return | ||
endtry | ||
endwhile | ||
|
||
endfunction | ||
|
||
nnoremap <silent> <Leader>] :call <SID>to_indent_end(0, 0)<CR> | ||
nnoremap <silent> <Leader>[ :call <SID>to_indent_end(1, 0)<CR> | ||
onoremap <silent> <Leader>] :call <SID>to_indent_end(0, 0)<CR> | ||
onoremap <silent> <Leader>[ :call <SID>to_indent_end(1, 0)<CR> | ||
vnoremap <silent> <Leader>] :call <SID>to_indent_end(0, 1)<CR> | ||
vnoremap <silent> <Leader>[ :call <SID>to_indent_end(1, 1)<CR> |