Giter Site home page Giter Site logo

pounce.nvim's Introduction

pounce.nvim

Pounce is a motion plugin similar to EasyMotion, Sneak, Hop, and Lightspeed. It's based on incremental fuzzy search. Here's a demo:

demo

The demo shows searching for the word "ht_mask" by typing "s" to activate Pounce, "htm" to refine the search, and then "J" to select the match.

Installation

Using vim-plug:

Plug 'rlane/pounce.nvim'

Usage

The :Pounce command starts the motion. Type the character at the destination and Pounce will highlight all matches on screen. Next, refine the matches by typing more characters (in order) that are present after the destination. The first letter of the match will be replaced with an uppercase "accept key". You can hit that key to jump to the match, or continue refining the search. Enter accepts the best match (highlighted in blue). Escape cancels the motion and leaves the cursor at its previous position.

You can also use :Pounce <chars> to initialize the search with <chars>. You can directly hit the accept key to jump to that match or continue refining as normal. You can use this with <C-r> to initialize the search with the contents of a register, For example <C-r>/ will initialize the search with the last search pattern you used in /. You can also consider using <expr> mappings or lua callbacks with vim.fn.expand. For these use cases the commands PounceReg <regname> and PounceExpand <expr> are defined.

The :PounceRepeat command works the same way but is initialized with the input from the previous Pounce command.

No mappings are created by default. Here's a suggestion:

nmap s <cmd>Pounce<CR>
nmap S <cmd>PounceRepeat<CR>
xmap s <cmd>Pounce<CR>
omap gs <cmd>Pounce<CR>  " 's' is used by vim-surround
nmap S :Pounce <C-r>/<cr> " note: if you want to use <C-r> you cannot use <cmd>

You can also use the lua api directly:

local map = vim.keymap.set
map("n", "s", function() require'pounce'.pounce { } end)
map("n", "s", function() require'pounce'.pounce { do_repeat = true } end)
map("x", "s", function() require'pounce'.pounce { } end)
map("o", "gs", function() require'pounce'.pounce { } end)
map("n", "S", function() require'pounce'.pounce { input = {reg="/"} } end)

The pounce function takes a table as its argument, you can use any keys that setup accepts, as well as:

require'pounce'.pounce{
    do_repeat = true|false -- to reuse the last pounce search
    input = string|table -- a string to initialize the input, or a table:
    input = {
        reg = string -- the name of a vim register to use as the input (:h registers)
        expand = string -- an expression passed to vim.fn.expand (:h expand())
    }
}

Configuration is done with the setup function. It's optional to call setup. Here are the defaults:

require'pounce'.setup{
  accept_keys = "JFKDLSAHGNUVRBYTMICEOXWPQZ",
  accept_best_key = "<enter>",
  multi_window = true,
  highlight_overrides = {},
  debug = false,
}

Note that accept_keys allows you to configure the order in which accept keys display โ€“ closest proximity match gets the first letter in the accept_keys string. Users of alternative keyboard layouts may wish to amend that string. Colemak DHm might start with NTESIROA... for example.

The default highlights can be overridden with the highlight_overrides table. The keys are the names of the highlights to override, keys are the highlight group options. See :h nvim_set_hl() for the highlighting options. For example, simple grayscale:

require('pounce').setup{
  highlight_overrides = {
    PounceMatch = {
      bold = true,
      fg = 'white',
      bg = 'gray'
    },
    PounceGap = {
      bold = true,
      fg = 'white',
      bg = 'darkgray'
    },
    PounceAccept = {
      bold = true,
      fg = 'black',
      bg = 'lightgray'
    },
    PounceAcceptBest = {
      bold = true,
      fg = 'black',
      bg = 'white'
    }
  }
}

Below are listed some example extra commands you can use:

<cmd>PounceReg /<cr> " Pounce with last search pattern
<cmd>PounceReg 0<cr> " Pounce with last yank
<cmd>PounceReg \"<cr> " Pounce with last d/c/y
<cmd>PounceReg .<cr> " Pounce with last inserted text
\"zy<cmd>PounceReg z<cr> " From visual mode: Pounce using the selection as the input
<cmd>PounceExpand <cword><cr> " Pounce with the current word
<cmd>PounceExpand %<cr> " Pounce with the current filename

Related Work

There are quite a few plugins in this space. Here are some alternatives to Pounce:

pounce.nvim's People

Contributors

benfrain avatar hippo0o avatar indianboy42 avatar jdelkins avatar jellyapple102 avatar kawarimidoll avatar lincheney avatar loc-cv avatar rlane avatar

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.