首页 > 解决方案 > Vim 没有正确缩进我的 C/C++ 文件

问题描述

我真的对此感到困惑,并希望能得到快速帮助,因为我从昨天开始一直在尝试解决这个问题。我看过与 vim 中的缩进相关的视频,它适用于我的 Python 文件。但不知何故,当涉及到 .cpp 文件时,vim 会忽略我的 vimrc 文件的参数。

我在 Windows 下的 _vimrc 文件中以这种方式配置了它。

" Add proper C/C++ indentation
au BufNewFile,BufRead *.c, *.cpp, *.h
    \ set tabstop=4 | 
    \ set softtabstop=4 |
    \ set shiftwidth=4 |
    \ set expandtab |
    \ set autoindent |
    \ set fileformat=unix

" Add proper PEP8 indentation
au BufNewFile,BufRead *.py
    \ set tabstop=4 | 
    \ set softtabstop=4 |
    \ set shiftwidth=4 |
    \ set textwidth=79 |
    \ set expandtab |
    \ set autoindent |
    \ set fileformat=unix

此配置适用于我的 Python 文件,但在我创建或打开 C/C++ 文件时会自动缩进 8 个字符。

知道这里有什么问题吗?

提前非常感谢。

标签: c++vimconfiguration

解决方案


推荐阅读