title: Using external commands in vim map-operator function
body: <p>I'd like to create a vim mapping that allows for motions to control what text to output. There doesn't seem to be a whole lot of documentation on this and I'm having trouble adapting <a href="http://vimdoc.sourceforge.net/htmldoc/map.html#%3amap-operator" rel="nofollow">the sample in vim's help page</a> to what I need. Here's what I have, which gives no errors but does not replace the text. What am I missing?</p>
  
  <pre><code>nmap ,s :set opfunc=CustomFunc&lt;cr&gt;g@
  
  function! CustomFunc(type, ...)
      let sel_save = &amp;selection
      let &amp;selection = "inclusive"
      let reg_save = @@
  
      if a:type == 'line'
          silent exe "normal! '[V']!sort"
      elseif a:type == 'block'
          silent exe "normal! `[\&lt;C-V&gt;`]!sort"
      else
          silent exe "normal! `[v`]!sort"
      endif
  
      let &amp;selection = sel_save
      let @@ = reg_save
  endfunction
  </code></pre>
  
  <p>I used <code>!sort</code> as a very simple example for testing. The idea here is you could have a block like:</p>
  
  <pre><code>{
      Hello, World!
      Hello, Earth!
      Hello, Planet!
  }
  </code></pre>
  
  <p>If you were to then move the cursor somewhere in the {} block and type <code>,si{</code> it would replace the block with</p>
  
  <pre><code>{
      Hello, Earth!
      Hello, Planet!
      Hello, World!
  }
  </code></pre>
  
  <p>The workaround would be <code>vi{:!sort&lt;cr&gt;</code>, or if you have <code>vmap ,s :!sort</code> then <code>vi{,s</code>, but it would be nice to have this as an operator mapping (less typing, more flexible, etc).</p>