diff --git a/lua/lualine/components/encoding.lua b/lua/lualine/components/encoding.lua index f40aecc..80a5ece 100644 --- a/lua/lualine/components/encoding.lua +++ b/lua/lualine/components/encoding.lua @@ -1,7 +1,7 @@ -- Copyright (c) 2020-2021 hoob3rt -- MIT license, see LICENSE for more details. local function encoding() - return [[%{strlen(&fenc)?&fenc:&enc}]] + return vim.opt.fileencoding:get() end return encoding diff --git a/lua/tests/spec/component_spec.lua b/lua/tests/spec/component_spec.lua index 18ed4a8..1697ae9 100644 --- a/lua/tests/spec/component_spec.lua +++ b/lua/tests/spec/component_spec.lua @@ -210,7 +210,13 @@ describe('Encoding component', function() component_separators = { left = '', right = '' }, padding = 0, } - assert_component('encoding', opts, '%{strlen(&fenc)?&fenc:&enc}') + local tmp_path = 'tmp.txt' + local tmp_fp = io.open(tmp_path, 'w') + tmp_fp:write 'test file' + tmp_fp:close() + vim.cmd('e ' .. tmp_path) + assert_component('encoding', opts, 'utf-8') + os.remove(tmp_path) end) end)