gpt4 book ai didi

ruby-on-rails - vim omnicomplete with ruby​​ 只能部分工作

转载 作者:数据小太阳 更新时间:2023-10-29 07:36:20 27 4
gpt4 key购买 nike

我有 vim 7.2 的 +ruby 版本(也尝试过 7.3 和自定义编译版本)但我只能在某些情况下使用 omnicomplete (ctrl-x ctrl-o)。

例如,如果我有

class MegaGreeter
attr_accessor :names

def initialize(names = "world")
@names = names
if @names.nil?
puts "hello #{@names}.each"
end
end
end

omnicomplete 适用于 .each,但不适用于 .nil。此外,它不会自动完成任何 attr_ 关键字。

我在禁用所有插件的情况下尝试过,然后再次启用所有插件。我也尝试过使用 vim-ruby 插件。我安装的插件有AfterColors、CSApprox、surround、color_sample_pack、mimpak、taglist。

我的 .vimrc 中有以下部分(如果需要,我可以发布整个 .vimrc)。我还在 C++、JavaScript 和大约 1/2 的其他语言中使用 VIM,因此对于其中一些语言也有无所不包的东西:

" ============================ "
" CTAGS / OMNICOMPLETE
" ============================ "

" map <ctrl>+F12 to generate ctags for current folder:
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR>
" add current directory's generated tags file to available tags
set tags+=./projects/.tags
" toggle list view
map <F4> :TlistToggle<cr>
" auto close omnicomplete options when exiting insert mode
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" configs for cpp
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

if has("win32")
let Tlist_Ctags_Cmd='c:\programs\ctags\ctags58\ctags.exe'
else
if has("win32unix")
let Tlist_Ctags_Cmd='/usr/bin/ctags.exe'
else
if has("unix")
let Tlist_Ctags_Cmd='/usr/bin/ctags'
endif
endif
endif

" omnicomplete settings for the popout menu
setlocal omnifunc=syntaxcomplete#Complete
" makes list show longest matching item at top of list
set completeopt=menuone,longest
" makes enter select item
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <Space> pumvisible() ? "\<C-y>" : "\<Space>"
inoremap <expr> <.> pumvisible() ? "\<C-y>" : "\<.>"
inoremap <expr> <S-CR> pumvisible() ? "\<C-n>\<C-y>" : ""
"manual up/down with tab & shift+tab
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : ""
"allows for autoselect of first item in user complete list
inoremap <expr> <C-n> pumvisible() ? '<C-n>' : '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
"allows autoselect of first item for omni complete
inoremap <expr> <leader>' pumvisible() ? '<C-n>' : '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
" open omni completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <C-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
\ '<C-x><C-o><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'
" open user completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <S-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
\ '<C-x><C-n><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'

" autocomplete for commands; and put most likely at top using tab complete
" (like windows cmd)
set wildmenu
set wildmode=list:longest

" for ruby
if has("autocmd")
filetype indent on
autocmd FileType cucumber,rspec,ruby set number
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_include_object = 1
autocmd FileType ruby,eruby let g:rubycomplete_include_objectspace = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
else
set autoindent
endif

" ruby requires bash --login;
" This is to correct running cmd from vim via :!
if has("unix")
set shell=/bin/bash\ -il
endif

"ruby end

那么,有没有一种方法可以让我在 omnicomplete 中获得对 Ruby 的全面支持,如果可以的话怎么办?或者,这是 omnicomplete 为 Ruby 提供的最多功能吗?

最佳答案

Vim 自动完成应该开箱即用,我不知道有任何方法 .nil 所以我不确定这是否是一个真正的问题。

然而,关于 omnicompletion 未完成 attr_reader 等问题,setlocal omnifunc=syntaxcomplete#Complete 修复了它,但是它应该放在 ftplugin 中/ruby/my_custom_ruby_ftplugin.vim 而不是仅仅在你的 vimrc 中,或者如果你愿意,你可以将该 setl 命令放在你的 vimrc 中的 autocmd FileType ruby​​ setl omnifunc=syntaxcompelete#Complete 中,并且然后它应该会像您期望的那样工作。

关于ruby-on-rails - vim omnicomplete with ruby​​ 只能部分工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15720313/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com