We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [search]

Searching for text with / or search(). For find/replace operations, use tag [substitute] instead.

Filter by
Sorted by
Tagged with
0
votes
1answer
32 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 ...
6
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 \...
3
votes
1answer
1k views

How to have forward search using Zathura PDF viewer and LaTeX-Box plugin?

I just started using Zathura to view pdfs while editing tex files. I am trying to have forward searching capability in Zathura. Using the LaTeX-Box plugin in Vim, I have added the following in my ...
17
votes
7answers
13k views

How to automatically turn off “hlsearch” after I'm done searching?

I love the "hlsearch" setting, but after I'm done searching, I find it obnoxious. Especially if I search for something that has a lot of matches. I know that I can turn this off with :set nohlsearch ...
3
votes
3answers
689 views

Apply a command to each occurrence of a pattern in a range

I have 'a and 'b bounding some lines of text. I want to convert all the w, h, n, and m variables to upper case. A sample line: f(w,h,n,m) | w <= 0 | h <= 0 | n < 0 | m < 0 = 0 It seems ...
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 ...
11
votes
3answers
963 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'...
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?
2
votes
1answer
415 views

Overriding highlighting style for one syntax

My colour scheme (morning) doesn't play nice with the quickfix window: I cannot read the selected item's location, because the foreground and background colours are the same. Because of this I want to ...
15
votes
4answers
1k views

How can I search for a string between certain line numbers?

This is a problem I had recently. I have a file with several hundred lines of text. How can I search for a string between two specific line numbers? For e.g. I want to search between line numbers 100 ...
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 ...
3
votes
1answer
26 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 ...
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 ...
4
votes
2answers
208 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 ...
0
votes
1answer
78 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?
0
votes
2answers
237 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 ...
61
votes
10answers
61k views

How can I clear word highlighting in the current document (e.g. such as after searching for a word)?

When you search for a word in a file with something like /console.log, all of the instances of console.log are highlighted. When you're no longer interested in these, the highlighting can be ...
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
68 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
696 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 ...
17
votes
4answers
5k views

How to show search results for all open buffers

One thing I often do (but rely on the command line to do) is searching/grepping in multiple files. Is there a way to display search results for all the open buffers? Ideally, I'd like to have a new ...
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 ...
1
vote
2answers
500 views

vimgrep can not find a pattern in specified directory

I have encountered very strange problem using vimgrep command. I try to find a match in all the files in all subdirs of a specified directory: :vimgrep /word_I_search/ path\to\my\dir\**\* (there are ...
0
votes
1answer
47 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 ...
8
votes
2answers
2k views

Multiline Search and Replace

Would like to perform a search and replace in a file with 12000 lines. Specifically, if an occurrence of ^ SetFontSize 28 exists after a ^Hide block and before the next ^Hide or ^Show, change 28 ...
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 ...
3
votes
2answers
101 views

Jumping to one character past the search

I understand that f jumps to the first matching character, and t jumps to one character just before the first matching character For example, given the string VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, I ...
30
votes
7answers
17k views

Show only matching lines?

In a long file, I would like to search for a pattern that will match roughly 200 lines or so. The matched lines are in random places in the file. When a line matches, only the line itself is relevant, ...
68
votes
6answers
37k views

Is there a way to count the number of occurrences of a word in a file?

Is it possible to count how many times a word or a pattern appears in a file? This is sometimes useful to find out how many times a function has been called, etc.
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 ...
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

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
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
43 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
62 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/*...
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, ...
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 ...
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 ...
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
340 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'...
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 ...
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
2answers
43 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 ...
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
184 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' ...