有没有任何提示或技巧可以轻松选择 (g)Vim 的全能完成弹出窗口的第一个单词?
例如,如果我写
可能会弹出以下文字(并且 php 在菜单中突出显示,但不显示在代码中):
php
phrase
phrases
如果我点击 Tab或 CTRL + N 它只是变成 “返回原始位置。”
如果我按 Shift + Tab 或 CTRL + P 转到phrase
。
虽然 php 在菜单中突出显示,但如果我按 Enter ph
则不会完成。
我不确定这是 Vim 中的正常行为还是我的 .vimrc 有问题:
" SHORTCUTS
nnoremap <F4> :set filetype=html<CR>
nnoremap <F5> :set filetype=php<CR>
nnoremap <F3> :TlistToggle<CR>
" press space to turn off highlighting and clear any message already displayed.
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" set buffers commands
nnoremap <silent> <M-F8> :BufExplorer<CR>
nnoremap <silent> <F8> :bn<CR>
nnoremap <silent> <S-F8> :bp<CR>
" open NERDTree with start directory: D:\wamp\www
nnoremap <F9> :NERDTree /home/alex/www<CR>
" open MRU
nnoremap <F10> :MRU<CR>
" open current file (silently)
nnoremap <silent> <F11> :let old_reg=@"<CR>:let @"=substitute(expand("%:p"), "/", "\\", "g")<CR>:silent!!cmd /cstart <C-R><C-R>"<CR><CR>:let @"=old_reg<CR>
" open current file in localhost (default browser)
nnoremap <F12> :! start "http://localhost" file:///"%:p""<CR>
" open Vim's default Explorer
nnoremap <silent> <F2> :Explore<CR>
nnoremap <C-F2> :%s/\.html/.php/g<CR>
"
set completeopt=menu,preview,longest
" REMAPPING
" map leader to ,
let mapleader = ","
" remap ` to '
nnoremap ' `
nnoremap ` '
" remap increment numbers
nnoremap <C-kPlus> <C-A>
" COMPRESSION
function Js_css_compress ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.".ext
else
let minfname = substitute(nam, "[\._]src$", "", "g").".".ext
endif
if ext == 'less'
if executable('lessc')
cal system( 'lessc '.cwd.'/'.nam.'.'.ext.' &')
endif
else
if filewritable(cwd.'/'.minfname)
if ext == 'js' && executable('closure-compiler')
cal system( 'closure-compiler --js '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
elseif executable('yuicompressor')
cal system( 'yuicompressor '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
endif
endif
endif
endfunction
autocmd FileWritePost,BufWritePost *.js :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.css :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.less :call Js_css_compress()
" GUI
" taglist right side
let Tlist_Use_Right_Window = 1
" hide tool bar
set guioptions-=T
"remove scroll bars
set guioptions+=LlRrb
set guioptions-=LlRrb
" set the initial size of window
set lines=46 columns=180
" set default font
set guifont=Monospace
" set guifont=Monospace\ 10
" show line number
set number
" set default theme
colorscheme ir_dark
" encoding
set encoding=utf-8
setglobal fileencoding=utf-8 bomb
set fileencodings=ucs-bom,utf-8,latin1
" SCSS syntax highlight
au BufRead,BufNewFile *.scss set filetype=scss
" LESS syntax highlight
syntax on
au BufNewFile,BufRead *.less set filetype=less
" Haml syntax highlight
"au! BufRead,BufNewFile *.haml
"setfiletype haml
" Sass syntax highlight
"au! BufRead,BufNewFile *.sass
"setfiletype sass
" set filetype indent
filetype indent on
" for snipMate to work
filetype plugin on
" show breaks
set showbreak=----->
" coding format
set tabstop=4
set shiftwidth=4
set linespace=1
" CONFIG
" keep the buffer around when left
set hidden
" enable matchit plugin
source $VIMRUNTIME/macros/matchit.vim
" folding
set foldmethod=marker
set foldmarker={,}
let g:FoldMethod = 0
map <leader>ff :call ToggleFold()<cr>
fun! ToggleFold()
if g:FoldMethod == 0
exe 'set foldmethod=indent'
let g:FoldMethod = 1
else
exe 'set foldmethod=marker'
let g:FoldMethod = 0
endif
endfun
" save and restore folds when a file is closed and re-opened
"au BufWrite ?* mkview
"au BufRead ?* silent loadview
" auto-open NERDTree everytime Vim is invoked
au VimEnter * NERDTree /home/alex/www
" set omnicomplete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
" Improve completion popup menu
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
" Remove trailing white-space once the file is saved
au BufWritePre * silent g/\s\+$/s///
" Use CTRL-S for saving, also in Insert mode
noremap <C-S> :update!<CR>
vnoremap <C-S> <C-C>:update!<CR>
inoremap <C-S> <C-O>:update!<CR>
" DEFAULT
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
"source $VIMRUNTIME/mswin.vim
"behave mswin
" disable creation of swap files
set noswapfile
" no back ups wwhile editing
set nowritebackup
" disable creation of backups
set nobackup
" no file change pop up warning
autocmd FileChangedShell * echohl WarningMsg | echo "File changed shell." | echohl None
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
有没有办法立即选择第一个单词?
编辑:
:map <c-y> says:
n <C-Y>A <Plug>ZenCodingAnchorizeSummary
n <C-Y>a <Plug>ZenCodingAnchorizeURL
n <C-Y>k <Plug>ZenCodingRemoveTag
n <C-Y>j <Plug>ZenCodingSplitJoinTagNormal
n <C-Y>/ <Plug>ZenCodingToggleComment
n <C-Y>i <Plug>ZenCodingImageSize
n <C-Y>N <Plug>ZenCodingPrev
n <C-Y>n <Plug>ZenCodingNext
v <C-Y>D <Plug>ZenCodingBalanceTagOutwardVisual
n <C-Y>D <Plug>ZenCodingBalanceTagOutwardNormal
v <C-Y>d <Plug>ZenCodingBalanceTagInwardVisual
n <C-Y>d <Plug>ZenCodingBalanceTagInwardNormal
n <C-Y>; <Plug>ZenCodingExpandWord
n <C-Y>, <Plug>ZenCodingExpandNormal
v <C-Y>, <Plug>ZenCodingExpandVisual
For instance, if I write <?ph
The following words may pop up (and php is highlighted in the menu but not displayed in the code):
php
phrase
phrases
If I hit Tab or CTRL + N it just goes "Back at original."
If I press Shift + Tab or CTRL + P it goes to phrase
.
While php is highlighted in the menu, If I press enter ph
doesn't get completed.
I'm not sure if this is a normal behaviour in Vim or something wrong with my .vimrc:
" SHORTCUTS
nnoremap <F4> :set filetype=html<CR>
nnoremap <F5> :set filetype=php<CR>
nnoremap <F3> :TlistToggle<CR>
" press space to turn off highlighting and clear any message already displayed.
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" set buffers commands
nnoremap <silent> <M-F8> :BufExplorer<CR>
nnoremap <silent> <F8> :bn<CR>
nnoremap <silent> <S-F8> :bp<CR>
" open NERDTree with start directory: D:\wamp\www
nnoremap <F9> :NERDTree /home/alex/www<CR>
" open MRU
nnoremap <F10> :MRU<CR>
" open current file (silently)
nnoremap <silent> <F11> :let old_reg=@"<CR>:let @"=substitute(expand("%:p"), "/", "\\", "g")<CR>:silent!!cmd /cstart <C-R><C-R>"<CR><CR>:let @"=old_reg<CR>
" open current file in localhost (default browser)
nnoremap <F12> :! start "http://localhost" file:///"%:p""<CR>
" open Vim's default Explorer
nnoremap <silent> <F2> :Explore<CR>
nnoremap <C-F2> :%s/\.html/.php/g<CR>
"
set completeopt=menu,preview,longest
" REMAPPING
" map leader to ,
let mapleader = ","
" remap ` to '
nnoremap ' `
nnoremap ` '
" remap increment numbers
nnoremap <C-kPlus> <C-A>
" COMPRESSION
function Js_css_compress ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.".ext
else
let minfname = substitute(nam, "[\._]src$", "", "g").".".ext
endif
if ext == 'less'
if executable('lessc')
cal system( 'lessc '.cwd.'/'.nam.'.'.ext.' &')
endif
else
if filewritable(cwd.'/'.minfname)
if ext == 'js' && executable('closure-compiler')
cal system( 'closure-compiler --js '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
elseif executable('yuicompressor')
cal system( 'yuicompressor '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
endif
endif
endif
endfunction
autocmd FileWritePost,BufWritePost *.js :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.css :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.less :call Js_css_compress()
" GUI
" taglist right side
let Tlist_Use_Right_Window = 1
" hide tool bar
set guioptions-=T
"remove scroll bars
set guioptions+=LlRrb
set guioptions-=LlRrb
" set the initial size of window
set lines=46 columns=180
" set default font
set guifont=Monospace
" set guifont=Monospace\ 10
" show line number
set number
" set default theme
colorscheme ir_dark
" encoding
set encoding=utf-8
setglobal fileencoding=utf-8 bomb
set fileencodings=ucs-bom,utf-8,latin1
" SCSS syntax highlight
au BufRead,BufNewFile *.scss set filetype=scss
" LESS syntax highlight
syntax on
au BufNewFile,BufRead *.less set filetype=less
" Haml syntax highlight
"au! BufRead,BufNewFile *.haml
"setfiletype haml
" Sass syntax highlight
"au! BufRead,BufNewFile *.sass
"setfiletype sass
" set filetype indent
filetype indent on
" for snipMate to work
filetype plugin on
" show breaks
set showbreak=----->
" coding format
set tabstop=4
set shiftwidth=4
set linespace=1
" CONFIG
" keep the buffer around when left
set hidden
" enable matchit plugin
source $VIMRUNTIME/macros/matchit.vim
" folding
set foldmethod=marker
set foldmarker={,}
let g:FoldMethod = 0
map <leader>ff :call ToggleFold()<cr>
fun! ToggleFold()
if g:FoldMethod == 0
exe 'set foldmethod=indent'
let g:FoldMethod = 1
else
exe 'set foldmethod=marker'
let g:FoldMethod = 0
endif
endfun
" save and restore folds when a file is closed and re-opened
"au BufWrite ?* mkview
"au BufRead ?* silent loadview
" auto-open NERDTree everytime Vim is invoked
au VimEnter * NERDTree /home/alex/www
" set omnicomplete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
" Improve completion popup menu
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
" Remove trailing white-space once the file is saved
au BufWritePre * silent g/\s\+$/s///
" Use CTRL-S for saving, also in Insert mode
noremap <C-S> :update!<CR>
vnoremap <C-S> <C-C>:update!<CR>
inoremap <C-S> <C-O>:update!<CR>
" DEFAULT
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
"source $VIMRUNTIME/mswin.vim
"behave mswin
" disable creation of swap files
set noswapfile
" no back ups wwhile editing
set nowritebackup
" disable creation of backups
set nobackup
" no file change pop up warning
autocmd FileChangedShell * echohl WarningMsg | echo "File changed shell." | echohl None
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
Is there a way to choose the first word immediately?
EDIT:
:map <c-y> says:
n <C-Y>A <Plug>ZenCodingAnchorizeSummary
n <C-Y>a <Plug>ZenCodingAnchorizeURL
n <C-Y>k <Plug>ZenCodingRemoveTag
n <C-Y>j <Plug>ZenCodingSplitJoinTagNormal
n <C-Y>/ <Plug>ZenCodingToggleComment
n <C-Y>i <Plug>ZenCodingImageSize
n <C-Y>N <Plug>ZenCodingPrev
n <C-Y>n <Plug>ZenCodingNext
v <C-Y>D <Plug>ZenCodingBalanceTagOutwardVisual
n <C-Y>D <Plug>ZenCodingBalanceTagOutwardNormal
v <C-Y>d <Plug>ZenCodingBalanceTagInwardVisual
n <C-Y>d <Plug>ZenCodingBalanceTagInwardNormal
n <C-Y>; <Plug>ZenCodingExpandWord
n <C-Y>, <Plug>ZenCodingExpandNormal
v <C-Y>, <Plug>ZenCodingExpandVisual
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 ctrl-y 选择列表中当前突出显示的选项。 ctrl-n 和 p 将浏览列表中的下一个/上一个,但 y 将选择当前。
Use ctrl-y to select the currently highlighted option in the list. ctrl-n and p will go through the list next/previous, but y will select current.
在您的
.vimrc
中,您已将“longest”添加到completeopt
选项中:这意味着全向补全只能填充所有可能匹配的最长公共子字符串。如果您只使用
:setcompleteopt=menu,preview
那么 vim 在使用全向补全时应该选择第一个匹配项。In your
.vimrc
you have added "longest" to thecompleteopt
option:This means that omni completion can only fill in the longest common substring of all possible matches. If you just use
:set completeopt=menu,preview
then vim should select the first match when using omni completion.