2016-07-26 4 views
1

ディレクトリ検索を作成し、vimscriptの関数をfzfで置き換えようとしています。私がブロックする場所は、Alt-a fzfバインディングを使用してリスト全体を選択しようとするときです。私はfzfが外部プロセスであることが可能であるかどうかも分かりませんが、間違っている可能性があります。ディレクトリ検索を作成し、vimscriptとfzfで置き換える方法

ここに私の現在の機能があります。

function! CWDSearchAndReplace() 

    " Try to get word under cursor else prompt user for a word 
    let wordToReplace = expand("<cword>") 
    if wordToReplace == "" 
     call inputsave() 
     let wordToReplace = input("Replace: ") 
     call inputrestore() 
    endif 

    " Prompt for replacement 
    call inputsave() 
    let replacement = input("Replace \"" . wordToReplace . "\" with: ") 
    call inputrestore() 
    execute "Ag " . wordToReplace 

    " =====> Here I'd like to execute Alt-a followed by <CR> 

    execute "cdo %s//" . replacement . "/gc" 
end function 

ありがとうございました!

+0

「Alt-a」はどこから入手できますか? [fzf](https://github.com/junegunn/fzf)または[fzf.vim](https://github.com/junegunn/fzf.vim)について話していますか?なぜあなたの機能にサードパーティのツールがたくさんあるのですか? – romainl

+0

fzf.vim。 Agはfzf.vimの一部であり、cdoはvimの一部です。 Alt-Aはfzf.vimドキュメントから来て、fzfの使用方法のためにハードコードされています –

+0

ファイルを検索して置換する便利で速い方法は、検索にvim-ripgrepを使用し、quickfix-reflectorを使用してクイックフィックスウィンドウが表示されます。 – jasonjonesutah

答えて

2

pointed outの作成者はfzf.vimを使用する必要はありません。ここではfzfを使用する必要はありません。単純にagを使用してください。

function! s:ag_to_qf(line) 
    let parts = split(a:line, ':') 
    echo parts 
    return {'filename': parts[0], 'lnum': parts[1], 'col': parts[2], 
     \ 'text': join(parts[3:], ':')} 
endfunction 

function! AgToQF(query) 
    call setqflist(map(systemlist('ag --column '.a:query), 's:ag_to_qf(v:val)')) 
endfunction 

function! CWDSearchAndReplace() 
    let wordUnderCursor = expand("<cword>") 
    call inputsave() 
    let wordToReplace = input("Replace : ", wordUnderCursor) 
    call inputrestore() 
    call inputsave() 
    let replacement = input("Replace \"" . wordUnderCursor . "\" with: ") 
    call inputrestore() 
    call AgToQF(wordUnderCursor) 
    execute "cdo %s/" . wordToReplace . "/" . replacement ."/gc" 
endfunction 

nnoremap <leader>r :call FileSearchAndReplace()<CR> 
関連する問題