├── README.md ├── doc └── smartusline.txt ├── img └── smartusline.gif └── plugin └── smartusline.vim /README.md: -------------------------------------------------------------------------------- 1 | SmartusLine 2 | ----------- 3 | 4 | SmartusLine is Vim plugin that changes the color of the statusline of the 5 | focused window according with the current mode (normal/insert/replace) 6 | 7 | it looks like this: 8 | 9 | ![SmartusLineGif](https://github.com/molok/vim-smartusline/raw/master/img/smartusline.gif) 10 | 11 | by default it highlights the filename on your statusline only, you can change 12 | that: 13 | 14 | let g:smartusline_string_to_highlight = '(%n) %f ' 15 | 16 | this is what you see in the picture. 17 | 18 | You can also change the default colors of the highlight, the name are 19 | self-explanatory, the defaults are: 20 | 21 | let g:smartusline_hi_replace = 'guibg=#e454ba guifg=black ctermbg=magenta ctermfg=black' 22 | let g:smartusline_hi_insert = 'guibg=orange guifg=black ctermbg=58 ctermfg=black' 23 | let g:smartusline_hi_virtual_replace = 'guibg=#e454ba guifg=black ctermbg=magenta ctermfg=black' 24 | let g:smartusline_hi_normal = 'guibg=#95e454 guifg=black ctermbg=lightgreen ctermfg=black' 25 | 26 | note: you probably want to set the statusline to never hide, like this: 27 | 28 | set laststatus=2 29 | 30 | other requirements are: 31 | 32 | set nocompatible 33 | syntax on 34 | 35 | also the statusline option can't be empty, if you want to use the 36 | default statusline you should set it explicitly in your vimrc, it should be 37 | something like this: 38 | 39 | set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P 40 | 41 | 42 | For a more complete documentation, read the help file (:help smartusline) 43 | 44 | Enjoy! 45 | 46 | 47 | -------------------------------------------------------------------------------- /doc/smartusline.txt: -------------------------------------------------------------------------------- 1 | *smartusline.txt* For Vim version 7.0 Last change: 2012 January 8 2 | 3 | Author: Alessio Bolognino 4 | Version: 0.3 5 | 6 | Homepage: https://github.com/molok/vim-smartusline 7 | 8 | 9 | ============================================================================== 10 | 1. Contents *smartusline* 11 | 12 | 1. Contents...................: |smartusline-contents| 13 | 2. Description................: |smartusline-description| 14 | 3. Configuration..............: |smartusline-configure| 15 | 3. Requirements...............: |smartusline-requirements| 16 | 17 | ============================================================================== 18 | 2. Description *smartusline-description* 19 | 20 | SmartusLine is Vim plugin that changes the color of the statusline of the 21 | focused window according with the current mode (normal/insert/replace) 22 | 23 | You can configure what part of the 'statusline' will be highlighted 24 | 25 | ============================================================================== 26 | 3. Configuration *smartusline-configure* 27 | 28 | SmartusLine allows the user to choose what part of the statusline will be 29 | highlighted 30 | 31 | These are the supported global variables that you can customize in your |.vimrc| 32 | > 33 | smartusline_string_to_highlight 34 | < Default: '%f' 35 | Defines which part of the statusline will be highlighted, by default 36 | it highlightes the filename ('%f'), it uses the same syntax used by 37 | 'statusline' 38 | > 39 | smartusline_deep_eval 40 | < Default: 0 41 | If this variable is set to 0 and your statusline starts with "%!" 42 | then only that expression is evaluated before searching for a match 43 | of smartusline_string_to_highlight. 44 | If this variable is set to 1, all the "%{}" expressions returned 45 | by the %! statusline function are evaluated before looking for a 46 | match. 47 | 48 | For example, suppose you have: 49 | > 50 | :fun! MyFilename() 51 | : return 'filename: %f' 52 | :endfun 53 | 54 | :fun! MyStatusLine() 55 | : return '(%n) %{MyFilename()}' 56 | :endfun 57 | 58 | :set statusline=%!MyStatusLine() 59 | < 60 | To highlight 'filename: %f' 61 | 62 | with smartusline_deep_eval = 0 63 | you can set 64 | smartusline_string_to_highlight = '%{MyFilename()}' 65 | 66 | with smartusline_deep_eval = 1 67 | you can set 68 | smartusline_string_to_highlight = 'filename: %f' 69 | 70 | 71 | The currently supported mode are |Normal-mode|, |Insert-mode|, |Replace-mode| 72 | and |Virtual-Replace-mode|: 73 | > 74 | smartusline_hi_normal 75 | < Default: 'guibg=#95e454 guifg=black ctermbg=lightgreen ctermfg=black' 76 | This variable sets the 'highlight' for the |Normal-mode| 77 | > 78 | smartusline_hi_insert 79 | < Default:'guibg=orange guifg=black ctermbg=58 ctermfg=black' 80 | This variable sets the 'highlight' for the |Insert-mode| 81 | > 82 | smartusline_hi_replace 83 | < Default: 'guibg=#e454ba guifg=black ctermbg=magenta ctermfg=black' 84 | This variable sets the 'highlight' for the |Replace-mode| 85 | > 86 | smartusline_hi_virtual_replace 87 | < Default: 'guibg=#e454ba guifg=black ctermbg=magenta ctermfg=black' 88 | This variable sets the 'highlight' for the |Virtual-Replace-mode| 89 | 90 | ============================================================================== 91 | 4. Requirements *smartusline-requirements* 92 | 93 | Note: you cant have an empty 'statusline', even if you want to use the 94 | default one, you have to set it explicitly in your |vimrc|, e.g.: 95 | > 96 | set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P 97 | 98 | Like most plugins, SmartusLine requires a couple of options set: 99 | > 100 | set nocompatible 101 | syntax on 102 | < 103 | When using SmartusLine you probably want to set your statusline to never hide, 104 | you can do it with 105 | > 106 | set laststatus=2 107 | < 108 | 109 | vim: ts=4 ft=help tw=78 110 | -------------------------------------------------------------------------------- /img/smartusline.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molok/vim-smartusline/a1c1f56b6e1579bfda1a4abb60a965833db3899b/img/smartusline.gif -------------------------------------------------------------------------------- /plugin/smartusline.vim: -------------------------------------------------------------------------------- 1 | " smartusline.vim 2 | " --------------------------------------------------------------- 3 | " Version: 0.3 4 | " Authors: Alessio 'molok' Bolognino 5 | " Last Modified: 2012-01-20 6 | " License: GPL (Gnu Public License) 7 | " ------------------------------------------------------------------------------ 8 | " Known reproducible bug: 9 | " :e foobar 10 | " :help help 11 | " :NERDTreeToggle 12 | " :NERDTreeToggle 13 | " triggers WinEnter in foobar instead of change, could be a NERDTreeBug 14 | 15 | if exists('g:loaded_smartusline') || &cp 16 | finish 17 | endif 18 | 19 | if &stl == "" 20 | echoerr "SmartusLine: statusline can't be empty" 21 | finish 22 | endif 23 | 24 | let g:loaded_smartusline = 0.3 25 | let s:keepcpo = &cpo 26 | set cpo&vim 27 | 28 | let s:def_cterm_replace = '' 29 | let s:def_cterm_normal = '' 30 | let s:def_cterm_insert = '' 31 | 32 | if (&t_Co > 0) 33 | if (&t_Co <= 16) 34 | let s:def_cterm_replace = 'ctermfg=black ctermbg=13' 35 | let s:def_cterm_normal = 'ctermfg=black ctermbg=10' 36 | let s:def_cterm_insert = 'ctermfg=white ctermbg=9' 37 | elseif (&t_Co <= 88) 38 | let s:def_cterm_replace = 'ctermfg=black ctermbg=13' 39 | let s:def_cterm_normal = 'ctermfg=black ctermbg=82' 40 | let s:def_cterm_insert = 'ctermfg=white ctermbg=9' 41 | elseif (&t_Co <= 256) 42 | let s:def_cterm_replace = 'ctermfg=black ctermbg=169' 43 | let s:def_cterm_normal = 'ctermfg=black ctermbg=113' 44 | let s:def_cterm_insert = 'ctermfg=black ctermbg=214' 45 | endif 46 | endif 47 | 48 | if !exists('g:smartusline_hi_replace') 49 | let g:smartusline_hi_replace = 'guibg=#e454ba guifg=black ' . s:def_cterm_replace 50 | endif 51 | 52 | if !exists('g:smartusline_hi_insert') 53 | let g:smartusline_hi_insert = 'guibg=orange guifg=black ' . s:def_cterm_insert 54 | endif 55 | 56 | if !exists('g:smartusline_hi_virtual_replace') 57 | let g:smartusline_hi_virtual_replace = 'guibg=#e454ba guifg=black ' . s:def_cterm_replace 58 | endif 59 | 60 | if !exists('g:smartusline_hi_normal') 61 | let g:smartusline_hi_normal = 'guibg=#95e454 guifg=black ' . s:def_cterm_normal 62 | endif 63 | 64 | if !exists('g:smartusline_deep_eval') 65 | let g:smartusline_deep_eval = 0 66 | endif 67 | 68 | execute 'hi StatColor ' . g:smartusline_hi_normal 69 | 70 | if !exists('g:smartusline_string_to_highlight') 71 | let g:smartusline_string_to_highlight = '%f' 72 | endif 73 | 74 | let s:open_hi = '%#StatColor#' 75 | let s:close_hi = '%*' 76 | 77 | function! SmartusLineWin(mode) 78 | 79 | let curr_stl = &stl 80 | let new_stl = "" 81 | 82 | let curr_stl = s:EvalSTL(curr_stl, g:smartusline_deep_eval) 83 | 84 | let string_to_match = substitute(g:smartusline_string_to_highlight,'\\','\\\\','g') 85 | let start_idx = match(curr_stl, '\V'. string_to_match) 86 | let end_idx = start_idx + len(g:smartusline_string_to_highlight) 87 | 88 | if start_idx >= 0 89 | if a:mode == 'Enter' 90 | if match(curr_stl, s:open_hi) < 0 91 | if start_idx > 0 92 | let new_stl .= curr_stl[0 : start_idx -1] 93 | endif 94 | let new_stl .= s:open_hi 95 | let new_stl .= curr_stl[start_idx : end_idx -1] . s:close_hi 96 | let new_stl .= curr_stl[end_idx : ] 97 | endif 98 | elseif a:mode == 'Leave' 99 | if match(curr_stl, s:open_hi) >= 0 100 | let new_stl .= curr_stl[0 : end_idx -1] 101 | let new_stl .= curr_stl[end_idx +len(s:close_hi) :] 102 | let new_stl = substitute(new_stl, s:open_hi, '', 'g') 103 | endif 104 | endif 105 | endif 106 | 107 | if new_stl != "" 108 | let &l:stl = new_stl 109 | endif 110 | 111 | endfunction 112 | 113 | function! SmartusLineInsert(mode) 114 | if a:mode == 'Enter' 115 | if v:insertmode == 'i' 116 | execute 'hi StatColor ' . g:smartusline_hi_insert 117 | elseif v:insertmode == 'r' 118 | execute 'hi StatColor ' . g:smartusline_hi_replace 119 | elseif v:insertmode == 'v' 120 | execute 'hi StatColor ' . g:smartusline_hi_virtual_replace 121 | endif 122 | elseif a:mode == 'Leave' 123 | execute 'hi StatColor ' g:smartusline_hi_normal 124 | endif 125 | endfunction 126 | 127 | augroup SmartusLine 128 | au WinLeave * call SmartusLineWin('Leave') 129 | au WinEnter,BufEnter,VimEnter * call SmartusLineWin('Enter') 130 | 131 | au InsertLeave * call SmartusLineInsert('Leave') 132 | au InsertEnter * call SmartusLineInsert('Enter') 133 | au InsertChange * call SmartusLineInsert('Enter') 134 | 135 | " this shouldn't be needed, but it is 136 | au GUIEnter * execute 'hi StatColor ' g:smartusline_hi_normal 137 | augroup END 138 | 139 | fun! s:EvalSTL(stl_to_eval, deep_eval) 140 | if match(a:stl_to_eval, '^%!') >= 0 141 | let str = eval(a:stl_to_eval[2:-1]) 142 | else 143 | let str = a:stl_to_eval 144 | endif 145 | if a:deep_eval == 0 146 | return str 147 | endif 148 | let prev_out = '0' 149 | let out = '1' 150 | 151 | " if out == prev_out then I don't have anything else to evaluate 152 | while out != prev_out 153 | let in_quote = 0 154 | let in_dquote = 0 155 | let in_fun = 0 156 | let prev_was_perc = 0 157 | let start_fun = -1 158 | 159 | let out = '' 160 | let i = 0 161 | 162 | while i < len(str) 163 | if str[i] == "'" && !in_dquote 164 | let in_quote = !in_quote 165 | endif 166 | 167 | if str[i] == '"' && !in_quote 168 | let in_dquote = !in_dquote 169 | endif 170 | 171 | if prev_was_perc == 1 172 | if str[i] == '{' && !in_quote && !in_dquote 173 | let in_fun = 1 174 | let start_fun = i+1 175 | else 176 | if !in_fun 177 | let out .= '%' 178 | endif 179 | endif 180 | let prev_was_perc = 0 181 | endif 182 | 183 | if str[i] == '}' && in_fun && !in_quote && !in_dquote 184 | let in_fun = 0 185 | let fun_to_eval = str[start_fun : i-1] 186 | let out .= eval(fun_to_eval) 187 | elseif str[i] != '%' 188 | if !in_fun 189 | let out .= str[i] 190 | endif 191 | else 192 | let prev_was_perc = 1 193 | endif 194 | let i = i+1 195 | endwhile 196 | let prev_out = out 197 | endwhile 198 | 199 | return out 200 | 201 | endfunction 202 | --------------------------------------------------------------------------------