From 1fb721ead7f8dd4f0b3f7df34b1e74c7d66f4056 Mon Sep 17 00:00:00 2001 From: gwbeip Date: Thu, 10 Apr 2025 09:36:37 +0800 Subject: [PATCH] Move key-bonding of Hop into hop.lua --- lua/config/lazy.lua | 48 ----------------------------- lua/plugins/hop.lua | 65 ++++++++++++++++++++++++++++++++++----- lua/vscodeplugins/hop.lua | 65 ++++++++++++++++++++++++++++++++++----- 3 files changed, 116 insertions(+), 62 deletions(-) diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index d8013b3..88c8883 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -63,30 +63,6 @@ if vim.g.vscode then checker = { enabled = true }, }) - local hop = require('hop') - local directions = require('hop.hint').HintDirection - vim.keymap.set('n', 'f', function() - hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true }) - end, {remap=true}) - vim.keymap.set('n', 'F', function() - hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true }) - end, {remap=true}) - vim.keymap.set('n', 't', function() - hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true, hint_offset = -1 }) - end, {remap=true}) - vim.keymap.set('n', 'T', function() - hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true, hint_offset = 1 }) - end, {remap=true}) - vim.keymap.set('n', 's', function() - hop.hint_char1() - end, {remap=true}) - vim.keymap.set('n', 'S', function() - hop.hint_char2() - end, {remap=true}) - vim.keymap.set('n', 'sw', function() - hop.hint_words() - end, {remap=true}) - else require("lazy").setup({ spec = { @@ -100,28 +76,4 @@ else checker = { enabled = true }, }) - local hop = require('hop') - local directions = require('hop.hint').HintDirection - vim.keymap.set('n', 'f', function() - hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true }) - end, {remap=true}) - vim.keymap.set('n', 'F', function() - hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true }) - end, {remap=true}) - vim.keymap.set('n', 't', function() - hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true, hint_offset = -1 }) - end, {remap=true}) - vim.keymap.set('n', 'T', function() - hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true, hint_offset = 1 }) - end, {remap=true}) - vim.keymap.set('n', 's', function() - hop.hint_char1() - end, {remap=true}) - vim.keymap.set('n', 'S', function() - hop.hint_char2() - end, {remap=true}) - vim.keymap.set('n', 'sw', function() - hop.hint_words() - end, {remap=true}) - end diff --git a/lua/plugins/hop.lua b/lua/plugins/hop.lua index 0665ffb..7284aca 100644 --- a/lua/plugins/hop.lua +++ b/lua/plugins/hop.lua @@ -1,9 +1,60 @@ return{ - { - 'smoka7/hop.nvim', - version = "*", - opts = { - keys = 'etovxqpdygfblzhckisuran' - } - } + { + 'smoka7/hop.nvim', + version = "*", + opts = { + keys = 'etovxqpdygfblzhckisuran' + }, + keys = { + { + 'f', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true }) + end, + desc = 'Hop forward', + }, + { + 'F', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true }) + end, + desc = 'Hop backward', + }, + { + 't', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true, hint_offset = -1 }) + end, + desc = 'Hop forward (offset)', + }, + { + 'T', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true, hint_offset = 1 }) + end, + desc = 'Hop backward (offset)', + }, + { + 's', + function() + require('hop').hint_char1() + end, + desc = 'Hop anywhere', + }, + { + 'S', + function() + require('hop').hint_char2() + end, + desc = 'Hop anywhere (2 chars)', + }, + { + 'sw', + function() + require('hop').hint_words() + end, + desc = 'Hop words', + }, + } + } } diff --git a/lua/vscodeplugins/hop.lua b/lua/vscodeplugins/hop.lua index 0665ffb..7284aca 100644 --- a/lua/vscodeplugins/hop.lua +++ b/lua/vscodeplugins/hop.lua @@ -1,9 +1,60 @@ return{ - { - 'smoka7/hop.nvim', - version = "*", - opts = { - keys = 'etovxqpdygfblzhckisuran' - } - } + { + 'smoka7/hop.nvim', + version = "*", + opts = { + keys = 'etovxqpdygfblzhckisuran' + }, + keys = { + { + 'f', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true }) + end, + desc = 'Hop forward', + }, + { + 'F', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true }) + end, + desc = 'Hop backward', + }, + { + 't', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true, hint_offset = -1 }) + end, + desc = 'Hop forward (offset)', + }, + { + 'T', + function() + require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true, hint_offset = 1 }) + end, + desc = 'Hop backward (offset)', + }, + { + 's', + function() + require('hop').hint_char1() + end, + desc = 'Hop anywhere', + }, + { + 'S', + function() + require('hop').hint_char2() + end, + desc = 'Hop anywhere (2 chars)', + }, + { + 'sw', + function() + require('hop').hint_words() + end, + desc = 'Hop words', + }, + } + } }