我的代码中有以下一行.vimrc
。
autocmd BufWritePre * silent! v/\_s*\S/d
Run Code Online (Sandbox Code Playgroud)
保存时,这会在文件末尾删除空行。问题是,当它删除行时,也会将光标移动到文件的最后一行。无论如何要避免修改光标位置?
function! <SID>DelEmptyLinesEnd()
let l = line(".")
let c = col(".")
v/\_s*\S/d
call cursor(l, c)
endfunction
autocmd BufWritePre * :call <SID>DelEmptyLinesEnd()
Run Code Online (Sandbox Code Playgroud)