mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
No commits in common. "a9fc298063a2fccf049dc1ec3295c16722a27d5c" and "12b0ff02b67bc42e961c2223088887397976dd6b" have entirely different histories.
a9fc298063
...
12b0ff02b6
@ -35,48 +35,33 @@ keymap.set("n", "N", "", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local check_cursor_word = function()
|
local no_word_under_cursor = function()
|
||||||
local cursor_word = vim.fn.expand("<cword>")
|
local cursor_word = vim.fn.expand("<cword>")
|
||||||
|
|
||||||
local result = cursor_word == ""
|
local result = cursor_word == ""
|
||||||
if result then
|
if result then
|
||||||
local msg = "E348: No string under cursor"
|
local msg = "E348: No string under cursor"
|
||||||
api.nvim_err_writeln(msg)
|
api.nvim_err_writeln(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
return result, cursor_word
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
keymap.set("n", "*", "", {
|
keymap.set("n", "*", "", {
|
||||||
callback = function()
|
callback = function()
|
||||||
local cursor_word_empty, cursor_word = check_cursor_word()
|
if no_word_under_cursor() then
|
||||||
if cursor_word_empty then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
vim.fn.execute("normal! *N")
|
||||||
local cmd = string.format([[normal! /\v<%s>]], cursor_word)
|
|
||||||
|
|
||||||
-- In order to say that we are pressing Enter key, instead of typing literally the character,
|
|
||||||
-- we need to replace special notation with their internal representation.
|
|
||||||
local escaped_enter = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
|
||||||
|
|
||||||
-- character `N` is used to keep the cursor when pressing `*`
|
|
||||||
local full_cmd = cmd .. escaped_enter .. "N"
|
|
||||||
vim.fn.execute(full_cmd)
|
|
||||||
hlslens.start()
|
hlslens.start()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
keymap.set("n", "#", "", {
|
keymap.set("n", "#", "", {
|
||||||
callback = function()
|
callback = function()
|
||||||
local cursor_word_empty, cursor_word = check_cursor_word()
|
if no_word_under_cursor() then
|
||||||
if cursor_word_empty then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
vim.fn.execute("normal! #N")
|
||||||
local cmd = string.format([[normal! ?\v<%s>]], cursor_word)
|
|
||||||
local escaped_enter = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
|
||||||
|
|
||||||
local full_cmd = cmd .. escaped_enter .. "N"
|
|
||||||
vim.fn.execute(full_cmd)
|
|
||||||
hlslens.start()
|
hlslens.start()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -163,16 +163,8 @@ api.nvim_create_autocmd("FileType", {
|
|||||||
-- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos)))
|
-- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos)))
|
||||||
-- it seems that without vim.schedule, the cursor position can not be set correctly
|
-- it seems that without vim.schedule, the cursor position can not be set correctly
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
|
api.nvim_win_set_cursor(0, mark_pos)
|
||||||
if not status then
|
|
||||||
api.nvim_err_writeln(string.format("Failed to resume cursor position. Context %s, error: %s",
|
|
||||||
vim.inspect(ev), result))
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
-- the following two ways also seem to work,
|
|
||||||
-- ref: https://www.reddit.com/r/neovim/comments/104lc26/how_can_i_press_escape_key_using_lua/
|
|
||||||
-- vim.api.nvim_feedkeys("g`\"", "n", true)
|
|
||||||
-- vim.fn.execute("normal! g`\"")
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -265,7 +257,7 @@ api.nvim_create_autocmd("BufReadPre", {
|
|||||||
if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then
|
if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then
|
||||||
vim.o.eventignore = "all"
|
vim.o.eventignore = "all"
|
||||||
-- turning off relative number helps a lot
|
-- turning off relative number helps a lot
|
||||||
vim.wo.relativenumber = false
|
vim.bo.relativenumber = false
|
||||||
|
|
||||||
vim.bo.swapfile = false
|
vim.bo.swapfile = false
|
||||||
vim.bo.bufhidden = "unload"
|
vim.bo.bufhidden = "unload"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user