Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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

search highlighting only in the current buffer

I know that I can run a search in vim using /. I prefer having search highlighting turned on, but if I have a two splits with different files open, and I search for a term in one, they get highlighted ...
0
votes
1answer
36 views

Can I use feedkeys() inside of a keyloop implemented by getchar()

I implemented a fuzzy filter, which accept a list argument, open a window with a scratch buffer whose content set to the list, then waiting for use input and do filtering. Here is why I ask this ...
7
votes
6answers
2k views

How to replace a pair of brackets

I have a file, containing some lines like this: aaa bbb (ccc) ddd. Now I want to replace the pair of brackets by a pair of square brackets to make this line become aaa bbb [ccc] ddd. I think that \...
0
votes
1answer
43 views

How to break lines into a certain amount of characters?

I have a long text file (300 lines), and I would like to format it so each line is not longer than 50 characters. For example, we have: I have a really long text, I have a really long text, I have a ...
0
votes
2answers
42 views

Search for a word and if occurs, delete it and move to the end of line

I need to search for a certain word, and if it occurs, move it to the end of the line where it occured. For instance, search for "bugs". Welcome! Meta Stack Exchange is intended for bugs, features, ...
0
votes
1answer
34 views

Search for lines that do not have certain characters in a row

I have a news article which I need to edit up a bit. Basically, I need to search for all lines that do not contain characters t and h 2 or more times in a row and replace 4 letter words with character ...
3
votes
1answer
27 views

search for pattern and insert text that precedes the pattern from pattern1 to pattern2 exclusive

basically I have a bunch of lines of code that all match the format .\module.variable (), .\module.variable2 (), I want to take everything between the backslash and the space, before the parentheses ...
2
votes
2answers
53 views

vim incremental command history search

In bash you can easily search the current history entries by hitting <C-r> or <C-s>. This search feature is incremental, and once you hit return, you get a bash prompt auto-filled with the ...
1
vote
0answers
26 views

How do I remap result navigation buttons after a search?

I search with /, press enter, and go a few results down using n. I realize that I have gone a few more results down than I meant to and want to go back a few. I press m because that is next to n just ...
2
votes
1answer
70 views

Don't jump on search and replace

How do I get my cursor to not move to the last thing it replaced after a search and replace. No <C-o> or extra key presses. Is there some autocmd magic I can setup to listen on any substitute ...
2
votes
4answers
697 views

Jump back to the position I started a search

I have a small question: let's suppose I'm at the beginning of line 10 and I search a term with the command /term_to_search and then I press <Enter> to start navigating search results with n or ...
0
votes
1answer
31 views

Add a line after 1 line after match in Ex mode

I need to search for a string in a file, then I need to some text after one line following the first match. I need to perform this for a number of files in a script. I am trying to use vim ex mode ...
0
votes
1answer
39 views

Are the contents of highlighted content saved to a register [closed]

Let me briefly explain what I am trying to do. I work on an air gap network. Anything not native to Red hat, or that I do not write is out of the question. The most popular two IDE's are VIM/GVIM ...
0
votes
1answer
48 views

What alternative to capture groups should I use in VimScript?

I understand that Vim does not support regex capture groups. The problem I am trying to solve is being able to easily capture parts of lines. For example, given the following line of python source ...
1
vote
3answers
72 views

Search for line and paste as column until next match

I'm wondering if this is possible, more for curiosity's sake, but also it might be useful to know. I have several ascii data tables and I want to combine them all into a single file. So I combined ...
0
votes
0answers
31 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 ...
3
votes
1answer
55 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
52 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
45 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
63 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
50 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
52 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
53 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
388 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'...
2
votes
2answers
98 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 ...
1
vote
2answers
49 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
88 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
44 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
51 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
1answer
29 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
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/...
2
votes
2answers
94 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
189 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
489 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
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
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 = ...
0
votes
3answers
102 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
611 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 ...
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
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
200 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
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 ...
1
vote
1answer
66 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
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 ...