1

I set up an auto run script in my vimrc to condense any block of 3 or more empty newlines down to 3 newlines. I set a mark so after the script executes, I retain my cursor position but I'm getting an E20 Mark not set error when the cursor is within an area that is being removed.

How can I fix this issue/silence the error when this happens?

" .vimrc file: autocmd BufWrite * mark ' | silent! %s/\n\{3,}/\r\r\r/e | norm''

Soumya R
  • 455
  • 1
  • 5
  • 21
Brian Egizi
  • 13
  • 1
  • 4

2 Answers2

1

You could replace your marks with winsaveview() and winrestview().

autocmd BufWrite * let w:winview = winsaveview() | ... | if exists('w:winview') | call winrestview(w:winview) | endif
romainl
  • 186,200
  • 21
  • 280
  • 313
  • This worked! Used `autocmd BufWrite * let w:winview = winsaveview() | %s/\n\{3,}/\r\r\r/e | if exists('w:winview') | call winrestview(w:winview) | endif` – Brian Egizi Jan 06 '15 at 23:51
0

Also silence the normal command:

autocmd BufWrite * mark ' | silent! %s/\n\{3,}/\r\r\r/e | silent! exe "norm! ''"
Ben
  • 8,725
  • 1
  • 30
  • 48