Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VIM changes encoding of all buffers when using setlocal?

Tags:

vim

When I'm using setlocal encoding on VIM to change the buffer encoding VIM changes the encoding of all buffers. It's really annoying because I'm editing files in different encoding and I'm corrupting them all the time. I tried it by creating two buffers, did a setlocal encoding=latin1 on one, a setlocal encoding=utf-8 on the other : the encoding is always the same on the two buffers and it's always the last encoding I set.

setlocal works well on 'shiftwidth' for example, the issue only exhibits on the encoding option.

I tried to reinstall a new copy of VIM, I tried the 7.2 and 7.1, I still have the issue. I've disabled all my plugins, my vimrc.

Am I losing my mind thinking that it's the way it used to work ? Do you have some idea that might cause that ?

I'm using VIM on Windows 7 if that's important.

like image 544
Emmanuel Caradec Avatar asked Nov 21 '25 15:11

Emmanuel Caradec


1 Answers

'encoding' is a global option that dictates how Vim treats text internally so you are two times wrong.

  1. setlocal doesn't work for global-only options like 'encoding'.

    :help 'option' tells you the "scope" of 'option'.

  2. 'encoding' is not the option you are looking for, you want :set fileencoding=utf-8.

Reference:

:help 'encoding'
:help 'fileencoding'
:help 'setlocal'
like image 126
romainl Avatar answered Nov 24 '25 08:11

romainl