Giter Club home page Giter Club logo

Comments (3)

echasnovski avatar echasnovski commented on August 11, 2024 3

@hunleyd, wanted to mention that thanks to this issue I decided to slightly redesign mapping process in 'mini.pairs' to make it (hopefully) more user-friendly. Now you can make global mappings in config and they will be automatically registered for <BS> and <CR> (if not changed explicitly). Also work with pair mappings now should be done with MiniPairs.map(), MiniPairs.map_buf(), MiniPairs.unmap(), MiniPairs.unmap_buf().

For example, global mappings for , <, and > can look something like this:

  require('mini.pairs').setup({
    mappings = {
      [' '] = { action = 'open', pair = '  ', neigh_pattern = '[%(%[{][%)%]}]' },
      ['<'] = { action = 'open', pair = '<>' },
      ['>'] = { action = 'close', pair = '<>' },
    },
  })

Also, all previous mappings (except ones with MiniPairs.bs() and MiniPairs.cr() which use custom pair list) still work as before.

from mini.nvim.

echasnovski avatar echasnovski commented on August 11, 2024

Thank you for your kind words!

Originally, informal general idea of 'mini.pairs' is this: "here are a bunch of autopairs-related actions; use them to make mappings for keys that you want; common ones are already done by default". I might rethink this in future, because coming back to it, this might be a little bit heavy on user-friendliness.

So about spaces. There are three actions supported: open(), close(), closeopen(). All of them work if cursor neighborhood (characters to left and right of cursor) is matched with supplied twochars_pattern (which is a Lua pattern). Unfortunately, Lua patterns don't seem to support alteration. So user can't say "match if neighborhood is this, or this, or this". The closest behavior to this might be "match if left character is one of these and right character is one of these". To add this behavior to space which checks for ([{ to the right and )]} to the left, make a standard Neovim mapping:

  • In Lua:
    vim.api.nvim_set_keymap('i', ' ', [[v:lua.MiniPairs.open('  ', '[%(%[{][%)%]}]')]], { expr = true, noremap = true })
  • In Vimscript:
    inoremap <expr> <space> v:lua.MiniPairs.open('  ', '[%(%[{][%)%]}]')

With <> everything is the same: make mappings. You, probably, would want something like this:

  • In Lua:
    vim.api.nvim_set_keymap('i', '<', [[v:lua.MiniPairs.open('<>', '[^\\].')]], { expr = true, noremap = true })
    vim.api.nvim_set_keymap('i', '>', [[v:lua.MiniPairs.close('<>', '[^\\].')]], { expr = true, noremap = true })
  • In Vimscript:
    inoremap <expr> < v:lua.MiniPairs.open('<>', '[^\\].')
    inoremap <expr> > v:lua.MiniPairs.close('<>', '[^\\].')

A big NOTE though. Currently all this does is mapping a key to an action. To make <BS> and <CR> respect new pairs, you need to remap them accordingly (supply full table of cursor neighborhoods in which those should act).

from mini.nvim.

hunleyd avatar hunleyd commented on August 11, 2024

excellent, thank you! i have this working as desired now.

from mini.nvim.

Related Issues (20)

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.