我使用 Vim 很多年了,但我仍然不知道如何在不按任何快捷键的情况下在启用自动弹出字典建议的情况下键入文本(如在 Notepad++ 或谷歌安卓键盘中)。
这些是我在 vimrc 中的选项:
set completeopt=longest,menuone
set omnifunc=syntaxcomplete#Complete
简而言之,我想要的是:
1) 打字时自动弹出只有字典建议。
2) 仅在supertab中缓冲单词建议(使用tab键)
(但是..不包括缓冲区名称)
我怎样才能得到这个?
最佳答案
- 如果您使用的是 Linux,您可以将现有的英语词典设置为
/usr/share/dict/american-english
或只设置您自己的文件:
:set dictionary+=/usr/share/dict/american-english
因为在插入模式下字典补全的快捷方式是 CTRL-X CTRL-K 你需要添加这些设置:
:set noshowmode
:set completeopt+=noinsert
:autocmd CursorHoldI * call feedkeys("\<c-x>\<c-k>")
:set updatetime=500
- 您可以限制 Supertab通过调用
SuperTabSetDefaultCompletionType
函数(实际上是默认函数)仅弹出缓冲区单词的插件:
:call SuperTabSetDefaultCompletionType("<c-x><c-n>")
但是您仍然需要在 TAB 之前按 CTRL-X。
- 禁用 NeoComplete 插件
:NeoCompleteDisable
:help ins-completion
(...) Completion can be done for: 1. Whole lines i_CTRL-X_CTRL-L 2. keywords in the current file i_CTRL-X_CTRL-N 3. keywords in 'dictionary' i_CTRL-X_CTRL-K 4. keywords in 'thesaurus', thesaurus-style i_CTRL-X_CTRL-T 5. keywords in the current and included files i_CTRL-X_CTRL-I 6. tags i_CTRL-X_CTRL-] 7. file names i_CTRL-X_CTRL-F 8. definitions or macros i_CTRL-X_CTRL-D 9. Vim command-line i_CTRL-X_CTRL-V 10. User defined completion i_CTRL-X_CTRL-U 11. omni completion i_CTRL-X_CTRL-O 12. Spelling suggestions i_CTRL-X_s 13. keywords in 'complete' i_CTRL-N
编辑:
这与此答案下方的评论有关:这是我编写的一个小脚本 PopUpDict.vim
(可以改进),它会在键入 后自动弹出字典中匹配的单词3 个字符,它使您能够在键入 ctrl-x
tab
后弹出匹配的缓冲区关键字:(较新版本的 vim >= 7.4)
set dictionary+=/usr/share/dict/american-english
set completeopt+=noinsert
set cmdheight=2
call SuperTabSetDefaultCompletionType("<c-x><c-n>")
NeoCompleteDisable
augroup Main
autocmd!
autocmd InsertCharPre * call <SID>PopUpDict()
augroup END
let s:count=0
function! s:PopUpDict()
let AsciiCode=char2nr(v:char)
if (AsciiCode <=# 122 && AsciiCode >=# 97) || (AsciiCode <=# 90 && AsciiCode >=# 65)
let s:count+=1
if s:count >=# 3
call feedkeys("\<c-x>\<c-k>")
endif
else
let s:count=0
endif
endfunction
Demo
关于自动弹出窗口中的字典建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41432303/