Mercurial > vim
comparison src/normal.c @ 5735:50dbef5e774a v7.4.212
updated for version 7.4.212
Problem: Now that the +visual feature is always enabled the #ifdefs for it
are not useful.
Solution: Remove the checks for FEAT_VISUAL.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sun, 23 Mar 2014 15:13:05 +0100 |
parents | 54b1a90c9373 |
children | 75f222d67cea |
comparison
equal
deleted
inserted
replaced
5734:657ade71d395 | 5735:50dbef5e774a |
---|---|
12 * the operators. | 12 * the operators. |
13 */ | 13 */ |
14 | 14 |
15 #include "vim.h" | 15 #include "vim.h" |
16 | 16 |
17 #ifdef FEAT_VISUAL | |
18 /* | 17 /* |
19 * The Visual area is remembered for reselection. | 18 * The Visual area is remembered for reselection. |
20 */ | 19 */ |
21 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | 20 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
22 static linenr_T resel_VIsual_line_count; /* number of lines */ | 21 static linenr_T resel_VIsual_line_count; /* number of lines */ |
23 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ | 22 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
24 static int VIsual_mode_orig = NUL; /* saved Visual mode */ | 23 static int VIsual_mode_orig = NUL; /* saved Visual mode */ |
25 | 24 |
26 static int restart_VIsual_select = 0; | 25 static int restart_VIsual_select = 0; |
27 #endif | |
28 | 26 |
29 #ifdef FEAT_EVAL | 27 #ifdef FEAT_EVAL |
30 static void set_vcount_ca __ARGS((cmdarg_T *cap, int *set_prevcount)); | 28 static void set_vcount_ca __ARGS((cmdarg_T *cap, int *set_prevcount)); |
31 #endif | 29 #endif |
32 static int | 30 static int |
35 #endif | 33 #endif |
36 nv_compare __ARGS((const void *s1, const void *s2)); | 34 nv_compare __ARGS((const void *s1, const void *s2)); |
37 static int find_command __ARGS((int cmdchar)); | 35 static int find_command __ARGS((int cmdchar)); |
38 static void op_colon __ARGS((oparg_T *oap)); | 36 static void op_colon __ARGS((oparg_T *oap)); |
39 static void op_function __ARGS((oparg_T *oap)); | 37 static void op_function __ARGS((oparg_T *oap)); |
40 #if defined(FEAT_MOUSE) && defined(FEAT_VISUAL) | 38 #if defined(FEAT_MOUSE) |
41 static void find_start_of_word __ARGS((pos_T *)); | 39 static void find_start_of_word __ARGS((pos_T *)); |
42 static void find_end_of_word __ARGS((pos_T *)); | 40 static void find_end_of_word __ARGS((pos_T *)); |
43 static int get_mouse_class __ARGS((char_u *p)); | 41 static int get_mouse_class __ARGS((char_u *p)); |
44 #endif | 42 #endif |
45 static void prep_redo_cmd __ARGS((cmdarg_T *cap)); | 43 static void prep_redo_cmd __ARGS((cmdarg_T *cap)); |
46 static void prep_redo __ARGS((int regname, long, int, int, int, int, int)); | 44 static void prep_redo __ARGS((int regname, long, int, int, int, int, int)); |
47 static int checkclearop __ARGS((oparg_T *oap)); | 45 static int checkclearop __ARGS((oparg_T *oap)); |
48 static int checkclearopq __ARGS((oparg_T *oap)); | 46 static int checkclearopq __ARGS((oparg_T *oap)); |
49 static void clearop __ARGS((oparg_T *oap)); | 47 static void clearop __ARGS((oparg_T *oap)); |
50 static void clearopbeep __ARGS((oparg_T *oap)); | 48 static void clearopbeep __ARGS((oparg_T *oap)); |
51 #ifdef FEAT_VISUAL | |
52 static void unshift_special __ARGS((cmdarg_T *cap)); | 49 static void unshift_special __ARGS((cmdarg_T *cap)); |
53 #endif | |
54 #ifdef FEAT_CMDL_INFO | 50 #ifdef FEAT_CMDL_INFO |
55 static void del_from_showcmd __ARGS((int)); | 51 static void del_from_showcmd __ARGS((int)); |
56 #endif | 52 #endif |
57 | 53 |
58 /* | 54 /* |
115 static void nv_kundo __ARGS((cmdarg_T *cap)); | 111 static void nv_kundo __ARGS((cmdarg_T *cap)); |
116 static void nv_Replace __ARGS((cmdarg_T *cap)); | 112 static void nv_Replace __ARGS((cmdarg_T *cap)); |
117 #ifdef FEAT_VREPLACE | 113 #ifdef FEAT_VREPLACE |
118 static void nv_vreplace __ARGS((cmdarg_T *cap)); | 114 static void nv_vreplace __ARGS((cmdarg_T *cap)); |
119 #endif | 115 #endif |
120 #ifdef FEAT_VISUAL | |
121 static void v_swap_corners __ARGS((int cmdchar)); | 116 static void v_swap_corners __ARGS((int cmdchar)); |
122 #endif | |
123 static void nv_replace __ARGS((cmdarg_T *cap)); | 117 static void nv_replace __ARGS((cmdarg_T *cap)); |
124 static void n_swapchar __ARGS((cmdarg_T *cap)); | 118 static void n_swapchar __ARGS((cmdarg_T *cap)); |
125 static void nv_cursormark __ARGS((cmdarg_T *cap, int flag, pos_T *pos)); | 119 static void nv_cursormark __ARGS((cmdarg_T *cap, int flag, pos_T *pos)); |
126 #ifdef FEAT_VISUAL | |
127 static void v_visop __ARGS((cmdarg_T *cap)); | 120 static void v_visop __ARGS((cmdarg_T *cap)); |
128 #endif | |
129 static void nv_subst __ARGS((cmdarg_T *cap)); | 121 static void nv_subst __ARGS((cmdarg_T *cap)); |
130 static void nv_abbrev __ARGS((cmdarg_T *cap)); | 122 static void nv_abbrev __ARGS((cmdarg_T *cap)); |
131 static void nv_optrans __ARGS((cmdarg_T *cap)); | 123 static void nv_optrans __ARGS((cmdarg_T *cap)); |
132 static void nv_gomark __ARGS((cmdarg_T *cap)); | 124 static void nv_gomark __ARGS((cmdarg_T *cap)); |
133 static void nv_pcmark __ARGS((cmdarg_T *cap)); | 125 static void nv_pcmark __ARGS((cmdarg_T *cap)); |
134 static void nv_regname __ARGS((cmdarg_T *cap)); | 126 static void nv_regname __ARGS((cmdarg_T *cap)); |
135 #ifdef FEAT_VISUAL | |
136 static void nv_visual __ARGS((cmdarg_T *cap)); | 127 static void nv_visual __ARGS((cmdarg_T *cap)); |
137 static void n_start_visual_mode __ARGS((int c)); | 128 static void n_start_visual_mode __ARGS((int c)); |
138 #endif | |
139 static void nv_window __ARGS((cmdarg_T *cap)); | 129 static void nv_window __ARGS((cmdarg_T *cap)); |
140 static void nv_suspend __ARGS((cmdarg_T *cap)); | 130 static void nv_suspend __ARGS((cmdarg_T *cap)); |
141 static void nv_g_cmd __ARGS((cmdarg_T *cap)); | 131 static void nv_g_cmd __ARGS((cmdarg_T *cap)); |
142 static void n_opencmd __ARGS((cmdarg_T *cap)); | 132 static void n_opencmd __ARGS((cmdarg_T *cap)); |
143 static void nv_dot __ARGS((cmdarg_T *cap)); | 133 static void nv_dot __ARGS((cmdarg_T *cap)); |
153 static void nv_pipe __ARGS((cmdarg_T *cap)); | 143 static void nv_pipe __ARGS((cmdarg_T *cap)); |
154 static void nv_bck_word __ARGS((cmdarg_T *cap)); | 144 static void nv_bck_word __ARGS((cmdarg_T *cap)); |
155 static void nv_wordcmd __ARGS((cmdarg_T *cap)); | 145 static void nv_wordcmd __ARGS((cmdarg_T *cap)); |
156 static void nv_beginline __ARGS((cmdarg_T *cap)); | 146 static void nv_beginline __ARGS((cmdarg_T *cap)); |
157 static void adjust_cursor __ARGS((oparg_T *oap)); | 147 static void adjust_cursor __ARGS((oparg_T *oap)); |
158 #ifdef FEAT_VISUAL | |
159 static void adjust_for_sel __ARGS((cmdarg_T *cap)); | 148 static void adjust_for_sel __ARGS((cmdarg_T *cap)); |
160 static int unadjust_for_sel __ARGS((void)); | 149 static int unadjust_for_sel __ARGS((void)); |
161 static void nv_select __ARGS((cmdarg_T *cap)); | 150 static void nv_select __ARGS((cmdarg_T *cap)); |
162 #endif | |
163 static void nv_goto __ARGS((cmdarg_T *cap)); | 151 static void nv_goto __ARGS((cmdarg_T *cap)); |
164 static void nv_normal __ARGS((cmdarg_T *cap)); | 152 static void nv_normal __ARGS((cmdarg_T *cap)); |
165 static void nv_esc __ARGS((cmdarg_T *oap)); | 153 static void nv_esc __ARGS((cmdarg_T *oap)); |
166 static void nv_edit __ARGS((cmdarg_T *cap)); | 154 static void nv_edit __ARGS((cmdarg_T *cap)); |
167 static void invoke_edit __ARGS((cmdarg_T *cap, int repl, int cmd, int startln)); | 155 static void invoke_edit __ARGS((cmdarg_T *cap, int repl, int cmd, int startln)); |
246 {Ctrl_L, nv_clear, 0, 0}, | 234 {Ctrl_L, nv_clear, 0, 0}, |
247 {Ctrl_M, nv_down, 0, TRUE}, | 235 {Ctrl_M, nv_down, 0, TRUE}, |
248 {Ctrl_N, nv_down, NV_STS, FALSE}, | 236 {Ctrl_N, nv_down, NV_STS, FALSE}, |
249 {Ctrl_O, nv_ctrlo, 0, 0}, | 237 {Ctrl_O, nv_ctrlo, 0, 0}, |
250 {Ctrl_P, nv_up, NV_STS, FALSE}, | 238 {Ctrl_P, nv_up, NV_STS, FALSE}, |
251 #ifdef FEAT_VISUAL | |
252 {Ctrl_Q, nv_visual, 0, FALSE}, | 239 {Ctrl_Q, nv_visual, 0, FALSE}, |
253 #else | |
254 {Ctrl_Q, nv_ignore, 0, 0}, | |
255 #endif | |
256 {Ctrl_R, nv_redo, 0, 0}, | 240 {Ctrl_R, nv_redo, 0, 0}, |
257 {Ctrl_S, nv_ignore, 0, 0}, | 241 {Ctrl_S, nv_ignore, 0, 0}, |
258 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | 242 {Ctrl_T, nv_tagpop, NV_NCW, 0}, |
259 {Ctrl_U, nv_halfpage, 0, 0}, | 243 {Ctrl_U, nv_halfpage, 0, 0}, |
260 #ifdef FEAT_VISUAL | |
261 {Ctrl_V, nv_visual, 0, FALSE}, | 244 {Ctrl_V, nv_visual, 0, FALSE}, |
262 {'V', nv_visual, 0, FALSE}, | 245 {'V', nv_visual, 0, FALSE}, |
263 {'v', nv_visual, 0, FALSE}, | 246 {'v', nv_visual, 0, FALSE}, |
264 #else | |
265 {Ctrl_V, nv_error, 0, 0}, | |
266 {'V', nv_error, 0, 0}, | |
267 {'v', nv_error, 0, 0}, | |
268 #endif | |
269 {Ctrl_W, nv_window, 0, 0}, | 247 {Ctrl_W, nv_window, 0, 0}, |
270 {Ctrl_X, nv_addsub, 0, 0}, | 248 {Ctrl_X, nv_addsub, 0, 0}, |
271 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | 249 {Ctrl_Y, nv_scroll_line, 0, FALSE}, |
272 {Ctrl_Z, nv_suspend, 0, 0}, | 250 {Ctrl_Z, nv_suspend, 0, 0}, |
273 {ESC, nv_esc, 0, FALSE}, | 251 {ESC, nv_esc, 0, FALSE}, |
425 {K_KDEL, nv_abbrev, 0, 0}, | 403 {K_KDEL, nv_abbrev, 0, 0}, |
426 {K_UNDO, nv_kundo, 0, 0}, | 404 {K_UNDO, nv_kundo, 0, 0}, |
427 {K_HELP, nv_help, NV_NCW, 0}, | 405 {K_HELP, nv_help, NV_NCW, 0}, |
428 {K_F1, nv_help, NV_NCW, 0}, | 406 {K_F1, nv_help, NV_NCW, 0}, |
429 {K_XF1, nv_help, NV_NCW, 0}, | 407 {K_XF1, nv_help, NV_NCW, 0}, |
430 #ifdef FEAT_VISUAL | |
431 {K_SELECT, nv_select, 0, 0}, | 408 {K_SELECT, nv_select, 0, 0}, |
432 #endif | |
433 #ifdef FEAT_GUI | 409 #ifdef FEAT_GUI |
434 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | 410 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, |
435 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | 411 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, |
436 #endif | 412 #endif |
437 #ifdef FEAT_GUI_TABLINE | 413 #ifdef FEAT_GUI_TABLINE |
577 int ctrl_w = FALSE; /* got CTRL-W command */ | 553 int ctrl_w = FALSE; /* got CTRL-W command */ |
578 int old_col = curwin->w_curswant; | 554 int old_col = curwin->w_curswant; |
579 #ifdef FEAT_CMDL_INFO | 555 #ifdef FEAT_CMDL_INFO |
580 int need_flushbuf; /* need to call out_flush() */ | 556 int need_flushbuf; /* need to call out_flush() */ |
581 #endif | 557 #endif |
582 #ifdef FEAT_VISUAL | |
583 pos_T old_pos; /* cursor position before command */ | 558 pos_T old_pos; /* cursor position before command */ |
584 int mapped_len; | 559 int mapped_len; |
585 static int old_mapped_len = 0; | 560 static int old_mapped_len = 0; |
586 #endif | |
587 int idx; | 561 int idx; |
588 #ifdef FEAT_EVAL | 562 #ifdef FEAT_EVAL |
589 int set_prevcount = FALSE; | 563 int set_prevcount = FALSE; |
590 #endif | 564 #endif |
591 | 565 |
641 oap->prev_opcount = 0; | 615 oap->prev_opcount = 0; |
642 oap->prev_count0 = 0; | 616 oap->prev_count0 = 0; |
643 } | 617 } |
644 #endif | 618 #endif |
645 | 619 |
646 #ifdef FEAT_VISUAL | |
647 mapped_len = typebuf_maplen(); | 620 mapped_len = typebuf_maplen(); |
648 #endif | |
649 | 621 |
650 State = NORMAL_BUSY; | 622 State = NORMAL_BUSY; |
651 #ifdef USE_ON_FLY_SCROLL | 623 #ifdef USE_ON_FLY_SCROLL |
652 dont_scroll = FALSE; /* allow scrolling here */ | 624 dont_scroll = FALSE; /* allow scrolling here */ |
653 #endif | 625 #endif |
664 * Get the command character from the user. | 636 * Get the command character from the user. |
665 */ | 637 */ |
666 c = safe_vgetc(); | 638 c = safe_vgetc(); |
667 LANGMAP_ADJUST(c, TRUE); | 639 LANGMAP_ADJUST(c, TRUE); |
668 | 640 |
669 #ifdef FEAT_VISUAL | |
670 /* | 641 /* |
671 * If a mapping was started in Visual or Select mode, remember the length | 642 * If a mapping was started in Visual or Select mode, remember the length |
672 * of the mapping. This is used below to not return to Insert mode for as | 643 * of the mapping. This is used below to not return to Insert mode for as |
673 * long as the mapping is being executed. | 644 * long as the mapping is being executed. |
674 */ | 645 */ |
675 if (restart_edit == 0) | 646 if (restart_edit == 0) |
676 old_mapped_len = 0; | 647 old_mapped_len = 0; |
677 else if (old_mapped_len | 648 else if (old_mapped_len |
678 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) | 649 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
679 old_mapped_len = typebuf_maplen(); | 650 old_mapped_len = typebuf_maplen(); |
680 #endif | |
681 | 651 |
682 if (c == NUL) | 652 if (c == NUL) |
683 c = K_ZERO; | 653 c = K_ZERO; |
684 | 654 |
685 #ifdef FEAT_VISUAL | |
686 /* | 655 /* |
687 * In Select mode, typed text replaces the selection. | 656 * In Select mode, typed text replaces the selection. |
688 */ | 657 */ |
689 if (VIsual_active | 658 if (VIsual_active |
690 && VIsual_select | 659 && VIsual_select |
701 else | 670 else |
702 c = 'c'; | 671 c = 'c'; |
703 msg_nowait = TRUE; /* don't delay going to insert mode */ | 672 msg_nowait = TRUE; /* don't delay going to insert mode */ |
704 old_mapped_len = 0; /* do go to Insert mode */ | 673 old_mapped_len = 0; /* do go to Insert mode */ |
705 } | 674 } |
706 #endif | |
707 | 675 |
708 #ifdef FEAT_CMDL_INFO | 676 #ifdef FEAT_CMDL_INFO |
709 need_flushbuf = add_to_showcmd(c); | 677 need_flushbuf = add_to_showcmd(c); |
710 #endif | 678 #endif |
711 | 679 |
712 getcount: | 680 getcount: |
713 #ifdef FEAT_VISUAL | |
714 if (!(VIsual_active && VIsual_select)) | 681 if (!(VIsual_active && VIsual_select)) |
715 #endif | |
716 { | 682 { |
717 /* | 683 /* |
718 * Handle a count before a command and compute ca.count0. | 684 * Handle a count before a command and compute ca.count0. |
719 * Note that '0' is a command and not the start of a count, but it's | 685 * Note that '0' is a command and not the start of a count, but it's |
720 * part of a count after other digits. | 686 * part of a count after other digits. |
854 #ifdef FEAT_AUTOCMD | 820 #ifdef FEAT_AUTOCMD |
855 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) | 821 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
856 goto normal_end; | 822 goto normal_end; |
857 #endif | 823 #endif |
858 | 824 |
859 #ifdef FEAT_VISUAL | |
860 /* | 825 /* |
861 * In Visual/Select mode, a few keys are handled in a special way. | 826 * In Visual/Select mode, a few keys are handled in a special way. |
862 */ | 827 */ |
863 if (VIsual_active) | 828 if (VIsual_active) |
864 { | 829 { |
890 { | 855 { |
891 mod_mask &= ~MOD_MASK_SHIFT; | 856 mod_mask &= ~MOD_MASK_SHIFT; |
892 } | 857 } |
893 } | 858 } |
894 } | 859 } |
895 #endif | |
896 | 860 |
897 #ifdef FEAT_RIGHTLEFT | 861 #ifdef FEAT_RIGHTLEFT |
898 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | 862 if (curwin->w_p_rl && KeyTyped && !KeyStuffed |
899 && (nv_cmds[idx].cmd_flags & NV_RL)) | 863 && (nv_cmds[idx].cmd_flags & NV_RL)) |
900 { | 864 { |
928 || (ca.cmdchar == 'q' | 892 || (ca.cmdchar == 'q' |
929 && oap->op_type == OP_NOP | 893 && oap->op_type == OP_NOP |
930 && !Recording | 894 && !Recording |
931 && !Exec_reg) | 895 && !Exec_reg) |
932 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') | 896 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
933 && (oap->op_type != OP_NOP | 897 && (oap->op_type != OP_NOP || VIsual_active)))) |
934 #ifdef FEAT_VISUAL | |
935 || VIsual_active | |
936 #endif | |
937 )))) | |
938 { | 898 { |
939 int *cp; | 899 int *cp; |
940 int repl = FALSE; /* get character for replace mode */ | 900 int repl = FALSE; /* get character for replace mode */ |
941 int lit = FALSE; /* get extra character literally */ | 901 int lit = FALSE; /* get extra character literally */ |
942 int langmap_active = FALSE; /* using :lmap mappings */ | 902 int langmap_active = FALSE; /* using :lmap mappings */ |
1166 { | 1126 { |
1167 msg_didout = FALSE; /* don't scroll screen up for normal command */ | 1127 msg_didout = FALSE; /* don't scroll screen up for normal command */ |
1168 msg_col = 0; | 1128 msg_col = 0; |
1169 } | 1129 } |
1170 | 1130 |
1171 #ifdef FEAT_VISUAL | |
1172 old_pos = curwin->w_cursor; /* remember where cursor was */ | 1131 old_pos = curwin->w_cursor; /* remember where cursor was */ |
1173 | 1132 |
1174 /* When 'keymodel' contains "startsel" some keys start Select/Visual | 1133 /* When 'keymodel' contains "startsel" some keys start Select/Visual |
1175 * mode. */ | 1134 * mode. */ |
1176 if (!VIsual_active && km_startsel) | 1135 if (!VIsual_active && km_startsel) |
1186 { | 1145 { |
1187 start_selection(); | 1146 start_selection(); |
1188 mod_mask &= ~MOD_MASK_SHIFT; | 1147 mod_mask &= ~MOD_MASK_SHIFT; |
1189 } | 1148 } |
1190 } | 1149 } |
1191 #endif | |
1192 | 1150 |
1193 /* | 1151 /* |
1194 * Execute the command! | 1152 * Execute the command! |
1195 * Call the command function found in the commands table. | 1153 * Call the command function found in the commands table. |
1196 */ | 1154 */ |
1218 set_reg_var(regname); | 1176 set_reg_var(regname); |
1219 } | 1177 } |
1220 #endif | 1178 #endif |
1221 } | 1179 } |
1222 | 1180 |
1223 #ifdef FEAT_VISUAL | |
1224 /* Get the length of mapped chars again after typing a count, second | 1181 /* Get the length of mapped chars again after typing a count, second |
1225 * character or "z333<cr>". */ | 1182 * character or "z333<cr>". */ |
1226 if (old_mapped_len > 0) | 1183 if (old_mapped_len > 0) |
1227 old_mapped_len = typebuf_maplen(); | 1184 old_mapped_len = typebuf_maplen(); |
1228 #endif | |
1229 | 1185 |
1230 /* | 1186 /* |
1231 * If an operation is pending, handle it... | 1187 * If an operation is pending, handle it... |
1232 */ | 1188 */ |
1233 do_pending_operator(&ca, old_col, FALSE); | 1189 do_pending_operator(&ca, old_col, FALSE); |
1245 * Don't redraw the screen, it would remove the message. | 1201 * Don't redraw the screen, it would remove the message. |
1246 */ | 1202 */ |
1247 if ( ((p_smd | 1203 if ( ((p_smd |
1248 && msg_silent == 0 | 1204 && msg_silent == 0 |
1249 && (restart_edit != 0 | 1205 && (restart_edit != 0 |
1250 #ifdef FEAT_VISUAL | |
1251 || (VIsual_active | 1206 || (VIsual_active |
1252 && old_pos.lnum == curwin->w_cursor.lnum | 1207 && old_pos.lnum == curwin->w_cursor.lnum |
1253 && old_pos.col == curwin->w_cursor.col) | 1208 && old_pos.col == curwin->w_cursor.col) |
1254 #endif | |
1255 ) | 1209 ) |
1256 && (clear_cmdline | 1210 && (clear_cmdline |
1257 || redraw_cmdline) | 1211 || redraw_cmdline) |
1258 && (msg_didout || (msg_didany && msg_scroll)) | 1212 && (msg_didout || (msg_didany && msg_scroll)) |
1259 && !msg_nowait | 1213 && !msg_nowait |
1260 && KeyTyped) | 1214 && KeyTyped) |
1261 || (restart_edit != 0 | 1215 || (restart_edit != 0 |
1262 #ifdef FEAT_VISUAL | |
1263 && !VIsual_active | 1216 && !VIsual_active |
1264 #endif | |
1265 && (msg_scroll | 1217 && (msg_scroll |
1266 || emsg_on_display))) | 1218 || emsg_on_display))) |
1267 && oap->regname == 0 | 1219 && oap->regname == 0 |
1268 && !(ca.retval & CA_COMMAND_BUSY) | 1220 && !(ca.retval & CA_COMMAND_BUSY) |
1269 && stuff_empty() | 1221 && stuff_empty() |
1366 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | 1318 * May restart edit(), if we got here with CTRL-O in Insert mode (but not |
1367 * if still inside a mapping that started in Visual mode). | 1319 * if still inside a mapping that started in Visual mode). |
1368 * May switch from Visual to Select mode after CTRL-O command. | 1320 * May switch from Visual to Select mode after CTRL-O command. |
1369 */ | 1321 */ |
1370 if ( oap->op_type == OP_NOP | 1322 if ( oap->op_type == OP_NOP |
1371 #ifdef FEAT_VISUAL | |
1372 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | 1323 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
1373 || restart_VIsual_select == 1) | 1324 || restart_VIsual_select == 1) |
1374 #else | |
1375 && restart_edit != 0 | |
1376 #endif | |
1377 && !(ca.retval & CA_COMMAND_BUSY) | 1325 && !(ca.retval & CA_COMMAND_BUSY) |
1378 && stuff_empty() | 1326 && stuff_empty() |
1379 && oap->regname == 0) | 1327 && oap->regname == 0) |
1380 { | 1328 { |
1381 #ifdef FEAT_VISUAL | |
1382 if (restart_VIsual_select == 1) | 1329 if (restart_VIsual_select == 1) |
1383 { | 1330 { |
1384 VIsual_select = TRUE; | 1331 VIsual_select = TRUE; |
1385 showmode(); | 1332 showmode(); |
1386 restart_VIsual_select = 0; | 1333 restart_VIsual_select = 0; |
1387 } | 1334 } |
1388 #endif | 1335 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
1389 if (restart_edit != 0 | |
1390 #ifdef FEAT_VISUAL | |
1391 && !VIsual_active && old_mapped_len == 0 | |
1392 #endif | |
1393 ) | |
1394 (void)edit(restart_edit, FALSE, 1L); | 1336 (void)edit(restart_edit, FALSE, 1L); |
1395 } | 1337 } |
1396 | 1338 |
1397 #ifdef FEAT_VISUAL | |
1398 if (restart_VIsual_select == 2) | 1339 if (restart_VIsual_select == 2) |
1399 restart_VIsual_select = 1; | 1340 restart_VIsual_select = 1; |
1400 #endif | |
1401 | 1341 |
1402 /* Save count before an operator for next time. */ | 1342 /* Save count before an operator for next time. */ |
1403 opcount = ca.opcount; | 1343 opcount = ca.opcount; |
1404 } | 1344 } |
1405 | 1345 |
1435 oparg_T *oap = cap->oap; | 1375 oparg_T *oap = cap->oap; |
1436 pos_T old_cursor; | 1376 pos_T old_cursor; |
1437 int empty_region_error; | 1377 int empty_region_error; |
1438 int restart_edit_save; | 1378 int restart_edit_save; |
1439 | 1379 |
1440 #ifdef FEAT_VISUAL | |
1441 /* The visual area is remembered for redo */ | 1380 /* The visual area is remembered for redo */ |
1442 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | 1381 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
1443 static linenr_T redo_VIsual_line_count; /* number of lines */ | 1382 static linenr_T redo_VIsual_line_count; /* number of lines */ |
1444 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ | 1383 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
1445 static long redo_VIsual_count; /* count for Visual operator */ | 1384 static long redo_VIsual_count; /* count for Visual operator */ |
1446 # ifdef FEAT_VIRTUALEDIT | 1385 #ifdef FEAT_VIRTUALEDIT |
1447 int include_line_break = FALSE; | 1386 int include_line_break = FALSE; |
1448 # endif | |
1449 #endif | 1387 #endif |
1450 | 1388 |
1451 #if defined(FEAT_CLIPBOARD) | 1389 #if defined(FEAT_CLIPBOARD) |
1452 /* | 1390 /* |
1453 * Yank the visual area into the GUI selection register before we operate | 1391 * Yank the visual area into the GUI selection register before we operate |
1457 * because gui_yank will be TRUE for the nested call. | 1395 * because gui_yank will be TRUE for the nested call. |
1458 */ | 1396 */ |
1459 if ((clip_star.available || clip_plus.available) | 1397 if ((clip_star.available || clip_plus.available) |
1460 && oap->op_type != OP_NOP | 1398 && oap->op_type != OP_NOP |
1461 && !gui_yank | 1399 && !gui_yank |
1462 # ifdef FEAT_VISUAL | |
1463 && VIsual_active | 1400 && VIsual_active |
1464 && !redo_VIsual_busy | 1401 && !redo_VIsual_busy |
1465 # endif | |
1466 && oap->regname == 0) | 1402 && oap->regname == 0) |
1467 clip_auto_select(); | 1403 clip_auto_select(); |
1468 #endif | 1404 #endif |
1469 old_cursor = curwin->w_cursor; | 1405 old_cursor = curwin->w_cursor; |
1470 | 1406 |
1471 /* | 1407 /* |
1472 * If an operation is pending, handle it... | 1408 * If an operation is pending, handle it... |
1473 */ | 1409 */ |
1474 if ((finish_op | 1410 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1475 #ifdef FEAT_VISUAL | 1411 { |
1476 || VIsual_active | |
1477 #endif | |
1478 ) && oap->op_type != OP_NOP) | |
1479 { | |
1480 #ifdef FEAT_VISUAL | |
1481 oap->is_VIsual = VIsual_active; | 1412 oap->is_VIsual = VIsual_active; |
1482 if (oap->motion_force == 'V') | 1413 if (oap->motion_force == 'V') |
1483 oap->motion_type = MLINE; | 1414 oap->motion_type = MLINE; |
1484 else if (oap->motion_force == 'v') | 1415 else if (oap->motion_force == 'v') |
1485 { | 1416 { |
1499 VIsual = oap->start; | 1430 VIsual = oap->start; |
1500 VIsual_mode = Ctrl_V; | 1431 VIsual_mode = Ctrl_V; |
1501 VIsual_select = FALSE; | 1432 VIsual_select = FALSE; |
1502 VIsual_reselect = FALSE; | 1433 VIsual_reselect = FALSE; |
1503 } | 1434 } |
1504 #endif | |
1505 | 1435 |
1506 /* Only redo yank when 'y' flag is in 'cpoptions'. */ | 1436 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1507 /* Never redo "zf" (define fold). */ | 1437 /* Never redo "zf" (define fold). */ |
1508 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | 1438 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
1509 #ifdef FEAT_VISUAL | |
1510 && ((!VIsual_active || oap->motion_force) | 1439 && ((!VIsual_active || oap->motion_force) |
1511 /* Also redo Operator-pending Visual mode mappings */ | 1440 /* Also redo Operator-pending Visual mode mappings */ |
1512 || (VIsual_active && cap->cmdchar == ':' | 1441 || (VIsual_active && cap->cmdchar == ':' |
1513 && oap->op_type != OP_COLON)) | 1442 && oap->op_type != OP_COLON)) |
1514 #endif | |
1515 && cap->cmdchar != 'D' | 1443 && cap->cmdchar != 'D' |
1516 #ifdef FEAT_FOLDING | 1444 #ifdef FEAT_FOLDING |
1517 && oap->op_type != OP_FOLD | 1445 && oap->op_type != OP_FOLD |
1518 && oap->op_type != OP_FOLDOPEN | 1446 && oap->op_type != OP_FOLDOPEN |
1519 && oap->op_type != OP_FOLDOPENREC | 1447 && oap->op_type != OP_FOLDOPENREC |
1552 repeat_cmdline = NULL; | 1480 repeat_cmdline = NULL; |
1553 } | 1481 } |
1554 } | 1482 } |
1555 } | 1483 } |
1556 | 1484 |
1557 #ifdef FEAT_VISUAL | |
1558 if (redo_VIsual_busy) | 1485 if (redo_VIsual_busy) |
1559 { | 1486 { |
1560 /* Redo of an operation on a Visual area. Use the same size from | 1487 /* Redo of an operation on a Visual area. Use the same size from |
1561 * redo_VIsual_line_count and redo_VIsual_vcol. */ | 1488 * redo_VIsual_line_count and redo_VIsual_vcol. */ |
1562 oap->start = curwin->w_cursor; | 1489 oap->start = curwin->w_cursor; |
1637 | 1564 |
1638 oap->start = VIsual; | 1565 oap->start = VIsual; |
1639 if (VIsual_mode == 'V') | 1566 if (VIsual_mode == 'V') |
1640 oap->start.col = 0; | 1567 oap->start.col = 0; |
1641 } | 1568 } |
1642 #endif /* FEAT_VISUAL */ | |
1643 | 1569 |
1644 /* | 1570 /* |
1645 * Set oap->start to the first position of the operated text, oap->end | 1571 * Set oap->start to the first position of the operated text, oap->end |
1646 * to the end of the operated text. w_cursor is equal to oap->start. | 1572 * to the end of the operated text. w_cursor is equal to oap->start. |
1647 */ | 1573 */ |
1688 #ifdef FEAT_VIRTUALEDIT | 1614 #ifdef FEAT_VIRTUALEDIT |
1689 /* Set "virtual_op" before resetting VIsual_active. */ | 1615 /* Set "virtual_op" before resetting VIsual_active. */ |
1690 virtual_op = virtual_active(); | 1616 virtual_op = virtual_active(); |
1691 #endif | 1617 #endif |
1692 | 1618 |
1693 #ifdef FEAT_VISUAL | |
1694 if (VIsual_active || redo_VIsual_busy) | 1619 if (VIsual_active || redo_VIsual_busy) |
1695 { | 1620 { |
1696 if (VIsual_mode == Ctrl_V) /* block mode */ | 1621 if (VIsual_mode == Ctrl_V) /* block mode */ |
1697 { | 1622 { |
1698 colnr_T start, end; | 1623 colnr_T start, end; |
1824 oap->motion_type = MLINE; | 1749 oap->motion_type = MLINE; |
1825 else | 1750 else |
1826 { | 1751 { |
1827 oap->motion_type = MCHAR; | 1752 oap->motion_type = MCHAR; |
1828 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | 1753 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL |
1829 # ifdef FEAT_VIRTUALEDIT | 1754 #ifdef FEAT_VIRTUALEDIT |
1830 && (include_line_break || !virtual_op) | 1755 && (include_line_break || !virtual_op) |
1831 # endif | 1756 #endif |
1832 ) | 1757 ) |
1833 { | 1758 { |
1834 oap->inclusive = FALSE; | 1759 oap->inclusive = FALSE; |
1835 /* Try to include the newline, unless it's an operator | 1760 /* Try to include the newline, unless it's an operator |
1836 * that works on lines only. */ | 1761 * that works on lines only. */ |
1838 { | 1763 { |
1839 if (oap->end.lnum < curbuf->b_ml.ml_line_count) | 1764 if (oap->end.lnum < curbuf->b_ml.ml_line_count) |
1840 { | 1765 { |
1841 ++oap->end.lnum; | 1766 ++oap->end.lnum; |
1842 oap->end.col = 0; | 1767 oap->end.col = 0; |
1843 # ifdef FEAT_VIRTUALEDIT | 1768 #ifdef FEAT_VIRTUALEDIT |
1844 oap->end.coladd = 0; | 1769 oap->end.coladd = 0; |
1845 # endif | 1770 #endif |
1846 ++oap->line_count; | 1771 ++oap->line_count; |
1847 } | 1772 } |
1848 else | 1773 else |
1849 { | 1774 { |
1850 /* Cannot move below the last line, make the op | 1775 /* Cannot move below the last line, make the op |
1866 * part. | 1791 * part. |
1867 */ | 1792 */ |
1868 if (!gui_yank) | 1793 if (!gui_yank) |
1869 { | 1794 { |
1870 VIsual_active = FALSE; | 1795 VIsual_active = FALSE; |
1871 # ifdef FEAT_MOUSE | 1796 #ifdef FEAT_MOUSE |
1872 setmouse(); | 1797 setmouse(); |
1873 mouse_dragging = 0; | 1798 mouse_dragging = 0; |
1874 # endif | 1799 #endif |
1875 if (mode_displayed) | 1800 if (mode_displayed) |
1876 clear_cmdline = TRUE; /* unshow visual mode later */ | 1801 clear_cmdline = TRUE; /* unshow visual mode later */ |
1877 #ifdef FEAT_CMDL_INFO | 1802 #ifdef FEAT_CMDL_INFO |
1878 else | 1803 else |
1879 clear_showcmd(); | 1804 clear_showcmd(); |
1884 || oap->op_type == OP_FILTER) | 1809 || oap->op_type == OP_FILTER) |
1885 && oap->motion_force == NUL) | 1810 && oap->motion_force == NUL) |
1886 redraw_curbuf_later(INVERTED); | 1811 redraw_curbuf_later(INVERTED); |
1887 } | 1812 } |
1888 } | 1813 } |
1889 #endif | |
1890 | 1814 |
1891 #ifdef FEAT_MBYTE | 1815 #ifdef FEAT_MBYTE |
1892 /* Include the trailing byte of a multi-byte char. */ | 1816 /* Include the trailing byte of a multi-byte char. */ |
1893 if (has_mbyte && oap->inclusive) | 1817 if (has_mbyte && oap->inclusive) |
1894 { | 1818 { |
1919 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | 1843 * empty region, when 'E' included in 'cpoptions' (Vi compatible). |
1920 */ | 1844 */ |
1921 empty_region_error = (oap->empty | 1845 empty_region_error = (oap->empty |
1922 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | 1846 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); |
1923 | 1847 |
1924 #ifdef FEAT_VISUAL | |
1925 /* Force a redraw when operating on an empty Visual region, when | 1848 /* Force a redraw when operating on an empty Visual region, when |
1926 * 'modifiable is off or creating a fold. */ | 1849 * 'modifiable is off or creating a fold. */ |
1927 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | 1850 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma |
1928 # ifdef FEAT_FOLDING | 1851 #ifdef FEAT_FOLDING |
1929 || oap->op_type == OP_FOLD | 1852 || oap->op_type == OP_FOLD |
1930 # endif | 1853 #endif |
1931 )) | 1854 )) |
1932 redraw_curbuf_later(INVERTED); | 1855 redraw_curbuf_later(INVERTED); |
1933 #endif | |
1934 | 1856 |
1935 /* | 1857 /* |
1936 * If the end of an operator is in column one while oap->motion_type | 1858 * If the end of an operator is in column one while oap->motion_type |
1937 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | 1859 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last |
1938 * character in the previous line. If op_start is on or before the | 1860 * character in the previous line. If op_start is on or before the |
1941 */ | 1863 */ |
1942 if ( oap->motion_type == MCHAR | 1864 if ( oap->motion_type == MCHAR |
1943 && oap->inclusive == FALSE | 1865 && oap->inclusive == FALSE |
1944 && !(cap->retval & CA_NO_ADJ_OP_END) | 1866 && !(cap->retval & CA_NO_ADJ_OP_END) |
1945 && oap->end.col == 0 | 1867 && oap->end.col == 0 |
1946 #ifdef FEAT_VISUAL | |
1947 && (!oap->is_VIsual || *p_sel == 'o') | 1868 && (!oap->is_VIsual || *p_sel == 'o') |
1948 && !oap->block_mode | 1869 && !oap->block_mode |
1949 #endif | |
1950 && oap->line_count > 1) | 1870 && oap->line_count > 1) |
1951 { | 1871 { |
1952 oap->end_adjusted = TRUE; /* remember that we did this */ | 1872 oap->end_adjusted = TRUE; /* remember that we did this */ |
1953 --oap->line_count; | 1873 --oap->line_count; |
1954 --oap->end.lnum; | 1874 --oap->end.lnum; |
1969 | 1889 |
1970 switch (oap->op_type) | 1890 switch (oap->op_type) |
1971 { | 1891 { |
1972 case OP_LSHIFT: | 1892 case OP_LSHIFT: |
1973 case OP_RSHIFT: | 1893 case OP_RSHIFT: |
1974 op_shift(oap, TRUE, | 1894 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
1975 #ifdef FEAT_VISUAL | |
1976 oap->is_VIsual ? (int)cap->count1 : | |
1977 #endif | |
1978 1); | |
1979 auto_format(FALSE, TRUE); | 1895 auto_format(FALSE, TRUE); |
1980 break; | 1896 break; |
1981 | 1897 |
1982 case OP_JOIN_NS: | 1898 case OP_JOIN_NS: |
1983 case OP_JOIN: | 1899 case OP_JOIN: |
1986 if (curwin->w_cursor.lnum + oap->line_count - 1 > | 1902 if (curwin->w_cursor.lnum + oap->line_count - 1 > |
1987 curbuf->b_ml.ml_line_count) | 1903 curbuf->b_ml.ml_line_count) |
1988 beep_flush(); | 1904 beep_flush(); |
1989 else | 1905 else |
1990 { | 1906 { |
1991 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE); | 1907 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
1908 TRUE, TRUE); | |
1992 auto_format(FALSE, TRUE); | 1909 auto_format(FALSE, TRUE); |
1993 } | 1910 } |
1994 break; | 1911 break; |
1995 | 1912 |
1996 case OP_DELETE: | 1913 case OP_DELETE: |
1997 #ifdef FEAT_VISUAL | |
1998 VIsual_reselect = FALSE; /* don't reselect now */ | 1914 VIsual_reselect = FALSE; /* don't reselect now */ |
1999 #endif | |
2000 if (empty_region_error) | 1915 if (empty_region_error) |
2001 { | 1916 { |
2002 vim_beep(); | 1917 vim_beep(); |
2003 CancelRedo(); | 1918 CancelRedo(); |
2004 } | 1919 } |
2024 (void)op_yank(oap, FALSE, !gui_yank); | 1939 (void)op_yank(oap, FALSE, !gui_yank); |
2025 check_cursor_col(); | 1940 check_cursor_col(); |
2026 break; | 1941 break; |
2027 | 1942 |
2028 case OP_CHANGE: | 1943 case OP_CHANGE: |
2029 #ifdef FEAT_VISUAL | |
2030 VIsual_reselect = FALSE; /* don't reselect now */ | 1944 VIsual_reselect = FALSE; /* don't reselect now */ |
2031 #endif | |
2032 if (empty_region_error) | 1945 if (empty_region_error) |
2033 { | 1946 { |
2034 vim_beep(); | 1947 vim_beep(); |
2035 CancelRedo(); | 1948 CancelRedo(); |
2036 } | 1949 } |
2124 op_function(oap); /* call 'operatorfunc' */ | 2037 op_function(oap); /* call 'operatorfunc' */ |
2125 break; | 2038 break; |
2126 | 2039 |
2127 case OP_INSERT: | 2040 case OP_INSERT: |
2128 case OP_APPEND: | 2041 case OP_APPEND: |
2129 #ifdef FEAT_VISUAL | |
2130 VIsual_reselect = FALSE; /* don't reselect now */ | 2042 VIsual_reselect = FALSE; /* don't reselect now */ |
2131 #endif | |
2132 #ifdef FEAT_VISUALEXTRA | 2043 #ifdef FEAT_VISUALEXTRA |
2133 if (empty_region_error) | 2044 if (empty_region_error) |
2134 { | 2045 { |
2135 vim_beep(); | 2046 vim_beep(); |
2136 CancelRedo(); | 2047 CancelRedo(); |
2156 vim_beep(); | 2067 vim_beep(); |
2157 #endif | 2068 #endif |
2158 break; | 2069 break; |
2159 | 2070 |
2160 case OP_REPLACE: | 2071 case OP_REPLACE: |
2161 #ifdef FEAT_VISUAL | |
2162 VIsual_reselect = FALSE; /* don't reselect now */ | 2072 VIsual_reselect = FALSE; /* don't reselect now */ |
2163 #endif | |
2164 #ifdef FEAT_VISUALEXTRA | 2073 #ifdef FEAT_VISUALEXTRA |
2165 if (empty_region_error) | 2074 if (empty_region_error) |
2166 #endif | 2075 #endif |
2167 { | 2076 { |
2168 vim_beep(); | 2077 vim_beep(); |
2218 } | 2127 } |
2219 else | 2128 else |
2220 { | 2129 { |
2221 curwin->w_cursor = old_cursor; | 2130 curwin->w_cursor = old_cursor; |
2222 } | 2131 } |
2223 #ifdef FEAT_VISUAL | |
2224 oap->block_mode = FALSE; | 2132 oap->block_mode = FALSE; |
2225 #endif | |
2226 clearop(oap); | 2133 clearop(oap); |
2227 } | 2134 } |
2228 } | 2135 } |
2229 | 2136 |
2230 /* | 2137 /* |
2233 static void | 2140 static void |
2234 op_colon(oap) | 2141 op_colon(oap) |
2235 oparg_T *oap; | 2142 oparg_T *oap; |
2236 { | 2143 { |
2237 stuffcharReadbuff(':'); | 2144 stuffcharReadbuff(':'); |
2238 #ifdef FEAT_VISUAL | |
2239 if (oap->is_VIsual) | 2145 if (oap->is_VIsual) |
2240 stuffReadbuff((char_u *)"'<,'>"); | 2146 stuffReadbuff((char_u *)"'<,'>"); |
2241 else | 2147 else |
2242 #endif | |
2243 { | 2148 { |
2244 /* | 2149 /* |
2245 * Make the range look nice, so it can be repeated. | 2150 * Make the range look nice, so it can be repeated. |
2246 */ | 2151 */ |
2247 if (oap->start.lnum == curwin->w_cursor.lnum) | 2152 if (oap->start.lnum == curwin->w_cursor.lnum) |
2402 int c1, c2; | 2307 int c1, c2; |
2403 #if defined(FEAT_FOLDING) | 2308 #if defined(FEAT_FOLDING) |
2404 pos_T save_cursor; | 2309 pos_T save_cursor; |
2405 #endif | 2310 #endif |
2406 win_T *old_curwin = curwin; | 2311 win_T *old_curwin = curwin; |
2407 #ifdef FEAT_VISUAL | |
2408 static pos_T orig_cursor; | 2312 static pos_T orig_cursor; |
2409 colnr_T leftcol, rightcol; | 2313 colnr_T leftcol, rightcol; |
2410 pos_T end_visual; | 2314 pos_T end_visual; |
2411 int diff; | 2315 int diff; |
2412 int old_active = VIsual_active; | 2316 int old_active = VIsual_active; |
2413 int old_mode = VIsual_mode; | 2317 int old_mode = VIsual_mode; |
2414 #endif | |
2415 int regname; | 2318 int regname; |
2416 | 2319 |
2417 #if defined(FEAT_FOLDING) | 2320 #if defined(FEAT_FOLDING) |
2418 save_cursor = curwin->w_cursor; | 2321 save_cursor = curwin->w_cursor; |
2419 #endif | 2322 #endif |
2430 else | 2333 else |
2431 #ifdef FEAT_GUI | 2334 #ifdef FEAT_GUI |
2432 if (!gui.in_use) | 2335 if (!gui.in_use) |
2433 #endif | 2336 #endif |
2434 { | 2337 { |
2435 #ifdef FEAT_VISUAL | |
2436 if (VIsual_active) | 2338 if (VIsual_active) |
2437 { | 2339 { |
2438 if (!mouse_has(MOUSE_VISUAL)) | 2340 if (!mouse_has(MOUSE_VISUAL)) |
2439 return FALSE; | 2341 return FALSE; |
2440 } | 2342 } |
2441 else | 2343 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
2442 #endif | |
2443 if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) | |
2444 return FALSE; | 2344 return FALSE; |
2445 } | 2345 } |
2446 | 2346 |
2447 for (;;) | 2347 for (;;) |
2448 { | 2348 { |
2506 return FALSE; | 2406 return FALSE; |
2507 } | 2407 } |
2508 #endif | 2408 #endif |
2509 } | 2409 } |
2510 } | 2410 } |
2511 | |
2512 #ifndef FEAT_VISUAL | |
2513 /* | |
2514 * ALT is only used for starting/extending Visual mode. | |
2515 */ | |
2516 if ((mod_mask & MOD_MASK_ALT)) | |
2517 return FALSE; | |
2518 #endif | |
2519 | 2411 |
2520 /* | 2412 /* |
2521 * CTRL right mouse button does CTRL-T | 2413 * CTRL right mouse button does CTRL-T |
2522 */ | 2414 */ |
2523 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | 2415 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) |
2584 { | 2476 { |
2585 clearopbeep(oap); | 2477 clearopbeep(oap); |
2586 return FALSE; | 2478 return FALSE; |
2587 } | 2479 } |
2588 | 2480 |
2589 #ifdef FEAT_VISUAL | |
2590 /* | 2481 /* |
2591 * If visual was active, yank the highlighted text and put it | 2482 * If visual was active, yank the highlighted text and put it |
2592 * before the mouse pointer position. | 2483 * before the mouse pointer position. |
2593 * In Select mode replace the highlighted text with the clipboard. | 2484 * In Select mode replace the highlighted text with the clipboard. |
2594 */ | 2485 */ |
2605 stuffcharReadbuff(K_MIDDLEMOUSE); | 2496 stuffcharReadbuff(K_MIDDLEMOUSE); |
2606 } | 2497 } |
2607 do_always = TRUE; /* ignore 'mouse' setting next time */ | 2498 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2608 return FALSE; | 2499 return FALSE; |
2609 } | 2500 } |
2610 #endif | |
2611 /* | 2501 /* |
2612 * The rest is below jump_to_mouse() | 2502 * The rest is below jump_to_mouse() |
2613 */ | 2503 */ |
2614 } | 2504 } |
2615 | 2505 |
2759 jump_flags = 0; | 2649 jump_flags = 0; |
2760 if (STRCMP(p_mousem, "popup_setpos") == 0) | 2650 if (STRCMP(p_mousem, "popup_setpos") == 0) |
2761 { | 2651 { |
2762 /* First set the cursor position before showing the popup | 2652 /* First set the cursor position before showing the popup |
2763 * menu. */ | 2653 * menu. */ |
2764 #ifdef FEAT_VISUAL | |
2765 if (VIsual_active) | 2654 if (VIsual_active) |
2766 { | 2655 { |
2767 pos_T m_pos; | 2656 pos_T m_pos; |
2768 | 2657 |
2769 /* | 2658 /* |
2798 } | 2687 } |
2799 } | 2688 } |
2800 } | 2689 } |
2801 else | 2690 else |
2802 jump_flags = MOUSE_MAY_STOP_VIS; | 2691 jump_flags = MOUSE_MAY_STOP_VIS; |
2803 #endif | |
2804 } | 2692 } |
2805 if (jump_flags) | 2693 if (jump_flags) |
2806 { | 2694 { |
2807 jump_flags = jump_to_mouse(jump_flags, NULL, which_button); | 2695 jump_flags = jump_to_mouse(jump_flags, NULL, which_button); |
2808 update_curbuf( | 2696 update_curbuf(VIsual_active ? INVERTED : VALID); |
2809 #ifdef FEAT_VISUAL | |
2810 VIsual_active ? INVERTED : | |
2811 #endif | |
2812 VALID); | |
2813 setcursor(); | 2697 setcursor(); |
2814 out_flush(); /* Update before showing popup menu */ | 2698 out_flush(); /* Update before showing popup menu */ |
2815 } | 2699 } |
2816 # ifdef FEAT_MENU | 2700 # ifdef FEAT_MENU |
2817 gui_show_popupmenu(); | 2701 gui_show_popupmenu(); |
2830 which_button = MOUSE_RIGHT; | 2714 which_button = MOUSE_RIGHT; |
2831 mod_mask &= ~MOD_MASK_SHIFT; | 2715 mod_mask &= ~MOD_MASK_SHIFT; |
2832 } | 2716 } |
2833 } | 2717 } |
2834 | 2718 |
2835 #ifdef FEAT_VISUAL | |
2836 if ((State & (NORMAL | INSERT)) | 2719 if ((State & (NORMAL | INSERT)) |
2837 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | 2720 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) |
2838 { | 2721 { |
2839 if (which_button == MOUSE_LEFT) | 2722 if (which_button == MOUSE_LEFT) |
2840 { | 2723 { |
2870 jump_flags |= MOUSE_FOCUS; | 2753 jump_flags |= MOUSE_FOCUS; |
2871 if (mouse_has(MOUSE_VISUAL)) | 2754 if (mouse_has(MOUSE_VISUAL)) |
2872 jump_flags |= MOUSE_MAY_VIS; | 2755 jump_flags |= MOUSE_MAY_VIS; |
2873 } | 2756 } |
2874 } | 2757 } |
2875 #endif | |
2876 | 2758 |
2877 /* | 2759 /* |
2878 * If an operator is pending, ignore all drags and releases until the | 2760 * If an operator is pending, ignore all drags and releases until the |
2879 * next mouse click. | 2761 * next mouse click. |
2880 */ | 2762 */ |
2939 clip_modeless(which_button, is_click, is_drag); | 2821 clip_modeless(which_button, is_click, is_drag); |
2940 return FALSE; | 2822 return FALSE; |
2941 } | 2823 } |
2942 #endif | 2824 #endif |
2943 | 2825 |
2944 #ifdef FEAT_VISUAL | |
2945 /* Set global flag that we are extending the Visual area with mouse | 2826 /* Set global flag that we are extending the Visual area with mouse |
2946 * dragging; temporarily minimize 'scrolloff'. */ | 2827 * dragging; temporarily minimize 'scrolloff'. */ |
2947 if (VIsual_active && is_drag && p_so) | 2828 if (VIsual_active && is_drag && p_so) |
2948 { | 2829 { |
2949 /* In the very first line, allow scrolling one line */ | 2830 /* In the very first line, allow scrolling one line */ |
3038 /* | 2919 /* |
3039 * If Visual mode started in insert mode, execute "CTRL-O" | 2920 * If Visual mode started in insert mode, execute "CTRL-O" |
3040 */ | 2921 */ |
3041 else if ((State & INSERT) && VIsual_active) | 2922 else if ((State & INSERT) && VIsual_active) |
3042 stuffcharReadbuff(Ctrl_O); | 2923 stuffcharReadbuff(Ctrl_O); |
3043 #endif | |
3044 | 2924 |
3045 /* | 2925 /* |
3046 * Middle mouse click: Put text before cursor. | 2926 * Middle mouse click: Put text before cursor. |
3047 */ | 2927 */ |
3048 if (which_button == MOUSE_MIDDLE) | 2928 if (which_button == MOUSE_MIDDLE) |
3116 * Shift-Mouse click searches for the next occurrence of the word under | 2996 * Shift-Mouse click searches for the next occurrence of the word under |
3117 * the mouse pointer | 2997 * the mouse pointer |
3118 */ | 2998 */ |
3119 else if ((mod_mask & MOD_MASK_SHIFT)) | 2999 else if ((mod_mask & MOD_MASK_SHIFT)) |
3120 { | 3000 { |
3121 if (State & INSERT | 3001 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
3122 #ifdef FEAT_VISUAL | |
3123 || (VIsual_active && VIsual_select) | |
3124 #endif | |
3125 ) | |
3126 stuffcharReadbuff(Ctrl_O); | 3002 stuffcharReadbuff(Ctrl_O); |
3127 if (which_button == MOUSE_LEFT) | 3003 if (which_button == MOUSE_LEFT) |
3128 stuffcharReadbuff('*'); | 3004 stuffcharReadbuff('*'); |
3129 else /* MOUSE_RIGHT */ | 3005 else /* MOUSE_RIGHT */ |
3130 stuffcharReadbuff('#'); | 3006 stuffcharReadbuff('#'); |
3151 update_mouseshape(-1); | 3027 update_mouseshape(-1); |
3152 } | 3028 } |
3153 # endif | 3029 # endif |
3154 } | 3030 } |
3155 #endif | 3031 #endif |
3156 #ifdef FEAT_VISUAL | |
3157 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) | 3032 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3158 && mouse_has(MOUSE_VISUAL)) | 3033 && mouse_has(MOUSE_VISUAL)) |
3159 { | 3034 { |
3160 if (is_click || !VIsual_active) | 3035 if (is_click || !VIsual_active) |
3161 { | 3036 { |
3265 /* If Visual mode changed show it later. */ | 3140 /* If Visual mode changed show it later. */ |
3266 if ((!VIsual_active && old_active && mode_displayed) | 3141 if ((!VIsual_active && old_active && mode_displayed) |
3267 || (VIsual_active && p_smd && msg_silent == 0 | 3142 || (VIsual_active && p_smd && msg_silent == 0 |
3268 && (!old_active || VIsual_mode != old_mode))) | 3143 && (!old_active || VIsual_mode != old_mode))) |
3269 redraw_cmdline = TRUE; | 3144 redraw_cmdline = TRUE; |
3270 #endif | |
3271 | 3145 |
3272 return moved; | 3146 return moved; |
3273 } | 3147 } |
3274 | 3148 |
3275 #ifdef FEAT_VISUAL | |
3276 /* | 3149 /* |
3277 * Move "pos" back to the start of the word it's in. | 3150 * Move "pos" back to the start of the word it's in. |
3278 */ | 3151 */ |
3279 static void | 3152 static void |
3280 find_start_of_word(pos) | 3153 find_start_of_word(pos) |
3370 */ | 3243 */ |
3371 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | 3244 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) |
3372 return 1; | 3245 return 1; |
3373 return c; | 3246 return c; |
3374 } | 3247 } |
3375 #endif /* FEAT_VISUAL */ | |
3376 #endif /* FEAT_MOUSE */ | 3248 #endif /* FEAT_MOUSE */ |
3377 | 3249 |
3378 #if defined(FEAT_VISUAL) || defined(PROTO) | |
3379 /* | 3250 /* |
3380 * Check if highlighting for visual mode is possible, give a warning message | 3251 * Check if highlighting for visual mode is possible, give a warning message |
3381 * if not. | 3252 * if not. |
3382 */ | 3253 */ |
3383 void | 3254 void |
3466 end_visual_mode(); | 3337 end_visual_mode(); |
3467 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | 3338 redraw_curbuf_later(INVERTED); /* delete the inversion later */ |
3468 VIsual_reselect = FALSE; | 3339 VIsual_reselect = FALSE; |
3469 } | 3340 } |
3470 } | 3341 } |
3471 #endif /* FEAT_VISUAL */ | |
3472 | 3342 |
3473 #if defined(FEAT_BEVAL) | 3343 #if defined(FEAT_BEVAL) |
3474 static int find_is_eval_item __ARGS((char_u *ptr, int *colp, int *nbp, int dir)); | 3344 static int find_is_eval_item __ARGS((char_u *ptr, int *colp, int *nbp, int dir)); |
3475 | 3345 |
3476 /* | 3346 /* |
3800 */ | 3670 */ |
3801 static int | 3671 static int |
3802 checkclearopq(oap) | 3672 checkclearopq(oap) |
3803 oparg_T *oap; | 3673 oparg_T *oap; |
3804 { | 3674 { |
3805 if (oap->op_type == OP_NOP | 3675 if (oap->op_type == OP_NOP && !VIsual_active) |
3806 #ifdef FEAT_VISUAL | |
3807 && !VIsual_active | |
3808 #endif | |
3809 ) | |
3810 return FALSE; | 3676 return FALSE; |
3811 clearopbeep(oap); | 3677 clearopbeep(oap); |
3812 return TRUE; | 3678 return TRUE; |
3813 } | 3679 } |
3814 | 3680 |
3828 { | 3694 { |
3829 clearop(oap); | 3695 clearop(oap); |
3830 beep_flush(); | 3696 beep_flush(); |
3831 } | 3697 } |
3832 | 3698 |
3833 #ifdef FEAT_VISUAL | |
3834 /* | 3699 /* |
3835 * Remove the shift modifier from a special key. | 3700 * Remove the shift modifier from a special key. |
3836 */ | 3701 */ |
3837 static void | 3702 static void |
3838 unshift_special(cap) | 3703 unshift_special(cap) |
3847 case K_S_HOME: cap->cmdchar = K_HOME; break; | 3712 case K_S_HOME: cap->cmdchar = K_HOME; break; |
3848 case K_S_END: cap->cmdchar = K_END; break; | 3713 case K_S_END: cap->cmdchar = K_END; break; |
3849 } | 3714 } |
3850 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | 3715 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); |
3851 } | 3716 } |
3852 #endif | |
3853 | 3717 |
3854 #if defined(FEAT_CMDL_INFO) || defined(PROTO) | 3718 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3855 /* | 3719 /* |
3856 * Routines for displaying a partly typed command | 3720 * Routines for displaying a partly typed command |
3857 */ | 3721 */ |
3858 | 3722 |
3859 #ifdef FEAT_VISUAL /* need room for size of Visual area */ | 3723 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
3860 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 | |
3861 #else | |
3862 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 | |
3863 #endif | |
3864 static char_u showcmd_buf[SHOWCMD_BUFLEN]; | 3724 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3865 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | 3725 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ |
3866 static int showcmd_is_clear = TRUE; | 3726 static int showcmd_is_clear = TRUE; |
3867 static int showcmd_visual = FALSE; | 3727 static int showcmd_visual = FALSE; |
3868 | 3728 |
3872 clear_showcmd() | 3732 clear_showcmd() |
3873 { | 3733 { |
3874 if (!p_sc) | 3734 if (!p_sc) |
3875 return; | 3735 return; |
3876 | 3736 |
3877 #ifdef FEAT_VISUAL | |
3878 if (VIsual_active && !char_avail()) | 3737 if (VIsual_active && !char_avail()) |
3879 { | 3738 { |
3880 int cursor_bot = lt(VIsual, curwin->w_cursor); | 3739 int cursor_bot = lt(VIsual, curwin->w_cursor); |
3881 long lines; | 3740 long lines; |
3882 colnr_T leftcol, rightcol; | 3741 colnr_T leftcol, rightcol; |
3958 } | 3817 } |
3959 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ | 3818 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3960 showcmd_visual = TRUE; | 3819 showcmd_visual = TRUE; |
3961 } | 3820 } |
3962 else | 3821 else |
3963 #endif | |
3964 { | 3822 { |
3965 showcmd_buf[0] = NUL; | 3823 showcmd_buf[0] = NUL; |
3966 showcmd_visual = FALSE; | 3824 showcmd_visual = FALSE; |
3967 | 3825 |
3968 /* Don't actually display something if there is nothing to clear. */ | 3826 /* Don't actually display something if there is nothing to clear. */ |
4201 { | 4059 { |
4202 int want_ver; | 4060 int want_ver; |
4203 int want_hor; | 4061 int want_hor; |
4204 win_T *old_curwin = curwin; | 4062 win_T *old_curwin = curwin; |
4205 buf_T *old_curbuf = curbuf; | 4063 buf_T *old_curbuf = curbuf; |
4206 #ifdef FEAT_VISUAL | |
4207 int old_VIsual_select = VIsual_select; | 4064 int old_VIsual_select = VIsual_select; |
4208 int old_VIsual_active = VIsual_active; | 4065 int old_VIsual_active = VIsual_active; |
4209 #endif | |
4210 colnr_T tgt_leftcol = curwin->w_leftcol; | 4066 colnr_T tgt_leftcol = curwin->w_leftcol; |
4211 long topline; | 4067 long topline; |
4212 long y; | 4068 long y; |
4213 | 4069 |
4214 /* | 4070 /* |
4221 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | 4077 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); |
4222 | 4078 |
4223 /* | 4079 /* |
4224 * loop through the scrollbound windows and scroll accordingly | 4080 * loop through the scrollbound windows and scroll accordingly |
4225 */ | 4081 */ |
4226 #ifdef FEAT_VISUAL | |
4227 VIsual_select = VIsual_active = 0; | 4082 VIsual_select = VIsual_active = 0; |
4228 #endif | |
4229 for (curwin = firstwin; curwin; curwin = curwin->w_next) | 4083 for (curwin = firstwin; curwin; curwin = curwin->w_next) |
4230 { | 4084 { |
4231 curbuf = curwin->w_buffer; | 4085 curbuf = curwin->w_buffer; |
4232 /* skip original window and windows with 'noscrollbind' */ | 4086 /* skip original window and windows with 'noscrollbind' */ |
4233 if (curwin != old_curwin && curwin->w_p_scb) | 4087 if (curwin != old_curwin && curwin->w_p_scb) |
4278 } | 4132 } |
4279 | 4133 |
4280 /* | 4134 /* |
4281 * reset current-window | 4135 * reset current-window |
4282 */ | 4136 */ |
4283 #ifdef FEAT_VISUAL | |
4284 VIsual_select = old_VIsual_select; | 4137 VIsual_select = old_VIsual_select; |
4285 VIsual_active = old_VIsual_active; | 4138 VIsual_active = old_VIsual_active; |
4286 #endif | |
4287 curwin = old_curwin; | 4139 curwin = old_curwin; |
4288 curbuf = old_curbuf; | 4140 curbuf = old_curbuf; |
4289 } | 4141 } |
4290 #endif /* #ifdef FEAT_SCROLLBIND */ | 4142 #endif /* #ifdef FEAT_SCROLLBIND */ |
4291 | 4143 |
5237 char_u *ptr = NULL; | 5089 char_u *ptr = NULL; |
5238 int len; | 5090 int len; |
5239 | 5091 |
5240 if (checkclearop(cap->oap)) | 5092 if (checkclearop(cap->oap)) |
5241 break; | 5093 break; |
5242 # ifdef FEAT_VISUAL | |
5243 if (VIsual_active && get_visual_text(cap, &ptr, &len) | 5094 if (VIsual_active && get_visual_text(cap, &ptr, &len) |
5244 == FAIL) | 5095 == FAIL) |
5245 return; | 5096 return; |
5246 # endif | |
5247 if (ptr == NULL) | 5097 if (ptr == NULL) |
5248 { | 5098 { |
5249 pos_T pos = curwin->w_cursor; | 5099 pos_T pos = curwin->w_cursor; |
5250 | 5100 |
5251 /* Find bad word under the cursor. When 'spell' is | 5101 /* Find bad word under the cursor. When 'spell' is |
5409 cmdarg_T *cap; | 5259 cmdarg_T *cap; |
5410 { | 5260 { |
5411 /* | 5261 /* |
5412 * Ignore 'Q' in Visual mode, just give a beep. | 5262 * Ignore 'Q' in Visual mode, just give a beep. |
5413 */ | 5263 */ |
5414 #ifdef FEAT_VISUAL | |
5415 if (VIsual_active) | 5264 if (VIsual_active) |
5416 vim_beep(); | 5265 vim_beep(); |
5417 else | 5266 else if (!checkclearop(cap->oap)) |
5418 #endif | |
5419 if (!checkclearop(cap->oap)) | |
5420 do_exmode(FALSE); | 5267 do_exmode(FALSE); |
5421 } | 5268 } |
5422 | 5269 |
5423 /* | 5270 /* |
5424 * Handle a ":" command. | 5271 * Handle a ":" command. |
5428 cmdarg_T *cap; | 5275 cmdarg_T *cap; |
5429 { | 5276 { |
5430 int old_p_im; | 5277 int old_p_im; |
5431 int cmd_result; | 5278 int cmd_result; |
5432 | 5279 |
5433 #ifdef FEAT_VISUAL | |
5434 if (VIsual_active) | 5280 if (VIsual_active) |
5435 nv_operator(cap); | 5281 nv_operator(cap); |
5436 else | 5282 else |
5437 #endif | |
5438 { | 5283 { |
5439 if (cap->oap->op_type != OP_NOP) | 5284 if (cap->oap->op_type != OP_NOP) |
5440 { | 5285 { |
5441 /* Using ":" as a movement is characterwise exclusive. */ | 5286 /* Using ":" as a movement is characterwise exclusive. */ |
5442 cap->oap->motion_type = MCHAR; | 5287 cap->oap->motion_type = MCHAR; |
5492 */ | 5337 */ |
5493 static void | 5338 static void |
5494 nv_ctrlg(cap) | 5339 nv_ctrlg(cap) |
5495 cmdarg_T *cap; | 5340 cmdarg_T *cap; |
5496 { | 5341 { |
5497 #ifdef FEAT_VISUAL | |
5498 if (VIsual_active) /* toggle Selection/Visual mode */ | 5342 if (VIsual_active) /* toggle Selection/Visual mode */ |
5499 { | 5343 { |
5500 VIsual_select = !VIsual_select; | 5344 VIsual_select = !VIsual_select; |
5501 showmode(); | 5345 showmode(); |
5502 } | 5346 } |
5503 else | 5347 else if (!checkclearop(cap->oap)) |
5504 #endif | |
5505 if (!checkclearop(cap->oap)) | |
5506 /* print full name if count given or :cd used */ | 5348 /* print full name if count given or :cd used */ |
5507 fileinfo((int)cap->count0, FALSE, TRUE); | 5349 fileinfo((int)cap->count0, FALSE, TRUE); |
5508 } | 5350 } |
5509 | 5351 |
5510 /* | 5352 /* |
5512 */ | 5354 */ |
5513 static void | 5355 static void |
5514 nv_ctrlh(cap) | 5356 nv_ctrlh(cap) |
5515 cmdarg_T *cap; | 5357 cmdarg_T *cap; |
5516 { | 5358 { |
5517 #ifdef FEAT_VISUAL | |
5518 if (VIsual_active && VIsual_select) | 5359 if (VIsual_active && VIsual_select) |
5519 { | 5360 { |
5520 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | 5361 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ |
5521 v_visop(cap); | 5362 v_visop(cap); |
5522 } | 5363 } |
5523 else | 5364 else |
5524 #endif | |
5525 nv_left(cap); | 5365 nv_left(cap); |
5526 } | 5366 } |
5527 | 5367 |
5528 /* | 5368 /* |
5529 * CTRL-L: clear screen and redraw. | 5369 * CTRL-L: clear screen and redraw. |
5556 */ | 5396 */ |
5557 static void | 5397 static void |
5558 nv_ctrlo(cap) | 5398 nv_ctrlo(cap) |
5559 cmdarg_T *cap; | 5399 cmdarg_T *cap; |
5560 { | 5400 { |
5561 #ifdef FEAT_VISUAL | |
5562 if (VIsual_active && VIsual_select) | 5401 if (VIsual_active && VIsual_select) |
5563 { | 5402 { |
5564 VIsual_select = FALSE; | 5403 VIsual_select = FALSE; |
5565 showmode(); | 5404 showmode(); |
5566 restart_VIsual_select = 2; /* restart Select mode later */ | 5405 restart_VIsual_select = 2; /* restart Select mode later */ |
5567 } | 5406 } |
5568 else | 5407 else |
5569 #endif | |
5570 { | 5408 { |
5571 cap->count1 = -cap->count1; | 5409 cap->count1 = -cap->count1; |
5572 nv_pcmark(cap); | 5410 nv_pcmark(cap); |
5573 } | 5411 } |
5574 } | 5412 } |
5673 /* | 5511 /* |
5674 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | 5512 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. |
5675 */ | 5513 */ |
5676 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | 5514 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') |
5677 { | 5515 { |
5678 #ifdef FEAT_VISUAL | |
5679 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | 5516 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) |
5680 return; | 5517 return; |
5681 #endif | |
5682 if (checkclearopq(cap->oap)) | 5518 if (checkclearopq(cap->oap)) |
5683 return; | 5519 return; |
5684 } | 5520 } |
5685 | 5521 |
5686 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | 5522 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, |
5870 do_cmdline_cmd(buf); | 5706 do_cmdline_cmd(buf); |
5871 | 5707 |
5872 vim_free(buf); | 5708 vim_free(buf); |
5873 } | 5709 } |
5874 | 5710 |
5875 #if defined(FEAT_VISUAL) || defined(PROTO) | |
5876 /* | 5711 /* |
5877 * Get visually selected text, within one line only. | 5712 * Get visually selected text, within one line only. |
5878 * Returns FAIL if more than one line selected. | 5713 * Returns FAIL if more than one line selected. |
5879 */ | 5714 */ |
5880 int | 5715 int |
5915 #endif | 5750 #endif |
5916 } | 5751 } |
5917 reset_VIsual_and_resel(); | 5752 reset_VIsual_and_resel(); |
5918 return OK; | 5753 return OK; |
5919 } | 5754 } |
5920 #endif | |
5921 | 5755 |
5922 /* | 5756 /* |
5923 * CTRL-T: backwards in tag stack | 5757 * CTRL-T: backwards in tag stack |
5924 */ | 5758 */ |
5925 static void | 5759 static void |
6038 static void | 5872 static void |
6039 nv_right(cap) | 5873 nv_right(cap) |
6040 cmdarg_T *cap; | 5874 cmdarg_T *cap; |
6041 { | 5875 { |
6042 long n; | 5876 long n; |
6043 #ifdef FEAT_VISUAL | 5877 int past_line; |
6044 int PAST_LINE; | |
6045 #else | |
6046 # define PAST_LINE 0 | |
6047 #endif | |
6048 | 5878 |
6049 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) | 5879 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6050 { | 5880 { |
6051 /* <C-Right> and <S-Right> move a word or WORD right */ | 5881 /* <C-Right> and <S-Right> move a word or WORD right */ |
6052 if (mod_mask & MOD_MASK_CTRL) | 5882 if (mod_mask & MOD_MASK_CTRL) |
6055 return; | 5885 return; |
6056 } | 5886 } |
6057 | 5887 |
6058 cap->oap->motion_type = MCHAR; | 5888 cap->oap->motion_type = MCHAR; |
6059 cap->oap->inclusive = FALSE; | 5889 cap->oap->inclusive = FALSE; |
6060 #ifdef FEAT_VISUAL | 5890 past_line = (VIsual_active && *p_sel != 'o'); |
6061 PAST_LINE = (VIsual_active && *p_sel != 'o'); | 5891 |
6062 | 5892 #ifdef FEAT_VIRTUALEDIT |
6063 # ifdef FEAT_VIRTUALEDIT | |
6064 /* | 5893 /* |
6065 * In virtual mode, there's no such thing as "PAST_LINE", as lines are | 5894 * In virtual edit mode, there's no such thing as "past_line", as lines |
6066 * (theoretically) infinitely long. | 5895 * are (theoretically) infinitely long. |
6067 */ | 5896 */ |
6068 if (virtual_active()) | 5897 if (virtual_active()) |
6069 PAST_LINE = 0; | 5898 past_line = 0; |
6070 # endif | |
6071 #endif | 5899 #endif |
6072 | 5900 |
6073 for (n = cap->count1; n > 0; --n) | 5901 for (n = cap->count1; n > 0; --n) |
6074 { | 5902 { |
6075 if ((!PAST_LINE && oneright() == FAIL) | 5903 if ((!past_line && oneright() == FAIL) |
6076 #ifdef FEAT_VISUAL | 5904 || (past_line && *ml_get_cursor() == NUL) |
6077 || (PAST_LINE && *ml_get_cursor() == NUL) | |
6078 #endif | |
6079 ) | 5905 ) |
6080 { | 5906 { |
6081 /* | 5907 /* |
6082 * <Space> wraps to next line if 'whichwrap' has 's'. | 5908 * <Space> wraps to next line if 'whichwrap' has 's'. |
6083 * 'l' wraps to next line if 'whichwrap' has 'l'. | 5909 * 'l' wraps to next line if 'whichwrap' has 'l'. |
6121 if (!lineempty(curwin->w_cursor.lnum)) | 5947 if (!lineempty(curwin->w_cursor.lnum)) |
6122 cap->oap->inclusive = TRUE; | 5948 cap->oap->inclusive = TRUE; |
6123 } | 5949 } |
6124 break; | 5950 break; |
6125 } | 5951 } |
6126 #ifdef FEAT_VISUAL | 5952 else if (past_line) |
6127 else if (PAST_LINE) | |
6128 { | 5953 { |
6129 curwin->w_set_curswant = TRUE; | 5954 curwin->w_set_curswant = TRUE; |
6130 # ifdef FEAT_VIRTUALEDIT | 5955 #ifdef FEAT_VIRTUALEDIT |
6131 if (virtual_active()) | 5956 if (virtual_active()) |
6132 oneright(); | 5957 oneright(); |
6133 else | 5958 else |
6134 # endif | 5959 #endif |
6135 { | 5960 { |
6136 # ifdef FEAT_MBYTE | 5961 #ifdef FEAT_MBYTE |
6137 if (has_mbyte) | 5962 if (has_mbyte) |
6138 curwin->w_cursor.col += | 5963 curwin->w_cursor.col += |
6139 (*mb_ptr2len)(ml_get_cursor()); | 5964 (*mb_ptr2len)(ml_get_cursor()); |
6140 else | 5965 else |
6141 # endif | 5966 #endif |
6142 ++curwin->w_cursor.col; | 5967 ++curwin->w_cursor.col; |
6143 } | 5968 } |
6144 } | 5969 } |
6145 #endif | |
6146 } | 5970 } |
6147 #ifdef FEAT_FOLDING | 5971 #ifdef FEAT_FOLDING |
6148 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | 5972 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped |
6149 && cap->oap->op_type == OP_NOP) | 5973 && cap->oap->op_type == OP_NOP) |
6150 foldOpenCursor(); | 5974 foldOpenCursor(); |
6501 curwin->w_cursor.coladd = ecol - scol; | 6325 curwin->w_cursor.coladd = ecol - scol; |
6502 } | 6326 } |
6503 else | 6327 else |
6504 curwin->w_cursor.coladd = 0; | 6328 curwin->w_cursor.coladd = 0; |
6505 #endif | 6329 #endif |
6506 #ifdef FEAT_VISUAL | |
6507 adjust_for_sel(cap); | 6330 adjust_for_sel(cap); |
6508 #endif | |
6509 #ifdef FEAT_FOLDING | 6331 #ifdef FEAT_FOLDING |
6510 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | 6332 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
6511 foldOpenCursor(); | 6333 foldOpenCursor(); |
6512 #endif | 6334 #endif |
6513 } | 6335 } |
6752 if (!checkclearop(cap->oap)) | 6574 if (!checkclearop(cap->oap)) |
6753 { | 6575 { |
6754 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') | 6576 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6755 ? FORWARD : BACKWARD; | 6577 ? FORWARD : BACKWARD; |
6756 int regname = cap->oap->regname; | 6578 int regname = cap->oap->regname; |
6757 #ifdef FEAT_VISUAL | |
6758 int was_visual = VIsual_active; | 6579 int was_visual = VIsual_active; |
6759 int line_count = curbuf->b_ml.ml_line_count; | 6580 int line_count = curbuf->b_ml.ml_line_count; |
6760 pos_T start, end; | 6581 pos_T start, end; |
6761 | 6582 |
6762 if (VIsual_active) | 6583 if (VIsual_active) |
6764 start = ltoreq(VIsual, curwin->w_cursor) | 6585 start = ltoreq(VIsual, curwin->w_cursor) |
6765 ? VIsual : curwin->w_cursor; | 6586 ? VIsual : curwin->w_cursor; |
6766 end = equalpos(start,VIsual) ? curwin->w_cursor : VIsual; | 6587 end = equalpos(start,VIsual) ? curwin->w_cursor : VIsual; |
6767 curwin->w_cursor = (dir == BACKWARD ? start : end); | 6588 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6768 } | 6589 } |
6769 #endif | |
6770 # ifdef FEAT_CLIPBOARD | 6590 # ifdef FEAT_CLIPBOARD |
6771 adjust_clip_reg(®name); | 6591 adjust_clip_reg(®name); |
6772 # endif | 6592 # endif |
6773 prep_redo_cmd(cap); | 6593 prep_redo_cmd(cap); |
6774 | 6594 |
6775 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | 6595 do_put(regname, dir, cap->count1, PUT_FIXINDENT); |
6776 #ifdef FEAT_VISUAL | |
6777 if (was_visual) | 6596 if (was_visual) |
6778 { | 6597 { |
6779 VIsual = start; | 6598 VIsual = start; |
6780 curwin->w_cursor = end; | 6599 curwin->w_cursor = end; |
6781 if (dir == BACKWARD) | 6600 if (dir == BACKWARD) |
6800 { | 6619 { |
6801 end_visual_mode(); | 6620 end_visual_mode(); |
6802 redraw_later(SOME_VALID); | 6621 redraw_later(SOME_VALID); |
6803 } | 6622 } |
6804 } | 6623 } |
6805 #endif | |
6806 } | 6624 } |
6807 } | 6625 } |
6808 | 6626 |
6809 /* | 6627 /* |
6810 * "['", "[`", "]'" and "]`": jump to next mark | 6628 * "['", "[`", "]'" and "]`": jump to next mark |
6934 curwin->w_cursor = *pos; | 6752 curwin->w_cursor = *pos; |
6935 curwin->w_set_curswant = TRUE; | 6753 curwin->w_set_curswant = TRUE; |
6936 #ifdef FEAT_VIRTUALEDIT | 6754 #ifdef FEAT_VIRTUALEDIT |
6937 curwin->w_cursor.coladd = 0; | 6755 curwin->w_cursor.coladd = 0; |
6938 #endif | 6756 #endif |
6939 #ifdef FEAT_VISUAL | |
6940 adjust_for_sel(cap); | 6757 adjust_for_sel(cap); |
6941 #endif | |
6942 } | 6758 } |
6943 } | 6759 } |
6944 #ifdef FEAT_FOLDING | 6760 #ifdef FEAT_FOLDING |
6945 if (cap->oap->op_type == OP_NOP | 6761 if (cap->oap->op_type == OP_NOP |
6946 && lnum != curwin->w_cursor.lnum | 6762 && lnum != curwin->w_cursor.lnum |
7025 */ | 6841 */ |
7026 static void | 6842 static void |
7027 nv_undo(cap) | 6843 nv_undo(cap) |
7028 cmdarg_T *cap; | 6844 cmdarg_T *cap; |
7029 { | 6845 { |
7030 if (cap->oap->op_type == OP_LOWER | 6846 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7031 #ifdef FEAT_VISUAL | |
7032 || VIsual_active | |
7033 #endif | |
7034 ) | |
7035 { | 6847 { |
7036 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | 6848 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ |
7037 cap->cmdchar = 'g'; | 6849 cap->cmdchar = 'g'; |
7038 cap->nchar = 'u'; | 6850 cap->nchar = 'u'; |
7039 nv_operator(cap); | 6851 nv_operator(cap); |
7087 { | 6899 { |
7088 clearopbeep(cap->oap); | 6900 clearopbeep(cap->oap); |
7089 return; | 6901 return; |
7090 } | 6902 } |
7091 | 6903 |
7092 #ifdef FEAT_VISUAL | |
7093 /* Visual mode "r" */ | 6904 /* Visual mode "r" */ |
7094 if (VIsual_active) | 6905 if (VIsual_active) |
7095 { | 6906 { |
7096 if (got_int) | 6907 if (got_int) |
7097 reset_VIsual(); | 6908 reset_VIsual(); |
7103 cap->nchar = -2; | 6914 cap->nchar = -2; |
7104 } | 6915 } |
7105 nv_operator(cap); | 6916 nv_operator(cap); |
7106 return; | 6917 return; |
7107 } | 6918 } |
7108 #endif | |
7109 | 6919 |
7110 #ifdef FEAT_VIRTUALEDIT | 6920 #ifdef FEAT_VIRTUALEDIT |
7111 /* Break tabs, etc. */ | 6921 /* Break tabs, etc. */ |
7112 if (virtual_active()) | 6922 if (virtual_active()) |
7113 { | 6923 { |
7271 curwin->w_set_curswant = TRUE; | 7081 curwin->w_set_curswant = TRUE; |
7272 set_last_insert(cap->nchar); | 7082 set_last_insert(cap->nchar); |
7273 } | 7083 } |
7274 } | 7084 } |
7275 | 7085 |
7276 #ifdef FEAT_VISUAL | |
7277 /* | 7086 /* |
7278 * 'o': Exchange start and end of Visual area. | 7087 * 'o': Exchange start and end of Visual area. |
7279 * 'O': same, but in block mode exchange left and right corners. | 7088 * 'O': same, but in block mode exchange left and right corners. |
7280 */ | 7089 */ |
7281 static void | 7090 static void |
7324 curwin->w_cursor = VIsual; | 7133 curwin->w_cursor = VIsual; |
7325 VIsual = old_cursor; | 7134 VIsual = old_cursor; |
7326 curwin->w_set_curswant = TRUE; | 7135 curwin->w_set_curswant = TRUE; |
7327 } | 7136 } |
7328 } | 7137 } |
7329 #endif /* FEAT_VISUAL */ | |
7330 | 7138 |
7331 /* | 7139 /* |
7332 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | 7140 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). |
7333 */ | 7141 */ |
7334 static void | 7142 static void |
7335 nv_Replace(cap) | 7143 nv_Replace(cap) |
7336 cmdarg_T *cap; | 7144 cmdarg_T *cap; |
7337 { | 7145 { |
7338 #ifdef FEAT_VISUAL | |
7339 if (VIsual_active) /* "R" is replace lines */ | 7146 if (VIsual_active) /* "R" is replace lines */ |
7340 { | 7147 { |
7341 cap->cmdchar = 'c'; | 7148 cap->cmdchar = 'c'; |
7342 cap->nchar = NUL; | 7149 cap->nchar = NUL; |
7343 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ | 7150 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7344 VIsual_mode = 'V'; | 7151 VIsual_mode = 'V'; |
7345 nv_operator(cap); | 7152 nv_operator(cap); |
7346 } | 7153 } |
7347 else | 7154 else if (!checkclearopq(cap->oap)) |
7348 #endif | |
7349 if (!checkclearopq(cap->oap)) | |
7350 { | 7155 { |
7351 if (!curbuf->b_p_ma) | 7156 if (!curbuf->b_p_ma) |
7352 EMSG(_(e_modifiable)); | 7157 EMSG(_(e_modifiable)); |
7353 else | 7158 else |
7354 { | 7159 { |
7367 */ | 7172 */ |
7368 static void | 7173 static void |
7369 nv_vreplace(cap) | 7174 nv_vreplace(cap) |
7370 cmdarg_T *cap; | 7175 cmdarg_T *cap; |
7371 { | 7176 { |
7372 # ifdef FEAT_VISUAL | |
7373 if (VIsual_active) | 7177 if (VIsual_active) |
7374 { | 7178 { |
7375 cap->cmdchar = 'r'; | 7179 cap->cmdchar = 'r'; |
7376 cap->nchar = cap->extra_char; | 7180 cap->nchar = cap->extra_char; |
7377 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | 7181 nv_replace(cap); /* Do same as "r" in Visual mode for now */ |
7378 } | 7182 } |
7379 else | 7183 else if (!checkclearopq(cap->oap)) |
7380 # endif | |
7381 if (!checkclearopq(cap->oap)) | |
7382 { | 7184 { |
7383 if (!curbuf->b_p_ma) | 7185 if (!curbuf->b_p_ma) |
7384 EMSG(_(e_modifiable)); | 7186 EMSG(_(e_modifiable)); |
7385 else | 7187 else |
7386 { | 7188 { |
7523 cap->oap->use_reg_one = TRUE; | 7325 cap->oap->use_reg_one = TRUE; |
7524 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | 7326 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ |
7525 curwin->w_set_curswant = TRUE; | 7327 curwin->w_set_curswant = TRUE; |
7526 } | 7328 } |
7527 | 7329 |
7528 #ifdef FEAT_VISUAL | |
7529 /* | 7330 /* |
7530 * Handle commands that are operators in Visual mode. | 7331 * Handle commands that are operators in Visual mode. |
7531 */ | 7332 */ |
7532 static void | 7333 static void |
7533 v_visop(cap) | 7334 v_visop(cap) |
7548 curwin->w_curswant = MAXCOL; | 7349 curwin->w_curswant = MAXCOL; |
7549 } | 7350 } |
7550 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | 7351 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); |
7551 nv_operator(cap); | 7352 nv_operator(cap); |
7552 } | 7353 } |
7553 #endif | |
7554 | 7354 |
7555 /* | 7355 /* |
7556 * "s" and "S" commands. | 7356 * "s" and "S" commands. |
7557 */ | 7357 */ |
7558 static void | 7358 static void |
7559 nv_subst(cap) | 7359 nv_subst(cap) |
7560 cmdarg_T *cap; | 7360 cmdarg_T *cap; |
7561 { | 7361 { |
7562 #ifdef FEAT_VISUAL | |
7563 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ | 7362 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7564 { | 7363 { |
7565 if (cap->cmdchar == 'S') | 7364 if (cap->cmdchar == 'S') |
7566 { | 7365 { |
7567 VIsual_mode_orig = VIsual_mode; | 7366 VIsual_mode_orig = VIsual_mode; |
7569 } | 7368 } |
7570 cap->cmdchar = 'c'; | 7369 cap->cmdchar = 'c'; |
7571 nv_operator(cap); | 7370 nv_operator(cap); |
7572 } | 7371 } |
7573 else | 7372 else |
7574 #endif | |
7575 nv_optrans(cap); | 7373 nv_optrans(cap); |
7576 } | 7374 } |
7577 | 7375 |
7578 /* | 7376 /* |
7579 * Abbreviated commands. | 7377 * Abbreviated commands. |
7583 cmdarg_T *cap; | 7381 cmdarg_T *cap; |
7584 { | 7382 { |
7585 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | 7383 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) |
7586 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | 7384 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ |
7587 | 7385 |
7588 #ifdef FEAT_VISUAL | |
7589 /* in Visual mode these commands are operators */ | 7386 /* in Visual mode these commands are operators */ |
7590 if (VIsual_active) | 7387 if (VIsual_active) |
7591 v_visop(cap); | 7388 v_visop(cap); |
7592 else | 7389 else |
7593 #endif | |
7594 nv_optrans(cap); | 7390 nv_optrans(cap); |
7595 } | 7391 } |
7596 | 7392 |
7597 /* | 7393 /* |
7598 * Translate a command into another command. | 7394 * Translate a command into another command. |
7756 } | 7552 } |
7757 else | 7553 else |
7758 clearopbeep(cap->oap); | 7554 clearopbeep(cap->oap); |
7759 } | 7555 } |
7760 | 7556 |
7761 #ifdef FEAT_VISUAL | |
7762 /* | 7557 /* |
7763 * Handle "v", "V" and "CTRL-V" commands. | 7558 * Handle "v", "V" and "CTRL-V" commands. |
7764 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | 7559 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg |
7765 * is TRUE. | 7560 * is TRUE. |
7766 * Handle CTRL-Q just like CTRL-V. | 7561 * Handle CTRL-Q just like CTRL-V. |
7948 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | 7743 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; |
7949 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | 7744 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; |
7950 } | 7745 } |
7951 } | 7746 } |
7952 | 7747 |
7953 #endif /* FEAT_VISUAL */ | |
7954 | 7748 |
7955 /* | 7749 /* |
7956 * CTRL-W: Window commands | 7750 * CTRL-W: Window commands |
7957 */ | 7751 */ |
7958 static void | 7752 static void |
7973 static void | 7767 static void |
7974 nv_suspend(cap) | 7768 nv_suspend(cap) |
7975 cmdarg_T *cap; | 7769 cmdarg_T *cap; |
7976 { | 7770 { |
7977 clearop(cap->oap); | 7771 clearop(cap->oap); |
7978 #ifdef FEAT_VISUAL | |
7979 if (VIsual_active) | 7772 if (VIsual_active) |
7980 end_visual_mode(); /* stop Visual mode */ | 7773 end_visual_mode(); /* stop Visual mode */ |
7981 #endif | |
7982 do_cmdline_cmd((char_u *)"st"); | 7774 do_cmdline_cmd((char_u *)"st"); |
7983 } | 7775 } |
7984 | 7776 |
7985 /* | 7777 /* |
7986 * Commands starting with "g". | 7778 * Commands starting with "g". |
7988 static void | 7780 static void |
7989 nv_g_cmd(cap) | 7781 nv_g_cmd(cap) |
7990 cmdarg_T *cap; | 7782 cmdarg_T *cap; |
7991 { | 7783 { |
7992 oparg_T *oap = cap->oap; | 7784 oparg_T *oap = cap->oap; |
7993 #ifdef FEAT_VISUAL | |
7994 pos_T tpos; | 7785 pos_T tpos; |
7995 #endif | |
7996 int i; | 7786 int i; |
7997 int flag = FALSE; | 7787 int flag = FALSE; |
7998 | 7788 |
7999 switch (cap->nchar) | 7789 switch (cap->nchar) |
8000 { | 7790 { |
8023 | 7813 |
8024 case '&': | 7814 case '&': |
8025 do_cmdline_cmd((char_u *)"%s//~/&"); | 7815 do_cmdline_cmd((char_u *)"%s//~/&"); |
8026 break; | 7816 break; |
8027 | 7817 |
8028 #ifdef FEAT_VISUAL | |
8029 /* | 7818 /* |
8030 * "gv": Reselect the previous Visual area. If Visual already active, | 7819 * "gv": Reselect the previous Visual area. If Visual already active, |
8031 * exchange previous and current Visual area. | 7820 * exchange previous and current Visual area. |
8032 */ | 7821 */ |
8033 case 'v': | 7822 case 'v': |
8124 # endif | 7913 # endif |
8125 cap->cmdchar = cap->nchar + ('v' - 'h'); | 7914 cap->cmdchar = cap->nchar + ('v' - 'h'); |
8126 cap->arg = TRUE; | 7915 cap->arg = TRUE; |
8127 nv_visual(cap); | 7916 nv_visual(cap); |
8128 break; | 7917 break; |
8129 #endif /* FEAT_VISUAL */ | |
8130 | 7918 |
8131 /* "gn", "gN" visually select next/previous search match | 7919 /* "gn", "gN" visually select next/previous search match |
8132 * "gn" selects next match | 7920 * "gn" selects next match |
8133 * "gN" selects previous match | 7921 * "gN" selects previous match |
8134 */ | 7922 */ |
8135 case 'N': | 7923 case 'N': |
8136 case 'n': | 7924 case 'n': |
8137 #ifdef FEAT_VISUAL | |
8138 if (!current_search(cap->count1, cap->nchar == 'n')) | 7925 if (!current_search(cap->count1, cap->nchar == 'n')) |
8139 #endif | |
8140 clearopbeep(oap); | 7926 clearopbeep(oap); |
8141 break; | 7927 break; |
8142 | 7928 |
8143 /* | 7929 /* |
8144 * "gj" and "gk" two new funny movement keys -- up and down | 7930 * "gj" and "gk" two new funny movement keys -- up and down |
8256 /* Decrease the cursor column until it's on a non-blank. */ | 8042 /* Decrease the cursor column until it's on a non-blank. */ |
8257 while (curwin->w_cursor.col > 0 | 8043 while (curwin->w_cursor.col > 0 |
8258 && vim_iswhite(ptr[curwin->w_cursor.col])) | 8044 && vim_iswhite(ptr[curwin->w_cursor.col])) |
8259 --curwin->w_cursor.col; | 8045 --curwin->w_cursor.col; |
8260 curwin->w_set_curswant = TRUE; | 8046 curwin->w_set_curswant = TRUE; |
8261 #ifdef FEAT_VISUAL | |
8262 adjust_for_sel(cap); | 8047 adjust_for_sel(cap); |
8263 #endif | |
8264 } | 8048 } |
8265 break; | 8049 break; |
8266 | 8050 |
8267 case '$': | 8051 case '$': |
8268 case K_END: | 8052 case K_END: |
8655 static void | 8439 static void |
8656 nv_Undo(cap) | 8440 nv_Undo(cap) |
8657 cmdarg_T *cap; | 8441 cmdarg_T *cap; |
8658 { | 8442 { |
8659 /* In Visual mode and typing "gUU" triggers an operator */ | 8443 /* In Visual mode and typing "gUU" triggers an operator */ |
8660 if (cap->oap->op_type == OP_UPPER | 8444 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
8661 #ifdef FEAT_VISUAL | |
8662 || VIsual_active | |
8663 #endif | |
8664 ) | |
8665 { | 8445 { |
8666 /* translate "gUU" to "gUgU" */ | 8446 /* translate "gUU" to "gUgU" */ |
8667 cap->cmdchar = 'g'; | 8447 cap->cmdchar = 'g'; |
8668 cap->nchar = 'U'; | 8448 cap->nchar = 'U'; |
8669 nv_operator(cap); | 8449 nv_operator(cap); |
8681 */ | 8461 */ |
8682 static void | 8462 static void |
8683 nv_tilde(cap) | 8463 nv_tilde(cap) |
8684 cmdarg_T *cap; | 8464 cmdarg_T *cap; |
8685 { | 8465 { |
8686 if (!p_to | 8466 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
8687 #ifdef FEAT_VISUAL | |
8688 && !VIsual_active | |
8689 #endif | |
8690 && cap->oap->op_type != OP_TILDE) | |
8691 n_swapchar(cap); | 8467 n_swapchar(cap); |
8692 else | 8468 else |
8693 nv_operator(cap); | 8469 nv_operator(cap); |
8694 } | 8470 } |
8695 | 8471 |
8904 | 8680 |
8905 if (n == FAIL && cap->oap->op_type == OP_NOP) | 8681 if (n == FAIL && cap->oap->op_type == OP_NOP) |
8906 clearopbeep(cap->oap); | 8682 clearopbeep(cap->oap); |
8907 else | 8683 else |
8908 { | 8684 { |
8909 #ifdef FEAT_VISUAL | |
8910 adjust_for_sel(cap); | 8685 adjust_for_sel(cap); |
8911 #endif | |
8912 #ifdef FEAT_FOLDING | 8686 #ifdef FEAT_FOLDING |
8913 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | 8687 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
8914 foldOpenCursor(); | 8688 foldOpenCursor(); |
8915 #endif | 8689 #endif |
8916 } | 8690 } |
8929 * - the column is > 0 | 8703 * - the column is > 0 |
8930 * - not in Visual mode or 'selection' is "o" | 8704 * - not in Visual mode or 'selection' is "o" |
8931 * - 'virtualedit' is not "all" and not "onemore". | 8705 * - 'virtualedit' is not "all" and not "onemore". |
8932 */ | 8706 */ |
8933 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | 8707 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL |
8934 #ifdef FEAT_VISUAL | |
8935 && (!VIsual_active || *p_sel == 'o') | 8708 && (!VIsual_active || *p_sel == 'o') |
8936 #endif | |
8937 #ifdef FEAT_VIRTUALEDIT | 8709 #ifdef FEAT_VIRTUALEDIT |
8938 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | 8710 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 |
8939 #endif | 8711 #endif |
8940 ) | 8712 ) |
8941 { | 8713 { |
8966 #endif | 8738 #endif |
8967 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a | 8739 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8968 one-character line). */ | 8740 one-character line). */ |
8969 } | 8741 } |
8970 | 8742 |
8971 #ifdef FEAT_VISUAL | |
8972 /* | 8743 /* |
8973 * In exclusive Visual mode, may include the last character. | 8744 * In exclusive Visual mode, may include the last character. |
8974 */ | 8745 */ |
8975 static void | 8746 static void |
8976 adjust_for_sel(cap) | 8747 adjust_for_sel(cap) |
8977 cmdarg_T *cap; | 8748 cmdarg_T *cap; |
8978 { | 8749 { |
8979 if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' | 8750 if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' |
8980 && gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor)) | 8751 && gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor)) |
8981 { | 8752 { |
8982 # ifdef FEAT_MBYTE | 8753 #ifdef FEAT_MBYTE |
8983 if (has_mbyte) | 8754 if (has_mbyte) |
8984 inc_cursor(); | 8755 inc_cursor(); |
8985 else | 8756 else |
8986 # endif | 8757 #endif |
8987 ++curwin->w_cursor.col; | 8758 ++curwin->w_cursor.col; |
8988 cap->oap->inclusive = FALSE; | 8759 cap->oap->inclusive = FALSE; |
8989 } | 8760 } |
8990 } | 8761 } |
8991 | 8762 |
9042 cap->arg = TRUE; | 8813 cap->arg = TRUE; |
9043 nv_g_cmd(cap); | 8814 nv_g_cmd(cap); |
9044 } | 8815 } |
9045 } | 8816 } |
9046 | 8817 |
9047 #endif | |
9048 | 8818 |
9049 /* | 8819 /* |
9050 * "G", "gg", CTRL-END, CTRL-HOME. | 8820 * "G", "gg", CTRL-END, CTRL-HOME. |
9051 * cap->arg is TRUE for "G". | 8821 * cap->arg is TRUE for "G". |
9052 */ | 8822 */ |
9093 restart_edit = 0; | 8863 restart_edit = 0; |
9094 #ifdef FEAT_CMDWIN | 8864 #ifdef FEAT_CMDWIN |
9095 if (cmdwin_type != 0) | 8865 if (cmdwin_type != 0) |
9096 cmdwin_result = Ctrl_C; | 8866 cmdwin_result = Ctrl_C; |
9097 #endif | 8867 #endif |
9098 #ifdef FEAT_VISUAL | |
9099 if (VIsual_active) | 8868 if (VIsual_active) |
9100 { | 8869 { |
9101 end_visual_mode(); /* stop Visual */ | 8870 end_visual_mode(); /* stop Visual */ |
9102 redraw_curbuf_later(INVERTED); | 8871 redraw_curbuf_later(INVERTED); |
9103 } | 8872 } |
9104 #endif | |
9105 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | 8873 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ |
9106 if (cap->nchar == Ctrl_G && p_im) | 8874 if (cap->nchar == Ctrl_G && p_im) |
9107 restart_edit = 'a'; | 8875 restart_edit = 'a'; |
9108 } | 8876 } |
9109 else | 8877 else |
9130 { | 8898 { |
9131 if (restart_edit == 0 | 8899 if (restart_edit == 0 |
9132 #ifdef FEAT_CMDWIN | 8900 #ifdef FEAT_CMDWIN |
9133 && cmdwin_type == 0 | 8901 && cmdwin_type == 0 |
9134 #endif | 8902 #endif |
9135 #ifdef FEAT_VISUAL | |
9136 && !VIsual_active | 8903 && !VIsual_active |
9137 #endif | |
9138 && no_reason) | 8904 && no_reason) |
9139 MSG(_("Type :quit<Enter> to exit Vim")); | 8905 MSG(_("Type :quit<Enter> to exit Vim")); |
9140 | 8906 |
9141 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | 8907 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be |
9142 * set again below when halfway a mapping. */ | 8908 * set again below when halfway a mapping. */ |
9150 return; | 8916 return; |
9151 } | 8917 } |
9152 #endif | 8918 #endif |
9153 } | 8919 } |
9154 | 8920 |
9155 #ifdef FEAT_VISUAL | |
9156 if (VIsual_active) | 8921 if (VIsual_active) |
9157 { | 8922 { |
9158 end_visual_mode(); /* stop Visual */ | 8923 end_visual_mode(); /* stop Visual */ |
9159 check_cursor_col(); /* make sure cursor is not beyond EOL */ | 8924 check_cursor_col(); /* make sure cursor is not beyond EOL */ |
9160 curwin->w_set_curswant = TRUE; | 8925 curwin->w_set_curswant = TRUE; |
9161 redraw_curbuf_later(INVERTED); | 8926 redraw_curbuf_later(INVERTED); |
9162 } | 8927 } |
9163 else | 8928 else if (no_reason) |
9164 #endif | 8929 vim_beep(); |
9165 if (no_reason) | |
9166 vim_beep(); | |
9167 clearop(cap->oap); | 8930 clearop(cap->oap); |
9168 | 8931 |
9169 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | 8932 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is |
9170 * set return to Insert mode afterwards. */ | 8933 * set return to Insert mode afterwards. */ |
9171 if (restart_edit == 0 && goto_im() | 8934 if (restart_edit == 0 && goto_im() |
9185 { | 8948 { |
9186 /* <Insert> is equal to "i" */ | 8949 /* <Insert> is equal to "i" */ |
9187 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | 8950 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) |
9188 cap->cmdchar = 'i'; | 8951 cap->cmdchar = 'i'; |
9189 | 8952 |
9190 #ifdef FEAT_VISUAL | |
9191 /* in Visual mode "A" and "I" are an operator */ | 8953 /* in Visual mode "A" and "I" are an operator */ |
9192 if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) | 8954 if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) |
9193 v_visop(cap); | 8955 v_visop(cap); |
9194 | 8956 |
9195 /* in Visual mode and after an operator "a" and "i" are for text objects */ | 8957 /* in Visual mode and after an operator "a" and "i" are for text objects */ |
9196 else | 8958 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
9197 #endif | 8959 && (cap->oap->op_type != OP_NOP || VIsual_active)) |
9198 if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') | |
9199 && (cap->oap->op_type != OP_NOP | |
9200 #ifdef FEAT_VISUAL | |
9201 || VIsual_active | |
9202 #endif | |
9203 )) | |
9204 { | 8960 { |
9205 #ifdef FEAT_TEXTOBJ | 8961 #ifdef FEAT_TEXTOBJ |
9206 nv_object(cap); | 8962 nv_object(cap); |
9207 #else | 8963 #else |
9208 clearopbeep(cap->oap); | 8964 clearopbeep(cap->oap); |
9465 */ | 9221 */ |
9466 static void | 9222 static void |
9467 nv_join(cap) | 9223 nv_join(cap) |
9468 cmdarg_T *cap; | 9224 cmdarg_T *cap; |
9469 { | 9225 { |
9470 #ifdef FEAT_VISUAL | |
9471 if (VIsual_active) /* join the visual lines */ | 9226 if (VIsual_active) /* join the visual lines */ |
9472 nv_operator(cap); | 9227 nv_operator(cap); |
9473 else | 9228 else if (!checkclearop(cap->oap)) |
9474 #endif | |
9475 if (!checkclearop(cap->oap)) | |
9476 { | 9229 { |
9477 if (cap->count0 <= 1) | 9230 if (cap->count0 <= 1) |
9478 cap->count0 = 2; /* default for join is two lines! */ | 9231 cap->count0 = 2; /* default for join is two lines! */ |
9479 if (curwin->w_cursor.lnum + cap->count0 - 1 > | 9232 if (curwin->w_cursor.lnum + cap->count0 - 1 > |
9480 curbuf->b_ml.ml_line_count) | 9233 curbuf->b_ml.ml_line_count) |
9493 */ | 9246 */ |
9494 static void | 9247 static void |
9495 nv_put(cap) | 9248 nv_put(cap) |
9496 cmdarg_T *cap; | 9249 cmdarg_T *cap; |
9497 { | 9250 { |
9498 #ifdef FEAT_VISUAL | |
9499 int regname = 0; | 9251 int regname = 0; |
9500 void *reg1 = NULL, *reg2 = NULL; | 9252 void *reg1 = NULL, *reg2 = NULL; |
9501 int empty = FALSE; | 9253 int empty = FALSE; |
9502 int was_visual = FALSE; | 9254 int was_visual = FALSE; |
9503 #endif | |
9504 int dir; | 9255 int dir; |
9505 int flags = 0; | 9256 int flags = 0; |
9506 | 9257 |
9507 if (cap->oap->op_type != OP_NOP) | 9258 if (cap->oap->op_type != OP_NOP) |
9508 { | 9259 { |
9524 ? BACKWARD : FORWARD; | 9275 ? BACKWARD : FORWARD; |
9525 prep_redo_cmd(cap); | 9276 prep_redo_cmd(cap); |
9526 if (cap->cmdchar == 'g') | 9277 if (cap->cmdchar == 'g') |
9527 flags |= PUT_CURSEND; | 9278 flags |= PUT_CURSEND; |
9528 | 9279 |
9529 #ifdef FEAT_VISUAL | |
9530 if (VIsual_active) | 9280 if (VIsual_active) |
9531 { | 9281 { |
9532 /* Putting in Visual mode: The put text replaces the selected | 9282 /* Putting in Visual mode: The put text replaces the selected |
9533 * text. First delete the selected text, then put the new text. | 9283 * text. First delete the selected text, then put the new text. |
9534 * Need to save and restore the registers that the delete | 9284 * Need to save and restore the registers that the delete |
9535 * overwrites if the old contents is being put. | 9285 * overwrites if the old contents is being put. |
9536 */ | 9286 */ |
9537 was_visual = TRUE; | 9287 was_visual = TRUE; |
9538 regname = cap->oap->regname; | 9288 regname = cap->oap->regname; |
9539 # ifdef FEAT_CLIPBOARD | 9289 #ifdef FEAT_CLIPBOARD |
9540 adjust_clip_reg(®name); | 9290 adjust_clip_reg(®name); |
9541 # endif | 9291 #endif |
9542 if (regname == 0 || regname == '"' | 9292 if (regname == 0 || regname == '"' |
9543 || VIM_ISDIGIT(regname) || regname == '-' | 9293 || VIM_ISDIGIT(regname) || regname == '-' |
9544 # ifdef FEAT_CLIPBOARD | 9294 #ifdef FEAT_CLIPBOARD |
9545 || (clip_unnamed && (regname == '*' || regname == '+')) | 9295 || (clip_unnamed && (regname == '*' || regname == '+')) |
9546 # endif | 9296 #endif |
9547 | 9297 |
9548 ) | 9298 ) |
9549 { | 9299 { |
9550 /* The delete is going to overwrite the register we want to | 9300 /* The delete is going to overwrite the register we want to |
9551 * put, save it first. */ | 9301 * put, save it first. */ |
9589 * forward. */ | 9339 * forward. */ |
9590 dir = FORWARD; | 9340 dir = FORWARD; |
9591 /* May have been reset in do_put(). */ | 9341 /* May have been reset in do_put(). */ |
9592 VIsual_active = TRUE; | 9342 VIsual_active = TRUE; |
9593 } | 9343 } |
9594 #endif | |
9595 do_put(cap->oap->regname, dir, cap->count1, flags); | 9344 do_put(cap->oap->regname, dir, cap->count1, flags); |
9596 | 9345 |
9597 #ifdef FEAT_VISUAL | |
9598 /* If a register was saved, put it back now. */ | 9346 /* If a register was saved, put it back now. */ |
9599 if (reg2 != NULL) | 9347 if (reg2 != NULL) |
9600 put_register(regname, reg2); | 9348 put_register(regname, reg2); |
9601 | 9349 |
9602 /* What to reselect with "gv"? Selecting the just put text seems to | 9350 /* What to reselect with "gv"? Selecting the just put text seems to |
9619 { | 9367 { |
9620 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | 9368 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
9621 coladvance((colnr_T)MAXCOL); | 9369 coladvance((colnr_T)MAXCOL); |
9622 } | 9370 } |
9623 } | 9371 } |
9624 #endif | |
9625 auto_format(FALSE, TRUE); | 9372 auto_format(FALSE, TRUE); |
9626 } | 9373 } |
9627 } | 9374 } |
9628 | 9375 |
9629 /* | 9376 /* |
9640 clearop(cap->oap); | 9387 clearop(cap->oap); |
9641 nv_diffgetput(FALSE); | 9388 nv_diffgetput(FALSE); |
9642 } | 9389 } |
9643 else | 9390 else |
9644 #endif | 9391 #endif |
9645 #ifdef FEAT_VISUAL | |
9646 if (VIsual_active) /* switch start and end of visual */ | 9392 if (VIsual_active) /* switch start and end of visual */ |
9647 v_swap_corners(cap->cmdchar); | 9393 v_swap_corners(cap->cmdchar); |
9648 else | 9394 else |
9649 #endif | |
9650 n_opencmd(cap); | 9395 n_opencmd(cap); |
9651 } | 9396 } |
9652 | 9397 |
9653 #ifdef FEAT_SNIFF | 9398 #ifdef FEAT_SNIFF |
9654 static void | 9399 static void |