Wednesday, February 6, 2013

Re: vim: help for scripting

On 16:08 Wed 06 Feb , ping wrote:
>
> whenever I come to a scenario that I have to (or better) script in vim ,
> it becomes a big headache and time consuming work -- turning my goal of
> efficiency boosting to the reverse effect --- spending a lotof time
> without success. I feel guilty to seek help for "simple-looking" task,
> but seems I have to...
>
> ok, anyway...
>
> say I want to achive one thing :
> in some setups , I need to open 2 new window for some quick work, and I
> can hit <cr> to jump between that 2 new windows (you will know better
> what I'm
> talking about if you ever used Voom plugin or other similiar tools)
>
> now , after some while I want to close those 2 newly opened windows --
> of course I can just close them manually, but I think this is really
> something can be done via a small map or func, making it much easier if
> I can then map it to a short key. so here is what I thought "should
> have" worked but not...
>
> function! QuitNR()
> "get number of one win
> let wn_curr=winnr()
> "jump to the other win
> normal! <CR>
> "get number of that win
> let wn_pair=winnr()
> "jump to the window
> exec wn_curr . "wincmd w"
> "close it
> close
> "jump to the other one
> exec wn_pair . "wincmd w"
> "and close that one too
> close
> endfu
>
> nn vV :call QuitNR()<CR>
>
> it looks sth got break in it, at least followig doesn't work when I
> tested it manually:
>
> normal! <CR>
>
> I thought this is equivalent to hitting a return, which jumps to the
> other window , which is what will happen if I hit return myself in
> Voom...but
> that "jump" doesn't happen here in the script.
>
> any thought?
>
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

Hi,

You should not use :normal! <CR> but rather :normal <CR>. The different
is that :normal! does not take any user specific maps, and since in
normal mode <CR> is just a jump to next line, it will just go to the
beginning of next line. This also applies to your manual test. It just
should be
:normal <CR>
without the bang. See ':help :normal'.

I hope it helps,
Marcin

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: