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
1answer
2k views

Select text till and including pattern

I want to select text from multiple lines up till and including the pattern pattern. When I use v/pattern the text till attern is selected (not including attern). How can I select text including ...
7
votes
1answer
1k 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 ...
2
votes
1answer
444 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\...
15
votes
3answers
1k 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 ...
3
votes
2answers
17k views

How to match the first occurence of a repeating pattern on the same line?

I'd like to replace the following code: ThisIsALoooongNameOfATwoDArray[100-rowIndex][j-2]-ThisIsALoooongNameOfATwoDArray[100+rowIndex][j+2]; by Ptr[j-2]-Ptr[j+2]; I tried the command :%s/This.*ex\]...
7
votes
2answers
1k views

How to easily search in the list of existing mappings?

From time to time I want to search on the list of my currents mappings. I search either for mapped keys (what /<Space>a does?) or for a command (What keys are mapped on /MyFunction()<CR>?) ...
10
votes
1answer
1k views

How to substitute in multiple lines?

I'd like to insert a word in multiple lines, is there any command like :[2,3,5,7,11]s/^/word\ /g which would insert word at the beginning of line 2, line 3, line 5, line 7 and line 11? Here, ...
20
votes
2answers
9k views

What is the reverse of the 'go to next' command

If I want to go to the next , on the line then I type t,. If I wanted to go to the previous , I could use /n, enter, N but this is a bit of a fiddle. What is the best way to go to reverse the t ...
4
votes
1answer
789 views

Search for the next line that does not match a pattern

The / command moves to the next occurrence of a pattern. But how do I move to the next line in which a pattern does not appear?
5
votes
4answers
901 views

How to search forward for pattern in the current line? Like `/` and `?` but stop at end of line

Is is possible to search for a regexp in only the current line. Here is an example line: This is some text that I have written. Can you find this word? ...
10
votes
1answer
446 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 ...
4
votes
1answer
135 views

Difference between two end of line signs

Both $ and \n represents the end of a line. To remove an empty line we can use either :g/^$/d or :%s/^\n//g My questions are: What's the difference between these two signs? It seems the first ...
2
votes
3answers
74 views

how to avoid highlighting when block commenting

I'm running the command :.,.5s/^/!& to block comment a section of code, however, after running the command the editor highlights the first character in every line of the file. I guess this doesn'...
2
votes
3answers
231 views

How to find non duplicate <type:keywords> of a file?

I need a vim shortcut to display all non-duplicate struct names in the file being edited. I have made this C program which does this, however I have to leave the editor and execute the program in bash ...
3
votes
3answers
2k 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
2answers
130 views

How to select with the same movement but on a different line

If I have the folowing file: XX:YY:ZZ foobar: some text XX:YY:ZZ foobar: some other text a text breaking the pattern XX:YY:ZZ foobar: some more text And I want to operate on the differents parts XX:...
28
votes
1answer
9k 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 ...
2
votes
1answer
857 views

Searching For a String Stored in a Register From Within a Function

If I have something stored in the named register n, then from the normal mode hitting /<C-R>n would search for what is stored inside the register. But suppose I want to write a function which ...
3
votes
1answer
433 views

To Return a True Value if Pattern Match is Found Else Return a False Value

Suppose I am searching for pattern in my text file using vim. Is there a way to store 0 in a variable foo if no matches to pattern are found and store 1 if at least 1 match is found? Thanks.
10
votes
1answer
30k views

Search for lines starting with given string in vim?

I have this code snippet: # import ipdb; ipdb.set_trace() def foo(): ... import ipdb; ipdb.set_trace() ... # import ipdb; ipdb.set_trace() How should I specify search query, that it ...
0
votes
1answer
71 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 ...
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 -...
4
votes
1answer
1k views

Change '\r' to '\n' for search and replace?

In expression :s/foo/bar\n/g When replacing \n inserts a null byte, according to the docs I have to use \r. Since I insert newlines more frequently than null bytes, is there a way to change this ...
2
votes
1answer
664 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 /&...
1
vote
1answer
90 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
1k 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 ...
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) ...
3
votes
1answer
161 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
219 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 ...
9
votes
2answers
790 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 ...
1
vote
1answer
395 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 ...
7
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 ...
3
votes
1answer
412 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 ...
10
votes
4answers
317 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 ...

1
5 6 7 8
9