From 2f8482639db32c665f78a211bd007aa9fc14d0c4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 27 Feb 2024 23:27:20 +0100 Subject: [PATCH] update some mappings 1. fix a typo in gJ mapping when setting the mark, the correct syntax is `mz` (set mark `z`), not `zm` 2. fix bug with `iB` text object: previously `viB` does not work as expected, because it does not select the entire buffer as expected. After much investigation, I found it is because the `` mapping argument. If we use `` argument for mapping, the mode does not change. So if we use `viB`, inititally we are still in visual mode. Later in the implementation, when we use `` normal! ` `` to select the entire buffer, it interferes with original visual mode. As a result, the entire buffer is not selected. In the text obj implementation, we can use `exe "normal! \"` to clear the visual mode and make `viB`, but this is not ideal. I think it is eaiser to just not use the `` argument and use `:` instead. --- lua/mappings.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index 1853317..2837650 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -170,7 +170,7 @@ keymap.set("n", "", "j") keymap.set({ "x", "o" }, "iu", "call text_obj#URL()", { desc = "URL text object" }) -- Text objects for entire buffer -keymap.set({ "x", "o" }, "iB", "call text_obj#Buffer()", { desc = "buffer text object" }) +keymap.set({ "x", "o" }, "iB", ":call text_obj#Buffer()", { desc = "buffer text object" }) -- Do not move my cursor when joining lines. keymap.set("n", "J", function() @@ -179,17 +179,17 @@ keymap.set("n", "J", function() delmarks z ]]) end, { - desc = "join line", + desc = "join lines without moving cursor", }) keymap.set("n", "gJ", function() -- we must use `normal!`, otherwise it will trigger recursive mapping vim.cmd([[ - normal! zmgJ`z + normal! mzgJ`z delmarks z ]]) end, { - desc = "join visual lines", + desc = "join lines without moving cursor", }) -- Break inserted text into smaller undo units when we insert some punctuation chars.