---
title: "Basic Searching inside a file in VIM"
url: "https://courses.osherove.com/courses/vim-hates-you/basic-searching-inside-a-file-in-vim.md"
canonical: "https://courses.osherove.com/courses/vim-hates-you/basic-searching-inside-a-file-in-vim/"
tags: []
author: "Roy Osherove"
description: "Lesson 5 of 26 in Vim Hates You (Get Somewhat productive in an hour or so), 2:42. Free video by Roy Osherove."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Basic Searching inside a file in VIM

1. [Courses](https://courses.osherove.com/#courses)
2. [Vim Hates You](https://courses.osherove.com/courses/vim-hates-you/)
3. Get Somewhat productive in an hour or so

Lesson 5 of 26

Duration: 2:42 [Watch on YouTube](https://www.youtube.com/watch?v=sojqXMtNolI)

## In this lesson

Roy searches inside a file by typing a forward slash and the text, then pressing n to go to the next match; the search is case sensitive by default and wraps around. He turns on incsearch to highlight the search while typing and hlsearch to highlight all matches, and removes the highlighting with set nohlsearch. A question mark can also be used to search.

## Transcript

407 words

[\[00:07\]](https://www.youtube.com/watch?v=sojqXMtNolI&t=7s) Let's talk about searching stuff in Vim. So, the way you search stuff in Vim is that you have two options in the command. Basically, you just type either the forward slash like this and let me just make sure Vim is in focus. So, I type forward slash and now I just type the thing that I'm looking for. So, let's say I'm looking for file type. I just have to type the first part of that. If I press enter, it's going to take me to the first found match. And I can then press N to go to the next match.

[\[00:37\]](https://www.youtube.com/watch?v=sojqXMtNolI&t=37s) And obviously, there's only one. Let's say I look I'm looking for the word plug. I'm going to type slash plug. And by default, this is case sensitive, which is usually what you want, but we'll talk about case insensitive in a second. If I type plug now, I'm getting to the first found match. If I press N, I go to the next one and then it basically circles around. There is one helpful option you can set by saying command

[\[01:08\]](https://www.youtube.com/watch?v=sojqXMtNolI&t=68s) Set incremental search. So incsearch and this basically highlights the search as I'm typing it. So if I type slash last status, I can see already where it's being found. If I type slashplug, I can see the first highlight. Another option I can set is to say set hlsearch, which means basically highlight all the matches that you find by default.

[\[01:40\]](https://www.youtube.com/watch?v=sojqXMtNolI&t=100s) So if I press this, I can see all the matches that were found. Let me search something else. Let's say I'm going to look for set and I can see the first match. But if I type enter, I can see all the matches and I can press N to move between them. Now, how do I remove the highlighting? Because it's going to stay there. I have to type set nohlsearch, which basically removes it. Now, in a later video, I'm going to show how to create custom keyboard bindings so that you can remove the hlsearch just by with the keyboard shortcut.

[\[02:20\]](https://www.youtube.com/watch?v=sojqXMtNolI&t=140s) And of course I said that slash is one of the ways to search, but you can also use the question mark. So if I type question mark set, I get the same result basically. And because I don't have hlsearch enabled, then I don't see all the types, all the matches that I

[Previous lesson Syntax Highlighting and Numbering in .vimrc file](https://courses.osherove.com/courses/vim-hates-you/syntax-highlighting-and-numbering-in-vimrc-file/) [Next lesson Indentation](https://courses.osherove.com/courses/vim-hates-you/indentation/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
