如何格式化 Vim 快速修复条目? [英] How to format Vim quickfix entries?

查看:23
本文介绍了如何格式化 Vim 快速修复条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是生成 Markdown 大纲的 vim 脚本:

This is the vim-script to generate Markdown outline:

fun! TOC()
    call setloclist(0, [])
    let save_cursor = getpos(".")
    call cursor(1, 1)
    while search("^#", 'W') > 0
       let msg = printf('%s:%d:%s', expand('%'), line('.'), substitute(getline('.'), '#', '»', 'g'))
       laddexpr msg
    endwhile
    call setpos('.', save_cursor)
endfun

com! -bar TOC call TOC()

<小时>

示例降价文件:https://github.com/progit/progit/raw/master/zh/01-introduction/01-chapter1.markdown

运行:TOC命令后,这是快速列表:

After running :TOC command, this is quick list:

01-chapter1.markdown|5| »» 关于版本控制 »»
01-chapter1.markdown|11| »»» 本地版本控制系统 »»»
01-chapter1.markdown|22| »»» 集中化的版本控制系统 »»»
01-chapter1.markdown|33| »»» 分布式版本控制系统 »»»
01-chapter1.markdown|42| »» Git 简史 »»
01-chapter1.markdown|56| »» Git 基础 »»
01-chapter1.markdown|60| »»» 直接记录快照,而非差异比较 »»»
01-chapter1.markdown|74| »»» 近乎所有操作都是本地执行 »»»
01-chapter1.markdown|82| »»» 时刻保持数据完整性 »»»
01-chapter1.markdown|92| »»» 多数操作仅添加数据 »»»
01-chapter1.markdown|98| »»» 文件的三种状态 »»»
01-chapter1.markdown|121| »» 安装 Git »»
01-chapter1.markdown|125| »»» 从源代码安装 »»»
01-chapter1.markdown|152| »»» 在 Linux 上安装 »»»
01-chapter1.markdown|162| »»» 在 Mac 上安装 »»»
01-chapter1.markdown|177| »»» 在 Windows 上安装 »»»
01-chapter1.markdown|185| »» 初次运行 Git 前的配置 »»
01-chapter1.markdown|197| »»» 用户信息 »»»
01-chapter1.markdown|206| »»» 文本编辑器 »»»
01-chapter1.markdown|212| »»» 差异分析工具 »»»
01-chapter1.markdown|220| »»» 查看配置信息 »»»
01-chapter1.markdown|240| »» 获取帮助 »»
01-chapter1.markdown|254| »» 小结 »»

<小时>

我想将快速修复条目格式化为:


I want to format the quick fix entries to this:

|005| »» 关于版本控制 »»
|011| »»» 本地版本控制系统 »»»
|022| »»» 集中化的版本控制系统 »»»
|033| »»» 分布式版本控制系统 »»»
|042| »» Git 简史 »»
|056| »» Git 基础 »»
|060| »»» 直接记录快照,而非差异比较 »»»
|074| »»» 近乎所有操作都是本地执行 »»»
|082| »»» 时刻保持数据完整性 »»»
|092| »»» 多数操作仅添加数据 »»»
|098| »»» 文件的三种状态 »»»
|121| »» 安装 Git »»
|125| »»» 从源代码安装 »»»
|152| »»» 在 Linux 上安装 »»»
|162| »»» 在 Mac 上安装 »»»
|177| »»» 在 Windows 上安装 »»»
|185| »» 初次运行 Git 前的配置 »»
|197| »»» 用户信息 »»»
|206| »»» 文本编辑器 »»»
|212| »»» 差异分析工具 »»»
|220| »»» 查看配置信息 »»»
|240| »» 获取帮助 »»
|254| »» 小结 »»

我找不到任何选项来做到这一点.如果你知道,请告诉我.谢谢!

I cannot find any option to do it. If you known, please tell me. Thanks!

推荐答案

无法配置 quickfix 位置的方式显示.只能通过以下方式指定如何解释它们errorformat 选项.但是,可以使用隐藏功能在 quickfix 或位置列表窗口中隐藏文件名.

It is not possible to configure the way quickfix locations are displayed. It is only possible to specify how to interpret them via the errorformat option. However, one can use the conceal feature to hide filenames in the quickfix or a location list window.

以下命令启用隐藏并定义语法规则匹配第一行之前行首的任何文本| 字符.

The following commands enable concealing and define a syntax rule matching any text at the beginning of a line before the first | character.

:set conceallevel=2 concealcursor=nc
:syntax match qfFileName /^[^|]*/ transparent conceal

可以为每个快速修复或位置列表触发这些命令使用自动命令的窗口.然而,总的来说,这不是一个好主意,因为在大多数情况下显示文件名是一个有用的功能.

One can trigger these commands for every quickfix or location list window using an auto-command. Yet, it is not a good idea in general, since in most cases displaying filenames is a useful feature.

对于问题中提出的案例,最好使这些仅针对新收集的位置列表进行自定义.这个需要不过,请先打开位置列表窗口.

For the case presented in the question, it is better to make these customizations only for the newly collected location list. It requires opening the location list window first, though.

:lopen
:set conceallevel=2 concealcursor=nc
:syntax match qfFileName /^[^|]*/ transparent conceal

这篇关于如何格式化 Vim 快速修复条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