Git Product home page Git Product logo

nvim-keymapper's Introduction

nvim-keymapper

Telescope extension for creating, documenting, and searching your Neovim keymappings.

screenshot

Why?

I created nvim-keymapper as a replacement for Telescope's built-in keymaps picker. I wanted something that only shows my custom keymaps and will also show a short documentation string that I can use to help remember what some of the mappings do. The documentation strings are also searchable in the Telescope picker, and the picker uses highlight groups to distinguish sections.

Install

  1. Install Telescope.
  2. Register nvim-keymapper as a Telescope extension:
    require('telescope').load_extension('nvim-keymapper')
  3. Set up commands and keymappings:
    local keymapper = require('nvim-keymapper')    
    vim.api.nvim_create_user_command('Keymaps', keymapper.keymaps_picker, {desc = 'Telescope: Show keymaps'})
    vim.api.nvim_create_user_command('AllKeymaps', builtin.keymaps, {desc = 'Telescope: Show all keymaps'})
    keymapper.set('n', '<leader>k', ':Keymaps<CR>', {}, 'Telescope: Show keymaps')

Usage

Creating Keymaps

Use the nvim-keymapper.set function to create your keymaps instead of vim.keymap.set. The first four arguments (mode, lhs, rhs, ops) are the same as vim.keymap.set and are passed through. The fifth argument is a documentation string and will also be set as opts.desc.

Example: Create a keymap for opening a terminal in a vertical split.

local keymapper = require('nvim-keymapper')
keymapper.set('n', '<leader>T', '<ESC>:vsplit | term<CR>', {}, 'Open a terminal in a vertical split')

Using the Telescope Picker

You can start the Telescope picker using the Telescope command:

:Telescope nvim-keymapper keymaps_picker

Alternatively, if you set up the custom command and keymap above, you can use the :Keymaps command or the <leader>k keymap.

Pressing Enter after selecting a keymap in the picker will run that keymap.

nvim-keymapper's People

Contributors

bgrohman avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

nvim-keymapper's Issues

Multiple modes not working as intended

Love the plugin! I'm opening this issue as I have found it doesn't support multiple modes like vim.keymap.set does. For example:

keymapper.set({'n', 'v'}, '<leader>y', '\"+y', { noremap = true }, "Native: Yank to system clipboard")
should work as intended to create:
vim.keymap.set({'n', 'v'}, '<leader>y', '\"+y', { noremap = true })

Instead, it errors out as the table that is passed to it needs to be concatenated to a string.

The reason this functionality is important is because adding separate lines for each mode clutters Telescope rather quickly.

The functionality can be restored by adding a concatenation in the make_key and module.set functions in mappings.lua as follows:

mappings.lua:

local module = {}
local mappings = {}

local make_key = function(mode, lhs)
    -- check if multiple modes present, then concatenate
    if type(mode) == 'table' then
        mode = table.concat(mode, ",")
    end
    return mode .. ' ' .. lhs
end

module.set = function(mode, lhs, rhs, opts, doc_string)
    local mode_str = mode
	
    -- check if multiple modes present, then concatenate
    if type(mode) == 'table' then
         mode_str = table.concat(mode, ",")
    end
	
    mappings[make_key(mode, lhs)] = {
        mode = mode_str,
        lhs = lhs,
        rhs = rhs,
        doc_string = doc_string
    }

    opts.desc = doc_string
    vim.keymap.set(mode, lhs, rhs, opts)
end

module.get = function(mode, lhs)
    return mappings[make_key(mode, lhs)]
end

module.get_all = function()
    return mappings
end

return module

They will show up as 'n,v' in :Keymaps as one entry, but 'n' and 'v' will still each have their own entry in :AllKeymaps

I've altered the plugin for myself accordingly but it's up to you if you'd like to restore this functionality.

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.