FileManager for vim - vim

Is there a way to make Vim work like notepad++ with explorer plugin or other text editors as pspad, ultraedit and editplus?
that is
keep a fileexplorer always left (left sidebar of 15% width)
and opens all files in the content window (85% of width) and every file in a new tab (above).
I checked nerdtree and vimexplorer plugin but could not find any way to do what I want.

Check out NERD Tree. This isn't the best screenshot, but it'll give you an idea of what to expect:

To your question there is definitely many ways you can possibly get the outcome. When you mentioned NERDTree does not work the way you want, I believe you have not tried it out well enough. I would recommend you read the documentation of the NERDTree plugin. Derek's answer just shows you that with NERDTree and minibufexplorer.
One solution I could suggest is have a windows file explorer open beside your gvim window. Follow instructions in the vim.wikia page to open files in a tab when you double click on the file. If you are using Mac, MacVim has an option to open new files in a tab by default.
Now that I have provided a solution, let me remind you that Vim is unlike most of the other editors you might have used earlier. Look at the answer titled "Your problem with Vim is that you don't grok vi.", here. Vim is different, learn to grok it.
Now the point of tabs in Vim. Tabs in Vim are different, look at an answer in SO here. Tabs in vi are more like workspaces. In Linux or Mac you have the concept of workspaces where you can place your application windows together. For example assume I am working on developing a website. In one workspace I would keep my code editor, my web browser and probably a terminal. And for all my personal stuffs I would you another workspace. Like for my social stuffs I would have another workspace with my twitter client, my chat messenger and a browser for facebook. Similarly in Vim use tabs as workspaces for your different files. You might be editing couple of files. Group the ones you edit, use window splits which vim is best for. This is my vim layout:
.
I havent used tabs but use NERDTree, minibufexplorer and serves my need. I don't have to use my mouse at all, it makes my editing more efficient. Take some time reading good articles about Vim. You will see that you actually don't need most of the GUI stuffs many other editors gloat about. Try using Command-T plugin for opening files. You will find it a lot more efficient.
Read the following to get a better idea about tabs, buffers and windows in Vim:
http://jonathan.jsphere.com/post/9927807318/taming-vim-4-buffers-windows-tabs
http://blog.interlinked.org/tutorials/vim_tutorial.html

I personally use a combination of minibufexplorer and NERDTree, and it works very well for me. minibufexplorer keeps a window at the top with all the files I've opened, which I can switch between using ctrl-tab. NERDTree is open on the left, and choosing a file opens it in my main editor window, and lists it in the minibufexplorer window.

VIM includes netrw, which is already a filebrowser and I like it a lot more than NERDTree.
I have included the function below in my local .alias file.
Thus, from a terminal or console execute vc (mnemonics for V.im C.ommander) and you'll get a nice double pane browser with ssh, ftp, file execution and a large array of capabilities.
In SH alike shells try:
vc ()
{
local TARGET='';
[ -z "$#" ] && TARGET=. || TARGET="$#";
vim \
-c "set cursorline" \
-c vsplit \
-c "normal gh" \
-c "let &titlestring=\"netrw\"" \
-c "set acd" "$TARGET";
return 0
}
Enjoy!
PS:// If you need netrw filetype definitions (i.e., executing a movie player for movie files and so forth, i'll publish mine)

Related

Open file with vim but keep the terminal open as well?

Is there a way to open a new vim file in basically a new terminal window(urxvt) ?
For example if I am currently in ~/X/Y.txt and I write
vim --new-window(basically the command needed to open a new window) Y.txt
I still want my current urxvt session while opening the Y.txt in a vim-Session.
gvim will open up vim in a GUI (i.e., not in the terminal).
You can use vim's client-server model. Run one instance as a server and edit files with option --remote.
Another solution would be to use terminal multiplexors like GNU screen, tmux or such.
Other variants are: use a terminal with tabs, use gvim.
I highly, highly, strongly recommend downloading NERDTree. It makes your Vim terminal look (relatively, comparatively) similar to a "normal" IDE, with a narrow file-and-folder bar on the left side, and a "main" terminal window taking up the rest of the screen. You use Ctrl+W to navigate back and forth between the two screens. Plus, in the sidebar, you can use normal Vim commands to move up and down. Whoever created that plugin put a lot of work into it.

