Vim change in N item of line possible? E.g. ci2" -



Vim change in N item of line possible? E.g. ci2" -

i commonly want alter sec (or third) attribute in string of html:

<div class="something" data-change="tobechanged">test</div>

at present, i'm doing f" ; needed ci". realise search , replace that's not i'm interested in.

then occurred should able c2i" (change 2nd in "). doesn't work - possible? if so, what's right syntax?

with built-in commands, two-step process: first locate quotes (e.g. via 3f"), select them (ci").

but can create single-step via custom text objects. have following, can c2if":

" af{c}, if{c} / inner [count]'th next {c} text object in current " line. " af{c}, if{c} / inner [count]'th previous {c} text object in " current line. " example, "dif(" go next "()" pair , " delete contents. " source: steve losh, https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc function! s:nexttextobject( scope, isbackward ) allow l:char = ingo#query#get#char() if empty(l:char) | homecoming | endif allow l:save_cursor = getpos('.') allow l:direction = (a:isbackward ? 'f' : 'f') " special case "tag" text object. allow l:findchar = tr(l:char, 't', '>') allow l:nexttextobject = l:direction . l:findchar . 'v' . a:scope . l:char " handle [count], can't prepend f / f command, " depending on text object, there can 2 identical delimiters " need skipped (e.g. in i", not in i[). instead, select each text " object in turn, , repeat @ corresponding border. allow l:count = v:count1 while l:count > 1 allow l:cursor = getpos('.') execute 'normal!' l:nexttextobject . "\<esc>" . \ (a:isbackward ? 'g`<' . (a:scope ==# 'i' ? "\<left>" : '') : '') if l:cursor == getpos('.') phone call cursor(l:save_cursor[1:2]) execute "normal! \<c-\>\<c-n>\<esc>" | " beep. homecoming endif allow l:count -= 1 endwhile execute 'normal!' l:nexttextobject if mode() ==# 'n' phone call cursor(l:save_cursor[1:2]) execute "normal! \<c-\>\<c-n>\<esc>" | " beep. endif endfunction onoremap <silent> af :<c-u>call <sid>nexttextobject('a', 0)<cr> xnoremap <silent> af :<c-u>call <sid>nexttextobject('a', 0)<cr> onoremap <silent> if :<c-u>call <sid>nexttextobject('i', 0)<cr> xnoremap <silent> if :<c-u>call <sid>nexttextobject('i', 0)<cr> onoremap <silent> af :<c-u>call <sid>nexttextobject('a', 1)<cr> xnoremap <silent> af :<c-u>call <sid>nexttextobject('a', 1)<cr> onoremap <silent> if :<c-u>call <sid>nexttextobject('i', 1)<cr> xnoremap <silent> if :<c-u>call <sid>nexttextobject('i', 1)<cr>

note: requires ingo-library plugin.

vim

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -