New answers tagged

2

But I don't know how to make [a-zA-Z]* a reference to be used to paste in the new form Just put it inside \( and \), that way you can refer to it in the replacement as \1 (assuming that's the first group inside parentheses.) %s/{\.\.\.messages\.\([a-zA-Z]*\)}/id="key.subkey.\1"/ See also :help s/\1.


4

So you want to skip the first column (comma delimited) and search for everything, where the second column is the same as the third column. As a regex this can be written like this: ^[^,]*,\zs\([^,]*\),\1 | | | | | | || └ Same match as what was captured | | | | | | |└ Comma | | | | | | └ End of captured group | | | | | └ ...


2

I'm late but here is my current solution based on @mike's work: nnoremap cri mmva[<bar>:s/\v:(\w+),?/\1/g<bar>s/\v(\[([^\]])*\])/%i\1/g<bar>:nohlsearch<bar>:normal `m<Return> Short breakdown: nnoremap cri maps cri in normal mode mm marks the current position va[ select the array around the cursor position <bar> pipes ...


0

My attempt :%norm 4ftdwx :%norm ......... execute in normal mode over the whole file 4ft ............ the 4th t matches the start of the second temp dw ............. deletes the current word x .............. deletes the dot


1

To highlight URL, you can use vim-highlighturl, which can highlight all kinds of URLs. To open URL in browser, you can use open-browser.vim and define the following shortcut to open URL in browser: nmap ob <Plug>(openbrowser-smart-search) vmap ob <Plug>(openbrowser-smart-search)


1

You have extra quotes in your regex, it should look like: syn match matchURL /http[s]\?:\/\/[[:alnum:]%\/_#.-]*/ hi matchURL ctermfg=14 Then, to save the match under the cursor in a variable, you can do: let link = expand('<cWORD>') let link = matchstr(link, 'http[s]\?:\/\/[[:alnum:]%\/_#.-]*')


-1

Here's my function (based on @BLayer’s answer: He's a self made man who gets what he wants. The small blue forget me not flower was first used by the Grand Lodge. function MyFunction() let myList1 = ["self made man", "forget me not"] for elem1 in myList1 if search("=/elem1", 'W') == 0 let elem2 = substitute(elem1, ' ', '-', ...


0

You're looking for the substitute() function... substitute({expr}, {pat}, {sub}, {flags}) expr is the string to work on pat is the pattern similar to :s/pat/sub/g. sub is the substitution similar to sub in the same :s command. flags, should include "g" as in global (again, like :s) So... let elem = substitute(elem, ' ', '-', 'g') The second param could ...


0

The problem you're having is that it's matching all the way to the last occurrence of the pattern suite on the line. To solve that, you can either use a non-greedy multi or you can restrict your match to non-whitespace characters only. A non-greedy multi such as \{-} would solve your issue: \{-} matches 0 or more of the preceding atom, as few as ...


0

You could just use \ze after suite, like this: silent! exe '%s/\<https.*suite\ze/\=add(myList, submatch(0))/gn' which will set the end of the match at that position. See: :help /\ze


1

The problem is with the ^\s* in ignoreHiInComments, that's outside of the negative look-behind match, so it will always only match from the first word of the line since it needs to match ^\s* first. Did you mean to include that inside the negative look-behind match? let ignoreHiInComments = '\(^\s*\/\/.*\)\@<!' "Ignore highlighting in C++ comments ...


2

From pattern.txt: */\@<!* \@<! Matches with zero width if the preceding atom does NOT match just before what follows. Thus this matches if there is no position in the current or previous line where the atom matches such that it ends just before what follows. Note the word atom. The definition of atom: ...


2

there's presumably something like g/BY EFT/s/\%23c-\%29c/X/ that would do it in a single command. 23-29 is the same as 7 columns/chars starting from 23. g/WITHDRAWAL BY EFT/s/\%23c.\{7\}/XXXXXXX If it's guaranteed to be the first 7-digit number in the string "WITHDRAWAL" you can change it to: g/WITHDRAWAL BY EFT/s/\d\{7\}/XXXXXXX


2

I feel like this is all overly complicated, you can realize this with just a few lines of regex: s/<\(\w\+\)>\%#/&<\/\1>/g This expression will allow you to add a closing tag after the cursor: - < matches the start of the opening tag - \w\+ matches the tag content, we include it in braces so that we can use it in the replacement - > ...


5

Characters displayed by ^ followed by a capital letter (or a small number of other symbols, such as ^[) are the usual notation for the ASCII character produced by pressing that letter while holding the Control key. Vim will typically show these in a distinct color or highlight (to indicate it's displaying a Control-sequence and not two separate characters, ...


0

As I am still relatively new to vim, if there is a better alternative or if there are improvements to be made, please do let me know. Setup The solution I ended up with makes use of a regular expression that is saved to a separate regex.vim file, which is sourced in init.vim. The full explanation can be found here: Save commonly used regex patterns in Vim?...


Top 50 recent answers are included