Questions tagged [search]

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

Filter by
Sorted by
Tagged with
3
votes
3answers
356 views

What does the 'z' flag for search() do?

I was looking at the documentation for search() (:help search()). I noticed that there is a "z" flag: 'z'    start searching at the cursor column instead of zero When the 'z' flag is not ...
1
vote
1answer
41 views

Multi-line python comment search and replace

I have a python code with several multi-line comments like this: def hello: ''' some comment some more text some mooore text ''' def ciaoo: ''' some comment some ...
3
votes
1answer
33 views

Backward search in current line with search() and z option

I am trying to write a couple of simple functions to find the next and previous links in Vimwiki and move to them. Links in Vimwiki are indicated with the syntax [[link to something]]. Since I only ...
0
votes
1answer
39 views

Multiline search and replace with quickfix list and :cdo

I'm working on applying doctrine/coding-standard on doctrine/orm, and I would like to work smarter. I would like to search occurences of /** * @Id * @Column(type="integer") ...
0
votes
1answer
32 views

Determine if there is a matching character on the current line past the cursor

I am trying to make a mapping that performs what f would normally do if there is a character match on the line, and to do something else if no such character exists. For example, suppose if I had the ...
0
votes
2answers
35 views

Autocomplete popup menu for search results

Autocomplete in insert mode (via <c-n>/<c-p>) is excellent, in particular the navigable popup box. I would like the same navigable popup box when I search: so, I type /, then start to type,...
3
votes
1answer
17 views

Replacing both upper case and lowercase findings [duplicate]

I often find myself running the following commands in sequence when wanting to replace both the lower case and title case instances of a given word, while retaining its original case. :'<,'>s/...
0
votes
0answers
20 views

How to point the cursor to result when search by 'let @/ = '?

To reproduce this problem: Open a new vim window, input "abc", leave cursor at the end of line set hlsearch let @/ = "abc" The cursor doesn't point to the beginning of "abc&...
0
votes
0answers
22 views

behavior of control characters has changed in ubuntu 20.04

Before upgrading to ubuntu 20.04, the line g/;/s//CTRL V CTRL M/ would replace the ; with a new line. Now, in ubuntu 20.04 this string translates to :g/;/s//^[[27;5;109~ which obviously doesn't have ...
2
votes
1answer
59 views

Is it possible to detect a highlighted search match with synIDattr() or similar?

When I have hlsearch on and my cursor is somewhere in a highlighted search match, is it possible to detect the search highlight hl-Search with synIDattr() or a similar function? As far as I can tell ...
0
votes
1answer
20 views

possible to search two form of hex string in one time?

Some text file contains lots of hex strings, a same string presents multiple times in two formats like: 00000000 aa bb cc 25 41 f3 d9 ed 58 5c ed a0 3c 61 60 ce ...%A...X..<a`. and ...
0
votes
1answer
43 views

Search for a pattern, copy the line with the matching pattern, copy the next 2 lines, output the results into a new file

I have a file with data that goes like this. Engine1 Temp:10 Humidity:23 Engine1 Temp:13 Humidity:21 Engine2 Temp:10 Humidity:23 This pattern repeats throughout the file. I want to do the following ...
3
votes
1answer
49 views

Skip to next batch of search results (or find next non-match)?

So you search /needle, and end up trapped in a haystack of result lines. Is there a quick way to skip to the first non-matching line (and then the next batch of results)? E.g. I'm viewing the results ...
0
votes
1answer
32 views

Searching a log file using vi or view

When I open a log file in vi or view and I need to search for a word, the first thing I do is to press G to get to the bottom. Then I'll start a search using a / followed by whatever word I'm looking ...
2
votes
1answer
32 views

Delete up everything until searched term, including searched term

If the cursor is at t in the quick brown fox and we type d/brown, we delete the quick . Is there a way to extend this such that the searched term is deleted too? (Such that only fox remains.)
0
votes
0answers
41 views

How to get information about search results from / or ? (the contents of @/)

In normal mode with default mappings, suppose I type /[,_@]. This then causes all matches of that pattern to be highlighted. Is there some way to examine the results of this search? I am specifically ...
1
vote
1answer
64 views

Show all instances of a certain string

I use * and # for quick and basic typo checking. If I type AVeryLongVariableName, I can put my cursor on the word, press * and see all the other places that word is used. I know I spelled it correctly....
4
votes
3answers
235 views

Recover whole search pattern for substitute command

Sometimes I type a long substitute command /%s/foo/bar.../ and while I am typing it or only after hiting enter I notice that I have mistakenly used a the search key (/) instead of the ex-command key (...
1
vote
2answers
158 views

Regular expression for searching IP addresses

I opened up a document in vim and I want to search the document for IP addresses. So I used this command /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3} But this pattern doesn't seem to return any of ...
0
votes
2answers
55 views

Bind a specific search to a map in normal mode

Specifically, I'm looking to bind the search /\(<<<<\|====\|>>>>\)/ (i.e. "find the next git merge boundary"). Ideally to <C-/> or <A-/>, but that part I'...
2
votes
1answer
66 views

Search and yank in visual line mode with execute normal

I have this in a buffer: aaa bbb ccc ddd eee with the cursor on the first line. I do :execute 'normal! jV/ddd\<CR>y' which I expect should result in the middle three lines yanked. But what ...
0
votes
2answers
56 views

Find the specific line with character in specific position

Finding the line with a specific character before the last character. Suppose, I have the following string 1. addar_ctrl1,1,2,0,0,1 2. addar_ctrl2,3,2,0,1,0 3. addar_ctrl3,4,8,0,0,0 4. addar_ctrl4,2,6,...
-1
votes
1answer
44 views

Enter insert mode after search?

So you're in Normal mode, then you press f followed by a character, then vim takes you to the next occurrence of that character. When you land on that character you are in Normal mode. My question is ...
-1
votes
1answer
49 views

Regex for any character that is not alphanumeric, whitespace, or a doublequote

I expect this to select all non-alphanumeric characters: [^\w] Instead it selects all non-w's. This is the regex I would use in JavaScript, Python etc.: [^\w\s"] How can I write this so that it'...
1
vote
1answer
96 views

Replace a character multiple times but within pattern

I am creating a yml file out of some variables. I have like 80 lines and they all have the pattern: my-first-command-line-var: {{ my-first-command-line-var }}, my-second-cli-var: {{ {{ my-second-cli-...
1
vote
2answers
67 views

How to remove spaces between parenthesis?

I have a text that looks like this " original call minpac#add('morhetz / gruvbox') " desired call minpac#add('morhetz/gruvbox') How can I limit vim pattern search within parentheses? I ...
0
votes
1answer
29 views

How to search/replace without appending search history?

In a BufWritePre to remove trailing spaces, my function uses a search/replace for \s\+$ over the current buffer. So after saving any buffer, this weird entry \s\+$ shows up in my search history. Is ...
1
vote
0answers
39 views

How to repeat `f <char>` in opposite direction when using `,` as the map leader?

I have set mapleader="," in my ~/.vimrc. How can I continue to repeat f <char> in the opposite direction, when using , as the map leader? Is it possible to remap , in the context of f &...
0
votes
3answers
55 views

Is it possible to exchange search patterns in vim?

Is there a way, built-in or with a plugin, that I can swap any number of two different patterns on an arbitrary range using a regex? Maybe something :s-style like :{range}exchange/{pattern-1}/{pattern-...
3
votes
1answer
67 views

open file with a particular regex search

Can one associate a regex query with a particular file, so that whenever that file is opened, the query (e.g., /text) is run, causing all instances of text to be highlighted? I considered using ...
1
vote
2answers
166 views

Trying to undestand why using \zs in regex is not working as I expect

Consider the following test String: County,Age,Age_group,Gender,Jurisdiction,Travel_related,Origin,EDvisit,Hospitalized,Died,Case_,Contact,Case1,EventDate,ChartDate,ObjectId If use the following ...
1
vote
1answer
38 views

Case-sensitive search with `smartcase` set

I have set smartcase in my init.vim so searching with /lowercase is case-insensitive, which is usually what I want. However, I sometimes want to do a case-sensitive search where my target is all ...
2
votes
1answer
45 views

Finding where one word is close to another word: parametrized command in vimrc

I asked this question, about how to find where one word is close to another word, and Quasimodo gave the very fine answer: /\vaid(\W+\w+){,3}\W+country Now I want to parametrize this command into ...
3
votes
1answer
127 views

Jump to selected word after a search in vim [duplicate]

I use / followed by word to be searched to search for a word in a document. However once I find the word pressing escape just takes me back to the cursor location which is at the beginning of the ...
0
votes
1answer
51 views

incsearch not working as expected

So I have the following example text: ##1## many text and lines ##z## ##1## many text and lines ##z## ##2## more text ##z## And after doing :set incsearch, and running :g/^##1##\n.*/+,/##z##/- (which ...
1
vote
2answers
31 views

Why does a range search “:[range]/pattern/action” not work the same way as “:[range]g/pattern/action”?

Can someone explain why range search :[range]/pattern/action does not work the same way as :[range]g/pattern/action? Also :'a,'b/pattern/action gives a warning that the range is 'backward', even ...
4
votes
1answer
51 views

Set variable equal to search match subsection

Unnecessary Context: I want to write a function that closes open HTML tags, because closetag.vim seems complicated, and I like to understand all the stuff I run in Vim. My plan for this is to match ...
3
votes
1answer
270 views

Date change question: Find and replace with wildcards?

I have a file with a bunch of dates of the form a/b/c, where a,b, and c are numbers of varying character length. However, I'd like to change every instance to read c/a/b. I'm wondering if there is a ...
2
votes
1answer
90 views

How can I find where one word is close to another word?

If I want to find occurrences of the word 'arc', I can type / arc , with spaces around the three letters, to find basic occurrences of the word (ignoring punctuation). But suppose I want to find where ...
3
votes
1answer
465 views

Can't search for strings within hidden files with fzf's Rg command in vim

I just installed fzf for my bash terminal and the fzf.vim plugin for vim. I've placed the following code at the bottom of my .bashrc script: export FZF_DEFAULT_COMMAND='rg --files --hidden --no-ignore-...
5
votes
4answers
759 views

Show exact number of matches even for large (>99) numbers

When I search for something /search-term and it shows up more than 100 times in my file, vim shows me that I'm on match x/>99 instead of x/121 etc. For smaller numbers it shows me the exact number ...
5
votes
1answer
85 views

Vim find/replace highlighting

I'm a long time Vim user but a few months back started dabbling in Emacs. One of the things I really liked about Emacs was when doing a find/replace s/you/me it would highlight the word I was ...
0
votes
0answers
12 views

How to not jump back on mismatch with incremental search

With incremental search (incsearch), we jump to matches and they are highlighted as they are found. But if we hit a character that makes the search not match anything, we’re thrown back to where we ...
2
votes
3answers
103 views

How can I repeat the cgn sequence?

Recently I learned the awesome command cgn to repeat a change to a word. I’ve seen several answers advising its use, like this: What is the best way to re-factor a variable name in vim? and this: How ...
0
votes
3answers
130 views

Conditional search and replace using repeated macro or commands

I want to search for a keyword, and replace a word in the line that is not a search word. I thought macros may be a good way to do it, but I am open to any methods. I have something like, blah blah ...
1
vote
1answer
13 views

Passing a pattern as argument without extra escaping

so I want to pass a pattern to a command. command! -nargs=1 -buffer Vim silent exec "vim! /" . <args> . "/ ./*" | copen | redraw! But there is a problem. If I want to match /foo i would use ...
0
votes
0answers
18 views

Reverse n and N for ? and # searches (compared to / searches) [duplicate]

When I search with ? or #, I want n to move "forwards" through the buffer, and N to move backwards. This is opposite to current behaviour (where n moves in the search direction). How can I set this ...
1
vote
1answer
36 views

Searching for multiple keywords listed in the buffer

Given two buffers, where the first one has a list of keywords delimited by a new line; the second buffer with text that contains a subset of keywords from the first buffer. How do I search and ...
0
votes
1answer
35 views

global search and replace on all lines that don't begin with a backslash

I'm trying to globally enclose in {}'s all instances of +,-,= that aren't already so enclosed. But I don't want to do this for lines that are latex commands. Since my latex commands are all on ...
1
vote
1answer
28 views

How to insert text using substitute and regex?

Honestly I can't read regex for now. I have quick-fix list and I have a hunch that this can be done with regex but I don't know how. I want this: @ViewChild(MatTable) @ViewChild('text 1') @...

1
2 3 4 5
9