Skip to main content
20 votes

Ignore folders when performing :find command

The following enables fuzzy file search (i.e :find script.js) through every file in your project root while excluding the node_modules dir and its contents. set path+=** ...
bajocode's user avatar
  • 301
18 votes

Simultaneous find and replace

Yes, you can do that by using an expression. For this particular case, you can use Vim arithmetic and calculate 1-x, which will turn 0 into 1 and 1 into 0. :s/\d/\=1-submatch(0)/g For a more general ...
filbranden's user avatar
  • 29k
17 votes

How to search for any repeating character, X number of times

There's two different regex features that would be helpful. First off, you can use capturing groups. If you put something in parentheses, you can refer to whatever matched inside. So /\(.\)\1 Will ...
DJMcMayhem's user avatar
  • 17.7k
17 votes

Simultaneous find and replace

There's a bunch of excellent answers here already, but for the sake of completeness I feel like I should point out that, in most practical respects, if you concatenate multiple ex commands with the ...
Rich's user avatar
  • 32.2k
8 votes

Simultaneous find and replace

In your specific use case, i think what you can do is this handy oneline: %s/0\|1/\=!submatch(0)/g That basically inverts the match.
Christian Brabandt's user avatar
7 votes
Accepted

Named capture groups in vim regex?

No, named capture groups are not available. In fact, some design decisions in Vim actually expose the limit of 9 (numbered) capture groups, such as the matchlist() function, which returns a list of 10 ...
filbranden's user avatar
  • 29k
7 votes

Simultaneous find and replace

Sure: %s/[01]/\="10"[submatch(0)]/g Matches either a 0 or 1 and replaces it with either "10"[0] = 1 or "10"[1] = 0
Ralf's user avatar
  • 9,287
7 votes

Simultaneous find and replace

This answer is longer than others, it didn't take the specific data value advantage, it's a general solution to replace n different values with n different replacements: let d={0:1,1:0} | %s/\v(0|1)/\...
dedowsdi's user avatar
  • 6,298
6 votes
Accepted

Advance to next (multi)characters on a line

Vim provides the f, t or F, T command to jump forward or backward to a character in current line, and you can repeat the action by pressing , or ;. While these commands are useful, they are not ...
jdhao's user avatar
  • 1,143
6 votes

Simultaneous find and replace

I'm actually surprised there is no native tr in vi/vim, but if your platform is UNIXy enough, there's an external command for just this: :%!tr 01 10 This is what I would personally use, but it may ...
pipe's user avatar
  • 239
5 votes
Accepted

Replace after a specific pattern

One way to do this is by using \zs to set the "start" of the match, so that everything before \zs is untouched by the replacement: :%s/RESULT=\zs.*/200/g Your original attempt using a lookbehind was ...
Rich's user avatar
  • 32.2k
5 votes
Accepted

How to do a find with a regex and jump to a specific position within the match

You can use \zs (and it's complement, \ze), e.g. /:q: \zs should work for your example (assuming there is exactly 1 space after the second :) It works by setting the start (or end in the case of \...
flemingfleming's user avatar
5 votes

How to "find" or "till" a bigram?

The sneak plugin provides that functionality. By default, it's bound to the s key, so you would need to use sts for your example. The documentation also gives example mappings to put sneak's ...
jamessan's user avatar
  • 11.1k
5 votes
Accepted

Keystroke to move cursor to the last character of a highlight?

gn + <Escape> gn Search forward for the last used search pattern, like with n, and start Visual mode to select the match. If ...
laktak's user avatar
  • 2,953
5 votes
Accepted

What is the difference between :find and :edit

The difference is that :find will actually search for a file by that name in the list of directories specified in 'path'. The default 'path' contains . (which is the path of the current file), then /...
filbranden's user avatar
  • 29k
5 votes

Simultaneous find and replace

I'm quite certain I've already gave an answer to the general case either here on vi.SE, or on stackoverflow, but impossible to find the Q/A... In that answer I provide the command CycleSubstitute ...
Luc Hermitte's user avatar
  • 17.5k
5 votes

Simultaneous find and replace

Similar to @LucHermitte's answer, the SwapStrings plugin lets you do :%SwapStrings 0 1 My own PatternsOnText plugin provides (among many others) a :SubstituteMultiple command that can do swaps as a ...
Ingo Karkat's user avatar
  • 17.9k
4 votes
Accepted

How to check if a pattern is contained in a register's content?

To get the content of the register "o you can use: getreg('o') This will return the content of the register as a string. To match a string you can use match(): echo match(getreg('o'), 'image') ...
statox's user avatar
  • 50.1k
4 votes
Accepted

How to find a executable file inside a folder?

I don't fully understand your question, i know two ways to find all executable files inside a folder: readdir( require patch 8.1.1120) echo readdir('dir', {v-> executable('dir/' . v) && !...
dedowsdi's user avatar
  • 6,298
4 votes
Accepted

Replace Only First Occurence after Pattern

That % in the %s command at the beginning of your command specifies a range and tells the command to be run for all lines (short for 1,$, where $ stands for the last line). Besides line numbers, you ...
Christian Brabandt's user avatar
4 votes
Accepted

Fastest way to find last occurence of a character in line?

I find it is best to not get too wrapped up in optimizing for minimal keystrokes, but instead learning & using motions effectively. Sometimes this means multiple motions, multiple operations, and ...
Peter Rincker's user avatar
4 votes
Accepted

Use *-like command in normal mode to execute a find/replace

You could do the replace in two steps: You prepare a search command using * (/\<the\>) You do your replace with an empty search (:%s//the only/g) The replace will default the search to the ...
Vivian De Smedt's user avatar
3 votes

How can I pass extra flags to FZF/ripgrep commands with the leader key?

Please note that I changed your mapping to suit my keyboard. However this is what I got in terms of functionality: nnoremap <C-P> :MyFind0<CR> nnoremap <Leader><C-P> :MyFind1&...
igorepst's user avatar
  • 143
3 votes

How to do a find with a regex and jump to a specific position within the match

You can change the location in which the cursor is left after a search by using an offset: You can either an "end" or "start" offset for your specific example: /:q:/e+2 /:q:/s+4 See :help search-...
Rich's user avatar
  • 32.2k
3 votes

Find and replace string with slash in it and retain the slash in the new string

As you state, your string contains / so presumably that is tripping you up since it must be escaped if you use / to delimit the sections of your substitution command. See the other answer here for ...
B Layer's user avatar
  • 20k
3 votes

Exclude some paths from :find path

vim-rails and vim-ruby are setting path, and they don't really care that path is limited to 1024 characters on some platforms throwing out what you set. Solved with autocmd: let g:project_find_path =...
phil pirozhkov's user avatar
3 votes

How to "find" or "till" a bigram?

Besides the plugins mentions, there are several other plugins available, that extend the f and t motions. Among there are clever-f, vim-fanfingtastic and my own ft-improved. At least for my plugin I ...
Christian Brabandt's user avatar
3 votes

How to "find" or "till" a bigram?

The easymotion plugin also provides functionality like that. Easymotion is considered to be larger with more features, both come highly recommended. Maybe someone needs to write a review of both, ...
mike's user avatar
  • 959
3 votes

Replace after a specific pattern

@Rich's solution is a perfect general solution, however maybe your question is a good example of an XY problem. For your specific use case Vim has :h CTRL-A and :h CTRL-X: CTRL-A Add [count] ...
statox's user avatar
  • 50.1k

Only top scored, non community-wiki answers of a minimum length are eligible