Search code examples
vimencodingutf-8line-endings

Is there a command you can enter into a Vim _gvimrc file to set default encoding and line endings?


Is there a command you can enter into a _gvimrc file to set default encoding and line endings?

I'm working on a Windows machine but i would like to create and edit files using UTF-8 encoding (no BOM) and standard Unix line endings (\n).

Can i set Vim up to create files with these specs?


Solution

  • After a while of reading and experimenting:

    Set these in _gvimrc

    set encoding=utf-8                      "Set default buffer encoding to UTF-8.
    set fileencodings=utf-8,latin1          "Set the order of file encodings when reading and creating files.
    set fileformats=unix,dos,mac            "Set the order of line endings when reading and creating files.
    

    These should be used in the command line.

    set fileencoding=utf-8                  "Change an opened file's encoding.
    set fileformat=unix                     "Change an opened file's line endings.