vim -- 'go to previous buffer' broken - vim

In my vim and gvim the memory for previous buffer is not functioning properly. It did work well before but I cannot say when it started to misbehave.
If I have opened more than 2 files as buffers in one vim session, the command :b# always gets me back to the buffer which I have opened first (instead of getting me back to the previous buffer).
What might be the reason for this?
Interesting enough, if I delete a buffer, then:b# restores it.
I am on Ubuntu 14.04, my vim version is 7.4.52 and I have installed the bufexplorer plugin.

You should be using the bufexplorer issue tracker. To point you in the right direction; read :h edit-intro, specifically :h keepalt. Then take a look at the bufexplorer source code.

Related

What is difference between :o and :e in vim when using these command to load a file into the buffer?

I was watching an online tutorial by tutsplus , during one of the lessons, the teacher started to move between buffers using :bn :bn :b#, but he forget to mention how to load files into the buffer before talking about navigating between the buffers, I searched and find that using:e filename or :o filename would load a file into the buffer.
So, what is the difference , I can't understand the document explanation provide within vim.
The difference is that you shouldn't use :o, which is a useless artefact of vi compatibility, and use :e (or one of its alternative) instead.
From :help :o:
Vim does not support open mode, since it's not really useful. For those
situations where ":open" would start open mode Vim will leave Ex mode, which
allows executing the same commands, but updates the whole screen instead of
only one line.
Just… forget that command even exists.
FWIW, even the vi specification is pretty vague about what open mode is and does.

How to prevent directory listing of netrw to appear in buffer

I use vim netrw for opening/editing files through browsing the directory hierachy.
I also often open files browsing through the bufferlist with the :bn & :bp command.
So my questing is: Is there a way to prevent that the netrw directory listing appear when i switch the buffers with the :bn & :bp commands?
Marc
Netrw buffers have nobuflisted set by default which is supposed to prevent them from appearing in :ls or from being reachable via :bnext or :bprevious. For some reason, it works in my slightly outdated MacVim (7.4.52): the file listing is never displayed with :bn and :bp, but it doesn't work in my slightly less outdated GVim (7.4.131) where I experience the same issue as you. I never use file listing, though, so I had no idea about that bug before your question. And I just found out another bug where the contents of buffers replaced by the netrw listing are wiped out.
I'll try to upgrade to a more recent build, maybe you should too.

undo reloading new buffer with vim

I had a file open with gvim and it asked me if I wanted to reload the current buffer because it detected a newer version of the file. I accepted, but it turns out the new buffer is not what I want. Is there a way to recover the old buffer? The file on disk (and the swp file, which I viewed with vim -r) contains the new buffer) unfortunately.
If your buffer had fewer lines than the 'undoreload' settings, then its content will be stored in the undotree just before it was reloaded. This means, that a simple u or g- should get your buffer contents back. A plugin like my histwin plugin or the famous Gundo or undotree plugin could be helpful as well.
Note, this needs a Vim of at least version 7.3 or newer to work. Older Vims didn't store the buffer state on reloading.
Try u (undo; if you’ve made changes since reloading, repeat until the old version shows up).
I am in terminal Vim, but I don’t think that should make a difference here. I opened a test file with Vim in one terminal tab, went to a new tab and edited it there, saved that, switched back to the first tab, ran :e to reload the file, and then switched it back to the last version I had opened in the tab with u.
I have something like this is my .vimrc
" Backup stuff
set backupdir=~/.vim/backup
set directory=~/.vim/swap
set undodir=~/.vim/undo
I can help with cases like this were you accidentally overwrite your local changes and you want to find your old version of the file. Make sure to create the directories first to avoid errors on startup.

VIM refreshing buffer whenever I switch to it

I'm using VIM to edit files over SCP, so reading and writing files is a very slow process.
For some reason, whenever I switch to a buffer, VIM reads it from disk. The status bar says: ~#k.
I've disabled all autocommands in my .vimrc, and I have no autocommands for BufEnter anyway. Any idea what I might be missing?
Update: I found one culprit, a word-count macro which wasn't an auto-command. Now when I switch it's a tad faster but still slow. Status bar says ^Ww.
Update 2: I tried ZyX's answer below (Thanks!!). The results:
1) setting eventignore=all absolutely solves it; it's blazing fast. BUT
2) trying to debug it doesn't work for me.
I tried both :debug buffer scp-buffer-name and :debug wincmd p and got:
Entering Debug mode. Type "cont" to continue.
cmd: wincmd p
line 1: for m in filter(copy(fuf#getModeNames()), 'fuf#{v:val}#requiresOnCommandPre()')`
And then no matter what I typed (s, n, "cont"), that single line would just repeat. It's obviously related to the Fuzzy Finder plugin, which I do use quite a lot and is a key reason for me to use VIM. Any ideas?
Thanks again for your help. Much appreciated, XyZ!
ISSUE SOLVED: It was indeed Fuzzy Finder. It has a MRU-File mode which documentation notes may cause a performance issue when switching buffers. I disabled this mode and now VIM is fast again! Thanks!
First, test this behavior with set eventignore=all. If the problem gets fixed, try to switch to scp buffer using (be sure you have unset eventignore) debug buffer scp-buffer-name or debug wincmd p (depending on when you see the problem), it will open debug mode and you will be able to see all autocommands it is executing (use s[tep] or n[ext] to move to next command, see :h >next and :h >step for more details).

Vim (terminal) - copy to x clipboard and paste while suspeneded

I have vimx installed, so I can copy in vimx to the x clipboard by using "+y and the like, which works well as long as I can keep the current vimx running.
However, I also love to be able to switch to the current running shell with ctrl-z and be able to paste what I copied from vim into the shell. Does anyone know how to do this, because as soon as I suspend vim with ctr-z the x-clipboard becomes empty, until I put vim into the fg again.
ok,
After about an hour of head bashing this issue, I have decided to use a different approach to do the same thing.
I will detail what I did here for the benefit of those with the same issue.
If you have wxcopy on your system that is enough to get copy/paste support on your system between vim and other apps. If you want to copy from vim, select the text using v or V or whatever method you prefer, then use the command :tee >(wxcopy). This will copy that code into the oldschool X11 cut buffer. This buffer has the added bonus of not requiring the parent application to be running for pasting to work, hence my problem goes away.
I realize it may be hard to get your hands on wxcopy, under fedora the package that provides it is:
WindowMaker
This isn't an answer as much as a push in the right direction, but start here:
:help quoteplus
:help x11-cut-buffer
Specifically the second help text has some interesting notes about suspending vim. It claims to write the buffer into PRIMARY and CUT_BUFFER0 so you can still use middle click after you've suspended. Maybe you've deleted those or a plugin is interfering? Maybe you are running an old version of vim (I'm running 7.2.182).
My suggestion is to disable all plugins you've manually installed and try vanilla vim. If that doesn't work, consider using vim's -V (verbose) flag and see if it will try to put the buffer into PRIMARY or CUT_BUFFER0 before it actually gets suspended.
I don't have vim compiled with X (vimx) so I can't actually test this myself. Hopefully that gets you in the right direction.

Resources