有没有办法改变quickfix列表的显示模式

问题描述 投票:1回答:1

我正在尝试使用grep和位置列表设置键绑定以生成当前文件的函数框架。由于我只扫描当前文件,因此每行开头的文件名是冗余的,并使输出的可读性降低。其次,默认显示模式在消息的乞讨时删除空白,删除有关函数嵌套的信息。

grepformat从默认的%f:%l:%m更改为%l:%m会删除位置列表中每行开头的文件名,但没有名称,它不知道查看当前文件,因此我无法跳转到不同的函数。

查看errorformatquickfix文档并未指出任何更改quickfix \位置列表显示模式的选项,据我所知。

这为功能位置列表提供了键绑定,但格式错误:

grepformat=%f:%l:%m
nnoremap <buffer> <leader>l :silent lgrep! function %<CR>:lopen<CR>

这提供了更好的格式化但非功能性的位置列表:

grepformat=%l:%m
nnoremap <buffer> <leader>l :silent lgrep! -h function %<CR>:lopen<CR>

请注意,-h grep选项会抑制输出中的文件名

原始grep输出几乎就是我希望代码格式化的方式:

1:function actigraphyCalculator(dirname)
69:     function [checkedFiles, metadata] = readQcData
75:    function fileContents = openFile(name, filePaths)
80:     function fileContents = qcprocessing(name, fileContents, metadata)
90:    function fileContents = removeBadDays(name, fileContents, metadata)
106:    function path = createSavePath(filepath)

唯一的问题是缩进是不一致的,不同的数字长度导致消息不能完美排列。

同一文件的位置列表的当前输出是:

calcActigraphy/actigraphyCalculator.m|1| function actigraphyCalculator(dirname)
calcActigraphy/actigraphyCalculator.m|69| function [checkedFiles, metadata] = readQcData
calcActigraphy/actigraphyCalculator.m|75| function fileContents = openFile(name, filePaths)
calcActigraphy/actigraphyCalculator.m|80| function fileContents = qcprocessing(name, fileContents, metadata)
calcActigraphy/actigraphyCalculator.m|90| function fileContents = removeBadDays(name, fileContents, metadata)

请注意消息开头缺少缩进。

vim neovim
1个回答
1
投票

您可以使用:help :syn-conceal隐藏quickfix列表中的文件名。它仍然在物理上(因此导航仍然有效),它不再显示。

我在how to format vim quickfix entry找到了基本的想法;这是我用它的映射(放入~/.vim/ftplugin/qf_conceal.vim

function! s:ToggleLocation()
    if ! v:count && &l:conceallevel != 0
        setlocal conceallevel=0
        silent! syntax clear qfLocation
    else
        setlocal concealcursor=nc
        silent! syntax clear qfLocation
        if v:count == 1
            " Hide file paths only.
            setlocal conceallevel=1
            " XXX: Couldn't find a way to integrate the concealment with the
            " existing "qfFileName" definition, and had to replace it. This will
            " persist when toggling off; only a new :setf qf will fix that.
            syntax match qfLocation /^\%([^/\\|]*[/\\]\)\+/ transparent conceal cchar=‥ nextgroup=qfFileName
            syntax clear qfFileName
            syntax match qfFileName /[^|]\+/ contained
        elseif v:count == 2
            " Hide entire filespec.
            setlocal conceallevel=2
            syntax match qfLocation /^[^|]*/ transparent conceal
        else
            " Hide filespec and location.
            setlocal conceallevel=2
            syntax match qfLocation /^[^|]*|[^|]*| / transparent conceal
        endif
    endif
endfunction
"[N]<LocalLeader>tf Toggle filespec and location to allow focusing on the
"           error text.
"           [N] = 1: Hide file paths only.
"           [N] = 2: Hide entire filespec.
"           [N] = 3: Hide filespec and location.
nnoremap <buffer> <silent> <LocalLeader>tf :<C-u>call <SID>ToggleLocation()<CR>
© www.soinside.com 2019 - 2024. All rights reserved.