I can use vi{ and va{ to select C++ code blocks. It helps me a lot when I need to yank/delete them.
But Python uses indentation to indicate code blocks. I cannot find any better way. Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I have not had much of an occasion to use it yet, but Michael Smith’s vim-indent-object sounds like it may be close to what you want.
Example usage (line numbers shown as with
set numberactive):With the cursor on the line 2, 4 or 5, type
Viito select lines 2 through 5.With the cursor on line 3, type
Vaito select lines 2 through 3.With the cursor on line 3, type
Vaiii(orViiii), to select lines 2 through 5 (in visual mode multiple uses of indentation objects extend the selection to the next level up/out).The text objects it defines are:
ai: the current indentation level plus the line aboveuseful when you want to grab the introductory line (e.g. grab the
ifand its “then” block)ii: the current indentation levelaI: the current indentation level plus the one line above and one line belowuseful for languages that use “end” statements:
if/endif).iI: the current indentation level (effectively,ii, andiIare the same)The objects can also be used with other commands that expect text objects (i.e.
ciito delete the current indentation level and start inserting its replacement).