diff --git a/README.md b/README.md index 552c12e..13580d6 100644 --- a/README.md +++ b/README.md @@ -162,8 +162,9 @@ You can use autoload functions to define your own commands. command! -bang -nargs=* GGrep \ call fzf#vim#grep('git grep --line-number '.shellescape(), 0, 0) -" We use VimEnter event so that the code is run after fzf.vim is loaded -autocmd VimEnter * command! -bang Colors +" Override Colors command. You can safely do this in your .vimrc as fzf.vim +" will not override existing commands. +command! -bang Colors \ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, 0) " 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 in fullscreen and display the preview window above -autocmd VimEnter * command! -bang -nargs=* Ag +command! -bang -nargs=* Ag \ call fzf#vim#ag(, \ 0 ? fzf#vim#with_preview('up:60%') \ : fzf#vim#with_preview('right:50%:hidden', '?'), diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 6ba2478..e325553 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -187,9 +187,31 @@ You can use autoload functions to define your own commands. command! -bang -nargs=* GGrep \ call fzf#vim#grep('git grep --line-number '.shellescape(), 0, 0) - " We use VimEnter event so that the code is run after fzf.vim is loaded - autocmd VimEnter * command! Colors + " Override Colors command. You can safely do this in your .vimrc as fzf.vim + " will not override existing commands. + command! Colors \ 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(, + \ 0 ? fzf#vim#with_preview('up:60%') + \ : fzf#vim#with_preview('right:50%:hidden', '?'), + \ 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(), 1, + \ 0 ? fzf#vim#with_preview('up:60%') + \ : fzf#vim#with_preview('right:50%:hidden', '?'), + \ 0) < diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 112cf62..b7955a7 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -33,7 +33,10 @@ function! s:defs(commands) return endif 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 endfunction