Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can vim set the path relative to its current working directory?

Tags:

vim

I use the :find command to find files in vim. My path is set like so:

set path=$PWD/**

This works well until I use :Explore and the c mapping to update the CWD at which point the PWD and CWD are no longer the same. I need to set the path again after each directory change. Does anyone have a solution to this problem?

P.S.

No plugins allowed =p

like image 355
robert Avatar asked Apr 29 '14 16:04

robert


People also ask

How do I navigate folders in Vim?

Select a file or directory name and press Enter to open that file or directory. (For example :e /home/user displays the contents of that directory.) To return to the explorer window, press Ctrl-^ (usually Ctrl-6). You can also "edit" a directory to explore that directory.

What is cwd in Vim?

cwd is short for “current working directory”. Every command you run has its own current working directory. When you start a terminal emulator, your first cwd is your home directory ( /home/user ), and then you can use cd to change the working directory.


2 Answers

You can use the following command to update your 'path' option to the CWD.

let &path = getcwd() . '/**'

Unfortunately, there's no event for directory changes to hook into. You could either:

  1. Override the mentioned c mapping in the netrw windows, with :autocmd FileType netrw nnoremap <buffer> c ...
  2. Hook into some events that fire frequently, e.g. :autocmd WinEnter,CursorHold ... and invoke the above command then.
like image 177
Ingo Karkat Avatar answered Oct 02 '22 16:10

Ingo Karkat


I think you need the autochdir to set on:

'autochdir' 'acd'   boolean (default off)
            global
            {not in Vi}
            {only available when compiled with it, use
            exists("+autochdir") to check}
    When on, Vim will change the current working directory whenever you
    open a file, switch buffers, delete a buffer or open/close a window.
    It will change to the directory containing the file which was opened
    or selected.
    This option is provided for backward compatibility with the Vim
    released with Sun ONE Studio 4 Enterprise Edition.
    Note: When this option is on some plugins may not work.

But this is buggy if you using netrw or fugitive for example.

like image 30
bimlas Avatar answered Oct 02 '22 15:10

bimlas