I need a simple (or complex) way to figure out what mode the user is in. I need to know if the user is in Normal, Insert, Visual, Replace, Change etc.
I am aware of the mode()
function, however I can't figure out how to make it output a full string instead of just one character.
My plan was to make a function which would dynamically change the statusline's background and foreground colors depending on what string mode()
returns. Basically a function with a bunch of ifs and elseifs which would do it for me. There is a flaw with this approach though, I can't know which color the theme setup by default for that.
So basically, I need some tips/help on how to make a function that does the following:
- Knows which mode the user is in. The rest of the functions react differently every time this changes.
- Sets some variables with
fg
andbg
values which reflect what the current theme has set for them. - Changes the statusline's foreground and background depending on these values.
I tried doing it, but it was a very crude way of doing it and it didn't work at all. It only set the colors once and after that it didn't react every time it changed.
Thanks for your help! :)
EDIT:
Pretty sure what I tried before that didn't work was this:
function! StatuslineModeColor()
let s:StatuslineMode=mode()
if s:StatuslineMode == 'n'
hi Statusline ctermbg=blue guibg=blue
elseif s:StatuslineMode == 'i'
hi Statusline ctermbg=red guibg=red
endif
endfunc
And in the statusline I put the following:
let &stl.='%{StatuslineModeColor()}'
EDIT 2:
I've figured out that basically what I need to do is find a way to grab whatever colors the theme was using before. That's if I use this solution: http://www.reddit.com/r/vim/comments/gexi6/a_smarter_statusline_code_in_comments/c1n2oo5
However this solution is not ideal in my standards, because it's not clean, or as clean as it could be since it makes up a lot of clutter. :/
mode()
to output a full string? 2. What is script-local variable doing in your function? It ought to be local one (l:
or nothing in place ofs:
). – Towbinl:
,s:
,a:
andg:
. :) – Psalm:h internal-variables
. For the first one: you can always use dictionary and/or bigif … elseif … elseif … endif
thing, like this. – TowbinFileInfo()
outputs a zero, probably easy reason though. Mind if we start a chat for this? – Psalm:h line-continuation
, it is not that good as in most languages, but it is there. About changing the color: the only thing I know is that the solution can be found somewhere at:h 'statusline'
(AFAIR some special atom, not that mess with changing properties ofStatusLine
group, though the latter should work). And that practical solution is buried somewhere inside powerline code (BTW why not use it, it changes color?). I did not ever touch that part of powerline, neither old nor new. – Towbin/master/
in URL and line URL fragments at the same time, it tends to change over time. Use/{sha hash}/
instead. – Towbin