Wansmer / langmapper.nvim

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

Help with minimal config #18

Closed virus-found closed 7 months ago

virus-found commented 7 months ago

I am new to both nvim (a vim user here), to lua and to lazy.nvim I just came here, copy pasted what I figured out to be needed and can't get it to work.

~/.config/nvim/init.lua

  {                                                                                                                                                                                                                                                                               
    'Wansmer/langmapper.nvim',                                                                                                                                                                                                                                                    
    lazy = false,                                                                                                                                                                                                                                                                 
    priority = 1, -- High priority is needed if you will use `autoremap()`                                                                                                                                                                                                        
    config = function()                                                                                                                                                                                                                                                           
      require('langmapper').setup({                                                                                                                                                                                                                                               
        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),                                                                                                                                                                                                                                      
        }, ',')                                                                                                                                                                                                                                                                   
      })                                                                                                                                                                                                                                                                          
    end,                                                                                                                                                                                                                                                                          
  },            

and in the very end:

require('langmapper').automapping({ global = true, buffer = true })                                                                                                                                                                                                               
-- end of init.lua

Using lazy.nvim as a plugin manager. Starting nvim gives me: E5112: Error while creating lua chunk: ~/.config/nvim/init.lua:248: unexpected symbol near 'local' 248 is: local function escape(str)

Wansmer commented 7 months ago

You don't need to add code setting vim.opt.langmap to the settings table. This basically breaks Lua syntax. Read : h luaref.

Add this code to the root of the init.lua file along with the other options.