繁体   English   中英

关于Cygwin的Vim:警告vimrc正在使用windows end of line char

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

我刚刚在我的机器上安装了cygwin,我只是设置了一切。

我在我的cygwin主目录中的.vimrc和我的windows home dir之间创建了一个软链接,但是vim在读取.vimrc文件时遇到了一些困难,因为它使用的是Windows行尾字符。

是否有一些方法可以用来警告vim我的vimrc文件正在使用windows end of line char?

这是一些输出。

~ $ 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
...

来自cygwin类型

dos2unix.exe _vimrc

如果启用了模式行,则可以将其作为vimrc中的第一行输入

" vim: se ff=unix :

当然,你必须在第一次手动修复它( :se ff=dos|w!

这样您就不必被警告,因为您将始终处于此文件的正确模式。

如果您想要所有文件,请查看自动命令(AuCommand,例如BufEnter)。 如果您只想始终看到fileformat,可以将其包含在标尺或状态行中

:he 'rulerformat'
:he 'statusline'

例如简单的状态线

:set statusline='%{&fileformat}'

HTH

PS如果你的文件需要更多的fixin',因为它已经混合了行尾,你可以

:%s/^M$//g

一定要添加$或你的中断映射。 输入^ M为CTRL-Q上的窗口(Ctrl-V键 Linux上输入 ;所有假设默认CONFIGS) 输入

我在状态行中有这个:

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

这样做的是,如果我加载一个有dos行结尾的文件,我会在状态行中得到这个漂亮的红色“dos”。

从cygwin shell中,您可以输入:

dos2unix.exe .vimrc

这会将您的文件转换为unix格式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM