NERDTree on Startup
If you use vim and you have haven't seen the excellent NERDTree plugin, you should really check it out.
I wanted NERDTree to automatically load if I start vim without arguments, so I added the following to my .vimrc:
function! StartUp()
if 0 == argc()
NERDTree
end
endfunction
autocmd VimEnter * call StartUp()
Very handy. I expect I might be adding more to my StartUp function in the future.
As a side note, it installs via a Rakefile, but if you don't have Rake available, I hacked the Rakefile to make this installable via bog-standard Ruby:
require 'fileutils'
require 'find'
require 'pathname'
IGNORE = [/\.gitignore$/, /Rakefile$/]
files = `git ls-files`.split("\n")
files.reject! { |f| IGNORE.any? { |re| f.match(re) } }
vimfiles = if ENV['VIMFILES']
ENV['VIMFILES']
elsif RUBY_PLATFORM =~ /(win|w)32$/
File.expand_path("~/vimfiles")
else
File.expand_path("~/.vim")
end
files.each do |file|
target_file = File.join(vimfiles, file)
FileUtils.mkdir_p File.dirname(target_file)
FileUtils.cp file, target_file
puts "Installed #{file} to #{target_file}"
end
Update: fixed my thinko after Aristotle pointed it out.
“
execute 'NERDTree'
”? Doesn’t just “NERDTree
” work?@Aristotle, why yes, yes it does. Thank you :)
NP. :-)
Nice startup function. I added it to my .vimrc. But what about reading from "stdin", e.g.:
date | vi -
If you want 'not' to open "NERDTree" if you read from STDIN for example in calling vim as:
. modify your function in "vimrc" as follows:Here it defines a variable only if it calls as STDIN. "NERDTree" is called only if this variable is not exist. before calling "NERDTREE".