How do I use my .vimrc file in Cygwin?
Solution 1
1) Yes it is possible. It doesnt need any cygwin specific settings, though you can add some windows specific ones. Just make sure to install vi (vim gvim equivalent) properly.
2) the same place as on *nix -- user home directory
Solution 2
I launched vi as vi -V
and got this:
chdir(/cygdrive/c/Users/johntron)
chdir(/etc)
chdir(/cygdrive/c/Users/johntron)
could not source "/etc/virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.exrc"
Realizing vi was looking for .virc
and not .vimrc
like all the other *nix systems I've ever used, I just ran this to fix the problem:
cp ~/.vimrc ~/.virc
... or if if you've configured symlinks:
ln -s ~/.vimrc ~/.virc
I'm pretty sure this was a problem, because Cygwin installs vi, and not vi improved; however, the loading screen if you launch vi with no parameters still says vi improved. Regardless, I installed vim
via setup.exe
and running vim
(not vi
) does indeed try to load ~/.vimrc
as expected. You can simply add an alias vi=vim
to your ~/.profile to use the improved version by default.
Solution 3
Cygwin (as of version 1.7.25) installs vi
(not vim
!) by default. If you also install vim
you will have two commands: /usr/bin/vi
and /usr/bin/vim
.
Unlike in other *nix (e.g. debian) both commands slightly differ in their behaviour on starting vi/vim.
Both commands will load Vi Enhanced but they differ in the files they look for to initialize the editor:
/usr/bin/vi
looks first for /etc/virc
and then for $HOME/.virc
/usr/bin/vim
looks first for /etc/vimrc
and then for $HOME/.vimrc
.
Both files (in /etc
and in $HOME
) will be sourced if found!
You can check it yourself entering vi -V
and vim -V
.
Use .vimrc
if you call vim
and .virc
if you call vi
. Or simply alias vi=vim
for using .vimrc
Solution 4
Beware one thing: there is a Cygwin port of vim, and a native win32 port of vim. Both have their advantages and their flaws when dialogue with cygwin or native-win32 applications is concerned.
A category on vim.wikia is dedicated to cygwin related tips.
Solution 5
Some parts of file system of Cygwin use your "host" file system as its own. Within cygwin, there is a user home directory (which actually resides under your "Documents and Settings/Username" folder), so you should place it there.
Just place your .vimrc somewhere you know how to access via cygwin and do a
directory/you/know$ cp .vimrc ~/
It will work--at least worked with default vim
on my Cygwin installation several months ago.
Nathan Long
I code mostly in Elixir, sometimes Ruby. More about me at nathanmlong.com and Stackoverflow Careers.
Updated on January 20, 2020Comments
-
Nathan Long over 4 years
I just installed Cygwin on my work machine and would like to use the .vimrc file I use on my Linux box at home.
- Is that possible, or does it need to have Cygwin-specific settings?
- Where would I put the .vimrc file?
I'm a little unsure of what directory I'm being dropped into at the bash prompt under Cygwin, but I think I'd create a subdirectory called .vim there, right?