d
모션 및 비주얼 모드로 명령에 작동하는 개념 증명 솔루션이 있습니다. 그것은 (예를 들어, 아직 완전히 강력한 해결책이 아니다 없습니다 d[count]d
일을하지 않는 , 그리고 어느 쪽도 않습니다 [count]D
)하지만, 매우 거의 모든 내 실제 사용 사례를 설명합니다.
다음과 같은 고객 운영자 기능을 설정하여 작동합니다.
- 레지스터 1-8의 내용을 사전에 저장합니다.
- 레지스터 1로 삭제를 수행합니다.
- 레지스터 2–9를 이전에 저장된 레지스터 1-8의 내용으로 설정합니다.
:help map-operator
연산자 기능 작동 방식에 대한 설명을 참조하십시오 .
function! ShiftingDeleteOperator(type)
let reg_dict = {}
for k in range(1, 8)
execute printf("let reg_dict[%d]=getreg('%d', 1)", k, k)
endfor
if a:type ==# 'v'
execute 'normal! `<v`>d'
elseif a:type ==# 'V'
execute 'normal! `<V`>d'
elseif a:type ==# "\<C-V>"
execute "normal! `<\<C-V>`>d"
elseif a:type ==# 'char'
execute 'normal! `[v`]d'
elseif a:type ==# 'line'
execute "normal! '[V']d"
else
return
endif
let deleted = getreg('"', 1)
call setreg(1, deleted)
for [k, v] in items(reg_dict)
execute printf("call setreg(%d, v)", k + 1)
endfor
endfunction
" Call the function for d{motion} via operatorfunc
nnoremap <silent> d :set operatorfunc=ShiftingDeleteOperator<CR>g@
" Call the function when d or x are hit in visual mode
vnoremap d :<C-U>call ShiftingDeleteOperator(visualmode())<CR>
vnoremap x :<C-U>call ShiftingDeleteOperator(visualmode())<CR>
" Use the d{motion} as defined above to add limited support for `D` command
nmap D d$
" Use the standard dd command
nnoremap dd dd