Questions tagged [search]

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

Filter by
Sorted by
Tagged with
2
votes
6answers
287 views

How to replace a list of numbers (or times/timestamps) with their sum?

For example, this text: 2:26 3:04 3:14 5:38 4:12 10:30 6:29 6:53 11:49 9:33 4:17 7:49 6:10 6:04 6:28 6:40 4:21 (These are actually minute:second format, not hour:minute, if it matters. So ideally ...
5
votes
1answer
97 views

Highlight words with no other occurence in file

Say I have a list of strings in my code, for example : var array = [ "foo", "bar", "John", "Doe", "Mary" ]; test("foo"); test("bar", "Doe"); Those strings are repeated at the ...
4
votes
3answers
188 views

How to find the next SpellLocal

I am curious to know how I can find the next instance of a SpellLocal mistake (either by a motion key or via a search command) in vim.
3
votes
2answers
2k views

Search entire file for a pattern; every time it's found, delete up until a certain character appears

I'm trying to search for the string /c in the entire file, and when it's found I'd like to delete everything - including the /c itself - up until the next occurrence of / (but not the / itself). For ...
4
votes
2answers
7k views

How to find multiple instances of same character on single line?

I have a CSV that uses ,(comma) as the delimiter. This CSV is nearly 20K lines long and there are 10 instances where a comma was used INSIDE the data. These errant commas are breaking my processor. ...
4
votes
4answers
2k views

Project Wide replace using Ag

Referencing Post: https://stackoverflow.com/questions/22206332/vim-ag-search-and-replace-globally-and-within-a-directory Specifically: :Ag foo :Qfdo s/foo/bar/c I type Ag miwt-os, I get this: ...
7
votes
2answers
3k views

gvim search query for mixed AND & OR conditions

Hi I want to search text inside gvim with the following criteria a&b&(c|d). I know for a&b it is /.*a\&.*b and for c|d it is /c\|d but combining these two doesnt work. what can be the ...
2
votes
1answer
75 views

How does this search-and-replace command work? `:g /start1/.,/start2/-1 move /end/-1`

I read this description of a different example, substitute command and it was very helpful, but I'm still not fully certain how to interpret the commands in :g /start1/.,/start2/-1 move /end/-1. It ...
10
votes
3answers
297 views

Alternative to escape slashes in search and replace for long strings

Is there any alternative in vim search and replace for strings, than having to escape every special character in string. For example, If I want to match following string and replace with something [...
4
votes
2answers
7k views

Match everything before first occurrence of a character

I want to find all the characters upto the first occurence of the character "/". I tried using /.\{-}\/ but this included every character upto the last occurrence. for example, test/path/...
5
votes
2answers
3k views

Do a forward slash search but don't have vim immediately jump to the string?

When I do a /someStringtoFind in vim it immediately jumps to the closest matched string. Almost always this is what I want it to do. Sometimes though, I want to be able to enter a string to find and ...
3
votes
1answer
597 views

Conditionally delete xml tags

In a file containing tags like these: <div class="myclass"> Something irrelevant. </div> <div class="myclass"> MATCH ME </div> I would like to delete all tags not containing ...
4
votes
1answer
580 views

if/else condition for matching a regex in a file [duplicate]

I want to run a function with a condition that checks for ANSI color escape codes when I open files but I don't know how to write the condition. I expect it to look something like this: if ? '^[[0;...
11
votes
3answers
405 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 ...
5
votes
1answer
867 views

Search and highlight two different strings in different colors

I have a situation with typesetting a book in which the quotation marks are all screwed up. The author used a variety of marks¹ and apparently didn't believe in discriminating between them. I've ...
3
votes
2answers
1k views

Vim navigate to next dot symbol in text

I'm trying to navigate to next dot in a file using windows version of vim: f. but it doesn't do anything as well as all other similar commands: F. d. D. What is correct way to do it?
3
votes
2answers
284 views

Find based on text objects

I am a big fan of text objects, and I like their composability. For example, if I have \label{sec:this-is-a-section} I can easily copy the sec:this-is-a-section part by navigating inside, and ...
1
vote
1answer
1k 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 ...
6
votes
1answer
971 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
287 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\...
13
votes
3answers
796 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
16k 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, ...
14
votes
2answers
6k 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 ...
3
votes
1answer
417 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
458 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
331 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
126 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
70 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'...
3
votes
1answer
239 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 '...
2
votes
3answers
227 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
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
2answers
126 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:...
19
votes
1answer
5k 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
736 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
340 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.
9
votes
1answer
25k 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
66 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
545 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
84 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
788 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
4k 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) ...
2
votes
1answer
127 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 ...
5
votes
1answer
197 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
733 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
354 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 ...
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 ...

1
4 5 6
7
8