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

[Bug]: Resize mode is deleting my global keymaps that remap j and k to gj and gk #126

Closed
1 task done
serranomorante opened this issue Sep 1, 2023 · 2 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@serranomorante
Copy link

Similar Issues

  • Before filing, I have searched for similar issues.

Neovim Version

NVIM v0.9.1

Multiplexer Integration

I don't use one

Multiplexer Version

No response

Steps to Reproduce

t-rec_12

Disclaimer

I have my global keymaps defined BEFORE my package manager (lazy.nvim) loads.

  1. Configure this global keymap (helps to move by display lines when I have the wrap set to on).
-- Navigate display lines
vim.keymap.set({ "n", "x" }, "j", function()
	return vim.v.count > 0 and "j" or "gj"
end, { noremap = true, expr = true })
vim.keymap.set({ "n", "x" }, "k", function()
	return vim.v.count > 0 and "k" or "gk"
end, { noremap = true, expr = true })
  1. Open a buffer (with any content) and make the text wrap (as in the screenshot). Pressing j or k should move your cursor by display lines (it will not skip the wrapped text lines). Good, your keymap is working normally.
  2. Enter resize mode and resize your window a little bit in any direction (as in the screenshot) and then exit resize mode.
  3. Try to move again between wrapped lines, now j and k are skipping the wrapped lines (this should not happen)

I think vim.api.nvim_del_keymap on file resize_mode.lua on line 47-51 are the ones to blame.

Expected Behavior

Entering resize mode should not delete my previous mapping.

Actual Behavior

Entering resize mode deletes my previous mapping.

Minimal Configuration to Reproduce

remap.lua -- loaded before my package manager

-- Navigate display lines
vim.keymap.set({ "n", "x" }, "j", function()
	return vim.v.count > 0 and "j" or "gj"
end, { noremap = true, expr = true })
vim.keymap.set({ "n", "x" }, "k", function()
	return vim.v.count > 0 and "k" or "gk"
end, { noremap = true, expr = true })

smart-splits.lua

local utils = require("serranomorante.utils")

return {
	{
		"kwkarlwang/bufresize.nvim",
		event = "VeryLazy",
		config = true,
	},

	{
		"mrjones2014/smart-splits.nvim",
		-- enabled = false,
		keys = {
			{
				"<leader>rs",
				function()
					require("smart-splits").start_resize_mode()
				end,
			},
			{
				"<leader><leader>h",
				function()
					-- Quick return if next window is neo-tree
					local next_winid = vim.fn.win_getid(vim.fn.winnr(utils.DirectionKeys[utils.Direction.left]))
					local filetype = utils.buf_filetype_from_winid(next_winid)
					if filetype == "neo-tree" then
						return
					end

					require("smart-splits").swap_buf_left()
				end,
			},
			{
				"<leader><leader>j",
				function()
					require("smart-splits").swap_buf_down()
				end,
			},
			{
				"<leader><leader>k",
				function()
					require("smart-splits").swap_buf_up()
				end,
			},
			{
				"<leader><leader>l",
				function()
					-- Quick return if next window is neo-tree
					local swap_direction = utils.Direction.right
					local will_wrap = utils.win_at_edge(swap_direction)
					if will_wrap then
						local wrap_winid = utils.win_wrap_id(swap_direction)
						local filetype = utils.buf_filetype_from_winid(wrap_winid)
						if filetype == "neo-tree" then
							return
						end
					end

					require("smart-splits").swap_buf_right()
				end,
			},
		},
		opts = function()
			return {
				cursor_follows_swapped_bufs = true,
				ignored_filetypes = {
					"nofile",
					"quickfix",
					"prompt",
					"neo-tree",
					"harpoon",
					"NvimTree",
				},
				resize_mode = {
					silent = true,
					hooks = {
						on_leave = function()
							require("bufresize").register()
							vim.notify("Smart Splits: RESIZE MODE OFF", vim.log.levels.INFO)
						end,
						on_enter = function()
							vim.notify("Smart Splits: RESIZE MODE ON", vim.log.levels.WARN)
						end,
					},
				},
			}
		end,
	},
}

Additional Details and/or Screenshots

No response

@serranomorante serranomorante added the bug Something isn't working label Sep 1, 2023
@mrjones2014
Copy link
Owner

Unfortunately there isn't a way the plugin can work around this directly. You can use this:

local function jkmaps()
  -- Navigate display lines
  vim.keymap.set({ "n", "x" }, "j", function()
	return vim.v.count > 0 and "j" or "gj"
  end, { noremap = true, expr = true })
  vim.keymap.set({ "n", "x" }, "k", function()
	return vim.v.count > 0 and "k" or "gk"
  end, { noremap = true, expr = true })
end

require('smart-splits').setup({
  resize_mode = {
    hooks = {
      on_leave = jkmaps,
    },
  },
})

@mrjones2014 mrjones2014 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
@serranomorante
Copy link
Author

That is good enough! thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants