Wansmer / langmapper.nvim

A plugin that makes Neovim more friendly to non-English input methods 🤝
MIT License
128 stars 7 forks source link

According to langmapper, default_layout and layout contain different number of characters, but they dont. #21

Closed agoodfellow123 closed 4 months ago

agoodfellow123 commented 4 months ago

Hi there, anytime I open my neovim I get a non-descriptive error about there being different amount of characters in my layout and default layout. Plus to that when I press space and enter whickey mode it defaults back to default keyboard. Which I think is connected to this problem, here is the entire lua file:

local function escape(str)
  -- You need to escape these characters to work correctly
  local escape_chars = [[;,."|\]]
  return vim.fn.escape(str, escape_chars)
end

-- Recommended to use lua template string
local en = [[`qwertyuiop[]asdfghjkl;'\zxcvbnm,./]]
local tr = [["qwertyuıopğüasdfghjklşi,zxcvbnmöç.]]
local en_shift = [[~QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?]]
local tr_shift = [[éQWERTYUIOPĞÜASDFGHJKLŞİ;ZXCVBNMÖÇ:]]

vim.opt.langmap = vim.fn.join({
    -- | `to` should be first     | `from` should be second
    escape(tr_shift) .. ';' .. escape(en_shift),
    escape(tr) .. ';' .. escape(en),
}, ',')

local default_config = {
  ---@type boolean Add mapping for every CTRL+ binding or not.
  map_all_ctrl = true,
  ---@type string[] Modes to `map_all_ctrl`
  ---Here and below each mode must be specified, even if some of them extend others.
  ---E.g., 'v' includes 'x' and 's', but must be listed separate.
  ctrl_map_modes = { 'n', 'o', 'i', 'c', 't', 'v' },
  ---@type boolean Wrap all keymap's functions (nvim_set_keymap etc)
  hack_keymap = true,
  ---@type string[] Usually you don't want insert mode commands to be translated when hacking.
  ---This does not affect normal wrapper functions, such as `langmapper.map`
  disable_hack_modes = { 'i' },
  ---@type table Modes whose mappings will be checked during automapping.
  automapping_modes = { 'n', 'v', 'x', 's' },
  ---@type string Standart English layout (on Mac, It may be different in your case.)
  default_layout = [[~QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?`qwertyuiop[]asdfghjkl;'\zxcvbnm,./]],
  ---@type string[] Names of layouts. If empty, will handle all configured layouts.
  use_layouts = {tr},
  ---@type table Fallback layouts
  layouts = {
    ---@type table Fallback layout item. Name of key is a name of language
    tr = {
      ---@type string Name of your second keyboard layout in system.
      ---It should be the same as result string of `get_current_layout_id()`
      id = 'tr',
      ---@type string Fallback layout to translate. Should be same length as default layout
      layout = [[éQWERTYUIOPĞÜASDFGHJKLŞİ;ZXCVBNMÖÇ:"qwertyuıopğüasdfghjklşi,zxcvbnmöç.]],
      ---@type string if you need to specify default layout for this fallback layout
      default_layout = tr,
    },
  },
}

return {
  'Wansmer/langmapper.nvim',
  lazy = false,
  priority = 1, -- High priority is needed if you will use `autoremap()`
  config = function()
    require('langmapper').setup(default_config)
  end,
}
Wansmer commented 4 months ago

Hi! About which-key see here.

By subject:

use_layouts = {tr}, -- Should be string with layout ID, not a langmap values, e.g. {"tr"}
  layouts = {
    tr = {
      id = 'tr', -- This is ID
      layout = [[éQWERTYUIOPĞÜASDFGHJKLŞİ;ZXCVBNMÖÇ:"qwertyuıopğüasdfghjklşi,zxcvbnmöç.]],
      default_layout = tr, -- Remove this line, you already set default layout above
    },
agoodfellow123 commented 4 months ago

Hello, thank you for your answer. I have set the config as you suggested unfortunately it still gives the same warning:

  use_layouts = {"tr"},
  layouts = {
    tr = {
      id = 'tr',
      layout = [[éQWERTYUIOPĞÜASDFGHJKLŞİ;ZXCVBNMÖÇ:"qwertyuıopğüasdfghjklşi,zxcvbnmöç.]],
    },

Just for good measure, I count the characters again, both layouts has 70 characters, so perhaps there is an escape character in one of the layouts? I tried adding \\ instead of \ unfortunately that didn't change anything.

As for whichkey, I don't want to make it english I just want to make it use the same bindings as the other modes use, for example Ş in Turkish keyboard is : in English keyboard and I use that in normal mod to get in command mod, so I want whichkey to show Ş instead instead of :.

Wansmer commented 4 months ago

Fixed the wrong number of characters bug and along the way a few other issues that came up when using the Turkish layout.

About which-key: I don't use which-key, so I can't help you to customize the display of Turkish characters only.