having buffers list as quickfix window in vim editor? - vim

Using vim editor, a common task is to browse buffers.
I now use standard commands like :ls or a :cnext
I would like to browse buffers as list in quickfix window,
in the simple (=excellent) way MRU plugin (https://github.com/yegappan/mru) implement.
There is a plugin simple as MRU files but acting on buffers ?
OK, a possible solution could be to use :CtrlpBuffers command, part of Ctrlp plugin (https://github.com/kien/ctrlp.vim) but I'm not a big fan of Ctrlp, that have sometime beahviours I do not fully understand (the fuzzy choices...); so I'm look for something really simple as MRU plugin.
BTW, I joked with :cexpr {expr} command, trying populate the quickfix windows with content of :buffers list, without success (maybe because my ignorance programming vimscripts)
Any suggestion ?
thanks
giorgio

Have a look at the bufexplorer plugin. It opens a browsable list of all buffers in a sidebar, similar to the mentioned MRU plugin. Also, there are several more such plugins on vim.org.

Related

Vim: file system navigation similar to Spacemacs

I'm currently going back to Vim from Spacemacs. Is there a plugin that offers a similar way to search / open files? In Spacemacs you can easily navigate the file system after pressing SPC-f-f.
You can see an example here. I really like how it shows a list of the files and directories under the current directory.
If you can live without as-you-type fuzzy-completion, the built-in :help 'wildmenu' works beautifully.
If you absolutely need as-you-type fuzzy-completion there are many plugins to choose from:
Fzf
CtrlP
Command-t
FuzzyFinder
Unite
etc.

Vim and NERDTree - Clear [No name] from buffers

I am new to Vim and NERDTree, and I am trying to understand why a buffer appears as [No name] after I delete it using :bd. I want to keep my NERDTree clean so I wonder if there is a way to remove the [No name].
For example,
The l.py file is the one I am working on, and the [No name] ones are the files that I already closed (with :bd). I don't want them to show up at all because it looks messy.
Thanks!
I doubt NerdTree is putting buffers into your status line. I imagine some status line plugin like vim-airline. It would probably be best to look at your status line plugin's documentation for how to make customizations or submit an issue on the plugin's bug tracker.
We need to talk...
The biggest problem I see is that you are trying to use the status line as a makeshift "tab bar". Most other editors use a tab bar as a way to manage documents, but not Vim. This makeshift "tab bar" is probably a bad idea once you start using more files or more complicated workflows with splits or tabs (Vim's tabs are different).
Oh yeah? What about Buftabline, Airline, BufTabs, MiniBufExpl, ...?
All these plugins do is show you your currently listed buffers. Maybe with some kind of positioning information so that you feel comfortable cycling via :bnext and :bprevious (or whatever mappings you might be using) through your buffer list.
Now that is great and all, these plugins have recreated other editor's version of tabs, but Vim already let you cycle through buffers without these plugins. The only thing missing was a menu which :ls will gladly do for you without wasting any screen real-estate.
Imagine having 10, 25, 50, or 100+ buffers open. How is your Buftabline going to handle that? My bet is not well. You need to stop reaching for simple tools like :bnext / :bprev and start reaching for a power tool like :b.
Behold the power of :b
The :b command can take a buffer number to switch directly to a buffer. Far more interesting, :b can take a partial filename.
:b partial-name
Need more power in your :b?
Uses tab completion
Uses <c-d> to list out completions
Accepts globs. e.g. :b *foo
Use ** to descend into directories. e.g. :b foo/**/bar
Don't forget to add set hidden to your vimrc. See :h 'hidden'
Why ride a bike when you can fly?
taken from Bairui's collection of Vim infographics.
You can use a simple mapping to leverage both :ls and :b:
nnoremap <leader>b :ls<cr>:b<space>
Now you can travel directly to you buffer you want. No more cycling.
But I like plugins
Who doesn't like a good plugin. As a matter a fact if you are looking for a nice buffer switching plugin then I would recommend you look into a nice fuzzy finder like CtrlP to aid you in switching between buffers. A fuzzy finder actually adds value to switching between buffers by getting you there faster with less typing.
Conclusion
Eventually you workflow will require you to use more than 3 buffers at a time. At that moment I would suggest you take another look at the :b command or at the very least get a nice fuzzy finder. It will save you time and effort.
So stop riding your bike when you can fly.

Vim NERDTree. How to prohibit duplicate files in tabs?

I use NERDTree with the setting:
""""
" NerdTree
"
Bundle 'scrooloose/nerdtree'
Bundle 'jistr/vim-nerdtree-tabs'
map <F2> :NERDTreeTabsToggle<CR>
I can open any number of tabs with the same file by pressing 't'. For example:
|foo.txt|bar.txt|foo.txt|foo.txt|
How to prevent the opening of duplicate files? I want to open an existing buffer by pressing 't'.
I found the solution here https://github.com/scrooloose/nerdtree/issues/439
Grab the latest version and stick this in
~/.vim/nerdtree_plugin/override_tab_mapping.vim
https://gist.github.com/scrooloose/0495cade24f1f2ebb602
Thanks #moeabdol
From what I understand NerdTree does not have such a behavior. I believe however what you are looking for is either :tab drop like #Ben mentioned or using :sb to switch buffers with the following setting: set swb=useopen,usetabe.
Personally I would suggest you use NerdTree for more of a File Explorer and less of a file/buffer manager. By leveraging Vim's buffer commands you can easily switch between buffers. Additionally by using Vim's buffer commands you can avoid the "one-to-one: file-to-tab relationship trap" that so many new vimmers get stuck on.
Aside about NerdTree
NerdTree is very helpful to explore a complex or unfamiliar file structure, but it comes at the cost of taking up screen real estate and disrupting buffer and window/split workflows. See Oil and vinegar - split windows and the project drawer for more. Using a nice fuzzyfinder plugin like CtrlP often takes the place of NerdTree for many people.
I have a nice post about NerdTree that might be of value: Files, Buffers, and Splits Oh My!
Aside about tabs
Vim's tabs are not like most text editors tab. They are more like viewports into a group of windows/splits. Additionally, Vim is buffer centric, not tab centric like most editors. Therefore using features like the quickfix list is often easier without tabs (See :h 'switchbuf if you must use tabs). Vim's tabs often get in the way of using a splits as there are better window and buffer navigation commands available. I personally have many files open (sometimes 100+) use no tabs and use on average 1-2 splits without any issue. Bottom line: read the following posts:
Why do Vim experts prefer buffers over tabs?
Use buffers effectively
Best practices with Vim mappings
Supply a mode. So :map becomes :nmap
Unless using a <Plug> or <SID> mapping you should probably be using :noremap
By following these 2 rules your mapping will become:
nnoremap <f2> :NERDTreeTabsToggle<cr>
to open a new buffer, just press o

Split window in vim to browse files, then open file in original window

I've tried out the NERDTree plugin for vim, and it's very powerful but is probably overkill for what I use it for. I'm not anti-plugin in general, but I don't like relying on plugins when I'm not using them to their full extent.
What I'm really looking for is the ability to open the file browser in a split, similar to how :Sex and :Vex work. I'd select the file I want, which would open in the original window, and the file browser goes away.
Are there any built-in commands that would work this way?
See :help netrw for all the mappings available in :Ex and friends.
The one you want is simply P.
By the way, netrw is also a plugin.

How do I list loaded plugins in Vim?

Does anybody know of a way to list up the "loaded plugins" in Vim?
I know I should be keeping track of this kind of stuff myself but
it would always be nice to be able to check the current status.
Not a VIM user myself, so forgive me if this is totally offbase. But according to what I gather from the following VIM Tips site:
" where was an option set
:scriptnames : list all plugins, _vimrcs loaded (super)
:verbose set history? : reveals value of history and where set
:function : list functions
:func SearchCompl : List particular function
The problem with :scriptnames, :commands, :functions, and similar Vim commands, is that they display information in a large slab of text, which is very hard to visually parse.
To get around this, I wrote Headlights, a plugin that adds a menu to Vim showing all loaded plugins, TextMate style. The added benefit is that it shows plugin commands, mappings, files, and other bits and pieces.
:set runtimepath?
This lists the path of all plugins loaded when a file is opened with Vim.
If you use Vundle, :PluginList.
:help local-additions
Lists local plugins added.
If you use vim-plug (Plug), "
A minimalist Vim plugin manager.":
:PlugStatus
That will not only list your plugins but check their status.

Resources