Wednesday 15 May 2013

VIm change bracket types (without using search and replace) -



VIm change bracket types (without using search and replace) -

this question has reply here:

quickest way alter pair of parenthesis brackets in vim 6 answers

i looking vim key combo changing like

blahblah["hello"]

to

blahblah("hello")

my best effort far is

0f[yi[%c%()^["0p^[

but improve much appreciated.

btw, combo works doing:

find first instance of [ (you point), yank insides (which of course of study means register 0 default, , leaves cursor on first "), move cursor onto first instance of [ %, delete whole [...] bit , go insert mode, write () , <esc> out of insert mode, paste contents of register 0 in between ().

i hoping have muscle-memorable key combination utilize things want 'keep contents alter surroundings'.

my proposal, if cut down minimum (and utilize ca[ rather %c% -- credit this so a motion had not known about) not bad because sort of thing can invent 1 time again 1 time know possible:

yi[ca[()<esc>"0p

however, occurred me search-and-replace going right kind of solution when need few of these in file. here best effort:

select area in visual mode (i tend utilize visual line mode default), then :s/\[\(.\{-}\)\]/(\1)/g<enter> , you're done.

that looks bit mad, simple illustration of so-called backreferencing quite happy have had clear in mind too.

vim

No comments:

Post a Comment