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
0 votes
2 answers
22 views

Key Shortcut to Search

Which key(s) are the shortcut for searching the file for the word the cursor was on? I was distracted and didn't realize that I was still in gvim when I started typing something for the terminal. ...
David Robie's user avatar
2 votes
2 answers
44 views

How to remove a subset of a word the first time it appears in a row, for every row in a file?

I have a csv file which is of roughly the following format, name image wht type zt dir sally sally.fits wht.fits map 100 /users/ but with many more rows than shown in this example. I am trying to ...
shram's user avatar
  • 23
1 vote
0 answers
29 views

Searching for a visual block

Let say I have the following : .................... .###....#........... .###....#........... .###....#........... ............###..... ..........###....... ........###.#....... ..###.....#.....###. .....
M42's user avatar
  • 11
1 vote
2 answers
176 views

How to start search manually from a command or mapping, after remapping /?

After remapping / to something other than search, how can I open the builtin search interface? Normally in Vim, when you press /, a / appears in the bottom-left (where the command line also would be), ...
minseong's user avatar
  • 2,323
0 votes
0 answers
28 views

How to get/print all max-nested non-empty subdirs starting from some path(dir)?

How to get/print all max-nested non-empty subdirs starting from path(dir)? I found a random option to do this on Linux (bash): find ~/.config/nvim -type f | sed 's%/[^/]*$%%' | sort -u But I'm ...
cuc's user avatar
  • 1
5 votes
3 answers
730 views

How to make searches not appear at the bottom of the window

When I press n or N to find the next match, it often happens that the window is redrawn such that the next match is displayed on the bottom-most or top-most line on the screen, and I have to scroll a ...
John Gordon's user avatar
1 vote
2 answers
35 views

Insert newline after each line with a search pattern depending on the line before it

Basically, how can I add log statements like this with Vim? Initial document (pseudocode): case VALUE_1: doFunc1(); case VALUE_2: doFunc2(); doAnotherFunc(); case ...
xaxa's user avatar
  • 177
1 vote
2 answers
47 views

In gVim 9.1 how to have different backgrounds for text and the empty area to the right of <EOL>, with hlsearch ans syntax highlight still working?

I would like to use two different backgrounds colors bg1 and bg2 with: bg1 for all text on a line (possibly nothing if line is empty) up to the end-of-line, bg2 for the empty area after the end-of-...
gilgron31's user avatar
1 vote
1 answer
110 views

Please explain/provide example of difference between gd and 1gd commands?

I was reading the vim :help docs and stumbled upon the gd and 1gd normal mode commands. But I haven't been able to grasp what's the difference. The docs says: *1gd* 1gd ...
d.k's user avatar
  • 692
1 vote
1 answer
99 views

Searching for text while in insert mode of Neovim

I know how to search for text in visual mode in Vim/Neovim. However, I find it unnecessary when I am in insert mode to have to exit it, search and then come back to insert mode. Is there a way to ...
user3236841's user avatar
1 vote
1 answer
35 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
228 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
35 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,194
0 votes
0 answers
44 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,194
2 votes
1 answer
71 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,194
0 votes
0 answers
105 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
123 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
23 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,194
0 votes
0 answers
96 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
  • 550
0 votes
3 answers
256 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
101 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,251
0 votes
2 answers
168 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
633 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,251
0 votes
2 answers
102 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
40 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
31 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
35 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
125 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
52 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,101
0 votes
0 answers
21 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
1 answer
231 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-...
minseong's user avatar
  • 2,323
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
119 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
99 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
  • 507
2 votes
1 answer
49 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,704
0 votes
0 answers
56 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
  • 206
1 vote
1 answer
995 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
58 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
44 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
27 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
31 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
68 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
73 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
905 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
87 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,462
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
88 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

1
2 3 4 5
10