在vim中执行命令后跳至最后一个光标位置

在vim中执行命令后跳至最后一个光标位置,vim,Vim,我有一个用户定义的vim命令,它调用vim SKIPT: command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) 光标跳到文件的第一行。但我想让它留在我进入指挥部之前的地方 我试过了 command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) | '' 命令-complete=she

我有一个用户定义的vim命令,它调用vim SKIPT:

command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
光标跳到文件的第一行。但我想让它留在我进入指挥部之前的地方

我试过了

command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) | ''
命令-complete=shellcmd-nargs=+Shell调用s:RunShellCommand()|“”
这似乎不起作用

runshell命令是

" 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
在vim暂存缓冲区中输出的Shell命令 函数!s:RunShellCommand(cmdline) 让isfirst=1 让单词=[] 对于拆分中的单词(a:cmdline) 如果是第一个 让isfirst=0“不更改第一个单词(shell命令) 其他的 如果单词[0]=~'\v[%#我想你需要“正常”`:

command!-complete=shellcmd-nargs=+Shell调用s:RunShellCommand()|正常``

另请参见此处描述的winsaveview/winrestview函数:

我尝试了这个命令!-complete=shellcmd-nargs=+Shell let saved_winnr=winnr()|调用s:RunShellCommand()| exec保存了_winnr。'wincmd w'但两者似乎都不起作用。runshell命令打开暂存缓冲区,通常会再次关闭它。原则上,添加标记或保存行号并在命令完成后返回到此位置应该很容易。但如何添加不会覆盖可能的用户标记的标记呢。RunShellCommand来自何处?我怀疑这可能是您正在使用的插件/脚本的一个功能,否则,最好将其作为一个(新)功能来实现。RunShellCommand是vim tips中vim脚本的修改版本,请参阅编辑。
" 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
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) | normal ``