1

Regenerate nvim config

This commit is contained in:
2024-06-02 03:29:20 +02:00
parent 75eea0c030
commit ef2e28883d
5576 changed files with 604886 additions and 503 deletions

View File

@ -0,0 +1,349 @@
*nvim-autopairs-rules.txt* nvim-autopairs rules
==============================================================================
Table of Contents *nvim-autopairs-rules-table-of-contents*
1. Rule Basics |nvim-autopairs-rules-rule-basics|
2. Controlling rule behavior |nvim-autopairs-rules-controlling-rule-behavior|
- Method Overview |nvim-autopairs-rules-method-overview|
- Conditions |nvim-autopairs-rules-conditions|
3. Method Explanations |nvim-autopairs-rules-method-explanations|
- The `with_*` methods |nvim-autopairs-rules-the-`with_*`-methods|
- The `use_*` methods |nvim-autopairs-rules-the-`use_*`-methods|
- Shorthand methods |nvim-autopairs-rules-shorthand-methods|
- Advanced methods |nvim-autopairs-rules-advanced-methods|
==============================================================================
1. Rule Basics *nvim-autopairs-rules-rule-basics*
At its core, a rule consists of two things: a **pair definition** and an
optional **declaration of filetypes** where the rule is in effect. A pair
definition has an opening part and a closing part. Each of these parts can be
as simple as a single character like a pair of parenthesis, or multiple
characters like Markdown code fences. Defining a rule is straightforward:
>
Rule(begin_pair, end_pair, filetypes)
<
Where `begin_pair` is the opening part of the pair and `end_pair` is the
closing part. `filetypes` may be specified in multiple ways:
>
Rule("(", ")") -- Enabled for all filetypes
Rule("(", ")", "markdown") -- As a string
Rule("(", ")", {"markdown", "vim"}) -- As a table
<
Additionally, it is possible to specify filetypes where the rule should **not**
be enabled by prefixing it with a `-` character:
>
Rule("(", ")", "-markdown") -- All filetypes *except* markdown
<
==============================================================================
2. Controlling rule behavior *nvim-autopairs-rules-controlling-rule-behavior*
By default, rules are very simple and will always complete a pair the moment
the opening part is typed. This is fine and in some cases desirable, but the
rules API allows you to control the manner and context in which pairs are
completed; this is done by attaching **conditions** (predicates) to **events**
and adding **modifiers** to the rule. `Rule` objects expose a variety of
methods to add these predicates and modifiers to the rule.
METHOD OVERVIEW *nvim-autopairs-rules-method-overview*
These methods allow control over if, when, and how rules perform completion of
pairs. Each method returns the `Rule` object so that they may be chained
together to easily define complex rules.
│ method │ usage │
│with_pair(cond) │add condition to check during pair event │
│with_move(cond) │add condition to check during move right event │
│with_cr(cond) │add condition to check during line break event │
│with_del(cond) │add condition to check during delete pair event │
│only_cr(cond) │enable _only_ the line break event; disable everything │
│ │else │
│use_regex(bool, "<k│interpret begin_pair as regex; optionally set trigger k│
│ey>") │ey │
│use_key("<key>") │set trigger key │
│replace_endpair(fun│define ending part with a function; optionally add with│
│c, check_pair) │_pair │
│set_end_pair_length│override offset used to position the cursor between the│
│(number) │ pair when replace_endpair is used │
│replace_map_cr(func│change the mapping for used for <CR> during the line br│
│) │eak event │
│end_wise(cond) │make the rule an end-wise rule │
AIDING UNDERSTANDING: "WHEN" INSTEAD OF "WITH" ~
It may be helpful to think of the `with_<event>` functions as reading more like
`when_<event>` instead, as the condition is checked **when** `<event>` happens
(or wants to happen). This naming scheme more accurately describes how the
`Rule` is affected and reads more intuitively when reading a rule definition.
For example, given a rule definition `Rule("(", ")")`, each method has a
certain effect on how and when the ending part of the pair, the closing
parenthesis, is completed. The ending part is only completed **when**
associated conditions are met upon typing the opening part of the pair.
CONDITIONS *nvim-autopairs-rules-conditions*
nvim-autopairs comes with a variety of common predicates ready to use simply by
including:
>
local cond = require('nvim-autopairs.conds')
<
│ function │ Usage │
│none() │always false │
│done() │always true │
│before_text(text) │text exists before opening part │
│after_text(text) │text exists after opening part │
│before_regex(regex, length│regex matches before opening part │
│) │ │
│after_regex(regex, length)│regex matches after opening part │
│ │ │
│not_before_text(text) │text is not before opening part │
│not_after_text(text) │text is not after opening part │
│not_before_regex(regex, le│regex doesnt match before opening part │
│ngth) │ │
│not_after_regex(regex, len│regex doesnt match after opening part │
│gth) │ │
│not_inside_quote() │not currently within quotation marks │
│is_inside_quote() │currently within quotation marks │
│not_filetypes({table}) │current filetype is not inside table │
│is_bracket_in_quote() │check the next char is quote and cursor is insi│
│ │de quote │
**N.B.** While `cond.not_filetypes` is available, its better to use the
minus syntax on the desired filetype in the initial rule declaration, since
then the rule is completely removed from the buffer.
TREESITTER CONDITIONS ~
Predicates based on the state of the Treesitter graph can be used by including:
>
local ts_conds = require('nvim-autopairs.ts-conds')
<
│ function │ Usage │
│is_ts_node({node_table}) │check current treesitter node│
│is_not_ts_node({node_table})│check not in treesitter node │
==============================================================================
3. Method Explanations *nvim-autopairs-rules-method-explanations*
This section explains each method in more detail: their signatures and how they
modify the rules behavior are all outlined here.
THE `WITH_*` METHODS *nvim-autopairs-rules-the-`with_*`-methods*
Calling these methods on a `Rule` will add predicate functions to their
corresponding event, which determines whether the effect of the event actually
takes place. There are no predicates if you dont define any, and so any
events without predicates behave as if they had a single predicate that always
returns true.
A `Rule` may have more than one predicate defined for a given event, and the
order that they are defined will be the order that they are checked. However,
the **first** non-`nil` value returned by a predicate is used and the remaining
predicates (if any) are **not** executed. In other words, predicates defined
earlier have priority over predicates defined later.
`WITH_PAIR(COND, POS)` ~
After typing the opening part, `cond` will fire and the ending part will only
be added if `cond` returned true. `with_pair` may be called more than once, and
by default, each predicate is appended to a list. When the "pair" event fires,
the _first_ predicate to return non-nil is used as the condition result.
Specifying `pos` allows explicit control over the order of the predicates.
`WITH_MOVE(COND)` ~
If `cond` is true, the cursor is simply moved right when typing the ending part
of the pair and the next character is also the ending part, e.g. `|" -> "|`
when typing `"`. If `cond` returns false, the ending part is inserted as normal
instead.
`WITH_CR(COND)` ~
If `cond` is true, then move the ending part of the pair to a new line below
the cursor after pressing `<CR>` while the cursor is between the pair (think
curly braces opening a block). Otherwise `<CR>` behaves as normal. For example:
>
{|}
<
Typing `<CR>` produces the following when `cond` is true:
>
{
|
}
<
`WITH_DEL(COND)` ~
If `cond` is true, when the cursor is between the pair, pressing `<BS>` to
delete the opening part of the pair will delete the ending part as well.
THE `USE_*` METHODS *nvim-autopairs-rules-the-`use_*`-methods*
The `use_*` functions alter how auto-pairing is triggered. Normally, the first
argument to `Rule` is taken literally as the opening part of the pair and as
soon as it is typed the "pair" event fires.
`USE_KEY(KEY)` ~
The pair is only completed when `key` is pressed, instead of the moment that
the opening part is typed. This is particularly useful in `use_regex`.
`USE_REGEX(BOOL, KEY)` ~
Causes the opening part to be interpreted as a lua pattern that triggers
insertion of the ending part when matched. If `key` is specified, then it acts
as an implicit `use_key`.
SHORTHAND METHODS *nvim-autopairs-rules-shorthand-methods*
These methods exist as convenient shortcuts for defining certain behaviors.
`END_WISE(FUNC)` ~
This method is used to make "end-wise" rules, which is terminology that should
be familiar to users of other auto-pair plugins, e.g. Lexima. Specifically,
this method makes it so that the ending part of the pair will be completed
_only upon pressing `<CR>` after the opening part_, in which case the "newline"
event is fired as usual.
This behavior is useful for languages with statement constructs like Lua and
Bash. For example, defining the following `Rule`:
>
Rule('then', 'end'):end_wise(function(opts))
-- Add any context checks here, e.g. line starts with "if"
return string.match(opts.line, '^%s*if') ~= nil
end)
<
And then pressing `<CR>` at the following cursor position:
>
if foo == bar then|
<
Would be completed as this (assuming some kind of automatic indent is enabled):
>
if foo == bar then
|
end
<
`ONLY_CR(COND)` ~
This shortcut method disables the "pair", "del", and "move" events by setting a
single predicate for each that is always false. Additionally, the effect of any
`use_key` modifiers are removed as well. If `cond` is specified, a "newline"
predicate is set as if `with_cr` were called.
This method is convenient for defining _simple_ end-wise rules. As an example,
a default rule is defined with `only_cr` for Markdown code blocks with an
explicit language; the closing triple-backtick is not completed until you press
`<CR>` after specifying the language:
>
```lua <-- <CR> pressed here
|
```
<
ADVANCED METHODS *nvim-autopairs-rules-advanced-methods*
These methods allow you to define more complex and dynamic rules. When combined
with `with_*` and `use_*` methods, it is possible to create very powerful
auto-pairs.
`REPLACE_ENDPAIR(FUNC, CHECK_PAIR)` ~
Facilitates the creation of dynamic ending parts. When the "pair" event fires
and the ending part is to be completed, `func` is called with a single `opts`
argument and should return a string. The returned string will be sent to
`nvim_feedkeys` to insert the ending part of the pair.
The `opts` parameter is a table that provides context for the current pair
completion, and can be useful for determining what to return. Note that because
`nvim_feedkeys` is used, arbitrary Vim functionality can be leveraged, such as
including `<Esc>` to be able to send normal mode commands.
*nvim-autopairs-rules-Optional-`check_pair`-parameter*
Optional `check_pair` parameter The `check_pair` parameter is optional,
and can either be a boolean or function.
If `check_pair` is a function, it is
passed as-is to `with_pair` to create a
"pair" predicate. If `check_pair` is
true, then an implicit
`with_pair(cond.after_text(rule.end_pair))`
predicate is added, where
`rule.end_pair` is the second argument
to the `Rule` constructor. If
`check_pair` is false, an "always false"
`with_pair` predicate is added.
As an example, these two rule definitions are equivalent:
>
-- This...
Rule("(", ")")
:use_key("<C-h>")
:replace_endpair(function() return "<BS><Del>" end, true)
-- ...is shorthand for this
Rule("(", "")
:use_key("<C-h>")
:with_pair(cond.after_text(")")) -- check that text after cursor is `)`
:replace_endpair(function() return "<BS><Del>" end)
<
`SET_END_PAIR_LENGTH(LEN)` ~
When completing the ending part of a pair, the cursor necessarily moves
backward so that is in between the opening part and the closing part. In order
to do this, the `Rule` must know the length of the ending part, which by
default is trivially determined. However, if you would like to override where
the cursor is placed after completion, i.e. using `replace_endpair`, you can
explicitly set the ending part length with this method.
`REPLACE_MAP_CR(FUNC)` ~
This method allows you to set a custom mapping for the "newline" (`<CR>`) event
that will be used instead of the normal behavior. This can be helpful for
enforcing certain styles or or adding additional edits. `func` is called with a
single `opts` argument and should return a string specifying the mapping for
`<CR>`. The default mapping is: `<C-g>u<CR><C-c>O`.
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
vim:tw=78:ts=8:noet:ft=help:norl:

