Questions tagged [search]
For questions about searching for text with / or search(). For find/replace operations, use tag [substitute] instead.
490
questions
0
votes
1
answer
24
views
search() finds hit on the current line only if column is 1
Consider the following snippet:
vim9script
var foo = 3
If go on line 3 and I run :echo search('^\s*var', 'cnW') I get the value 3 only if the cursor is on columns 1. If keep the cursor on the ...
0
votes
2
answers
38
views
search('map <F\d>.','W') fails to find pattern in my .vimrc
Mostly I invoke my key-mappings with a function key followed by a single character.
Finding an unused combination gets tedious, so I'm writing a mapping to list all such combinations in my .vimrc
But ...
0
votes
2
answers
24
views
How to recall terms from all search methods?
vim have many things that the manual describe just as "search forward".
1. Search commands search-commands
...
1
vote
1
answer
88
views
How do I start a search with the currently selected text?
What to add to init.lua such that / set the CLI with:
/ followed by the selected text if any
/ otherwise
0
votes
2
answers
70
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. ...
2
votes
2
answers
48
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 ...
1
vote
0
answers
33
views
Searching for a visual block
Let say I have the following :
....................
.###....#...........
.###....#...........
.###....#...........
............###.....
..........###.......
........###.#.......
..###.....#.....###.
.....
1
vote
2
answers
221
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), ...
0
votes
0
answers
31
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 ...
5
votes
3
answers
750
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 ...
1
vote
2
answers
82
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 ...
1
vote
2
answers
63
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-...
1
vote
1
answer
160
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 ...
1
vote
1
answer
313
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 ...
1
vote
1
answer
38
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 ...
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 ...
1
vote
2
answers
262
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 ...
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 ...
2
votes
0
answers
36
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 ...
0
votes
0
answers
55
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, ...
2
votes
1
answer
77
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 ...
0
votes
0
answers
138
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 ...
0
votes
0
answers
24
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
...
0
votes
0
answers
107
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-...
1
vote
3
answers
326
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
114
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
287
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
853
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
118
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
41
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
33
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
41
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
149
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
53
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
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 ...
0
votes
1
answer
324
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
23
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
156
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 ...
3
votes
1
answer
109
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 ...
2
votes
1
answer
50
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
69
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
1k
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
66
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
49
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
29
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
42
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
107
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
82
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
1k
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 ...
7
votes
3
answers
2k
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 ...