From 87c73b77964b582900c50308eddd9518948eb895 Mon Sep 17 00:00:00 2001 From: Adam Hovorka Date: Sun, 7 Oct 2018 09:54:18 -0600 Subject: Customize vim statusline --- base.yaml | 1 + base/vim/autoload/gitbranch.vim | 59 +++++++++++++++++++++++++++++++++++++++++ base/vim/plugin/gitbranch.vim | 23 ++++++++++++++++ base/vimrc | 49 ++++++++++++++++++++++++++-------- base/zsh/aliases.zsh | 3 ++- 5 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 base/vim/autoload/gitbranch.vim create mode 100644 base/vim/plugin/gitbranch.vim diff --git a/base.yaml b/base.yaml index 6c525df..bac93b9 100644 --- a/base.yaml +++ b/base.yaml @@ -22,6 +22,7 @@ ~/.makepkg.conf: base/makepkg.conf ~/.npmrc: base/npmrc ~/.tmux.conf: base/tmux.conf + ~/.vim/autoload: base/vim/autoload ~/.vim/colors: base/vim/colors ~/.vim/doc: base/vim/doc ~/.vim/ftdetect: base/vim/ftdetect diff --git a/base/vim/autoload/gitbranch.vim b/base/vim/autoload/gitbranch.vim new file mode 100644 index 0000000..58f6dd8 --- /dev/null +++ b/base/vim/autoload/gitbranch.vim @@ -0,0 +1,59 @@ +" ============================================================================= +" Filename: autoload/gitbranch.vim +" Author: itchyny +" License: MIT License +" Last Change: 2015/02/26 00:34:03. +" ============================================================================= + +let s:save_cpo = &cpo +set cpo&vim + +function! gitbranch#name() abort + if get(b:, 'gitbranch_pwd', '') !=# expand('%:p:h') || !has_key(b:, 'gitbranch_path') + call gitbranch#detect(expand('%:p:h')) + endif + if has_key(b:, 'gitbranch_path') && filereadable(b:gitbranch_path) + let branch = get(readfile(b:gitbranch_path), 0, '') + if branch =~# '^ref: ' + return substitute(branch, '^ref: \%(refs/\%(heads/\|remotes/\|tags/\)\=\)\=', '', '') + elseif branch =~# '^\x\{20\}' + return branch[:6] + endif + endif + return '' +endfunction + +function! gitbranch#dir(path) abort + let path = a:path + let prev = '' + while path !=# prev + let dir = path . '/.git' + let type = getftype(dir) + if type ==# 'dir' && isdirectory(dir.'/objects') && isdirectory(dir.'/refs') && getfsize(dir.'/HEAD') > 10 + return dir + elseif type ==# 'file' + let reldir = get(readfile(dir), 0, '') + if reldir =~# '^gitdir: ' + return simplify(path . '/' . reldir[8:]) + endif + endif + let prev = path + let path = fnamemodify(path, ':h') + endwhile + return '' +endfunction + +function! gitbranch#detect(path) abort + unlet! b:gitbranch_path + let b:gitbranch_pwd = expand('%:p:h') + let dir = gitbranch#dir(a:path) + if dir !=# '' + let path = dir . '/HEAD' + if filereadable(path) + let b:gitbranch_path = path + endif + endif +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/base/vim/plugin/gitbranch.vim b/base/vim/plugin/gitbranch.vim new file mode 100644 index 0000000..a6f776a --- /dev/null +++ b/base/vim/plugin/gitbranch.vim @@ -0,0 +1,23 @@ +" ============================================================================= +" Filename: plugin/gitbranch.vim +" Author: itchyny +" License: MIT License +" Last Change: 2015/05/12 08:16:47. +" ============================================================================= + +if exists('g:loaded_gitbranch') || v:version < 700 + finish +endif +let g:loaded_gitbranch = 1 + +let s:save_cpo = &cpo +set cpo&vim + +augroup GitBranch + autocmd! + autocmd BufNewFile,BufReadPost * call gitbranch#detect(expand(':p:h')) + autocmd BufEnter * call gitbranch#detect(expand('%:p:h')) +augroup END + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/base/vimrc b/base/vimrc index befd96e..0d3871c 100644 --- a/base/vimrc +++ b/base/vimrc @@ -61,14 +61,10 @@ set wrap "set textwidth=79 "set formatoptions=tqrn1 set colorcolumn=85 -set ruler set number set relativenumber -set laststatus=2 -set shortmess=aoOstTWAI set cursorline -"set showmode -set showcmd +set shortmess=aoOstTWAI set title " change the terminal's title set scrolloff=3 @@ -88,6 +84,38 @@ set ttyfast hi ColorColumn ctermbg=18 hi Folded ctermbg=0 ctermfg=12 +" Statusline ====---- +function! StatusGitInfo() + let git = gitbranch#name() + if git != '' + return ' '.git.' ' + else + return '' +endfunction + +"set ruler +set showmode +set showcmd +set laststatus=2 +set statusline= +"set statusline+=\ S%{strftime('%R',\ getftime(expand('%')))} " Time when last saved +set statusline+=%1*\ %2*%<\ " Cut at start +set statusline+=%3*%f " Path +set statusline+=%{&modified?'\ +':''} " Modified +set statusline+=%{&ro?'\ ':''} " Read only +set statusline+=%{&paste?'\ P':''} " Paste mode +"set statusline+=[%n%H%M%R%W]\ " flags and buf no +set statusline+=%4*%=%3*\ " Section break +set statusline+=%{&ff=='unix'?'':&ff\ } " Line ending +set statusline+=%l\ %c\ %P\ " Line column percent +set statusline+=%2*%1*%{StatusGitInfo()}\ " Git branch +" ^Vue0b0 + +hi User1 ctermfg=020 ctermbg=019 +hi User2 ctermfg=019 ctermbg=018 +hi User3 ctermfg=020 ctermbg=018 +hi User4 ctermfg=018 ctermbg=000 + " Stop using arrow keys ====---- " noremap " noremap @@ -138,13 +166,13 @@ nnoremap q gqip nnoremap vp `[V`] nnoremap h :syntax sync fromstart nnoremap l :nohlsearch:diffupdate:syntax sync fromstart -nnoremap l :nohlsearch:diffupdate:syntax sync fromstart nnoremap [ :put! =repeat(nr2char(10), v:count1)'[ nnoremap ] :put =repeat(nr2char(10), v:count1) noremap y "+y noremap yy "+Y noremap p :set paste:put +:set nopaste +vnoremap p "_dP noremap + :s/^\s*/&\/\//:noh noremap - :s/^\(\s*\)\/\//\1/:noh @@ -152,7 +180,9 @@ noremap - :s/^\(\s*\)\/\//\1/:noh vnoremap Q gq nnoremap Q gqap -cnoremap w!! w !sudo tee % >/dev/null +cnoremap w!! %!sudo tee % >/dev/null +cnoremap +cnoremap " helper function to toggle hex mode function! ToggleHex() @@ -231,9 +261,6 @@ au BufNewFile,BufRead * call SetLocalOptions(bufname("%")) " To move elsewhere ====---- au BufNewFile,BufRead *.less set filetype=less autocmd! BufWritePost $MYVIMRC source $MYVIMRC -packadd! matchit -cnoremap -cnoremap autocmd! BufRead,BufNewFile *.md set filetype=markdown autocmd! BufRead,BufNewFile *.md set spell -vnoremap p "_dP +packadd! matchit diff --git a/base/zsh/aliases.zsh b/base/zsh/aliases.zsh index b0c73ca..8784e86 100644 --- a/base/zsh/aliases.zsh +++ b/base/zsh/aliases.zsh @@ -27,9 +27,10 @@ alias cp="cp -i" alias mv="mv -i" # GIT -alias gs='git status --short' +alias gits='git status --short' alias gp='git push' alias ga='git add' +alias gco='git checkout' alias gwc='git whatchanged -p --abbrev-commit --pretty=medium' # POWER -- cgit v1.2.3-70-g09d2