Tabbing visual selection in VIM

后端 未结 9 740
悲哀的现实
悲哀的现实 2020-12-02 18:35

In many GUIs when I select a section of text and then hit the Tab or Shift+Tab button the selected section will indent in or out.

I

相关标签:
9条回答
  • 2020-12-02 19:36

    Or, you can go the nearest brace and type =% in normal mode -- it indents the block covered by the brace and its matching one. But I'm not sure how this is useful in a language such as Python.

    0 讨论(0)
  • 2020-12-02 19:38

    The following key map works like Brian's solution, But also keep the cursor position related to the word.

    " tap indent movement (use mark `m' for cursor position)
    vmap <S-Tab>  mm<`m:<C-U>exec "normal ".&shiftwidth."h"<CR>mmgv`m
    vmap <Tab>    mm>`m:<C-U>exec "normal ".&shiftwidth."l"<CR>mmgv`m
    
    0 讨论(0)
  • 2020-12-02 19:39

    Since I've abandoned vi to vim, I've never used > nor < again. I exploit vim automated indentation that can be explicitly triggered with =

    It works very well to motions like =a{ which is even more efficient than =%

    Otherwise, If one > isn't enough, just redo it with ., or undo the change with u.

    0 讨论(0)
提交回复
热议问题