Questions tagged [search]

Searching for text with / or search()

Filter by
Sorted by
Tagged with
94
votes
2answers
5k 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?
59
votes
10answers
52k 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 ...
67
votes
6answers
33k 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.
13
votes
5answers
1k views

Quick search, limited to a C++ function

I work on a rather large C++ project. One of the more frustrating aspects of its organization is very large functions placed inside ridiculously large files. I often want to search for any instance ...
18
votes
3answers
691 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 ...
9
votes
4answers
643 views

How to search for pattern in certain syntax regions?

I am using vim to edit latex documents. Often, I will want to change the name of a variable to something else. However, it's a little annoying to have to wade through irrelevant matches when I search ...
3
votes
1answer
698 views

How to show all unique types of a pattern?

I have a very large file containing about, for example, 5 million lines like this: Songs=****, Singers=**** Singers=*** Songs=*** .... # many many lines SongType=*** ... # many many lines again Album=...
2
votes
1answer
487 views

How to remove inner content of html tag conditionally?

I've html file (e.g. curl -o page.html http://example.com/) where I would like to remove inner html block for given html tag. I've the following code which works: $ ex -V1 page.html <<-EOF /&...
34
votes
5answers
8k 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'...
15
votes
2answers
7k 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....
10
votes
1answer
664 views

different search patterns per window / buffer

Is it somehow possible to have different search patterns per window or buffer, ie. I want to search for term A in window/buffer A and term B in window/buffer B so that using hlsearch, highlights ...
8
votes
2answers
2k views

Multiline Search and Replace

Would like to perform a search and replace in a file with 12000 lines. Specifically, if an occurrence of ^ SetFontSize 28 exists after a ^Hide block and before the next ^Hide or ^Show, change 28 ...
8
votes
2answers
735 views

How do I make list of search results editable?

There are several times, I need to grep for some_pattern in some XHTML files (many a time, file count in a specified folder goes beyond 10K+). Previously, I have used Lugaru's Epsilon Programmer's ...
0
votes
0answers
43 views

How to get the same message and error behavior as normal `n` when calling `normal n` in function

I wrote a vimscript function that prevents the cursor from changing its location on the screen when I press n: function! my_n() let l:start=line("w0") let end = line("w$") let cursor = ...
53
votes
11answers
10k views

How to find and replace in Vim without having to type the original word?

I'd like to optimize my "find and replace" workflow in Vim. It's something I do often, as I'm sure most of you do too. Usually something along the lines of -- copy a block and change the name of a ...
30
votes
7answers
16k views

Show only matching lines?

In a long file, I would like to search for a pattern that will match roughly 200 lines or so. The matched lines are in random places in the file. When a line matches, only the line itself is relevant, ...
17
votes
2answers
679 views

How can I perform a search when vim displays content using “more” pager?

I want to see the value of a variable, so I run the command :let Vim displays the results of this command using the --more-- pager. How can I search this for a phrase, e.g. html? I've looked the ...
14
votes
4answers
4k views

Delete from cursor till nth occurence of character x

I know that I can delete from the cursor till and including the first occurence of a character x with d/x<CR> or with v/x<CR>d if I want to see the selection first and then delete. How can ...
12
votes
2answers
3k 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) ...
10
votes
3answers
359 views

How to selectively change a hightlighted string?

By searching, I've highlighted the string that I want to change. Now I want to replace only the highlighted text. I'm using n to advance to the next instance of the search string. I was thinking I ...
2
votes
3answers
2k views

How to execute command on every matching pattern, not just lines?

I know in vim I can use :global to execute commands on the matching lines. But I'm wondering if it's possible to execute those commands on every matching pattern, not just lines, consider following ...
16
votes
1answer
3k views

Can I search for a Unicode combining character in Vim?

