使用 argdo 打开多个文件时,vim 中未打开语法突出显示

2024-04-06

我经常从 MacVim 中一次打开整组文件。为此,我通常使用以下命令:

args *PATTERN*
argdo tabedit

这会将工作目录中与模式匹配的所有文件加载到参数列表中,然后在单独的选项卡中将它们全部打开。当我执行此操作时,语法突出显示不会自动打开,我必须手动设置它。我怎样才能解决这个问题?


我已经发布了解决方法 https://stackoverflow.com/a/10515142/813602 for :bufdo在类似的问题中;这是一个扩展版本,也可以处理您的用例。解决自动设置问题'eventignore'相当棘手,因此有充分的评论:

" Enable syntax highlighting when buffers are displayed in a window through
" :argdo and :bufdo, which disable the Syntax autocmd event to speed up
" processing.
augroup EnableSyntaxHighlighting
    " Filetype processing does happen, so we can detect a buffer initially
    " loaded during :argdo / :bufdo through a set filetype, but missing
    " b:current_syntax. Also don't do this when the user explicitly turned off
    " syntax highlighting via :syntax off.
    " The following autocmd is triggered twice:
    " 1. During the :...do iteration, where it is inactive, because
    " 'eventignore' includes "Syntax". This speeds up the iteration itself.
    " 2. After the iteration, when the user re-enters a buffer / window that was
    " loaded during the iteration. Here is becomes active and enables syntax
    " highlighting. Since that is done buffer after buffer, the delay doesn't
    " matter so much.
    " Note: When the :...do command itself edits the window (e.g. :argdo
    " tabedit), the BufWinEnter event won't fire and enable the syntax when the
    " window is re-visited. We need to hook into WinEnter, too. Note that for
    " :argdo split, each window only gets syntax highlighting as it is entered.
    " Alternatively, we could directly activate the normally effectless :syntax
    " enable through :set eventignore-=Syntax, but that would also cause the
    " slowdown during the iteration Vim wants to avoid.
    " Note: Must allow nesting of autocmds so that the :syntax enable triggers
    " the ColorScheme event. Otherwise, some highlighting groups may not be
    " restored properly.
    autocmd! BufWinEnter,WinEnter * nested if exists('syntax_on') && ! exists('b:current_syntax') && ! empty(&l:filetype) && index(split(&eventignore, ','), 'Syntax') == -1 | syntax enable | endif

    " The above does not handle reloading via :bufdo edit!, because the
    " b:current_syntax variable is not cleared by that. During the :bufdo,
    " 'eventignore' contains "Syntax", so this can be used to detect this
    " situation when the file is re-read into the buffer. Due to the
    " 'eventignore', an immediate :syntax enable is ignored, but by clearing
    " b:current_syntax, the above handler will do this when the reloaded buffer
    " is displayed in a window again.
    autocmd! BufRead * if exists('syntax_on') && exists('b:current_syntax') && ! empty(&l:filetype) && index(split(&eventignore, ','), 'Syntax') != -1 | unlet! b:current_syntax | endif
