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. :/