]> Sergey Matveev's repositories - dotfiles.git/commitdiff
IndentWise is replaced with navindent
authorSergey Matveev <stargrave@stargrave.org>
Wed, 26 Oct 2022 10:41:42 +0000 (13:41 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 26 Oct 2022 10:41:42 +0000 (13:41 +0300)
vim/.vim/pack/stargrave/start/navindent/autoload/navindent.vim [new file with mode: 0644]
vim/.vim/pack/stargrave/start/navindent/plugin/navindent.vim [new file with mode: 0644]

diff --git a/vim/.vim/pack/stargrave/start/navindent/autoload/navindent.vim b/vim/.vim/pack/stargrave/start/navindent/autoload/navindent.vim
new file mode 100644 (file)
index 0000000..961cfa6
--- /dev/null
@@ -0,0 +1,22 @@
+vim9script
+
+# Based on https://vim.fandom.com/wiki/Move_to_next/previous_line_with_same_indentation
+
+export def Do(step: number, diff: number)
+    var l = line(".")
+    var cin = indent(l)
+    var last = line("$")
+    var lin: number
+    while (l > 0 && l <= last)
+        l += step
+        if (strlen(getline(l)) == 0) | continue | endif
+        lin = indent(l)
+        if !(
+            ((diff == 0) && (lin == cin)) ||
+            ((diff == 1) && (lin > cin)) ||
+            ((diff == -1) && (lin < cin))
+        ) | continue | endif
+        cursor(l, lin + 1)
+        return
+    endwhile
+enddef
diff --git a/vim/.vim/pack/stargrave/start/navindent/plugin/navindent.vim b/vim/.vim/pack/stargrave/start/navindent/plugin/navindent.vim
new file mode 100644 (file)
index 0000000..138a26b
--- /dev/null
@@ -0,0 +1,7 @@
+if exists("*navindent#Do") | finish | endif
+nmap <silent> [- :call navindent#Do(-1, -1)<CR>
+nmap <silent> ]- :call navindent#Do(+1, -1)<CR>
+nmap <silent> [= :call navindent#Do(-1, 0)<CR>
+nmap <silent> ]= :call navindent#Do(+1, 0)<CR>
+nmap <silent> [+ :call navindent#Do(-1, +1)<CR>
+nmap <silent> ]+ :call navindent#Do(+1, +1)<CR>