【问题标题】:How to get vim to sync syntax highlighting when opening file打开文件时如何让vim同步语法突出显示
【发布时间】:2014-10-11 17:53:10
【问题描述】:

我已经设置 vim 以在打开文件时跳转到最后一个已知的光标位置,但有时该位置位于 html 页面上某些 javascript 或 css 的中间,并且语法突出显示没有捕捉到这一点。我可以手动运行

:syntax sync minlines=200

修复突出显示,但我希望 vim 在我打开文件时为我运行它。

我尝试在我的 vimrc 中执行此操作,但它无法修复打开文件时的语法高亮显示。

  " 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

我关闭并重新打开 vim,所以它应该得到新的 .vimrc 设置。

不确定我在这里缺少什么。谢谢。

【问题讨论】:

    标签: vim vim-syntax-highlighting


    【解决方案1】:

    好的,我使用 BufWinEnter 事件而不是 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
    

    【讨论】:

    • 您可能还想知道&lt;c-l&gt;:redraw 会重绘屏幕。
    猜你喜欢
    • 2015-11-26
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2011-01-10
    • 2010-12-20
    • 1970-01-01
    • 2011-10-15
    相关资源
    最近更新 更多