Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to search in vim like in emacs?

More precisely, say I start searching with incremental search turned on. The cursor will go to the first match. I hit enter and then 'n' to go to the next match. Now I want to add some characters to my original search expression and search for the next match. I can't do this because after I hit 'enter', the focus leaves the search term area.

The emacs equivalent would be ctrl-s blah ctrl-s ha. And I would end up searching for the term 'blahha'.

Does that make sense? Is it possible?

Edit

The ideal situation would be to do something like /blah < C-S >, and have it immediately jump to the second occurance of 'blah', while keeping the focus in the search buffer.

share|improve this question

migrated from stackoverflow.com Oct 25 '12 at 7:41

This question came from our site for professional and enthusiast programmers.

    
Why the down vote? – juniper- Oct 24 '12 at 18:41
    
On the topic of search refinement, you may want to take a look at q/. See :h q/ for more information. Also there is a nice Vimcast about this subject. vimcasts.org/episodes/… – Peter Rincker Oct 24 '12 at 20:27
up vote 4 down vote accepted

The closest thing I can think of off the top of my head would be to hit /<C-R>/ then append your new text. / will pop open the search dialog, <C-R> allows you to paste from one of your registers, and the / registers is the previous search buffer, which contains your most recent search text.

If you find yourself doing this a lot, you might make a mapping for it, like

nnoremap <leader>/ /<C-R>/

As I mentioned in the other comment, if you want to stay in the search buffer, you could add something like this to your vimrc. I think this will get you what you want.

cnoremap <C-S> <CR>/<C-R>/
share|improve this answer
    
I'm probably stupid, but this doesn't work for me. – juniper- Oct 24 '12 at 18:58
    
<C-R> here means control + R at the same time. If that doesn't work, I'm a bit surprised. I think Tom's answer is probably better anyway. – Alex Oct 24 '12 at 19:03
    
Yup. I'm stupid. I hit control-R, but didn't hit the '/' afterwards. Sweet trick. Thanks! – juniper- Oct 24 '12 at 19:06
    
The suggested edit doesn't work. Hitting C-S while in the search buffer does nothing. – juniper- Oct 24 '12 at 19:14
1  
<C-s> is often eaten by the terminal. – romainl Oct 24 '12 at 19:35

/<Up> or /<C-P> will get you to your previous seach, and you can continue to type after that to append. You can add :nnoremap / /<Up> to your vimrc if you would like this to be your default behaviour.

share|improve this answer
    
This works, but it's still one more keystroke than the ideal. I still have to hit 'enter' after entering the original search and then '/' to search again :) – juniper- Oct 24 '12 at 18:59
    
Try adding cnoremap <C-S> <cr>/<up> to your vimrc. I think that will do what you're asking. – Alex Oct 24 '12 at 19:06
    
The .vimrc change doesn't do much. Same with Alex's. Perhaps my C-S isn't recognized as such. Or I'm not putting it in the proper place, even though it's right smack between two nnoremap directiv lines. – juniper- Oct 24 '12 at 19:16
    
Thanks for help!! Works with <C-L>. This would be a prime time for a double accept feature :-/ Unfortunately you lost a coin toss. – juniper- Oct 24 '12 at 19:39
    
Ah, you may have <C-S> getting remapped to Save (say, you're on Windows and using the default setup). You can check your mappings by executing :map <C-S> – dash-tom-bang Oct 25 '12 at 3:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .