Command line option to open mac formatted file in Vim

百般思念 提交于 2019-12-09 17:04:45

问题


I have a file with mac format, I know I can use :e! ++ff=mac to change to the correct fileformat. What I'd like to know is if there is a command line option I can pass when I open the file to open it directly with the correct fileformat.


回答1:


You can do this using the command line, try:

$ vim -c "set fileformat=mac"

-c <command> executes before loading the first file. As jammessan has noted, this will only affect the first file that is loaded, subsequent files will require that you change fileformat for each buffer.

If that doesn't work, you can also try:

$ vim -c "e ++ff=mac"

But it's better to set this up in your .vimrc on that machine:

set fileformats=mac,unix,dos

specifies which formats to try when starting a new buffer. This also can influence what fileformat is chosen for existing files.

See help file-formats, :help 'fileformat' and :help 'fileformats' for more details.




回答2:


The better solution would be to make Vim automatically recognize files in that format. You can do this by updating the 'fileformats' option in your ~/.vimrc

set fileformats=unix,dos,mac

This will make Vim check all three formats when determining which format a file is in.



来源:https://stackoverflow.com/questions/10952327/command-line-option-to-open-mac-formatted-file-in-vim

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