Reputation: 338
I want to insert 8 blanks at the front of many lines of code,
my cursor is in the front of if strftime()
,i want to add 8 blanks in all lines from if strftime()
till endif
,
13>> #count how many lines behind the cursor ,and `number >>` can do.
I don't want to count how many lines behind the cursor ,is there simple way to do that?
Upvotes: 0
Views: 99
Reputation: 172768
The >
command takes a {motion}
that selects the range of lines to be indented. Now for Vimscript's if...endif
, the matchit.vim plugin (that ships with Vim, see :help matchit
) adds cycling through those. As you have else
clauses in between, you need to use the reverse g%
motion to cycle backwards to the final endif
.
So, the shortest command to indent is >g%
.
Upvotes: 0
Reputation: 652
Open file in visual mode by pressing v
now select the block of code you want to modify
press >
to insert a tab at the beginning of each line of selected block.
and you have done.
Upvotes: 0
Reputation:
Another way using marks:
Position your cursor at the beginning of the first line where you want to insert the blanks, perhaps by typing /if (strftime/
in command mode. Now type m followed by any letter to set the mark with that letter as a reference. For example, I typed m followed by a to set mark 'a'.
Position your cursor at the beginning of the last line where you want to insert blanks. Now set a mark using a different letter (I used mark 'b'.)
Now as your question is unclear about whether you want to shift the lines by inserting 8 blanks at the start or whether you actually want to shift the line using the shift command 8 times, I'll answer with both:
Shift by shiftwidth
8 times:
:'a,'b>>>>>>>>
The quantity of >
characters is the number of times to shift (8 in this case), and 'a
and 'b
are the mark names preceded by the ' character.
Shift by inserting 8 leading spaces: type
:'a,'bs/^/ /
Yes, the spaces must be typed out fully.
Upvotes: 0
Reputation: 42942
Here's how to do it simply without having to estimate the lines.
Upvotes: 1
Reputation: 980
This is what I would do in such cases:
I tried another option it also works for me:
:set nu
to display the line numbers:34,46>>
then the lines in the range between line 34 and 46 would do the >>
change, you can change the two line numbers to yours in your case.Upvotes: 1
Reputation: 8905
Using >>
with a count, if you turn on relative line numbering (:set relativenumber
), you can get the count of lines very easily.
Or, use >
instead of >>
, which takes a motion command afterward. If there is a blank line after your block, just use >}
to indent up to the blank line. Or it could be a search, like >/endif<Enter>
.
Or visually select what you want and press >
once.
Upvotes: 1