I’m a fan of Visual mode in Vim, as it allows to insert text before any given column.
For example, insertion of spaces after the quotation leaders below:
> one
> two
> three
can be done via <Ctrl-V>jjI <Esc>
:
> one
> two
> three
as follows:
- Start Visual mode with?Ctrl-V.
- Extend visual selection with?
jj
.
- Insert some spaces with?
I__
.
- Propagate the change to all the lines of the block selection with?Esc.
Now I have a text file that needs some formatting. This is what it looks like:
start() -- xxx
initialize() -- xxx
go() -- xxx
Now I want to align part of this text to arrange it into columns like this:
start() -- xxx
initialize() -- xxx
go() -- xxx
The problem I have is that I cannot insert a different amount of indentation into each line and merely indenting a fixed amount of spaces/tabs is insufficient.
How can you do an indentation where all indented text will have to be aligned at the same column?
Update
I only figured out a rather verbose and unwieldy method:
- Find the string position to indent from:
--
.
- Insert n (let's say 20) spaces before that:
20i <Esc>
.
- Delete a part of those spaces back to a certain column (let's say 15):
d|15
.
- Save those steps as a macro and repeat the macro as often as necessary.
But this approach is very ugly, though!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…