cloned from https://github.com/ysmb-wtsg/in-and-out.nvim, fixed vim.validate() being called incorrectly in config function
commit
98df147ad8
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 ysmb-wtsg
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
# in-and-out.nvim
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://github.com/ysmb-wtsg/in-and-out.nvim/assets/85178719/cdfa26ec-6302-4413-b586-781ece8e99c0" width="70%" height="400px" object-fit="cover">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
`in-and-out` is a Neovim plugin designed to quickly navigate in and out of surrounding characters like quotes (`"`, `'`), parentheses (`(`, `)`), curly braces (`{`, `}`), square brackets (`[`, `]`), and backticks (<code>`</code>).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Use your favorite package manager. For example, using `lazy`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
"ysmb-wtsg/in-and-out.nvim",
|
||||||
|
keys = {
|
||||||
|
{
|
||||||
|
"<C-CR>",
|
||||||
|
function()
|
||||||
|
require("in-and-out").in_and_out()
|
||||||
|
end,
|
||||||
|
mode = "i"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
By default, this plugin will jump into and out of the following surrounding characters:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{ '"', "'", "(", ")", "{", "}", "[", "]", "`" }
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are happy with this list of targets, you don't need to do any configuration, and you don't need to call `setup`.
|
||||||
|
|
||||||
|
On the other hand, if you want to add to the list of targets or replace it altogether, use the plugin's `setup` method. To add targets, pass `setup` an options table containing a sublist named `additional_targets`. To replace the original targets list entirely, pass `setup` an options table with a sublist called `targets`.
|
||||||
|
|
||||||
|
Note: you cannot use both the `targets` and the `additional_targets` sublists at the same time. If you try, the plugin will apply `targets` and ignore `additional_targets`.
|
||||||
|
|
||||||
|
See the examples below.
|
||||||
|
|
||||||
|
Using `lazy` to add smart quotes as a target:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
"ysmb-wtsg/in-and-out.nvim",
|
||||||
|
keys = {
|
||||||
|
{
|
||||||
|
"<C-CR>",
|
||||||
|
function()
|
||||||
|
require("in-and-out").in_and_out()
|
||||||
|
end,
|
||||||
|
mode = "i"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts = { additional_targets = { "“", "”" } },
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Manual `require` to reset the targets altogether:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require("in-and-out.nvim").setup({
|
||||||
|
targets = { "(", ")", "[", "]" }
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mapping
|
||||||
|
|
||||||
|
By default, the plugin does not set any mapping. You can set one through your plugin manager (if it supports setting mappings) or manually.
|
||||||
|
|
||||||
|
Using `lazy`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
"ysmb-wtsg/in-and-out.nvim",
|
||||||
|
keys = {
|
||||||
|
{
|
||||||
|
"<C-CR>",
|
||||||
|
function()
|
||||||
|
require("in-and-out").in_and_out()
|
||||||
|
end,
|
||||||
|
mode = "i"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts = { additional_targets = { "“", "”" } },
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Manually:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.keymap.set("i", "<C-CR>", function() require("in-and-out").in_and_out()
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
*in-and-out.txt* in-and-out plugin for Neovim
|
||||||
|
|
||||||
|
INTRODUCTION *in-and-out*
|
||||||
|
|
||||||
|
in-and-out is a Neovim plugin designed to quickly navigate in and out of surrounding characters like quotes (`"`, `'`), parentheses (`(`, `)`), curly braces (`{`, `}`), square brackets (`[`, `]`), and backticks ("`").
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
|
||||||
|
In insert mode, press <C-CR> to move the cursor out of the paired characters.
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
|
||||||
|
Author: ysmb-wtsg <telecaster1121@gmail.com>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
in-and-out in_and_out.txt /*in-and-out*
|
||||||
|
in-and-out.txt in_and_out.txt /*in-and-out.txt*
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function escape_lua_pattern(s)
|
||||||
|
local matches = {
|
||||||
|
["^"] = "%^",
|
||||||
|
["$"] = "%$",
|
||||||
|
["("] = "%(",
|
||||||
|
[")"] = "%)",
|
||||||
|
["%"] = "%%",
|
||||||
|
["."] = "%.",
|
||||||
|
["["] = "%[",
|
||||||
|
["]"] = "%]",
|
||||||
|
["*"] = "%*",
|
||||||
|
["+"] = "%+",
|
||||||
|
["-"] = "%-",
|
||||||
|
["?"] = "%?",
|
||||||
|
}
|
||||||
|
return s:gsub(".", matches)
|
||||||
|
end
|
||||||
|
|
||||||
|
local targets = { '"', "'", "(", ")", "{", "}", "[", "]", "`" }
|
||||||
|
|
||||||
|
function M.setup(config)
|
||||||
|
vim.validate({ config = { config, "table", true } })
|
||||||
|
vim.validate({ additional_targets = { config.additional_targets, "table", true } })
|
||||||
|
vim.validate({ targets = { config.targets, "table", true } })
|
||||||
|
--
|
||||||
|
if config and config.targets then
|
||||||
|
targets = config.targets
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if config and config.additional_targets then
|
||||||
|
for _, target in ipairs(config.additional_targets) do
|
||||||
|
targets[#targets + 1] = target
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.in_and_out()
|
||||||
|
local current_row, current_col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
local lines_in_buf = vim.api.nvim_buf_get_lines(0, current_row - 1, -1, false)
|
||||||
|
|
||||||
|
local target_row = 0
|
||||||
|
local target_col = nil
|
||||||
|
for i, line in ipairs(lines_in_buf) do
|
||||||
|
for _, char in ipairs(targets) do
|
||||||
|
local found_col = string.find(line, escape_lua_pattern(char), current_col + 1)
|
||||||
|
if found_col and (not target_col or found_col < target_col) then
|
||||||
|
-- If char is a multibyte character, we need to take into account the extra bytes.
|
||||||
|
target_col = found_col + vim.fn.strlen(char) - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if target_col then
|
||||||
|
target_row = current_row + i - 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
current_col = 0
|
||||||
|
end
|
||||||
|
if target_col then
|
||||||
|
vim.api.nvim_win_set_cursor(0, { target_row, target_col })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
column_width = 120
|
||||||
|
line_endings = "Unix"
|
||||||
|
indent_type = "Tabs"
|
||||||
|
quote_style = "AutoPreferDouble"
|
||||||
|
call_parentheses = "Always"
|
||||||
|
collapse_simple_statement = "Never"
|
||||||
Loading…
Reference in New Issue