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

Re: Using "strlen" under Visual Mode

Expand Messages
  • Arun Easi
    ... and look towards the lower-right-corner of the screen. -Arun
    Message 1 of 7 , May 2, 2005
    • 0 Attachment
      If the selection is within a line and if you just want to see the len:

      :set showcmd

      and look towards the lower-right-corner of the screen.

      -Arun

      On Mon, 2 May 2005, Edward WIJAYA wrote:

      > Hi,
      >
      > Suppose I want to measure then length of the
      > string highlighted under visual mode.
      >
      > Is there a way to do it?
      >
      > --
      > Regards,
      > Edward WIJAYA
      > SINGAPORE
      >
    • Keith Roberts
      ... I think visualmode() would work here ... It doesn t matter if you ve crossed into normal mode, since it returns what the mode was last time visual mode was
      Message 2 of 7 , May 10, 2005
      • 0 Attachment
        >-----Original Message-----
        >From: Eric Arnold [mailto:eric_p_arnold@...]
        >Sent: Sunday, May 01, 2005 9:45 PM
        >To: jamessan@...; vim@...
        >Subject: Re: Using "strlen" under Visual Mode[answer + question]
        >
        >
        >--- jamessan@... wrote:
        >
        >> On Mon, May 02, 2005 at 06:49:19AM +0800, Edward WIJAYA wrote:
        >> > Suppose I want to measure then length of the string highlighted
        >> > under visual mode.
        >> >
        >> > Is there a way to do it?
        >>
        >> You could yank the text into a register and then call strlen on the
        >> buffer. For example:
        >>
        >> <select visual range>
        >> "ay
        >> :echo strlen(@a)
        >
        >
        >If you want to restore the selection area, try:
        >
        > `<v`>
        >
        >or V or which-ever. I tried making a function to do it automatically,
        >
        > function! Vislen()
        > let modetype = mode()
        > let do = 'normal "by`<' . modetype . '`>'
        > echo do
        > exe do
        > echo modetype . ": strlen(" . @b . ")=" . strlen(@b)
        > endfunction
        > map ,t :call Vislen()<CR>
        >
        >but the "mode()" call returns "n" normal mode when I call the
        >,t macro from a visual selection. The help says:
        >
        > This is useful in the 'statusline'
        >option. In most other
        > places it always returns "c" or "n".
        >
        >Sadly, the help for "mode()" doesn't refer you to what
        >actually works, getregtype(). It does mean that you can't
        >find out the mode without yanking into a register, as far as I
        >can tell.

        I think visualmode() would work here ... It doesn't matter if you've
        crossed into normal mode, since it returns what the mode was last time
        visual mode was entered.

        -Keith
      Your message has been successfully submitted and would be delivered to recipients shortly.