ข้ามไปยังตำแหน่งเคอร์เซอร์สุดท้ายหลังจากคำสั่งในกลุ่ม

ฉันมีคำสั่ง vim ที่ผู้ใช้กำหนดซึ่งเรียก vim-Skript:

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

vim
person highsciguy    schedule 03.04.2012    source แหล่งที่มา


คำตอบ (1)


ฉันคิดว่าคุณต้องการ "ปกติ ``":

command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) | normal ``

ดูฟังก์ชัน winsaveview / winrestview ที่อธิบายไว้ที่นี่: https://stackoverflow.com/a/9989348/85371

person sehe    schedule 03.04.2012
comment
ฉันลองแล้วสั่งเลย! -complete=shellcmd -nargs=+ Shell ให้ save_winnr = winnr() | โทร s:RunShellCommand(‹q-args›) | ผู้บริหารที่บันทึกไว้_winnr 'wincmd w' แต่ดูเหมือนว่าจะไม่ทำงาน RunShellCommand เปิดบัฟเฟอร์เริ่มต้นและมักจะปิดอีกครั้ง โดยหลักการแล้ว ควรง่ายเหมือนกับการเพิ่มเครื่องหมายหรือบันทึกหมายเลขบรรทัดแล้วกลับมาที่ตำแหน่งนี้เมื่อคำสั่งเสร็จสิ้น แต่ฉันจะเพิ่มเครื่องหมายที่ไม่เขียนทับเครื่องหมายผู้ใช้ที่เป็นไปได้ได้อย่างไร - person highsciguy; 03.04.2012
comment
RunShellCommand มาจากไหน? ฉันสงสัยว่านี่อาจเป็นคุณลักษณะของปลั๊กอิน/สคริปต์ที่คุณใช้อยู่ หรือมิฉะนั้น ควรนำไปใช้เป็นคุณลักษณะ (ใหม่) ของปลั๊กอินดังกล่าว - person sehe; 04.04.2012
comment
RunShellCommand เป็นเวอร์ชันแก้ไขของสคริปต์ vim จากเคล็ดลับ vim โปรดดูการแก้ไข - person highsciguy; 04.04.2012