1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vimでsequential-command.el の <C-a> <C-e>の機能を実現したい。

Last updated at Posted at 2013-11-24

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>を上書いてしまっていいのかは謎い。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?