title: Insert vim variables into text for comment shortcut
body: <p>I have a simple goal: Map Ctrl-C, a command I don't think I've ever used to kill vim, to automatically insert at the beginning of a line the correct character(s) to comment out that line according to the file's filetype.</p>
  
  <p>I figured I could use an autocommand the recognize the file type and set a vim variable to the correct comment character when the file is open. So I tried something like:</p>
  
  <pre><code>" Control C, which is NEVER used. Now comments out lines!
  autocmd BufNewFile,BufRead *.c let CommentChar = "//"
  autocmd BufNewFile,BufRead *.py let CommentChar = "#"
  map &lt;C-C&gt; mwI:echo &amp;CommentChar&lt;Esc&gt;`wll
  </code></pre>
  
  <p>That map marks my current location, goes to the beginning of the line in insert mode, <em>echoes the Comment Character(s) at that point</em>, enters command mode, goes back to the set mark, and goes two characters right to make up for the inserted comment characters (assuming C style comment).</p>
  
  <p>The italicized portion is the part I'm having trouble with; it is only there as a place holder to represent what I want to do. Can you help me figure out how to achieve this? Bonus points if you use strlen(CommentChar) to step the correct number of spaces to the right! Extra bonus points for the vim-master that includes how to do block-style comments if you are in visual mode!!</p>
  
  <p>I'm still fairly new at vim scripting; my .vimrc is a measly 98 lines long, so if you could please help me by explaining any answers you provide! Thanks.</p>