I am trying to learn MacVim with the Janus build. I've done the Vim tutorial and now I want to dive in and create some simple websites. My first project is a site that will convert roman numerals to arabic. But I can't seem to do the simplest thing - create new files in seperate tabs in one window for html, css, and js - using MacVim. I can create blank files from the terminal and then open the finder and drag these files to an open MacVim window and achieve my goal but it seems like a very convoluted approach. What I want to do is launch MacVim and create my blank html file in the open window and then create a blank css file in an adjacent tab and then create a blank js file in a third adjacent tab and then get to work on them. But when I use the command line in MacVim to create a new file (:!mvim roman.html), I get a new window. So I end up with a series of windows instead of a series of tabs. I googled around and it seems like others have had this problem. Their solution is to modify .bashrc or .bash_profie with an alias (MacVim Open File In Existing Window), but when I tried this and attempted to open a file in MacVim, I got a file filled with garbage, not an empty file. I'm also trying to make sense of NERDTRee. Maybe there is a simple solution there but I am just starting to explore it. Any guidance would be appreciated. Thanks.
3 Answers
You didn't ask for that much but here we go…
Drop Janus as soon as you can. This piece of shit gives you a false sense of comfort while actively preventing you from learning how to use Vim and making it a lot harder than necessary to customize it to your liking.
Vim's tabs are not like tabs in other editors: they are not and can't be 1-to-1 proxies for files. In Vim, a file is loaded in a "buffer" and that buffer may or may not be displayed in zero or more "windows", in zero or more "tabs". This particularity will probably bite you one of these days so you'd better get used to deal with buffers.
In Vim, creating a new file works the same as in any editor: you edit a new empty file and, when you are done, you write it to disk.
:e[dit] file.html (editing) :w[rite]
Use
:sp[lit] file.js
to editfile.js
in a new horizontally window.Use
:vs[plit] file.html
to editfile.html
in a new vertical window.Use
:tabe[dit] file.css
to editfile.css
in a new tab.If you want to postpone the decision of the filename,
:enew
,:new
,:vnew
and:tabnew
create empty buffers in place, in an horizontal window, in a vertical one and a tab.You don't really need to create those files from outside of Vim.
From the Finder, the simplest way to edit a file in MacVim is to right-click on it and choose "Edit in MacVim". Same for three files.
There is a drop menu, somewhere in MacVim's Preferences window, that lets you define the default behavior when MacVim is launched by other programs. Try it.
Since you seem to have installed the
mvim
script, editing a file in the MacVim GUI is done with$ mvim filename
and editing the same file directly in your shell is done with$ mvim -v filename
.You can also open multiples files (even if they don't exist) in their own tabs from your shell:
$ mvim -p file1 file2 file3
Your command,
:!mvim filename
, does exactly what it's supposed to do: it launches a new MacVim instance.Vim already comes with a file explorer that does a lot more than NERDTree called
Netrw
. See:help netrw
.Did I tell you that you shouldn't use tabs if you don't have a solid understanding of what they are and what they do?

- 186,200
- 21
- 280
- 313
-
1Wow! I appreciate your taking the time to provide feedback. But now I have more questions. 1. If tabs aren't equivalent to buffers, how should I proceed to work on multiple files, like related html, css files? It doesn't sound like multiple windows solves the problem. 2. I think I'd like to figure out what Janus is before I get rid of it, but how do I delete it when the time comes. 3. What I was hoping to get from a set of core configurations was some support for working in html, css, even javascript - e.g., color coding, indentation, autocomplete. Are there better ways to achieve this? – Oct 05 '13 at 14:54
-
4. And finally, is there a way to test my javascript in vim? I am thinking of something akin to REPL in emacs. Right now I am going to Firebug to right code snippets and then cutting and pasting into vim - that doesn't seem to be very good workflow. Thanks for your help! – Oct 05 '13 at 14:54
-
11. Simple: instead of juggling with tabs like you would do in TextMate or whatever editor, you juggle with buffers. `:b
` goes a *long* way… I do frontend dev for a living and my setup is simple: the HTML is in a vertical window that takes half of the available space and the other half is home either to the CSS or the JS, depending on what feature I work on. I rarely need to have both the CSS and the JS visible but the HTML is necessary because the two others deal with the structure in the HTML. So… two vertical windows is IMO the best setup. Split windows, not GUI windows, of course. – romainl Oct 05 '13 at 19:57 -
2. I have no idea how to remove that cancer, maybe it's somewhere in their README. Trust me, you don't need that thing. – romainl Oct 05 '13 at 19:59
-
13. All of that is built-in: no need to add anything and certainly not a freaking distribution. You only need `filetype plugin indent on` and `syntax on` in your `~/.vimrc` to get syntax highlighting, omni-completion and proper indenting rules. If you want a linter, there are many plugins available. Again, no need for a freaking distro! – romainl Oct 05 '13 at 20:03
-
4. Yes, this is a bad workflow. Since your JS file is called in your HTML, you can interact with your code in Firebug's console. It's extremelly easy and convenient and you obviously don't have to copy/paste anything. That's like Web Dev 101… There are quite a bunch of plugins designed to give you a REPL *feel* in Vim try them. I recently found [Pippe2Eval](https://github.com/zweifisch/pipe2eval) which works very well with JavaScript. – romainl Oct 05 '13 at 20:10
-
Okay, again very helpful. I tried your split screen suggestion and I like how that works. I will checkout Pippe2Eval when I have a chance. I'm going to stick with Janus for awhile, and then see if I can find a way to remove it and build my own .vimrc. I'm not seeing a lot of guidance on how to uninstall Janus so I will probably trash everything and try a new install of MacVim. – Oct 06 '13 at 04:05
I think the command you want is :tabe something.html
. That creates a new tab in the current window with the file something.html
in it, and will create a new file if that doesn't exist. (Technically it won't create the new file until you save it).
If you like using tabs, it's probably worth your time to read :help tab-page-commands
.

- 3,662
- 1
- 13
- 7
-
Yes, that's it. And really that could not have been simpler. I thought I was going to have to implement a 30 line script or something. Thanks too for the help command. I had looked at others but not that one. It also showed me how to reopen those files I had created! Excellent! – Oct 04 '13 at 17:31