Questions tagged [search]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
76 views

how to write following pattern in vim?

I am sorry for the rather fuzzy title of my question. I am working on some text, which I take from web-page and try to annotate it with LaTeX commands using Vim. How can I write in Vim following ...
0
votes
1answer
164 views

Copy lines matching pattern, then substitute

I want to search file for pattern, duplicate every line that matches that pattern, then in perform substitution on each duplicated line. Suppose file looks like this: a 1 a 2 b 1 b 2 c 1 c 2 I want ...
0
votes
2answers
136 views

Why when I type * over double slashes '//' doesn't vim highlight it as a search word?

Let's say I have // that is just a comment // that is just a comment // that is just a comment // that is just a comment // that is just a comment And I want to type * at // to use the command cgn ...
0
votes
1answer
89 views

Search for 2 but not for 3 tab characters

I want to search in Vi for two tabs but not for three or more tabs. I tried several things like this: /\t\t\(\t\)@! But nothing works. Any idea?
3
votes
1answer
521 views

How to put space before and after operators for enhanced readability?

I want - variable++; then variable ++; variable1 + variable2 nothing to do variable1 +variable2 then variable1 + variable2 variable1+ variable2 then variable1 + variable2 variable1+variable2 then ...
0
votes
1answer
108 views

CursorHold event not working on nohlsearch

I added set hlsearch to highlight my searches which is helpful. And I can turn it off by using :nohlsearch or remapping that to a key. But when I tried to use it on CursorHold event, it doesn't work. ...
1
vote
1answer
101 views

How to use zero matches in regular expression?

I have following text _printer _printer _printer _printer _printer _printer _printer _printer printer and I want to find the last one by using a search for the text printer which is not preceded by ...
1
vote
1answer
272 views

Search confuses periods and underscores

I'm debugging a problematic function that imports another function with a similar name - read_table vs read.table. I've examined the file in sublime, which concludes that there are no instances of ...
1
vote
1answer
128 views

Highlight the current word… or using :let and <cword> together

I'm trying to do this: nnoremap <leader>* :let @/ ="<cword>"<cr><bar>:set hlsearch<cr> but can't get the first bit to ...
1
vote
1answer
298 views

How do you use variables in a search?

I'd like to pull out a variable something like this to save repeating the same thing let s:twoLinesStartingWithWords = '^\w\+.*\n\w\+.*' "next/previous definition nnoremap <Leader>n /\=s:...
2
votes
2answers
77 views

search nongreedily for a bunch of terms delimited by parentheses

I have something like the following text ( parens ) ( 1 + growth ) (1+growth) (1 +growth) ( parens ) and I'd like replace every instance of ( 1 + growth ), regardless of whitespace, with say, ...
1
vote
2answers
73 views

don't retype search

When searching for something in vim or gvim, I use the /. If I make a type and press enter, I need to type the string in again, hopefully a second time without a typo. Is it possible to configure vim ...
0
votes
1answer
102 views

Vim - find an occurence of a pattern one by one and and edit it at once

I would like to be able to find an occurence of a pattern, highlight it, go to the next occurence of the pattern, highlight it, go to the next one, and so on and so forth, and on the end delete all ...
6
votes
3answers
841 views

Delete block of code if a pattern is (not) detected in one of the lines

I have managed to do this with a super long find-replace but I'm sure there's a simpler way: I have a file of the form: E01 2017 10 24 00 00 00-1.90001e-04-8.79280e-12 0.00000e+00 3....
0
votes
1answer
323 views

Search and replace multiple files [duplicate]

I have several files where I want to change a word in several files from oldWord to newWord. Please note I want to do this with the new cpo feature. I also would like to do this in one command line ...
0
votes
1answer
199 views

Is it possible to use vimgrep with file paths from a file?

