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
0answers
285 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
1k 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
77 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 ...
2
votes
2answers
549 views

Show leading whitespaces, but not including tabs

I am a tabs kind of guy, I do not like when my code contains leading whitespaces instead of leading tabs. I often exchange codes with colleagues and I first have to convert the leading whitespaces to ...
0
votes
2answers
487 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
186 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
641 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
411 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 ...
4
votes
2answers
2k views

Searching/replacing exact word in vim by default

In vim when searching or replacing an exact word you need to type: \<word\> to match it exactly, this is cumbersome to type, and I find myself wanting to search/replace exact words a lot more ...
3
votes
2answers
89 views

How do I map *, so after each recurrent press, it expands its selection one word over?

For example: QString QSSMLTools::heather(QString s) { if (!m_Enable) {return s;} s.insert(0,"<voice name='Heather'>"); s.append("</voice>"); return s; } QString ...
3
votes
1answer
944 views

Percent key ( % ) matching behavior for angle brackets ( < > )

In vi it's very helpful to be able to place the cursor on a '(' or '{' or '[' character, press the '%' key, and move to the matching ')', '}', or ']'. But this does not work for me with angle ...
0
votes
1answer
141 views

Globally replace a particular pattern with another string

In VI I need to replace a pattern that looks like this: seq- followed by exactly 24 chars (can be 0-9, a-z, A-Z only) followed by / followed by some number of (0-9, a-z, A-Z). So an example string ...
9
votes
1answer
656 views

Visual select current search result

I have hlsearch set, but it sometimes lulls me into thinking t hat I have the search term visually selected, and can just hit c to change it. The term searched for may not be an easy number of ...
3
votes
1answer
5k views

searching duplicate words

This page says that I can find duplicate words using a regular expression. The suggested command is \(\<\w\+\>\)\_s*\<\1\> What does "\w" mean here? Suppose the target pattern is "123\...
3
votes
1answer
684 views

How can I search and replace within multiple files? [duplicate]

