feat: improve performance by mapping less text objects

Mapping things like tab navigation on text object is unnecessary and
even detrimental as these could be used for something else.
This commit is contained in:
Clément Joly 2022-05-07 20:24:52 +00:00
parent 00362b9325
commit d7dc868fe4
2 changed files with 60 additions and 48 deletions

View File

@ -23,11 +23,15 @@
(vim.api.nvim_set_keymap :x key target {:noremap true})) (vim.api.nvim_set_keymap :x key target {:noremap true}))
nil) nil)
(fn map-normal [key target]
"For normal mode mappings"
(when (= (vim.fn.maparg key :n) "")
(vim.api.nvim_set_keymap :n key target {:noremap true})))
(fn map-all [key target] (fn map-all [key target]
"For everything else" "For all directional mappings"
(if (= (vim.fn.maparg key :n) "") (map-normal key target)
(vim.api.nvim_set_keymap :n key target {:noremap true}) (map-text-object key target))
(map-text-object key target)))
(fn mapping-setup [] (fn mapping-setup []
;; Keys still free ;; Keys still free
@ -51,8 +55,9 @@
(map-all :gs :gk) (map-all :gs :gk)
;; ------ ;; ------
;; on préserve les variantes avec 'z' ;; on préserve les variantes avec 'z'
;; I like zt better (map-all :zj :zt)
;; (map-all "zt" "zj") (map-all :zt :zj)
(map-all :zk :zs)
(map-all :zs :zk) (map-all :zs :zk)
;; ------ ;; ------
(map-all :h :t) (map-all :h :t)
@ -71,19 +76,19 @@
;; {k} devient [s] ;; {k} devient [s]
(map-all :K :S) (map-all :K :S)
;; {h} devient [S] ;; {h} devient [S]
(map-all :gb :gT) (map-normal :gb :gT)
;; le couple [gb]/[gé] agit sur les tabs ;; le couple [gb]/[gé] agit sur les tabs
(map-all "gé" :gt) (map-normal "gé" :gt)
;; le couple [gb]/[gé] agit sur les tabs ;; le couple [gb]/[gé] agit sur les tabs
(map-all :gB ":execute \"silent! tabfirst\"<CR>") (map-normal :gB ":execute \"silent! tabfirst\"<CR>")
;; [gB] va au premier tab ;; [gB] va au premier tab
(map-all "gÉ" ":execute \"silent! tablast\"<CR>") (map-normal "gÉ" ":execute \"silent! tablast\"<CR>")
;; [gÉ] au dernier ;; [gÉ] au dernier
(map-all :gT "<C-]>") (map-normal :gT "<C-]>")
;; [gT] est libéré et peut agir sur les tags ;; [gT] est libéré et peut agir sur les tags
(map-all "«" "<") (map-normal "«" "<")
;; [<] est moins accessible que [«] ;; [<] est moins accessible que [«]
(map-all "»" ">") (map-normal "»" ">")
;; idem pour [»] et [>] ;; idem pour [»] et [>]
(map-all "g," "g;") (map-all "g," "g;")
;; idem pour [g,] et [g;] ;; idem pour [g,] et [g;]
@ -103,33 +108,33 @@
(map-text-object "iÉ" :iW) (map-text-object "iÉ" :iW)
;; idem pour [iW] et [iÉ] ;; idem pour [iW] et [iÉ]
;; ------ ;; ------
(map-all :w :<C-w>) (map-normal :w :<C-w>)
;; [w] est libre pour faire <C-w> ;; [w] est libre pour faire <C-w>
(map-all :W :<C-w><C-w>) (map-normal :W :<C-w><C-w>)
;; et [w] pour faire <C-w><C-w> ;; et [w] pour faire <C-w><C-w>
(map-all :wc :<C-w>h) (map-normal :wc :<C-w>h)
;; on map [w]+direction ;; on map [w]+direction
(map-all :wt :<C-w>j) (map-normal :wt :<C-w>j)
;; on map [w]+direction ;; on map [w]+direction
(map-all :ws :<C-w>k) (map-normal :ws :<C-w>k)
;; on map [w]+direction ;; on map [w]+direction
(map-all :wr :<C-w>l) (map-normal :wr :<C-w>l)
;; on map [w]+direction ;; on map [w]+direction
(map-all :wC :<C-w>H) (map-normal :wC :<C-w>H)
;; idem pour les majuscules ;; idem pour les majuscules
(map-all :wT :<C-w>J) (map-normal :wT :<C-w>J)
;; idem pour les majuscules ;; idem pour les majuscules
(map-all :wS :<C-w>K) (map-normal :wS :<C-w>K)
;; idem pour les majuscules ;; idem pour les majuscules
(map-all :wR :<C-w>L) (map-normal :wR :<C-w>L)
;; idem pour les majuscules ;; idem pour les majuscules
;; ------ ;; ------
(map-all :wh :<C-w>s) (map-normal :wh :<C-w>s)
;; crée un split _h_orizontal ;; crée un split _h_orizontal
;; ------ ;; ------
(map-all "wé" :<C-w>t) (map-normal "wé" :<C-w>t)
;; va en haut à gauche ;; va en haut à gauche
(map-all "wÉ" :<C-w>T) (map-normal "wÉ" :<C-w>T)
;; déplace sur un nouveau tab ;; déplace sur un nouveau tab
) )

