自动弹出窗口中的字典建议
Dictionary suggestions in autopopup
我使用 Vim 很多年了,但我仍然不知道如何在启用自动弹出词典建议的情况下键入文本(例如在 notepad++ 或 google android 键盘中)按任意快捷键。
这些是我在 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
- 您可以通过调用
SuperTabSetDefaultCompletionType
函数(实际上是默认函数)来限制 Supertab 插件仅弹出缓冲词:
: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
我使用 Vim 很多年了,但我仍然不知道如何在启用自动弹出词典建议的情况下键入文本(例如在 notepad++ 或 google android 键盘中)按任意快捷键。
这些是我在 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
- 您可以通过调用
SuperTabSetDefaultCompletionType
函数(实际上是默认函数)来限制 Supertab 插件仅弹出缓冲词:
: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