News for hackers. Stuff that matters.
Re:Vim Plugins You Should Know About, Part I: surround.vim by thomasmallen on Monday December 08, 2008 @09:06AM (#389836)

  <!-- Ugh. Surround is OK, but sucks for wrapping in HTML tags. If I select the line: -->

  Hello!

  <!-- And use stp (surround selection with <p/>) I get: -->

  <p>
      Hello!
  </p>

  <!-- Instead of -->
  
  <p>Hello!</p>

  <!-- The workaround? ^v$ which is tedious. I recommend mapping this for those times when you want to wrap the current line quickly in XML tags. 

  function! TagWrapper()
      let a:tag = input("Tag: ")
      normal `>
      exe "normal a</" . a:tag . ">"
      normal `<
      exe "normal i<" . a:tag . ">"
  endfunction
  -->
Re:Vim Plugins You Should Know About, Part I: surround.vim by pkrumins on Monday December 08, 2008 @09:18AM (#389846)
This plugin does not define 'stp'. You must be using some other plugin that has this mapping.

The plugin I wrote about wraps HTML around perfectly. Try:

    ysiWt<p>
Or if you knew the tag you were going to wrap your "Hello!" in, then in insert mode you could have pressed:

    <CTRL+s>t<p>.
Re:Vim Plugins You Should Know About, Part I: surround.vim by thomasmallen on Monday December 08, 2008 @09:31AM (#389856)
No, the plugin does define stp.

  :help Surround
The pattern you have there ("ysiWtp", < is unnecessary, as is >) is actually not thoroughly tested (as mentioned in the docs) and is used when not in a visual selection. In a visual selection, you use "s" followed by what you want to surround with, e.g. s"
Re:Vim Plugins You Should Know About, Part I: surround.vim by pkrumins on Monday December 08, 2008 @09:40AM (#389864)
You must have a different surround.vim script. Perhaps someone else wrote a script and called "surround.vim" as well.

The one I am talking about does not define stp and requires < > between tags.

What does your 'stp' do?

Edit: I see what you did there. You were in visual mode!

Re:Vim Plugins You Should Know About, Part I: surround.vim by thomasmallen on Monday December 08, 2008 @09:50AM (#389872)
Of course. surround.vim couldn't get away with clobbering "s" in normal mode.
Re:Vim Plugins You Should Know About, Part I: surround.vim by pkrumins on Monday December 08, 2008 @09:54AM (#389877)
this works for me:

  viwstp>
turns

  foo
into

  <p>foo</p>
Edit: (30 mins later) Now I understood fully what was happening. ;)
Re:Vim Plugins You Should Know About, Part I: surround.vim by pmarin on Monday December 08, 2008 @02:53PM (#390278)
My favorite vim plugin is to not use any plugin: use the filter command "!", the unix way.
Re:Vim Plugins You Should Know About, Part I: surround.vim by newsycaccount on Monday December 08, 2008 @08:51PM (#390770)
more on "!":

Run the given cmd/pipeline, and put it's output at the current cursor location:

    :r ! <cmd>

Filter the whole buffer through the given cmd/pipeline:

    :%! <cmd>

Filter a visual selection through the given cmd/pipeline: make selection (with mouse if you have :set mouse=a or gvim, or with any of the variations on 'v'), then hit '!'

you will pop into a command line like this:

    :'<,'>! <cmd>

'< is the beginning of the visual selection, and '> is the end.
Re:Vim Plugins You Should Know About, Part I: surround.vim by orib on Tuesday December 09, 2008 @12:04AM (#390970)
Sure, but some things (eg, surround.vim) can't be emulated with that.
Re:Vim Plugins You Should Know About, Part I: surround.vim by pmarin on Wednesday December 10, 2008 @09:14AM (#392902)
give me an example of something that i can't filter in a sed/grep/ed/awk/perl script.
Re:Vim Plugins You Should Know About, Part I: surround.vim by kilowatt on Monday December 08, 2008 @10:21AM (#389909)
I just made a plugin recently for on the fly Python checking with squiggly underlines, like a "real" IDE: pyflakes.vim http://www.vim.org/scripts/script.php?script_id=2441

(Make sure you grab a Python 2.5/gvim--required ATM--build from the link on that page as well.)

Re:Vim Plugins You Should Know About, Part I: surround.vim by thamer on Monday December 08, 2008 @09:06AM (#389835)
I tried this plugin a few days ago, but it seemed to break the s (substitute) command, so I removed it. Does someone know how to make it work?

The problem is the following: Write a line of text, select part of it using v, then press s to remove the selection and enter insert mode to start replacing it. This doesn't work anymore when surround.vim is loaded. Too bad, it sure looks great…

Re:Vim Plugins You Should Know About, Part I: surround.vim by pkrumins on Monday December 08, 2008 @09:23AM (#389850)
Try 'R' instead of 's' that you were used to.

  OR
Edit surround.vim and comment out the 's' mappings in visual mode. Like this:

    "    if !hasmapto("<Plug>Vsurround","v")
    "        if exists(":xmap")
    "            xmap  s    <Plug>Vsurround
    "        else
    "            vmap  s    <Plug>Vsurround
    "        endif
    "    endif
    "    if !hasmapto("<Plug>VSurround","v")
    "        if exists(":xmap")
    "            xmap  S    <Plug>VSurround
    "        else
    "            vmap  S    <Plug>VSurround
    "        endif
    "    endif
Re:Vim Plugins You Should Know About, Part I: surround.vim by thamer on Monday December 08, 2008 @10:11AM (#389896)
'R' replaces the whole line, so that won't do. I commented the script as you suggested and it works. Thank you!
Re:Vim Plugins You Should Know About, Part I: surround.vim by sofal on Monday December 08, 2008 @10:13AM (#389900)
If I'm not mistaken, I believe that pressing c instead of s in that situation will do the exact same thing.
Re:Vim Plugins You Should Know About, Part I: surround.vim by tumult on Monday December 08, 2008 @08:43AM (#389822)
oh my god, thank you. i love you.
Re:Vim Plugins You Should Know About, Part I: surround.vim by tdavis on Monday December 08, 2008 @10:03AM (#389886)
I've been looking for a plugin that does precisely this. Thank you Peteris, you've got another subscriber ;)
Re:Vim Plugins You Should Know About, Part I: surround.vim by pkrumins on Monday December 08, 2008 @10:12AM (#389898)
Thank you! :)