Questions tagged [search]

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

Filter by
Sorted by
Tagged with
1
vote
3answers
136 views

Copy a line, comment it and replace a word in copied line

Libraries evolve all the time and I often face the situation where after an update some function name have changed and they return errors in the updated version of the library. It's easy to replace ...
4
votes
2answers
895 views

How do I jump to the next line with the same indent level?

I have a space formatted (yaml) file like the following: en: templates: template: "VERYLONGTEXTHEREWITHHUNDREDSOFLINES" destination: "I want to jump here" other: stuff ...
0
votes
1answer
249 views

Toggle search highlight while on match

I'd like to have search highlights (set hlsearch) while the cursor is on a match and to turn it off automatically (set nohlsearch) when I move the cursor away. Example: foo bar foo text text bar ...
3
votes
1answer
466 views

How to delete blocks of text which contain a specific string?

I have a file which has the following structure From: foo@example.org Subject: Bar Date: 2017-06-27 Mailbox: /some/dire/ctory <CR> Such a block always contains of four lines followed by an ...
4
votes
1answer
69 views

Make * stay on current keyword

I often use * with cgn and end up missing the first match (or doing *N...). So I'd prefer for * to stay where it is. nnoremap * *N Does almost what I want except it recenters the cursor line. Is ...
6
votes
1answer
196 views

How to move the cursor to the next reference, option, heading in man pages?

If we load the built-in man.vim filetype plugin by writing in our vimrc: runtime ftplugin/man.vim We can read a man page inside a Vim buffer, using the :Man command described in :h :Man: MAN ...
1
vote
1answer
82 views

cnoremap <CR> <CR> breaks search fold opening

In order to switch between relative and absolute line numbering upon entering command-line, I noremap <expr> <CR> to "someStuff". Unfortunately this breaks the foldopen-ing feature for ...
3
votes
1answer
256 views

Character in math mode replacement

I would like to replace instances of a single character variable, say x, throughout all my equations in a latex file, say the replacement is \x. The equations are denoted by one of the following: \...
3
votes
1answer
162 views

How to jump to a next or previous specific character ignoring linebreaks and not destroying highlight or overwriting my registry?

I have not found much use for ()[]{}, and so I want to map them so it does a find command, jumping to the previous instance of that particular character. Thus, ) will jump forward to the next ), ...
1
vote
1answer
378 views

Consistent repeat search [duplicate]

Is there a way to do a forward (resp. backward) repeat search with n (resp. N) indifferently I start the research with //* or ?/# ?
2
votes
2answers
81 views

Add a space and then text at the end of a line

I would like to know how to add a space and then text at the end of a line. For example, adding a space and then /abc/aaa/abc/. I am trying :%s/$/ /abc/aaa/abc/ but that does not work. I know I am ...
1
vote
0answers
43 views

Search local to buffer [duplicate]

I'm often searching elements inside the buffer to have a visual indication where in lines the 'text' exists but that overrides the search for all buffers. Is there an option to make it local to ...
1
vote
1answer
168 views

Replace n with n+1

I want to replace a number n, with the number n+1. Here's what's working: :%s/\([0-9]\+\)/\=(submatch(0)+1)/ But this one doesn't work: :%s/-c \([0-9]\+\)/-c \=(submatch(0)+1)/ Why?
1
vote
0answers
32 views

substitute a join for a character that ends a line

when pasting from a pdf document, words in the original document are being split up, and replaced by a - and a line break. For example: alternative specifications. In con- clusion, these findings ...
4
votes
1answer
1k views

Searching for text when launching Vim

I am writing a shell script to view a text file and search for a pattern. I want to specify this pattern in the command line when launching Vim. This command is what I am currently using do ...
1
vote
1answer
218 views

Pass word one-by-one and replace (Search and replace with confirmation) [duplicate]

I'd like to pass through a text an replace word1 by word2. However, I don't want to execute this task in one pass, but rather word by word. I know I could put the cursor on the word I want, execute *, ...
0
votes
2answers
94 views

