簡體   English   中英

如何在vim中使用ctags進行自動完成

[英]How to use ctags for autocomplete in vim

我嘗試在vim中開發android項目。但是發現在ctags中查找一個方法有點無聊。有沒有辦法在vim中使用ctags顯示自動完成列表?

謝謝

這是我的ctags版本如下:

Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Mar 21 2011, 10:34:51
  Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex

和vim的版本:

Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Mar 21 2011, 10:34:51
  Addresses: <dhiebert@users.sourceforge.net>, 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 pkg-vim-maintainers@lists.alioth.debian.org
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

我的.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

我想澄清一下:聽起來你已經設置了ctags並且想知道如何使用它來自動填充方法名稱,是嗎?

正如romainl所提到的那樣, <Cn><Cp>就是你正在尋找的東西。 他們分別complete using next match complete using previous matchcomplete using previous match

它們不是vim唯一的自動完成類型,請參閱:he ins-completion其他內容:he ins-completion (包括拼寫和文件名)。 我想指出的一個具體完成是<Cx><Co> (omni-completion),你可能會發現它很有用。

如果你不僅僅關心自動完成:在這個類似的SO問題中, richq接受的答案總體上有一些關於ctags的好信息。

我沒有在VIM中嘗試自動完成,但是快速搜索發現http://vim.wikia.com/wiki/Any_word_completion :“完整”選項控制搜索關鍵字的位置(包括文件, 標記文件 ,緩沖區等) 。

您可以使用[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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM