Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to leave search mode in VIM?

Tags:

vim

Given a file like the following:

blah
blah
collection = getCollection();
process(somethingInTheWay, target);

...after this short sequence of 'search' commands in vim...

/col<carriage return>

My cursor will be under the first appearance of "collection."

Now, what command(s) will remove the '/col' from my vim command line (in case I want to search afresh, for example)?

like image 748
gallygator Avatar asked Sep 11 '14 11:09

gallygator


People also ask

How do I search in vim/vi?

This tutorial shows you how to search in Vim/Vi with practical examples. Important: Make sure you are in Normal Mode before you start searching. This allows in-text navigating while using normal editor commands. Vi and Vim open a file in normal mode by default. To switch to normal mode, press Esc.

How do I go back to normal mode in Vim?

To go back to normal mode from any other mode, just press the Esc key. Vim allows you to quickly find text using the / (forward slash) and ? (question mark) commands. To search forward, press / and to search backward press ?, type the search pattern and press Enter to run the search:

How do I Quit VI or Vim on Linux?

Here’s how to quit vi or vim on Linux, macOS, or any other Unix-like system. If you’re in vi or vim and need to get out—with or without saving your changes—here’s how: First, press the Esc key a few times. This will ensure vi is out of Insert mode and in Command mode. Second, type :q! and press Enter.

How do I navigate in vim/vi text editor?

This allows in-text navigating while using normal editor commands. Vi and Vim open a file in normal mode by default. To switch to normal mode, press Esc. There are two ways to search for a pattern of numbers or letters in the Vim/Vi text editor. 1.


1 Answers

I am not completely sure what you mean, because there are a couple of things that play a role here. Your input ("/col") is displayed in the command line for some extra time after search. Usually people don't care about this and after some time find it even helpful. You already left "search mode" when you pressed Enter and after vim put the cursor on the first match. vim will lazily remove the search string when redrawing screen or when the space is needed. There are some ways to remove it, if you want to:

  • Ctrl-L (redraw)
  • :redraw
  • any combination of / or : with Esc or Backspace

Now I wrote, that you already left "search mode" with Enter, but you may continue your last search at any time with n / N. These commands will just take whatever is in the special register / and use it for further searching. It would be possible to "disable" this behaviour by removing the last search pattern from /:

:let @/ = ""

You could manually put something into that register which would enable you to "continue search" without ever having started any search.

If you just want to get rid of the currently highlighted matches, type:

:noh

You can turn off or toggle highlighting matches in general:

:set nohls
:set hls!

The latter is a good candidate for a key binding. I use this to toggle highlighting of the last search (mnemonic: klear - not very accurate but works for me):

:nno <C-k> :set hls!<CR>
like image 194
steffen Avatar answered Oct 06 '22 22:10

steffen