From 756494b15089cc8bd6e768743f429758de4d1c22 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Tue, 4 Jun 2019 21:40:57 +0200 Subject: [PATCH] better space backspacing and add a paragraph wrapping keybinding --- config/vis/visrc.lua | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/config/vis/visrc.lua b/config/vis/visrc.lua index dbe6cdc..220695a 100644 --- a/config/vis/visrc.lua +++ b/config/vis/visrc.lua @@ -66,16 +66,26 @@ vis:map(vis.modes.NORMAL, ";b", function() end) vis:map(vis.modes.INSERT, '', function() - local found_tab = true local tabwidth = 4 + local single_selection = false for selection in vis.win:selections_iterator() do - local pos = selection.pos - if not pos or pos < tabwidth or vis.win.file:content(pos - tabwidth, tabwidth) ~= string.rep(' ', tabwidth) then - found_tab = false + if single_selection then + single_selection = false break end - end - vis:feedkeys(string.rep('', found_tab and tabwidth or 1)) + single_selection = true + end + + local to_stop = (vis.win.selection.col - 1) % tabwidth + if to_stop == 0 then + to_stop = tabwidth + end + + if single_selection and to_stop > 1 and vis.win.file:content(vis.win.selection.pos - to_stop, to_stop) == string.rep(' ', to_stop) then + vis:feedkeys(string.rep('', to_stop)) + else + vis:feedkeys('') + end end) vis:map(vis.modes.NORMAL, ";s", function() @@ -85,3 +95,11 @@ end) vis:map(vis.modes.NORMAL, ";p", function() vis:command("