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

Pls help with writing this plugin

Expand Messages
  • googler
    Hi all, I m trying to write a vim script (plugin) that will do the following. When I visually select a part of the text and press the key F2, it will highlight
    Message 1 of 3 , Aug 2, 2009
    • 0 Attachment
      Hi all,

      I'm trying to write a vim script (plugin) that will do the following.
      When I visually select a part of the text and press the key F2, it
      will highlight this text. Now I may go to other parts of the file and
      highlight other sections using the same mechanism. After a while I
      return to my previously highlighted section and with the cursor on it,
      I press F2 again. This will remove the highlight from this section.

      I have been trying to code this up but haven't been successful so far.
      I don't have any experience with vim scripting before. This is what
      I'm trying to do. I select the part visually. So the marks '< and '>
      will have information on start and end of the selected text. Now I
      call getpos() on each of these marks to get their line number and
      column number and store these in variables (so that they can be used
      when I want to remove highlighting). In order to highlight the text
      from (line=10,col=7) to (line=24,col=33), I do :match ErrorMsg /\%10l\
      %7c\_.*\%24l\%33c . But in this case, my line and column numbers are
      stored in variables. So how do I use these in the match command? Is
      there a way?

      A related question is, is it possible to create marks not by going to
      a certain position and doing a ma (for example), but just by
      specifying the line and column numbers? Also, is it possible to copy a
      mark a to another mark b?

      Thanks.

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • John Beckett
      ... The following is NOT what you asked for, but it is similar: http://vim.wikia.com/wiki/Highlight_multiple_words The tip matches all occurrences of a
      Message 2 of 3 , Aug 2, 2009
      • 0 Attachment
        googler wrote:
        > I'm trying to write a vim script (plugin) that will do the following.
        > When I visually select a part of the text and press the key
        > F2, it will highlight this text.

        The following is NOT what you asked for, but it is similar:
        http://vim.wikia.com/wiki/Highlight_multiple_words

        The tip matches all occurrences of a pattern, whereas you want
        to match the text between two positions.

        > But in this case, my line and column numbers are stored in
        > variables. So how do I use these in the match command? Is
        > there a way?

        See ":help :execute" and you might find some clues in some of
        the tips, but I don't think any highlight between two positions.

        > A related question is, is it possible to create marks not by
        > going to a certain position and doing a ma (for example), but
        > just by specifying the line and column numbers?

        It's useful to try ":help function-list" and search for likely
        terms. It looks like setpos() might help.

        John


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • googler
        ... Thank you. This is what I needed. The execute command seems to be pretty common as I found it in many other scripts too. It will be helpful in the future.
        Message 3 of 3 , Aug 2, 2009
        • 0 Attachment
          > > But in this case, my line and column numbers are stored in
          > > variables. So how do I use these in the match command? Is
          > > there a way?
          >
          > See ":help :execute" and you might find some clues in some  of
          > the tips, but I don't think any highlight between two positions.
          >
          Thank you. This is what I needed. The execute command seems to be
          pretty common as I found it in many other scripts too. It will be
          helpful in the future.
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.