gVim Find & Replace shortcut keys

569 views
Skip to first unread message

Alain Forget

unread,
May 10, 2009, 6:53:21 PM5/10/09
to vim...@googlegroups.com
I've been using gVim in Windows for a year now, but there is one thing I've
been unable to do (or figure out via Googling):

How can I set the shortcut key Ctrl-F to display the Edit->Find... dialog
box, and Ctrl-H to display the Edit->Find and Replace... dialog box? (Ctrl-F
and Ctrl-H are typically the shortcuts for Find and Find & Replace in the
Microsoft Windows world, so it's just what many Windows users are familiar
with.)

I imagine there should be two "imap" or "inoremap" instructions I could put
in the mswin.vim file, but I don't know how to programmatically display the
Find... and Find and Replace... dialog boxes. To illustrate, I'm pretty sure
this should work:

inoremap <C-F> [INSERT COMMAND TO DISPLAY "FIND..." HERE]
inoremap <C-H> [INSERT COMMAND TO DISPLAY "FIND AND REPLACE..." HERE]

I just haven't been able to find what those two commands are. Any ideas?

Thanks,
Alain


_sc_

unread,
May 10, 2009, 11:00:47 PM5/10/09
to vim...@googlegroups.com

find and replace have a dialog accessible via:

:promptrepl

you can use it for finding or for finding and replacing

sc


John Beckett

unread,
May 11, 2009, 12:04:09 AM5/11/09
to vim...@googlegroups.com
Alain Forget wrote:
> How can I set the shortcut key Ctrl-F to display the
> Edit->Find... dialog box, and Ctrl-H to display the
> Edit->Find and Replace... dialog box?

Amazing ... I vaguely knew this was possible, so had a look and
found the following:

inoremap <C-F> <C-O>:promptfind<CR>
inoremap <C-H> <C-O>:promptrepl<CR>

I used the following to find what the commands were:
:menu Edit

I never use the menus, and would recommend the Vim method of
using the command line which has history and <C-R> to insert
registers and probably other good stuff.

John

Tim Chase

unread,
May 11, 2009, 6:04:09 AM5/11/09
to vim...@googlegroups.com
> inoremap <C-H> [INSERT COMMAND TO DISPLAY "FIND AND REPLACE..." HERE]
>
> I just haven't been able to find what those two commands are. Any ideas?

Just a caveat that came up on this list recently regarding the
same idea: beware remapping control+H because it's often
interpreted as the same key as backspace. In Normal mode
(nnoremap) this isn't much of a problem because I don't recall
ever using backspace. However in Insert mode (your "inoremap"),
backspace and I are good friends.

-tim

Alain Forget

unread,
May 11, 2009, 2:33:01 PM5/11/09
to vim...@googlegroups.com
So simple. Thanks a bunch!

Alain

Alain Forget

unread,
May 11, 2009, 2:54:37 PM5/11/09
to vim...@googlegroups.com
Awesome, that worked like a charm. I have another problem however...

Is there any way to map the <F3> key to "Find Next" (i.e. find the next
occurrence of the string I just searched for) in gVim?

Goggling found that the <n> keystroke does this, but I am unclear on its
usage. For example, when in insert mode, and I do the following:

<C-O>:n<CR>

I get an error saying "E163: There is only one file to edit", rather than
the, "E486: Pattern not found: \V\C[MY SEARCH TEXT]" I would have expected
from the Find Next command.

Any ideas?

Alain

-----Original Message-----
From: vim...@googlegroups.com [mailto:vim...@googlegroups.com] On Behalf
Of John Beckett
Sent: May 11, 2009 00:04
To: vim...@googlegroups.com
Subject: RE: gVim Find & Replace shortcut keys


Tim Chase

unread,
May 11, 2009, 3:06:39 PM5/11/09
to vim...@googlegroups.com
> Is there any way to map the <F3> key to "Find Next" (i.e. find the next
> occurrence of the string I just searched for) in gVim?
>
> Goggling found that the <n> keystroke does this, but I am unclear on its
> usage. For example, when in insert mode, and I do the following:
>
> <C-O>:n<CR>

Sooooo close :)

:nnoremap <f3> n

...and soooo boringly simple :)

The catch is that "n" searches in the same direction as the last
search. So if you search backwards, "n" will continue to search
backwards.

-tim

Alain Forget

unread,
May 11, 2009, 3:14:23 PM5/11/09
to vim...@googlegroups.com

But how do I make it work when I'm in insert mode? I would have thought:

inoremap <F3> <C-O>:n<CR>

would have done the trick, but it doesn't. Any ideas?

Alain

wormi...@gmail.com

unread,
May 11, 2009, 3:22:24 PM5/11/09
to vim...@googlegroups.com
inoremap <F3> <c-o>n
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: Alain Forget <afo...@scs.carleton.ca>

Date: Mon, 11 May 2009 15:14:23
To: <vim...@googlegroups.com>
Subject: RE: gVim Find Next shortcut key

Ben Fritz

unread,
May 11, 2009, 3:20:30 PM5/11/09
to vim_use


On May 11, 1:54 pm, Alain Forget <afor...@scs.carleton.ca> wrote:
> Awesome, that worked like a charm. I have another problem however...
>

Next time, please start a new thread for a new question. Also, please
"bottom-post" in accordance with posted guidelines:
http://groups.google.com/group/vim_use/web/vim-information

> Is there any way to map the <F3> key to "Find Next" (i.e. find the next
> occurrence of the string I just searched for) in gVim?
>
> Goggling found that the <n> keystroke does this, but I am unclear on its
> usage. For example, when in insert mode, and I do the following:
>
> <C-O>:n<CR>
>
> I get an error saying "E163: There is only one file to edit", rather than
> the, "E486: Pattern not found: \V\C[MY SEARCH TEXT]" I would have expected
> from the Find Next command.
>

The "n" keystroke is something you type directly in normal mode, it is
not an ex command (command-line mode). You have accidentally made a
mapping to issue the :next command instead of simply pressing n.

Your mapping should be <C-O>n rather than <C-O>:n<CR>.

See :help vim-modes, :help n, and :help :next

Vim has a wide range of normal, insert, and command-line mode
commands. If you have not already done so, Vim ships with a tutorial
that can give you a great introduction.

Tim Chase

unread,
May 11, 2009, 3:21:02 PM5/11/09
to vim...@googlegroups.com
>> :nnoremap <f3> n
>>
>> ...and soooo boringly simple :)
>>
>> The catch is that "n" searches in the same direction as the last
>> search. So if you search backwards, "n" will continue to search
>> backwards.
>>
>> -tim
>
> But how do I make it work when I'm in insert mode? I would have thought:
>
> inoremap <F3> <C-O>:n<CR>

:inoremap <f3> <c-o>n

-tim


Alain Forget

unread,
May 11, 2009, 3:24:23 PM5/11/09
to vim...@googlegroups.com

:inoremap <f3> <c-o>n

-tim

Works like a charm. Thanks!

Alain

Reply all
Reply to author
Forward
0 new messages