View File

@ -7,13 +7,17 @@ local function map_text_object(key, target)
end end
return nil return nil
end end
local function map_all(key, target) local function map_normal(key, target)
if (vim.fn.maparg(key, "n") == "") then if (vim.fn.maparg(key, "n") == "") then
return vim.api.nvim_set_keymap("n", key, target, {noremap = true}) return vim.api.nvim_set_keymap("n", key, target, {noremap = true})
else else
return map_text_object(key, target) return nil
end end
end end
local function map_all(key, target)
map_normal(key, target)
return map_text_object(key, target)
end
local function mapping_setup() local function mapping_setup()
map_all("c", "h") map_all("c", "h")
map_all("t", "j") map_all("t", "j")
@ -25,6 +29,9 @@ local function mapping_setup()
map_all("R", "L") map_all("R", "L")
map_all("gt", "gj") map_all("gt", "gj")
map_all("gs", "gk") map_all("gs", "gk")
map_all("zj", "zt")
map_all("zt", "zj")
map_all("zk", "zs")
map_all("zs", "zk") map_all("zs", "zk")
map_all("h", "t") map_all("h", "t")
map_all("H", "T") map_all("H", "T")
@ -34,13 +41,13 @@ local function mapping_setup()
map_all("J", "R") map_all("J", "R")
map_all("k", "s") map_all("k", "s")
map_all("K", "S") map_all("K", "S")
map_all("gb", "gT") map_normal("gb", "gT")
map_all("g\195\169", "gt") map_normal("g\195\169", "gt")
map_all("gB", ":execute \"silent! tabfirst\"<CR>") map_normal("gB", ":execute \"silent! tabfirst\"<CR>")
map_all("g\195\137", ":execute \"silent! tablast\"<CR>") map_normal("g\195\137", ":execute \"silent! tablast\"<CR>")
map_all("gT", "<C-]>") map_normal("gT", "<C-]>")
map_all("\194\171", "<") map_normal("\194\171", "<")
map_all("\194\187", ">") map_normal("\194\187", ">")
map_all("g,", "g;") map_all("g,", "g;")
map_all("g;", "g,") map_all("g;", "g,")
map_all("\195\169", "w") map_all("\195\169", "w")
@ -49,19 +56,19 @@ local function mapping_setup()
map_text_object("a\195\137", "aW") map_text_object("a\195\137", "aW")
map_text_object("i\195\169", "iw") map_text_object("i\195\169", "iw")
map_text_object("i\195\137", "iW") map_text_object("i\195\137", "iW")
map_all("w", "<C-w>") map_normal("w", "<C-w>")
map_all("W", "<C-w><C-w>") map_normal("W", "<C-w><C-w>")
map_all("wc", "<C-w>h") map_normal("wc", "<C-w>h")
map_all("wt", "<C-w>j") map_normal("wt", "<C-w>j")
map_all("ws", "<C-w>k") map_normal("ws", "<C-w>k")
map_all("wr", "<C-w>l") map_normal("wr", "<C-w>l")
map_all("wC", "<C-w>H") map_normal("wC", "<C-w>H")
map_all("wT", "<C-w>J") map_normal("wT", "<C-w>J")
map_all("wS", "<C-w>K") map_normal("wS", "<C-w>K")
map_all("wR", "<C-w>L") map_normal("wR", "<C-w>L")
map_all("wh", "<C-w>s") map_normal("wh", "<C-w>s")
map_all("w\195\169", "<C-w>t") map_normal("w\195\169", "<C-w>t")
return map_all("w\195\137", "<C-w>T") return map_normal("w\195\137", "<C-w>T")
end end
local function setup() local function setup()
if (vim.g.loaded_bepo_nvim == nil) then if (vim.g.loaded_bepo_nvim == nil) then