View File

@ -0,0 +1,444 @@
*nvim-autopairs.txt* A super powerful autopair for Neovim.
==============================================================================
Table of Contents *nvim-autopairs-table-of-contents*
- nvim-autopairs |nvim-autopairs-nvim-autopairs|
- Installation |nvim-autopairs-installation|
- Default values |nvim-autopairs-default-values|
- Sponsors |nvim-autopairs-sponsors|
NVIM-AUTOPAIRS *nvim-autopairs-nvim-autopairs*
A super powerful autopair plugin for Neovim that supports multiple characters.
Requires neovim 0.7
INSTALLATION *nvim-autopairs-installation*
Install the plugin with your preferred package manager:
VIM-PLUG <HTTPS://GITHUB.COM/JUNEGUNN/VIM-PLUG> ~
>
Plug 'windwp/nvim-autopairs'
lua << EOF
require("nvim-autopairs").setup {}
EOF
<
PACKER <HTTPS://GITHUB.COM/WBTHOMASON/PACKER.NVIM> ~
>
use {
"windwp/nvim-autopairs",
config = function() require("nvim-autopairs").setup {} end
}
<
DEFAULT VALUES *nvim-autopairs-default-values*
>
local disable_filetype = { "TelescopePrompt" }
local disable_in_macro = false -- disable when recording or executing a macro
local disable_in_visualblock = false -- disable when insert after visual block mode
local disable_in_replace_mode = true
local ignored_next_char = [=[[%w%%%'%[%"%.%`%$]]=]
local enable_moveright = true
local enable_afterquote = true -- add bracket pairs after quote
local enable_check_bracket_line = true --- check bracket in same line
local enable_bracket_in_quote = true --
local enable_abbr = false -- trigger abbreviation
local break_undo = true -- switch for basic rule break undo sequence
local check_ts = false
local map_cr = true
local map_bs = true -- map the <BS> key
local map_c_h = false -- Map the <C-h> key to delete a pair
local map_c_w = false -- map <c-w> to delete a pair if possible
<
OVERRIDE DEFAULT VALUES ~
>
require('nvim-autopairs').setup({
disable_filetype = { "TelescopePrompt" , "vim" },
})
<
*nvim-autopairs-Mapping-`<CR>`*
>
Before Input After
------------------------------------
{|} <CR> {
|
}
------------------------------------
<
nvim-cmp ~
<h3>
You need to add mapping `CR` on nvim-cmp setup.
Check readme.md on nvim-cmp repo.
</h3>
>
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
<
Mapping `<CR>` You can customize the kind of completion
to add `(` or any character.
>
local handlers = require('nvim-autopairs.completion.handlers')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done({
filetypes = {
-- "*" is a alias to all filetypes
["*"] = {
["("] = {
kind = {
cmp.lsp.CompletionItemKind.Function,
cmp.lsp.CompletionItemKind.Method,
},
handler = handlers["*"]
}
},
lua = {
["("] = {
kind = {
cmp.lsp.CompletionItemKind.Function,
cmp.lsp.CompletionItemKind.Method
},
---@param char string
---@param item table item completion
---@param bufnr number buffer number
---@param rules table
---@param commit_character table<string>
handler = function(char, item, bufnr, rules, commit_character)
-- Your handler function. Inpect with print(vim.inspect{char, item, bufnr, rules, commit_character})
end
}
},
-- Disable for tex
tex = false
}
})
)
<
Dont use `nil` to disable a filetype. If a filetype is `nil` then `*` is
used as fallback.
coq_nvim ~
>
local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
npairs.setup({ map_bs = false, map_cr = false })
vim.g.coq_settings = { keymap = { recommended = false } }
-- these mappings are coq recommended mappings unrelated to nvim-autopairs
remap('i', '<esc>', [[pumvisible() ? "<c-e><esc>" : "<esc>"]], { expr = true, noremap = true })
remap('i', '<c-c>', [[pumvisible() ? "<c-e><c-c>" : "<c-c>"]], { expr = true, noremap = true })
remap('i', '<tab>', [[pumvisible() ? "<c-n>" : "<tab>"]], { expr = true, noremap = true })
remap('i', '<s-tab>', [[pumvisible() ? "<c-p>" : "<bs>"]], { expr = true, noremap = true })
-- skip it, if you use another global object
_G.MUtils= {}
MUtils.CR = function()
if vim.fn.pumvisible() ~= 0 then
if vim.fn.complete_info({ 'selected' }).selected ~= -1 then
return npairs.esc('<c-y>')
else
return npairs.esc('<c-e>') .. npairs.autopairs_cr()
end
else
return npairs.autopairs_cr()
end
end
remap('i', '<cr>', 'v:lua.MUtils.CR()', { expr = true, noremap = true })
MUtils.BS = function()
if vim.fn.pumvisible() ~= 0 and vim.fn.complete_info({ 'mode' }).mode == 'eval' then
return npairs.esc('<c-e>') .. npairs.autopairs_bs()
else
return npairs.autopairs_bs()
end
end
remap('i', '<bs>', 'v:lua.MUtils.BS()', { expr = true, noremap = true })
<
without completion plugin ~
>
-- add option map_cr
npairs.setup({ map_cr = true })
<
another completion plugin
<https://github.com/windwp/nvim-autopairs/wiki/Completion-plugin>
If you have a problem with indent after you press `<CR>` please check the
settings of treesitter indent or install a plugin that has indent support for
your filetype.
RULE ~
nvim-autopairs uses rules with conditions to check pairs.
>
local Rule = require('nvim-autopairs.rule')
local npairs = require('nvim-autopairs')
npairs.add_rule(Rule("$$","$$","tex"))
-- you can use some built-in conditions
local cond = require('nvim-autopairs.conds')
print(vim.inspect(cond))
npairs.add_rules({
Rule("$", "$",{"tex", "latex"})
-- don't add a pair if the next character is %
:with_pair(cond.not_after_regex("%%"))
-- don't add a pair if the previous character is xxx
:with_pair(cond.not_before_regex("xxx", 3))
-- don't move right when repeat character
:with_move(cond.none())
-- don't delete if the next character is xx
:with_del(cond.not_after_regex("xx"))
-- disable adding a newline when you press <cr>
:with_cr(cond.none())
},
-- disable for .vim files, but it work for another filetypes
Rule("a","a","-vim")
)
npairs.add_rules({
Rule("$$","$$","tex")
:with_pair(function(opts)
print(vim.inspect(opts))
if opts.line=="aa $$" then
-- don't add pair on that line
return false
end
end)
}
)
-- you can use regex
-- press u1234 => u1234number
npairs.add_rules({
Rule("u%d%d%d%d$", "number", "lua")
:use_regex(true)
})
-- press x1234 => x12341234
npairs.add_rules({
Rule("x%d%d%d%d$", "number", "lua")
:use_regex(true)
:replace_endpair(function(opts)
-- print(vim.inspect(opts))
return opts.prev_char:sub(#opts.prev_char - 3,#opts.prev_char)
end)
})
-- you can do anything with regex +special key
-- example press tab to uppercase text:
-- press b1234s<tab> => B1234S1234S
npairs.add_rules({
Rule("b%d%d%d%d%w$", "", "vim")
:use_regex(true,"<tab>")
:replace_endpair(function(opts)
return
opts.prev_char:sub(#opts.prev_char - 4,#opts.prev_char)
.."<esc>viwU"
end)
})
-- you can exclude filetypes
npairs.add_rule(
Rule("$$","$$")
:with_pair(cond.not_filetypes({"lua"}))
)
--- check ./lua/nvim-autopairs/rules/basic.lua
<
Rules API <https://github.com/windwp/nvim-autopairs/wiki/Rules-API>
TREESITTER ~
You can use treesitter to check for a pair.
>
local npairs = require("nvim-autopairs")
local Rule = require('nvim-autopairs.rule')
npairs.setup({
check_ts = true,
ts_config = {
lua = {'string'},-- it will not add a pair on that treesitter node
javascript = {'template_string'},
java = false,-- don't check treesitter on java
}
})
local ts_conds = require('nvim-autopairs.ts-conds')
-- press % => %% only while inside a comment or string
npairs.add_rules({
Rule("%", "%", "lua")
:with_pair(ts_conds.is_ts_node({'string','comment'})),
Rule("$", "$", "lua")
:with_pair(ts_conds.is_not_ts_node({'function'}))
})
<
DONT ADD PAIRS IF IT ALREADY HAS A CLOSE PAIR IN THE SAME LINE ~
if **next character** is a close pair and it doesnt have an open pair in
same line, then it will not add a close pair
>
Before Input After
------------------------------------
( |)) ( ( (|))
<
>
require('nvim-autopairs').setup({
enable_check_bracket_line = false
})
<
DONT ADD PAIRS IF THE NEXT CHAR IS ALPHANUMERIC ~
You can customize how nvim-autopairs will behave if it encounters a specific
character
>
require('nvim-autopairs').setup({
ignored_next_char = "[%w%.]" -- will ignore alphanumeric and `.` symbol
})
<
>
Before Input After
------------------------------------
|foobar ( (|foobar
|.foobar ( (|.foobar
<
PLUGIN INTEGRATION ~
>
require('nvim-autopairs').disable()
require('nvim-autopairs').enable()
require('nvim-autopairs').remove_rule('(') -- remove rule (
require('nvim-autopairs').clear_rules() -- clear all rules
-- get rule " then modify it. It can return a list of rule or just a rule
require('nvim-autopairs').get_rule('"')
<
- Sample
>
-- remove add single quote on filetype scheme or lisp
require("nvim-autopairs").get_rule("'")[1].not_filetypes = { "scheme", "lisp" }
require("nvim-autopairs").get_rule("'")[1]:with_pair(cond.not_after_text("["}))
<
FASTWRAP ~
>
Before Input After
--------------------------------------------------
(|foobar <M-e> then press $ (|foobar)
(|)(foobar) <M-e> then press q (|(foobar))
<
>
-- put this to setup function and press <a-e> to use fast_wrap
npairs.setup({
fast_wrap = {},
})
-- change default fast_wrap
npairs.setup({
fast_wrap = {
map = '<M-e>',
chars = { '{', '[', '(', '"', "'" },
pattern = [=[[%'%"%>%]%)%}%,]]=],
end_key = '$',
keys = 'qwertyuiopzxcvbnmasdfghjkl',
check_comma = true,
highlight = 'Search',
highlight_grey='Comment'
},
})
<
AUTOTAG HTML AND TSX ~
autotag <https://github.com/windwp/nvim-ts-autotag>
ENDWISE ~
endwise <https://github.com/windwp/nvim-autopairs/wiki/Endwise>
CUSTOM RULES ~
rules <https://github.com/windwp/nvim-autopairs/wiki/Custom-rules>
SPONSORS *nvim-autopairs-sponsors*
Thanks to everyone who sponsors my projects and makes continued development
maintenance possible! <!-- patreon --><a href="https://github.com/t4t5"><img
src="https://github.com/t4t5.png" width="60px" alt="" /></a><!-- patreon-->
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
vim:tw=78:ts=8:noet:ft=help:norl: