首页 > 解决方案 > 输入 :make 后恢复光标位置

问题描述

.vimrc在重新打开文件后使用以下内容来恢复光标位置:

" Copied from defaults.vim
" Put these in an autocmd group, so that you can revert them with:
" ":augroup vimStartup | au! | augroup END"
augroup vimStartup
  au!

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid, when inside an event handler
  " (happens when dropping a file on gvim) and for a commit message (it's
  " likely a different one than last time).
  autocmd BufReadPost *
    \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
    \ |   exe "normal! g`\""
    \ | endif

augroup END

问题是当我输入时:make,光标位置没有恢复;光标仅出现在键入之前所在行的开头:make

您对如何解决此问题有任何建议吗?谢谢你的帮助。

标签: vim

解决方案


该命令:make似乎没有 throw BufReadPost,因此自动命令不会执行。

你可以做:make | norm! ``

:help ''


推荐阅读