Sawyer
Sawyer

Reputation: 15927

automatically set certain filetype's file format to unix

How can I let vim automatically set the file format as UNIX for certain filetypes? For example if I create a script.sh, and I want vim automatically set the file format to UNIX, now it's DOS.

Upvotes: 0

Views: 440

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172768

In ~/.vim/after/ftplugin/sh.vim, put the following:

if &modifiable
    setlocal fileformat=unix
endif

Alternatively, you can also configure this via an explicit :autocmd in your ~/.vimrc

autocmd FileType sh if &modifiable|setlocal fileformat=unix|endif

(But I would recommend using the provided abstractions to avoid cluttering your vimrc file.)

Upvotes: 3

Related Questions