Is there a way of disabling NERDTree when opening a file? When I open a file in mvim (using --remote-silent) and a NERDtree window is currently active, the file will open in that (narrow) window. How can I configure Vim to select another window if available and to open one if not?
There's no way to intercept the --remote-silent; you have to send explict commands to open the file with --remote-send instead. There, you can encode logic to deal with the NERDTree window, e.g. to move to the previous one if it is active:
$ gvim --remote-send "<C-\><C-n>:if &ft == 'nerdtree'|wincmd p|endif|edit filename<CR>"
Related
Suppose I browse to a directory in vim by typing :e some/dir/. Vim will take me to a list of directories and files.
If I now select some.file it will either
Open the file if it is not already open, or
Take me to the tab/window where the file is already open
How do I disable the 2nd option, so that vim will open the file in that window even if it is already open elsewhere? I can force this behaviour manually by typing :e some/dir/some.file but how do I make it happen when I select the file?
I am running vim 7.4
I use Gvim to write code. And use vifm to make file management ( copy, move files, extract tar's ). Sometimes, when navigating in vifm i need to open some file to edit him. Using :e it opened vim in same window. Is there any way to open file to edit in already opened gvim program?
You can use Vim's client-server feature to send the :edit to the existing GVIM instance. In the terminal Vim / vifm, execute:
:!gvim --remote path/to/file
See :help remote.txt for details. You can also open the file in a new tab page with --remote-tab etc.
Partial solution/workaround (I'm using a mac fwiw):
In vfimrc, define
" yank current file path into the clipboard
nnoremap Cf :!echo -n %c:p | pbcopy %i<cr>
To copy filename and dir into system clipboard
Then in vifm, cursor over file and type
Cf
:!gvim "
<cmd-v>
to paste clipboard,
and finish expression with...
"
<enter>
and now that file should open in gvim. It worked for me
I'm basically working in an environment where I sometimes use ctrlp and sometimes nerdtree. But when I start vim using vim . it always opens NERDTree. I've tried various .vimrc config commands:
let NERDTreeQuitOnOpen=1
let g:nerdtree_tabs_open_on_gui_startup=0
But they all don't work. Is there some whay I can disable the NERDTree directory listing when VIM opens? Note, I don't like just using the vim command by itself because I'm usually opening VIM when I'm in the application directory.
Thanks!
Netrw plugin opens when vim opens a directory. NerdTree takes over netrw and therefore opens when editing a directory.
vim . is equivalent to :e .
Just open vim without the . and you will be good
If I open a folder in vim like this:
$ mvim . # or vim .
NERDTree opens by default in full width:
How can I prevent this from happening and show default VIM welcome screen instead?
You are explicitly telling vim to start with a listing of the current directory, if you don't want that, just do $ vim.
Run vim to get the Welcome Screen.
If you open vim . you'll get a directory listing of the current working directory (Netrw or NERDTree Directory Listing).
NERDTree overrides the default file browser (netrw).
To disable directory listing by NERDTree at startup, add let g:NERDTreeHijackNetrw=0 to your ".vimrc".
This Option tells NERD tree whether to replace the netrw autocommands for exploring local directories.
Run vim --noplugin . and you see an empty buffer.
When using the vim editor with the NERDTree plugin to navigate through the tree of your project, is there an easy way to create a new source code file under the currently highlighted directory?
Currently I go into my shell, add the file and then refresh the tree. There must be a better way.
Activate the NERDTree and navigate to the directory in which the new file should live. Then press m to bring up the NERDTree Filesystem Menu and choose a for "add child node". Then simply enter the file's (or directory's name) and you're done.
From vim you can run shell commands. So in this case I use:
:!touch somefile.txt
and then hit r to reload the nerdtree window.
The other thing to do is to just start the new file from within vim.
:e somefile.txt
One handy thing for this is that in my .vimrc I auto change the cwd to the directory my current file is in:
" Auto change the directory to the current file I'm working on
autocmd BufEnter * lcd %:p:h
This way if I'm editing a file and want another one in the same place the path is changed right there. Opening any file from NERDTree sets the directory to the one that file is in.