I find myself opening files inside the wrong window in Vim — sometimes the NERDTree or MiniBuffExplorer — and it’s really throwing me off.
I’m sure it’s happening because my cursor is mistakenly focused inside one of these windows, but is there anything I can add to my .vimrc file to prevent this from happening?
I finally found the solution to this annoyance in the MiniBufExplorer source comments. It looks like this feature has been available since version 6.2.8 (release 2004-06-07):
If you use other explorers like TagList you can (As of 6.2.8) put:
let g:miniBufExplModSelTarget = 1
into your .vimrc in order to force MBE to try to place selected
buffers into a window that does not have a nonmodifiable buffer.
The upshot of this should be that if you go into MBE and select
a buffer, the buffer should not show up in a window that is
hosting an explorer.
It's possibly related to the setting of mousefocus. From :help mousefocus
The window that the mouse pointer is
on is automatically activated. When
changing the window layout or window
focus in another way, the mouse
pointer is moved to the window with
keyboard focus. Off is the default
because it makes using the pull down
menus a little goofy, as a pointer
transit may activate a window
unintentionally.
Related
I am just getting started using Vim and came across :set mouse=a which I've found really useful for navigating a file, however for some reason when I try and scroll now it scrolls the whole terminal window and not just the vim window.
Then I scroll up and can see the terminal outside Vim
Any ideas on how to fix this? I've tried resetting mouse= and exiting and re entering vim.
The problem was that I had accidentally disabled Allow Mouse Reporting in error.
Checking Menu > View > Allow Mouse Reporting or Cmd + R has fixed it!
I think the cheap answer to your question is that you should be navigating through files in vim using motion commands, Ctrl + d, etc. It might seem slow at first, but it really becomes more natural down the line.
That said, if you are on Mac and using Terminal, you might need to hold the Fn to temporarily disable mouse support. (Check this out for reference: OS X Terminal Mouse Support
Also, you can always try MacVim, which supports mouse scrolling out of the box.
If neither of those solutions work for you, some more information would be helpful for troubleshooting, e.g., your operating system, recent changes to your vimrc, etc.
I am aware that the mousefocus option is only supposed to work in gVim. But I was wondering, if it's possible to have the console Vim switch to different windows in response to mouse clicks, would it be not possible to easily add following mouse movement to it, too?
I'm an xmonad user, I love the focus following the pointer feature, I do a lot of pdf viewing and browsing while writing in Vim, and I'd be so much happier if I didn't have to keep mentally switching back and forth between two different types of focus changing.
If that's completely not possible, I guess opening new Vim windows (as with :split) in new instances of the terminal is no easier to do?
It would not be at all simple to add this. Using the mouse within the terminal works by vim sending control codes to the terminal requesting that mouse actions be sent as part of the input stream. Terminals only report clicks not changes in the pointer position, so vim has no way of knowing where the mouse is.
With major changes it would likely be possible for a vim with X support to get pointer activity directly from the X server, but that would likely be reported by pixel rather than by character so further work would need to be done before it could determine which vim window is currently under the pointer.
set mouse=a
should do the trick but it will probably depend on your terminal emulator. See :help 'mouse'.
This works for Windows 7/Cygwin 32bit mintty/vim 7.3: (I DO NOT use gvim!)
Having installed this: http://ehiti.de/katmouse/, I can scroll the window under my cursor without having to have clicked to select a window, click-selecting of single vim-windows works, too. It does not pull the vim window to the foreground, if another window overlaps it, if that is what you desire. Still it can be scrolled without click-selecting it first.
So:
Check if there exists a software paket for your distribution, that implements your desired mouse behavior on the OS level. When this works for my self-compiled vim in cygwin, it might very well work with console vim on linux, too.
This post here serves as evidence, that it is possible at all, that is the reason this was not made a comment. When I am on linux again I will investigate this further and update this post, but that might take a while.
On set mouse=a: The vim help states you a need a terminal capable of handling mouse inputs, further information can be found here. :help ttymouse might also be helpful, i.e. if you have a xterm-compliant console, but :help term is set to something else.
UPDATE: (Freshly installed Fedora 19 with packages, no self-compiled stuff.)
Fedora 19 + se mouse=a = scrolling in single console vim window with several buffers opened next to each other independently works, too. Window manager used is LXDE.
I've searched for different types of workarounds to deal with the preview window splitting the current window to display documentation when doing a selection in Omnicompletion, like closing the preview window if it exists when you leave insert mode.
However, those solutions are impractical. Sometimes you may want to go into the preview window to read some documentation about the current completing module, but with the autocommand in place this would not be possible.
Even if it would, I am looking to have the documentation never show up because I really don't want it.
Reading the source code in pythoncomplete.vim I see that the value for the documentation is hard coded and it will force the preview window to show up if this has any contents (it skips this if it can't come up with docs for the module).
Is there a global option that I am not aware to tell Vim to never display docs? Or be able to toggle it?
If I do want to read the docs in a split window allow me to do so (maybe with some shortcut) otherwise don't show me anything.
I really want to avoid having to copy/paste pythoncomplete.vim to tweak this particular setting to my liking.
The preview is controlled by the global 'completeopt' setting. To turn that off, use
:set completeopt-=preview
I know that using a command like:
:%bdelete
Using this command I can close all buffers, in all tabs, what I'd like to do is to close all buffers open in the current tab, is that possible?
Usage:
What I'd like to do, is to open ViM and load :VSTreeExplorer and then open related files in the same window switching between them using :next and :previous and then open other files a new tab (with VSTreeExplorer as well), when I need to clean one of the tabs, I would like to use whatever command that closes buffers in the current tab.
For now, what I do is use :%bd and then open the VSTreeExplorer and start over...
Thanks
If you're done with a tab you can just use :tabclose.
:windo bd will delete all buffers in the current tab.
Buffers are global to the Vim instance, not confined to a specific tab page. A tab page is simply a way to organize windows and windows are simply a way to display a buffer. Zero or more windows (and therefore tab pages) can display the same buffer. Getting used to this concept should help your workflow in Vim.
The Vim wiki has a couple pages that give some more explanation and tips for using tab pages.
I've been forcing myself to use gvim for Windows for much of my text editing needs. I'm gradually growing more comfortable with it, but one problem has been annoying me greatly.
I use the project plugin to keep a window up on the left side of my gVim screen, listing my projects. It's handy and keeps me from going into IDE withdraw. Here's an idea of what it looks like:
I then invoke NERDTree on the right side with <Leader>][:
I then navigate through NERDTree to find whatever I was looking for, and dismiss NERDTree with <Leader>][. This makes the NERDTree window go away, but rather than put the main window back to the size it was, it grows the project window instead:
Right now I manually resize the project window, but that really interrupts the flow I'm trying to achieve with vim.
I'm using gvim 7.2, NERDTree 3.1.1, and project 1.4.1. Anyone have any ideas how to fix this?
UPDATE: Based on Steve K's answer I've figured out the solution. When you run the :Project command and it creates the project window, the project window is the active one. So I just added set winfixwidth to my .vimrc after :Project, and that solved the problem. Now I can show and hide NERDtree to my heart's content with no annoying window resizing.
With the cursor inside the left most project window, do
:set winfixwidth
I think that will do it for you.