Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change vim's current directory upon starting from command line

Tags:

vim

Vim (actually, gvim is in question, but I believe it works both ways) upon starting has its current directory in its runtime directory.

I would like to upon starting, to have its cd in let's say, c:\pro
I know I can just do :cd c:\pro, but is there a way to change it upon starting it, with
something alike gvim c:\pro (only that doesn't work :-| ?

like image 957
Rook Avatar asked Dec 03 '09 16:12

Rook


People also ask

Which command line command is used to change the current directory?

The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.

How do I change the current directory in Vim?

txt The ":cd" command changes the current directory. You can see what the current directory is with the ":pwd" command: :pwd /home/Bram/VeryLongFileName Vim remembers the last directory that you used. Use "cd -" to go back to it.

How do I change the directory in terminal?

To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory"). For example, to move one directory upwards (into the current folder's parent folder), you can just call: $ cd ..


1 Answers

You can use

gvim -c "cd C:/pro"

-c allows you to run commands just after Vim has finished loading.

Vim's working directory is initially set to the working directory of the process that invokes Vim.

If you're double-clicking on the .exe in Explorer, that's why it's the runtime directory.

If you're using the Start Menu shortcut, then it has the Start in path set to the runtime directory. You could change the Start in path of the shortcut.

If you use the run dialog, then vim's initial working directory is likely your Documents and Settings directcory.

like image 72
jamessan Avatar answered Oct 11 '22 07:10

jamessan