Skip to content

Commit 145b908

Browse files
committed
Replace incsearch workflow with hop.nvim
1 parent 266669c commit 145b908

File tree

6 files changed

+52
-110
lines changed

6 files changed

+52
-110
lines changed

nvim/lazy-lock.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616
"fzf.vim": { "branch": "master", "commit": "879db51d0965515cdaef9b7f6bdeb91c65d2829e" },
1717
"gitsigns.nvim": { "branch": "main", "commit": "20ad4419564d6e22b189f6738116b38871082332" },
1818
"gruvbox": { "branch": "master", "commit": "697c00291db857ca0af00ec154e5bd514a79191f" },
19-
"incsearch-easymotion.vim": { "branch": "master", "commit": "fcdd3aee6f4c0eef1a515727199ece8d6c6041b5" },
20-
"incsearch-fuzzy.vim": { "branch": "master", "commit": "b08fa8fbfd633e2f756fde42bfb5251d655f5403" },
21-
"incsearch.vim": { "branch": "master", "commit": "c83de6d1ac31d173d7c3ffee0ad61dc643ee4f08" },
19+
"hop.nvim": { "branch": "v2", "commit": "90db1b2c61b820e230599a04fedcd2679e64bd07" },
2220
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
23-
"lazy.nvim": { "branch": "main", "commit": "db067881fff0fd4be8c00e5bde7492e0e1c77a2f" },
21+
"lazy.nvim": { "branch": "main", "commit": "f0f5bbb9e5bfae5e6468f9359ffea3d151418176" },
2422
"lightline.vim": { "branch": "master", "commit": "e358557e1a9f9fc860416c8eb2e34c0404078155" },
2523
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
2624
"menu": { "branch": "main", "commit": "7a0a4a2896b715c066cfbe320bdc048091874cc6" },
2725
"minty": { "branch": "main", "commit": "aafc9e8e0afe6bf57580858a2849578d8d8db9e0" },
2826
"nerdcommenter": { "branch": "master", "commit": "02a3b6455fa07b61b9440a78732f1e9b7876c991" },
2927
"nerdtree": { "branch": "master", "commit": "690d061b591525890f1471c6675bcb5bdc8cdff9" },
3028
"nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" },
31-
"nvim-cmp": { "branch": "main", "commit": "a7bcf1d88069fc67c9ace8a62ba480b8fe879025" },
32-
"nvim-lspconfig": { "branch": "master", "commit": "87d30189b24caa496b54affd65594a309ac6d929" },
29+
"nvim-cmp": { "branch": "main", "commit": "cf22c9e32512de3be1fd6b65fd25e3aabead4d8b" },
30+
"nvim-lspconfig": { "branch": "master", "commit": "e25994a1c2373784364852cd904cb39b6d75f227" },
3331
"nvim-tree.lua": { "branch": "master", "commit": "64e2192f5250796aa4a7f33c6ad888515af50640" },
3432
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
3533
"nvim-web-devicons": { "branch": "master", "commit": "8dcb311b0c92d460fac00eac706abd43d94d68af" },

nvim/lua/autocmds.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,3 @@ api.nvim_create_autocmd("FileType", {
302302
end,
303303
})
304304

305-
api.nvim_create_autocmd("VimEnter", {
306-
group = api.nvim_create_augroup("incsearch-keymap", { clear = true }),
307-
callback = function()
308-
user.incsearch_keymap()
309-
end,
310-
})

nvim/lua/mappings.lua

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ require "nvchad.mappings"
33
local map = vim.keymap.set
44
local user = require "user"
55
local fn = vim.fn
6-
local echo = vim.api.nvim_echo
6+
local api = vim.api
7+
local echo = api.nvim_echo
8+
9+
local function feedkeys(keys)
10+
api.nvim_feedkeys(api.nvim_replace_termcodes(keys, true, false, true), "n", true)
11+
end
712

813
map("n", "zo", "zO", { remap = true })
914
map("n", "bm", "<Plug>BookmarkToggle")
@@ -95,20 +100,20 @@ map("n", "<F10>", function()
95100
vim.cmd([[echo "hi<" . synIDattr(synID(line('.'),col('.'),1),'name') . "> trans<" . synIDattr(synID(line('.'),col('.'),0),'name') . "> lo<" . synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name') . ">"]])
96101
end, { silent = true })
97102
map("n", "g/", function()
98-
return fn["incsearch#go"](user.legacy_incsearch_config { is_stay = 1 })
99-
end, { expr = true, silent = true, noremap = true })
103+
if not user.hop_patterns { current_line_only = true } then
104+
feedkeys "g/"
105+
end
106+
end, { silent = true, noremap = true })
100107
map("n", "/", function()
101-
return fn["incsearch#go"](user.legacy_incsearch_config { is_stay = 0 })
102-
end, { expr = true, silent = true, noremap = true })
108+
if not user.hop_patterns() then
109+
feedkeys "/"
110+
end
111+
end, { silent = true, noremap = true })
103112
map("n", "f", function()
104-
return fn["incsearch#go"](user.legacy_incsearch_config { converters = { fn["incsearch#config#fuzzy#converter"]() } })
105-
end, { expr = true, silent = true, noremap = true })
106-
map("n", "n", "<Plug>(incsearch-nohl-n)")
107-
map("n", "N", "<Plug>(incsearch-nohl-N)")
108-
map("n", "*", "<Plug>(incsearch-nohl-*)")
109-
map("n", "#", "<Plug>(incsearch-nohl-#)")
110-
map("n", "g*", "<Plug>(incsearch-nohl-g*)")
111-
map("n", "g#", "<Plug>(incsearch-nohl-g#)")
113+
if not user.hop_char1 { current_line_only = true } then
114+
feedkeys "f"
115+
end
116+
end, { silent = true, noremap = true })
112117
map("n", "i", ":noh<CR>i", { noremap = true, silent = true })
113118
map("n", "<BS>", "mzJ`z", { noremap = true })
114119
map("n", "gj", "<Plug>(signify-next-hunk)")

