Pregunta

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.

¿Fue útil?

Solución 2

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.

Otros consejos

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 edit file.js in a new horizontally window.

    Use :vs[plit] file.html to edit file.html in a new vertical window.

    Use :tabe[dit] file.css to edit file.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?

Command + T

Creates a new tab in MacVim.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top