假设我有这个代码:
width: 215px;
height: 22px;
margin-top: 3px;
background-color: white;
border: 1px solid #999999;
Run Code Online (Sandbox Code Playgroud)
我想这样对齐:
width: 215px;
height: 22px;
margin-top: 3px;
background-color: white;
border: 1px solid #999999;
Run Code Online (Sandbox Code Playgroud)
使用Align.vim我可以:Align \s使用空格作为分隔符,但这有两个问题
我已经阅读了Align.vim提供的许多选项,但我还没有找到办法.
Tal*_*tle 25
您可以使用Vim宏执行此操作,无需插件.将光标放在第一行的任意位置,然后键入普通模式,而不是插入模式:
qa0f:w100i <Esc>19|dwjq4@a
Run Code Online (Sandbox Code Playgroud)
注意100i之后的单个空格,<Esc>表示"按下转义" - 不要按字面意义键入"<Esc>".
翻译:
qa -- record macro in hotkey a
0 -- go to beginning of line
f: -- go to first : symbol
w -- go to next non-space character after the symbol
100i <Esc> -- insert 100 spaces
19| -- go to 19th column (value 19 figured out manually)
dw -- delete spaces until : symbol
j -- go to next line
q -- stop recording macro
4@a -- run the macro 4 times (for the remaining 4 lines)
Run Code Online (Sandbox Code Playgroud)
是的,我使用类似的宏来格式化上面的代码块:)
要在可视模式下将其应用于多个行,请执行,选择并键入:
:norm!@a
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4815 次 |
| 最近记录: |