c++ - 仅为 C++ header 设置 vim 文件类型脚本

标签 c++ vim

我基本上想让 vim 在 c++ 头文件上使用一个命令,并且只在 c++ 头文件上使用。我怎样才能做到这一点?

我已经尝试将命令放在 ~/.vim/ftplugin/hpp.vim 中,但没有用,因为 hpp 文件被 Vim 视为 cpp 文件。

最佳答案

在你的 ~/.vim/ftplugin/cpp.vim 中:

if expand('%:e') ==? 'hpp'
    " your script here
endif

更好的是:

if expand('%:e') =~? '\v^h%(pp|h|\+\+|xx)?$'
    " your script here
endif

关于c++ - 仅为 C++ header 设置 vim 文件类型脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32226834/

相关文章:

c++ - 矩阵的 Armadillo 稀疏分配

c++ - 从子类c++调用基类方法

C++ 运算符歧义

function - VIM 函数 : when to use "normal", 什么时候使用 "exec"什么时候不使用?

git - .gitattributes 文件不转换行尾

python - 保存时自动运行python代码

c++ - std::string 没有空字符

c++ - 程序在部署时表现异常

vim - 有没有办法在航空公司表格中显示标签索引号?

git - 使用 vimdiff 查看所有 `git diffs`