New answers tagged

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 ...


2

You can use the HTML/XML tag text object: :g/DOG/norm v2at"AY Or if you have a way to reformat the XML afterwards, then this shorter command also works: :g/DOG/norm y2at Both should work in standard vim without plugins.


3

If you have indent-object, you could do something like :global/DOG/normal "Ayii I haven’t come up with a simple vanilla answer yet, but maybe :global/DOG/ ?ROW?,/ROW/yank A @Lie Ryan reminded me of the at text-object, giving :global/DOG/normal "Ay2at Otherwise I’d use a dedicated XML parser and copy the output.


-2

I have found : exe printf('1,'.line('$').'s/\<%s\>/%s/g', elem, 'REPLACE')


2

You have a text (where? in a buffer? in a variable?) and you want replace words given in a list in the text with REPLACE? TEXT: I want to select nest and not nestlé in this text. Only the word nest! LIST OF WORDS: ['nest', 'this'] RESULT: I want to select REPLACE and not nestlé in REPLACE text. Only the word REPLACE! Is this correct? Assuming TEXT is ...


3

Nowdays you can use: set shortmess-=S to enable a count of [x/y] showing in the bottom right corner every time you do a / or ? search. Relavant section from the Vim help


2

:argdo @d doesn’t act like executing @d in every buffer in the arg list: it instead runs :@d in each buffer. It doesn’t execute the contents of the d register as a macro: it executes them as an Ex command. See :help argdo and :help :@. Try :argdo norm!@d instead.


2

One simple tweak is to use \%^ which only matches at the start of the file. You'll also want to pass search() a 'c' flag, to match at the current cursor position (which should be the start of the file.) au BufRead,BufNewFile * \ if search('\%^---', "cn") | \ set filetype=diff | \ endif Another option would be to use getline(1) to get the contents ...


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


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, ...


Top 50 recent answers are included