重复后,在同一分割中加载外部命令

Chr*_*oph 2 vim vim-plugin

我想将一些来自命令行命令的文本加载到新的vim拆分中.我得到了这个工作,但如果我再次运行该命令,它会继续打开新的分裂.

我想要达到的目的是让它成为同样的分裂.我怎样才能做到这一点?

nnoremap <leader>q :execute 'new <bar> 0read ! bq query --dry_run --use_legacy_sql=false < ' expand('%')<cr> 
Run Code Online (Sandbox Code Playgroud)

Pet*_*ker 8

我建议通过:pedit命令使用预览窗口.

nnoremap <leader>q :execute 'pedit <bar> wincmd p <bar> 0read ! bq query --dry_run --use_legacy_sql=false < ' expand('%')<cr>
Run Code Online (Sandbox Code Playgroud)

但是,通过执行以下操作,我们可以做得更好:

  • 使用g@和创建"查询"运算符'opfunc'
  • 一个查询命令(感觉非常像这样)
  • 使用stdin而不是文件名

例:

function! s:query(str)
    pedit [query]
    wincmd p
    setlocal buftype=nofile
    setlocal bufhidden=wipe
    setlocal noswapfile
    %delete _
    call setline(1, systemlist('awk 1', a:str))
endfunction

function! s:query_op(type, ...)
    let selection = &selection
    let &selection = 'inclusive'
    let reg = @@

    if a:0
        normal! gvy
    elseif a:type == 'line'
        normal! '[V']y
    else
        normal! `[v`]y
    endif

    call s:query(@@)

    let &selection = selection
    let @@ = reg
endfunction

command! -range=% Query call s:query(join(getline(<line1>, <line2>), "\n"))
nnoremap \qq :.,.+<c-r>=v:count<cr>Query<cr>
nnoremap \q :set opfunc=<SID>query_op<cr>g@
xnoremap \q :<c-u>call <SID>query_op(visualmode(), 1)<cr>
Run Code Online (Sandbox Code Playgroud)

注意:我awk 1用作"查询"命令.改变以满足您的需求.

有关更多帮助请参阅:

:h :pedit
:h :windcmd
:h operator
:h g@
:h 'opfunc'
:h systemlist()
Run Code Online (Sandbox Code Playgroud)