27

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?

Nathan Long
  • 122,748
  • 97
  • 336
  • 451
  • I just got a badge for this question, but it really belongs on Superuser. Voted to move it there. – Nathan Long Dec 20 '11 at 19:22
  • `vim --version | grep vimrc` It shows all observable locations. Many [thanks](http://stackoverflow.com/questions/15651286/where-is-vimrc-or-vim-profile-for-githubs-mingw32-shell-on-a-windows-machine/15651421#15651421) – it3xl Dec 11 '16 at 18:23

10 Answers10

39

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.

Community
  • 1
  • 1
Johntron
  • 2,443
  • 2
  • 24
  • 26
  • In the latest cygwin (1.7.x x86) `vim-minimal` is installed by default from the Base category which provides `/bin/vi`. even if you install `vim (Vi Enhanced)` from Editors `/bin/vi` is still from `vim-minimal`. Your suggestion was easier than breaking the package installed /bin/vi and symlinking it to /bin/vim and will work across my linux/darwin systems. My previous cygwin 1.7.x (before they just broke out x84 vs. x64) used /etc/alternatives to figure out the system vi so I didn't need to do anything to fix this before. – johnnyB Nov 22 '13 at 00:08
  • 6
    Its better to use "ln -s ~/.vimrc ~/.virc" instead of cp. If you don't one day you'll be editing .vimrc and begin to wonder again why your changes have no effect. – ndemou Nov 13 '14 at 09:32
  • @ndemou I agree, but I have no way to test at the moment. I know Windows doesn't support symlinks out of the box, but if you confirm it works, I'll update my answer. – Johntron Jul 25 '16 at 00:24
  • @JohnSyrinek, I've used symlinks on windows 7 as explained here http://stackoverflow.com/questions/18654162/enable-native-ntfs-symbolic-links-for-cygwin/18659632#18659632 – ndemou Jul 25 '16 at 09:29
19

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

wolfrevo
  • 6,651
  • 2
  • 26
  • 38
14

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

vehomzzz
  • 42,832
  • 72
  • 186
  • 216
  • 2
    Your cygwin ~ directory (at least by default on xp) is c:\documents and settings\username – stonemetal Sep 29 '09 at 20:36
  • 7
    I believe the default installion use: c:\cygwin\home\ – Amro Sep 30 '09 at 08:22
  • @vehomzzz Unlike in other *nix (e.g. debian) both commands slightly differ in their behaviour on starting vi/vim. See my answer. – wolfrevo Feb 09 '14 at 11:44
  • 1
    @stonemetal Just wanted to update that the home directory is no longer in "Documents and settings" on Windows. In fact Cygwin will give you a warning if you try to use a directory with spaces in it as the home directory. It's just c:\cygwin (or c:\cygwin64 as my 64-bit version called it). – felwithe Sep 14 '19 at 12:52
2

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.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
1

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.

P Shved
  • 96,026
  • 17
  • 121
  • 165
1

I don't see any reason why your Linux ~/.vimrc should not work in your cygwin install.

To go to your home directory in cygwin,
cd ~
or
cd $HOME

In Windows, you can use WinSCP to connect to your Linux box, open your Linux .vimrc in the WinSCP default editor, copy the contents. Then switch to the Cgywin terminal and type
getclip > ~/.vimrc

Start vi/vim to see if your new settings have taken effect:
vi

1

I had to rename / symlink my .vimrc file to .virc in a directory like /home/Leo/.virc or more generally $HOME/.virc.

Leopd
  • 41,333
  • 31
  • 129
  • 167
0

I just created my own and worked out of box:

1) vim ~/.vimrc

Once inside the .vimrc (blank file) I like to copy the example from:

2) :r $VIMRUNTIME/vimrc_example.vim
3) :wq

Then check any file should have lots of color and stuff

4) vim .vimrc (or whatever file, e.g. ~/.bashrc)
0

simply navigate to your home directory which is c:/Users/user_name/ create the file using vi .vimrc set your preferences here, and they would surely reflect like

set nu "show line numbers
set ai "auto indentations 
colors blue " or elflord or whatever you like.

save and try.

0

I had issue with Cygwin vi tabstop. It was always defaulting to 8. While launching it was giving error "Failed to source defaults.vim" Tried to follow various solutions but below worked for me.

Create .vim directory under current user home ($HOME) directory.

Create .virc file under .vim directory.

Add below line to .virc

set tabstop=4

Cygwin version details CYGWIN_NT-10.0-22000 3.3.5-341.x86_64 x86_64 Cygwin

Praful
  • 1
  • 2