Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/liangxianzhe/nap.nvim

Quickly move between next and previous NeoVim buffer, tab, file, quickfix, diagnostic, etc.
https://github.com/liangxianzhe/nap.nvim

neovim

Last synced: about 2 months ago
JSON representation

Quickly move between next and previous NeoVim buffer, tab, file, quickfix, diagnostic, etc.

Lists

README

        

# nap.nvim (next and previous)

Quickly jump between next and previous NeoVim buffer, tab, file, quickfix, diagnostic, etc.

A lightweight plugin inspired by [unimpaired.vim](https://github.com/tpope/vim-unimpaired), but:

* 🌱 Focus on navigation, not editing or option toggling.
* 🚀 Jump back and forth easily with a single key, instead of two keys.

## TLDR

Use `b` (buffer) as an example:

* `]b`/`[b` jump to next/previous buffer. Then just pressing `...` to cycle
through buffers.
* `]B`/`[B` jump to last/first buffer.

## Operators

| Operator | Description |
| ---------------- | ------------------ |
| a, A | Tab |
| b, B | Buffer |
| d | Diagnostic |
| e | Edit (Change list) |
| f, F | File |
| l, L, C-l, M-l | Location list |
| q, Q, C-q, M-q | Quickfix |
| s | Spell |
| t, T, C-t | Tag |
| z | Fold |
| ' | Mark |

Expand to see how they are defined.

```lua
operators = {
["a"] = {
next = { rhs = "tabnext", opts = { desc = "Next tab" } },
prev = { rhs = "tabprevious", opts = { desc = "Prev tab" } },
},
["A"] = {
next = { rhs = "tablast", opts = { desc = "Last tab" } },
prev = { rhs = "tabfirst", opts = { desc = "First tab" } },
},
["b"] = {
next = { rhs = "bnext", opts = { desc = "Next buffer" } },
prev = { rhs = "bprevious", opts = { desc = "Prev buffer" } },
},
["B"] = {
next = { rhs = "blast", opts = { desc = "Last buffer" } },
prev = { rhs = "bfirst", opts = { desc = "First buffer" } },
},
["d"] = {
next = { rhs = vim.diagnostic.goto_next, opts = { desc = "Next diagnostic" } },
prev = { rhs = vim.diagnostic.goto_prev, opts = { desc = "Prev diagnostic" } },
mode = { "n", "v", "o" }
},
["e"] = {
next = { rhs = "g;", opts = { desc = "Older edit (change-list) item" } },
prev = { rhs = "g,", opts = { desc = "Newer edit (change-list) item" } }
},
["f"] = {
next = { rhs = M.next_file, opts = { desc = "Next file" } },
prev = { rhs = M.prev_file, opts = { desc = "Prev file" } },
},
["F"] = {
next = { rhs = M.last_file, opts = { desc = "Last file" } },
prev = { rhs = M.first_file, opts = { desc = "First file" } },
},
["l"] = {
next = { rhs = "lnext", opts = { desc = "Next loclist item" } },
prev = { rhs = "lprevious", opts = { desc = "Prev loclist item" } }
},
["L"] = {
next = { rhs = "llast", opts = { desc = "Last loclist item" } },
prev = { rhs = "lfirst", opts = { desc = "First loclist item" } }
},
[""] = {
next = { rhs = "lnfile", opts = { desc = "Next loclist item in different file" } },
prev = { rhs = "lpfile", opts = { desc = "Prev loclist item in different file" } }
},
[""] = {
next = { rhs = "lnewer", opts = { desc = "Next loclist list" } },
prev = { rhs = "lolder", opts = { desc = "Prev loclist list" } }
},
["q"] = {
next = { rhs = "cnext", opts = { desc = "Next quickfix item" } },
prev = { rhs = "cprevious", opts = { desc = "Prev quickfix item" } }
},
["Q"] = {
next = { rhs = "clast", opts = { desc = "Last quickfix item" } },
prev = { rhs = "cfirst", opts = { desc = "First quickfix item" } }
},
[""] = {
next = { rhs = "cnfile", opts = { desc = "Next quickfix item in different file" } },
prev = { rhs = "cpfile", opts = { desc = "Prev quickfix item in different file" } }
},
[""] = {
next = { rhs = "cnewer", opts = { desc = "Next quickfix list" } },
prev = { rhs = "colder", opts = { desc = "Prev quickfix list" } }
},
["s"] = {
next = { rhs = "]s", opts = { desc = "Next spell error" } },
prev = { rhs = "[s", opts = { desc = "Prev spell error" } },
mode = { "n", "v", "o" },
},
["t"] = {
next = { rhs = "tnext", opts = { desc = "Next tag" } },
prev = { rhs = "tprevious", opts = { desc = "Prev tag" } }
},
["T"] = {
next = { rhs = "tlast", opts = { desc = "Last tag" } },
prev = { rhs = "tfirst", opts = { desc = "First tag" } }
},
[""] = {
next = { rhs = "ptnext", opts = { desc = "Next tag in previous window" } },
prev = { rhs = "ptprevious", opts = { desc = "Prev tag in previous window" } }
},
["z"] = {
next = { rhs = "zj", opts = { desc = "Next fold" } },
prev = { rhs = "zk", opts = { desc = "Prev fold" } },
mode = { "n", "v", "o" },
},
["'"] = {
next = { rhs = "]`", opts = { desc = "Next lowercase mark" } },
prev = { rhs = "[`", opts = { desc = "Prev lowercase mark" } }
},
```

## Add new operator

You can add/override operators easily, for example:
```lua
require("nap").map("o", {
next = { rhs = "AerialNext", opts = { desc = "Next outline symbol" } },
prev = { rhs = "AerialPrev", opts = { desc = "Prev outline symbol" } },
mode = { "n", "v", "o" },
})
```
Under hood, this plugin calls `vim.keymap.set` to define two keybindings for you, see its doc about
`rhs` and `opts`.

## Helper functions

Helper functions are provided for the following plugins to save your time:

* With [Gitsigns](https://github.com/lewis6991/gitsigns.nvim)
```lua
-- The provided implementation falls back to ]c [c in diff mode.
require("nap").map('c', require("nap").gitsigns())
```
* With [Aerial](https://github.com/stevearc/aerial.nvim)
```lua
require("nap").map('o', require("nap").aerial())
```
* With [vim-illuminate](https://github.com/RRethy/vim-illuminate)
```lua
require("nap").map('r', require("nap").illuminate())
```

You can also add/remove operators inside setup call if you prefer to put them in a central place,
see next section.

## Install and config

Add `liangxianzhe/nap-nvim` to your plugin manager. Call `require("nap").setup()` to use defaults:

```lua
require("nap").setup({
next_prefix = "]",
prev_prefix = "[",
next_repeat = "",
prev_repeat = "",
-- to exclude some keys from the default
exclude_default_operators = {"a", "A"},
-- to add custom keys
operators = {
...
},
})
```

We need two pairs of keys: `prefix` keys to trigger the first jump, and `repeat` keys to repeat with
a single press.

The best config for you depends on many factors. Here are a few examples, feel free to try it out:

* `]` and `[` (":help ]" to check default mappings)
* `` and ``
* `` and `` (Some terminal doesn't support `C-Enter`)
* `` and `\` (If you remap leader key, the original leader key is near Enter)
* `` and ``
* `;` and `,` (use flash.nvim, flit.nvim or similar plugins to free these two keys)
* `>` and `<` (":help >" to check default mappings)
* Some `Alt` prefixed keys (Need terminal supports)

Technically you can set `prefix` and `repeat` to the same key (e.g. `]`). It has one issue that when
pressing `]` to repeat jump, vim will need to wait
[timeoutlen](https://neovim.io/doc/user/options.html#'timeoutlen') to determine whether its is `]`
or `]b`.

## Credits

* [unimpaired.vim](https://github.com/tpope/vim-unimpaired)