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

Re: put html tags around selected text

Expand Messages
  • Vitor Eiji Justus Sakaguti
    ... Take a look into this one http://www.vim.org/scripts/script.php?script_id=1697 -- You received this message from the vim_use maillist. Do not top-post!
    Message 1 of 9 , Mar 1, 2010
    • 0 Attachment
      On Mon, Mar 1, 2010 at 3:31 PM, rameo <raiwil@...> wrote:
      > I'm searching for a script to:
      >
      > select a text and put a html tag around

      Take a look into this one
      http://www.vim.org/scripts/script.php?script_id=1697

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • rameo
      Hi Kai, Thank you. Yes that is what I searched :-) This is my output: test -- I would like to remove the 2nd and keep a 1 character space before the
      Message 2 of 9 , Mar 1, 2010
      • 0 Attachment
        Hi Kai,

        Thank you.
        Yes that is what I searched :-)

        This is my output:
        <!-->test -->

        I would like to remove the 2nd ">" and keep a 1 character space before
        the text.

        Tried everything but I believe I haven't understand very well what you
        are doing here.
        what is 41a + a ?


        On Mar 1, 8:03 pm, vi...@... wrote:
        > Hej,
        >
        > vmap ,C :call Blub()<CR>
        > --------------------------------------
        >
        > Select the part of the text you want to apply this function to, and hit
        > ,C in normal mode.
        >
        >

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • vimml@selgrad.org
        Hej :) ... I ll try to explain... ... 1 function! Blub() range 2 exec normal ` start of the comment 3 if a:firstline ==
        Message 3 of 9 , Mar 1, 2010
        • 0 Attachment
          Hej :)

          > Tried everything but I believe I haven't understand very well what you
          > are doing here.
          > what is 41a + a ?
          I'll try to explain...

          --------------------------------------
          1 function! Blub() range
          2 exec "normal `<i<!--\<esc>" " start of the comment
          3 if a:firstline == a:lastline
          4 exec "normal `>4la-->" " end
          5 else
          6 exec "normal `>a-->" " end
          7 endif
          8 endfunction
          9
          10 vmap ,C :call Blub()<CR>
          --------------------------------------

          After you have selected something in visual mode the normal mode command
          `< moves you to the start of your selection, and `> to the end of it.
          See :help `<

          Line 2 first jumps to the start of the selection, (`<) enters insert
          mode (i) and inserts "<!--". The explicit use of \<esc> is necessary to
          get out of insert mode (or so I think).
          The conditional is used because if the end of the selection is on the
          same line as is the start of the selection then the last character you
          selected will be 4 steps to the right of the original selection, because
          the string "<!--" has been inserted before. As you can see, the only
          difference of the commands in the body of the if/else is the 4l, which
          moves the cursor 4 steps to the right.
          The a is for append which inserts "-->" after the cursor position (which
          in this case is after the originally selected character), and somehow
          doesn't need "\<esc>" at the end. Maybe this isn't necessary in line 2
          either. I'm no vimscript expert ;)

          So as you can see, this is just a hack. If you want to use it for more
          than just one case -- luckily I don't have to edit much html/xml, so I
          did not care ;) -- it would be best to get rid of that hardcoded four,
          see :help functions and choose wisely :)

          > This is my output:
          > <!-->test -->
          That looks strange. Are you sure you got the quotes/accents right?

          I transform
          ^test$
          (where ^ is start-of-line and $ is end-of-line)
          to
          ^<!--test-->$

          Or when selecting both lines
          ^test$
          ^blub$
          ^<!--test$
          ^blub-->$

          Hope this was helpful :)
          Kai

          --
          All mail clients suck. This one just sucks less.

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • caruso_g
          ... Use surround plugin, it s practically perfect. While for comments there is the excellent NERDCommenter:
          Message 4 of 9 , Mar 1, 2010
          • 0 Attachment
            On 1 Mar, 23:47, vi...@... wrote:
            > Hej :)
            >
            > > Tried everything but I believe I haven't understand very well what you
            > > are doing here.
            > > what is 41a + a ?
            >
            > I'll try to explain...
            >
            > --------------------------------------
            > 1       function! Blub() range
            > 2               exec "normal `<i<!--\<esc>"             " start of the comment
            > 3               if a:firstline == a:lashttp://www.vim.org/scripts/script.php?script_id=1218tline
            > 4                       exec "normal `>4la-->"                          " end
            > 5               else
            > 6                       exec "normal `>a-->"                            " end
            > 7               endif
            > 8       endfunction
            > 9      
            > 10      vmap ,C :call Blub()<CR>
            > --------------------------------------
            >
            > After you have selected something in visual mode the normal mode command
            > `< moves you to the start of your selection, and `> to the end of it.
            > See :help `<
            >
            > Line 2 first jumps to the start of the selection, (`<) enters insert
            > mode (i) and inserts "<!--". The explicit use of \<esc> is necessary to
            > get out of insert mode (or so I think).
            > The conditional is used because if the end of the selection is on the
            > same line as is the start of the selection then the last character you
            > selected will be 4 steps to the right of the original selection, because
            > the string "<!--" has been inserted before. As you can see, the only
            > difference of the commands in the body of the if/else is the 4l, which
            > moves the cursor 4 steps to the right.
            > The a is for append which inserts "-->" after the cursor position (which
            > in this case is after the originally selected character), and somehow
            > doesn't need "\<esc>" at the end. Maybe this isn't necessary in line 2
            > either. I'm no vimscript expert ;)
            >
            > So as you can see, this is just a hack. If you want to use it for more
            > than just one case -- luckily I don't have to edit much html/xml, so I
            > did not care ;) -- it would be best to get rid of that hardcoded four,
            > see :help functions and choose wisely :)
            >
            > > This is my output:
            > > <!-->test -->
            >
            > That looks strange. Are you sure you got the quotes/accents right?
            >
            > I transform
            > ^test$
            > (where ^ is start-of-line and $ is end-of-line)
            > to
            > ^<!--test-->$
            >
            > Or when selecting both lines
            > ^test$
            > ^blub$
            > ^<!--test$
            > ^blub-->$
            >
            > Hope this was helpful :)
            >         Kai
            >
            > --
            > All mail clients suck. This one just sucks less.

            Use surround plugin, it's practically perfect. While for comments
            there is the excellent NERDCommenter: http://www.vim.org/scripts/script.php?script_id=1218

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • rameo
            Kai, Thank you very much for your reply! I don t know why but whatever I try I always have the after
            Message 5 of 9 , Mar 2, 2010
            • 0 Attachment
              Kai,

              Thank you very much for your reply!

              I don't know why but whatever I try I always have the ">" after <!--

              I went on searching on the net and with the code I found I created
              this:
              :vmap ,C "zdi<!-- <C-R>z --><ESC>

              this works for one and multiline.

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Vitor Eiji Justus Sakaguti
              Hey Kai! ... The following works fine for me. ... function! Blub() range echo hallo exec normal ` a-- exec normal `
              Message 6 of 9 , Mar 2, 2010
              • 0 Attachment
                Hey Kai!

                On Mon, Mar 1, 2010 at 7:47 PM, <vimml@...> wrote:
                > Line 2 first jumps to the start of the selection, (`<) enters insert
                > mode (i) and inserts "<!--". The explicit use of \<esc> is necessary to
                > get out of insert mode (or so I think).
                > The conditional is used because if the end of the selection is on the
                > same line as is the start of the selection then the last character you
                > selected will be 4 steps to the right of the original selection, because
                > the string "<!--" has been inserted before. As you can see, the only
                > difference of the commands in the body of the if/else is the 4l, which
                > moves the cursor 4 steps to the right.
                > The a is for append which inserts "-->" after the cursor position (which
                > in this case is after the originally selected character), and somehow
                > doesn't need "\<esc>" at the end. Maybe this isn't necessary in line 2
                > either. I'm no vimscript expert ;)

                The following works fine for me.
                ---------------------------------------
                function! Blub() range
                echo "hallo"
                exec "normal `>a-->"
                exec "normal `<i<!--"
                endfunction
                ---------------------------------------

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • rameo
                Kai, I have found the reason why there was a behind the tag
                Message 7 of 9 , Mar 2, 2010
                • 0 Attachment
                  Kai,

                  I have found the reason why there was a ">" behind the tag <!--
                  I have the plugin autoclose and added autoclose of "<" character.

                  Thanks.
                  Rameo

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                Your message has been successfully submitted and would be delivered to recipients shortly.