Created
March 21, 2023 13:56
-
-
Save pguimier/b4928911887e02d102c9a645b7f27a3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ~/.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