Vim encodings: latin1 and utf-8

Here's my problem:

  • when i open the file i get this message from vim:

    "myfilename.sql" [converted] 78565L, 10487381C
    
          

  • if i do :set

    i get:

    Options
      backspace=2         colorcolumn=+1      formatoptions=qc    scrolloff=15        smartindent         textwidth=80        visualbell
      backup              expandtab           ignorecase          shiftwidth=4        syntax=sql          ttyfast             t_vb=
      bomb                filetype=sql        number              showcmd             tabstop=4           ttymouse=sgr
      backupdir=~/.vim/backup
      comments=s1:/*,mb:*,ex:*/,:--,://
      define=\c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>
      directory=~/.vim/tmp
      fileencoding=utf-8
      fileencodings=utf-8,ucs-bom,default,latin1
      matchpairs=(:),{:},[:],<:>
      omnifunc=sqlcomplete#Complete
      viminfo='10,"100,:20,%,n~/.viminfo
    
          

  • I have symbols visible like this:

    vim bad encoding

  • I found that if I reload and force encode latin1 with :e ++enc=latin1

    , I get the accents correct, but not all:

    vim almost good encoding

  • So I found out (the only solution) to get all the correct visible encoding to manually force back to utf8 : :set encoding=utf8

    , then I get:

    vim good encoding

  • if i do :set

    i get:

    --- Options ---
      backspace=2         encoding=utf-8      formatoptions=qc    scrolloff=15        smartindent         textwidth=80        visualbell
      backup              expandtab           ignorecase          shiftwidth=4        syntax=sql          ttyfast             t_vb=
      colorcolumn=+1      filetype=sql        number              showcmd             tabstop=4           ttymouse=sgr
      backupdir=~/.vim/backup
      comments=s1:/*,mb:*,ex:*/,:--,://
      define=\c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>
      directory=~/.vim/tmp
      fileencoding=latin1
      fileencodings=utf-8,ucs-bom,default,latin1
      matchpairs=(:),{:},[:],<:>
      omnifunc=sqlcomplete#Complete
      viminfo='10,"100,:20,%,n~/.viminfo
    
          

  • As you can see, I see fileencoding=latin1

    , so I'm trying to get him to use the utf8: :set fileencoding=utf-8

    . I save it :wq

    and whenever I want to open it again nothing has changed, I still need to do all of this to get a good preview with good accents!

  • The only thing I want from now on is to save it so that I can reopen it without having it all to get it right. What should I do?

+3


source to share


2 answers


and file encoding are two options in vim. please read the doc help for details.

If your file was encoded as UTF-8, the easiest way to read it is to install encoding=utf-8

and fileencoding=utf-8

.



You can add these lines to your vimrc to make it the default.

+1


source


Short answer: I had a similar problem with displaying international characters as ▒ and it was fixed with

:set termencoding=utf-8

      

Longer answer: here are three related settings. They usually do the right thing automatically, but if they don't, you can install them.



  • : set encoding - set encoding used to read the file
  • : set fileencoding - set the encoding used when saving the file
  • : set termencoding - set the encoding for displaying characters to your terminal.

The odd results you described can happen if, for example, the file is UTF-8, but Vim reads it as Latin1, and at the same time your terminal is UTF-8, but Vim writes to the terminal as Latin1. In this case, the characters may look correct even if everything is ok. You can test this hypothesis by hovering over the corresponding character and clicking ga

to find its encoded value.

0


source







All Articles