Search and replace workflow [closed]

Classical replace command looks like %s/old_pattern/new_pattern which is fine, but working with code or constructing complex search regular expression is not the best option. I'd like to present my ...
2
votes
1answer
79 views

Key n moves up in the file instead of down

Sometimes n (next instance of a search) starts moving me up in the file instead of down. Could this be caused by a bug in a plugin?
4
votes
3answers
594 views

How can I quote text in a search regex?

I want to yank text from a window and search for it but the text contains characters not interpreted literally by the search command, e.g. a file path. Is there an easy way I can quote the yanked text ...
12
votes
1answer
934 views

Is there an incsearch for the replace command?

I really enjoy Vim's incsearch functionality. Is there a way to have it, or something similar to it, working while I do a replacement? For example, if in normal mode I type: :%s/potato/ Can I get ...
0
votes
1answer
180 views

Notify when one search loop is complete

I am searching a pattern with /pattern starting from a random line number ln1. Sometimes I kept on going with n without realizing that I completed searching the whole file. Given the premise, I ...
6
votes
5answers
661 views

truncate sentence: delete up to, but not including period

How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period? The commands df., d), and D all truncate the sentence but don't keep the period. ...
1
vote
1answer
93 views

Finding all occurences of backslash and deleting twice before every occurence of them

