Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [search]

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

Filter by
Sorted by
Tagged with
5
votes
5answers
3k views

Match any number of digits NOT followed by

I want to search for: From start of the line, any number of white spaces followed by any number of digits NOT followed by a dot. And replace it with all that was searched and a dot. This is just ...
1
vote
1answer
33 views

How to get a variable with the contents of a file on the filesystem?

I intend to use this to optionally share the search buffer between different Vim instances. I'll have a file on the filesystem that contains the content. So it means I need to set the search register ...
1
vote
2answers
450 views

Replace two word sequence with second word

I need to replace on all lines sequence of words: public boolean public string public IList etc.. with modifier removed aka: boolean string IList Is there a way how to remove first part of match ...
14
votes
4answers
5k views

Delete from cursor till nth occurence of character x

I know that I can delete from the cursor till and including the first occurence of a character x with d/x<CR> or with v/x<CR>d if I want to see the selection first and then delete. How can ...
0
votes
2answers
190 views

is search a true mode in vim?

Listed here is "each mode" for vim. I did not see "search" in the list, but I should think that search (/ or ?) would be a mode on its own. I have to make a very formal presentation about my ...
4
votes
1answer
213 views

find next comma, skipping anything in parens?

Suppose I want to create a macro that swaps two function parameters. For example, I search for swap: swap(first, second); And with the cursor pointing at the 's' in swap, I can search forward for ...
0
votes
1answer
320 views

How to escape @ in search replacement

I usually have to worry about escaping search parameters to get special characters to match literally, but this time I'm seeing a problem with my replacement string. I want to take text like this: @@...
1
vote
3answers
133 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 ...
3
votes
2answers
524 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
208 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
429 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
67 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
192 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
66 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
218 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
141 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
362 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
1answer
684 views

autocompletion in command line/search

There is some way to "extend" autocomplete functionality (like that one supplied by SuperTab plugin) to be used in command line mode so I would autocomplete when searching a text with / command? ...
2
votes
2answers
80 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
42 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
153 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
31 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 ...
3
votes
1answer
876 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
200 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
90 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
78 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
375 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 ...
15
votes
2answers
7k views

How to use Ctrl-P to interactively search file contents for all files in a project?

I tried today to perform a search on every files of a project. I use Ctrl-P and search on lines like so : But the result of the search is only on the previously opened file. Here I open only main....
12
votes
1answer
700 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
117 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
593 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
79 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
139 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 ...
12
votes
1answer
2k 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
703 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
315 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
423 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
430 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
398 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
137 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
168 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
79 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
346 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 ...
17
votes
2answers
752 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
648 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
2k 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
660 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
186 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
581 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 ...