title: Vim: How to detect the mode in which the user is in, for statusline?
body: <p>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.</p>
  
  <p>I am aware of the <code>mode()</code> function, however I can't figure out how to make it output a full string instead of just one character.</p>
  
  <p>My plan was to make a function which would dynamically change the statusline's background and foreground colors depending on what string <code>mode()</code> 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.</p>
  
  <p>So basically, I need some tips/help on how to make a function that does the following:</p>
  
  <ul>
  <li>Knows which mode the user is in. The rest of the functions react differently every time this changes.</li>
  <li>Sets some variables with <code>fg</code> and <code>bg</code> values which reflect what the current theme has set for them.</li>
  <li>Changes the statusline's foreground and background depending on these values.</li>
  </ul>
  
  <p>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.</p>
  
  <p>Thanks for your help! :)</p>
  
  <p>EDIT:</p>
  
  <p>Pretty sure what I tried before that didn't work was this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And in the statusline I put the following:</p>
  
  <pre><code>let &amp;stl.='%{StatuslineModeColor()}'
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>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: <a href="http://www.reddit.com/r/vim/comments/gexi6/a_smarter_statusline_code_in_comments/c1n2oo5" rel="nofollow">http://www.reddit.com/r/vim/comments/gexi6/a_smarter_statusline_code_in_comments/c1n2oo5</a></p>
  
  <p>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. :/</p>