mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
Merge #21677 fix(defaults): visual star (*,#) is fragile
This commit is contained in:
@@ -1408,7 +1408,7 @@ deprecate({name}, {alternative}, {version}, {plugin}, {backtrace})
|
|||||||
• {backtrace} boolean|nil Prints backtrace. Defaults to true.
|
• {backtrace} boolean|nil Prints backtrace. Defaults to true.
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
Deprecated message, or nil if no message was shown.
|
(string|nil) # Deprecated message, or nil if no message was shown.
|
||||||
|
|
||||||
inspect({object}, {options}) *vim.inspect()*
|
inspect({object}, {options}) *vim.inspect()*
|
||||||
Gets a human-readable representation of the given object.
|
Gets a human-readable representation of the given object.
|
||||||
|
@@ -114,15 +114,15 @@ DEFAULT MAPPINGS
|
|||||||
*default-mappings*
|
*default-mappings*
|
||||||
Nvim creates the following default mappings at |startup|. You can disable any
|
Nvim creates the following default mappings at |startup|. You can disable any
|
||||||
of these in your config by simply removing the mapping, e.g. ":unmap Y".
|
of these in your config by simply removing the mapping, e.g. ":unmap Y".
|
||||||
>vim
|
|
||||||
nnoremap Y y$
|
- |Y-default|
|
||||||
nnoremap <C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>
|
- |i_CTRL-U-default|
|
||||||
inoremap <C-U> <C-G>u<C-U>
|
- |i_CTRL-W-default|
|
||||||
inoremap <C-W> <C-G>u<C-W>
|
- |CTRL-L-default|
|
||||||
xnoremap * y/\V<C-R>"<CR>
|
- |&-default|
|
||||||
xnoremap # y?\V<C-R>"<CR>
|
- |v_#-default|
|
||||||
nnoremap & :&&<CR>
|
- |v_star-default|
|
||||||
<
|
|
||||||
DEFAULT AUTOCOMMANDS
|
DEFAULT AUTOCOMMANDS
|
||||||
*default-autocmds*
|
*default-autocmds*
|
||||||
Default autocommands exist in the following groups. Use ":autocmd! {group}" to
|
Default autocommands exist in the following groups. Use ":autocmd! {group}" to
|
||||||
|
@@ -435,7 +435,7 @@ vim.cmd = setmetatable({}, {
|
|||||||
do
|
do
|
||||||
local validate = vim.validate
|
local validate = vim.validate
|
||||||
|
|
||||||
--@private
|
---@private
|
||||||
local function make_dict_accessor(scope, handle)
|
local function make_dict_accessor(scope, handle)
|
||||||
validate({
|
validate({
|
||||||
scope = { scope, 's' },
|
scope = { scope, 's' },
|
||||||
@@ -985,7 +985,7 @@ end
|
|||||||
--- Defaults to "Nvim".
|
--- Defaults to "Nvim".
|
||||||
---@param backtrace boolean|nil Prints backtrace. Defaults to true.
|
---@param backtrace boolean|nil Prints backtrace. Defaults to true.
|
||||||
---
|
---
|
||||||
---@returns Deprecated message, or nil if no message was shown.
|
---@return string|nil # Deprecated message, or nil if no message was shown.
|
||||||
function vim.deprecate(name, alternative, version, plugin, backtrace)
|
function vim.deprecate(name, alternative, version, plugin, backtrace)
|
||||||
local msg = ('%s is deprecated'):format(name)
|
local msg = ('%s is deprecated'):format(name)
|
||||||
plugin = plugin or 'Nvim'
|
plugin = plugin or 'Nvim'
|
||||||
@@ -1000,9 +1000,7 @@ function vim.deprecate(name, alternative, version, plugin, backtrace)
|
|||||||
if displayed and backtrace ~= false then
|
if displayed and backtrace ~= false then
|
||||||
vim.notify(debug.traceback('', 2):sub(2), vim.log.levels.WARN)
|
vim.notify(debug.traceback('', 2):sub(2), vim.log.levels.WARN)
|
||||||
end
|
end
|
||||||
if displayed then
|
return displayed and msg or nil
|
||||||
return msg
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create builtin mappings (incl. menus).
|
--- Create builtin mappings (incl. menus).
|
||||||
@@ -1010,9 +1008,38 @@ end
|
|||||||
function vim._init_default_mappings()
|
function vim._init_default_mappings()
|
||||||
-- mappings
|
-- mappings
|
||||||
|
|
||||||
--@private
|
---@private
|
||||||
|
local function region_chunks(region)
|
||||||
|
local chunks = {}
|
||||||
|
local maxcol = vim.v.maxcol
|
||||||
|
for line, cols in vim.spairs(region) do
|
||||||
|
local endcol = cols[2] == maxcol and -1 or cols[2]
|
||||||
|
local chunk = vim.api.nvim_buf_get_text(0, line, cols[1], line, endcol, {})[1]
|
||||||
|
table.insert(chunks, chunk)
|
||||||
|
end
|
||||||
|
return chunks
|
||||||
|
end
|
||||||
|
|
||||||
|
---@private
|
||||||
|
local function _visual_search(cmd)
|
||||||
|
assert(cmd == '/' or cmd == '?')
|
||||||
|
vim.api.nvim_feedkeys('\27', 'nx', true) -- Escape visual mode.
|
||||||
|
local region = vim.region(0, "'<", "'>", vim.fn.visualmode(), vim.o.selection == 'inclusive')
|
||||||
|
local chunks = region_chunks(region)
|
||||||
|
local esc_chunks = vim
|
||||||
|
.iter(chunks)
|
||||||
|
:map(function(v)
|
||||||
|
return vim.fn.escape(v, [[/\]])
|
||||||
|
end)
|
||||||
|
:totable()
|
||||||
|
local esc_pat = table.concat(esc_chunks, [[\n]])
|
||||||
|
local search_cmd = ([[%s\V%s%s]]):format(cmd, esc_pat, '\n')
|
||||||
|
vim.api.nvim_feedkeys(search_cmd, 'nx', true)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@private
|
||||||
local function map(mode, lhs, rhs)
|
local function map(mode, lhs, rhs)
|
||||||
vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true, desc = 'Nvim builtin' })
|
vim.keymap.set(mode, lhs, rhs, { desc = 'Nvim builtin' })
|
||||||
end
|
end
|
||||||
|
|
||||||
map('n', 'Y', 'y$')
|
map('n', 'Y', 'y$')
|
||||||
@@ -1020,8 +1047,12 @@ function vim._init_default_mappings()
|
|||||||
map('n', '<C-L>', '<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>')
|
map('n', '<C-L>', '<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>')
|
||||||
map('i', '<C-U>', '<C-G>u<C-U>')
|
map('i', '<C-U>', '<C-G>u<C-U>')
|
||||||
map('i', '<C-W>', '<C-G>u<C-W>')
|
map('i', '<C-W>', '<C-G>u<C-W>')
|
||||||
map('x', '*', 'y/\\V<C-R>"<CR>')
|
vim.keymap.set('x', '*', function()
|
||||||
map('x', '#', 'y?\\V<C-R>"<CR>')
|
_visual_search('/')
|
||||||
|
end, { desc = 'Nvim builtin', silent = true })
|
||||||
|
vim.keymap.set('x', '#', function()
|
||||||
|
_visual_search('?')
|
||||||
|
end, { desc = 'Nvim builtin', silent = true })
|
||||||
-- Use : instead of <Cmd> so that ranges are supported. #19365
|
-- Use : instead of <Cmd> so that ranges are supported. #19365
|
||||||
map('n', '&', ':&&<CR>')
|
map('n', '&', ':&&<CR>')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user