if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; }; package vi; # vi - Adds a vi editing-mode to epic5 # -skullY (zwhite@darkstar.frop.org) 2009 Jun 14 # # skully: this is pure evil genius stuff. @ vi.mode = "off"; # Whether vi mode is active @ vi.insert = "on"; # Whether we're in insert mode # Create a "/set vi_mode" ^on %set "vi_mode *" { if ([$1]==[on]) { @vi.mode = "on"; } elif ([$1]==[off]) { @vi.mode = "off"; }; xecho -b Current value of VI_MODE is $vi.mode }; # Make sure that we always leave command mode when enter is pressed ^on -input "*" { if (vi.insert == "off") { insert_mode; }; }; # There's a slight delay between pressing escape and entering command_mode # due to escape being used for things like function keys, arrows and the # like. I'm not sure there's a good way to get rid of it. bind ^[ parse_command command_mode; # Enters command mode by saving all the keybindings to the stack and # overwriting them. We need to trap all the keys the user might type so # that the illusion of command mode is maintained. alias command_mode (void) { if ((vi.insert == "off") || (vi.mode == "off")) { return; }; @ vi.insert = "off"; stack push bind \ ; stack push bind ^[; stack push bind ~; stack push bind `; stack push bind !; stack push bind @; stack push bind #; stack push bind \$; stack push bind %; stack push bind ^; stack push bind &; stack push bind *; stack push bind \(; stack push bind \); stack push bind \\; stack push bind |; stack push bind ?; stack push bind >; stack push bind <; stack push bind /; stack push bind .; stack push bind ,; stack push bind "; stack push bind '; stack push bind :; stack push bind \;; stack push bind \{; stack push bind \}; stack push bind ]; stack push bind [; stack push bind 1; stack push bind 2; stack push bind 3; stack push bind 4; stack push bind 5; stack push bind 6; stack push bind 7; stack push bind 8; stack push bind 9; stack push bind 0; stack push bind a; stack push bind b; stack push bind c; stack push bind d; stack push bind d\$; stack push bind d^; stack push bind d0; stack push bind dd; stack push bind db; stack push bind dB; stack push bind dw; stack push bind dW; stack push bind e; stack push bind f; stack push bind g; stack push bind h; stack push bind i; stack push bind j; stack push bind k; stack push bind l; stack push bind m; stack push bind n; stack push bind o; stack push bind p; stack push bind q; stack push bind r; stack push bind s; stack push bind t; stack push bind u; stack push bind v; stack push bind w; stack push bind x; stack push bind y; stack push bind z; stack push bind A; stack push bind B; stack push bind C; stack push bind D; stack push bind E; stack push bind F; stack push bind G; stack push bind H; stack push bind I; stack push bind J; stack push bind K; stack push bind L; stack push bind M; stack push bind N; stack push bind O; stack push bind P; stack push bind Q; stack push bind R; stack push bind S; stack push bind T; stack push bind U; stack push bind V; stack push bind W; stack push bind X; stack push bind Y; stack push bind Z; stack push bind ^\\; stack push bind ^A; stack push bind ^B; stack push bind ^C; stack push bind ^D; stack push bind ^E; stack push bind ^F; stack push bind ^G; stack push bind ^H; stack push bind ^I; stack push bind ^K; stack push bind ^L; stack push bind ^N; stack push bind ^O; stack push bind ^P; stack push bind ^Q; stack push bind ^R; stack push bind ^S; stack push bind ^T; stack push bind ^U; stack push bind ^V; stack push bind ^W; stack push bind ^X; stack push bind ^Y; stack push bind ^Z; ^bind " " forward_character; ^bind ^[ nothing; ^bind ~ nothing; ^bind ` nothing; ^bind ! nothing; ^bind @ nothing; ^bind # nothing; ^bind \$ end_of_line; ^bind % nothing; ^bind ^ beginning_of_line; ^bind & nothing; ^bind * nothing; ^bind \( nothing; ^bind \) nothing; ^bind \\ nothing; ^bind | nothing; ^bind ? nothing; ^bind > nothing; ^bind < nothing; ^bind / nothing; ^bind . nothing; ^bind , nothing; ^bind " nothing; ^bind ' nothing; ^bind : nothing; ^bind \; nothing; ^bind \{ nothing; ^bind \} nothing; ^bind ] nothing; ^bind [ nothing; ^bind 1 nothing; ^bind 2 nothing; ^bind 3 nothing; ^bind 4 nothing; ^bind 5 nothing; ^bind 6 nothing; ^bind 7 nothing; ^bind 8 nothing; ^bind 9 nothing; ^bind 0 beginning_of_line; ^bind a parse_command append_mode; ^bind b backward_word; ^bind c nothing; ^bind d nothing; ^bind d\$ erase_to_end_of_line; ^bind d^ erase_to_beg_of_line; ^bind d0 erase_to_beg_of_line; ^bind dd erase_line; ^bind db delete_previous_word; ^bind dB delete_to_previous_space; ^bind dw delete_next_word; ^bind dW delete_next_word; ^bind e parse_command { parsekey forward_word; parsekey backward_character; parsekey backward_character; }; ^bind f nothing; ^bind g scroll_start; ^bind h backward_character; ^bind i parse_command insert_mode; # FIXME: Tie into history somehow ^bind j nothing; ^bind k nothing; ^bind l forward_character; ^bind m nothing; ^bind n nothing; ^bind o nothing; ^bind p yank_from_cutbuffer; ^bind q nothing; ^bind r parse_command replace_char; ^bind s parse_command replace_char; ^bind t nothing; ^bind u nothing; ^bind v nothing; ^bind w forward_word; ^bind x delete_character; # FIXME: Figure out a good way to yank ^bind y nothing; ^bind z nothing; ^bind A parse_command end_of_line_insert_mode; ^bind B backward_word; ^bind C nothing; ^bind D erase_to_end_of_line; ^bind E nothing; ^bind F nothing; ^bind G scroll_end; ^bind H nothing; ^bind I parse_command beginning_of_line_insert_mode; ^bind J nothing; ^bind K nothing; ^bind L nothing; ^bind M nothing; ^bind N nothing; ^bind O nothing; ^bind P yank_from_cutbuffer; ^bind Q nothing; ^bind R parse_command replace_char; ^bind S parse_command replace_line; ^bind T nothing; ^bind U nothing; ^bind V nothing; ^bind W forward_word; ^bind X backspace; ^bind Y nothing; ^bind Z nothing; ^bind ^\\ nothing; ^bind ^A nothing; ^bind ^B scroll_backward; ^bind ^C nothing; ^bind ^D nothing; ^bind ^E nothing; ^bind ^F scroll_forward; ^bind ^G nothing; ^bind ^H backward_character; ^bind ^I nothing; ^bind ^K nothing; ^bind ^L refresh_screen; ^bind ^N nothing; ^bind ^O nothing; ^bind ^P nothing; ^bind ^Q nothing; ^bind ^R nothing; ^bind ^S nothing; ^bind ^T nothing; ^bind ^U nothing; ^bind ^V nothing; ^bind ^W nothing; ^bind ^X nothing; ^bind ^Y nothing; ^bind ^Z nothing; parsekey backward_character; }; alias insert_mode (void) { if (vi.insert == "on") { return; }; @ vi.insert = "on"; stack pop bind \ ; stack pop bind ^[; stack pop bind ~; stack pop bind `; stack pop bind !; stack pop bind @; stack pop bind #; stack pop bind \$; stack pop bind %; stack pop bind ^; stack pop bind &; stack pop bind *; stack pop bind \(; stack pop bind \); stack pop bind \\; stack pop bind |; stack pop bind ?; stack pop bind >; stack pop bind <; stack pop bind /; stack pop bind .; stack pop bind ,; stack pop bind "; stack pop bind '; stack pop bind :; stack pop bind \;; stack pop bind \{; stack pop bind \}; stack pop bind ]; stack pop bind [; stack pop bind 1; stack pop bind 2; stack pop bind 3; stack pop bind 4; stack pop bind 5; stack pop bind 6; stack pop bind 7; stack pop bind 8; stack pop bind 9; stack pop bind 0; stack pop bind a; stack pop bind b; stack pop bind c; stack pop bind d; stack pop bind d\$; stack pop bind d^; stack pop bind d0; stack pop bind dd; stack pop bind db; stack pop bind dB; stack pop bind dw; stack pop bind dW; stack pop bind e; stack pop bind f; stack pop bind g; stack pop bind h; stack pop bind i; stack pop bind j; stack pop bind k; stack pop bind l; stack pop bind m; stack pop bind n; stack pop bind o; stack pop bind p; stack pop bind q; stack pop bind r; stack pop bind s; stack pop bind t; stack pop bind u; stack pop bind v; stack pop bind w; stack pop bind x; stack pop bind y; stack pop bind z; stack pop bind A; stack pop bind B; stack pop bind C; stack pop bind D; stack pop bind E; stack pop bind F; stack pop bind G; stack pop bind H; stack pop bind I; stack pop bind J; stack pop bind K; stack pop bind L; stack pop bind M; stack pop bind N; stack pop bind O; stack pop bind P; stack pop bind Q; stack pop bind R; stack pop bind S; stack pop bind T; stack pop bind U; stack pop bind V; stack pop bind W; stack pop bind X; stack pop bind Y; stack pop bind Z; stack pop bind ^\\; stack pop bind ^A; stack pop bind ^B; stack pop bind ^C; stack pop bind ^D; stack pop bind ^E; stack pop bind ^F; stack pop bind ^G; stack pop bind ^H; stack pop bind ^I; stack pop bind ^K; stack pop bind ^L; stack pop bind ^N; stack pop bind ^O; stack pop bind ^P; stack pop bind ^Q; stack pop bind ^R; stack pop bind ^S; stack pop bind ^T; stack pop bind ^U; stack pop bind ^V; stack pop bind ^W; stack pop bind ^X; stack pop bind ^Y; stack pop bind ^Z; }; alias append_mode (void) { parsekey forward_character; insert_mode; }; alias beginning_of_line_insert_mode (void) { parsekey beginning_of_line; insert_mode; }; alias end_of_line_insert_mode (void) { parsekey end_of_line; insert_mode; }; alias replace_char (void) { parsekey delete_character; # FIXME: Figure out a good way to exit input mode after one char insert_mode; }; alias replace_line (void) { parsekey erase_line; insert_mode; };