Stack Exchange Network

Stack Exchange network consists of 175 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()

0
votes
2answers
27 views

How to replace a string only if the line starts with another string

I need to find ONLY the lines that start with the string G1 Z, and then replace any occurrence on that same line of F1800 with a new value of F500. For example: G1 Z9.800 F1800.000 ; move to next ...
2
votes
4answers
62 views

Search for line, move to end of search string, then search+replace

(EDIT: In the original question, I had accidentally used \w instead of \<. Comments and answers with \w should be interpreted as using \< as well.) In my LaTeX source files, section headings ...
1
vote
2answers
26 views

Read-only mode in Vim while using cscope?

I am traversing through a C code in Vim using cscope. Sometimes while traversing, some key gets pressed or mouse gets right-clicked and the Vim enters in insert mode, and it creates a mess to undo the ...
0
votes
2answers
47 views

Incremental search: is it possible to push 'Esc` without scrolling back?

My problem on this gif: I am in one place, searching for meta, I do not want to loose my current search highlighting (yes I know that I can restore it later in / menu). I found what I need - without ...
1
vote
0answers
17 views

How do I keep the spacevim search results window open after opening a file?

How can I keep the search results location list window open after opening a file in a new buffer?
1
vote
1answer
16 views

how to add a word two lines above certain word in multiples places

my text look like this in several places of the file: FDE PW91k XCNADD PBE ::FULLGRID END END eor and I want to introduce a word two lines above "eor" word throughout. I have tried :,.-2/eor/...
2
votes
2answers
50 views

Search only within a relevant context?

When running through a log file, I will catch a log that's bad, and I want to search around that line for other lines that will match search parameters. Frequently the log files are very long, and ...
1
vote
1answer
27 views

Exclude folder when searching files in working directory

I'm working in a react project and opened vim from the root folder. When I'm using :vimgrep /pattern/ ** I just can search everywhere, but I want to search everywhere except the 'node_modules' ...
3
votes
2answers
200 views

How do I use 'cgn' for word under cursor?

I really like and often use the cgn command for replacing something I was currently searching for, but it sort of lacks a (imho) rather intuitive feature: replace the word (or whatever) under the ...
0
votes
1answer
18 views

Edit colorscheme to tell me which search result my cursor is currently on

When I search for a word in my files, many of them come up, and it's tough to tell which one my cursor is currently over. See image: Is there a way to edit the background color for the search I'm ...
0
votes
1answer
52 views

function to search for a pattern

I just recently found a very nice command to search for a pattern in a document, and display all hits: :g/pattern/z#.1 Since the command is a bit cumbersome to type, I would like to make a shortcut, ...
0
votes
1answer
22 views

scroll while writing a substitution

how can I scroll or move around in the code while writing a search or command ? I want to write a substitution :s/xxx/yyy but I forgot what yyy should be and I need to scroll a little bit to find it, ...
0
votes
0answers
24 views

How to get the same message and error behavior as normal `n` when calling `normal n` in function

I wrote a vimscript function that prevents the cursor from changing its location on the screen when I press n: function! my_n() let l:start=line("w0") let end = line("w$") let cursor = ...
0
votes
3answers
50 views

Find duplicate entries in two different lists

I have two different lists of words and I want to make sure that they have no mutual duplicates. In other words, none of the words in list A can be in list B and vice versa. They must be mutually ...
1
vote
1answer
60 views

How to search and replace this using vim and regex?

Input if(statement) { to Ouput if ( statement ) { I can find the input using /if(\S\(.*\)) Explanation : if( is the keyword to be searched , \S to negate whitespace , (.*) for anything in ...
0
votes
1answer
18 views

Why doesn't the + regular expression quantifier (one or more) work when searching?

I have a file with the following lines: a=117 a=100 a=101 When I try searching using /a=10*, it correctly matches all of those lines. But when I try searching using /a=10+, it does not match any of ...
2
votes
2answers
95 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
31 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
67 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
71 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
45 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 ...
2
votes
1answer
63 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
252 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
92 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
26 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
150 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
46 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
45 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
55 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
50 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
50 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
76 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 ...
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
162 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
46 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
37 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
68 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
126 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
680 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
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
416 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
83 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
181 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
159 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 ...