title: Javascript indentation in VIM
body: <p>I'm trying to get VIM to indent Javascript with the '=' and related commands. When I try to auto indent the following, for example:</p>
  
  <pre><code>   new function($) {
       $.fn.setCursorPosition = function(pos) { 
         if ($(this).setSelectionRange) {
           $(this).setSelectionRange(pos, pos);
         } else if ($(this).createTextRange) {
           var range = $(this).createTextRange();
           range.collapse(true);
           range.moveEnd('character', pos);
           range.moveStart('character', pos);
           range.select();
         }
  </code></pre>
  
  <p>The result is the rather absurd:</p>
  
  <pre><code>       new function($) {
         $.fn.setCursorPosition = function(pos) {
         if ($(this).setSelectionRange) {
         $(this).setSelectionRange(pos, pos);
         } else if ($(this).createTextRange) {
         var range = $(this).createTextRange();
         range.collapse(true);
         range.moveEnd('character', pos);
         range.moveStart('character', pos);
         range.select();
         }
  </code></pre>
  
  <p>I've set <code>set syntax=javascript</code>, and I've set <code>filetype</code> to:</p>
  
  <pre><code>filetype detection:ON  plugin:ON  indent:ON
  </code></pre>
  
  <p>Though I've tried every permutation of this. I've tried every permutation of <code>smartindent</code>, <code>autoindent</code>, and <code>cindent</code>, but nothing seems to have the correct effect of giving Vim the expected indentation. I've set <code>tabstop=4</code>. </p>
  
  <p>I've installed <a href="http://www.vim.org/scripts/script.php?script_id=1840" rel="noreferrer"><code>javascript.vim</code></a>, and <a href="http://www.vim.org/scripts/script.php?script_id=1839" rel="noreferrer"><code>IndentAnything</code></a>, though they don't seem to have any effect.</p>
  
  <p>I'd be very grateful for any suggestions as to how to get Vim indenting properly in JavaScript.</p>