java 如何在 vim 中使用 ctags 进行自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7579361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use ctags for autocomplete in vim
提问by Frank Cheng
I try to develop android project in vim.But find it a bit of boring to look up in ctags for one method.Is there a way to show up a auto-complete list in vim using ctags?
我尝试在vim中开发android项目。但是发现在ctags中查找一种方法有点无聊。有没有办法使用ctags在vim中显示自动完成列表?
thanks
谢谢
it's my ctags's version below:
下面是我的 ctags 版本:
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Mar 21 2011, 10:34:51
Addresses: <[email protected]>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex
and vim's version:
和 vim 的版本:
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Mar 21 2011, 10:34:51
Addresses: <[email protected]>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex
ccheng@ccheng-desktop:~$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Mar 24 2011 07:10:07)
Included patches: 1-35
Modified by [email protected]
Compiled by buildd@
Huge version without GUI. Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path
+find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape
+mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse
+mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype
+path_extra -perl +persistent_undo +postscript +printer +profile +python/dyn
+python3/dyn +quickfix +reltime +rightleft -ruby +scrollbind +signs
+smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
-toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
-xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"
Compilation:
gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wall -g -O2 -D_FORTIFY_SOURCE=1
Linking:
gcc -Wl,--as-needed -o vim -lm -lncurses -lselinux -lacl -lgpm
my .vimrc file:
我的 .vimrc 文件:
1 set autochdir
2 filetype plugin indent on
3 set nu
4 set tags=./tags
5 set path=.,..,../..
6 set tabstop=4
7 set hlsearch
8 set cscopequickfix=s-,c-,d-,i-,t-,e-
9 set tags=$HOME/gingerbread/frameworks/tags,$HOME/gingerbread/packages/provid ers/ContactsProvider/tags
10
11 :" Only do this part when compiled with support for autocommands.
12 :if has("autocmd")
13 : autocmd Filetype java setlocal omnifunc=javacomplete#Complete
14 :endif
15 setlocal completefunc=javacomplete#CompleteParamsInfo
回答by Nick Knowlson
I want to clarify: it sounds like you have ctags set up already and would like to know how to use it to autocomplete method names, is that right?
我想澄清一下:听起来您已经设置了 ctags 并且想知道如何使用它来自动完成方法名称,对吗?
As romainl mentions, <C-n>
and <C-p>
are what you're looking for then. They're complete using next match
and complete using previous match
, respectively.
作为romainl提到,<C-n>
和<C-p>
你在找什么呢。它们分别是complete using next match
和complete using previous match
。
They are not the only types of autocompletion vim has though, see :he ins-completion
for the rest (includes spelling and file names). One specific completion I'd like to point out is <C-x><C-o>
(omni-completion) which you might find useful.
不过,它们并不是 vim 唯一的自动完成类型,请参阅:he ins-completion
其余的(包括拼写和文件名)。我想指出的一个特定完成是<C-x><C-o>
(omni-completion),您可能会发现它很有用。
In case you weren't only concerned with autocompletion: in this similar SO question, the accepted answer by richqhas some good info on ctags in general.
如果您不只关心自动完成:在这个类似的 SO 问题中,richq 接受的答案通常有一些关于 ctags 的好信息。
回答by Miserable Variable
I haven't tried autocomplete in VIM but a quick search found http://vim.wikia.com/wiki/Any_word_completion: The 'complete' option controls where the keywords are searched (include files, tag files, buffers, and more).
我没有在 VIM 中尝试过自动完成,但快速搜索发现http://vim.wikia.com/wiki/Any_word_completion:“完成”选项控制搜索关键字的位置(包括文件、标签文件、缓冲区等) .
回答by mosh
You can complete everything with [TAB], with this in vimrc. We use [char][char][dot][tab] to trigger tag completion, Also see https://stackoverflow.com/a/46645434/476175on how to integrate spelling, thesaurus, dictionary.
你可以用 [TAB] 完成所有事情,在 vimrc 中使用它。我们使用 [char][char][dot][tab] 来触发标签补全,关于如何整合拼写、同义词库、字典,另见https://stackoverflow.com/a/46645434/476175。
:inoremap <Tab> <C-R>=MoshTabOrComplete()<CR>
function! MoshTabOrComplete()
if col('.') > 3
\ && strpart( getline('.'), col('.')-3, 4 ) =~ '^[a-zA-Z]\+[.]' " prev 2 char are alpha+dot?
" Tag-completion eg. print.<tab> will complete to printf or println
return "\<BS>\<C-x>\<C-]>"
endif
" if exists("g:MoshThesaurusOmniCompleter") && col('.') > 3
" \ && strpart( getline('.'), col('.')-3, 4 ) =~ '^[a-zA-Z]\+[!%?~-]' " prev 2 char are alpha+punct?
" Calls MoshThesaurusOmniCompleter
" Test: qieut!<tab> will spell correct to quiet, more tests in ./thesaurus-omni.vim
" return "\<C-x>\<C-o>"
" endif
if col('.') > 1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w' " prev char is alphabet?
" Usual omni-completion
return "\<C-N>"
endif
" Insert regular TAB
return "\<Tab>"
endfunction