nvim/lua/options.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ g["prettier#config#bracket_spacing"] = "true"
115115
g["prettier#config#print_width"] = 100
116116

117117
g["asterisk#keeppos"] = 1
118-
g["incsearch#auto_nohlsearch"] = 1
119-
120118
g.coc_snippet_next = "<c-j>"
121119
g.coc_snippet_prev = "<c-k>"
122120
g.coc_node_path = fn.expand "~/.nvm/versions/node/v16.12.0/bin/node"

nvim/lua/plugins/init.lua

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,11 @@ return {
4040
},
4141
{ "kana/vim-submode" },
4242
{
43-
"haya14busa/incsearch.vim",
44-
lazy = false,
45-
},
46-
{
47-
"haya14busa/incsearch-fuzzy.vim",
48-
lazy = false,
49-
dependencies = { "haya14busa/incsearch.vim" },
50-
},
51-
{
52-
"haya14busa/incsearch-easymotion.vim",
53-
lazy = false,
54-
dependencies = { "haya14busa/incsearch.vim", "easymotion/vim-easymotion" },
43+
"phaazon/hop.nvim",
44+
branch = "v2",
45+
config = function()
46+
require("hop").setup {}
47+
end,
5548
},
5649
{ "jiangmiao/auto-pairs" },
5750
{ "szw/vim-ctrlspace" },

nvim/lua/user/init.lua

Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -213,91 +213,45 @@ function M.zoom_toggle()
213213
vim.t.zoomed = true
214214
end
215215

216-
local function ensure_incsearch_core()
217-
if fn.exists "*incsearch#util#deepextend" == 1 then
218-
return true
219-
end
216+
local hop_warning_shown = false
220217

221-
local ok, lazy = pcall(require, "lazy")
218+
local function load_hop()
219+
local ok, hop = pcall(require, "hop")
222220
if ok then
223-
lazy.load { plugins = { "incsearch.vim" } }
224-
end
225-
226-
return fn.exists "*incsearch#util#deepextend" == 1
227-
end
228-
229-
local function ensure_incsearch_easymotion()
230-
if fn.exists "*incsearch#config#easymotion#module" == 1 then
231-
return true
221+
return hop
232222
end
233223

234-
local ok, lazy = pcall(require, "lazy")
235-
if ok then
236-
lazy.load { plugins = { "incsearch-easymotion.vim" } }
224+
if not hop_warning_shown then
225+
hop_warning_shown = true
226+
vim.schedule(function()
227+
vim.notify("hop.nvim is not available; search mappings will fall back to their defaults", vim.log.levels.WARN, {
228+
title = "hop",
229+
})
230+
end)
237231
end
238232

239-
return fn.exists "*incsearch#config#easymotion#module" == 1
233+
return nil
240234
end
241235

242-
local function warn_once(msg)
243-
vim.schedule(function()
244-
vim.notify(msg, vim.log.levels.WARN, { title = "incsearch" })
245-
end)
246-
end
247-
248-
function M.incsearch_config(opts)
249-
opts = opts or {}
250-
251-
local modules = {}
252-
if ensure_incsearch_easymotion() then
253-
table.insert(modules, fn["incsearch#config#easymotion#module"]())
254-
else
255-
warn_once "incsearch-easymotion.vim is not available; incremental search will fall back to the default behaviour"
256-
end
257-
258-
local base = {
259-
is_expr = 0,
260-
}
261-
262-
if #modules > 0 then
263-
base.modules = modules
264-
base.keymap = { ["<CR>"] = "<Over>(easymotion)" }
265-
else
266-
base.keymap = vim.empty_dict()
267-
end
268-
269-
if ensure_incsearch_core() then
270-
local ok, extended = pcall(fn["incsearch#util#deepextend"], vim.deepcopy(base), opts)
271-
if ok then
272-
return extended
273-
end
274-
warn_once(string.format("incsearch#util#deepextend failed: %s; falling back to Lua deep extend", extended))
275-
else
276-
warn_once "incsearch.vim is not available; incremental search will fall back to Lua deep extend"
236+
function M.hop_patterns(opts)
237+
local hop = load_hop()
238+
if hop then
239+
hop.hint_patterns(opts or {})
240+
return true
277241
end
278-
279-
return vim.tbl_deep_extend("force", vim.deepcopy(base), opts)
242+
return false
280243
end
281244

282-
function M.legacy_incsearch_config(opts)
283-
return M.incsearch_config(opts or {})
284-
end
285-
286-
function M.incsearch_keymap()
287-
if fn.exists ":IncSearchNoreMap" == 0 then
288-
return
289-
end
290-
291-
local function map(lhs, rhs)
292-
vim.cmd(string.format([[IncSearchNoreMap %s %s]], lhs, rhs))
245+
function M.hop_char1(opts)
246+
local hop = load_hop()
247+
if hop then
248+
hop.hint_char1(opts or {})
249+
return true
293250
end
294-
295-
map("<Right>", "<Over>(incsearch-next)")
296-
map("<Left>", "<Over>(incsearch-prev)")
297-
map("<Tab>", "<Over>(incsearch-scroll-f)")
298-
map("<S-Tab>", "<Over>(incsearch-scroll-b)")
251+
return false
299252
end
300253

254+
301255
function M.print_foobar()
302256
vim.notify("Foo Bar!", vim.log.levels.INFO, { title = "CtrlSpace" })
303257
end

0 commit comments

Comments
 (0)