问题
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?
回答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
回答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.
回答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
回答4:
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.
回答5:
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 ~
orcd $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 typegetclip > ~/.vimrc
Start vi/vim to see if your new settings have taken effect:vi
回答6:
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.
回答7:
I had to rename / symlink my .vimrc
file to .virc
in a directory like /home/Leo/.virc
or more generally $HOME/.virc
.
回答8:
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)
回答9:
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.
来源:https://stackoverflow.com/questions/1494631/how-do-i-use-my-vimrc-file-in-cygwin