Sometimes I want to open vim in preparation of opening a file in the directory tree.
So i start it without a file:
vim
Then I use a map to open NERDTree:
:NERDTreeFind<CR>
This fails with
NERDTree: no file for the current buffer
OK so this is perhaps a deficiency in the plugin, and I want to add a check (either to use inside my bind, or to PR upstream to handle this edge case for the plugin).
How do I check that I am in a [No Name] buffer? @%? :f?
nnoremap <expr> <leader>f ':call ' . (@% == '' ? 'NERDTreeToggle' : 'NERDTreeFind') . "\<cr>". See:h :map-expression. However, I feel readability is more important as you may want make edits in the future and functions can be simpler for such cases. – Peter Rincker May 02 '18 at 19:59expris required? It makes maintenance a lot less palatable. I know I can make anifwith|s inline and all that. But?conditional operator would be somewhat more elegant. I just a bit of trouble finding out whether vimscript even has that operator. it seems that it does... – Steven Lu May 02 '18 at 20:21<expr>. Use:execute, e.g.nnoremap <leader>f :execute (@% == '' ? 'NERDTreeToggle' : 'NERDTreeFind')<cr>or use<c-r>=e.g.nnoremap <leader>f :<c-r>=@% == '' ? 'NERDTreeToggle' : 'NERDTreeFind'<cr><cr>or as you say with an:ifand|, e.g.nnoremap <leader>f :if @% == ""<bar> NERDTreeToggle<bar>else<bar> NERDTreeFind<bar>endif<cr>– Peter Rincker May 02 '18 at 20:40map? – Steven Lu May 02 '18 at 21:37:set filetype=pythonvs:let &filetype=somefunc(arg). Anything that is sourced or executed via command-line(:) is a statement/command. A command may take a certain syntax or sometimes an expression. I used:executeabove because:executetakes an expression and then executes it as a command. It is can be a tricky. I would recommend reading:h eval(actually whole manual would be best). May also want to look into Learn Vimscript the Hard Way by Steve Losh. – Peter Rincker May 02 '18 at 22:02