Vim Auto Indent with newline

前端 未结 6 1110
礼貌的吻别
礼貌的吻别 2021-02-01 13:18

How do I get vim to place the cursor within the braces starting on a new line, ie with | denoting the cursor position :

class {
  |
}

right now

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 13:55

    I have Ubuntu 12.04 and I found no vimrc file in home directory. Global vimrc file was in /etc/vim/vimrc.
    There was almost nothing in this file. So for me it worked to add this 3 lines to the end of /etc/vim/vimrc

    set autoindent
    set cindent
    inoremap { {}
    

    When you will type { next time it will be changed by combination {, Enter, }, up, end, Enter. cindent and autoindent will add required amount of Tab's.
    P.S. I'm not good in tuning up vim so some explanations may be not so accurate. It's how I think it works.

提交回复
热议问题