作者ViewMoon (阳春白雪)
看板Editor
标题[vim ] 开档後,部分档案内容被截掉
时间Tue Mar 24 21:00:06 2020
vim version <= 7.4 的 vimrc_example.vim 中有这一段 script, 或是
vim version >= 8.0 的 vimrc_example.vim 中会去 source $VIMRUNTIME/defaults.vim
里的同一段 script
让你每次开档时, cursor 就直接跳至上次关档时的 position
但这段 script 会造成偶发性 (很低的机率, 但还是有可能遇到) 的开档後
档案前半部被截掉, 只看到 g`" 之类的乱码, 若没注意到又存档就会...
但我不清楚为什麽没人在讨论这事,
虽然我在 CentOS/Ubuntu/vim 旧版新版都遇过, 除非你把这段 comment out
或 vim version >= 8.0 , 在 ~/.vimrc 里, source $VIMRUNTIME/defaults.vim 之前
加上这行
augroup vimStartup | au! | augroup END
那麽就不会执行这段 script
----------------------
" 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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.137.91.246 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Editor/M.1585054808.A.F3E.html
※ 编辑: ViewMoon (220.134.104.66 台湾), 03/27/2020 08:34:36
1F:推 mars90226: 推推,我是都用 vim-lastplace,把原本这段注解掉 03/28 01:36
2F:→ Bellkna: vimrc不要source defaults.vim不就好了? 04/04 19:05
3F:推 bootleq: 好奇怎样才会发生问题,我也有这个设定 04/09 22:42
4F:推 mars90226: 要有 source defaults.vim 才会有 04/11 13:31
5F:→ mars90226: 不过我自己是因为有用 vim-fetch 跟这个冲突 04/11 13:32