History
Article Edit this page Discussion

Visual selection of indent block

From Vim Tips Wiki

Jump to: navigation, search

Tip 1014 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

[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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Visual selection of indent block"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation