在错误的vim窗口中忽略特定命令

3

我经常会在快速修复、nerdtree或其他特殊窗口中按下Ctrl-O,以为自己在主窗口中。我想做的是回到我的主窗口中之前的位置。我还倾向于在我的快速修复窗口中打开bufexplorer,这会导致一些非常奇怪的问题。

有没有一种简单的方法可以在某些类型的缓冲区中忽略某些命令?

3个回答

2
你可以将某些内容映射到<NOP> (无操作),例如在netrw中 (:e .)。
nnoremap <C-o> <NOP>
"<C-o> no longer works

当然,这将取决于具体情况。结合文件类型和autocommands中的<buffer>,可以得到良好的结果。

谢谢,这个方法对于nerdtree来说有效。但是我还没有完全让它在quickfix窗口中起作用,因为当打开quickfix窗口时,它不算作bufenter。如果我离开并重新进入quickfix窗口,它就可以工作了。以下是我的.vimrc文件中的代码:au BufEnter NERD_tree_* map au BufEnter NERD_tree_* map au BufEnter * call TurnOffQFCommands() au BufEnter * call TurnOffQFCommands() function! TurnOffQFCommands() if &ft=="qf" map map endif endfunction - notid

1

<C-w>p 可以让你跳转到前一个窗口。


0

如果要在跳回之后向前跳转,可以按下Ctrl+I

来自vim wiki - 跳转到先前访问的位置

Like a web browser, you can go back, then forward:

 Press Ctrl-O to jump back to the previous (older) location.
 Press Ctrl-I (same as Tab) to jump forward to the next (newer) location.

Display the jump list for the current window with:

:jumps

Your current location in the jump list is indicated with '>', and the first number in each row is a count that can be used to jump to that position. For example, after pressing Ctrl-O three times, the :jumps command may show something like this:

 jump line  col file/text
   4   102    0 somefile.txt
   3    93    0 -invalid-
   2    23    0 the current line 23 is shown here
   1    89   34 the current line 89 is shown here
>  0    22   40 Display the jump list for the current window with:
   1    39    0 the current line 39 is shown here
   2   995    0 anotherfile.txt
   3    53  102 the current line 53 is shown here

Given the above, you could press:

Ctrl-I to jump to line 39 in the current buffer.
Ctrl-O to jump to line 89 in the current buffer.
4 then Ctrl-O to jump to line 102 in file somefile.txt.
3 then Ctrl-I to jump to line 53 in the current buffer.

In the example above: The last line was added to the jump list when the first Ctrl-O was pressed (so you can return to the initial position: line 53, column 102). Line 93 in the current buffer no longer exists (the jump location is invalid).


抱歉,我表达不够清晰。我知道如何在历史记录中前后切换。只是我想忽略或重定向这些命令到正确的窗口。感谢您的帮助。 - notid
@notid 啊,我的错误。虽然我不认为可以重新映射vim命令以在多个窗口中工作,但我希望我对此是错误的,为了你的利益)。 - chown

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接