c++ - 如何在 vim 中自动包含 C++ 头文件?

标签 c++ vim

我经常想使用 STL 函数和容器,但发现自己必须手动添加:

#include <vector>
using std::vector;

到文件开头。有人知道 vim 插件或命令行程序会自动执行此类操作吗?

最佳答案

您首先需要编写一个 .cpp 文件,其中将包含您通常需要的所有 header 。

我的看起来像这样,

#include<iostream>
#include<stdio.h>

using namespace std;

typedef long long int ll;

int main(void) {

return 0;
}

现在将这一行添加到您的 vimrc 文件中,

autocmd BufNewFile *.cpp r /path/to/template.cpp

现在,每次打开 .cpp 文件时,您都将拥有预先编写好的所有内容。

关于c++ - 如何在 vim 中自动包含 C++ 头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416259/

相关文章:

c++ - (从 istream 中提取并插入到 ostream 中)操作 : is >><T> os;

vim - 如何在保存文件后自动运行命令

将 vim ctags <C-]> 和 <C-T> 键映射复制到 <C-Q> 和 <C-A>

c++ - 2d thrust::device_vector 到内核

c++ - 代码解释 c++ [struct/two diamentinal array/pointers]

c++ - MFC:将 GetContextMenuManager()->ShowPopup 与 Office2007 视觉对象一起使用时出现延迟

c++ - 用给定的线段数逼近圆

c++ - vim 插件注释 block

linux - vim 如何区分 ESC 键和转义序列头?

javascript - 函数内的 Vim Javascript 缩进