Explore filesystem/directories in vim?

What is the best way/plugin to explore filesystem and to open files and directories?
The best way to explore filesystem/directories in Vim is the one that best suits your needs. As it is phrased, this question can't get an answer because there's no "way" universally agreed upon.
On the other hand, if you want to have an overview of the many ways to explore the filesystem in Vim then, yes, that is a question that can be answered. In a non-exhaustive way, though.
NERDTree and netrw are already covered. These plugins show you a tree-like list of files and directories that you can act on. Before trying NERDTree, I'd suggest you try your hands on netrw as it comes with Vim by default and offers a much wider range of features than NERDTree. You should look around on http://www.vim.org because there are a bunch of similar plugins.
On the opposite side of the spectrum, you have Vim's own file handling capabilities. Here is a sample of commands you can use from Vim to open files:
:e filename edits filename
:sp filename edits filename in an horizontal split
:vs filename edits filename in a vertical split
:tabe filename edits filename in a new tab
You have tab-completion, just like in the shell:
:e <tab> goes through all the directories/files in the working directory
You can use wildcards, of course:
:e **/*.js<tab> shows all the js files in the working directory and its subdirectories
Assuming you have set wildmenu in your ~/.vimrc, you can make tab-completion even better with an horizontal menu which can be customized further…
You can also use "args"… but that will be for another time.
Somewhere between Vim's default commands and netrw/NERDTree you can find a bunch of "fuzzy" and less fuzzy file openers more or less modeled after a feature introduced in TextMate a while ago: FuzzyFinder, LustyExplorer, Command-T, CtrlP and many other variations on the same theme. The core concept is to provide you with a list of choice that you narrow down by typing more characters in a prompt until the file ou want to edit is selected.
If you decide you want to go down the plugin road, I'd suggest you visit http://www.vim.org, compare what's there, try a few plugins and decide for yourself.
Anyway, you should get used to the basics before looking for a plugin.
Try NERD Tree, besides the tree tab it also enhances the classical directory listing as suggested by #ATOzToa.
On Windows, I find :!start explorer %:p:h to be the way to go, or :!start explorer . if I'm in the directory I want opened.
On MacVim you could probably do something similar with :!open . to open a Finder window on the current directory but I don't have a Mac handy to try it out.
Not sure what you'd use in GNU/Linux; it probably depends on your desktop manager.

Open vim tab in new (GUI) window?

I'd like to move the current tab into a new (visual/real) window in MacVim.
It's probably difficult, as:
there is nothing in the vim help and only very few - not helpful - hits on google
MacVim does not support it (link, 2009)
So I am wondering if someone has found a way to achieve this?
The closest I think you can come is using mksession
This will have several drawbacks (like, initially the secondary session will open a few more buffers than ultimately desired).
However, it will preserve your mappings, settings, history, window layout (if you had multiple windows inside the current tab, they will all get cloned).
If this idea tickles your fancy, you could look at creating a script that will filter parts out of the session file (which is Yust Another Vim Text Script)
:mksession! $HOME/detach.vim
:tabclose
:silent! !gvim remote --servername Detach -nR +'silent! source H:\detach.vim' +tabonly
save all current windows, mappings, settings (:he mksession)
close the tab we are about to detach
clone the session (detach.vim) into a remote vim
:silent! (try not to talk too much)
!gvim remote --servername Detach; launch a new remote Vim server if it doesn't yet exist, or talk to the existing server named Detach
-nR TODO Fix This is here to avoid the use of swapfiles (because I found no way to suppress the dreaded ATTENTION messages[1]). However, this may be unsafe advice depending on your situation, which is why I also include -R for read-only mode
+'silent! source H:\detach.vim' +tabonly -- In the remote vim, source the session to clone, and keep only the active tab (that was already closed in step 1.)
A little rough around the edges, for sure, but quite close to what you intended, I feel.
If you are comfortable, you can drop the -nR flags and just click through a few annoying swapfile attention messages (keyboard: Q).
[1] :he ATTENTION
Post-scripts:
on windows you might want to use :silent! !start /b gvim .... in case you have terminal windows sticking around
also on windows, you might get annoying behaviour if the resulting gvim window is too small. The :simalt ~x sequence is one hacky way to maximize the window (assuming English UI, because x is the accelerator for Maximize)
as icing on the cake, vim 7.3 has 'persistent undo'. See e.g. :se undofile
I don't think this is possible because, when you open a new instance of (g)vim you don't have access to the undo-history of the previous vim instance. All you can do is (in command mode):
:!gvim %
It will open the current file in a new instance of gvim. At least this is all I could think of. I may be wrong

MacVim: Opening webview or displaying tooltips like TextMate

I am starting on VIM and trying to understand it a bit. I currently use TextMate for web development, so I can build nice commands which take my current document/selection and display as a web view very quickly or send some results through tooltips.
I believe it's more appropriate to refer this question to MacVim since it has access to GUI elements so sometimes it might be possible?
"HTML Output for Commands" is a good explanation.
So I would like to know if it's posibble to output commands to a HTML window just like TextMate?
Or would I have to create my own program that accepts STDIN and display it as an html output on a view?
The same for the tooltips?
I was hoping that as MacVim is has access to Cocoa library and GUI elements perhaps it could already have some feature like this?
Sorry if I am misunderstanding things here, I really feel that it would be a good idea to migrate but obviously I would like to keep the nice and quick tools that I use and not losing a good visual appeal.
so I would like to know if its posibble to output commands to an html window just like TextMate?
You could have vim issue a command at the command-line which would tell a browser to open a file you're editing.
On a Mac, using either vim at the command-line or MacVim, if you were editing a file called "test.html" in the buffer and it was in your Desktop folder:
:!open ~/Desktop/test.html
will open, or re-open the file in the browser. So, when you make a change you issue that and the browser will come to the foreground with the latest version of the file. You could use the other options to "open" to specify which browser to use. And, you could easily add a key press to open the current file, which is "%" on the command line.
If you want to capture the output of a command in vim, there are a couple ways to do that. If you execute a command vim will capture its output in a temporary buffer for viewing.
:!ls
displays:
:!ls
Desktop Downloads Library Music Photo Tools Public VirtualBox VMs bin
Documents Editors Movies Music Tools Pictures Sites Web Tools
You can also see what's in Command - R like functionality in MacVim and Vim - Displaying Code Output in a New Window á la Textmate?.
I'm not sure what you mean by "tooltips". Usually that refers to pop-up text at the tip of your mouse offering context sensitive help. You can't send text through that, so your use of the word is confusing.
MacVim and vim do have snippet-like capability, plus are scriptable, can work on text that is the current selection, plus a whole lot more. It's important to understand that MacVim is a GUI layer on top of the regular vim editor, so there are somethings it won't do because vim's engine doesn't make it easy. That hasn't ever bothered me, because if I need a particular TextMate feature I'll fire it up, use that particular thing, then jump back if I feel like it. But, that's not too common a need for me.
You might want to look at some of the related threads here on SO, over on the right hand side of the page, plus look at some of vim's plugins like:
taglist.vim
vimspell
matchit.zip
align
surround
Tabular
I use the above ones all the time. The following ones I'd miss if I didn't have them.
Command-T
SnipMate
Rails.vim
EDIT:
Capturing the temporary buffer to a new buffer in Vim is pretty easy:
:redir #a
:sil !ls -al
:redir end
:vnew
"agp
The second line :sil !ls -al could be any execution of a command. :sil tells Vim to not echo the output to the temporary buffer, instead capture it silently, which gets rid of the "Press any key" pause.
:vnew creates a vertical split with a new buffer in it. You could use :tabnew instead if you want a new tab.
"agp tells it to use buffer #a and paste the output into the current buffer and leave the cursor below the pasted text.

Using Vim's tabs like buffers

I have looked at the ability to use tabs in Vim (with :tabe, :tabnew, etc.) as a replacement for my current practice of having many files open in the same window in hidden buffers.
I would like every distinct file that I have open to always be in its own tab. However, there are some things that get in the way of this. How do I fix these:
When commands like gf and ^] jump to a location in another file, the file opens in a new buffer in the current tab. Is there a way to have all of these sorts of commands open the file in a new tab, or switch to the existing tab with the file if it is already open?
When switching buffers I can use
:b <part of filename><tab>
and it will complete the names of files in existing buffers. <part of filename> can even be the middle of a filename instead of the beginning. Is there an equivalent for switching tabs?
Stop, stop, stop.
This is not how Vim's tabs are designed to be used. In fact, they're misnamed. A better name would be "viewport" or "layout", because that's what a tab is—it's a different layout of windows of all of your existing buffers.
Trying to beat Vim into 1 tab == 1 buffer is an exercise in futility. Vim doesn't know or care and it will not respect it on all commands—in particular, anything that uses the quickfix buffer (:make, :grep, and :helpgrep are the ones that spring to mind) will happily ignore tabs and there's nothing you can do to stop that.
Instead:
:set hidden
If you don't have this set already, then do so. It makes vim work like every other multiple-file editor on the planet. You can have edited buffers that aren't visible in a window somewhere.
Use :bn, :bp, :b #, :b name, and ctrl-6 to switch between buffers. I like ctrl-6 myself (alone it switches to the previously used buffer, or #ctrl-6 switches to buffer number #).
Use :ls to list buffers, or a plugin like MiniBufExpl or BufExplorer.
Bit late to the party here but surprised I didn't see the following in this list:
:tab sball - this opens a new tab for each open buffer.
:help switchbuf - this controls buffer switching behaviour, try :set switchbuf=usetab,newtab. This should mean switching to the existing tab if the buffer is open, or creating a new one if not.
Vim :help window explains the confusion "tabs vs buffers" pretty well.
A buffer is the in-memory text of a file.
A window is a viewport
on a buffer.
A tab page is a collection of windows.
Opening multiple files is achieved in vim with buffers. In other editors (e.g. notepad++) this is done with tabs, so the name tab in vim maybe misleading.
Windows are for the purpose of splitting the workspace and displaying multiple files (buffers) together on one screen. In other editors this could be achieved by opening multiple GUI windows and rearranging them on the desktop.
Finally in this analogy vim's tab pages would correspond to multiple desktops, that is different rearrangements of windows.
As vim help: tab-page explains a tab page can be used, when one wants to temporarily edit a file, but does not want to change anything in the current layout of windows and buffers. In such a case another tab page can be used just for the purpose of editing that particular file.
Of course you have to remember that displaying the same file in many tab pages or windows would result in displaying the same working copy (buffer).
Contrary to some of the other answers here, I say that you can use tabs however you want. vim was designed to be versatile and customizable, rather than forcing you to work according to predefined parameters. We all know how us programmers love to impose our "ethics" on everyone else, so this achievement is certainly a primary feature.
<C-w>gf is the tab equivalent of buffers' gf command. <C-PageUp> and <C-PageDown> will switch between tabs. (In Byobu, these two commands never work for me, but they work outside of Byobu/tmux. Alternatives are gt and gT.) <C-w>T will move the current window to a new tab page.
If you'd prefer that vim use an existing tab if possible, rather than creating a duplicate tab, add :set switchbuf=usetab to your .vimrc file. You can add newtab to the list (:set switchbuf=usetab,newtab) to force QuickFix commands that display compile errors to open in separate tabs. I prefer split instead, which opens the compile errors in a split window.
If you have mouse support enabled with :set mouse=a, you can interact with the tabs by clicking on them. There's also a + button by default that will create a new tab.
For the documentation on tabs, type :help tab-page in normal mode. (After you do that, you can practice moving a window to a tab using <C-w>T.) There's a long list of commands. Some of the window commands have to do with tabs, so you might want to look at that documentation as well via :help windows.
Addition: 2013-12-19
To open multiple files in vim with each file in a separate tab, use vim -p file1 file2 .... If you're like me and always forget to add -p, you can add it at the end, as vim follows the normal command line option parsing rules. Alternatively, you can add a bash alias mapping vim to vim -p.
I ran into the same problem. I wanted tabs to work like buffers and I never quite manage to get them to. The solution that I finally settled on was to make buffers behave like tabs!
Check out the plugin called Mini Buffer Explorer, once installed and configured, you'll be able to work with buffers virtaully the same way as tabs without losing any functionality.
This is an answer for those not familiar with Vim and coming from other text editors (in my case Sublime Text).
I read through all these answers and it still wasn't clear. If you read through them enough things begin to make sense, but it took me hours of going back and forth between questions.
The first thing is, as others have explained:
Tab Pages, sound a lot like tabs, they act like tabs and look a lot like tabs in most other GUI editors, but they're not. I think it's an a bad mental model that was built on in Vim, which unfortunately clouds the extra power that you have within a tab page.
The first description that I understood was from #crenate's answer is that they are the equivalent to multiple desktops. When seen in that regard you'd only ever have a couple of desktops open but have lots of GUI windows open within each one.
I would say they are similar to in other editors/browsers:
Tab groupings
Sublime Text workspaces (i.e. a list of the open files that you have in a project)
When you see them like that you realise the power of them that you can easily group sets of files (buffers) together e.g. your CSS files, your HTML files and your JS files in different tab pages. Which is actually pretty awesome.
Other descriptions that I find confusing
Viewport
This makes no sense to me. A viewport which although it does have a defined dictionary term, I've only heard referring to Vim windows in the :help window doc. Viewport is not a term I've ever heard with regards to editors like Sublime Text, Visual Studio, Atom, Notepad++. In fact I'd never heard about it for Vim until I started to try using tab pages.
If you view tab pages like multiple desktops, then referring to a desktop as a single window seems odd.
Workspaces
This possibly makes more sense, the dictionary definition is:
A memory storage facility for temporary use.
So it's like a place where you store a group of buffers.
I didn't initially sound like Sublime Text's concept of a workspace which is a list of all the files that you have open in your project:
the sublime-workspace file, which contains user specific data, such as the open files and the modifications to each.
However thinking about it more, this does actually agree. If you regard a Vim tab page like a Sublime Text project, then it would seem odd to have just one file open in each project and keep switching between projects. Hence why using a tab page to have open only one file is odd.
Collection of windows
The :help window refers to tab pages this way. Plus numerous other answers use the same concept. However until you get your head around what a vim window is, then that's not much use, like building a castle on sand.
As I referred to above, a vim window is the same as a viewport and quiet excellently explained in this linux.com article:
A really useful feature in Vim is the ability to split the viewable area between one or more files, or just to split the window to view two bits of the same file more easily. The Vim documentation refers to this as a viewport or window, interchangeably.
You may already be familiar with this feature if you've ever used Vim's help feature by using :help topic or pressing the F1 key. When you enter help, Vim splits the viewport and opens the help documentation in the top viewport, leaving your document open in the bottom viewport.
I find it odd that a tab page is referred to as a collection of windows instead of a collection of buffers. But I guess you can have two separate tab pages open each with multiple windows all pointing at the same buffer, at least that's what I understand so far.
You can map commands that normally manipulate buffers to manipulate tabs, as I've done with gf in my .vimrc:
map gf :tabe <cfile><CR>
I'm sure you can do the same with [^
I don't think vim supports this for tabs (yet). I use gt and gT to move to the next and previous tabs, respectively. You can also use Ngt, where N is the tab number. One peeve I have is that, by default, the tab number is not displayed in the tab line. To fix this, I put a couple functions at the end of my .vimrc file (I didn't paste here because it's long and didn't format correctly).
I use buffers like tabs, using the BufExplorer plugin and a few macros:
" CTRL+b opens the buffer list
map <C-b> <esc>:BufExplorer<cr>
" gz in command mode closes the current buffer
map gz :bdelete<cr>
" g[bB] in command mode switch to the next/prev. buffer
map gb :bnext<cr>
map gB :bprev<cr>
With BufExplorer you don't have a tab bar at the top, but on the other hand it saves space on your screen, plus you can have an infinite number of files/buffers open and the buffer list is searchable...
Looking at
:help tabs
it doesn't look like vim wants to work the way you do...
Buffers are shared across tabs, so it doesn't seem possible to lock a given buffer to appear only on a certain tab.
It's a good idea, though.
You could probably get the effect you want by using a terminal that supports tabs, like multi-gnome-terminal, then running vim instances in each terminal tab. Not perfect, though...
If you want buffers to work like tabs, check out the tabline plugin.
That uses a single window, and adds a line on the top to simulate the tabs (just showing the list of buffers). This came out a long time ago when tabs were only supported in GVim but not in the command line vim. Since it is only operating with buffers, everything integrates well with the rest of vim.
relevant:
Vim: can global marks switch tabs instead of the file in the current tab?
maybe useful to solve a little part of OP's problem:
nno \ <Cmd>call To_global_mark()<cr>
fun! To_global_mark()
-tab drop /tmp/useless.md
exe 'normal! `' .. toupper(input("To global mark: "))
endf

Resources