Questions tagged [search]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
32 views

How do I search for lines containing a string that are followed by a line that does NOT contain that string?

I have a text file with lines like the following: 3005,23,1,NI,2348,2 3005,17,NI,2348 3005,23,1,NI,2348,2 3005,17,NI,2347 The 2348 and 2347 in those lines could actually be any numbers. I want to ...
pacoverflow's user avatar
2 votes
1 answer
154 views

Search for \w chars ending with parenthesis excluding other signs

Hello I have this text: public static Type Name = new Type(); public static Type NameX() {} If I search: /public static \(.\{-}\) \(\w\+\)( I get both lines selected until the (, but I expect the ...
rodrigoq's user avatar
  • 123
1 vote
2 answers
158 views

Highlight the full text searched on vi editor?

We've only vi editor on servers (There are 100+ of them so installing vim in each of them is not really an option as that's not our servers as we're just providing a service to others). No ...
achhainsan's user avatar
0 votes
1 answer
36 views

Searching a non repetitive in Vi [closed]

I'm quite new to Linux as well as to vi so I have several questions. Assume the text is as below: Hi one and one. Hi one. Is there anyway to search the first line where the word one exist twice in ...
Aaron Tan's user avatar
2 votes
0 answers
30 views

How do search's b and z flags interact?

I'm using searchpos instead of search is I can echo the column where the match happens, which, with example file below coincides with the matched character. 123456789 ^ | +-- cursor is ...
Enlico's user avatar
  • 2,172
0 votes
0 answers
43 views

How can I get the number of matches of pattern without altering the search buffer nor moving the cursor?

My end goal is to be able to highlight all the matches of the word being typed and echo their number, but this question is about one specific aspect of this, which I've been having trouble with, ...
Enlico's user avatar
  • 2,172
2 votes
1 answer
63 views

How to match latin letters + their accented versions?

\a is equivalent to [A-Za-z] so it matches only non-accented letters. I know of [=name-of-equivalence-class=], so I can clearly use something like \(\a\|[[=a=][=e=][=i=][=o=][=u=]]\), but I was ...
Enlico's user avatar
  • 2,172
0 votes
0 answers
68 views

How to search for yanked text in a macro?

How do I search for yanked text in a macro properly? I tried the following: qq (start a macro) yi" (yank text inbetween ", let's say the yanked text is foo) / press ctrl + r " (I ...
Sebastian Nielsen's user avatar
0 votes
0 answers
86 views

Search forward / backward (`*` / `#`) in visual select mode

This seems to be a mismatch in behavior between Vim and Neovim. In Vim, when in visual selection mode, * and # work as expected: they jump forward / backward to the next occurrence of the word under ...
phg's user avatar
  • 197
0 votes
0 answers
18 views

autocmd to set hls after having manually :nohls doesn't turn search highlighing on

tl;dr Why, after sourceing the following, moving the cursor doesn't result in the text matching the / being highlighted? set hls augroup AU_NAME autocmd! autocmd CursorMoved * set hls augroup END ...
Enlico's user avatar
  • 2,172
0 votes
0 answers
83 views

How to find all the lines that match a literal string?

How to find all the lines that match exactly a given string, literally? For literally, I mean that if the string has special characters used in regex, like *, ?, etc., then they shall be consider as-...
Barzi2001's user avatar
  • 481
0 votes
3 answers
185 views

How to replace hex encoded string with chars?

I have UTF-8 encoded HTML with id(s) and href(s) encoded as hex values like %D0%B0%D0%B1 or .D0.B0.D0.B1. Can I convert such strings into readable form using Vim?
hobo-mts's user avatar
  • 123
1 vote
2 answers
92 views

How to tell Vim to count a pattern, but without modifying cursor location?

I'm trying to streamline my workflow. I want one keystroke to slurp the token that my cursor is on, setting it in the search register enable hlsearch to show where else it is in the buffer not move ...
Steven Lu's user avatar
  • 2,231
0 votes
2 answers
89 views

How to search within a vimscript function

I'm trying to write a vimscript function that will search for a ruby class definition. My function correctly goes to the top of the file to start the search, but then doesn't move to the given class ...
Leonard's user avatar
  • 99
1 vote
2 answers
298 views

How to grab visual selection for search, but apply the appropriate escapes?

In this clip, From visual mode here after selecting im.g.mat I trigger my vnoremap <m-/> y:%s/<c-r>0//g<left><left> bind. The purpose of this bind is to initiate a global file ...
Steven Lu's user avatar
  • 2,231
0 votes
2 answers
93 views

Searching with "/" with line limits: Is it possible to specify relative line numbers?

Vim has the very good feature to limit the range for searching to start at from-line up to end searching at end-line, e.g.: /\%>1114l\%<1116lPATTERN I would like to set the cursor to line 1115 ...
Anton Wessel's user avatar
0 votes
0 answers
38 views

Why does Vim search for the word under the cursor when pressing "i" after running an external command?

I stumbled on a behaviour which I don't understand. I'm using Bash and Vim 8.2.2434 in Debian 11. To reproduce it, I created two new files in an empty directory: foo.py class Foo: def __init__(...
mkrieger1's user avatar
  • 135
1 vote
1 answer
30 views

Why does the command ":g x" show all lines matching the last search?

I accidentally stumbled on a solution for a problem I had: I wanted to get an overview over all occurrances of the word under the cursor, after I used # to find them individually. For some reason I ...
mkrieger1's user avatar
  • 135
0 votes
3 answers
29 views

How to use AG plugin to search a word inside a git repo?

I want to enable vim-ag to search a word inside specific directory. Currently I have the following mapping in my vimrc: noremap <leader>a :Ag! <C-r>=expand('<cword>')<CR><...
CIsForCookies's user avatar
1 vote
1 answer
113 views

Display pattern count when highlighting searched pattern

Running Neovim 0.9, I have this mapping: nnoremap <silent> <leader>l :<c-u>let @/ = '\<'.expand('<cword>').'\>'\|set hlsearch<CR>wb which is a shortcut to ...
reject-cookies's user avatar
-1 votes
1 answer
38 views

Start a new search

Sometimes when I am searching I want to do a new search or maybe enter a command. I notice that if I press escape twice the current search is cancelled. I can then type "/" to start a new ...
Tyler Durden's user avatar
  • 2,083
0 votes
0 answers
20 views

Map key code to specific forward search query

I'm trying to remap <leader>t to search for a specific string [ ] to save time running /\[ \] every time I search for it. Things I've tried :nnoremap <leader>t /\[ \]<CR> but it ...
jjohnson28's user avatar
0 votes
0 answers
160 views

How to tab autocomplete in command-line and search using CoC?

How can I have autocompletion in the colon command-line and during / search just as autocomplete works in my buffers?
theonlygusti's user avatar
  • 2,229
0 votes
1 answer
139 views

Replace inside matching parentheses

I want to replace all Box::new(x) with x, e.g. Box::new(A(B()) + C()) becomes A(B()) + C(). Does neovim (0.8.1) support that? I expect that there must be some feature for such a likely developer-...
theonlygusti's user avatar
  • 2,229
1 vote
1 answer
22 views

Can the '[[' search algorithm be changed to match a '{' not in column 1?

I use terrible languages that do not even allow you to put the { character in the first column. Doing so makes the compiler fail. When I work on my project in C++, I use the [[ command all the time to ...
Alexis Wilke's user avatar
0 votes
2 answers
77 views

How to change the color of "search hit BOTTOM, continuing at TOP" to red?

The message "search hit BOTTOM, continuing at TOP" was always red in my previous experience. But in the new system, this message is in the same color as the comments in the code. This makes ...
Chris.L's user avatar
3 votes
1 answer
79 views

How to call incremental forward/reverse search inside function in Neovim?

I'm trying to implement a search function that finds a pattern and jumps to it without overriding the current searched for & highlighted pattern. Specifically, I want to be able to type out the ...
WalksB's user avatar
  • 497
2 votes
1 answer
47 views

Force `gd` to be case-sensitive with ignorecase on

I have the following options: set ignorecase set smartcase set incsearch set wrapscan The first two options cause the searches to be case-insensitive if there is no uppercase letter in the pattern. I ...
3N4N's user avatar
  • 5,544
0 votes
0 answers
50 views

How can I maintain the status message after `zz` command?

I like to see the number of matches in a search on the bottom right set shortmess-=S But I also like to center the screen after I search nnoremap n nzz nnoremap N Nzz nnoremap * *zz nnoremap # #zz ...
nullromo's user avatar
  • 161
1 vote
1 answer
713 views

How can use :grep with range in neovim with ripgrep as external grep program?

I am using ripgrep as external grep program in neovim. Which works when I call :grep 'pattern' in neovim Command Mode. I frequently have to search some strings within a blocked range in long json ...
avimehenwal's user avatar
0 votes
1 answer
50 views

Unfold lines that matches a search query

How do I fold many lines and then do a search so that only the lines with search hits pop up while all the rest stay folded? This is how text editors of the 1970s worked. Much appreciated if you can ...
David Solan's user avatar
2 votes
1 answer
39 views

How to get command-line mode typing to interact with incsearch

When I type the pattern part of a global command (like so: :global/xxx), the windows in front of me get highlighted as if I was typing directly into a / or ? style search command. I'm writing a small ...
Ari Sweedler's user avatar
0 votes
1 answer
26 views

Is the older behaviour (easier to break out of search term entry) of / searches still available?

I remember older vim installations (in 2.4.x/2.6.x era linux distributions) behaving differently with / searches, often you were able to almost instantly follow the search up with an edit or movement ...
rackandboneman's user avatar
0 votes
1 answer
25 views

Backward search issue by repeated sequence and repeated match in a line

When I search backward a pattern that contains a repetition of characters, vim doesn’t always positions on the last occurrence of the pattern in the matching line if the matching line contains ...
Adrian54's user avatar
0 votes
2 answers
49 views

Neovim wont match beginning of word with # sign

/\< matches beginning of all words as expected. /\<a matches beginning of all words starting with a but /\<# doesn't match words starting with # what am I missing here? Was planning on using ...
Jordan Mandel's user avatar
1 vote
1 answer
62 views

Why are incsearch and hlsearch disabled when opening a .csv file?

I like the incsearch and hlsearch options in Vim, so early on in my .vimrc file, I have the following lines: augroup allfiles autocmd FileType * :set nocindent noexpandtab incsearch hlsearch ...
Gern Blanston's user avatar
0 votes
1 answer
707 views

Vim search: how to factor in the white space during the search?

Doing a search with / can be useful, however, it becomes harder to find things if the term you are searching for is a part of other words. I have a large text document with notes i've made about the ...
user avatar
6 votes
3 answers
1k views

How do I search the contents of registers?

I have a bad habit of deleting some text a, heading off to another section of the document to paste it, and finding something else along the way that I need to delete. When I get to my final ...
LSpice's user avatar
  • 249
1 vote
2 answers
59 views

How to find/highlight a word in the current line only

As title. The current problem is that my window is scrolled to the first/next(?) global occurrence. But I just want it to move my cursor to the local one, i.e. the current line, if any.
NeoZoom.lua's user avatar
  • 1,302
0 votes
1 answer
31 views

how to find the all the lines where they are the same like A(A)(A), B(B)(B), Z(Z)(Z)?

For example: sfdAAAzsd sdfBBBadf sd1ZZZsdf Hightlighted: sfd"AAA"zsd sdf"BBB"adf sd1"ZZZ"sdf all letters will be searched only
Maxfield's user avatar
  • 113
1 vote
1 answer
73 views

"non-greedy" [<any chars>](word) regexp problem

consider this sentence (a line in a text file): mi chiamo [Giorgio Robino](person) ed abito in [corso Magenta 35/4 a Genova](address) I want to search (select/extract) the pattern <any chars> ...
Giorgio Robino's user avatar
2 votes
1 answer
421 views

How to select a regexp group in vim?

I want to select/visualize a regexp GROUP in a vim regexp expression in vim. By example I would like to highlight (search) a span of characters inside square brackets, having this line: bla bla bla [...
Giorgio Robino's user avatar
0 votes
1 answer
113 views

Can't read my highlighted searches

In this display, what does the "xxx" mean? :hi Search Search xxx term=reverse ctermbg=11 guibg=Yellow On my display (cygwin/xterm), Search displays as black on black. If I do this, ...
n952162's user avatar
1 vote
1 answer
28 views

Trim tabs at the end of a search query

When searching in vim and mostly in netrw I add a tab before hitting enter; muscle memory from other places. /file^I How do I make it so that a tab at the end of a search query is trimmed ...
jhylands's user avatar
  • 113
0 votes
1 answer
841 views

VIM search and replace regex - how to keep the search string intact and adding to it?

I'd like to learn how to search and replace in VIM - keeping the search string intact and adding to it. Take this as a simple example. See image below. I copied a simple python script written for ...
tre332sju's user avatar
0 votes
2 answers
135 views

How can I display a minimap with search results?

I have a big sheet of data that I constantly input more into. It gets to a point that is hard to use, especially when I do a search of a certain topic. I am having tough time managing the data of the ...
purityKEF's user avatar
4 votes
3 answers
5k views

Find and replace with incrementing numbers

I have several lines that look like the following: "Timestamp": 200, "Timestamp": 1200, "Timestamp": 3100, I want to replace all the numbers, starting at 10 and ...
NH86Pen's user avatar
  • 41
1 vote
1 answer
194 views

Advance to next non-blank line only if current line is not blank

I want to tell a command or mapping to advance to the next non-blank line before executing - but to do this only if the current line is not blank. Ultimately, I intend to apply this to a command to ...
markling's user avatar
  • 319
3 votes
1 answer
155 views

Capitalizing a backreference in a search (NOT a substitute)

I am looking for a way to match any line in a csv file that contains an identifier (e.g. OfficeLocation) and then, later on, the same identifier in all caps. A line to be matched might look like: ...
mcwayliffe's user avatar
1 vote
2 answers
486 views

Delete a line if it contains N occurrences

Is there a way to do a search and replace where it searches for if a line contains 4 pipes ( | ) anywhere in the line it will delete it? I'm working with a big csv file and some lines have 4 pipes and ...
Patoshi パトシ's user avatar

1
2 3 4 5
10