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

Re: matching g0 and g$

Expand Messages
  • Tim Chase
    ... Depending on how your wrapping is configured, you may have a modestly easy job, or a more difficult job. Because those positions are actually within the
    Message 1 of 4 , Sep 2, 2004
      > Is there a way to match the portion of the current wrapped line at the
      > cursor between the edges of the window? I have a routine to highlight

      Depending on how your wrapping is configured, you may have a
      modestly easy job, or a more difficult job. Because those
      positions are actually within the line, you'll likely have to use
      the %123c atom to hit those actual columns. It's nothing as
      pleasant as having a "real" atom for it. If your wrapping just
      wraps at the given column (such as in the middle of words), then
      you should be able to just use a fixed atom (or collection of
      atoms something like

      \(%70c\|%140c\|%210c\)

      If, however, your wrapping is configured to wrap at word
      boundaries, you'll likely have to use something like the above in
      conjunction with a search for the "word" that the above happens
      to bisect. Something akin, perhaps to

      \w*\(%70c\|%140c\|%210c\).

      I'm sure there are some odd edge cases that this doesn't properly
      deal with, but it's just my first thoughts on the matter. I
      haven't encountered any native atom like you detail, so I guess
      either wait for Bram to add such a creature, or roll your own :)

      HTH,

      -tim
    • Antony Scriven
      ... I ve not entirely followed the thread, but if you are after the number of the leftmost column of the current screen line then virtcol( . ) - wincol() + 1
      Message 2 of 4 , Sep 2, 2004
        Tim Chase wrote:

        > > Is there a way to match the portion of the current
        > > wrapped line at the cursor between the edges of the
        > > window? I have a routine to highlight
        >
        > Depending on how your wrapping is configured, you may have a
        > modestly easy job, or a more difficult job. Because those
        > positions are actually within the line, you'll likely have to use
        > the %123c atom to hit those actual columns. It's nothing as
        > pleasant as having a "real" atom for it. If your wrapping just
        > wraps at the given column (such as in the middle of words), then
        > you should be able to just use a fixed atom (or collection of
        > atoms something like
        >
        > \(%70c\|%140c\|%210c\)
        >
        > If, however, your wrapping is configured to wrap at word
        > boundaries, you'll likely have to use something like the above in
        > conjunction with a search for the "word" that the above happens
        > to bisect. Something akin, perhaps to
        >
        > \w*\(%70c\|%140c\|%210c\).
        >
        > I'm sure there are some odd edge cases that this doesn't properly
        > deal with, but it's just my first thoughts on the matter. I
        > haven't encountered any native atom like you detail, so I guess
        > either wait for Bram to add such a creature, or roll your own :)

        I've not entirely followed the thread, but if you are after
        the number of the leftmost column of the current screen line
        then

        virtcol('.') - wincol() + 1

        or something similar might help.

        Antony
      • Steve Hall
        ... [...] Didn t realize I could specify both line *and* column at the same time, that was the trick, found below in lines 6-8. And in case anyone s
        Message 3 of 4 , Sep 2, 2004
          On Thu, 2004-09-02 at 09:18, Tim Chase wrote:
          > > Is there a way to match the portion of the current wrapped line at
          > > the cursor between the edges of the window? I have a routine to
          > > highlight the current line...
          >
          > Depending on how your wrapping is configured, you may have a
          > modestly easy job, or a more difficult job. Because those positions
          > are actually within the line, you'll likely have to use the %123c
          > atom to hit those actual columns. It's nothing as pleasant as
          > having a "real" atom for it.
          [...]

          Didn't realize I could specify both line *and* column at the same
          time, that was the trick, found below in lines 6-8.

          And in case anyone's interested, here's a distillation of how to
          highlight the current line/screenline. Of course, you'll have to map
          each motion key and mouse click to call the first function. :)


          Steve Hall [ digitect@... ]

          --------------------------------------------------------------
          Highlight Current Line

          1: highlight! link CurrentLine Todo
          2:
          3: function! Highlight_currentline()
          4: let linewidth = Linewidth()
          5: let linestart = Winline_start(linewidth)
          6: execute 'silent! match CurrentLine /\%' . line('.') .
          7: \ 'l\%<' . (linestart + linewidth) .
          8: \ 'v.\%>' . (linestart) . 'v/'
          9: endfunction
          10:
          11: function! Winline_start(linewidth)
          12: " return start of current screen line
          13: let len = virtcol('$')
          14: let pos = virtcol('.')
          15: " if line shorter than window, only one screen line
          16: if len <= a:linewidth
          17: return 1
          18: endif
          19: " if position is less than line width, on first line
          20: if pos <= a:linewidth
          21: return 1
          22: endif
          23: " we're beyond the first screen line
          24: let i = 1
          25: while i < pos + 1
          26: let i = i + a:linewidth
          27: endwhile
          28: return i - a:linewidth
          29: endfunction
          30:
          31: function! Linewidth()
          32: " calculate text width according to state of signs, fold
          33: " columns, and line numbers.
          34: let foldcolumn = &foldcolumn
          35: if Marks_Exist() == 1
          36: let signs = 2
          37: else
          38: let signs = 0
          39: endif
          40: if &number == 1
          41: let number = 8
          42: else
          43: let number = 0
          44: endif
          45: return winwidth(0) - signs - foldcolumn - number
          46: endfunction
          47:
          48: function! Marks_Exist()
          49: " if you've used signs, return 1 here
          50: return 0
          51: endfunction
          --------------------------------------------------------------
        Your message has been successfully submitted and would be delivered to recipients shortly.