Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [search]

Searching for text with / or search()

2
votes
2answers
82 views

Can I use a different color for the selected match than for other matches

In the screencast below I searched statusline and then cycle through the results with n. Is it possible to highlight the selected match with a different color than the other matches, instead of ...
0
votes
1answer
27 views

Grep on type with delay. Scripting / Looking for plugin

I use fzf.vim (with rg) to search through (grep) my project. The problem with this implementation is that (from what I understand) fzf.vim joins all the files (adding filename at the beginning of the ...
0
votes
1answer
52 views

Vim can't search for dot

I'm trying to write a Vim script function to toggle between -> and . but searching for . is seemingly impossible. I've tried to search using ASCII (decimal and hex) and it doesn't work. It all ...
0
votes
1answer
67 views

Asterisk search does not find text with question marks

In gvim normal mode, the * key searches for the word under the cursor. Say I have a file with the following lines: life alifexea a_life_xea a life x a=life life=a b=life; c=b?life:a; life? ?life ...
1
vote
1answer
42 views

How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?

Based on the accepted answer to this previous question, I put the code below in my .vimrc, which changes the color of my statusline depending on whether my search (started with / or ?) yields results ...
0
votes
0answers
23 views

Search multi-line records separated by multi-char sequence

I have been looking online for an answer for weeks now, but I am still at a loss... (I didn't learn much from syntax highlighting, and can't find any way to make \._ exclude a match) I have a file ...
2
votes
1answer
58 views

How to yank count of matches of a pattern to a register?

%s///n show number of matching pattern like 102 matches on 102 lines. How to copy this output to a register?
1
vote
1answer
69 views

Faster way to search for whole words

I can search for whole words like this /\<search term\> \< and \> match left and right word boundaries respectively. But how can I insert those automatically? They are awkward to type ...
3
votes
1answer
88 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 ...
1
vote
2answers
22 views

Swap grid[X][Y] to grid[Y][X] in full file

In my file, I have many instances of grid[X][Y] where X and Y are variables. I would like to swap all instances to grid[Y][X] (preferably one by one so I can check them). Examples (especially note ...
4
votes
1answer
139 views

Replace With Text From The Line Above?

I have a text file like this: ge-0/0/45.0,First-Floor-Security,13 ,Voice_First_Floor,18 ge-0/0/46.0,First-Floor-Security,13 ,Voice_First_Floor,18 ge-0/0/47.0,AV-Media,155 ,Building-Automation,75 ,...
0
votes
1answer
36 views

Match all digits but not string

I'm trying to find a pattern that will match for any digits, except ":3" I've tried this /\v(:3)@!&\d But it doesn't work and I've no idea why
0
votes
1answer
42 views

Remap / to a another search function?

I there a way to remap / that trigger builtin search function of vim to another search fuzzy function and how to achieve that?
1
vote
2answers
53 views

Search and replace multiple line items within a range?

The following search command will make a range and search/replace within it. Specifically, it looks for 'first' in the text, then stops when it finds 'second' across multiple lines. Then, within that ...
0
votes
3answers
48 views

Append `0,` to all lines having 2 commas and not more than 2 commas?

I have a file 0,3, 7,2,0, 1,2,3, 1,2, which should be 0,3,0, 7,2,0, 1,2,3, 1,2,0, So how can I append each line with two commas with 0,? I am interested in the most elegant solution and ...
1
vote
1answer
33 views

How to exactly search current word?

Want to exactly matching current word with below function. function! My_Exact_Search () let CurrentWord = expand("<cword>") exec "/\<".CurrentWord."\>" endfunction But get error: ...
1
vote
1answer
31 views

Search not behaving as expected

I have the following bit of text in a vim file with cursor where the asterisk is while in insert mode: \begin{document} [latex] Some text* [\latex] \end{document} \begin{document} [latex] [\latex] \...
1
vote
1answer
38 views

Match and replace very specific number

I would like to replace every number n in my document with n+1. Easy: :%s/\([0-9]\+\)/\=(submatch(0)+1)/g Now I would like to replace every number n with n+1, only when the number has exactly three ...
0
votes
0answers
49 views

Highlighting a search capture group

By :set hl, the search result of a / expression is highlighted, for example: And if one wants to replace one substring distinguished by its surrounding, one can do so elegantly using regex capture ...
0
votes
0answers
34 views

Sublime Text *like* project handling

Sublime Text has the concept of projects which map to a folder. When you search for a file or search for text within files, sublime presents the following search form: Find: Hello World Where: <...
1
vote
0answers
42 views

change ofWord to of Word, and ignore offer, office, off etc

I OCRed a document but has this problem: some spaces between "of" and the word after are gone and I need to add a space between "of" and "word". Is there any way to do it? And also to avoid adding ...
1
vote
1answer
26 views

Pasting from register to command line inserts ^M instead of new line

Say I want to search for multiple lines (or do anything with them in the command line). I yank some lines and enter search mode (/). I press Ctrl + r" to paste what I just yanked, but I get ^M for ...
1
vote
2answers
88 views

How to match braces or brackets?

Suppose I want to search for things like \todo{English sentence} Then the regex \\todo{\_.\{-}} works (I don't know why. I copied it from somewhere long time ago (embarrassed)). But suppose I ...
4
votes
1answer
43 views

Add ^M character in mapping without entering <CR>

I've run into the problem mentioned here, but in a context in which I don't have an easy alternative that I can think of. I'm trying to add a mapping to fix bad newline characters in a file. I would ...
2
votes
1answer
31 views

Search and Replace in each PATTERN with counter [duplicate]

I am trying to search and replace certain pattern "\x" to REPLACE_counter. Where counter goes from $0$ to $N$. The text is \x & \x & \x & \x & \x \\ \cline{1-1} \x &...
0
votes
1answer
23 views

map something to the action of the leader key?

I have this in my vimrc: let g:mapleader = "," nnoremap # , so I use , as my leader, and want to use # for backwards search after f,t...But my # mapping does not work, so something is amiss thanks
0
votes
1answer
53 views

Any way to prevent :Ag search from automatically opening the first returned result?

Whenever I run an :Ag search on my present working directory, the first entry in the returned results list is always automatically opened in the currently active pane. Is there any way to disable ...
1
vote
2answers
108 views

How to redirect search results into a new file?

Let's say, I want to search for email addresses and output them to a new file. What I can do so far with a help from another discussion is this: g/pattern/.w! >> output.txt but that saves ...
10
votes
3answers
611 views

What's the difference between the '\zs' and '\@<=' atoms in Vim regex?

This is what I get from the documentation: \zs "starts the highlighted part" after matching the preceding regex, and \@<= "starts the highlighted part" after matching the preceding atom. But I don'...
0
votes
0answers
26 views

Make n search downward all the time regardless of / or? [duplicate]

I've been finding that I'll oftentimes forget whether I searched forward or backward using / or ? and then when I use n and N to go to the next result, I get disoriented trying to remember if it would ...
0
votes
1answer
51 views

Setting the search pattern to just a portion of a regex pattern

I'm not sure if the title makes sense, but I'll try to explain what I'm trying to do. I have a file with some code like: some_var = 3; ... func(some_var); The file has a bunch of calls to func and ...
1
vote
1answer
338 views

Find the nth word in a line, and replace it back into the line in different position

I have searched unsuccessfully everywhere for an answer to this question and could not find an acceptable answer. I am taking a list of table names from a database, and dynamically creating alter ...
0
votes
2answers
51 views

limiting global search&replace to matches that occur immediately to the right of the cursor

If I have this line: a{word} a{20] a{word} a{20] and type :g/a{.\{-}\]/s/{/\[/gc vi prompts me to change all four occurrences of { to [. I want it to prompt me to replace only the matches ...
3
votes
1answer
77 views

How to display in the statusline the number of matches from a search?

I've seen this question: Is there a way to count the number of occurrences of a word in a file? but most of the time I search using * or just /. It is possible to display automatically in the ...
1
vote
1answer
121 views

How can I change the colors used for highlight search matches?

When I do a search within VIM the found text is highlighted in yellow with white letters. For my eyes it is impossible to distinguish the text highlighted. I am looking for the way to change those ...
2
votes
1answer
53 views

How do I jump to the next search result in a different window?

Sometimes I have two windows open and I search for a word that appears in both. Hitting n only cycles through the results in the active window. It'd be really convenient to somehow jump to the next ...
1
vote
4answers
147 views

Vim only show current line / hide every other line

My question is if there is a possible way to hide everything except all text except the current line? Some background: I have a really big JSON file which I just did a macro on and am doing a quick ...
0
votes
1answer
89 views

How to see the number of search return with Ag?

Is there anyway that I can see the number of result with :Ag (attached) If somewhere I could see the number of return would be awesome. I can't find any reference for it on Internet. Thanks My ....
4
votes
4answers
210 views

Is there a key to go to the next search result that is not on the screen currently?

If i press a bunch of key sequences like this: /term<cr> and there are five matches on the screen currently, i will have to press n five times to see the next search result that is not on the ...
1
vote
1answer
315 views

Find only between marks

Suppose that I have marks 'a and 'b, and I want to search for all occurrences of foo between them. The ex command :'a,'bs/foo/bar will replace only between 'a and 'b. Is there any command like :'...
2
votes
2answers
48 views

How to search and replace in the history

Is there a way edit command line or search history? I have read Is there search and replace history in vim? and tried using q: to open the history and do changes there, but all it seems to be able to ...
0
votes
0answers
26 views

Navigate to file plugin like Intellij Idea

Does any plugin exist which can index files in current directory on start, allow enter text to search, show matches in tab and open these files in new tab? Similar to Intellij Idea "navigate to file" ...
1
vote
1answer
64 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
55 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
52 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
54 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
33 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?
0
votes
0answers
110 views

Auto-complete with the slash while stepping down a path

How can I get vim to append a slash / while moving through a file system path in the command line (eg. with :tabfind) ? Right now I am force to manually type it each time. To reproduce the problem, ...
0
votes
0answers
35 views

Search not to work on each new char

After updating to Vim 8.0, I get an annoying behavior (to me) during my / searches: at every new char I insert, the search is triggered, moving my cursor away to the next interim seach. How can I ...
3
votes
1answer
256 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 ...