Initial BufTabline
authorSergey Matveev <stargrave@stargrave.org>
Sun, 26 Jul 2020 16:13:50 +0000 (19:13 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 26 Jul 2020 16:13:50 +0000 (19:13 +0300)
vim/.vim/plugin/buftabline.vim [new file with mode: 0644]

diff --git a/vim/.vim/plugin/buftabline.vim b/vim/.vim/plugin/buftabline.vim
new file mode 100644 (file)
index 0000000..30a0c3c
--- /dev/null
@@ -0,0 +1,29 @@
+function! BufTabline()
+    redir => bufsRaw
+    silent buffers
+    redir END
+    let bufs = []
+    for buf in split(bufsRaw, "\n")
+        let buf = substitute(buf, "\"", "", "g")
+        let ents = []
+        for ent in split(buf, " ")
+            if len(ent) == 0 | continue | endif
+            let ents = add(ents, substitute(ent, "%", "%%", "g"))
+        endfor
+        let ents = ents[:-3]
+        if len(ents) == 4 | let ents = [ents[0], ents[1] . ents[2], ents[3]] | endif
+        if len(ents) == 3 | let ents = [ents[0] . ":" . ents[1], ents[2]] | endif
+        let ents[0] = "%#TabLine#" . ents[0] . "%*"
+        if len(ents[1]) > 20 | let ents[1] = "<" . ents[1][-19:] | endif
+        if match(ents[0], "%%") == -1
+            let ents[1] = "%#TabLine#:" . ents[1] . "%*"
+        else
+            let ents[1] = "%#TabLineSel#" . ents[1] . "%*"
+        endif
+        let bufs = add(bufs, join(ents[:1], ""))
+    endfor
+    return join(bufs, "%#Comment#|%*")
+endfunction
+
+set showtabline=2
+set tabline=%!BufTabline()