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.
I kind of new to vim, and when I usually edit things in vim I go something like:
vim .
or
vim /path/to/some/project
And then Ctrl-P to the file I need to edit. The problem with this approach is that plugins like NERDTree or FZF understand that the working directory is the one I started vim from not the directory I gave it as the parameter. Example:
/some/path$ vim /other/path
vim would understand that /some/path is the working directory not /other/path. Because of this I would have to manually :cd :%p:%h each time I start vim. Is there a way to make vim automatically :cd to the first opened directory?
I never thougth about that, but while reading your question i thougth, that could be nice ... or totaly horrible. Anyway interesting problem and I tried it for like 30 seconds and already hate it. The reason is, that your projectfolder almost never directly contains code files which you want to edit.
It should work like this:
autocmd VimEnter * silent! cd %:p:h
Imagine I'm editing file, and I want to show the list of the files inside the folder who belongs the file I'm editing, to edit one of them.
How can I do that? Is there any way using FuzzyFinder?
Did you even read FuzzyFinder's documentation (:help fuzzyfinder)? Quickly opening nearby files is one of that plugin's main features.
Without installing anything, you can do:
:Ex[plore]
to open the netrw file tree. See :help netrw.
You can also do:
:e <Tab>
Add these lines to your ~/.vimrc to make command line completion even better:
set wildmenu
set wildmode=list:full
and read :help wildmenu and :help commandline-completion.
set autochdir is a useful option to add to your ~/.vimrc, by the way.
change vim current directory to current file's:
:cd %:h
then
FuzzyFinder can do what you want (pick and edit). (:FufFile) I have mapping :
nmap <Leader>ff :FufFile<cr>
NERDTree can do that as well.
Depends on what you mean by showing the file.
To include the list of files in the currently edited files, you can do something like:
:read !ls /path/to/file
(it can be shortened to :cd %:h | read !ls if you don't mind if vim changes it's current directory...)
If you want to pick another file to edit, I'd suggest to take a look at NerdTree plugin (here is a little intro). Or you can simply issue:
:cd %:h | e .
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.
I code in Vim, not an IDE.
My source code is often nested 2-3 directories deep.
~/foo$ find
xyz
bar/abc
bar/def
~/foo$ vim
// inside of vim
:e bar/abc
... some work ...
:e <-- is there a way I can have this :e start in ~/foo/bar instead of ~/foo ?
Basically, I want :e to start the directory in "pathname of last edited file"
Thanks!
There's a lot of reasons not to like autochdir as it messes up some plugins and if you end up doing :e ../../../foo.txt you are not gaining anything. Just as an idea try this cmap I knocked up
:cnoremap red edit <c-r>=expand("%:h")<cr>/
then you can type :red and get
:e /the/path/to/your/current/files/dir/
(edit: perhaps use z instead of red as there are commands that start with red)
To expand the topic, also check out the FuzzyFinder plugin and some custom mappings to rapidly jump to common files you are always editing. Eg
10 or so of your regular files should be no more than 2 keystrokes away. It helps if they are systematically named
Here's an idea I use for django.
http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings
Try the autochdir option. It will automatically change the current working directory to whatever file was most recently opened or selected. In .vimrc:
set autochdir
For more info, :help autochdir
To always change the working directory to the current file's directory I have this in my .vimrc:
if has("autocmd")
autocmd BufEnter * :lcd %:p:h
endif " has("autocmd")
Sorry, but vim's :edit command takes a path which is interpreted relative to the present working directory of the vim instance.
You do have a :cd command which you could use to :cd bar then work for a while, then :cd ...
Hope that help some.
Some time ago I asked questions related to this on the vim mailing list: http://www.mail-archive.com/vim_use#googlegroups.com/msg03266.html Maybe you will find useful tips in that thread.
I tested a lot of plugins, but since CLI based GUIs are not my taste, I simply ended up using standard vim with a few configuration settings.
As honk pointed out, this line sets the working directory to the same as the file your working on:
autocmd BufEnter * lcd %:p:h
My other tip is to use the wildmenu. It makes it easier to get an overview of the files in your current directory when you go :e and then TAB. I'm a python programmer so the last line shows how to hide auto generated files that the python interpreter spits out, but you could use it to hide java .class files or c .obj files or whatever.
set wildmode=list:longest
set wildignore=*.pyc,*pyo
:cd changes directory
:pwd prints the current one.
why not just :E? Explore directory of current file.
:help :E
This isn't exactly what you wanted, but check out NERDTree.
On vim/gVim I just have cd C:/blah/blah at the top of my vimrc. I imagine it works on all platforms.
I personally use vagrant for each project so one CD is enough, but I think you can get vim to use different config files too, -u flag I think.
Or map a key to each project you have so pressing Ctrl+F1 does cd path/to/project/1 and Ctrl+F2 does cd path/to/project/2 perhaps?
Note: I don't use any plugins