While browsing in Netrw, how do I change Netrw's browsing directory to Vim's current directory?
Typing cd changes Vim's current directory to Netrw's browsing directory, but I want the opposite.
Type :e . in the netrw window to reset to your vim current directory.
Related
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.
I open up a project in Vim. Lets call it portfolio. I open up the index.php but now want to leave that and go to another file, controller.php. I learned that the command :e. will take me out but then it may lead me outside the scope of my project.
How do I stay within the scope of my project when leaving a file in vim?
If I understand your question correctly, you want :e. to show you the files in the same directory as the first file. If that's correct, and if the files are in one directory, use :cd path-to-your-project-directory
That will change your working directory to your project directory, and subsequently :e. will show the files in that directory.
Note too that once you use :e. (or :Explore :Texplore or :Sexplore), you can navigate through your directory hierarchy by navigating to subdirectories and pressing enter, or to the .. entry and pressing enter to move up a directory.
You may also be interested in the NERDTree plugin.
Your initial working directory in vim is the directory you're in when you start vim. If you're in a directory other than your project directory when you start vim, :e will not change your current directory to your project directory when you open a file, so if you just use :e to open different files, you'll have to specify the path each time.
eg: say your project path is /project/foo and you cd to /project and open vim. To open /project/foo/a.txt, you'll have to :e foo/a.txt. If you then want to open file /project/foo/b.txt, you'll have to :e foo/b.txt. :e doesn't change the current working directory in vim. If you cd /project/foo then start vim, you can just do :e a.txt and :e b.txt
You could also do :cd foo from within vim in the scenario above.
Hope this helps
I would say, just open controller.php with :sp controller.php you can then edit both files and switch between then with: ^w k and ^w j
I agree with other answers:
:e. provides a listing of the current working directory.
Plugins such as NERDTree build on this basic idea but also allow you to store bookmarks to commonly visited files and other cool features, see
If you augment this with plugins like bufkill, and tagbar you can actually build up quite a feature rich IDE where you can edit project files within the same context. I put together an installer script you can grab from here
Another alternative is the autochdir option which changes your working directory to that of the current buffer (so each time you change tabs/windows/buffers it changes the current directory to that of the file being edited). Link
It's not usually recommended because it doesn't play nicely with some plugins.
My projects are all under /Users/username/workspace/my_project where /Users/username/ is $HOME.
I want macvim to always have the home as /Users/username/workspace/my_project instead of /Users/username/.
I understand set autochdir sets the home to whatever the current file's directory is, but this is not what I want.
Also I'm using NerdTree if that helps.
Do you want Vim's working directory to be ~/my_project?
Add cd ~/my_project to your ~/.vimrc.
Do you want all your plugins and colorschemes to be loaded from ~/my_project, however silly it is?
See :help runtimepath.
add autocmd VimEnter * :cd ~/my_project/ to your vimrc
the directory will change only when your open vim, and you can decide change to another directory whenever you want use :cd /directory/
Let's say I have project residing in /home/myname/project. There are couple of subfolders in it too. Can I make a autocommand, so that it sets the path to /home/myname/project/** whenever I open a file from any subdirectory of the project?
Try the command below.
:autocmd BufNewFile,BufRead /home/myname/project/* sil! cd %:h
Use the :lcd command instead of :cd to change the current directory only
for the current window.
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.