vimでsequential-command.el の <C-a> <C-e>の機能を実現したい。
Emacs使っていた頃につかっていた sequential-command.el (の <C-a>
と<C-e>
のみ)みたいなこと出来ないかな?と、vimrcを頑張ってみた。
いろいろ拙いし考慮漏れもあるような気がするけどとりあえず出来たので書いてみる。
※車輪が再開発されている可能性は否めない
.vimrc(一部)
"ローテート {{{
function! s:save_pos()
let b:cur_pos = getpos('.')
endfunction
autocmd WinEnter,BufRead * call <SID>save_pos()
nnoremap h h:<C-u>call <SID>save_pos()<CR>
nnoremap j j:<C-u>call <SID>save_pos()<CR>
nnoremap k k:<C-u>call <SID>save_pos()<CR>
nnoremap l l:<C-u>call <SID>save_pos()<CR>
nnoremap b b:<C-u>call <SID>save_pos()<CR>
nnoremap <C-b> <C-b>:<C-u>call <SID>save_pos()<CR>
nnoremap <C-f> <C-f>:<C-u>call <SID>save_pos()<CR>
function! s:rotate_in_buffer(r)
let pos_f= getpos('.')
if pos_f == [b:cur_pos[0],1,1,b:cur_pos[0]]
call setpos('.',b:cur_pos)
return
endif
execute a:r ? "normal! ^" : "normal! $"
let pos_s= getpos('.')
if pos_f == pos_s
execute a:r ? "normal! 0" : "normal! G$"
let pos_t = getpos('.')
if pos_s == pos_t
if a:r
execute "normal! gg^"
else
call setpos('.',b:cur_pos)
endif
endif
elseif a:r && pos_s[1] == b:cur_pos[1] && pos_f[2] < pos_s[2]
execute "normal! gg^"
endif
endfunction
nnoremap <silent><C-a> :<C-u>call <SID>rotate_in_buffer(1)<CR>
nnoremap <silent><C-e> :<C-u>call <SID>rotate_in_buffer(0)<CR>
"}}}
<C-a>
を上書いてしまっていいのかは謎い。
Author And Source
この問題について(vimでsequential-command.el の <C-a> <C-e>の機能を実現したい。), 我々は、より多くの情報をここで見つけました https://qiita.com/Echos/items/3086ec5d86e96563a4e8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .