Visual selection of indent block
From Vim Tips Wiki
(Redirected from VimTip1014)
Tip 1014 Previous Tip • Next Tip
Created: October 8, 2005 Complexity: basic Author: Robert Schols Minimum version: 5.7 Karma: 16/11 Imported from: Tip#1014
This command will make a visual selection of the lines that have the same indent level or more as the current line.
:exe "normal V" | let temp_var=indent(line(".")) | while indent(line(".")+1) >= temp_var | exe "normal j" | endwhile
[edit] Comments
A slight modification, to select the area above the cursor position as well, and the whole thing wrapped in a function (and nmapped to <Space>):
function! SelectIndent ()
let temp_var=indent(line("."))
while indent(line(".")-1) >= temp_var
exe "normal k"
endwhile
exe "normal V"
while indent(line(".")+1) >= temp_var
exe "normal j"
endwhile
endfun
nmap <space> :call SelectIndent()<cr>
Currently, I just set foldmethod=indent and select the folded area.
