Vim ctags:我们可以在不关闭 taglist 窗口的情况下在 taglist 窗口和源代码窗口之间切换焦点吗?

Posted

技术标签:

【中文标题】Vim ctags:我们可以在不关闭 taglist 窗口的情况下在 taglist 窗口和源代码窗口之间切换焦点吗?【英文标题】:Vim ctags: can we toggle focus between taglist window and source code window without closing the taglist window? 【发布时间】:2016-01-19 11:33:56 【问题描述】:

我在 linux 上使用 ctags 和 vim。

只要我在任何标签上按 Enter,焦点就会转到源代码窗口,为了重新关注 taglist 窗口,我必须做两次 :TlistToggle(变量 'Tlist_GainFocus_On_ToggleOpen' set to 1)——这基本上关闭 taglist 窗口并再次打开它并获得焦点。

我只是好奇我们是否可以在不关闭 taglist 窗口的情况下在 taglist 窗口和源窗口之间切换焦点?

【问题讨论】:

尽管已经发布了答案,但我投票决定将此问题作为离题结束,因为它与编程无关。应移至vi.stackexchange.com。 【参考方案1】:
:help window

...给出关于 Vim 窗口的章节,与

:help window-move-cursor

...成为您正在寻找的子章节:

4. Moving cursor to other windows           *window-move-cursor*

CTRL-W <Down>                   *CTRL-W_<Down>*
CTRL-W CTRL-J                   *CTRL-W_CTRL-J* *CTRL-W_j*
CTRL-W j    Move cursor to Nth window below current one.  Uses the cursor
        position to select between alternatives.

CTRL-W <Up>                 *CTRL-W_<Up>*
CTRL-W CTRL-K                   *CTRL-W_CTRL-K* *CTRL-W_k*
CTRL-W k    Move cursor to Nth window above current one.  Uses the cursor
        position to select between alternatives.

CTRL-W <Left>                   *CTRL-W_<Left>*
CTRL-W CTRL-H                   *CTRL-W_CTRL-H*
CTRL-W <BS>                 *CTRL-W_<BS>* *CTRL-W_h*
CTRL-W h    Move cursor to Nth window left of current one.  Uses the
        cursor position to select between alternatives.

CTRL-W <Right>                  *CTRL-W_<Right>*
CTRL-W CTRL-L                   *CTRL-W_CTRL-L* *CTRL-W_l*
CTRL-W l    Move cursor to Nth window right of current one.  Uses the
        cursor position to select between alternatives.

CTRL-W w                    *CTRL-W_w* *CTRL-W_CTRL-W*
CTRL-W CTRL-W   Without count: move cursor to window below/right of the
        current one.  If there is no window below or right, go to
        top-left window.
        With count: go to Nth window (windows are numbered from
        top-left to bottom-right).  To obtain the window number see
        |bufwinnr()| and |winnr()|.  When N is larger than the number
        of windows go to the last window.

                        *CTRL-W_W*
CTRL-W W    Without count: move cursor to window above/left of current
        one.  If there is no window above or left, go to bottom-right
        window.  With count: go to Nth window, like with CTRL-W w.

CTRL-W t                    *CTRL-W_t* *CTRL-W_CTRL-T*
CTRL-W CTRL-T   Move cursor to top-left window.

CTRL-W b                    *CTRL-W_b* *CTRL-W_CTRL-B*
CTRL-W CTRL-B   Move cursor to bottom-right window.

CTRL-W p                    *CTRL-W_p* *CTRL-W_CTRL-P*
CTRL-W CTRL-P   Go to previous (last accessed) window.

                        *CTRL-W_P* *E441*
CTRL-W P    Go to preview window.  When there is no preview window this is
        an error.
        not available when compiled without the |+quickfix| feature

If Visual mode is active and the new window is not for the same buffer, the
Visual mode is ended.  If the window is on the same buffer, the cursor
position is set to keep the same Visual area selected.

                        *:winc* *:wincmd*
These commands can also be executed with ":wincmd":

:[count]winc[md] arg
        Like executing CTRL-W [count] arg.  Example: >
            :wincmd j
<       Moves to the window below the current one.
        This command is useful when a Normal mode cannot be used (for
        the |CursorHold| autocommand event).  Or when a Normal mode
        command is inconvenient.
        The count can also be a window number.  Example: >
            :exe nr . "wincmd w"
<       This goes to window "nr".

话虽如此,通过启用鼠标支持 (set mouse=a),您只需左键单击您希望光标所在的位置(并拖动窗口边框,然后...)

【讨论】:

@Yogesh:没问题。元答案:使用 Vim :help 函数。内置文档是Good,大写“G”。【参考方案2】:

这不就是TlistOpen的目的吗?

否则,如果taglist窗口有一个可以识别的名字,你可以用let b = bufwinnr(the_buffer_name_or_id)提取窗口号,用exe b.'wincmd w'跳转到它。您可能需要使用 let buf_id = filter(range(1,bufnr('$')), 'v:val =~ "THEPATTERN"'))

之类的内容搜索正确的缓冲区

【讨论】:

以上是关于Vim ctags:我们可以在不关闭 taglist 窗口的情况下在 taglist 窗口和源代码窗口之间切换焦点吗?的主要内容,如果未能解决你的问题,请参考以下文章

linux ctags

关于VIM的ctags的问题,在一个文件夹里面用了ctags -R 后,是否里面的所有子文件夹都有tags文件。

vim的配置——ctags

ctags and vim

ctags 和Makefile的简单使用

Centos 中 vim 的配置