From 2c33e3dd3892f737dc4639ee4c99840a34516206 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Fri, 27 Aug 2021 08:30:14 +0530 Subject: [PATCH] mappings: Fix strange delete/yank/cut behaviour | Resolve #379 use mode() to detect if currently in operator pending mode, if then use normal j otherwise gj --- lua/core/mappings.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index b372c30..6f58bdb 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -19,10 +19,11 @@ M.misc = function() -- Allow moving the cursor through wrapped lines with j, k, and -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ -- empty mode is same as using :map - map("", "j", 'v:count ? "j" : "gj"', { expr = true }) - map("", "k", 'v:count ? "k" : "gk"', { expr = true }) - map("", "", 'v:count ? "j" : "gj"', { expr = true }) - map("", "", 'v:count ? "k" : "gk"', { expr = true }) + -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour + map("", "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) + map("", "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) + map("", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) + map("", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) -- use ESC to turn off search highlighting map("n", "", ":noh ")