Command mode move to matching paren/brace/bracket/angles... like '%'

16 views
Skip to first unread message

jjlu...@yahoo.com

unread,
Oct 8, 2020, 11:43:11 AM10/8/20
to vim_use
Please help me find a way to move to the matching char pair from within a :source'd script...
Something like the Command mode move to matching paren/brace/bracket/angles... using the '%' key... but from the :source'd script...

Tim Chase mentions in another article (reference below) using % to move to the matching in normal mode.  The CTRL-O in insert mode was interesting as well... 

I'm trying to use a "move to matching" inside a :source'd script.  Is there a way to still move to matching brace after finding the start brace inside the :source'd script?

more info....

I tried a line with a single percent '%' and it moves the cursor to the end of the file. So I always got from the starting point to the end of the file and not the matching brace.

After reading Tim's response, I also tried something like this after finding the starting brace.  Here I am typing out the characters representing the characters i, CTRL-o, %,  escape key, where CTRL-o and escape were entered using the escaping key mech of CTRL-V (linux): 
i^O%^[

thanks for looking and thanks in advance for the help... newbie...  
Jim



=================================
Subject: How to move cursor in insert mode?
Credit: Tim Chase

Some gross movements (such as by word or screen) can be done in 
insert-mode as well (control+left/right, home/end, pgup/dn) 
though some may be limited to gvim. For some of the other 
vim-specific movements, you can also use control+o ("oh", not 
"zero") to temporarily enter normal mode to issue one normal-mode 
command such as "%" to move to the matching paren/brace/bracket 
or ")" to move to the next sentence. All your typical motions 
should work here.

:help i_CTRL-O
:help motion.txt

-tim

Gary Johnson

unread,
Oct 8, 2020, 1:46:26 PM10/8/20
to vim_use
On 2020-10-08, 'jjlu...@yahoo.com' via vim_use wrote:
> Please help me find a way to move to the matching char pair from within a
> :source'd script...
> Something like the Command mode move to matching paren/brace/bracket/angles...
> using the '%' key... but from the :source'd script...
>
> Tim Chase mentions in another article (reference below) using % to move to the
> matching in normal mode. The CTRL-O in insert mode was interesting as well...
>
> I'm trying to use a "move to matching" inside a :source'd script. Is there a
> way to still move to matching brace after finding the start brace inside the
> :source'd script?

I think you're looking for the :normal command. See

:help :normal

Then you can put this in your script to move the cursor to the
matching item:

normal %

Regards,
Gary

jjlu...@yahoo.com

unread,
Oct 8, 2020, 6:40:00 PM10/8/20
to vim_use
very cool... worked like a charm Gary, thank you for sharing!!
Reply all
Reply to author
Forward
0 new messages