Vim: Change start up directory? - windows

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

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.

Within vim, you can change the current directory with the :cd command:
:cd c:\users\casey

I found this way to be better:
Open gVim
:cd $vim
:e _gvimrc
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\

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.

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

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.

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

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>

Inside init.vim, I use:
lcd $HOME/Projects

Related

Read only for open directories in vim

Then I open vim from terminal and open an directory like vim ., my starts in Read Only Mode.
I cant figure out why this happen and how I can change it.
If I start MacVim everything is fine. But then I start vim from the terminal and open a directory this screen comes. I can navigate one dir up and back again, and I have write access.
EDIT
I installed all my vim settings on Ubuntu 15.04. Now I can use
Does anybody know how to change this behaviour of vim?
Now I can use netw with the command vim . like I always used.
As you can see, there is no RO (read only) mark. How can
I have this in Mac on iTerm too?
What you see is exactly what you are supposed to see when doing $ vim .: the built-in netrw plugin displays a listing of the current directory that you can use to navigate your project.
If you don't want that listing, don't ask for it:
$ vim
or:
$ vim file
ctrl-p is not mapped by netrw; on my system, its set up by the yankring plugin. If vim is doing something other than going up one line, then you have a plugin involved. Try using :map to see what its mapped to; then do a search for that in your plugins directory.
The netrw way of opening a file in the same window is to use the <enter> key, although the g:netrw_browse_split variable may be used to change that default behavior.
Netrw opens in read-only mode, and that's not going to change. The file being opened should not be in read-only mode, however, if that's what you meant. If you're having a problem of that sort, please update your netrw; the most up-to-date version is at http://www.drchip.org/astronaut/vim/index.html#NETRW .
After I installed macvim 7.4 Every thing works!

How do I change the default save location in Vim?

Currently it's C:\Windows\System32 which is pretty impractical. I know that you can change the current directory with :cd [directory], but is there any way to change the default save location for new files without having to change directories all the time?
I am not at Windows so I cannot find the exact menu names and such, but if I recall correctly the easiest way to go about it is:
Find your gVim application
Right click it
Choose Properties,
Change the startup location in one of the tabs. The usual place to set it to would be your home directory.
You can change Vim's current working directory with the :cd command.
See
:help :cd
.
If you want Vim to always start in a particular directory, you can
put the :cd command in your ~/_vimrc file.
If you want Vim to use
the parent directory of the file you are editing as its current
working directory, you can put this setting in your ~/_vimrc file:
.
set autochdir
See
:help 'autochdir'

Vim inserting _viminfo files after every save

I just did a clean (re)install of Vim (Downloaded from vim.org/download.php, used the gvim73_46.exe installer. Version is 7.3 (patches 1-46)
The only changes to my _vimrc are to set line numbers, lines, columns, and enable syntax.
Everytime I edit a file with vim, save it and close it (:wq), a new _viminfo file is created in that files directory.
Also, the backup *.*~ files and .swp files persist, and arn't cleared upon saving. Running Windows 7 enterprise.
This really clutters everything - and is a pain trying to open a file for which a .swp file exists..
Help?
disable viminfo file:
set viminfo="NONE"
disable swap file:
set noswf
disable backup :
set nobk
set nowb
more details:
:h 'swf'
:h 'bk'
:h 'wb'
:h 'viminfo'
That's strange; the viminfo file should be written in your home directory, nowhere else:
The default name of the viminfo file is "$HOME/.viminfo" for Unix and OS/2,
"s:.viminfo" for Amiga, "$HOME_viminfo" for MS-DOS and Win32. For the last
two, when $HOME is not set, "$VIM_viminfo" is used. When $VIM is also not
set, "c:_viminfo" is used. For OS/2 "$VIM/.viminfo" is used when $HOME is
not set and $VIM is set.
It appears as if your %HOME% variable (or the %HOMEDRIVE%%HOMEPATH%) isn't properly set.

Vim opens a new folder instead of an existing file with `set enc=utf-8` enabled

When I open a file with vim or gvim from console on windows that is located in a sub directory (e.g. gvim subdir/file), it creates a new file at subdir\subdir\file saying "subdir\file" [New DIRECTORY] instead of simply opening the existing file at subdir\file.
This happens since I added the following line to my vimrc:
set enc=utf-8
Is there a possibility to open and create files in UTF-8 mode on Windows without this issue?
You may also look at my vimrc file.
Thank you for any help.
Change the order of the autochdir and encoding options in your vimrc. First set the encoding then autochdir
set enc=utf-8
set autochdir
An explanation can be found here

Is it possible to get gVim to remember window size?

I know how to set the initial window size in gVim, but how do I get it to automatically restore the window dimensions from last session? Is this even possible?
Edit: Corrected my answer. The mentioned winsize sessionoption only refers to the vim internal window layout, not the external dimensions.
If you use
:mksession
and load the session on vim startup with
gvim -S Session.vim
you can include the window position and size into the session by including winpos and resize in the sessionoptions, see
:help 'sessionoptions
With autocommands you could even automate the saving and restoring of the session on Vim entry and exit.
These lines save and restore just the position and size:
set sessionoptions+=resize,winpos
autocmd VIMEnter * :source C:/session.vim
autocmd VIMLeave * :mksession! C:/session.vim
Additionally:
In your .vimrc:
set ssop+=resize,winpos,winsize,blank,buffers,curdir,folds,help,options,tabpages
Then, use the script from this article. It works beautifully!
I had the same question, and to expand on the above answer, you can simply add the following to your .vimrc to get the behaviour you want:
set sessionoptions+=resize,winpos
see :h ssop
gvim -geom 85x55
as in, putting this in your .bashrc:
alias G='gvim -geom 85x55'
If you just want vim to open to the same size every time, you can edit your user's vimrc in C:/Users/<yourUserName>/_vimrc (this is preferred to editing the system _vimrc in your vim installation folder)
to include the line set lines=<yourHeight> columns=<yourWidth>

Resources