Sunday, March 28, 2010

Re: Going back to normal mode from visual mode in a function

Am 28.03.2010 07:30, schrieb James Cole:
> Hi,
>
> At one point in a vim script function I'm writing, the system will be
> in visual mode and I want it to go back out of visual mode to normal
> mode.
>
> I know it doesn't really work to use something like 'normal! v'
> because if the visual mode it stared in was 'V' then that command will
> just change it to a character-based selection rather than going back
> to normal mode.
>
> If I use
>
> normal!<ESC>
>
> that's treated as just typing '<' 'E' 'S' 'C''>'

yep, :normal does not accept key codes, use
:exec "normal! \<Esc>"
instead.

> so I thought I could use this:
>
> normal! ^[

It works for me.

> (which I've entered by typing 'normal ' and then pressing CTRL-Q
> then<ESC>. I'm doing this on a windows machine, so on other
> systems you'd be typing CTRL-V instead of CTRL-Q).
>
> and I /thought/ this was working the other day, but now when I try
> using it, it keeps giving me this error:
>
> E471: Argument required: normal!
> [...]

> so I'm wondering, what (preferably non-hack-like) means can I use in a
> function to get out of visual
> mode and return to normal mode? I figure there must be some means of
> escaping or specifying a<ESC> key-press that I don't know about.

or use :exec "normal! \e" (:h expr-quote)


func! VisModeTest()
normal! v
" exec "normal! \e\e"
exec "normal! \e"
endfunc

call VisModeTest()


No problem here: a single \e works ok, if doubled it'll beep.

--
Andy

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: