langmapper.nvim icon indicating copy to clipboard operation
langmapper.nvim copied to clipboard

langmapper.nvim with lazivim

Open mr-scrpt opened this issue 11 months ago • 2 comments

Hi. I am using the lazivim build and decided to try your plugin with it. Normal, native vim keyboard shortcuts like V (Select all line) works and when pressing ‘M’ (cyrillic), but hotkeys from plugins don't work, for example calling search sg(latin) doesn't work ып(cyrillic). Is there any way to make all keyboard shortcuts, default for lazivim or any other custom build, work with Langmapper.nvim?

  "Wansmer/langmapper.nvim",
  lazy = false,
  priority = 1, -- High priority is needed if you will use `autoremap()`
  config = function()
    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 ru = [[ёйцукенгшщзхъфывапролджэячсмить]]
    local en_shift = [[~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>]]
    local ru_shift = [[ËЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ]]

    vim.opt.langmap = vim.fn.join({
      -- | `to` should be first     | `from` should be second
      escape(ru_shift)
        .. ";"
        .. escape(en_shift),
      escape(ru) .. ";" .. escape(en),
    }, ",")
    require("langmapper").setup({--[[ your config ]]
    })
  end,
}

mr-scrpt avatar Feb 05 '25 09:02 mr-scrpt

Hi. You should use automapping: https://github.com/Wansmer/langmapper.nvim?tab=readme-ov-file#with-automapping

Personally, I am not use LazyVim but as I know it can be used with Langmapper. Example: https://github.com/aimuzov/LazyVimx/blob/3cebc80d9e08d7fc2d5d4995ee22d34f55c74f01/lua/lazyvimx/extras/nav/langmapper.lua

Wansmer avatar Feb 05 '25 15:02 Wansmer

@mr-scrpt I use langmapper with LazyVim and it works great! Here is my config with additional filtration of cyrllic keybindings for which-key and snacks-picker help window:

return {
  {
    "Wansmer/langmapper.nvim",
    lazy = false,
    enabled = true,
    priority = 1, -- High priority is needed if you will use `autoremap()`
    opts = {},
  },
  {
    "folke/which-key.nvim",
    opts = function(_, opts)
      local translate_key = require("langmapper.utils").translate_keycode
      -- don't show mappings translated by langmapper.nvim. Show entry if func returns true
      opts.filter = function(mapping)
        return mapping.lhs
          and mapping.lhs == translate_key(mapping.lhs, "default", "ru")
          and mapping.desc
          and mapping.desc:find("LM") == nil
      end
    end,
  },
  {
    "folke/snacks.nvim",
    optional = true,
    opts = function(_, _)
      local translate_key = require("langmapper.utils").translate_keycode
      local normkey_orig = Snacks.util.normkey
      Snacks.util.normkey = function(key)
        if key then
          key = translate_key(key, "default", "ru")
        end
        return normkey_orig(key)
      end
    end,
  },
}

trems avatar Apr 15 '25 09:04 trems