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
94 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
500 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 ...
2
votes
1answer
74 views

Break-down long strings and search/replace individual words

I am trying to do a search and replace in vim (rather, gvim) and keep getting stuck up trying to separate words. I need to convert something like this: (COND <ASEL&~ASELb|XOR|~XORb> ( To ...
0
votes
2answers
392 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
343 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
854 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
332 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
253 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
240 views

How to run vim from command line and prevent press ENTER or type command to continue

I have a bind that invokes vim on a file with a search term: This is shell scripting. vim $FILE "+/$SEARCHTERM" The problem that happens is that only if $SEARCHTERM appears just once in a file, it ...
1
vote
1answer
548 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
445 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
82 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
96 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
172 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 ...
2
votes
1answer
503 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 ...
5
votes
3answers
940 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
851 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 ...
1
vote
2answers
593 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 ...
1
vote
1answer
396 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 ...
2
votes
1answer
1k 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 ...
2
votes
1answer
434 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
87 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 ...
3
votes
1answer
62 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
411 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 ...
2
votes
1answer
682 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 ...
3
votes
1answer
162 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
2answers
4k 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
38 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
398 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]*...
68
votes
12answers
19k 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 ...
2
votes
1answer
511 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?
2
votes
1answer
894 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
2answers
129 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 ...
1
vote
1answer
84 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....
2
votes
2answers
166 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'...
1
vote
1answer
132 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 ...
6
votes
3answers
4k 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 ...
3
votes
1answer
495 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
1k 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 ...
3
votes
1answer
52 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
5k 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
36 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
853 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 ...
1
vote
2answers
303 views

is search a true mode in vim?

Listed here is "each mode" for vim. I did not see "search" in the list, but I should think that search (/ or ?) would be a mode on its own. I have to make a very formal presentation about my ...
9
votes
2answers
1k 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
3answers
150 views

Copy a line, comment it and replace a word in copied line

Libraries evolve all the time and I often face the situation where after an update some function name have changed and they return errors in the updated version of the library. It's easy to replace ...
6
votes
2answers
2k views

How do I jump to the next line with the same indent level?

I have a space formatted (yaml) file like the following: en: templates: template: "VERYLONGTEXTHEREWITHHUNDREDSOFLINES" destination: "I want to jump here" other: stuff ...
0
votes
1answer
360 views

Toggle search highlight while on match

I'd like to have search highlights (set hlsearch) while the cursor is on a match and to turn it off automatically (set nohlsearch) when I move the cursor away. Example: foo bar foo text text bar ...
3
votes
1answer
541 views

How to delete blocks of text which contain a specific string?

I have a file which has the following structure From: foo@example.org Subject: Bar Date: 2017-06-27 Mailbox: /some/dire/ctory <CR> Such a block always contains of four lines followed by an ...
4
votes
1answer
82 views

Make * stay on current keyword

I often use * with cgn and end up missing the first match (or doing *N...). So I'd prefer for * to stay where it is. nnoremap * *N Does almost what I want except it recenters the cursor line. Is ...

1
3 4
5
6 7
9