[英]How to indent group of lines multiple times
在Vim中5>>將五個線移位下方並包括一個光標是一個翼片或shiftwidth
空間權。 5 <<做了同樣的左側。
如果我想向左或向右移動兩次或三行一些行,該怎么辦? 我在尋找某種方式指定shiftwidth的數字的,而不是5轉向>>>>>>
一種方法是使用視覺選擇來選擇行:
例如,要縮進當前行和后4行,請使用v 4 j選擇
然后使用數字后跟>
進行多次縮進,例如3 >
從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指出的正常模式下
你可以這樣做:
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,則不會考慮到這一點。
使用命令的注釋器選項
4:>>>
當您按<Enter>
您將看到:
:.,.+3>>>
然后按<Enter>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.