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
0answers
3 views

Find location of matched pattern

I am using matchadd() to match some text in a line. Using Vim script, how can I jump to the matched text? Or, instead, how can I get the column number of the start of the match? Motivation: I have ...
1
vote
1answer
19 views

How to replace the first matching for each line with regular expression

Saying that I have such a file as below: <random_string>hello<random_string> random_string<random_string>hello<random_string> I want to remove the first square bracket and ...
-1
votes
1answer
29 views

search one word containing # with *

I would like to search the word under my prompt on vim. For this, i tried to press touch *. But, if the word i want to search is #foo, as an exemple, vim only searches word foo (without hashtag), so ...
3
votes
1answer
44 views

How to make vim spell error search the current line only?

This vim binding will make <C-l> correct the previous spelling mistake: inoremap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u How do I modify it to make it correct the previous ...
2
votes
1answer
27 views

Difference between searching and substituting pattern matching

I have a string in a JSON file which is repeated with different values for chance. I want to replace all of these blocks by moving the miss chance out of the attack array and into a separate property. ...
0
votes
3answers
52 views

How to search in beginning of line and add something at end of that line

I want to search lines beginning with certain string in Vim, and then add something at the end of file. I have tried the following but it removed everything instead of appending :%s/^12138/*...
2
votes
0answers
34 views

Is it possible to call searchpair or searchpairpos on string instead of current buffer?

searchpair or searchpairpos works only on current buffer. Are there similar functions work on string instead of buffer?
0
votes
1answer
24 views

Can you match unicode blocks by name in vim?

\p{Cyrillic} Works in my normal regular expressions. When trying to match in Vim or gvim however, I can not seem to get it to work. I tried something like this: \p\{Cyrillic} Is it not supported, ...
0
votes
1answer
44 views

Are there any built-in functions to search sorted list?

Are there any built-in functions to search sorted list? Such as binary_search, lower_bound, upper_bound, etc.
1
vote
1answer
35 views

How to search for any repeating character, X number of times

Let's say a buffer has a certain characters I know will be repeated seven (7) times. How can I search for any character repeated seven times? I know I can search for .., but those to characters won'...
3
votes
2answers
91 views

creating a “:KeepCursor” command

I'd like to make a command that works like this: :KeepCursor {cmd} will the given execute ex command string, then restore the cursor's position. A primary example is: :KeepCursor normal! * which ...
0
votes
2answers
36 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
83 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
31 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
49 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
19 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
18 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
84 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
45 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
252 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
57 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
26 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
29 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
55 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
134 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
19 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
98 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
32 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
83 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
85 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
53 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
75 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?
2
votes
1answer
694 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
95 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
28 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
161 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
63 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
55 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
58 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
56 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
56 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
33 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
39 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
94 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
30 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
296 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
47 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
46 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 &...