]> Sergey Matveev's repositories - dotfiles.git/commitdiff
:Align
authorSergey Matveev <stargrave@stargrave.org>
Tue, 1 Mar 2022 09:40:43 +0000 (12:40 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 1 Mar 2022 09:44:49 +0000 (12:44 +0300)
vim/.vim/pack/stargrave/start/align/autoload/align.vim [new file with mode: 0644]
vim/.vim/pack/stargrave/start/align/plugin/align.vim [new file with mode: 0644]

diff --git a/vim/.vim/pack/stargrave/start/align/autoload/align.vim b/vim/.vim/pack/stargrave/start/align/autoload/align.vim
new file mode 100644 (file)
index 0000000..869fd50
--- /dev/null
@@ -0,0 +1,13 @@
+" something that won't be met anywhere
+let s:sep = "₀◎○ë"
+
+function! align#do(first, last, sep) abort
+    let in = []
+    for n in range(a:first, a:last)
+        let in = add(in, substitute(getline(n), a:sep, "\t" . s:sep, "g"))
+    endfor
+    let out = systemlist("column -t -s \"\t\"", add(in, ""))
+    for n in range(a:first, a:last)
+        call setline(n, substitute(out[n - a:first], "  " . s:sep, a:sep, "g"))
+    endfor
+endfunction
diff --git a/vim/.vim/pack/stargrave/start/align/plugin/align.vim b/vim/.vim/pack/stargrave/start/align/plugin/align.vim
new file mode 100644 (file)
index 0000000..5d95b11
--- /dev/null
@@ -0,0 +1,2 @@
+if exists("*align#do") | finish | endif
+command! -nargs=1 -range Align call align#do(<line1>, <line2>, <f-args>)