I have a quite large directory that I frequently need to search through for specific lines. Currently I simply use the built in grep: :vim "search" **/*.cpp | cw The problem is that going through ...
1
vote
1answer
405 views

Search query to match multiple instances on a line, only between certain delimiters?

I do a lot of programming in Ruby, and a common edit suggested by Rubocop (a linter) is to reformat an array of symbols [:foo, :bar, :baz] as a percent string: %i[foo bar baz] I'm looking for a ...
2
votes
1answer
390 views

How do you clear highlighting if you edit text?

I find it obnoxious that highlight search stays on until you manually turn it off. If I have edited some text after searching, 99% of the time that means I found what I was looking for and I don't ...
3
votes
1answer
102 views

repeat search in vim: count is off by one sometimes

I've happily used count prefixes on search commands in vim for probably a couple of decades, so I know they used to count correctly. 5n was equivalent to n 5 times. As of some recent version, 5n is ...
2
votes
1answer
135 views

vimscript: strange behavior of search() with flags 'be'?

vim-help :h search() says it start search at column 0 of cursor position. Search for regexp pattern {pattern}. The search starts at the cursor position (you can use |cursor()| to set it). .... ...
2
votes
0answers
74 views

why does cpo-=c cause perceptual “lag?”

I'm using a CursorMoved autocommand with searchpos to do highlighting of special words. I've been using set cpo-=c to handle possible overlapping matches, and I restore it afterwards. This set seems ...
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?
36
votes
5answers
9k 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'...
3
votes
1answer
56 views

Is it possible to open multiple files at the end or at the first occurrence of a string?

To open multiple files at a time I use this command (here using the vi tab feature): vim -p file1 file2 ... fileN If I want to open a file at the end or at the first occurrence of a text: vim + ...
0
votes
1answer
144 views

why doesn't ag in my vimrc ignore multiple patterns [closed]

I have this in my .vimrc: " The Silver Searcher if executable('ag') " Use ag over grep set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ wiki --ignore\tests endif " bind \ (backward slash) to ...
0
votes
1answer
389 views

Find two consecutive non-empty lines

I want to find two consecutive non-empty lines. AAA BBB AAA BBB AAA BBB AAA BBB The file above shows four pairs of consecutive non-empty lines. All of the lines can have trailing ...
2
votes
2answers
2k views

vim how to move last word of each line to beginning of line using regex and backreferences?

I've been trying to select all characters except the last word (2 groups where 1 group is everything but the last word and the other group is only the last word) :%s/^.\+\([^\w\+]$\)/\2\1/g is what ...
1
vote
1answer
29 views

How to search and replace each hit with a multiline register in which each hit is replaced with an individual line from the register?

so if i have the following multiline text in my register +: ZERO SIGN CARRY AUXILIARY PARITY OVERFLOW INTERRUPT DIRECTION TRAP And I have the following code: case ZERO : ...
1
vote
1answer
80 views

Search pattern for an if statement that isn't followed by curly brace on the next line

How would I formulate a search pattern for matching if statements that don't have an opening curly brace on the next line? I assume it requires the use of something like [^{] or \@!, but I'm having ...
2
votes
2answers
5k views

Search a string excluding the lines starting with another string

In a fortran code for example, there are lines like c write(6,*) "some text" write(6,*) "some other text" How would I search for lines having a write but exclude all lines starting with c or ...
1
vote
1answer
93 views

How to remove all words which doesn't match the pattern?

I've the following content: a1a foo bar buzz foo b2b bar buzz foo bar c3c buzz foo bar buzz d4d where I can match all words consisting only alpha characters by the following pattern: /\<[a-zA-Z]*...
9
votes
4answers
663 views

Can I use “gf” (or similar) to open a file and jump to a search term?

Is there a way to get vim's gf command (or something similar) to recognize a +{cmd} argument for file-paths? One can start vim and go directly to a search term by doing: $ vim +/coding_effort ~/...
7
votes
4answers
253 views

Use pattern of global ex command found on a line to substitute in another line

In my fortran code I have a lot of blocks like the following subroutine name(arg1,arg2,arg3,...) : end subroutine and I want them to become subroutine name(arg1,arg2,arg3,...) : end subroutine name ...
2
votes
1answer
183 views

How can I center the window on each search result

When searching for /a_string and getting several matches, I can cycle through them with n, but I'd like the editor window centered on each matching line so I don't have to move my eyes around all the ...
0
votes
1answer
317 views

How to use the JS regex engine instead of the built in engine?

Is it possible to use the javascript regex engine instead of built-in one for search and substitute?
0
votes
2answers
112 views

Search and replace all next word

If I had something like a list of #defines in a c file, say #define a #define cd #define blah and I wanted to replace all the #defines to capitalized characters, can I do this in a single ...
5
votes
2answers
614 views

Stay at matching search result after escape

For years I unknowingly used some, shall we say, deviant distribution of vim that would stay at the location of the highlighted search result after hitting <Esc> in the middle of a search ...
1
vote
1answer
69 views

How to print only pattern, not a line?

I've got the following shell command: $ ex +'/>\zs\w\+\ze</p' -scq! /dev/stdin <<<$"foo>bar<buzz" foo>bar<buzz however it's matching the whole line, instead of the pattern....
3
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 ...
6
votes
2answers
210 views

How to store all occurrences of a multiline search in a register?

I'm not sure if I've failed at searching for the answer to this, but now I've worked it out I wanted to document it here. The problem is searching for a multiline pattern, and storing all such ...
0
votes
1answer
127 views

Vim with syntax highlighting has slow searching in XML

My experience is that Vim is slow when searching in large XML files with syntax highlighting turned on. I find it to be very dissatisfactory. I have read about the issue elsewhere but I have not been ...
1
vote
2answers
94 views

How do I replace only the current instance of the search pattern without losing the pattern?

I often find myself doing an interactive search and replace for a string that may be either a whole word or a partial word, such as changing bar to jaz and also foo_bar_blah to foo_jaz_blah. So I can'...
3
votes
1answer
172 views

How to set nowrapscan when formatting text with gq

When I was editing a fairly large text, I accidentally hit gq* instead of gq} and then vim apparently seemed to freeze a moment with the message search hit BOTTOM, continuing at TOP displayed in the ...
0
votes
1answer
349 views

Jump to next occurrence of the current character

I often navigate to the next occurrence of the current non-paren character. For example, `HTTP GET www.example.com/example/com` is an example URL. When the cursor is at the beginning of the line at ...
14
votes
1answer
1k views

Is it possible to get the matched string after calling :search()

In a vimscript-function, I need to assign a matched string to a variable l:matched after calling search() and I am wondering if there is a shorter way than what I am currently doing: let l:pattern =...
1
vote
1answer
41 views

How to assign a search range selection into a register?

I'd like to assign the result of search range selection into a register, instead of printing it, e.g.: :/pattern1/;,/pattern2/p What syntax I can use to achieve that?
3
votes
1answer
43 views

How to check if a pattern is contained in a register's content?

I'm writing a new plugin and as part of a function, I need to check that a register contains a particular pattern. I checked the official documentation but couldn't manage to use any of the search() ...
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 ...
1
vote
1answer
33 views

How to get a variable with the contents of a file on the filesystem?

I intend to use this to optionally share the search buffer between different Vim instances. I'll have a file on the filesystem that contains the content. So it means I need to set the search register ...
1
vote
2answers
445 views

Replace two word sequence with second word

I need to replace on all lines sequence of words: public boolean public string public IList etc.. with modifier removed aka: boolean string IList Is there a way how to remove first part of match ...