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

Re: Setting of visual mode marks for put text

Expand Messages
  • Jens Paulus
    Hi Keith, ... obviously there is already a mechanism to know whether the last selection was characterwise, linewise or blockwise. The gv command activates the
    Message 1 of 6 , Dec 1, 2004
    • 0 Attachment
      Hi Keith,

      On Wed, Dec 01, 2004 at 09:18:32 -0800, Keith Roberts wrote:
      > >On Tue, Nov 30, 2004 at 11:39:39 +0100, Bram Moolenaar wrote:
      > >> > when selecting text with visual mode and then deleting it and
      > >> > putting it to some other location I suggest that the < and > marks
      > >> > will then be set to mark the region of this put text. Then if the
      > >> > user continues editing the text file and later presses gv
      > >he or she
      > >> > can operate on that text again. Currently the < and > marks both
      > >> > mark the first line after the deleted text and I think
      > >this does not
      > >> > make much sense and the gv command is useless then. Of
      > >course, these
      > >> > marks should not be set with each putting of text but only when
      > >> > putting text that was deleted using visual mode.
      > >>
      > >> The text you put back doesn't know it came from a Visual
      > >selected area.
      > >> The delete and put operations are independent. Any sequence of
      > >> commands may appear in between the two operations.
      > >
      > >well I was just thinking there could be a boolean variable
      > >created that is normally false and only made true if text is
      > >deleted using visual mode. Then whenever text is put this
      > >variable would be checked and if it is true the < and > marks
      > >are made equal to the [ and ] marks and it is made false.
      > Actually, this makes some sense to me ... But perhaps the better
      > question is: is there a way (no matter how it was selected or put) to
      > turn the last put into a visual selection?
      > The problem, as I see it, is that you have to know whether the last
      > selection (and therefore the put) was line-wise, character-wise or
      > block-wise. I can use `[,`] as my limits, but do I use v, V or CTRL-V
      > when moving from `[ to `] to make it visual? [This will also be
      > influenced by how it was put: normal p will put it in all 3 modes, but
      > :put only linewise.]

      obviously there is already a mechanism to know whether the last
      selection was characterwise, linewise or blockwise. The gv command
      activates the last selected area in the right mode. If this mechanism is
      not enough there need to be one or two new variables created. Either one
      variable of type char which can have the values c, l or b or two boolean
      variables which are for example false,false, false,true or true,true to
      report the type of the last selection. If :put is entered and the last
      deleted text was deleted using visual mode, this variable or these
      variables need to be set to the linewise state and the put command can
      proceed. When putting the text the variable which reports whether the
      last deleted text was by using visual mode needs to be made false as I
      described earlier. My opinion is that it would be more useful if the gv
      command selects a text region than if it possibly selects the position
      where the last deleted text was. This is how it currently works.

      Best regards

    • Jens Paulus
      Hi Keith, ... here is how I did it. vn d d:let gvtest= vn D D:let gvtest= no p :exe norm! p call Gv() no gp :exe norm!
      Message 2 of 6 , Dec 4, 2004
      • 0 Attachment
        Hi Keith,

        On Fri, Dec 03, 2004 at 14:08:43 -0800, Keith Roberts wrote:
        > You could create a command, something like:
        > command GV call GV()
        > And the function GV(), which would do something like:
        > - use visualmode() to figure out the type of selection
        > - col('.') and line('.') will show if current selection is empty
        > - if not empty, :normal gv
        > - if empty, :normal `[{v|V|CTRL-V}`]

        here is how I did it.

        vn <silent> d d:let gvtest=""<CR>
        vn <silent> D D:let gvtest=""<CR>
        no p :exe "norm! p"<bar>call Gv()<CR>
        no gp :exe "norm! gp"<bar>call Gv()<CR>
        no p] :exe "norm! p]"<bar>call Gv()<CR>
        no P :exe "norm! P"<bar>call Gv()<CR>
        no gP :exe "norm! gP"<bar>call Gv()<CR>
        no [p :exe "norm! [p"<bar>call Gv()<CR>
        fun Gv()
        if exists("g:gvtest")
        exe "norm mp`[".visualmode()."`]\<C-\>\<C-N>`p"
        unl g:gvtest

        This works well. One mark is used to store the cursor position after the
        put cmmmand. The cursor position within the visual area is not stored.

        Best regards

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