Questions tagged [search]
For questions about searching for text with / or search(). For find/replace operations, use tag [substitute] instead.
468
questions
0
votes
2
answers
21
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?
1
vote
2
answers
67
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 ...
0
votes
2
answers
40
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 ...
1
vote
2
answers
41
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 ...
0
votes
2
answers
53
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 ...
0
votes
0
answers
31
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__(...
1
vote
1
answer
20
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 ...
0
votes
3
answers
25
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><...
1
vote
1
answer
77
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 ...
-1
votes
1
answer
25
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 ...
0
votes
0
answers
19
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 ...
0
votes
0
answers
62
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?
0
votes
1
answer
40
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-...
1
vote
1
answer
19
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 ...
0
votes
2
answers
27
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 ...
2
votes
1
answer
42
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 ...
0
votes
0
answers
13
views
How can I backspace over a specific sequence of characters in search mode?
I'm working on a autocmd CmdLineEnter / that should map backspace to delete a specific sequence of characters, say FOO, as unit. For instance, if the current command line is
This is a text with a FOO ...
2
votes
1
answer
44
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 ...
0
votes
0
answers
42
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
...
1
vote
1
answer
221
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 ...
0
votes
1
answer
26
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 ...
2
votes
1
answer
34
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 ...
0
votes
1
answer
25
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 ...
0
votes
1
answer
17
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 ...
0
votes
2
answers
35
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 ...
1
vote
1
answer
46
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
...
0
votes
1
answer
237
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 ...
6
votes
3
answers
990
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 ...
1
vote
2
answers
33
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.
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
1
vote
1
answer
50
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> ...
2
votes
1
answer
138
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 [...
0
votes
1
answer
61
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, ...
1
vote
1
answer
25
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 ...
0
votes
1
answer
325
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 ...
0
votes
2
answers
83
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 ...
4
votes
3
answers
3k
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 ...
1
vote
1
answer
140
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 ...
3
votes
1
answer
118
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:
...
1
vote
2
answers
376
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 ...
2
votes
1
answer
106
views
Prevent jumping when pattern matching
Is there a way to prevent cursor to search forward when using the * or /?
I just want to highlight the word I am on & others, but not move to forward nor backward.
5
votes
1
answer
565
views
Search and Replace on odd/even numbered lines using g
I was looking for ways to search and replace on even/odd numbered lines in vim and I came across some solution on google groups https://groups.google.com/g/comp.editors/c/xk9DMoszgq4.
To search and ...
2
votes
1
answer
27
views
Advance from currrent cursor position to next line not containing one of several expressions
In vim, is there a way to advance from the current line or cursor position to the next line that doesn't contain one of several regular expressions? For example, I can use /RegExp/<CR> or :g/...
1
vote
3
answers
102
views
List/navigate specific syntax elements in a file?
I would like to jump through specific syntax elements in a file. For example, quickly navigate to the next string element. In a .vim file strings are defined as vimString syntax elements. For ...
1
vote
1
answer
60
views
Jump to pattern without overriding search
I'm trying to implement a mapping for making the vim cursor jump to a pre-defined search pattern without overriding the current search, but it is falling short in multiple ways:
function! ...
1
vote
1
answer
52
views
Why is asterisk not highlighting repeated occurences of a character?
I am using the latest version of Gvim on Windows 10.
When I type / and some expression, for example /a, I see all matches in the document highlighted.
The documentation says that the asterisk symbol * ...
1
vote
1
answer
116
views
Vim search quantifier "\?" failing on backward search
I have the text in the file tmp.txt below with fileformat=unix. In normal mode, if I issue the backward search command ?da\?ta<CR>, the many occurrences of data are not found. If I then search ...
1
vote
1
answer
248
views
argdo vs bufdo for project-wide search and replace in specific folders
I have the following structure:
myproject
----src
file1.cpp, ..., file10.cpp
----include
incl1.h, ..., incl10.h
----data
data1.txt, ..., data10.txt
I would like to ...
2
votes
2
answers
98
views
Search from vim function
I am trying to use a vim function to search whether :noh has been set or not
This is similar to question found here except that question does not take :noh into account
One way to search from a ...
2
votes
1
answer
106
views
Increment numbers found in search results, using search result number as an iterator
Suppose I have a file and littered throughout are a bunch of placeholder strings for images, they all have img1.gif at present.
Is there a way to search for that string and increment the number each ...