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



我想将一些来自命令行命令的文本加载到新的vim拆分中。我让这个工作正常,但是如果我再次运行命令,它将继续打开新的拆分。

我想实现的目标是将其融入同一拆分。我该怎么做?

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

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

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

但是,我们可以通过以下几种方法做得更好:

  • 使用g@'opfunc'
  • 制作"查询"操作员
  • QUERY命令(感觉很像这样做(
  • 使用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>

注意:我正在使用awk 1作为我的"查询"命令。更改以满足您的需求。

有关更多帮助,请参见:

:h :pedit
:h :windcmd
:h operator
:h g@
:h 'opfunc'
:h systemlist()

最新更新