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

Re: Changing modes & a few questions...

Expand Messages
  • Benji Fisher
    Please do not combine top-quoting with bottom-quoting. It gets confusing. There are several questions here. First, getting out of Select mode. If your
    Message 1 of 7 , Dec 12, 2005
    • 0 Attachment
      Please do not combine top-quoting with bottom-quoting. It gets
      confusing.

      There are several questions here. First, getting out of Select
      mode. If your script is called from a mapping (common, but not
      universal) then you can add "gV" to the mapping. If not, have you tried
      adding the line

      normal gV

      to your script? (I have not tested it myself.)

      In a script, you can get the cursor position and Visual area with
      line() and col().

      :help line()
      :help col()
      :help '<

      (I have not yet played with lists in vim 7.0, so I do not know whether
      they make all this any simpler.) You can set the cursor position with
      cursor(). You can set the Visual selection with

      :execute "normal 30G5|\<C-V>32G7|\<Esc>"

      :help :normal

      It would be nice if the Visual marks were writeable, so that a script
      could avoid the :normal command with something like

      :call cursor(30,5)
      :mark < " error
      :call cursor(32,7)
      :mark > " error

      HTH --Benji Fisher

      On Mon, Dec 12, 2005 at 10:54:33AM +0100, Jeff Rose wrote:
      > Yeah, I've seen the select-mode mappings, but I need a function to call
      > rather than a mapping because this is something I need to do inside of a
      > script. Ideally I could query for the coordinates of the currently
      > selected region, deselect, move to a new location and possibly select a
      > new region. Can you do this programmaticly?
      >
      > I have been using this, but it doesn't work when text is still selected,
      > and it seems klunky to have to call commands from a script like this:
      >
      > line_num, col_num = VIM::Window.current.cursor
      >
      > # do some stuff...
      >
      > VIM::Window.current.cursor = [new_line_num, new_col_num]
      >
      > if width > 0
      > VIM::command("stopinsert")
      > VIM::command("normal! v#{width}l^G")
      > end
      >
      > It would be great if there was something like:
      >
      > VIM::Window.current.select_region(sline, scol, eline, ecol)
      > VIM::Window.mode(VIM::NORMAL_MODE) # Or VIM::SELECT_MODE
      >
      > I know this is ruby, but the same functionality would be required by any
      > language binding. Set and get cursor, region & mode.
      >
      > Thanks,
      > Jeff
    Your message has been successfully submitted and would be delivered to recipients shortly.