From 34a010557caf40c7c6640bd85a0dfb528e449da5 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 2 Dec 2021 00:27:01 +0900 Subject: neovim: emulate `g:EasyMotion_startofline = 0` in hop.nvim --- .config/nvim/init.lua | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 8148eb1..a8d131a 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1549,9 +1549,32 @@ require('hop').setup { keys = 'asdfghweryuiocvbnmjkl;', } --- TODO: hop cannot emulate these behaviors of EasyMotion. --- let g:EasyMotion_space_jump_first = v:true --- let g:EasyMotion_startofline = v:false +-- Emulate `g:EasyMotion_startofline = 0` in hop.nvim. +function vimrc.map_callbacks.hop_jk(opts) + local hop = require('hop') + local jump_target = require('hop.jump_target') + + local column = F.col('.') + local match + if column == 1 then + match = function(_) + return 0, 1, false + end + else + local pat = vim.regex('\\%' .. column .. 'c') + match = function(s) + return pat:match_str(s) + end + end + setmetatable(opts, { __index = hop.opts }) + hop.hint_with( + jump_target.jump_targets_by_scanning_lines({ + oneshot = true, + match = match, + }), + opts + ) +end vimrc.map('', '(hop-f)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true })", { silent = true }) vimrc.map('', '(hop-F)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true })", { silent = true }) @@ -1561,8 +1584,8 @@ vimrc.map('', '(hop-T)', "lua require('hop').hint_char1({ direction = vimrc.map('', '(hop-s2)', "lua require('hop').hint_char2()", { silent = true }) vimrc.map('', '(hop-n)', "lua require('hop').hint_patterns({ direction = require('hop.hint').HintDirection.AFTER_CURSOR }, vim.fn.getreg('/'))", { silent = true }) vimrc.map('', '(hop-N)', "lua require('hop').hint_patterns({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR }, vim.fn.getreg('/'))", { silent = true }) -vimrc.map('', '(hop-j)', "lua require('hop').hint_lines({ direction = require('hop.hint').HintDirection.AFTER_CURSOR })", { silent = true }) -vimrc.map('', '(hop-k)', "lua require('hop').hint_lines({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR })", { silent = true }) +vimrc.map('', '(hop-j)', "lua vimrc.map_callbacks.hop_jk({ direction = require('hop.hint').HintDirection.AFTER_CURSOR })", { silent = true }) +vimrc.map('', '(hop-k)', "lua vimrc.map_callbacks.hop_jk({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR })", { silent = true }) vimrc.map_plug('n', 'f', '(hop-f)') vimrc.map_plug('o', 'f', '(hop-f)') -- cgit v1.2.3-70-g09d2