I have a file with the character ã (lowercase a + combining tilde). Encoding and fileencoding are both utf-8. ga shows <a> 97, hex 61, octal 141 <~> 771, Hex 0303, Octal 1403 (but ...
14
votes
2answers
1k views

Is there search and replace history in vim?

We can retrieve search and replace history on IDEs and text editors. Likewise is there a search history or a way to retrieve previously searched expression in vim?
13
votes
3answers
621 views

How do I apply a set of keystrokes to every occurrence of a word?

If I want to delete every word, that is easy, because I would do something like this: :s%/WORD//g But what if I want to do xyz to every occurrence of "WORD"? For example, let's say I want to delete ...
10
votes
1answer
283 views

To print with search results highlighted

When we search a pattern in vim, the matches are usually highlighted. However, when we print it out, the highlights disappear. I tried both :hardcopy > my_file.pdf and :TOhtml. Neither retains the ...
9
votes
2answers
698 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 ...
6
votes
1answer
776 views

How can I repeat last Ex-mode command in normal mode?

I'm looking for something like . or @@ that will work in normal mode for repeating the last Ex-mode command. As per the rule of the XY problem, I'll also state the broader goal: I have a fancy regex ...
6
votes
1answer
188 views

How to move the cursor to the next reference, option, heading in man pages?

If we load the built-in man.vim filetype plugin by writing in our vimrc: runtime ftplugin/man.vim We can read a man page inside a Vim buffer, using the :Man command described in :h :Man: MAN ...
5
votes
5answers
3k views

Match any number of digits NOT followed by

I want to search for: From start of the line, any number of white spaces followed by any number of digits NOT followed by a dot. And replace it with all that was searched and a dot. This is just ...
4
votes
2answers
537 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 ...
4
votes
2answers
334 views

Copy text based on delimiting strings

I see how to copy text in vim using visual mode, arrow keys, y to yank, and p to paste. I also see how to find a given starting string using back slash. However, I'd appreciate knowing how to copy ...
3
votes
3answers
1k views

Delete all of a file except for certain words that contain certain letters

I have a file that contains words that I want to save, along with other junk that I do not need. I just want to delete everything except the words that contain a certain pattern. Take email addresses ...
3
votes
1answer
185 views

case-sensitive * with ignorecase on

I like the behavior of the 'smartcase' option, which lets searches I type in by hand be case-insensitive by default, case-sensitive when there are any capital letters. I also like the behavior of the '...
3
votes
1answer
140 views

How to jump to a next or previous specific character ignoring linebreaks and not destroying highlight or overwriting my registry?

I have not found much use for ()[]{}, and so I want to map them so it does a find command, jumping to the previous instance of that particular character. Thus, ) will jump forward to the next ), ...
3
votes
1answer
101 views

Get immediate feedback about a search string with no matches in vim

Is there a way to immediately get feedback about a search string with no matches? At the moment I have to press Enter first to get Pattern not found. I'd like if the background (of the search line or ...
2
votes
0answers
140 views

Search within syntax group?

Is there a way to take advantage of syntax highlighting for searches? For example, can a search be limited to comments or non-comments, if they are correctly marked by syntax highlighting?
2
votes
4answers
86 views

Search for line, move to end of search string, then search+replace

(EDIT: In the original question, I had accidentally used \w instead of \<. Comments and answers with \w should be interpreted as using \< as well.) In my LaTeX source files, section headings ...
2
votes
1answer
217 views

How to print a multi-line match?

I've a file where I would like to extract a multiline pattern in non-greedy way (similar to this scenario) by using ex editor. This example works fine: $ ex +'/aa/,/cc/p' -scq! <(echo -e "start\...
0
votes
1answer
380 views

Run a command on every match of a search (not on the line)

I am trying to run a command on every occurrence of a search match. So, If i have some thing like this where a search match matches only these two anchor tags, .................. <a src="****" &...
0
votes
1answer
60 views

How do you substitute on previous matches?

For example, if I have the following: MY_VAR = "hello world" print "the var %s" % MY_VAR If I position the cursor on MY_VAR and press *, Vim highlights both matches. Suppose I want to rename this to ...