Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syncing vimrc and plugins between unix and windows machine

Tags:

vim

I am using the method described in this screencast to keep my vimrc and plugins synced across multiple machines. The problem I'm running into is that one machine is running ubuntu and the other running win7.

I've found two types of problems so far. The first seems to be with line endings. To get my windows vimrc to be read on the linux box, I had to do :set fileformat=unix and write. But even after doing that, I am getting similar line-ending problems with all the plugins:

jg@jg-VirtualBox:~$ vim ~/.vimrc
Error detected while processing /home/jg/.vimrc:
line   11:
E484: Can't open file /home/jg/vimfiles/plugin/autotag.vim
Error detected while processing /home/jg/.vim/plugin/DrawIt.vim:
line   60:
E492: Not an editor command: ^M
line   62:
E15: Invalid expression: &cp^M
line 1290:
E171: Missing :endif
Error detected while processing /home/jg/.vim/plugin/auto_number.vim:
line    5:
E488: Trailing characters

I could do something like vim ~/.vim/**/*.vim to load them all and then :argdo set ff=unix | w to fix all the files in the same way, but that seems like a poor method, since any time I update the git repo with my vimfiles from one computer and pull it from the other, I'll have to remember to do this file conversion. Is there a better way?

Finally, certain configuration details in the vimrc, such as the location of the location of certain binaries, will be different depending on the OS. What is the best way to handle these differences? Should I be peppering my .vimrc with if statements branching on has("gui_win32"), or is there a better way?

Thanks!

like image 861
Jonah Avatar asked Apr 22 '26 13:04

Jonah


1 Answers

Yes, you'll have to add branches in your vimrc to have machine/OS-specific settings. That's not as dirty as it sounds: a single if/ifelse/endif is enough.

Another approach is to keep your machine/OS specific settings in a separate non-version-controled file: because it is very localized, you don't need to propagate its contents on other machines/OSes.

You could put these settings in ~/.vim/vimrc.local and explicitely add this file to .gitignore or outside of the repo in ~/.vimrc.local and source that file from your vimrc.

Vim has troubles with Windows line endings on Linux but it doesn't have troubles dealing with Linux line endings on Windows. Just use Linux line endings everywhere and you'll be fine.

like image 192
romainl Avatar answered Apr 26 '26 08:04

romainl