2017-08-30 81 views
2

组线在Vim中 >>将五个线移位下方并包括一个光标是一个翼片或shiftwidth空间权。 <<对左侧是否也是如此。如何缩进多次

如果我想将某些行数向左或向右移动两次或三次,该怎么办?我在寻找某种方式指定shiftwidth的数量的转移,而不是 >>>>>>

+4

我通常只是做'5 >>'之后'.'多次我需要的。 – acushner

+1

https://vi.stackexchange.com/q/9795/2920 – DJMcMayhem

回答

3

的一种方法是使用可视化选择来选择行:

eg缩进当前行和下一4行,选择具有vĴ

,然后使用数字后跟>缩进许多倍例如 >

0

你可以这样做:

nnoremap > :<C-u>exec 'set shiftwidth='.v:count1<cr>> 
nnoremap < :<C-u>exec 'set shiftwidth='.v:count1<cr>< 
xnoremap > :<C-u>exec 'set shiftwidth='.v:count1<cr>gv> 
xnoremap < :<C-u>exec 'set shiftwidth='.v:count1<cr>gv< 

这样一来,像5>>会缩进当前行与5位。这不是一个完美的解决方案,因为你可能想要做很多不同的方法。例如,如果你希望这是5个标签呢?或者当前设置为sw的5倍?但是这归结为个人偏好,你并没有在你的问题中具体说明这一点,所以如果你想要做这样的事情,我会让你知道。

但举例来说,如果你知道你想要4个空格,你可以这样做:

nnoremap > :<C-u>exec 'set shiftwidth=4*'.v:count1<cr>> 
nnoremap < :<C-u>exec 'set shiftwidth=4*'.v:count1<cr>< 
xnoremap > :<C-u>exec 'set shiftwidth=4*'.v:count1<cr>gv> 
xnoremap < :<C-u>exec 'set shiftwidth=4*'.v:count1<cr>gv< 

但如果您使用的是较小的shiftwidth的这并没有考虑到。

+0

这并不能真正解决我的问题,它只是将它从“我如何获得目前被'5> >'“到”我如何得到X的部分将被卡住在1用'5 >>'“ –

+0

@Austin_Anderson你必须基本上分开计数和动作。 count是第一个'>'之前的所有内容,count是第一个'>'之后的所有内容。所以你可以做'5> 5>'或'5> 4j' – DJMcMayhem

2

vim官方手册::help >

要移动一行多个“shiftwidth'列,使用可视模式或者:命令。

例如:

Vjj4>   move three lines 4 indents to the right 
    :<<<   move current line 3 indents to the left 
    :>> 5   move 5 lines 2 indents to the right 
    :5>>   move line 5 2 indents to the right 

或简称为5>>和在正常模式下与.重复该命令作为@acushner指出

+0

生活和学习。谢谢! – Ves

0

Anoter选项使用命令

4:>>> 

当你按<Enter>你会看到:

:.,.+3>>> 

然后按<Enter>