osyo-manga / vital-over

18 stars 3 forks source link

ノーマルモードがほしい #115

Open osyo-manga opened 9 years ago

osyo-manga commented 9 years ago

あると便利そう

osyo-manga commented 9 years ago

素案

call vital#of("vital").unload()
let s:cmdline  = vital#of("vital").import("Over.Commandline")
let s:my = s:cmdline.make_standard("$ ")

let s:normal_mode = {
\   "name" : "NormalMode"
\}

function! s:normal_mode.on_char_pre(cmdline)
    if a:cmdline.is_input("Û")
"   if a:cmdline.is_input("\<A-[>")
        call a:cmdline.tap_keyinput("normal_mode")
        call a:cmdline.setchar("")
        let s:old_highlight = deepcopy(a:cmdline.highlights)
        let a:cmdline.highlights.cursor = "Error"
        let a:cmdline.highlights.cursor_on = "Error"
    endif

    if a:cmdline.is_input("i", "normal_mode")
        call a:cmdline.untap_keyinput("normal_mode")
        call a:cmdline.setchar("")
        let a:cmdline.highlights = s:old_highlight
    endif

    if a:cmdline.is_input("a", "normal_mode")
        call a:cmdline.untap_keyinput("normal_mode")
        call a:cmdline.setchar("")
        call a:cmdline.line.next()
        let a:cmdline.highlights = s:old_highlight
    endif

    if a:cmdline.is_input("\<Esc>", "normal_mode")
\   || a:cmdline.is_input("\<C-c>", "normal_mode")
\   || a:cmdline.is_input("<Over>(exit)", "normal_mode")
        call a:cmdline.exit(1)
    endif

    if a:cmdline.is_input("x", "normal_mode")
        let char = a:cmdline.line.remove_pos()
        if char != ""
            call setreg("*", char)
        endif
    endif

    if a:cmdline.is_input("h", "normal_mode")
        call a:cmdline.line.prev()
    endif

    if a:cmdline.is_input("l", "normal_mode")
        call a:cmdline.line.next()
    endif

    if a:cmdline.is_input("p", "normal_mode")
        call a:cmdline.line.next()
        call a:cmdline.insert(tr(getreg("*"), "\n", "\r"))
        call a:cmdline.line.prev()
    endif

    if a:cmdline.is_input("P", "normal_mode")
        let pos = a:cmdline.getpos()
        call a:cmdline.insert(tr(getreg("*"), "\n", "\r"))
        call a:cmdline.setpos(pos)
    endif

    if a:cmdline.get_tap_key() == "normal_mode"
        if a:cmdline.line.pos() >= a:cmdline.line.length()
            call a:cmdline.line.prev()
        endif
        call a:cmdline.setchar("")
    endif
endfunction

call s:my.connect(s:normal_mode)

function! Test()
    call s:my.start("aaaaa\<A-[>")
endfunction

<A-[> でノーマルモードを開始します。 operator と motion がほしくなる…。