1

我的 中有以下几行.vimrc

" UNIX fileformat
au BufRead,BufNewFile * set fileformats=unix,dos
au BufRead,BufNewFile * set fileformat=unix

这些是使用 unix 文件格式制作任何打开的文件。

除了帮助消息外,它几乎适用于所有情况。如果我输入,让我们说:

:h help

Vim 首先抱怨:

"helphelp.txt" [readonly] 350L, 13662C Error detected while processing
BufRead Auto commands for "*": E21: Cannot make changes, 'modifiable'
is off: fileformat=unix

显然,我试图在不可修改的缓冲区上设置 fileformat 选项,所以这个错误是可以预料的。但是,在不删除其他文件功能的情况下摆脱它的最干净的方法是什么?

有没有办法有条件地应用/不应用帮助缓冲区的自动命令?

谢谢你。

4

1 回答 1

3

'fileformats'是一个全局设置,只需在 .vimrc 中设置一次就足够了:

set fileformats=unix,dos

任何其他不可修改的文件都会发生该错误,而不仅仅是帮助文件。因此,最好以'modifiable'缓冲区设置为条件进行设置:

au BufRead,BufNewFile * if &l:modifiable | setlocal fileformat=unix | endif

(Alternatively, you could also just :silent! the error, but I regard the conditional as cleaner.)

于 2012-07-09T10:27:55.977 回答