Questions tagged [search]

Searching for text with / or search(). For find/replace operations, use tag [substitute] instead.

Filter by
Sorted by
Tagged with
3
votes
2answers
315 views

How do I search for line containing an unclosed parenthesis?

How to search for line containing unclosed parenthesis. /([^)]*$ works only for non-nested parenthesis. If the closing parenthesis is present in the next lines, it should still be a match. for ...
1
vote
1answer
88 views

Search for continuation line

How to search for continuation line, as detected by c-indent in vim ? ie. the +N cinoption.
4
votes
2answers
988 views

How to search in Ex mode and place the cursor on the matched pattern?

I've the following example: vim -E http://example.com/ where I'd like to search for <head> tag. It seems that search only works when the lines are separated, but when the lines are joined ...
17
votes
2answers
10k views

How to use Ctrl-P to interactively search file contents for all files in a project?

I tried today to perform a search on every files of a project. I use Ctrl-P and search on lines like so : But the result of the search is only on the previously opened file. Here I open only main....
3
votes
1answer
1k views

How to setup AG (the silver searcher) in vim?

I am using AG to simplifying and improve the search in my vim. I remapped K to search for the current selected word as follows: if executable('ag') set grepprg=ag\ --nogroup\ --nocolor command -...
13
votes
2answers
6k views

What is the functional difference between :nohlsearch and :set nohlsearch?

I noticed that when I use :nohlsearch that it does not actually do the same thing as :set nohlsearch. In particular, the hlsearch setting is not actually switched off (which is what :set hlsearch) ...
4
votes
2answers
566 views

How to search for a matching pattern only in the first line across multiple files?

How do I search in multiple files for 1st line of file matching a pattern? e.g. I want to search for files starting with ++ ++ Heading 1 and not + Heading 1 ++ Heading 2 Any pointers appreciated....
3
votes
1answer
157 views

Configuring include-search for PHP

I just learned of the existence of include-search, but even after reading :help include-searchand :help includeexpr I'm not sure what I need to do to have [I find included and required files. How do ...
6
votes
1answer
210 views

What's the point of :promptfind after all

Not sure if it's an appropriate question. But I just can't help wondering, why would any Vim user find it necessary to invoke a GUI search prompt instead of search using / or ?, why would the designer ...
21
votes
4answers
9k views

How to show search results for all open buffers

One thing I often do (but rely on the command line to do) is searching/grepping in multiple files. Is there a way to display search results for all the open buffers? Ideally, I'd like to have a new ...
9
votes
2answers
782 views

Navigating code projects without using external commands

I am trying to gather a toolbox of Vim commands/queries, in command or search mode, for navigating a code-base without using Ctags or other external tools. Ctags are great but support can vary ...
5
votes
1answer
7k views

searching duplicate words

This page says that I can find duplicate words using a regular expression. The suggested command is \(\<\w\+\>\)\_s*\<\1\> What does "\w" mean here? Suppose the target pattern is "123\...
62
votes
5answers
24k views

Vim search replace all files in current (project) folder

One of the open questions I have about Vim is if there is a way to perform a search/replace in the current project (bear with me if I use this notion inherited from other editors). For instance, let'...
1
vote
1answer
380 views

Delete all lines which contain any word not used anywhere else in the buffer

Note: For those of you who do not know VHDL do not worry, I will explain the problem with an example. Motivation I have a VHDL file which is a big mess of buses. I have declared many signals and I ...
21
votes
3answers
1k views

How can I get ‘n’ to go forward even if I started searching with ‘?’ or ‘#’?

Vim has (at least) two sets of commands that search in opposite directions. Typing / and then a pattern will search forward through the document for the pattern; typing ? and then a pattern will ...
3
votes
1answer
1k views

How can I search and replace within multiple files? [duplicate]

I have the same text that I want to replace in multiple files (say, I'm updating version numbers in multiple files). Even using the command history to reuse commands, it sure is tedious to open each ...
47
votes
7answers
36k views

How to show only matching lines?

Is there a way to hide all lines that did not match, while going through the list of result lines? In a long file, I would like to search for a pattern that will match roughly 200 lines or so. The ...
114
votes
2answers
11k views

How do I navigate to topics in Vim's documentation?

In Vim's built-in help system, how do I… search for topics that I want help on? follow hyperlinks? browse around for related material?
3
votes
1answer
383 views

How can I make the "gn" motion wrap to the beginning of the file?

gn is a very useful command that selects the next search result. For example, if I insert foo bar baz into a file, move to the beginning, type /[aeiou]., and press gn, it would select oo in a visual ...
6
votes
2answers
2k views

How do I search for a line that contains a pattern at column n

In writing some Vimscript to try to answer this question, I was exploring ways to "search for a line with pattern P in position X" (P is a search pattern, X is a number). One way to do this would be ...
94
votes
10answers
128k views

How can I clear word highlighting in the current document (e.g. such as after searching for a word)?

When you search for a word in a file with something like /console.log, all of the instances of console.log are highlighted. When you're no longer interested in these, the highlighting can be ...
10
votes
4answers
290 views

Restricting operations to a section of code

There is many times in my day to day work life that I need to operate on a specific function, things like highlighting or searching for a variable, but I have never managed to limit the scope of the ...
106
votes
7answers
68k views

Is there a way to count the number of occurrences of a word in a file?

Is it possible to count how many times a word or a pattern appears in a file? This is sometimes useful to find out how many times a function has been called, etc.
15
votes
4answers
3k views

How can I search for a string between certain line numbers?

This is a problem I had recently. I have a file with several hundred lines of text. How can I search for a string between two specific line numbers? For e.g. I want to search between line numbers 100 ...

1
5 6 7 8
9