Skip to content

Instantly share code, notes, and snippets.

@pguimier
Created March 21, 2023 13:56
Show Gist options
  • Save pguimier/b4928911887e02d102c9a645b7f27a3f to your computer and use it in GitHub Desktop.
Save pguimier/b4928911887e02d102c9a645b7f27a3f to your computer and use it in GitHub Desktop.
-- ~/.config/nvim/lua/custom/utils.lua
-- vim.keymap.set('n', '<F4>', function () require("custom.utils").toggleEncoding() end, {desc = 'Toggle encoding'})
local M = {}
M.encIndex = 1
local encodings = {'latin1', 'iso-8859-15', 'utf-8', 'ucs-bom'}
M.toggleEncoding = function()
local command = 'e ++enc=' .. encodings[M.encIndex] .. ' %:p'
print("Reopen file using " .. encodings[M.encIndex] .. " encoding")
vim.cmd(command)
if M.encIndex >=3 then
M.encIndex = 1
else
M.encIndex = M.encIndex + 1
end
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment