New answers tagged

5

Vee has already given you the answer. I'd like to point out an equivalent but easier to type search pattern. \v(\d{1,3}\.){3}\d{1,3} \v enables very-magic mode, which allows no escaping on {() characters, and \d is a digit.


3

When trying to specify the number of matches to be 1 to 3 entries of the preceding sequence of numbers, the correct format is \{m,n}. The manual reference is here. Your example works when I change it to: /[0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3} in my local test file. Edit As pointed out in the comments, the . should be escaped to be \. to match ...


0

Beside tpope/vim-surround, there is another good plugin called vim-sandwich that can add, replace and delete surround pairs of characters: With vim-sandwich, you can use srb] or sr)] to replace a pair of () to []: sr: start to replace sandwiched text ) or b: the character pair you want to replace, (you use b when there is no ambiguity which pair you want to ...


2

Kind of this %s/Model\a\+/&New/g See :h :s, :h /\a, :h sub-replace-special and so on.


0

With the cursor on the first line at the first column, the command t=<C-v>2jINew<Esc> where: t= moves the cursor to immediately before the first =. <C-v> for visual block mode. 2j to select the two lines beneath. Replace the 2 with any number or press j until the cursor has selected the desired number of lines. I for insert mode. New for ...


1

One of the links referenced put the expression in double quotes ". Using single quotes ' instead fixes the problem with if line =~ '^\(\a\)\{1,}$'. In order for match() to be used in logic like this it needs to be compared to something like: if match(line, '^\(\a\)\{1,}$') == 0 since match() returns 0 when it finds a match at the first character or ...


1

An alternative solution using strptime/strftime to demonstrate expression substitution; %s/[0-9-]\+/\=strftime('%y-%m-%d', strptime('%m-%d-%Y', submatch(0)))/g


2

You need to escape the opening square bracket: :%s/\[s/(s/g For the whole replace, you can use: :%s/]\[\(.)]/](\1)


2

Vim paths in that context are more like shell-globs than regular-expressions. A simple solution in a *nix shell would be $ vim **/*.py (This needs extglob in bash, I think, but should work out of the box in zsh.) Inside of vim, I'm surprised it would match hidden files in the first place, though :help wildcard is clear that it matches "anything." ...


Top 50 recent answers are included