diff --git a/nvim/autoload/airline/extensions/dotfiles_filesize.vim b/nvim/autoload/airline/extensions/dotfiles_filesize.vim new file mode 100644 index 0000000..aa52fcd --- /dev/null +++ b/nvim/autoload/airline/extensions/dotfiles_filesize.vim @@ -0,0 +1,43 @@ +" Based on + +function! airline#extensions#dotfiles_filesize#init(ext) abort + call airline#parts#define_function('dotfiles_filesize', 'airline#extensions#dotfiles_filesize#get') + call a:ext.add_statusline_func('airline#extensions#dotfiles_filesize#apply') +endfunction + +function! airline#extensions#dotfiles_filesize#apply(...) abort + call airline#extensions#append_to_section('y', airline#section#create_right(['', '', 'dotfiles_filesize'])) +endfunction + +" Finally, this function will be invoked from the statusline. +function! airline#extensions#dotfiles_filesize#get() abort + " Use several preliminary checks to prevent frequent updates. You see, + " wordcount() has to iterate the entire file to calculate its byte size. + " + " + " Implementation of wordcount: + if empty(get(b:, 'dotfiles_filesize_str', '')) || + \ (get(b:, 'dotfiles_filesize_changedtick', 0) !=# b:changedtick && + \ reltimefloat(reltime()) - get(b:, 'dotfiles_filesize_timer') >=# get(g:, 'airline#extensions#dotfiles_filesize#update_delay', 0)) + let bytes = wordcount().bytes + let b:dotfiles_filesize = bytes + + let factor = 1 + for unit in ['B', 'K', 'M', 'G'] + let next_factor = factor * 1024 + if bytes <# next_factor + let number_str = printf('%.2f', (bytes * 1.0) / factor) + " remove trailing zeros + let number_str = substitute(number_str, '\v(\.0*)=$', '', '') + let b:dotfiles_filesize_str = number_str . unit + break + endif + let factor = next_factor + endfor + + let b:dotfiles_filesize_changedtick = b:changedtick + let b:dotfiles_filesize_timer = reltimefloat(reltime()) + endif + + return b:dotfiles_filesize_str +endfunction diff --git a/nvim/autoload/airline/extensions/dotfiles_tweaks.vim b/nvim/autoload/airline/extensions/dotfiles_tweaks.vim new file mode 100644 index 0000000..d1822a3 --- /dev/null +++ b/nvim/autoload/airline/extensions/dotfiles_tweaks.vim @@ -0,0 +1,11 @@ +function! airline#extensions#dotfiles_tweaks#init(ext) abort + " Undo this commit a little bit: + " + call airline#parts#define('maxlinenr', { + \ 'raw': trim(airline#parts#get('maxlinenr').raw), + \ }) + call airline#parts#define('colnr', { + \ 'raw': trim(airline#parts#get('colnr').raw), + \ 'accent': 'none', + \ }) +endfunction diff --git a/nvim/dotfiles/plugins-list.vim b/nvim/dotfiles/plugins-list.vim index ccd39a0..f3494cd 100644 --- a/nvim/dotfiles/plugins-list.vim +++ b/nvim/dotfiles/plugins-list.vim @@ -14,12 +14,7 @@ endif Plug 'Raimondi/delimitMate' Plug 'tpope/vim-repeat' - " if g:vim_ide Plug 'tomtom/tcomment_vim' - Plug 'glts/vim-textobj-comment' - " else - " Plug 'tpope/vim-commentary' - " endif Plug 'tpope/vim-surround' Plug 'Yggdroot/indentLine' Plug 'idbrii/detectindent' @@ -37,6 +32,7 @@ Plug 'kana/vim-textobj-entire' Plug 'kana/vim-textobj-line' Plug 'kana/vim-textobj-indent' + Plug 'glts/vim-textobj-comment' " }}} " UI {{{ diff --git a/nvim/plugin/editing.vim b/nvim/plugin/editing.vim index 8b2ec27..62b7c4c 100644 --- a/nvim/plugin/editing.vim +++ b/nvim/plugin/editing.vim @@ -31,6 +31,13 @@ set commentstring=//%s let g:indentLine_showFirstIndentLevel = 1 let g:indentLine_fileTypeExclude = ['text', 'help', 'tutor', 'man'] + augroup vimrc-indentlines-disable + autocmd! + autocmd TermOpen * IndentLinesDisable + " + autocmd VimEnter * if bufname('%') == '' | IndentLinesDisable | endif + augroup END + let g:detectindent_max_lines_to_analyse = 128 let g:detectindent_check_comment_syntax = 1 diff --git a/nvim/plugin/interface.vim b/nvim/plugin/interface.vim index 2f4ac1f..11671da 100644 --- a/nvim/plugin/interface.vim +++ b/nvim/plugin/interface.vim @@ -87,71 +87,35 @@ endif " Airline (statusline) {{{ - let g:airline_theme = 'dotfiles' - let g:airline_symbols = { \ 'readonly': 'RO', - \ 'whitespace': "\u21e5 ", + \ 'whitespace': '', \ 'colnr': '', \ 'linenr': '', \ 'maxlinenr': ' ', \ 'branch': '', - \ 'notexists': " [?]", + \ 'notexists': ' [?]', \ } - - let g:airline#extensions#branch#enabled = 1 - let g:airline#extensions#tabline#enabled = 1 - let g:airline#extensions#coc#enabled = 1 - let g:airline#extensions#po#enabled = 0 - let g:airline#extensions#scrollbar#enabled = 0 - + let g:airline_extensions = [ + \ 'quickfix', + \ 'fzf', + \ 'term', + \ 'hunks', + \ 'branch', + \ 'fugitiveline', + \ 'coc', + \ 'whitespace', + \ 'wordcount', + \ 'tabline', + \ 'obsession', + \ 'dotfiles_tweaks', + \ 'dotfiles_filesize', + \ ] + let g:airline_detect_iminsert = 1 let g:airline#extensions#tabline#left_sep = ' ' let g:airline#extensions#tabline#left_alt_sep = '' - - function StatusLine_filesize() - let bytes = getfsize(expand('%')) - if bytes < 0 | return '' | endif - - let factor = 1 - for unit in ['B', 'K', 'M', 'G'] - let next_factor = factor * 1024 - if bytes < next_factor - let number_str = printf('%.2f', (bytes * 1.0) / factor) - " remove trailing zeros - let number_str = substitute(number_str, '\v\.?0+$', '', '') - return number_str . unit - endif - let factor = next_factor - endfor - endfunction - call airline#parts#define('filesize', { 'function': 'StatusLine_filesize' }) - - " Undo this commit a little bit: - " - call airline#parts#define('maxlinenr', { - \ 'raw': '/%L%{g:airline_symbols.maxlinenr}', - \ 'accent': 'bold', - \ }) - call airline#parts#define('colnr', { - \ 'raw': '%{g:airline_symbols.colnr}:%v', - \ 'accent': 'none', - \ }) - - function s:airline_section_prepend(section, items) - let g:airline_section_{a:section} = airline#section#create_right(a:items + ['']) . g:airline_section_{a:section} - endfunction - function s:airline_section_append(section, items) - let g:airline_section_{a:section} = g:airline_section_{a:section} . airline#section#create_left([''] + a:items) - endfunction - function s:tweak_airline() - call s:airline_section_append('y', ['filesize']) - endfunction - augroup vimrc-interface-airline - autocmd! - autocmd user AirlineAfterInit call s:tweak_airline() - augroup END - + let g:airline#extensions#dotfiles_filesize#update_delay = 2 " }}} @@ -173,12 +137,4 @@ endif " }}} -" Terminal {{{ - augroup vimrc-terminal - autocmd! - autocmd TermOpen * IndentLinesDisable - augroup END -" }}} - - nnoremap make