Loading ...
Sorry, an error occurred while loading the content.

Wrapping a selection in tags

Expand Messages
  • Rory Campbell-Lange
    I d like to: 1. Select some text 2. Hit a key sequence such as ;t 3. Be prompted for a tag (I ll input something like b or h1 ) 4. The text selection will
    Message 1 of 4 , Dec 31, 2006
    • 0 Attachment
      I'd like to:

      1. Select some text
      2. Hit a key sequence such as ;t
      3. Be prompted for a tag (I'll input something like 'b' or 'h1')
      4. The text selection will be wrapped in -- say --
      <b>text selection</b>

      What doesn't work so far:

      map ;t <ESC>:call Tag_Maker()<CR>
      function! Tag_Maker()
      let l:tagger = input("tag? ")
      normal @zd
      execute "normal i<" . l:tagger . ">"
      normal @zp
      execute "normal a</" . l:tagger . ">"
      endfunction

      Basically I don't know what I'm doing with the execute and normal
      commands. I'm sorry to say that a read of usr_41 hasn't helped much!

      Rory
      --
      Rory Campbell-Lange
      <rory@...>
      <www.campbell-lange.net>
    • Suresh Govindachar
      ... I assume step 1 is a visual selection. What you might not know: Whenever something is selected in visual mode, vim automatically marks the two end points
      Message 2 of 4 , Dec 31, 2006
      • 0 Attachment
        Rory Campbell-Lange wrote:

        > I'd like to:
        >
        > 1. Select some text
        > 2. Hit a key sequence such as ;t
        > 3. Be prompted for a tag (I'll input something like 'b' or 'h1')
        > 4. The text selection will be wrapped in -- say --
        > <b>text selection</b>
        >
        > What doesn't work so far:

        I assume step 1 is a visual selection.

        What you might not know:

        Whenever something is selected in visual mode, vim automatically
        marks the two end points of the selection with the marks < and >.
        You can jump to these locations by normal mode commands `< and `>.

        > map ;t <ESC>:call Tag_Maker()<CR>
        > function! Tag_Maker()
        > let l:tagger = input("tag? ")
        > normal @zd

        Don't know why you have the preceding; what is needed is a jump
        to the "start" of the visual selection with

        normal `<

        > execute "normal i<" . l:tagger . ">"
        > normal @zp

        Don't know why you have the preceding; what is needed is a jump
        to the "end" of the visual selection with

        normal `>

        > execute "normal a</" . l:tagger . ">"
        > endfunction
        >
        > Basically I don't know what I'm doing with the execute and
        > normal commands. I'm sorry to say that a read of usr_41 hasn't
        > helped much!

        It helps to first do the operations manually -- the code is then
        just a record of what was done manually.

        --Suresh
      • A.J.Mechelynck
        ... It might work (untested) with zd and zp instead of @zd and @zp Or just d and p if you don t mind clobbering the default register (the above clobbers
        Message 3 of 4 , Dec 31, 2006
        • 0 Attachment
          Rory Campbell-Lange wrote:
          > I'd like to:
          >
          > 1. Select some text
          > 2. Hit a key sequence such as ;t
          > 3. Be prompted for a tag (I'll input something like 'b' or 'h1')
          > 4. The text selection will be wrapped in -- say --
          > <b>text selection</b>
          >
          > What doesn't work so far:
          >
          > map ;t <ESC>:call Tag_Maker()<CR>
          > function! Tag_Maker()
          > let l:tagger = input("tag? ")
          > normal @zd
          > execute "normal i<" . l:tagger . ">"
          > normal @zp
          > execute "normal a</" . l:tagger . ">"
          > endfunction
          >
          > Basically I don't know what I'm doing with the execute and normal
          > commands. I'm sorry to say that a read of usr_41 hasn't helped much!
          >
          > Rory

          It might work (untested) with "zd and "zp instead of @zd and @zp

          Or just d and p if you don't mind clobbering the default register (the above
          clobbers register z instead).


          Best regards,
          Tony.
        • David Fishburn
          ... I created a tip for this: Tip #346: Wrap text in HTML/XML tags after prompting for the tag name http://www.vim.org/tips/tip.php?tip_id=346 With some
          Message 4 of 4 , Dec 31, 2006
          • 0 Attachment
            > I'd like to:
            >
            > 1. Select some text
            > 2. Hit a key sequence such as ;t
            > 3. Be prompted for a tag (I'll input something like 'b' or 'h1')
            > 4. The text selection will be wrapped in -- say --
            > <b>text selection</b>

            I created a tip for this:
            Tip #346: Wrap text in HTML/XML tags after prompting for the tag name
            http://www.vim.org/tips/tip.php?tip_id=346


            With some refinements at the bottom (plus a pile of SPAM!!).

            HTH,
            Dave
          Your message has been successfully submitted and would be delivered to recipients shortly.