Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easymotion crashes NeoVim #507

Open
synic opened this issue Apr 2, 2024 · 3 comments
Open

Easymotion crashes NeoVim #507

synic opened this issue Apr 2, 2024 · 3 comments

Comments

@synic
Copy link

synic commented Apr 2, 2024

This is my lazy.nvim configuration for easymotion:

	{
		"Lokaltog/vim-easymotion",
		init = function()
			vim.g.EasyMotion_smartcase = true
			vim.g.EasyMotion_do_mapping = false
			vim.g.EasyMotion_inc_highlight = false
			vim.g.EasyMotion_disable_two_key_combo = true
			vim.g.EasyMotion_keys = "abcdefhjkmnoprstuvwxyz;"
		end,
		keys = {
			{ "<leader><leader>", "<plug>(easymotion-overwin-f)", desc = "Jump to location", mode = "n" },
			{ "<leader><leader>", "<plug>(easymotion-bd-f)", desc = "Jump to location", mode = "v" },
		},
	},

My NeoVim version is: v0.10.0-dev-2786+gb3f9da952, though this happens with 0.9 as well.

I mostly just use <space><space> and then a character to jump anywhere in neovim, even across windows. However, sometimes when I press the target key, neovim just crashes immediately.

I have not determined exactly what causes this. It seems to be random, but more often when there's more than one split window visible.

@synic
Copy link
Author

synic commented Apr 2, 2024

Oh wow, I just realized I haven't updated the repository from Lokaltog. I'll try that to see if it helps.

@synic
Copy link
Author

synic commented Apr 3, 2024

Nope, that definitely did not help.

@synic
Copy link
Author

synic commented Dec 7, 2024

Found a solution. Didn't really fix the NeoVim+EasyMotion crashing problem, but I did find a way to emulate EasyMotion using hop.nvim:

https://synic.dev/article/2024-12-07/bringing-easymotion-back-to-neovim

	{
		"smoka7/hop.nvim",
		version = "*",
		opts = { keys = "etovxpdygfblzhckisuran;,", quit_key = "q" },
		config = function(_, opts)
			local hop = require("hop")
			hop.setup(opts)

			-- Create custom command for hopping to character/word matches
			vim.api.nvim_create_user_command("HopEasyMotion", function()
				local char = vim.fn.getchar()
				-- Convert numeric char code to string
				char = type(char) == "number" and vim.fn.nr2char(char) or char

				-- Create pattern based on input character type
				local pattern
				if char:match("%a") then
					-- For letters: match words starting with that letter (case insensitive)
					pattern = "\\c\\<" .. char
				elseif char:match("[%(%)]") then
					-- For parentheses: match them literally
					pattern = char
				elseif char == "." then
					-- For period: match literal period
					pattern = "\\."
				else
					-- For other non-letters: escape special characters
					pattern = char:gsub("([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
				end

				---@diagnostic disable-next-line: missing-fields
				hop.hint_patterns({
					current_line_only = false,
					multi_windows = true,
					hint_position = require("hop.hint").HintPosition.BEGIN,
				}, pattern)
			end, { desc = "Hop to words starting with input character" })
		end,
		keys = {
			{ "<leader><leader>", "<cmd>HopEasyMotion<cr>", desc = "Hop to word" },
			{ ";b", "<cmd>HopWordBC<cr>", desc = "Hop to word before cursor" },
			{ ";w", "<cmd>HopWord<cr>", desc = "Hop to word in current buffer" },
			{ ";a", "<cmd>HopWordAC<cr>", desc = "Hop to word after cursor" },
			{ ";d", "<cmd>HopLineMW<cr>", desc = "Hop to line" },
			{ ";f", "<cmd>HopNodes<cr>", desc = "Hop to node" },
			{ ";s", "<cmd>HopPatternMW<cr>", desc = "Hop to pattern" },
			{ ";j", "<cmd>HopVertical<cr>", desc = "Hop to location vertically" },
		},
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant