diff options
author | Yaroslav <contact@yaroslavps.com> | 2019-09-05 19:35:38 +0300 |
---|---|---|
committer | Yaroslav <contact@yaroslavps.com> | 2019-09-05 19:35:38 +0300 |
commit | 212dcd0bf753f08c0127a26a71b673c734b45c02 (patch) | |
tree | 4a43e43c7c9b9ccfcaef4088ba9e5f52154994b5 /.vim/autoload/airline/extensions/tabline/formatters | |
download | vimrice-212dcd0bf753f08c0127a26a71b673c734b45c02.tar.gz vimrice-212dcd0bf753f08c0127a26a71b673c734b45c02.zip |
init commit, extracted vim config from i3rice
Diffstat (limited to '.vim/autoload/airline/extensions/tabline/formatters')
5 files changed, 204 insertions, 0 deletions
diff --git a/.vim/autoload/airline/extensions/tabline/formatters/default.vim b/.vim/autoload/airline/extensions/tabline/formatters/default.vim new file mode 100644 index 0000000..c98d7ef --- /dev/null +++ b/.vim/autoload/airline/extensions/tabline/formatters/default.vim @@ -0,0 +1,43 @@ +" MIT License. Copyright (c) 2013-2018 Bailey Ling et al. +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +let s:fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1) +let s:fnametruncate = get(g:, 'airline#extensions#tabline#fnametruncate', 0) +let s:buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ') +let s:buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0) +let s:buf_modified_symbol = g:airline_symbols.modified + +function! airline#extensions#tabline#formatters#default#format(bufnr, buffers) + let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.') + let _ = '' + + let name = bufname(a:bufnr) + if empty(name) + let _ .= '[No Name]' + else + if s:fnamecollapse + " Does not handle non-ascii characters like Cyrillic: 'D/Учёба/t.c' + "let _ .= substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g') + let _ .= pathshorten(fnamemodify(name, fmod)) + else + let _ .= fnamemodify(name, fmod) + endif + if a:bufnr != bufnr('%') && s:fnametruncate && strlen(_) > s:fnametruncate + let _ = strpart(_, 0, s:fnametruncate) + endif + endif + + return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, _) +endfunction + +function! airline#extensions#tabline#formatters#default#wrap_name(bufnr, buffer_name) + let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : '' + let _ .= substitute(a:buffer_name, '\\', '/', 'g') + + if getbufvar(a:bufnr, '&modified') == 1 + let _ .= s:buf_modified_symbol + endif + return _ +endfunction diff --git a/.vim/autoload/airline/extensions/tabline/formatters/jsformatter.vim b/.vim/autoload/airline/extensions/tabline/formatters/jsformatter.vim new file mode 100644 index 0000000..b16d06f --- /dev/null +++ b/.vim/autoload/airline/extensions/tabline/formatters/jsformatter.vim @@ -0,0 +1,15 @@ +" MIT License. Copyright (c) 2013-2018 Bailey Ling et al. +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +function! airline#extensions#tabline#formatters#jsformatter#format(bufnr, buffers) + let buf = bufname(a:bufnr) + let filename = fnamemodify(buf, ':t') + + if filename == 'index.js' || filename == 'index.jsx' || filename == 'index.ts' || filename == 'index.tsx' + return fnamemodify(buf, ':p:h:t') . '/i' + else + return airline#extensions#tabline#formatters#unique_tail_improved#format(a:bufnr, a:buffers) + endif +endfunction diff --git a/.vim/autoload/airline/extensions/tabline/formatters/tabnr.vim b/.vim/autoload/airline/extensions/tabline/formatters/tabnr.vim new file mode 100644 index 0000000..fa71014 --- /dev/null +++ b/.vim/autoload/airline/extensions/tabline/formatters/tabnr.vim @@ -0,0 +1,14 @@ +" MIT License. Copyright (c) 2017-2018 C.Brabandt et al. +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +function! airline#extensions#tabline#formatters#tabnr#format(tab_nr_type, nr) + if a:tab_nr_type == 0 " nr of splits + return (g:airline_symbols.space).'%{len(tabpagebuflist('.a:nr.'))}' + elseif a:tab_nr_type == 1 " tab number + return (g:airline_symbols.space).a:nr + else "== 2 splits and tab number + return (g:airline_symbols.space).a:nr.'.%{len(tabpagebuflist('.a:nr.'))}' + endif +endfunction diff --git a/.vim/autoload/airline/extensions/tabline/formatters/unique_tail.vim b/.vim/autoload/airline/extensions/tabline/formatters/unique_tail.vim new file mode 100644 index 0000000..3e61b60 --- /dev/null +++ b/.vim/autoload/airline/extensions/tabline/formatters/unique_tail.vim @@ -0,0 +1,41 @@ +" MIT License. Copyright (c) 2013-2018 Bailey Ling et al. +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +function! airline#extensions#tabline#formatters#unique_tail#format(bufnr, buffers) + let duplicates = {} + let tails = {} + let map = {} + for nr in a:buffers + let name = bufname(nr) + if empty(name) + let map[nr] = '[No Name]' + else + let tail = fnamemodify(name, ':s?/\+$??:t') + if has_key(tails, tail) + let duplicates[nr] = nr + endif + let tails[tail] = 1 + let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, tail) + endif + endfor + + let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.') + for nr in values(duplicates) + let name = bufname(nr) + let fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1) + if fnamecollapse + let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g')) + else + let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, fnamemodify(name, fmod)) + endif + endfor + + if has_key(map, a:bufnr) + return map[a:bufnr] + endif + + " if we get here, the buffer list isn't in sync with the selected buffer yet, fall back to the default + return airline#extensions#tabline#formatters#default#format(a:bufnr, a:buffers) +endfunction diff --git a/.vim/autoload/airline/extensions/tabline/formatters/unique_tail_improved.vim b/.vim/autoload/airline/extensions/tabline/formatters/unique_tail_improved.vim new file mode 100644 index 0000000..c48174b --- /dev/null +++ b/.vim/autoload/airline/extensions/tabline/formatters/unique_tail_improved.vim @@ -0,0 +1,91 @@ +" MIT License. Copyright (c) 2013-2018 Bailey Ling et al. +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +let s:skip_symbol = '…' + +function! airline#extensions#tabline#formatters#unique_tail_improved#format(bufnr, buffers) + if len(a:buffers) <= 1 " don't need to compare bufnames if has less than one buffer opened + return airline#extensions#tabline#formatters#default#format(a:bufnr, a:buffers) + endif + + let curbuf_tail = fnamemodify(bufname(a:bufnr), ':t') + let do_deduplicate = 0 + let path_tokens = {} + + for nr in a:buffers + let name = bufname(nr) + if !empty(name) && nr != a:bufnr && fnamemodify(name, ':t') == curbuf_tail " only perform actions if curbuf_tail isn't unique + let do_deduplicate = 1 + let tokens = reverse(split(substitute(fnamemodify(name, ':p:h'), '\\', '/', 'g'), '/')) + let token_index = 0 + for token in tokens + if token == '' | continue | endif + if token == '.' | break | endif + if !has_key(path_tokens, token_index) + let path_tokens[token_index] = {} + endif + let path_tokens[token_index][token] = 1 + let token_index += 1 + endfor + endif + endfor + + if do_deduplicate == 1 + let path = [] + let token_index = 0 + for token in reverse(split(substitute(fnamemodify(bufname(a:bufnr), ':p:h'), '\\', '/', 'g'), '/')) + if token == '.' | break | endif + let duplicated = 0 + let uniq = 1 + let single = 1 + if has_key(path_tokens, token_index) + let duplicated = 1 + if len(keys(path_tokens[token_index])) > 1 | let single = 0 | endif + if has_key(path_tokens[token_index], token) | let uniq = 0 | endif + endif + call insert(path, {'token': token, 'duplicated': duplicated, 'uniq': uniq, 'single': single}) + let token_index += 1 + endfor + + let buf_name = [curbuf_tail] + let has_uniq = 0 + let has_skipped = 0 + for token1 in reverse(path) + if !token1['duplicated'] && len(buf_name) > 1 + call insert(buf_name, s:skip_symbol) + let has_skipped = 0 + break + endif + + if has_uniq == 1 + call insert(buf_name, s:skip_symbol) + let has_skipped = 0 + break + endif + + if token1['uniq'] == 0 && token1['single'] == 1 + let has_skipped = 1 + else + if has_skipped == 1 + call insert(buf_name, s:skip_symbol) + let has_skipped = 0 + endif + call insert(buf_name, token1['token']) + endif + + if token1['uniq'] == 1 + let has_uniq = 1 + endif + endfor + + if has_skipped == 1 + call insert(buf_name, s:skip_symbol) + endif + + return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, join(buf_name, '/')) + else + return airline#extensions#tabline#formatters#default#format(a:bufnr, a:buffers) + endif +endfunction |