Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Visual selection of indent block
Back to page
Edit
Edit source
View history
Talk (0)
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.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=1014 |previous=1012 |next=1016 |created=2005 |complexity=basic |author=Robert Schols |version=5.7 |rating=16/11 |category1= |category2= }} This command will make a visual selection of the lines that have the same indent level or more as the current line. <pre> :exe "normal V" | let temp_var=indent(line(".")) | while indent(line(".")+1) >= temp_var | exe "normal j" | endwhile </pre> ==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>): <pre> 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> </pre> ---- Currently, I just <code>:set foldmethod=indent</code> and select the folded area. ---- I believe this function might be better. <pre> function SelectIndent() let cur_line = line(".") let cur_ind = indent(cur_line) let line = cur_line while indent(line - 1) >= cur_ind let line = line - 1 endw exe "normal " . line . "G" exe "normal V" let line = cur_line while indent(line + 1) >= cur_ind let line = line + 1 endw exe "normal " . line . "G" endfunction nnoremap vip :call SelectIndent()<CR> </pre> --February 23, 2013 :Thanks, but any chance of mentioning ''why'' it is better? [[User:JohnBeckett|JohnBeckett]] ([[User talk:JohnBeckett|talk]]) 23:42, February 23, 2013 (UTC)
Summary:
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)
Templates used on this page:
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab