我想将一些来自命令行命令的文本加载到新的vim拆分中.我得到了这个工作,但如果我再次运行该命令,它会继续打开新的分裂.
我想要达到的目的是让它成为同样的分裂.我怎样才能做到这一点?
nnoremap <leader>q :execute 'new <bar> 0read ! bq query --dry_run --use_legacy_sql=false < ' expand('%')<cr>
Run Code Online (Sandbox Code Playgroud)
我建议通过: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'例:
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)
| 归档时间: |
|
| 查看次数: |
321 次 |
| 最近记录: |