开发者

VIM+ctags+omnicppcomplete

开发者 https://www.devze.com 2023-03-25 13:29 出处:网络
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 did

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 re开发者_JAVA技巧ad 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?


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:

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

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:

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

Then change your mapping to:

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

Otherwise, you can escape the '+' characters:

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


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.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号