Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gvim: change the default working directory

Tags:

when I open gvim using Alt+F2 it takes as its default working directory my home folder.

How can I change the working folder after or while running gvim? can i pass that folder as a parameter when open gvim?

like image 780
ziiweb Avatar asked Sep 19 '12 21:09

ziiweb


People also ask

How do I change my working directory in Gvim?

Or you can use :cd %:h which will also change to the directory the current file is in, but without setting autochdir. will change directory to your home directory (or on windows, print the current directory).

How do I change the default directory in Vim?

Use e.g. From the docs: 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.

How to get working directory in Vim?

When you start vim, it gets the working directory of your shell. And then you can type commands like :e to open paths relative to your working directory. you can run :e bar. c to open a window containing the contents of the bar.

Where is Vim directory windows?

On Windows 10, the vim directory is located at %USERPROFILE\vimfiles , you may link it to any other directory through the mklink command.


1 Answers

You could use a shortcut.

The simplest way, though, would be to

:edit $MYVIMRC 

append a line

cd /home/user/my/work/dir 

save (optionally execute :w|source % to immediately reload)


Inside vim

use

:pwd :cd some/other/dir 

To view/change current working directory.

Use e.g.

:cd %:h 

to change to the directory containing the file loaded in the active window. If you need/want to do this often, consider just setting 'autochdir'

:se autochdir 

From the docs:

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.

like image 98
sehe Avatar answered Sep 21 '22 05:09

sehe