Hãy xem xét các ánh xạ sau đó tuân thủ các hành vi của các !
linewise lệnh lọc (xem :helpg \*!\*
và :help v_!
).
nnoremap <silent> <leader>! :set opfunc=ProgramFilter<cr>[email protected]
vnoremap <silent> <leader>! :<c-u>call ProgramFilter(visualmode(), 1)<cr>
function! ProgramFilter(vt, ...)
let [qr, qt] = [getreg('"'), getregtype('"')]
let [oai, ocin, osi, oinde] = [&ai, &cin, &si, &inde]
setl noai nocin nosi inde=
let [sm, em] = ['[<'[a:0], ']>'[a:0]]
exe 'norm!`' . sm . a:vt . '`' . em . 'x'
call inputsave()
let cmd = input('!')
call inputrestore()
let out = system(cmd, @")
let out = substitute(out, '\n$', '', '')
exe "norm!i\<c-r>=out\r"
let [&ai, &cin, &si, &inde] = [oai, ocin, osi, oinde]
call setreg('"', qr, qt)
endfunction
Nguồn
2012-03-10 08:53:40
có thể trùng lặp của "[Thi 'base64 --decode' trên một lựa chọn trong vim] (http://stackoverflow.com/questions/7845671/executing-base64-decode-on-a-selection-in -vim) ". –