有没有办法改变快速修复列表的显示模式
Is there a way to change display pattern of quickfix list
我正在尝试设置一个键绑定,以使用 grep 和位置列表生成当前文件的功能框架。由于我只扫描当前文件,因此每行开头的文件名都是多余的,并且使输出的可读性降低。其次,默认显示模式会删除消息开头的空格,从而删除有关函数嵌套的信息。
将 grepformat
从默认的 %f:%l:%m
更改为 %l:%m
会删除位置列表中每行开头的文件名,但没有它不知道要查找的名称当前文件,所以我不能跳转到不同的函数。
据我所知,查看 errorformat
和 quickfix
文档并未指出任何更改 quickfix\location 列表显示模式的选项。
这为功能位置列表提供了键绑定,但格式不正确:
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)
请注意邮件开头没有缩进。
您可以使用 :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>
我正在尝试设置一个键绑定,以使用 grep 和位置列表生成当前文件的功能框架。由于我只扫描当前文件,因此每行开头的文件名都是多余的,并且使输出的可读性降低。其次,默认显示模式会删除消息开头的空格,从而删除有关函数嵌套的信息。
将 grepformat
从默认的 %f:%l:%m
更改为 %l:%m
会删除位置列表中每行开头的文件名,但没有它不知道要查找的名称当前文件,所以我不能跳转到不同的函数。
据我所知,查看 errorformat
和 quickfix
文档并未指出任何更改 quickfix\location 列表显示模式的选项。
这为功能位置列表提供了键绑定,但格式不正确:
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)
请注意邮件开头没有缩进。
您可以使用 :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>