Giter Site home page Giter Site logo

b0o / mapx.nvim Goto Github PK

View Code? Open in Web Editor NEW
255.0 5.0 5.0 196 KB

๐Ÿ—บ A better way to create key mappings in Neovim

License: MIT License

Lua 93.78% Makefile 0.08% Shell 5.99% Vim Script 0.15%
neovim vim neovim-lua neovim-lua-plugin lua neovim-configuration vim-configuration nvim

mapx.nvim's Issues

Execute multiple commands using a dictionary

I'm looking for a quick way to execute vim commands without writing functions, like so.

nnoremap([[keymap]], {Command1, Command2, Command3}, silent)

So if the second function in nnoremap is a table, each command in the table can be called using vim.fn.execute or similar.

Is something like this feasible or available, without using Lua functions?

Packer.nvim recompile error

Prevent packer.nvim from PackerCompile twice.

packer.compile: Complete
packer.nvim: Error running config for mapx.nvim: [string "..."]:0: attempt to call field 'setup' (a boolean value)

It's annoying as I have to delete the plugin/packer_compiled.lua manually.

Announcements

Important information will be announced here, such as new major versions and breaking changes. Please subscribe to this issue to receive a notification when there's a new announcement.

`v:count` parameter passed to Lua functions causing conflicts

Hello, I really like the idea of this plugin and have something similar implemented in my dotfiles:

local escape_cmd = function(string)
    return string:gsub("'", "\\'"):gsub('"', '\\"'):gsub('\\[', '\\['):gsub('\\]', '\\]'):gsub('<', '<lt>')
end

local bounded_funcs = 'global_bounded_funcs_namespace'
_G[bounded_funcs] = {}
for _, mode in ipairs { '', 'n', 'i', 'v', 't', 's' } do
    _G[mode .. 'noremap'] = function(input, output)
        if type(output) == 'function' then
            local func_name = mode .. '_' .. input
            local func_name_escaped = escape_cmd(func_name)
            _G[bounded_funcs][func_name] = output
            local lua_cmd = ':lua ' .. bounded_funcs .. "['" .. func_name_escaped .. "']()<cr>"
            vim.api.nvim_set_keymap(mode, input, lua_cmd, { noremap = true, silent = true })
        elseif type(output) == 'string' then
            vim.api.nvim_set_keymap(mode, input, output, { noremap = true, silent = true })
        else
            error(mode .. 'noremap' .. ' expects a string or callback', 2)
        end
    end
end

This generates the [nivts]noremap family of functions which have two arguments. The first argument is the input keybinding and the second is either a string which can be a vim command OR it can be lua callback. This allows me to make the following types of mappings:

  1. Mappings where the second argument is a string.
nnoremap('<leader>a', ':echo "using lua string"')
  1. Mappings where the second argument is an anonymous function.
nnoremap('<leader>b', function() print('using anonymous function') end)
  1. Mappings where the second argument is a named function (useful for mapping functions provided by other plugins).
my_func = function() print('using named function') end
nnoremap('<leader>c', my_func)

I tried switching to mapx.nvim, mainly for the which-key.nvim integration and while example 1 and 2 work I'm not able to bind named functions. I know I can wrap the functions in an anonymous function but I'm just wondering why it doesn't work and what mistake I'm making.

`v:lua` string doesn't work

I have the following code to be converted.

local escape = function(str)
  return vim.api.nvim_replace_termcodes(str, true, true, true)
end

-- HACK
function _G.enhance_align()
  if not packer_plugins["vim-easy-align"].loaded then
    vim.cmd [[packadd vim-easy-align]]
  end
  return escape "<Plug>(EasyAlign)"
end

function M.setup_easy_align()
  vim.api.nvim_set_keymap("n", "ga", "v:lua.enhance_align()", { expr = true })
  vim.api.nvim_set_keymap("x", "ga", "v:lua.enhance_align()", { expr = true })
end

First I tried the following, which doesn't work

  mapx.nmap("ga", "v:lua.enhance_align()", mapx.expr)
  mapx.xmap("ga", "v:lua.enhance_align()", mapx.expr)

Then I make it work using the following

  mapx.nmap("ga", enhance_align, mapx.expr)
  mapx.xmap("ga", enhance_align, mapx.expr)

I am not sure whether this is a bug.

Integration with whichkey doesn't work

Hi, when enable the whichkey integration, the following works

  mapx.nmap("]t", '<cmd>lua require("trouble").next({skip_groups = true, jump = true})<CR>')
  mapx.nmap("[t", '<cmd>lua require("trouble").previous({skip_groups = true, jump = true})<CR>')

while the following doesn't

  mapx.nmap("]t", '<cmd>lua require("trouble").next({skip_groups = true, jump = true})<CR>', "Next Trouble")
  mapx.nmap("[t", '<cmd>lua require("trouble").previous({skip_groups = true, jump = true})<CR>', "Previous Trouble" )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.