c++ - VIM+ctags+omnicppcomplete

标签 c++ c vim ctags omnicppcomplete

我是 linux 新手,但我终于决定尝试一个,我最近安装了 openSUSE。在 Windows 7 上,我使用 Visual Studio 进行 c/c++ 编程。我试图在 linux 下找到任何 IDE,尝试了 KDevelop 但不喜欢它,所以我决定尝试将 VIM 设置为我的源代码编辑器。

首先,我需要找到一些自动完成功能。我读了一些关于 GCCSense 和 clang_complete 的东西,但现在安装这些东西对我来说有点复杂,所以我选择了 omnicpp 和 ctags。

我下载了 omnicpp 并将这些文件放在 ~/.vim 文件夹中,我安装了 ctags。我的 .vimrc 看起来像这样:

set number

" --- OmniCppComplete ---  
" -- required --  
set nocp " non vi compatible mode
filetype plugin on " enable plugins

" -- optional --
" auto close options when exiting insert mode
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
set completeopt=menu,menuone

" -- configs --
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype (i.e. parameters) in popup window

" -- ctags --
" map F8 to generate ctags for current folder:
map <F8> :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
" add current directory's generated tags file to available tags

set tags=./tags,tags,/home/andrzej/vim/commontags

为了尝试,我制作了简单的 .c 文件

struct str
{
    int aaa;
};

int main()
{
    str *wsk;
    wsk->aaa=5;
    return 0;
}

当我不在输入模式时按 F8,它应该在找到 .c 文件时生成标记文件(map :!/usr/bin/ctags -R --c++-kinds=+p --fields =+iaS --extra=+q .) 但没有生成这样的文件。我做错了什么?

最佳答案

编辑:

默认情况下,vim 和 gvim 都不会为您更改当前目录。因此,命令将在您环境的当前工作目录中执行。简而言之,如果你跑了:

cd / && vi ~/prog/c/file.c

您在 vi 中会遇到与在 gvim 中遇到的相同的“问题”。这就是我在评论中显示的绑定(bind)中使用绝对路径的原因。如果这是您期望的行为,那么使用 autochdir 是一个合理的解决方案。

原文:

问题似乎是 + 字符。我建议将您的 ctags 参数放入 ~/.ctags:

$ echo -e "--c++-kinds=+p\n--fields=+iaS\n--extras=+q" > ~/.ctags
$ cat ~/.ctags
--c++-kinds=+p
--fields=+iaS
--extra=+q

然后将映射更改为:

map <F8> :!/usr/bin/ctags -R<CR>

否则,您可以转义“+”字符:

map <F8> :!/usr/bin/ctags -R --c\+\+-kinds=\+p --fields=\+iaS --extra=\+q .<CR>

关于c++ - VIM+ctags+omnicppcomplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6934031/

相关文章:

c++ - 未能在 SFINAE 中将概念类型识别为 bool

c++ - 如何在 Visual Studio C++ 2010 中将不同的扩展文件编译为 C++?

vim - VIM中删除多行空格

vim - 在暂停 vim 时设置光标形状

search - 如何使用vim的 'f'命令(查找)查找下一个选项卡

c++ - 自动检查 std::vector 中的边界

C++、Allegro、Ubuntu 和 libpng/LoadPNG

为 CPU Arch 交叉编译或编译 native

c++ - 接口(interface)名称(eth0 等)的等效 inet_addr C/C++、Linux

c - 如何在 C 中最近创建的文件夹和文件中具有读取权限?