I started using NERDTree recently.
When I opened a file while having split window, the window of a new file was not I intended.
Consequently, I had lost my unsaved buffer by opening a file.
Is there any way to undo opening files or reopen my unsaved buffer?
You can go back to the previous file in a buffer using Ctrl6.
You haven't lost anything (yet), the buffer was hidden. Since it is the alternate buffer of that window, you can just switch back via <C-^>. You'll also find it in the buffer list of :ls (with a h prefix for hidden), from which you can re-edit it via its buffer number, e.g. :buffer 42 or :sbuf 42.
If there are unsaved changes, Vim will prompt you on :quit (unless you provide a ! to it).
Related
Vim newbie here.
I use :find command to open a file and make some changes.
Suppose I want to open another file without saving the current changes, then how should I do it.
What is the best way to list all open files and quickly open them again for editing.
Thanks in advance.
:e! filename
will allow you to open a named file in a new buffer (note the exclamation mark overrides the warning re. an unsaved file).
CTRL-W + cursor
will move between visible buffers and does not enforce the saving of your file as you navigate.
:buffers
will list your open buffers and allow you to navigate to each one (albeit with some cryptic flags indicating which buffers are visible/hidden/amended etc.)
:help buffers
will tell you about all the buffer-related features.
:help :wincmd
will tell you all about windows navigations
See also the VIM buffer FAQ
I first open a directory in Vim. Then I browse it and open a file. After I'm done with a file, I close it, whether by :w or :bd or :q -- doesn't matter, and I expect to come back the same buffer where I were initially -- the directory. But when I close the file, it also quits Vim. How can I just close that file and return to the initial buffer with the directory?
:w should be :wq.
Anyway, you don't need to "close" that buffer. Just go back to the file listing with :b#, or <C-^>, or :Rex[plore].
If you absolutely need to "close" that buffer you can go back to the listing with :b# (# represents the previous buffer) and close that unwanted buffer with :bd#. In short:
:b#|bd#
Sometime when I open file and open buffer list :ls my buffer list is empty even when I had some open files before.
Then I have to quit vim and open again to get buffers works.
Is the way to restart/reload vim without closing window?
For now I know that it usually happens when I close buffer by :bd or :BD(bfkill) or maybe it can be related with closing open split window.
This is my vimrc: https://gist.github.com/1791434
My guess is you might have bufhidden set to unload, delete or wipeout
Check that with
:verbose set bufhidden
Assuming that I have two buffers. One is NERDTree, the other is an actually file I'm editing. I accidentally open an another file from NERDTree and the new file hides the previous file I was editing.
A similar case occurs whether I use NERDTree or not.
How can I bring back the previous state by opening the mostly recently hidden file? I'm using the word "hide" because this is probably not "closing".
I use ctrl-6 to switch back to the previous buffer in the window.
I am using FuzzyFinder with Vim to open files and switch between buffers. It works like a charm except when the current file I am working on has some changes. Vim wouldn't let me switch the buffer till I save it:
"E37: No write since last change (add ! to override)".
Is there a way of suppressing this warning unless I am quitting the editor? All I want to do it switch to a different buffer for referencing some code and switch back.
I think you can use :set hidden.
Use the :set hidden option and Vim will hide the buffer until you come back to it.
You can also use :set confirm to deal with the unsaved buffer warning more conveniently.