Automatic colon… and more

1 Point

Romain Lafourcade Romain Lafourcade

9 years ago

Automatically presses : for you after list-like commands… and more.

Supported commands:

:dlist and :ilist

:clist and :llist

:changes

:jumps

:oldfiles

:undolist

:ls, :files, :buffers

:#

function! CmdCR()
	if getcmdtype() == ":"
		let cmdline = getcmdline()
		    if cmdline =~ '\v\C^(dli|il)' | return "\<CR>:" . cmdline[0] . "jump  " . split(cmdline, " ")[1] . "\<S-Left>\<Left>"
		elseif cmdline =~ '\v\C^(cli|lli)' | return "\<CR>:silent " . repeat(cmdline[0], 2) . "\<Space>"
		elseif cmdline =~ '\C^changes' | set nomore | return "\<CR>:sil se more|norm! g;\<S-Left>"
		elseif cmdline =~ '\C^ju' | set nomore | return "\<CR>:sil se more|norm! \<C-o>\<S-Left>"
		elseif cmdline =~ '\C^ol' | set nomore | return "\<CR>:sil se more|e #<"
		elseif cmdline =~ '\C^undol' | return "\<CR>:u "
		elseif cmdline =~ '\v\C^(ls|files|buffers)' | return "\<CR>:b"
		elseif cmdline =~ '/#$' | return "\<CR>:"
		else | return "\<CR>" | endif
	else | return "\<CR>" | endif
endfunction

cnoremap <expr> <CR> CmdCR()