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
21 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/...
1
vote
1answer
185 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
484 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 ...
2
votes
2answers
106 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
19 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
80 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
46 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
3answers
99 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 ...
0
votes
0answers
46 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 = ...
1
vote
1answer
603 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
22 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 ...
0
votes
1answer
36 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
112 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 ...
0
votes
1answer
197 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 ...
15
votes
2answers
6k views

search for lines which contain a pattern but do not contain a second pattern

I need to search for lines which contain some word but do not contain a second word. For example, find lines that contain the word "This" but not the word "red" so that for a file containing these ...
2
votes
1answer
128 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?
4
votes
1answer
2k 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
106 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
31 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
195 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
89 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
1
vote
2answers
74 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 ...
14
votes
4answers
9k views

When to use :grep and :vimgrep in vim?

In vim :make makes it easy to build and fix errors, and :grep and :vimgrep behaves like :make. But why do you need these two commands? Why not just search for the pattern and just press n? What are ...
0
votes
3answers
62 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
376 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 ...
1
vote
1answer
75 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: ...
54
votes
11answers
11k 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 ...
8
votes
2answers
761 views

How do I make list of search results editable?

There are several times, I need to grep for some_pattern in some XHTML files (many a time, file count in a specified folder goes beyond 10K+). Previously, I have used Lugaru's Epsilon Programmer's ...
1
vote
1answer
37 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
41 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 ...
4
votes
3answers
545 views

How can I make a search in vimscript let n and N look for more?

I'm writing a script that does a search like so: normal /needle^M. This works like I want, except that I want to be able to use n or N to repeat the search. In case it helps, here's the full ...
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 ...
11
votes
7answers
3k views

How to search for lines matching current line in vim

I usually search for words by :/string, but if I have to search entire current line, how to do that. event: 1 beacon: 0x02 //line 1 event: 19 beacon: 0x02 //line 2 event: 1 ...
1
vote
2answers
575 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 ...
1
vote
1answer
41 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 ...
4
votes
1answer
63 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
77 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
25 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
1
vote
2answers
331 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 ...
0
votes
1answer
97 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 ...
18
votes
3answers
709 views

How can I get ‘n’ to go forward even if I started searching with ‘?’ or ‘#’?

Vim has (at least) two sets of commands that search in opposite directions. Typing / and then a pattern will search forward through the document for the pattern; typing ? and then a pattern will ...
7
votes
1answer
3k views

find next occurrence of word or line at cursor

For example when editing a big .gitignore file and pasting in a block for a newly added toolset's suggested ignore patterns, I manually looked at each line and typed /\.filetype where filetype is what'...
2
votes
1answer
66 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
1answer
53 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
612 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
52 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 ...
1
vote
4answers
244 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 ...
2
votes
1answer
59 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 ...
0
votes
1answer
114 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 ....
1
vote
1answer
129 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 ...