How to avoid namespace content indentation in vim?

前端 未结 5 678
慢半拍i
慢半拍i 2020-12-24 11:57

How to set vim to not indent namespace content in C++?

namespace < identifier >
{
    < statement_list > // Unwanted indentation
}
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 12:51

    I've configured vim to not indent for the namespace. These are the relevant lines in my vimrc:

    autocmd Filetype cpp set shiftwidth=2
    set cino=>2(0^-2g0h2
    

    Frankly, I don't remember how to interpet the cino statement, but :help cinoptions should help in deciphering it. One caveat: I think it's configured to not indent when using a format like so:

    namespace foo 
    { // <- curly bracket on next line
    ...
    

    versus

    namespace foo { // <- same line
    

    Since I put the curly bracket on the next line exclusively for namespaces, it does what I want, but it might not work if you use that style for other function declarations, for, etc.

提交回复
热议问题