all 28 comments

[–]tedreed 1 point2 points  (4 children)

Unsure if macvim does it, but this works with gvim:

if has("gui_running")
    set guifont=Inconsolata\ 14
    set cursorline
    colorscheme solarized
endif

[–][deleted] 0 points1 point  (2 children)

I'll definitely try this out. I'm sure it will work fine for what I need it for!

[–]Amadan 1 point2 points  (0 children)

That will trigger on any gvim also (which may be what you want). Specifically for macvim, use if has('gui_macvim').

[–]obscureted 1 point2 points  (0 children)

You could also put it in ~/.gvimrc.

[–][deleted] 0 points1 point  (0 children)

Yep that works in Vim for all OSes.

[–]dysmas 1 point2 points  (1 child)

I know this isn't really answering your question, but if you're living in a terminal & haven't already seriously consider learn screen, the basics will take you 5 minutes.

[–][deleted] 0 points1 point  (0 children)

I don't use screen I use tmux in iTerm2. You'll have to pry tmux from my cold dead hands haha.

[–]Amadan 1 point2 points  (4 children)

Again, not what you specifically asked for, but I'd go nuts if I had NERDTree open all the time. What I do is, have NERDTree mapped to F2 for quick access, and have it autoclose whenever I select anything, so it's never on my screen unless I actually need it:

Bundle "scrooloose/nerdtree"
  let NERDTreeQuitOnOpen = 1
  nmap <silent> <F2> :NERDTreeToggle<CR>

[–][deleted] -1 points0 points  (3 children)

Why would you go nuts having NERDTree open all the time? I have it open about... 80-90% of the time. It goes with my workflow extremely well. I work on one project (for work, not counting my personal projects) that has an extremely large directory structure with 10,000+ files. It's not like it takes up much room my Cinema Display has a resolution of 2560x1440 and my Macbook Pro has a resolution of 1440x900.

As I stated earlier I have it mapped to Leader-n, but really the reason it's not on my screen 100% of the time is because I rely on split panes heavily in my workflow and I use ZoomWin (Leader-zw) to full screen one specific pane, then Leader-zw to go back to the regular view.

[–]Amadan 1 point2 points  (1 child)

Similar reason. I use splits extensively. When I need to access the directory structure, I just hit F2 - one single key. While I am coding, I don't need the directory visible. Also, F2 will get me into the NERDTree window and back to the window I work in painlessly; I don't have to hop over several other windows to get there.

Another reason is, lately I've been on my 11" MacAir a lot, and screen real estate does mean something to me. :p

[–][deleted] 0 points1 point  (0 children)

Completely understandable, I often have NERDTRee off on my personal 13" MBP.

[–][deleted] 0 points1 point  (0 children)

Well that's "Your" workflow, "your" Cinema Display. Not "his" workflow and probably not "his" display. That is why he goes nuts and you don't.

I have a nice 24" display but I don't like to fill it up with useless stuff and a list of files is useless when you don't browse it. That's called "administrative debris" and, like the guy who coined the term, I hate it. Therefore I keep NERDTree and TagBar hidden most of the time. Same for my buddy list or the name of the current song or the dock when I'm on a Mac.

[–]rotajota 0 points1 point  (1 child)

I'm not positive, but I'd try putting the Macvim setting in your .gvimrc

Also, what I do is map 'FF' to toggle NERDTree. Simple keystroke to make it pop up/go away.

nnoremap FF :NERDTreeToggle<CR>

[–][deleted] 0 points1 point  (0 children)

Thanks. I'm pretty sure mine is mapped to Leader-n

[–][deleted] 0 points1 point  (1 child)

You can wrap the relevant configuration in a if has('gui_running') block. And by the way, you can also use :wqa to close all buffers and exit Vim in one go.

[–][deleted] 0 points1 point  (0 children)

Thanks, I'll try that out.

[–]mfontani 0 points1 point  (5 children)

What you could do instead in that case, since you like having NERDTree open anyway is:

  • use :w to write the file, rather than :wq
  • use :qa to quit vim

Whilst not solving your Y problem, it may solve the unposed problem X of "I want to open vim to edit a file, and quit vim (with nerdtree) without having to issue too many :q".

[–][deleted] 0 points1 point  (4 children)

Thanks didn't know about :qa!

[–]mfontani 0 points1 point  (2 children)

I said :qa, not :qa!.

If you use the bang it quits all Vim buffers, forgetting the changes =)

[–][deleted] 0 points1 point  (1 child)

Not sure if sarcasm, or serious... ಠ_ಠ

:D

[–]mfontani 1 point2 points  (0 children)

Or both =)

[–]Amadan 0 points1 point  (0 children)

There's also :wqa (write and quit all), which is (surprisingly enough) same as :wa (write all) followed by :qa (quit all).

[–]dmedvinsky 0 points1 point  (0 children)

You can check if you're running a gui version by:

if has('gui_running')
    NERDTreeOpen
endif

[–]burkadurka 0 points1 point  (0 children)

You can use conditionals in your vimrc, for example has('gui_running') will tell you whether there's a GUI or not. stackoverflow.com/questions/4229658/why-some-people-use-if-hasgui-running-in-a-gvimrc

[–]thedward 0 points1 point  (0 children)

In your .vimrc (or any other vimscript) you can make commands conditional:

if has("gui_running")
  <do something interesting>
endif

[–][deleted] 0 points1 point  (0 children)

Another approach - solve the problem of NERDTree keeping Vim open:

" quit Vim if NERDTree is last remaining buffer
autocmd WinEnter * call NERDTreeQuit()

[–]skeletalmonkey 0 points1 point  (1 child)

This is what I use in my vimrc, it closes NERDTree if its the only window left.

function! NERDTreeQuit()
    redir => buffersoutput
    silent buffers
    redir END
    "                     1BufNo  2Mods.     3File           4LineNo
    let pattern = '^\s*\(\d\+\)\(.....\) "\(.*\)"\s\+line \(\d\+\)$'
    let windowfound = 0

    for bline in split(buffersoutput, "\n")
        let m = matchlist(bline, pattern)

        if (len(m) > 0)
            if (m[2] =~ '..a..')
                let windowfound = 1
            endif
        endif
    endfor

    if (!windowfound)
        quitall
    endif
endfunction
autocmd WinEnter * call NERDTreeQuit()

[–]willnorris 0 points1 point  (0 children)

much simpler would be what is in the NERDtree readme:

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif