Vim on Cygwin: Warn that vimrc is using windows end of line char

六眼飞鱼酱① 提交于 2019-12-30 06:09:10

问题


I just installed cygwin on my machine and I am just getting everything setup.

I created a softlink between .vimrc in my cygwin home dir and my windows home dir but vim is having some difficulties reading the .vimrc file since it is using windows end of line characters.

Is there some method that I can use to warn vim that my vimrc file is using windows end of line char?

Here is some output.

~ $ ls -la
total 43
drwxr-xr-x+ 1 Jake None    0 Mar 30 10:11 .
drwxrwxrwt+ 1 Jake root    0 Mar 30 09:33 ..
-rw-------  1 Jake None  504 Mar 30 10:10 .bash_history
-rwxr-xr-x  1 Jake None 1103 Mar 29 14:24 .bash_profile
-rwxr-xr-x  1 Jake None 5737 Mar 30 10:06 .bashrc
-rwxr-xr-x  1 Jake None 1461 Mar 29 14:24 .inputrc
-rw-------  1 Jake None   57 Mar 30 10:05 .lesshst
-rwxr-xr-x  1 Jake None 8945 Mar 30 09:52 .mkshrc
-rwxr-xr-x  1 Jake None  792 Mar 29 14:24 .profile
-rw-------  1 Jake None 1087 Mar 30 10:11 .viminfo
lrwxrwxrwx  1 Jake None   29 Mar 30 10:05 .vimrc -> /cygdrive/c/Users/Jake/_vimrc
~ $
~ $ vim
Error detected while processing /home/Jake/.vimrc:
line    2:
E492: Not an editor command: ^M
line    3:
E492: Not an editor command: ^M
line    4:
E492: Not an editor command: ^M
line    5:
E492: Not an editor command: ^M
line   11:
E492: Not an editor command: ^M
line   14:
E492: Not an editor command: ^M
line   16:
E492: Not an editor command: ^M
line   20:
E492: Not an editor command: ^M
line   21:
E492: Not an editor command: ^M
line   22:
E492: Not an editor command: ^M
line   27:
E474: Invalid argument: backspace=indent,eol,start^M
...

回答1:


From cygwin type

dos2unix.exe _vimrc



回答2:


If you have modeline enabled, you could enter this as the first line in your vimrc

" vim: se ff=unix :

of course, you'd have to fix it manually the first time around (:se ff=dos|w!)

This way you don't have to be warned, because you'll always be in the right mode for this file.

If you wanted it for all files, look at auto commands (AuCommand, e.g. BufEnter). If you wanted just to always see the fileformat, you can include it in the ruler or statusline

:he 'rulerformat'
:he 'statusline'

e.g. simplistic status line

:set statusline='%{&fileformat}'

HTH

P.S. If your file needs more fixin' because it was already mixing line-ends, you can

:%s/^M$//g

be sure to add the $ or you'd break mappings. Enter ^M as Ctrl-QEnter on windows (Ctrl-VEnter on Linux; all assuming default configs)




回答3:


I have this in my status line:

hi User9 term=reverse cterm=bold ctermbg=12 gui=bold guibg=Red
set statusline=...
set statusline+=\ %9*%{&ff=='unix'?'':&ff.'\ format'}%*

What that does is that if I ever load up a file that has dos line endings, I get this nice red "dos" in my status line.




回答4:


From cygwin shell, you can type:

dos2unix.exe .vimrc

This will convert your file to unix format.



来源:https://stackoverflow.com/questions/5487527/vim-on-cygwin-warn-that-vimrc-is-using-windows-end-of-line-char

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!