augroup END
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 argdo 打开多个文件时,vim 中未打开语法突出显示 的相关文章

  • vim:打开预览窗口而不移动主窗口中的文本

    当全能完成 或其他方式 打开预览窗口时 主窗口的大小会减小 以便为预览窗口腾出空间 默认情况下 预览窗口弹出前主窗口中可见的第一行在预览窗口弹出后也将相同 这会产生不幸的效果 即主窗口中的文本在视觉上被下推 我希望主窗口中的文本保留在原来的
  • Vim 中的类和函数名称高亮显示

    在沉迷于它的模态输入之后 我最近刚刚从 Textmate 设置了我的 Vim 环境 不过 Vim 中的语法高亮似乎不太美观 我用 C 编写代码 由于函数调用和类名无法突出显示 因此代码更难以阅读 我玩了一下配色方案 但找不到任何与 类名 或
  • 你能让 vi 在打开时“前进”屏幕吗?

    我经常在 vi 中工作 暂停 vi 在 cli 上运行一些东西 然后返回到 vi 来处理结果 例如 修复运行 cli 命令时出现的错误 但是 当我 fg vi 时 vi 会 擦除 当前终端缓冲区 并且我在回滚缓冲区中看不到终端输出的 最后一
  • VIM:有没有一种简单的方法可以从 Vim 管理 Visual Studio 解决方案/makefile 项目? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我尝试使用 Visual Studio 而不是 VIM 插件 但说实话 VS 相对于 VIM 的唯一优势是它能够自动管理我的项目 我知道 VS
  • 切换 git 分支时如何处理 vim 缓冲区?

    因此 我在 vim 缓冲区中打开了大量文件 并且正在使用 git 处理功能分支 突然 我意识到我需要恢复到主分支来进行快速修复 提交后 我将 vim 会话保持打开状态并切换回 master 分支 但是 当我尝试从缓冲区加载我需要的文件时 我
  • 如何更改每种语言的 vim 设置?

    我将 vim 与许多不同的语言 C C Java shell 等 一起使用 我知道 vim 已经为每种语言预设了设置 但我想根据我个人的喜好更改每种语言的设置 我已经有一个带有设置的 vimrc 文件 但我想要更多文件来根据我使用的语言声明
  • 如何在 Vim 中从命令行模式复制文本?

    比如说 我刚刚在 Vim 中运行了这个命令 nmap
  • Vim 中的空格作为制表符和退格键行为

    在我的 vimrc 中我有 set shiftwidth 4 set tabstop 4 set expandtab 当我点击 Tab 按钮时 设置为使用 4 个空格而不是 Tab 但是当我在 Tab 之后按退格键时 我需要退格所有 4 个
  • Vim / vi 生存指南

    基本的 vim 命令有哪些 新用户需要了解什么才能避免陷入麻烦 请每条评论一条命令 我发现不可替代的 因为它也可以在 vi 中使用 与 vim 的视觉模式不同 是标记 您可以用以下标记标记不同的点m 小写 然后是您选择的字母 例如 x 然后
  • 带有 Viper 和 Vimpulse 的 Emacs 缺少哪些 Vim 功能?

    Emacs 的一些重要功能在 Vim 中是缺失的 例如 comint 模式 并且没有脚本 插件可以替代它们 与 Emacs 相比 Vim 也有一些优点 例如模式编辑和通常更好的默认快捷键 然而 Viper 模式让我两者兼而有之 Vimpul
  • 使用 vim 重构目录中的类/方法/字符串的有效方法

    到目前为止 我一直在使用查找和替换操作手动重构代码 s stringiwanttoreplace newstring g in vim 但这是一个缓慢而费力的过程 如果我有的话字符串我想更换在特定目录内的许多文件中 我当前 典型的缓慢而费力
  • 禁用 VIM 中的警告?

    有没有办法禁用 VIM 中的警告 特别是 当文件从只读变为可写时 我想禁用警告 12 我有一个脚本可以打开文件进行编辑 但 vim 认为文件已更改并发出警告 Thanks 我的 vimrc 中有以下内容 你应该只需要第二个 它将消息回显到状
  • svn:使用vim合并冲突

    我正在尝试看看如何使 svn 中的合并变得容易 This page http svnbook red bean com en 1 7 svn advanced externaldifftools html提到可以使用外部工具进行合并 vim
  • Vim errorformat:在消息字符串中包含部分表达式

    使用vim的errorformat语法 有没有办法使用部分消息来过滤结果 例如 除了错误本身之外 某些链接器错误没有任何明确的内容将它们区分为线路上的错误 path to foo cpp 42 undefined reference to
  • vim 退出时恢复 shell

    我刚刚在我的新计算机上安装了 Arch 但我不知道需要向 vimrc 添加什么命令 以便它在退出时恢复 shell 内容 在调用 vim 之前 也就是说 我希望我的 shell 看起来像这样 whoami root who root tty
  • :set 选项的显示值

    如果你不给 colorscheme一个参数 然后它显示 vim 当前使用的颜色方案的名称 vim 中是否有类似的方法来显示是否设置了选项或如果选项的值不是布尔值则设置为什么 例如 如果我想知道是否autoindent已设置或者我想知道的值t
  • 文件类型更改时颜色方案也会更改

    当我打开 vim htm html xml 或 vimrc 文件时 是否可以更改 Vim 中的颜色方案 当我切换到具有上述扩展名的已打开文件时 也会更改颜色方案 这就是我想要我的 vim 做的事情 file txt 或新的 未保存 缓冲区
  • 如何使用 JSHint 配置 Syntastic?

    如何使用 Syntastic Vim 插件和 JSHint 来验证 JavaScript 代码 环境 乌班图11 04 VIM Vi 改进 7 3 我已经安装了 按照解决方案VIM JSLint https stackoverflow co
  • 如何在 Vimscript 中获取光标下的单词和当前行的文本?

    我正在写一个 Vim 脚本 如何获取光标下的单词和当前行的文本 你可以与expand https vimdoc sourceforge net htmldoc eval html expand and getline https vimdo
  • VIM:我如何知道关键字使用了哪个突出显示规则?

    colorscheme default 文件类型是php 谁能帮我找出突出显示规则 hi light 将列出所有定义的规则并进行预览 您还可以查询单个项目 hi Keyword 手动查找任何语法组在光标下 有选择 我的是一个绑定到键的函数

随机推荐