I have the same text that I want to replace in multiple files (say, I'm updating version numbers in multiple files). Even using the command history to reuse commands, it sure is tedious to open each ...
5
votes
1answer
80 views

Searching for a phrase in hard-wrapped text

When searching for a phrase in hard-wrapped text, one wants newlines to be treated as spaces. Can one have that happen? Saying /the\_sphrase\_sI\_sseek is a bit awkward.
2
votes
1answer
313 views

understand backslash in search pattern in case of “very nomagic” mode

I have a following text: Search items: [http://vimdoc.net/search?q=/\\][s] ... [s]: http://vimdoc.net/search?q=/\\ Now I would like to find the http://vimdoc.net/search?q=/\\ string from this text. ...
1
vote
0answers
64 views

Is there a way to highlight searches done with grepprg?

I'm using vim-grepper plugin, but I guess it doesn't really matter. What I want is when I'm searching for something inside my project via vim-grepper or some grepprg if there are matches inside opened ...
13
votes
5answers
1k views

Quick search, limited to a C++ function

I work on a rather large C++ project. One of the more frustrating aspects of its organization is very large functions placed inside ridiculously large files. I often want to search for any instance ...
3
votes
1answer
738 views

How to show all unique types of a pattern?

I have a very large file containing about, for example, 5 million lines like this: Songs=****, Singers=**** Singers=*** Songs=*** .... # many many lines SongType=*** ... # many many lines again Album=...
4
votes
1answer
7k views

ignoring spaces in search like ignoring cases

I frequently search in my files using /, and \c is really helpful in these situations. Is there any similar way to ignore white space and line breaks? It would really be nice to be able to add ...
2
votes
1answer
62 views

Running find-and-replace in Visual Mode :'<,'>s/^/string/g inserts “string” at 0 position instead of ^ (first non-whitespace) position

I have some visual-mode commenting macros that should place a comment character g:CommentChar before the first non-whitespace character of each line in the selection. However, it places it right of ...
1
vote
1answer
84 views

Find a non-regular expression tag in a specific tags file

I have a tags plugin that I'm adding features to. In order to test that it is working correctly, I need to examine the tags inside a tags file. I am trying to make sure the correct tags appear in the ...
12
votes
3answers
1k views

Mapping with motion

I'm trying to understand how can I use operator with subsequent motion inside a mapping. For example: nmap /c c{here we pending for a motion}/<C-r>"<CR> The map should do the following: ...
3
votes
1answer
95 views

How to not display a certain error

My situation is, I have set nowrapscan, however now, when I hit the end of a file, it will display E385: search hit BOTTOM without match for: \v^[^=]*(… How can I avoid that from displaying? I used ...
2
votes
1answer
219 views

Don't fail if pattern is not found

I have the following autocmd to search for function definitions in C files. autocmd Filetype c,cpp execute "nnoremap ]m /\\v^[^=]*(([a-zA-Z_][a-zA-Z_0-9]+)|(operator .*))\\(.*\\)( const|:)?( \\{)?$\&...
2
votes
1answer
115 views

search: move window below next found line

When I'm searching my document with / when the next match line is off screen, the cursor jumps down so that the matched line is the very last line in the window. For example, if I'm searching for ...
2
votes
3answers
3k views

How to delete searched line and next

I have a file containing special comments in the following forms: // SPECIAL // Some stuff // Some other stuff // Last line of other stuff So I need to be able to delete the line containing SPECIAL ...
0
votes
1answer
160 views

How to make vim search every time I add a new character to the search?

When I use sublime text I find that it starts searching every time I press a key in the search, i.e. every time I add another letter to the searchsublime performs the search and shows a match with all ...
1
vote
2answers
424 views

Find first occurrence of string or return end of file

I am currently setting up my Vim to work with matlab. In matlab, sections are separated by %%, and I am looking for a command to select my current section. I currently use nnoremap <Leader>f ...
3
votes
2answers
170 views

Search for mismatched length alternative pattern?

My file consists of the following text one bone stone cuttlebone minestrone cornerstone and I want to select all instances of bone and stone, so I get the following highlighted text: one BONE STONE ...
14
votes
2answers
2k views

Is there search and replace history in vim?

We can retrieve search and replace history on IDEs and text editors. Likewise is there a search history or a way to retrieve previously searched expression in vim?
2
votes
1answer
376 views

Get 'second previous' occurrence using `search()`

I would like to get not the first, but the second occurrence of my pattern using search('pattern', 'myflags'). I could not find any flag or option in search() documentation that could help me do ...
5
votes
2answers
415 views

Set highlight in vim function

I am trying to highlight a word in the current buffer dynamically like so: function! Highlight() let @/ = 'word' set hlsearch endfunction When I run this function, the register / contains word ...
4
votes
1answer
988 views

How to clear previous search highlight in vim? [duplicate]

After performing some search operation vim highlights its occurrences. These occurrences persist as long as editor is opened or another search is performed. How to clear previous search highlights ...
4
votes
1answer
164 views

Backward search command ignores “\” in regexp “o\?”

I'm using Vim 7.4. I tried to search backward for front and frnt, so I pressed ? and entered the regular expression fro\?nt. Vim tells me that it can't find fro?nt (the backslash is missing in the ...
7
votes
2answers
138 views

Is there a way to restrict search results to differences in a diff?

I want to be able to search only within the DiffText regions of a file that I'm editing. Related question: https://stackoverflow.com/questions/2683521/vim-search-in-c-c-code-lines The accepted ...
1
vote
2answers
851 views

How to map key to a substitute command with dynamic text?

I've found this little trick in vim wiki. nnoremap <Leader>s :%s/\<<C-r><C-w>\>//g<Left><Left> Immediately I thought that in some cases it would be beneficial to ...
4
votes
1answer
95 views

How do I search only the displayed part of concealed text?

If I have syntax highlighting rules setup using conceal to hide or change certain characters in a file, how do I search what is displayed, as opposed to what the buffer actually contains? The ...
1
vote
1answer
267 views

Why doesn't search for word under cursor (* and #) turn on search highlighting and how do I enable it?

I can't find info in help about whether it should or shouldn't turn on highlighting, but I find it strange that I have to press n or N after * or # to turn on search highlighting. How do I enable ...
4
votes
3answers
1k views

How to disable search highlight automatically after searching?

Search highlight is very convenient for me when I'm searching, but after I'm done with doing stuff with search matches it's distracting to me, so I'm using :noh mapped to F3 everytime I've done what I ...
2
votes
0answers
618 views

multiple highlight with multiple color

When we search for a word, it gets highlighted. I want to search for another word keeping the previous one highlighted (with a different color probably). Please let me know if it's doable.
2
votes
5answers
8k views

Replacing last comma on each line

The following will replace the first comma on each line with a pipe: :%s/,/|/ How can I do the same for the last comma?
4
votes
1answer
94 views

Search and replace depending on capitalization of letters [duplicate]

I would like to replace foo with bar and Foo with Bar. I can do :s/Foo/Bar/g :s/foo/bar/g Can I do this in one command?
3
votes
2answers
221 views

How do I search for line containing an unclosed parenthesis?

How to search for line containing unclosed parenthesis. /([^)]*$ works only for non-nested parenthesis. If the closing parenthesis is present in the next lines, it should still be a match. for ...
1
vote
2answers
128 views

One-liner? Move lines after 1st line not matching pattern after one that does

I’m exploring Vim’s capabilities and somehow stumbled upon this task. It’s constructed, but I’m curious: Is there a one-liner colon command that can find the first line that matches a pattern p (say,...
11
votes
3answers
1k views

Jump to next occurrence of the word I just changed

If I have the following: function foo(bar) { return bar + 1; } And I use cw to change the first bar to baz, how do I jump to the next matching bar, so that I can use . to make the same change? ...
2
votes
0answers
140 views

Search within syntax group?

Is there a way to take advantage of syntax highlighting for searches? For example, can a search be limited to comments or non-comments, if they are correctly marked by syntax highlighting?
9
votes
2answers
653 views

Duplicate lines beginning with “x”, replacing “x” in the duplicate with “y”?

I have a file with the following pattern: foo 111 baz foo 222 baz foo 333 baz which needs to be turned into foo 111 bar 111 baz foo 222 bar 222 baz foo 333 bar 333 baz So, duplicate all the lines ...