Avoid moving the cursor to autcmd BufWritePre in .vimrc

I have the following line in .vimrc .

 autocmd BufWritePre * silent! v/\_s*\S/d 

This removes empty lines at the end of files when saving. The problem is that when it splits lines, it also moves the cursor to the last line of the file. Is there a way to avoid changing the location of the cursor?

+4
source share
1 answer
 function! <SID>DelEmptyLinesEnd() let l = line(".") let c = col(".") v/\_s*\S/d call cursor(l, c) endfunction autocmd BufWritePre * :call <SID>DelEmptyLinesEnd() 
+4
source

Source: https://habr.com/ru/post/1433106/


All Articles