Nope
Nope

Reputation: 35990

Vim: Change start up directory?

When I start GVim and start writing my little program I'd like to save the file to the Desktop but it seems that Vim is starting the command line in:

C:\Windows\System32

How would I go about changing that to:

C:\Users\Casey

so then I could just:

:w Desktop\my_program.py

Upvotes: 33

Views: 24281

Answers (9)

Steve Chavez
Steve Chavez

Reputation: 1156

Inside init.vim, I use:

lcd $HOME/Projects

Upvotes: 0

Piotr
Piotr

Reputation: 31

Use this mapping in your .vimrc file :cd $USERPROFILE\Desktop<cr>

or the same shorter cd ~\Desktop<cr>

A mapping that also displays afterwards the path instead of the command nmap <leader>d :cd ~\Desktop<cr>:pwd<cr>

Upvotes: 0

user3386110
user3386110

Reputation: 41

How about changing your starting position?

vim icon -> right click -> property -> shortcut -> Start in -> your path you want to change.

but it works perfectly.

I think :cd yourpath also works. but it will change when you don't want to change.

Upvotes: 4

octopusgrabbus
octopusgrabbus

Reputation: 10685

I found the following to be very useful. I am on Windows 7 and vim 7.3.46, and am using gVim.

I edited startup settings, which wound up altering the _vimrc in c:\Users\me\.

I also tried using :version and editing the _vimrc files I found at $VIM, as well as the _vimrc I found at c:\windows\system32.

Editing those files to include :cd c:\Users\me did not result in my default startup directory changing after starting vim. I wanted my default directory to be c:\Users\me\, and editing c:\Users\me\_vimrc achieved that. That is I entered

:e $MYVIMRC

and added

cd c:\Users\cnorton.Arlington1\

to that file.

Upvotes: 1

Aaron
Aaron

Reputation: 2351

I found this way to be better:

  1. Open gVim
  2. :cd $vim
  3. :e _gvimrc
  4. Add the following line:

    :cd c:\users\user\desktop\
    

I found that :Ex is slow on large directories like c:\windows\system32\ (where gVim usually starts).


Also, here is my full _gvimrc in case anyone is interested. I prefer Consolas for coding. The tabstop setting helps when coding especially in Python, and Ctrl+Tab/Ctrl+Shift+Tab is great for switching between buffers:

set guifont=Consolas:h12:cANSI
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
map <C-Tab> :bnext<cr>
map <C-S-Tab> :bprevious<cr>
:cd c:\users\user\desktop\

Upvotes: 11

nightingale2k1
nightingale2k1

Reputation: 10305

Use :cd c:\users\casey, after that save into session (in gVim there is button up and down in red, click on it and save as mySessionProject.vim). Next time you need to go to that directory, open that session (you can also use :source mySessionProject.vim)

for command line:

:mksession! yourdir/yourVimConfName.vim

to load

:source yourDir/yourVimConfName.vim 

Upvotes: 1

RJ-
RJ-

Reputation: 3037

Just to to put this up incase anyone needs it: vimrc accepts enironmental parameters. you can put cd $USERPROFILE in your vimrc

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 992707

Within vim, you can change the current directory with the :cd command:

:cd c:\users\casey

Upvotes: 13

Alex Martelli
Alex Martelli

Reputation: 881487

Assuming you're starting gvim from an icon/shortcut in Windows (from the kind of paths you supply), you can change the starting directory (completely independent from the fact that it IS gvim: it would be the same from any other app!) by editing the "starting directory" property of that Windows icon/shortcut.

Upvotes: 50

Related Questions