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 文件所在位置时生成标记文件(地图:!/usr/bin/ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .)但没有生成这样的文件。我做错了什么?
I am linux newbie, but I finally decided to try one, I recently installed openSUSE. On windows 7 I used Visual Studio for c/c++ programming. I tried to find any IDE under linux, tried KDevelop but didn't like it, so i decided to try to setup VIM to be my source code editor.
Firstly I needed to find some auto completion. I read some things about GCCSense and clang_complete but for now installing those things is a bit complicated for me, so I settled for omnicpp and ctags.
I downloaded omnicpp and put those files in ~/.vim folder, I installed ctags. My .vimrc looks like this:
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
So to try it I made simple .c file
struct str
{
int aaa;
};
int main()
{
str *wsk;
wsk->aaa=5;
return 0;
}
I press F8 when I am not in input mode, it should generate tag file in place when .c file is located (map :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .) but no such file is generated. What I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:
默认情况下,vim 和 gvim 都不会为您更改当前目录。因此,命令将在环境的当前工作目录中执行。简而言之,如果你运行:
你将在 vi 中遇到与 gvim 中相同的“问题”。这就是为什么我在评论中显示的绑定中使用绝对路径。如果这是您所期望的行为,那么使用 autochdir 是一个合理的解决方案。
原文:
问题似乎出在
+
字符上。我建议将您的 ctags 参数放入~/.ctags
中:然后将您的映射更改为:
否则,您可以转义“+”字符:
Edit:
Neither vim nor gvim change the current directory for you by default. Therefore, commands will be executed in the current working directory of your environment. In short, if you ran:
you would have the same "problem" with vi that you're having in gvim. That's why I used absolute paths in the binding I showed in my comment. Using autochdir is a reasonable solution, if that's the behavior you're expecting.
Original:
The problem seems to be the
+
characters. I'd suggest placing your ctags arguments into~/.ctags
:Then change your mapping to:
Otherwise, you can escape the '+' characters:
Omni:
有人看到或引用过这个吗?
https://llvm.org/svn/llvm-project/llvm /trunk/utils/vim/vimrc
标签:
从臀部拍摄(阅读:未经测试和未经验证)尝试 CD'ing 到当前目录。
Omni:
Anyone seen or referenced this?
https://llvm.org/svn/llvm-project/llvm/trunk/utils/vim/vimrc
Tags:
Shot from the hip (Read: untested and unverified) Try CD'ing to the current dir.
好的,谢谢大家的回答,我已经找到问题的根源了。当我从终端 F8 运行 VIM 时工作正常,当我输入 !pwd 时,它显示我的 .c 文件所在的目录(例如 ~/prog/C),但是当我使用 GvIM 时,我打开相同的 .c 文件并输入!pwd 它显示 ~/dokumenty,所以我认为问题出在 VIM/GVIM 的某个地方。我想知道为什么无论我打开什么文件,GVIM 都无法识别该文件夹?
- -编辑 - -
我将 set autochdir 添加到我的 .vimrc 中,现在一切正常,问题解决了,但如果有人能回答我,我将不胜感激,为什么当我从终端运行 VIM 时一切正常(即使 autochdir 已关闭)但它不适用于 GVIM。
Ok, thanks for all your answers, I found where the source of the problem is. When I run VIM from terminal F8 works fine, when I type !pwd it shows the directory where my .c file is (ex. ~/prog/C), but when I use GvIM and I open the same .c file and type !pwd it shows ~/dokumenty, so I think the problem lies somewhere in VIM/GVIM. I wonder why GVIM doesen't recognize the folder, no matter what file I open?
---edit---
I added set autochdir to my .vimrc and now everything works fine, the problem is solved, but I would be grateful if someone could answer me, why everything was working when i run VIM from terminal(even when autochdir was turned off) but it didn't work for GVIM.