2
我有調用一個VIM-Skript一個用戶定義的VIM命令:跳轉到一個光標位置命令後,在vim
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
如果我執行它
:Shell echo "foo"
光標跳到第一文件的行。但是我希望它能保持在我進入命令之前的相同位置。
我試圖
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) | ''
這似乎並沒有工作。
的RunShellCommand是
" Shell command with output in vim scratch buffer
function! s:RunShellCommand(cmdline)
let isfirst = 1
let words = []
for word in split(a:cmdline)
if isfirst
let isfirst = 0 " don't change first word (shell command)
else
if word[0] =~ '\v[%#<]'
let word = expand(word)
endif
let word = shellescape(word, 1)
endif
call add(words, word)
endfor
let expanded_cmdline = join(words)
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1, 'You entered: ' . a:cmdline)
call setline(2, 'Expanded to: ' . expanded_cmdline)
call append(line('$'), substitute(getline(2), '.', '=', 'g'))
silent execute '$read !'. expanded_cmdline
" close scratch buffer if successfull
if v:shell_error == 0
q
endif
1
endfunction
我想這和命令! -complete = shellcmd -nargs = + Shell let saved_winnr = winnr()|調用s:RunShellCommand()| exec saved_winnr。 'wincmd w' 但似乎都沒有工作。 RunShellCommand打開暫存緩衝區並通常再次關閉它。原則上,它應該像添加標記或保存行號一樣簡單,並在命令完成時返回到此位置。但是,如何添加不覆蓋可能的用戶標記的標記。 –
highsciguy
2012-04-03 19:31:36
RunShellCommand從何而來?我懷疑這可能是您正在使用的插件/腳本的一個功能,否則,它最好作爲它的一個(新)特性來實現。 – sehe 2012-04-03 21:17:12
RunShellCommand是vim提示的vim腳本的修改版本,請參閱編輯。 – highsciguy 2012-04-03 22:50:02