I got some output code that has random backslashes, followed by a new line. For example: ( 1-z+z^11-z^12+z^22-z^23+z^33-z^34+z^37-z^38+z^40-z^41+z^43- z^45+2*z^46-2*z^47+z^49-z^50+z^52-z^53+2*z^55-2*...
2
votes
1answer
147 views

How to show the index of the current match?

I search some words so that there are many highlight results in the current window. I use n to move cursor to a matching result, how to know its index of match results easily? I have tried ...
13
votes
1answer
3k views

How to interactively search/grep with VIM?

Is there any way to configure VIM to interactively search inside every file for an entire project? By interactive, I mean updating each keystroke. Something like Emacs counsel-git-grep, see: example ...
10
votes
1answer
813 views

different search patterns per window / buffer

Is it somehow possible to have different search patterns per window or buffer, ie. I want to search for term A in window/buffer A and term B in window/buffer B so that using hlsearch, highlights ...
1
vote
0answers
359 views

Set highlighted token to blink during search and replace

When I do a global search and replace with confirm (e.g., :s/t/s/gc) I have a lot of trouble seeing which of many occurrences is currently under the cursor. I've tried the usual tricks, e.g., hi ...
7
votes
2answers
484 views

How can I automatically center first search result?

I want to have the very first search result centered on the screen. I know about :nnoremap n nzz mapping, but it only works for centering next matches, not the first. I thought that maybe I could use ...
3
votes
1answer
442 views

How to always append parameters for a Ggrep command?

I'm using the Fugitive plugin. It has the :Ggrep command which is very useful for searching the repo. One annoying thing is that I have huge .map files and I want to omit them from my search. I ...
1
vote
2answers
450 views

reverse-i-search à la Bash Ctrl-r

I would like to be able to search through the previous commands starting with : that I entered, using an interactive incremental search, as it is possible in some shells (example: with Ctrl-r in bash)....
5
votes
2answers
147 views

How to replace buffer with a search range selection?

I'd like to replace the entire buffer (file) with the current search range selection: :/pattern1/;,/pattern2/p How this can be achieved?
2
votes
2answers
181 views

How to exclude the ending pattern in a search range?

I've the following content: group1 item1 item2 item3 group2 item4 item5 group3 item6 where I'd like to select all items which belong to group2 using a search range. Here is my approach: ...
2
votes
0answers
84 views

vim-latex suit forward search

First, sorry for the cross-posting. I have posted it in https://tex.stackexchange.com/q/345060 as well. I am trying to enable forward search in vim-latex. Since it is not working, I tried a vanilla ....
4
votes
1answer
30 views

Self-define command to search a certain symbol

I want to define a command that jumps to next closest Chinese-period or Chinese-comma and perhaps other punctuations, and another command that do the same but for previous closest puncutation. To ...
4
votes
2answers
425 views

Search and Replace inside block-selected text

I just discovered you can't search and replace within a block selection without adding the ugly and unintuitive \%V to the search term. The default behaviour seems to be to ignore the fact that you've ...
20
votes
2answers
1k views

How can I perform a search when vim displays content using “more” pager?

I want to see the value of a variable, so I run the command :let Vim displays the results of this command using the --more-- pager. How can I search this for a phrase, e.g. html? I've looked the ...
0
votes
1answer
883 views

How to get the content between two specific lines in vimscript?

How can I write a function to get the content between mark 1 and mark 2 for further processing? mark can be a string, or a function call, it doesn't matter. mark 1 foo1 foo2 foo3 mark 2
5
votes
3answers
3k views

search line which contains forward slashes

I have a following line in one script: cp "$uploaddir"/"$file" "$cvsdir"/"$device" I would like to search if this exact line is present elsewhere in the script. Usually I would do yy and then /...
0
votes
4answers
717 views

How to quickly replace a single character in a word search, but only for a block of code in Fakevim?

3rd block of code needs to go from ipt1 to ipt4 4th block of code needs to go from ipt1 to ipt5 Because it is only 3 selections, creating a macro is probably slower than manually, but doing it ...
1
vote
1answer
215 views

How to quickly cycle through the search history?

The fact that Vim highlights the strings matched by a search expression can be useful if you are searching for visual patterns in a text. I would like to now if it was possible to quickly cycle ...
4
votes
2answers
655 views

How to highlight a search range?

I'd like to test the range pattern, same as Vim highlights the text while searching (e.g. :/), but for the range command instead. So in other words, instead of executing: :/<head/,/\/head>/d ...
3
votes
1answer
643 views

How to avoid 'Backwards range given' warning when invoking search range?

I've got the following sample HTML code: <html><body> <table class="foo"> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>...
3
votes
0answers
309 views

Is there a way in vim to determine if something is highlighted after search?

What I want to do is make CursorMoved autocmd that would check if there is a search highlight is on and if it is it would start a timer that would deactivate it. PS I know about all available ...
1
vote
1answer
2k views

Searching with vimscript function

I want to create a custom search in vimscript, using this line for searching: :execute "normal gg/[A-Z]\\+*.:\<cr>" it will tell me (correctly) that it searched for the pattern: /[A-Z]\+3a.*: ...
2
votes
1answer
79 views

Get index of search in substitute expression

In a substitute command, is it possible to retrieve the 'index' of the search (i.e. for the n-th match, the index is n)? I am looking to use this in this context: :s/pattern/\=[SEARCH INDEX HERE]. I ...
0
votes
2answers
589 views

Multi file search for selected text

Using atom I can CtrlShiftf while a word is selected in order to start a multi file search for a matching string. I would like to emulate this flow as much as possible with Vim. I know I can yank ...
4
votes
1answer
238 views

Don't expand `%` in external grep call

I try to search for {% amount in all files under the current directory. Using ag, this works fine: ag -Q '{% amount' (-Q specify to not use any regex, try to match text literally) I have this in ...
1
vote
0answers
696 views

Enter insert to insert mode from function

I want to create function that search for selection and then automatically replace selection with given text. Something like *Ncgn but with custom movement (not exactly word only). My current ...
0
votes
1answer
522 views

Run a command on every match of a search (not on the line)

I am trying to run a command on every occurrence of a search match. So, If i have some thing like this where a search match matches only these two anchor tags, .................. <a src="****" &...
12
votes
1answer
1k views

Why is a Line Feed converted into a Null character inside the search register and into a Carriage Return on the command line?

If I have the following text: foo bar I visually select it and copy it. The text is now stored in the unnamed register " and here is its contents (output of :reg "): "" foo^Jbar^J According to ...

1
4
5
6 7 8