Prevent fuzzyfinder loading files in NERDTree window - vim

I'm using both fuzzyfinder and NERDTree for vim. When my cursor is in the Window that NERDTree resides in and I use fuzzyfinder, it will open a file in the NERDTree window.
Is there a way to prevent this behaviour and force files not to open in the NERDTree window?

You'd have to use a custom mapping or override the default FuzzyFinder mapping to start it. In there you can then check for an open NERDTree, and jump to the previous window (or maybe close NERDTree), like this:
:nnoremap <silent> <F5> :<C-u>if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) == winnr() <Bar> wincmd p <Bar> endif <Bar> FufBuffer<CR>

See if this script (at the bottom of the page works for you.

Related

Default Vim to always open help in a new tab

Since I've started using Vim tabs (I'm a bit late to the game since they've been there since 2009!), I find I'd like most thing to default to tabs, so I always open files with vim -p file1 file2 etc. I would like :help / :h to always open in tabs also. I can do :tab help ctrl-w or :tab h ctrl-w but how can I use .vimrc to always default :h or :help to open in a new tab?
Additionally, is there a way to take an open file and push it into a tab, or to tell vim to take all open buffers and dynamically shift them all into tabs?
"take an open file and push it into a tab"
You can do that with this normal mode command:
<C-w>T
or this equivalent Ex command:
:wincmd T
See :help ctrl-w_t and :help :wincmd.
":h to always open in tabs"
You only need to put the aforementioned Ex command in after/ftplugin/help.vim:
wincmd T
You can use autocmd to always open help in a new tab
" This won't work if you open the same help file more than once
autocmd FileType help wincmd T
" This works
autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
Or you can define a new command to only open it in a new tab, when in a small screen or there are many to read, for example.
With the following, you can use :Tabhelp ....
function! Tabhelp(arg)
execute 'tab help '.a:arg
endfunction
command -nargs=? -complete=help Tabhelp call Tabhelp(<q-args>)

Vim: Shortcut to toggle between NERDTreeCWD and NERDTreeClose

I'd like to be able to use the same shortcut to jump to a file in NERDTree and close NERDTree. I have no experience with VimL and could use some help.
Add the following to you vimrc
set autochdir
noremap <F2> :NERDTreeTabsToggle<cr>
The first command will automatically change the current directory to be the same the same as the file you are editing.
The second command will then set F2 to toggle toggles NERDTree on/off for all tabs. you can use any key i prefer F2.
Just say you want to do this with <leader>n:
" This in your ~/.vimrc
nnoremap <leader>n :NERDTreeFind<CR>
" This in ~/.vim/ftplugin/nerdtree.vim
nnoremap <buffer> <leader>n :NERDTreeClose<CR>
Substitute whatever you want for <leader>n.

Stop NERDTree opening when vim starts

I have NERDTree plugin installed but it is always present when I start vim like this:
vim .
I only want it to open on demand.
How can I stop it opening whenever I start vim?
Try adding
let g:NERDTreeHijackNetrw=0
to your vimrc and make sure there is no other line that sets this variable.
$ vim . always opens a file explorer. If you don't have NERDTree or NERDTree is configured as per ZyX's answer you'll get netrw by default anyway.
I wonder what would happen if the netrw plugin was somehow removed.
In your vimrc file, do below steps
comment autocmd VimEnter * NERDTree, which stops opening nerdTree
by default
paste map <C-n> :NERDTreeToggle<CR> in vimrc, this will open
NerdTree only when 'Ctrl+n' is pressed from keyboard

NERDTree opens up everytime I hit return in Normal Mode

This is getting really annoying for me. I only have this line for my NERDTree in my .vimrc file,
nmap <silent> <c-o> :NERDTreeToggle <CR>
Every time I hit return key in my Vim window in normal mode (Command Mode). NERDTree pops up.
Can anyone help me out with this problem?
Here's generally what I use.
:noremap <Leader>n :NERDTreeToggle<CR>
autocmd VimEnter * exe 'NERDTree' | wincmd l
starts up nerdtree on start and give me ',n' as my toggle
I had this issue when i mapped
<C-m>
to NERDTree. Fixed it by changing to something else which didn't involve ctrl key

How can I make NERDTree to open on the same drive that the file that I'm editing?

NERDTree shows in viewport disk c: regardless from which disk do I open the file.
When I use gvim in windows I open files using:
gvim.exe --remote-tab-silent [FILE]
I'm loading NERDTree with this line in _vimrc:
au VimEnter * NERDTree
Can NERDTree automaticaly change drive to correct drive somehow?
Actually, my last answer does not work because once the NERDTree have been opened, it does not open again in the new buffer dir. It must work similarly to NERDTreeFind but it does not have a Toggle feature.
I made a function and mapped it to my key and now it works perfectly even opening the Ruby project if you have the vim-rails plugin.
Add this to your vimrc:
function! NTFinderP()
"" Check if NERDTree is open
if exists("t:NERDTreeBufName")
let s:ntree = bufwinnr(t:NERDTreeBufName)
else
let s:ntree = -1
endif
if (s:ntree != -1)
"" If NERDTree is open, close it.
:NERDTreeClose
else
"" Try to open a :Rtree for the rails project
if exists(":Rtree")
"" Open Rtree (using rails plugin, it opens in project dir)
:Rtree
else
"" Open NERDTree in the file path
:NERDTreeFind
endif
endif
endfunction
"" Toggles NERDTree
map <silent> <F1> :call NTFinderP()<CR>
It should work now.
Previous answer below:
You could map the key you use to open
NERDTree like this(in .vimrc):
map <silent> <F1> :NERDTreeToggle %:p:h<CR>
This maps my F1 key to
toggle(open/close) NERDTree using the
path of the currently active buffer.
If no buffer is open, it opens in the
currently launched Macvim directory.
NERDTree provides several Ex commands to manipulate its buffer (see
:help NERDTreeGlobalCommands). Among them there is the :NERDTreeFind
command which behaves the same way as the :NERDTree command except it opens
the NERDTree buffer in the directory containing currently opened file.
So, in order to achieve the desired effect described in the question, you can
simply change the auto-command to read
:autocmd VimEnter * NERDTreeFind
I use mapping for NERDTree and in this way when I open it always opens in current dir
" NERDTree mappings
nnoremap <silent> <F9> :NERDTreeToggle <cr>
inoremap <silent> <F9> <Esc>:NERDTreeToggle <cr>
But if you open a file like gvim ~/other/dir/file NERDTree will open current dir from where gvim was called. So this is not a real solution to your problem.
Perhaps if you cd in working dir before calling gvim will solve your problem. In this case even your au VimEnter * NERDTree in _vimrc must work as you espect .
About changing directory and setting working dir set autochdir read here
Add
au VimEnter,BufWinEnter * NERDTreeFind
to your .vimrc.
VimEnter part makes it work on load.
BufWinEnter makes it happen you open a new file.
* tells it to do this with all files
NERDTreeFind is the command to run
srcs:
http://vimdoc.sourceforge.net/htmldoc/autocmd.html

Resources