Do not override existing commands

So that we don't have to use VimEnter autocmd to override the commands
This commit is contained in:
Junegunn Choi 2017-02-07 11:40:31 +09:00
parent 4329721384
commit 1bf68a978b
No known key found for this signature in database
GPG key ID: 254BC280FEF9C627
3 changed files with 32 additions and 6 deletions

View file

@ -162,8 +162,9 @@ You can use autoload functions to define your own commands.
command! -bang -nargs=* GGrep command! -bang -nargs=* GGrep
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0) \ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
" We use VimEnter event so that the code is run after fzf.vim is loaded " Override Colors command. You can safely do this in your .vimrc as fzf.vim
autocmd VimEnter * command! -bang Colors " will not override existing commands.
command! -bang Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0) \ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
" Augmenting Ag command using fzf#vim#with_preview function " Augmenting Ag command using fzf#vim#with_preview function
@ -173,7 +174,7 @@ autocmd VimEnter * command! -bang Colors
" "
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key " :Ag - Start fzf with hidden preview window that can be enabled with "?" key
" :Ag! - Start fzf in fullscreen and display the preview window above " :Ag! - Start fzf in fullscreen and display the preview window above
autocmd VimEnter * command! -bang -nargs=* Ag command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>, \ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%') \ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'), \ : fzf#vim#with_preview('right:50%:hidden', '?'),

View file

@ -187,9 +187,31 @@ You can use autoload functions to define your own commands.
command! -bang -nargs=* GGrep command! -bang -nargs=* GGrep
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0) \ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
" We use VimEnter event so that the code is run after fzf.vim is loaded " Override Colors command. You can safely do this in your .vimrc as fzf.vim
autocmd VimEnter * command! Colors " will not override existing commands.
command! Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}) \ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'})
" Augmenting Ag command using fzf#vim#with_preview function
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
" * Preview script requires Ruby
" * Install Highlight or CodeRay to enable syntax highlighting
"
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
" :Ag! - Start fzf in fullscreen and display the preview window above
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
< <

View file

@ -33,7 +33,10 @@ function! s:defs(commands)
return return
endif endif
for command in a:commands for command in a:commands
execute substitute(command, '\ze\C[A-Z]', prefix, '') let name = ':'.prefix.matchstr(command, '\C[A-Z]\S\+')
if !exists(name)
execute substitute(command, '\ze\C[A-Z]', prefix, '')
endif
endfor endfor
endfunction endfunction