Vim Tips Wiki
(minor cleanup)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1014
 
|id=1014
  +
|previous=1013
|title=Visual selection of indent block
 
  +
|next=1015
|created=October 8, 2005 1:24
+
|created=October 8, 2005
 
|complexity=basic
 
|complexity=basic
 
|author=Robert Schols
 
|author=Robert Schols
 
|version=5.7
 
|version=5.7
 
|rating=16/11
 
|rating=16/11
|text=
 
 
}}
 
}}
 
This command will make a visual selection of the lines that have the same indent level or more as the current line.
 
This command will make a visual selection of the lines that have the same indent level or more as the current line. Somebody told me that this would be useful when programming Python.
 
   
 
<pre>
 
<pre>
:exe "normal V" | let temp_var=indent(line(".")) | while indent(line(".")+1) &gt;= temp_var | exe "normal j" | endwhile
+
:exe "normal V" | let temp_var=indent(line(".")) | while indent(line(".")+1) &gt;= temp_var | exe "normal j" | endwhile
 
</pre>
 
</pre>
   
 
==Comments==
 
==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 &lt;Space&gt;):
This idea was immensely useful for me, thank you.
 
A slight modification, to select the area above the cursor position as well, and the whole thing wrapped in a function (and nmapped to &lt;space&gt;):
 
   
  +
<pre>
function! SelectIndent ()
+
function! SelectIndent ()
let temp_var=indent(line("."))
 
while indent(line(".")-1) &gt;= temp_var
+
let temp_var=indent(line("."))
 
while indent(line(".")-1) &gt;= temp_var
exe "normal h"
 
  +
exe "normal k"
endwhile
 
  +
endwhile
exe "normal V"
 
 
exe "normal V"
while indent(line(".")+1) &gt;= temp_var
 
  +
while indent(line(".")+1) &gt;= temp_var
exe "normal j"
+
exe "normal j"
endwhile
 
  +
endwhile
endfun
+
endfun
 
nmap &lt;space&gt; :call SelectIndent()&lt;cr&gt;
 
nmap &lt;space&gt; :call SelectIndent()&lt;cr&gt;
  +
</pre>
   
spaceman--AT--foo.at
 
, October 9, 2005 4:24
 
 
----
 
----
Actually it should be "normal k" and not "normal h".
 
 
h is left but k is up.
 
 
'''Anonymous'''
 
, October 16, 2005 1:45
 
----
 
Interesting; I might try it.
 
 
Currently, I just set foldmethod=indent and select the folded area.
 
Currently, I just set foldmethod=indent and select the folded area.
   
Eric
 
, October 27, 2005 12:10
 
----
 
you made python bearable for an old lady like me.
 
bless you son.
 
 
Jackie
 
, June 24, 2006 22:52
 
 
----
 
----
<!-- parsed by vimtips.py in 0.852093 seconds-->
 

Revision as of 03:34, 16 December 2007

Tip 1014 Printable Monobook Previous Next

created October 8, 2005 · complexity basic · author Robert Schols · version 5.7


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

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.