vim 快速修复列表:操纵位置?
vim quickfix list: manipulate location?
当我使用 vim 时,我偶尔会遇到这样的拆分菜单设置:
###############################################
# | | #
# | | #
# NERDTree | main window | tagbar #
# | | #
# | | #
###############################################
即使 tagbar 关闭,我也可能会得到类似的设置,例如当我比较不同的文件时。
然而,当我执行 vimgrep 命令时,结果(显示在 quickfix 列表中)仅显示在主 window 下方,而标签栏(或右侧的其他拆分)是已关闭。
因此,此设置每次都能正常工作:
###############################################
# | #
# | #
# NERDTree | main window #
# | #
# | #
# |__________________________________#
# | #
# | quickfix list: vimgrep results #
# | #
###############################################
...虽然这不是:
###############################################
# | | #
# | | #
# NERDTree | main window | tagbar #
# | | #
# | |________#
# | | quick- #
# | | fix #
# | | list: #
# | | vimgrep#
# | | results#
###############################################
如何强制快速修复列表始终在 window 下面打开(包含 vimgrep 结果)?
目前它刚刚正确打开(在主 window 下方)如果 - 并且仅当 - 主 window 右侧没有其他拆分 window。
如果主 window 右侧存在任何拆分,vimgrep 命令总是在那里打开 quickfix :/
我已经使用 vimgrep 命令搜索当前光标下的词(在整个文件中搜索这个词):
nnoremap some-key :execute "vimgrep /\<" . expand("<cword>") . "\>/j ".expand("%") <Bar> cw<CR>
...只是为了展示我在用 vimgrep 做什么。
遗憾的是 Vim 没有 project drawer 的概念,只有 windows(拆分)。使用命令打开 Quickfix 列表后,例如:copen
或 :cwindow
,最好先关闭再打开 NerdTree 和 Tagbar。像这样:
command! Copen copen|NERDTreeToggle|TagbarClose|TagbarOpen
注意:我没有测试这个命令,因为我没有 NERDTree 或 Tagbar 插件。这也集中了标签栏 window,这可能是不需要的。
或者,您可能希望通过关闭 tagbar 和 nerdtree 来简化您的工作流程,除非您正在使用它们。这对于某些工作流来说很有意义,因为需要查看标签或文件结构的情况相对不常见(可能只有 10% 的时间)。对于标签,您可以完全避免标签栏并直接使用 :tag
命令,或者如果您在符号上,则使用 <c-]>
。 Nerdtree 可以像 netrw 一样使用来避免这个问题(见 Oil and vinegar - split windows and the project drawer). I talk about these issues in the post: Files, Buffers, and Splits Oh My!
就我个人而言,我不使用 NerdTree、Tagbar 或任何类似的东西。我更喜欢一次打开 1-2 个拆分。我使用 projectionist.vim, a fuzzy finder like CtrlP、:find
,或者如果我真的必须使用 netrw。
您可以在 .vimrc
:
中使用此代码强制 quickfix
全宽打开
augroup DragQuickfixWindowDown
autocmd!
autocmd FileType qf wincmd J
augroup end
现在是要求的内容,但它已经尽可能接近了。
我找到了一个很好的解决方案here,只需将下面的文本放入您的 vimrc 中即可。它会始终将 quickfix window 全宽移动到屏幕底部,而不会影响其他 quickfix 内容。
" Position the (global) quickfix window at the very bottom of the window
" (useful for making sure that it appears underneath splits)
"
" NOTE: Using a check here to make sure that window-specific location-lists
" aren't effected, as they use the same `FileType` as quickfix-lists.
autocmd FileType qf if (getwininfo(win_getid())[0].loclist != 1) | wincmd J | endif
当我使用 vim 时,我偶尔会遇到这样的拆分菜单设置:
###############################################
# | | #
# | | #
# NERDTree | main window | tagbar #
# | | #
# | | #
###############################################
即使 tagbar 关闭,我也可能会得到类似的设置,例如当我比较不同的文件时。
然而,当我执行 vimgrep 命令时,结果(显示在 quickfix 列表中)仅显示在主 window 下方,而标签栏(或右侧的其他拆分)是已关闭。
因此,此设置每次都能正常工作:
###############################################
# | #
# | #
# NERDTree | main window #
# | #
# | #
# |__________________________________#
# | #
# | quickfix list: vimgrep results #
# | #
###############################################
...虽然这不是:
###############################################
# | | #
# | | #
# NERDTree | main window | tagbar #
# | | #
# | |________#
# | | quick- #
# | | fix #
# | | list: #
# | | vimgrep#
# | | results#
###############################################
如何强制快速修复列表始终在 window 下面打开(包含 vimgrep 结果)?
目前它刚刚正确打开(在主 window 下方)如果 - 并且仅当 - 主 window 右侧没有其他拆分 window。 如果主 window 右侧存在任何拆分,vimgrep 命令总是在那里打开 quickfix :/
我已经使用 vimgrep 命令搜索当前光标下的词(在整个文件中搜索这个词):
nnoremap some-key :execute "vimgrep /\<" . expand("<cword>") . "\>/j ".expand("%") <Bar> cw<CR>
...只是为了展示我在用 vimgrep 做什么。
遗憾的是 Vim 没有 project drawer 的概念,只有 windows(拆分)。使用命令打开 Quickfix 列表后,例如:copen
或 :cwindow
,最好先关闭再打开 NerdTree 和 Tagbar。像这样:
command! Copen copen|NERDTreeToggle|TagbarClose|TagbarOpen
注意:我没有测试这个命令,因为我没有 NERDTree 或 Tagbar 插件。这也集中了标签栏 window,这可能是不需要的。
或者,您可能希望通过关闭 tagbar 和 nerdtree 来简化您的工作流程,除非您正在使用它们。这对于某些工作流来说很有意义,因为需要查看标签或文件结构的情况相对不常见(可能只有 10% 的时间)。对于标签,您可以完全避免标签栏并直接使用 :tag
命令,或者如果您在符号上,则使用 <c-]>
。 Nerdtree 可以像 netrw 一样使用来避免这个问题(见 Oil and vinegar - split windows and the project drawer). I talk about these issues in the post: Files, Buffers, and Splits Oh My!
就我个人而言,我不使用 NerdTree、Tagbar 或任何类似的东西。我更喜欢一次打开 1-2 个拆分。我使用 projectionist.vim, a fuzzy finder like CtrlP、:find
,或者如果我真的必须使用 netrw。
您可以在 .vimrc
:
quickfix
全宽打开
augroup DragQuickfixWindowDown
autocmd!
autocmd FileType qf wincmd J
augroup end
现在是要求的内容,但它已经尽可能接近了。
我找到了一个很好的解决方案here,只需将下面的文本放入您的 vimrc 中即可。它会始终将 quickfix window 全宽移动到屏幕底部,而不会影响其他 quickfix 内容。
" Position the (global) quickfix window at the very bottom of the window
" (useful for making sure that it appears underneath splits)
"
" NOTE: Using a check here to make sure that window-specific location-lists
" aren't effected, as they use the same `FileType` as quickfix-lists.
autocmd FileType qf if (getwininfo(win_getid())[0].loclist != 1) | wincmd J | endif