0
votes

I've got vim setup to jump to the last known cursor position when opening a file, but sometimes that position is in the middle of some javascript or css on a html page, and the syntax highlighting doesn't catch that. I can manually run

:syntax sync minlines=200

to fix the highlighting, but I'd like vim to run that for me whenever I open a file.

I tried to do this in my vimrc, but it doesn't fix the syntax highlighting when I open a file.

  " Jump to last known cursor porition
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif
  " Sync syntax highlighting
  autocmd BufReadPost * syntax sync minlines=200

I close and reopen vim, so it should be getting the new .vimrc settings.

Not sure what I'm missing here. Thanks.

1

1 Answers

0
votes

Ok, I got it using the BufWinEnter event instead of BufReadPost

  " Jump to last known cursor porition
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif
  " Sync syntax highlighting
  autocmd BufWinEnter * syntax sync minlines=200