Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | /* |
| 10 | * normal.c: Contains the main routine for processing characters in command |
| 11 | * mode. Communicates closely with the code in ops.c to handle |
| 12 | * the operators. |
| 13 | */ |
| 14 | |
| 15 | #include "vim.h" |
| 16 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | /* |
| 18 | * The Visual area is remembered for reselection. |
| 19 | */ |
| 20 | static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
| 21 | static linenr_T resel_VIsual_line_count; /* number of lines */ |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 22 | static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
Bram Moolenaar | 7d311c5 | 2014-02-22 23:49:35 +0100 | [diff] [blame] | 23 | static int VIsual_mode_orig = NUL; /* saved Visual mode */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | |
| 25 | static int restart_VIsual_select = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 27 | #ifdef FEAT_EVAL |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 28 | static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 29 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | static int |
Bram Moolenaar | 0c50a6b | 2012-05-25 11:04:38 +0200 | [diff] [blame] | 31 | #ifdef __BORLANDC__ |
| 32 | _RTLENTRYF |
| 33 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 34 | nv_compare(const void *s1, const void *s2); |
| 35 | static int find_command(int cmdchar); |
| 36 | static void op_colon(oparg_T *oap); |
| 37 | static void op_function(oparg_T *oap); |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 38 | #if defined(FEAT_MOUSE) |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 39 | static void find_start_of_word(pos_T *); |
| 40 | static void find_end_of_word(pos_T *); |
| 41 | static int get_mouse_class(char_u *p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 43 | static void prep_redo_cmd(cmdarg_T *cap); |
| 44 | static void prep_redo(int regname, long, int, int, int, int, int); |
| 45 | static int checkclearop(oparg_T *oap); |
| 46 | static int checkclearopq(oparg_T *oap); |
| 47 | static void clearop(oparg_T *oap); |
| 48 | static void clearopbeep(oparg_T *oap); |
| 49 | static void unshift_special(cmdarg_T *cap); |
| 50 | static void may_clear_cmdline(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 52 | static void del_from_showcmd(int); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
| 55 | /* |
| 56 | * nv_*(): functions called to handle Normal and Visual mode commands. |
| 57 | * n_*(): functions called to handle Normal mode commands. |
| 58 | * v_*(): functions called to handle Visual mode commands. |
| 59 | */ |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 60 | static void nv_ignore(cmdarg_T *cap); |
| 61 | static void nv_nop(cmdarg_T *cap); |
| 62 | static void nv_error(cmdarg_T *cap); |
| 63 | static void nv_help(cmdarg_T *cap); |
| 64 | static void nv_addsub(cmdarg_T *cap); |
| 65 | static void nv_page(cmdarg_T *cap); |
| 66 | static void nv_gd(oparg_T *oap, int nchar, int thisblock); |
| 67 | static int nv_screengo(oparg_T *oap, int dir, long dist); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | #ifdef FEAT_MOUSE |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 69 | static void nv_mousescroll(cmdarg_T *cap); |
| 70 | static void nv_mouse(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 71 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 72 | static void nv_scroll_line(cmdarg_T *cap); |
| 73 | static void nv_zet(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | #ifdef FEAT_GUI |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 75 | static void nv_ver_scrollbar(cmdarg_T *cap); |
| 76 | static void nv_hor_scrollbar(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 77 | #endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 78 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 79 | static void nv_tabline(cmdarg_T *cap); |
| 80 | static void nv_tabmenu(cmdarg_T *cap); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 81 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 82 | static void nv_exmode(cmdarg_T *cap); |
| 83 | static void nv_colon(cmdarg_T *cap); |
| 84 | static void nv_ctrlg(cmdarg_T *cap); |
| 85 | static void nv_ctrlh(cmdarg_T *cap); |
| 86 | static void nv_clear(cmdarg_T *cap); |
| 87 | static void nv_ctrlo(cmdarg_T *cap); |
| 88 | static void nv_hat(cmdarg_T *cap); |
| 89 | static void nv_Zet(cmdarg_T *cap); |
| 90 | static void nv_ident(cmdarg_T *cap); |
| 91 | static void nv_tagpop(cmdarg_T *cap); |
| 92 | static void nv_scroll(cmdarg_T *cap); |
| 93 | static void nv_right(cmdarg_T *cap); |
| 94 | static void nv_left(cmdarg_T *cap); |
| 95 | static void nv_up(cmdarg_T *cap); |
| 96 | static void nv_down(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 97 | #ifdef FEAT_SEARCHPATH |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 98 | static void nv_gotofile(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 99 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 100 | static void nv_end(cmdarg_T *cap); |
| 101 | static void nv_dollar(cmdarg_T *cap); |
| 102 | static void nv_search(cmdarg_T *cap); |
| 103 | static void nv_next(cmdarg_T *cap); |
| 104 | static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt); |
| 105 | static void nv_csearch(cmdarg_T *cap); |
| 106 | static void nv_brackets(cmdarg_T *cap); |
| 107 | static void nv_percent(cmdarg_T *cap); |
| 108 | static void nv_brace(cmdarg_T *cap); |
| 109 | static void nv_mark(cmdarg_T *cap); |
| 110 | static void nv_findpar(cmdarg_T *cap); |
| 111 | static void nv_undo(cmdarg_T *cap); |
| 112 | static void nv_kundo(cmdarg_T *cap); |
| 113 | static void nv_Replace(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 114 | #ifdef FEAT_VREPLACE |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 115 | static void nv_vreplace(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 116 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 117 | static void v_swap_corners(int cmdchar); |
| 118 | static void nv_replace(cmdarg_T *cap); |
| 119 | static void n_swapchar(cmdarg_T *cap); |
| 120 | static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos); |
| 121 | static void v_visop(cmdarg_T *cap); |
| 122 | static void nv_subst(cmdarg_T *cap); |
| 123 | static void nv_abbrev(cmdarg_T *cap); |
| 124 | static void nv_optrans(cmdarg_T *cap); |
| 125 | static void nv_gomark(cmdarg_T *cap); |
| 126 | static void nv_pcmark(cmdarg_T *cap); |
| 127 | static void nv_regname(cmdarg_T *cap); |
| 128 | static void nv_visual(cmdarg_T *cap); |
| 129 | static void n_start_visual_mode(int c); |
| 130 | static void nv_window(cmdarg_T *cap); |
| 131 | static void nv_suspend(cmdarg_T *cap); |
| 132 | static void nv_g_cmd(cmdarg_T *cap); |
| 133 | static void n_opencmd(cmdarg_T *cap); |
| 134 | static void nv_dot(cmdarg_T *cap); |
| 135 | static void nv_redo(cmdarg_T *cap); |
| 136 | static void nv_Undo(cmdarg_T *cap); |
| 137 | static void nv_tilde(cmdarg_T *cap); |
| 138 | static void nv_operator(cmdarg_T *cap); |
Bram Moolenaar | 8af1fbf | 2008-01-05 12:35:21 +0000 | [diff] [blame] | 139 | #ifdef FEAT_EVAL |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 140 | static void set_op_var(int optype); |
Bram Moolenaar | 8af1fbf | 2008-01-05 12:35:21 +0000 | [diff] [blame] | 141 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 142 | static void nv_lineop(cmdarg_T *cap); |
| 143 | static void nv_home(cmdarg_T *cap); |
| 144 | static void nv_pipe(cmdarg_T *cap); |
| 145 | static void nv_bck_word(cmdarg_T *cap); |
| 146 | static void nv_wordcmd(cmdarg_T *cap); |
| 147 | static void nv_beginline(cmdarg_T *cap); |
| 148 | static void adjust_cursor(oparg_T *oap); |
| 149 | static void adjust_for_sel(cmdarg_T *cap); |
| 150 | static int unadjust_for_sel(void); |
| 151 | static void nv_select(cmdarg_T *cap); |
| 152 | static void nv_goto(cmdarg_T *cap); |
| 153 | static void nv_normal(cmdarg_T *cap); |
| 154 | static void nv_esc(cmdarg_T *oap); |
| 155 | static void nv_edit(cmdarg_T *cap); |
| 156 | static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 157 | #ifdef FEAT_TEXTOBJ |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 158 | static void nv_object(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 159 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 160 | static void nv_record(cmdarg_T *cap); |
| 161 | static void nv_at(cmdarg_T *cap); |
| 162 | static void nv_halfpage(cmdarg_T *cap); |
| 163 | static void nv_join(cmdarg_T *cap); |
| 164 | static void nv_put(cmdarg_T *cap); |
| 165 | static void nv_open(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 166 | #ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 167 | static void nv_nbcmd(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 168 | #endif |
| 169 | #ifdef FEAT_DND |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 170 | static void nv_drop(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 171 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 172 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 173 | static void nv_cursorhold(cmdarg_T *cap); |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 174 | #endif |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 175 | static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 176 | |
Bram Moolenaar | 9fd01c6 | 2008-11-01 12:52:38 +0000 | [diff] [blame] | 177 | static char *e_noident = N_("E349: No identifier under cursor"); |
| 178 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 179 | /* |
| 180 | * Function to be called for a Normal or Visual mode command. |
| 181 | * The argument is a cmdarg_T. |
| 182 | */ |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 183 | typedef void (*nv_func_T)(cmdarg_T *cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | |
| 185 | /* Values for cmd_flags. */ |
| 186 | #define NV_NCH 0x01 /* may need to get a second char */ |
| 187 | #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ |
| 188 | #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ |
| 189 | #define NV_LANG 0x08 /* second char needs language adjustment */ |
| 190 | |
| 191 | #define NV_SS 0x10 /* may start selection */ |
| 192 | #define NV_SSS 0x20 /* may start selection with shift modifier */ |
| 193 | #define NV_STS 0x40 /* may stop selection without shift modif. */ |
| 194 | #define NV_RL 0x80 /* 'rightleft' modifies command */ |
| 195 | #define NV_KEEPREG 0x100 /* don't clear regname */ |
| 196 | #define NV_NCW 0x200 /* not allowed in command-line window */ |
| 197 | |
| 198 | /* |
| 199 | * Generally speaking, every Normal mode command should either clear any |
| 200 | * pending operator (with *clearop*()), or set the motion type variable |
| 201 | * oap->motion_type. |
| 202 | * |
| 203 | * When a cursor motion command is made, it is marked as being a character or |
| 204 | * line oriented motion. Then, if an operator is in effect, the operation |
| 205 | * becomes character or line oriented accordingly. |
| 206 | */ |
| 207 | |
| 208 | /* |
| 209 | * This table contains one entry for every Normal or Visual mode command. |
| 210 | * The order doesn't matter, init_normal_cmds() will create a sorted index. |
| 211 | * It is faster when all keys from zero to '~' are present. |
| 212 | */ |
| 213 | static const struct nv_cmd |
| 214 | { |
| 215 | int cmd_char; /* (first) command character */ |
| 216 | nv_func_T cmd_func; /* function for this command */ |
| 217 | short_u cmd_flags; /* NV_ flags */ |
| 218 | short cmd_arg; /* value for ca.arg */ |
| 219 | } nv_cmds[] = |
| 220 | { |
| 221 | {NUL, nv_error, 0, 0}, |
| 222 | {Ctrl_A, nv_addsub, 0, 0}, |
| 223 | {Ctrl_B, nv_page, NV_STS, BACKWARD}, |
| 224 | {Ctrl_C, nv_esc, 0, TRUE}, |
| 225 | {Ctrl_D, nv_halfpage, 0, 0}, |
| 226 | {Ctrl_E, nv_scroll_line, 0, TRUE}, |
| 227 | {Ctrl_F, nv_page, NV_STS, FORWARD}, |
| 228 | {Ctrl_G, nv_ctrlg, 0, 0}, |
| 229 | {Ctrl_H, nv_ctrlh, 0, 0}, |
| 230 | {Ctrl_I, nv_pcmark, 0, 0}, |
| 231 | {NL, nv_down, 0, FALSE}, |
| 232 | {Ctrl_K, nv_error, 0, 0}, |
| 233 | {Ctrl_L, nv_clear, 0, 0}, |
Bram Moolenaar | 9c96f59 | 2005-06-30 21:52:39 +0000 | [diff] [blame] | 234 | {Ctrl_M, nv_down, 0, TRUE}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 235 | {Ctrl_N, nv_down, NV_STS, FALSE}, |
| 236 | {Ctrl_O, nv_ctrlo, 0, 0}, |
| 237 | {Ctrl_P, nv_up, NV_STS, FALSE}, |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 238 | {Ctrl_Q, nv_visual, 0, FALSE}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 239 | {Ctrl_R, nv_redo, 0, 0}, |
| 240 | {Ctrl_S, nv_ignore, 0, 0}, |
| 241 | {Ctrl_T, nv_tagpop, NV_NCW, 0}, |
| 242 | {Ctrl_U, nv_halfpage, 0, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 243 | {Ctrl_V, nv_visual, 0, FALSE}, |
| 244 | {'V', nv_visual, 0, FALSE}, |
| 245 | {'v', nv_visual, 0, FALSE}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 246 | {Ctrl_W, nv_window, 0, 0}, |
| 247 | {Ctrl_X, nv_addsub, 0, 0}, |
| 248 | {Ctrl_Y, nv_scroll_line, 0, FALSE}, |
| 249 | {Ctrl_Z, nv_suspend, 0, 0}, |
| 250 | {ESC, nv_esc, 0, FALSE}, |
| 251 | {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, |
| 252 | {Ctrl_RSB, nv_ident, NV_NCW, 0}, |
| 253 | {Ctrl_HAT, nv_hat, NV_NCW, 0}, |
| 254 | {Ctrl__, nv_error, 0, 0}, |
| 255 | {' ', nv_right, 0, 0}, |
| 256 | {'!', nv_operator, 0, 0}, |
| 257 | {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, |
| 258 | {'#', nv_ident, 0, 0}, |
| 259 | {'$', nv_dollar, 0, 0}, |
| 260 | {'%', nv_percent, 0, 0}, |
| 261 | {'&', nv_optrans, 0, 0}, |
| 262 | {'\'', nv_gomark, NV_NCH_ALW, TRUE}, |
| 263 | {'(', nv_brace, 0, BACKWARD}, |
| 264 | {')', nv_brace, 0, FORWARD}, |
| 265 | {'*', nv_ident, 0, 0}, |
| 266 | {'+', nv_down, 0, TRUE}, |
| 267 | {',', nv_csearch, 0, TRUE}, |
| 268 | {'-', nv_up, 0, TRUE}, |
| 269 | {'.', nv_dot, NV_KEEPREG, 0}, |
| 270 | {'/', nv_search, 0, FALSE}, |
| 271 | {'0', nv_beginline, 0, 0}, |
| 272 | {'1', nv_ignore, 0, 0}, |
| 273 | {'2', nv_ignore, 0, 0}, |
| 274 | {'3', nv_ignore, 0, 0}, |
| 275 | {'4', nv_ignore, 0, 0}, |
| 276 | {'5', nv_ignore, 0, 0}, |
| 277 | {'6', nv_ignore, 0, 0}, |
| 278 | {'7', nv_ignore, 0, 0}, |
| 279 | {'8', nv_ignore, 0, 0}, |
| 280 | {'9', nv_ignore, 0, 0}, |
| 281 | {':', nv_colon, 0, 0}, |
| 282 | {';', nv_csearch, 0, FALSE}, |
| 283 | {'<', nv_operator, NV_RL, 0}, |
| 284 | {'=', nv_operator, 0, 0}, |
| 285 | {'>', nv_operator, NV_RL, 0}, |
| 286 | {'?', nv_search, 0, FALSE}, |
| 287 | {'@', nv_at, NV_NCH_NOP, FALSE}, |
| 288 | {'A', nv_edit, 0, 0}, |
| 289 | {'B', nv_bck_word, 0, 1}, |
| 290 | {'C', nv_abbrev, NV_KEEPREG, 0}, |
| 291 | {'D', nv_abbrev, NV_KEEPREG, 0}, |
| 292 | {'E', nv_wordcmd, 0, TRUE}, |
| 293 | {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, |
| 294 | {'G', nv_goto, 0, TRUE}, |
| 295 | {'H', nv_scroll, 0, 0}, |
| 296 | {'I', nv_edit, 0, 0}, |
| 297 | {'J', nv_join, 0, 0}, |
| 298 | {'K', nv_ident, 0, 0}, |
| 299 | {'L', nv_scroll, 0, 0}, |
| 300 | {'M', nv_scroll, 0, 0}, |
| 301 | {'N', nv_next, 0, SEARCH_REV}, |
| 302 | {'O', nv_open, 0, 0}, |
| 303 | {'P', nv_put, 0, 0}, |
| 304 | {'Q', nv_exmode, NV_NCW, 0}, |
| 305 | {'R', nv_Replace, 0, FALSE}, |
| 306 | {'S', nv_subst, NV_KEEPREG, 0}, |
| 307 | {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, |
| 308 | {'U', nv_Undo, 0, 0}, |
| 309 | {'W', nv_wordcmd, 0, TRUE}, |
| 310 | {'X', nv_abbrev, NV_KEEPREG, 0}, |
| 311 | {'Y', nv_abbrev, NV_KEEPREG, 0}, |
| 312 | {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, |
| 313 | {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, |
| 314 | {'\\', nv_error, 0, 0}, |
| 315 | {']', nv_brackets, NV_NCH_ALW, FORWARD}, |
| 316 | {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, |
| 317 | {'_', nv_lineop, 0, 0}, |
| 318 | {'`', nv_gomark, NV_NCH_ALW, FALSE}, |
| 319 | {'a', nv_edit, NV_NCH, 0}, |
| 320 | {'b', nv_bck_word, 0, 0}, |
| 321 | {'c', nv_operator, 0, 0}, |
| 322 | {'d', nv_operator, 0, 0}, |
| 323 | {'e', nv_wordcmd, 0, FALSE}, |
| 324 | {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, |
| 325 | {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, |
| 326 | {'h', nv_left, NV_RL, 0}, |
| 327 | {'i', nv_edit, NV_NCH, 0}, |
| 328 | {'j', nv_down, 0, FALSE}, |
| 329 | {'k', nv_up, 0, FALSE}, |
| 330 | {'l', nv_right, NV_RL, 0}, |
| 331 | {'m', nv_mark, NV_NCH_NOP, 0}, |
| 332 | {'n', nv_next, 0, 0}, |
| 333 | {'o', nv_open, 0, 0}, |
| 334 | {'p', nv_put, 0, 0}, |
| 335 | {'q', nv_record, NV_NCH, 0}, |
| 336 | {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, |
| 337 | {'s', nv_subst, NV_KEEPREG, 0}, |
| 338 | {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, |
| 339 | {'u', nv_undo, 0, 0}, |
| 340 | {'w', nv_wordcmd, 0, FALSE}, |
| 341 | {'x', nv_abbrev, NV_KEEPREG, 0}, |
| 342 | {'y', nv_operator, 0, 0}, |
| 343 | {'z', nv_zet, NV_NCH_ALW, 0}, |
| 344 | {'{', nv_findpar, 0, BACKWARD}, |
| 345 | {'|', nv_pipe, 0, 0}, |
| 346 | {'}', nv_findpar, 0, FORWARD}, |
| 347 | {'~', nv_tilde, 0, 0}, |
| 348 | |
| 349 | /* pound sign */ |
| 350 | {POUND, nv_ident, 0, 0}, |
| 351 | #ifdef FEAT_MOUSE |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 352 | {K_MOUSEUP, nv_mousescroll, 0, MSCR_UP}, |
| 353 | {K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN}, |
| 354 | {K_MOUSELEFT, nv_mousescroll, 0, MSCR_LEFT}, |
| 355 | {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 356 | {K_LEFTMOUSE, nv_mouse, 0, 0}, |
| 357 | {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, |
| 358 | {K_LEFTDRAG, nv_mouse, 0, 0}, |
| 359 | {K_LEFTRELEASE, nv_mouse, 0, 0}, |
| 360 | {K_LEFTRELEASE_NM, nv_mouse, 0, 0}, |
| 361 | {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
| 362 | {K_MIDDLEDRAG, nv_mouse, 0, 0}, |
| 363 | {K_MIDDLERELEASE, nv_mouse, 0, 0}, |
| 364 | {K_RIGHTMOUSE, nv_mouse, 0, 0}, |
| 365 | {K_RIGHTDRAG, nv_mouse, 0, 0}, |
| 366 | {K_RIGHTRELEASE, nv_mouse, 0, 0}, |
| 367 | {K_X1MOUSE, nv_mouse, 0, 0}, |
| 368 | {K_X1DRAG, nv_mouse, 0, 0}, |
| 369 | {K_X1RELEASE, nv_mouse, 0, 0}, |
| 370 | {K_X2MOUSE, nv_mouse, 0, 0}, |
| 371 | {K_X2DRAG, nv_mouse, 0, 0}, |
| 372 | {K_X2RELEASE, nv_mouse, 0, 0}, |
| 373 | #endif |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 374 | {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 375 | {K_NOP, nv_nop, 0, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 376 | {K_INS, nv_edit, 0, 0}, |
| 377 | {K_KINS, nv_edit, 0, 0}, |
| 378 | {K_BS, nv_ctrlh, 0, 0}, |
| 379 | {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, |
| 380 | {K_S_UP, nv_page, NV_SS, BACKWARD}, |
| 381 | {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, |
| 382 | {K_S_DOWN, nv_page, NV_SS, FORWARD}, |
| 383 | {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, |
| 384 | {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, |
| 385 | {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, |
| 386 | {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, |
| 387 | {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, |
| 388 | {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, |
| 389 | {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, |
| 390 | {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, |
| 391 | {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, |
| 392 | {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, |
| 393 | {K_END, nv_end, NV_SSS|NV_STS, FALSE}, |
| 394 | {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 395 | {K_S_END, nv_end, NV_SS, FALSE}, |
| 396 | {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, |
| 397 | {K_HOME, nv_home, NV_SSS|NV_STS, 0}, |
| 398 | {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 399 | {K_S_HOME, nv_home, NV_SS, 0}, |
| 400 | {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, |
| 401 | {K_DEL, nv_abbrev, 0, 0}, |
| 402 | {K_KDEL, nv_abbrev, 0, 0}, |
| 403 | {K_UNDO, nv_kundo, 0, 0}, |
| 404 | {K_HELP, nv_help, NV_NCW, 0}, |
| 405 | {K_F1, nv_help, NV_NCW, 0}, |
| 406 | {K_XF1, nv_help, NV_NCW, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 407 | {K_SELECT, nv_select, 0, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 408 | #ifdef FEAT_GUI |
| 409 | {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, |
| 410 | {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, |
| 411 | #endif |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 412 | #ifdef FEAT_GUI_TABLINE |
| 413 | {K_TABLINE, nv_tabline, 0, 0}, |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 414 | {K_TABMENU, nv_tabmenu, 0, 0}, |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 415 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 416 | #ifdef FEAT_FKMAP |
Bram Moolenaar | ee2615a | 2016-07-02 18:25:34 +0200 | [diff] [blame] | 417 | {K_F8, farsi_f8, 0, 0}, |
| 418 | {K_F9, farsi_f9, 0, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 419 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 420 | #ifdef FEAT_NETBEANS_INTG |
| 421 | {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, |
| 422 | #endif |
| 423 | #ifdef FEAT_DND |
| 424 | {K_DROP, nv_drop, NV_STS, 0}, |
| 425 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 426 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 427 | {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 428 | #endif |
Bram Moolenaar | ec2da36 | 2017-01-21 20:04:22 +0100 | [diff] [blame] | 429 | {K_PS, nv_edit, 0, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | /* Number of commands in nv_cmds[]. */ |
| 433 | #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) |
| 434 | |
| 435 | /* Sorted index of commands in nv_cmds[]. */ |
| 436 | static short nv_cmd_idx[NV_CMDS_SIZE]; |
| 437 | |
| 438 | /* The highest index for which |
| 439 | * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ |
| 440 | static int nv_max_linear; |
| 441 | |
| 442 | /* |
| 443 | * Compare functions for qsort() below, that checks the command character |
| 444 | * through the index in nv_cmd_idx[]. |
| 445 | */ |
| 446 | static int |
| 447 | #ifdef __BORLANDC__ |
| 448 | _RTLENTRYF |
| 449 | #endif |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 450 | nv_compare(const void *s1, const void *s2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 451 | { |
| 452 | int c1, c2; |
| 453 | |
| 454 | /* The commands are sorted on absolute value. */ |
| 455 | c1 = nv_cmds[*(const short *)s1].cmd_char; |
| 456 | c2 = nv_cmds[*(const short *)s2].cmd_char; |
| 457 | if (c1 < 0) |
| 458 | c1 = -c1; |
| 459 | if (c2 < 0) |
| 460 | c2 = -c2; |
| 461 | return c1 - c2; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Initialize the nv_cmd_idx[] table. |
| 466 | */ |
| 467 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 468 | init_normal_cmds(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 469 | { |
| 470 | int i; |
| 471 | |
| 472 | /* Fill the index table with a one to one relation. */ |
Bram Moolenaar | 78a1531 | 2009-05-15 19:33:18 +0000 | [diff] [blame] | 473 | for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 474 | nv_cmd_idx[i] = i; |
| 475 | |
| 476 | /* Sort the commands by the command character. */ |
| 477 | qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); |
| 478 | |
| 479 | /* Find the first entry that can't be indexed by the command character. */ |
Bram Moolenaar | 78a1531 | 2009-05-15 19:33:18 +0000 | [diff] [blame] | 480 | for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 481 | if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
| 482 | break; |
| 483 | nv_max_linear = i - 1; |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * Search for a command in the commands table. |
| 488 | * Returns -1 for invalid command. |
| 489 | */ |
| 490 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 491 | find_command(int cmdchar) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 492 | { |
| 493 | int i; |
| 494 | int idx; |
| 495 | int top, bot; |
| 496 | int c; |
| 497 | |
| 498 | #ifdef FEAT_MBYTE |
| 499 | /* A multi-byte character is never a command. */ |
| 500 | if (cmdchar >= 0x100) |
| 501 | return -1; |
| 502 | #endif |
| 503 | |
| 504 | /* We use the absolute value of the character. Special keys have a |
| 505 | * negative value, but are sorted on their absolute value. */ |
| 506 | if (cmdchar < 0) |
| 507 | cmdchar = -cmdchar; |
| 508 | |
| 509 | /* If the character is in the first part: The character is the index into |
| 510 | * nv_cmd_idx[]. */ |
| 511 | if (cmdchar <= nv_max_linear) |
| 512 | return nv_cmd_idx[cmdchar]; |
| 513 | |
| 514 | /* Perform a binary search. */ |
| 515 | bot = nv_max_linear + 1; |
| 516 | top = NV_CMDS_SIZE - 1; |
| 517 | idx = -1; |
| 518 | while (bot <= top) |
| 519 | { |
| 520 | i = (top + bot) / 2; |
| 521 | c = nv_cmds[nv_cmd_idx[i]].cmd_char; |
| 522 | if (c < 0) |
| 523 | c = -c; |
| 524 | if (cmdchar == c) |
| 525 | { |
| 526 | idx = nv_cmd_idx[i]; |
| 527 | break; |
| 528 | } |
| 529 | if (cmdchar > c) |
| 530 | bot = i + 1; |
| 531 | else |
| 532 | top = i - 1; |
| 533 | } |
| 534 | return idx; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * Execute a command in Normal mode. |
| 539 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 540 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 541 | normal_cmd( |
| 542 | oparg_T *oap, |
| 543 | int toplevel UNUSED) /* TRUE when called from main() */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 544 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 545 | cmdarg_T ca; /* command arguments */ |
| 546 | int c; |
| 547 | int ctrl_w = FALSE; /* got CTRL-W command */ |
| 548 | int old_col = curwin->w_curswant; |
| 549 | #ifdef FEAT_CMDL_INFO |
| 550 | int need_flushbuf; /* need to call out_flush() */ |
| 551 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 552 | pos_T old_pos; /* cursor position before command */ |
| 553 | int mapped_len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 554 | static int old_mapped_len = 0; |
| 555 | int idx; |
Bram Moolenaar | 8df74be | 2008-11-20 15:12:02 +0000 | [diff] [blame] | 556 | #ifdef FEAT_EVAL |
| 557 | int set_prevcount = FALSE; |
| 558 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 559 | |
| 560 | vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ |
| 561 | ca.oap = oap; |
Bram Moolenaar | a983fe9 | 2008-07-31 20:04:27 +0000 | [diff] [blame] | 562 | |
| 563 | /* Use a count remembered from before entering an operator. After typing |
| 564 | * "3d" we return from normal_cmd() and come back here, the "3" is |
| 565 | * remembered in "opcount". */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 566 | ca.opcount = opcount; |
| 567 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 568 | /* |
| 569 | * If there is an operator pending, then the command we take this time |
| 570 | * will terminate it. Finish_op tells us to finish the operation before |
| 571 | * returning this time (unless the operation was cancelled). |
| 572 | */ |
| 573 | #ifdef CURSOR_SHAPE |
| 574 | c = finish_op; |
| 575 | #endif |
| 576 | finish_op = (oap->op_type != OP_NOP); |
| 577 | #ifdef CURSOR_SHAPE |
| 578 | if (finish_op != c) |
| 579 | { |
| 580 | ui_cursor_shape(); /* may show different cursor shape */ |
| 581 | # ifdef FEAT_MOUSESHAPE |
| 582 | update_mouseshape(-1); |
| 583 | # endif |
| 584 | } |
| 585 | #endif |
| 586 | |
Bram Moolenaar | a983fe9 | 2008-07-31 20:04:27 +0000 | [diff] [blame] | 587 | /* When not finishing an operator and no register name typed, reset the |
| 588 | * count. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 589 | if (!finish_op && !oap->regname) |
Bram Moolenaar | 8df74be | 2008-11-20 15:12:02 +0000 | [diff] [blame] | 590 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 591 | ca.opcount = 0; |
Bram Moolenaar | 8df74be | 2008-11-20 15:12:02 +0000 | [diff] [blame] | 592 | #ifdef FEAT_EVAL |
| 593 | set_prevcount = TRUE; |
| 594 | #endif |
| 595 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 596 | |
Bram Moolenaar | a983fe9 | 2008-07-31 20:04:27 +0000 | [diff] [blame] | 597 | #ifdef FEAT_AUTOCMD |
| 598 | /* Restore counts from before receiving K_CURSORHOLD. This means after |
| 599 | * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not |
| 600 | * "3 * 2". */ |
| 601 | if (oap->prev_opcount > 0 || oap->prev_count0 > 0) |
| 602 | { |
| 603 | ca.opcount = oap->prev_opcount; |
| 604 | ca.count0 = oap->prev_count0; |
| 605 | oap->prev_opcount = 0; |
| 606 | oap->prev_count0 = 0; |
| 607 | } |
| 608 | #endif |
| 609 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 610 | mapped_len = typebuf_maplen(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 611 | |
| 612 | State = NORMAL_BUSY; |
| 613 | #ifdef USE_ON_FLY_SCROLL |
| 614 | dont_scroll = FALSE; /* allow scrolling here */ |
| 615 | #endif |
| 616 | |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 617 | #ifdef FEAT_EVAL |
| 618 | /* Set v:count here, when called from main() and not a stuffed |
| 619 | * command, so that v:count can be used in an expression mapping |
Bram Moolenaar | 0a36fec | 2014-02-11 15:10:43 +0100 | [diff] [blame] | 620 | * when there is no count. Do set it for redo. */ |
| 621 | if (toplevel && readbuf1_empty()) |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 622 | set_vcount_ca(&ca, &set_prevcount); |
| 623 | #endif |
| 624 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 625 | /* |
| 626 | * Get the command character from the user. |
| 627 | */ |
| 628 | c = safe_vgetc(); |
Bram Moolenaar | 2528163 | 2016-01-21 23:32:32 +0100 | [diff] [blame] | 629 | LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 630 | |
| 631 | /* |
| 632 | * If a mapping was started in Visual or Select mode, remember the length |
| 633 | * of the mapping. This is used below to not return to Insert mode for as |
| 634 | * long as the mapping is being executed. |
| 635 | */ |
| 636 | if (restart_edit == 0) |
| 637 | old_mapped_len = 0; |
| 638 | else if (old_mapped_len |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 639 | || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 640 | old_mapped_len = typebuf_maplen(); |
| 641 | |
| 642 | if (c == NUL) |
| 643 | c = K_ZERO; |
| 644 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 645 | /* |
| 646 | * In Select mode, typed text replaces the selection. |
| 647 | */ |
| 648 | if (VIsual_active |
| 649 | && VIsual_select |
| 650 | && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) |
| 651 | { |
Bram Moolenaar | 686f51e | 2005-05-20 21:19:57 +0000 | [diff] [blame] | 652 | /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
| 653 | * 'insertmode' is set) fake a "d"elete command, Insert mode will |
| 654 | * restart automatically. |
Bram Moolenaar | cf8e7d1 | 2006-12-05 20:43:17 +0000 | [diff] [blame] | 655 | * Insert the typed character in the typeahead buffer, so that it can |
| 656 | * be mapped in Insert mode. Required for ":lmap" to work. */ |
Bram Moolenaar | d8fc5c0 | 2006-04-29 21:55:22 +0000 | [diff] [blame] | 657 | ins_char_typebuf(c); |
Bram Moolenaar | 686f51e | 2005-05-20 21:19:57 +0000 | [diff] [blame] | 658 | if (restart_edit != 0) |
| 659 | c = 'd'; |
| 660 | else |
| 661 | c = 'c'; |
Bram Moolenaar | b388adb | 2006-02-28 23:50:17 +0000 | [diff] [blame] | 662 | msg_nowait = TRUE; /* don't delay going to insert mode */ |
Bram Moolenaar | 9bad29d | 2013-05-21 12:46:02 +0200 | [diff] [blame] | 663 | old_mapped_len = 0; /* do go to Insert mode */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 664 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 665 | |
| 666 | #ifdef FEAT_CMDL_INFO |
| 667 | need_flushbuf = add_to_showcmd(c); |
| 668 | #endif |
| 669 | |
| 670 | getcount: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 671 | if (!(VIsual_active && VIsual_select)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 672 | { |
| 673 | /* |
| 674 | * Handle a count before a command and compute ca.count0. |
| 675 | * Note that '0' is a command and not the start of a count, but it's |
| 676 | * part of a count after other digits. |
| 677 | */ |
| 678 | while ( (c >= '1' && c <= '9') |
| 679 | || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) |
| 680 | { |
| 681 | if (c == K_DEL || c == K_KDEL) |
| 682 | { |
| 683 | ca.count0 /= 10; |
| 684 | #ifdef FEAT_CMDL_INFO |
| 685 | del_from_showcmd(4); /* delete the digit and ~@% */ |
| 686 | #endif |
| 687 | } |
| 688 | else |
| 689 | ca.count0 = ca.count0 * 10 + (c - '0'); |
| 690 | if (ca.count0 < 0) /* got too large! */ |
| 691 | ca.count0 = 999999999L; |
Bram Moolenaar | f13249a | 2007-10-14 15:16:27 +0000 | [diff] [blame] | 692 | #ifdef FEAT_EVAL |
| 693 | /* Set v:count here, when called from main() and not a stuffed |
| 694 | * command, so that v:count can be used in an expression mapping |
Bram Moolenaar | 0a36fec | 2014-02-11 15:10:43 +0100 | [diff] [blame] | 695 | * right after the count. Do set it for redo. */ |
| 696 | if (toplevel && readbuf1_empty()) |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 697 | set_vcount_ca(&ca, &set_prevcount); |
Bram Moolenaar | f13249a | 2007-10-14 15:16:27 +0000 | [diff] [blame] | 698 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 699 | if (ctrl_w) |
| 700 | { |
| 701 | ++no_mapping; |
| 702 | ++allow_keys; /* no mapping for nchar, but keys */ |
| 703 | } |
| 704 | ++no_zero_mapping; /* don't map zero here */ |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 705 | c = plain_vgetc(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 706 | LANGMAP_ADJUST(c, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 707 | --no_zero_mapping; |
| 708 | if (ctrl_w) |
| 709 | { |
| 710 | --no_mapping; |
| 711 | --allow_keys; |
| 712 | } |
| 713 | #ifdef FEAT_CMDL_INFO |
| 714 | need_flushbuf |= add_to_showcmd(c); |
| 715 | #endif |
| 716 | } |
| 717 | |
| 718 | /* |
| 719 | * If we got CTRL-W there may be a/another count |
| 720 | */ |
| 721 | if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) |
| 722 | { |
| 723 | ctrl_w = TRUE; |
| 724 | ca.opcount = ca.count0; /* remember first count */ |
| 725 | ca.count0 = 0; |
| 726 | ++no_mapping; |
| 727 | ++allow_keys; /* no mapping for nchar, but keys */ |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 728 | c = plain_vgetc(); /* get next character */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 729 | LANGMAP_ADJUST(c, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 730 | --no_mapping; |
| 731 | --allow_keys; |
| 732 | #ifdef FEAT_CMDL_INFO |
| 733 | need_flushbuf |= add_to_showcmd(c); |
| 734 | #endif |
| 735 | goto getcount; /* jump back */ |
| 736 | } |
| 737 | } |
| 738 | |
Bram Moolenaar | a983fe9 | 2008-07-31 20:04:27 +0000 | [diff] [blame] | 739 | #ifdef FEAT_AUTOCMD |
| 740 | if (c == K_CURSORHOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 741 | { |
Bram Moolenaar | a983fe9 | 2008-07-31 20:04:27 +0000 | [diff] [blame] | 742 | /* Save the count values so that ca.opcount and ca.count0 are exactly |
| 743 | * the same when coming back here after handling K_CURSORHOLD. */ |
| 744 | oap->prev_opcount = ca.opcount; |
| 745 | oap->prev_count0 = ca.count0; |
| 746 | } |
| 747 | else |
| 748 | #endif |
| 749 | if (ca.opcount != 0) |
| 750 | { |
| 751 | /* |
| 752 | * If we're in the middle of an operator (including after entering a |
| 753 | * yank buffer with '"') AND we had a count before the operator, then |
| 754 | * that count overrides the current value of ca.count0. |
| 755 | * What this means effectively, is that commands like "3dw" get turned |
| 756 | * into "d3w" which makes things fall into place pretty neatly. |
| 757 | * If you give a count before AND after the operator, they are |
| 758 | * multiplied. |
| 759 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 760 | if (ca.count0) |
| 761 | ca.count0 *= ca.opcount; |
| 762 | else |
| 763 | ca.count0 = ca.opcount; |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * Always remember the count. It will be set to zero (on the next call, |
| 768 | * above) when there is no pending operator. |
| 769 | * When called from main(), save the count for use by the "count" built-in |
| 770 | * variable. |
| 771 | */ |
| 772 | ca.opcount = ca.count0; |
| 773 | ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); |
| 774 | |
| 775 | #ifdef FEAT_EVAL |
| 776 | /* |
| 777 | * Only set v:count when called from main() and not a stuffed command. |
Bram Moolenaar | 0a36fec | 2014-02-11 15:10:43 +0100 | [diff] [blame] | 778 | * Do set it for redo. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 779 | */ |
Bram Moolenaar | 0a36fec | 2014-02-11 15:10:43 +0100 | [diff] [blame] | 780 | if (toplevel && readbuf1_empty()) |
Bram Moolenaar | 8df74be | 2008-11-20 15:12:02 +0000 | [diff] [blame] | 781 | set_vcount(ca.count0, ca.count1, set_prevcount); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 782 | #endif |
| 783 | |
| 784 | /* |
| 785 | * Find the command character in the table of commands. |
| 786 | * For CTRL-W we already got nchar when looking for a count. |
| 787 | */ |
| 788 | if (ctrl_w) |
| 789 | { |
| 790 | ca.nchar = c; |
| 791 | ca.cmdchar = Ctrl_W; |
| 792 | } |
| 793 | else |
| 794 | ca.cmdchar = c; |
| 795 | idx = find_command(ca.cmdchar); |
| 796 | if (idx < 0) |
| 797 | { |
| 798 | /* Not a known command: beep. */ |
| 799 | clearopbeep(oap); |
| 800 | goto normal_end; |
| 801 | } |
Bram Moolenaar | 05a7bb3 | 2006-01-19 22:09:32 +0000 | [diff] [blame] | 802 | |
Bram Moolenaar | 2d3f489 | 2006-01-20 23:02:51 +0000 | [diff] [blame] | 803 | if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 804 | { |
Bram Moolenaar | d69bd9a | 2014-04-29 12:15:40 +0200 | [diff] [blame] | 805 | /* This command is not allowed while editing a cmdline: beep. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 806 | clearopbeep(oap); |
Bram Moolenaar | 2d3f489 | 2006-01-20 23:02:51 +0000 | [diff] [blame] | 807 | text_locked_msg(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 808 | goto normal_end; |
| 809 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 810 | #ifdef FEAT_AUTOCMD |
| 811 | if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
| 812 | goto normal_end; |
| 813 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 814 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 815 | /* |
| 816 | * In Visual/Select mode, a few keys are handled in a special way. |
| 817 | */ |
| 818 | if (VIsual_active) |
| 819 | { |
| 820 | /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ |
| 821 | if (km_stopsel |
| 822 | && (nv_cmds[idx].cmd_flags & NV_STS) |
| 823 | && !(mod_mask & MOD_MASK_SHIFT)) |
| 824 | { |
| 825 | end_visual_mode(); |
| 826 | redraw_curbuf_later(INVERTED); |
| 827 | } |
| 828 | |
| 829 | /* Keys that work different when 'keymodel' contains "startsel" */ |
| 830 | if (km_startsel) |
| 831 | { |
| 832 | if (nv_cmds[idx].cmd_flags & NV_SS) |
| 833 | { |
| 834 | unshift_special(&ca); |
| 835 | idx = find_command(ca.cmdchar); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 836 | if (idx < 0) |
| 837 | { |
| 838 | /* Just in case */ |
| 839 | clearopbeep(oap); |
| 840 | goto normal_end; |
| 841 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 842 | } |
| 843 | else if ((nv_cmds[idx].cmd_flags & NV_SSS) |
| 844 | && (mod_mask & MOD_MASK_SHIFT)) |
| 845 | { |
| 846 | mod_mask &= ~MOD_MASK_SHIFT; |
| 847 | } |
| 848 | } |
| 849 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 850 | |
| 851 | #ifdef FEAT_RIGHTLEFT |
| 852 | if (curwin->w_p_rl && KeyTyped && !KeyStuffed |
| 853 | && (nv_cmds[idx].cmd_flags & NV_RL)) |
| 854 | { |
| 855 | /* Invert horizontal movements and operations. Only when typed by the |
| 856 | * user directly, not when the result of a mapping or "x" translated |
| 857 | * to "dl". */ |
| 858 | switch (ca.cmdchar) |
| 859 | { |
| 860 | case 'l': ca.cmdchar = 'h'; break; |
| 861 | case K_RIGHT: ca.cmdchar = K_LEFT; break; |
| 862 | case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; |
| 863 | case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; |
| 864 | case 'h': ca.cmdchar = 'l'; break; |
| 865 | case K_LEFT: ca.cmdchar = K_RIGHT; break; |
| 866 | case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; |
| 867 | case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; |
| 868 | case '>': ca.cmdchar = '<'; break; |
| 869 | case '<': ca.cmdchar = '>'; break; |
| 870 | } |
| 871 | idx = find_command(ca.cmdchar); |
| 872 | } |
| 873 | #endif |
| 874 | |
| 875 | /* |
| 876 | * Get an additional character if we need one. |
| 877 | */ |
| 878 | if ((nv_cmds[idx].cmd_flags & NV_NCH) |
| 879 | && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP |
| 880 | && oap->op_type == OP_NOP) |
| 881 | || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW |
| 882 | || (ca.cmdchar == 'q' |
| 883 | && oap->op_type == OP_NOP |
| 884 | && !Recording |
| 885 | && !Exec_reg) |
| 886 | || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 887 | && (oap->op_type != OP_NOP || VIsual_active)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 888 | { |
| 889 | int *cp; |
| 890 | int repl = FALSE; /* get character for replace mode */ |
| 891 | int lit = FALSE; /* get extra character literally */ |
| 892 | int langmap_active = FALSE; /* using :lmap mappings */ |
| 893 | int lang; /* getting a text character */ |
| 894 | #ifdef USE_IM_CONTROL |
| 895 | int save_smd; /* saved value of p_smd */ |
| 896 | #endif |
| 897 | |
| 898 | ++no_mapping; |
| 899 | ++allow_keys; /* no mapping for nchar, but allow key codes */ |
Bram Moolenaar | c2f5abc | 2007-08-08 19:42:05 +0000 | [diff] [blame] | 900 | #ifdef FEAT_AUTOCMD |
| 901 | /* Don't generate a CursorHold event here, most commands can't handle |
| 902 | * it, e.g., nv_replace(), nv_csearch(). */ |
| 903 | did_cursorhold = TRUE; |
| 904 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 905 | if (ca.cmdchar == 'g') |
| 906 | { |
| 907 | /* |
| 908 | * For 'g' get the next character now, so that we can check for |
| 909 | * "gr", "g'" and "g`". |
| 910 | */ |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 911 | ca.nchar = plain_vgetc(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 912 | LANGMAP_ADJUST(ca.nchar, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 913 | #ifdef FEAT_CMDL_INFO |
| 914 | need_flushbuf |= add_to_showcmd(ca.nchar); |
| 915 | #endif |
| 916 | if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' |
Bram Moolenaar | ba2d44f | 2013-11-28 19:27:30 +0100 | [diff] [blame] | 917 | || ca.nchar == Ctrl_BSL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 918 | { |
| 919 | cp = &ca.extra_char; /* need to get a third character */ |
| 920 | if (ca.nchar != 'r') |
| 921 | lit = TRUE; /* get it literally */ |
| 922 | else |
| 923 | repl = TRUE; /* get it in replace mode */ |
| 924 | } |
| 925 | else |
| 926 | cp = NULL; /* no third character needed */ |
| 927 | } |
| 928 | else |
| 929 | { |
| 930 | if (ca.cmdchar == 'r') /* get it in replace mode */ |
| 931 | repl = TRUE; |
| 932 | cp = &ca.nchar; |
| 933 | } |
| 934 | lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); |
| 935 | |
| 936 | /* |
| 937 | * Get a second or third character. |
| 938 | */ |
| 939 | if (cp != NULL) |
| 940 | { |
| 941 | #ifdef CURSOR_SHAPE |
| 942 | if (repl) |
| 943 | { |
| 944 | State = REPLACE; /* pretend Replace mode */ |
| 945 | ui_cursor_shape(); /* show different cursor shape */ |
| 946 | } |
| 947 | #endif |
| 948 | if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) |
| 949 | { |
| 950 | /* Allow mappings defined with ":lmap". */ |
| 951 | --no_mapping; |
| 952 | --allow_keys; |
| 953 | if (repl) |
| 954 | State = LREPLACE; |
| 955 | else |
| 956 | State = LANGMAP; |
| 957 | langmap_active = TRUE; |
| 958 | } |
| 959 | #ifdef USE_IM_CONTROL |
| 960 | save_smd = p_smd; |
| 961 | p_smd = FALSE; /* Don't let the IM code show the mode here */ |
| 962 | if (lang && curbuf->b_p_iminsert == B_IMODE_IM) |
| 963 | im_set_active(TRUE); |
| 964 | #endif |
| 965 | |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 966 | *cp = plain_vgetc(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 967 | |
| 968 | if (langmap_active) |
| 969 | { |
| 970 | /* Undo the decrement done above */ |
| 971 | ++no_mapping; |
| 972 | ++allow_keys; |
| 973 | State = NORMAL_BUSY; |
| 974 | } |
| 975 | #ifdef USE_IM_CONTROL |
| 976 | if (lang) |
| 977 | { |
| 978 | if (curbuf->b_p_iminsert != B_IMODE_LMAP) |
| 979 | im_save_status(&curbuf->b_p_iminsert); |
| 980 | im_set_active(FALSE); |
| 981 | } |
| 982 | p_smd = save_smd; |
| 983 | #endif |
| 984 | #ifdef CURSOR_SHAPE |
| 985 | State = NORMAL_BUSY; |
| 986 | #endif |
| 987 | #ifdef FEAT_CMDL_INFO |
| 988 | need_flushbuf |= add_to_showcmd(*cp); |
| 989 | #endif |
| 990 | |
| 991 | if (!lit) |
| 992 | { |
| 993 | #ifdef FEAT_DIGRAPHS |
| 994 | /* Typing CTRL-K gets a digraph. */ |
| 995 | if (*cp == Ctrl_K |
| 996 | && ((nv_cmds[idx].cmd_flags & NV_LANG) |
| 997 | || cp == &ca.extra_char) |
| 998 | && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) |
| 999 | { |
| 1000 | c = get_digraph(FALSE); |
| 1001 | if (c > 0) |
| 1002 | { |
| 1003 | *cp = c; |
| 1004 | # ifdef FEAT_CMDL_INFO |
| 1005 | /* Guessing how to update showcmd here... */ |
| 1006 | del_from_showcmd(3); |
| 1007 | need_flushbuf |= add_to_showcmd(*cp); |
| 1008 | # endif |
| 1009 | } |
| 1010 | } |
| 1011 | #endif |
| 1012 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1013 | /* adjust chars > 127, except after "tTfFr" commands */ |
| 1014 | LANGMAP_ADJUST(*cp, !lang); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1015 | #ifdef FEAT_RIGHTLEFT |
| 1016 | /* adjust Hebrew mapped char */ |
| 1017 | if (p_hkmap && lang && KeyTyped) |
| 1018 | *cp = hkmap(*cp); |
| 1019 | # ifdef FEAT_FKMAP |
| 1020 | /* adjust Farsi mapped char */ |
| 1021 | if (p_fkmap && lang && KeyTyped) |
| 1022 | *cp = fkmap(*cp); |
| 1023 | # endif |
| 1024 | #endif |
| 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * When the next character is CTRL-\ a following CTRL-N means the |
| 1029 | * command is aborted and we go to Normal mode. |
| 1030 | */ |
| 1031 | if (cp == &ca.extra_char |
| 1032 | && ca.nchar == Ctrl_BSL |
| 1033 | && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) |
| 1034 | { |
| 1035 | ca.cmdchar = Ctrl_BSL; |
| 1036 | ca.nchar = ca.extra_char; |
| 1037 | idx = find_command(ca.cmdchar); |
| 1038 | } |
Bram Moolenaar | 12a753a | 2012-10-23 05:08:53 +0200 | [diff] [blame] | 1039 | else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
Bram Moolenaar | f00dc26 | 2012-10-21 03:54:33 +0200 | [diff] [blame] | 1040 | ca.oap->op_type = get_op_type(*cp, NUL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1041 | else if (*cp == Ctrl_BSL) |
| 1042 | { |
| 1043 | long towait = (p_ttm >= 0 ? p_ttm : p_tm); |
| 1044 | |
| 1045 | /* There is a busy wait here when typing "f<C-\>" and then |
| 1046 | * something different from CTRL-N. Can't be avoided. */ |
| 1047 | while ((c = vpeekc()) <= 0 && towait > 0L) |
| 1048 | { |
| 1049 | do_sleep(towait > 50L ? 50L : towait); |
| 1050 | towait -= 50L; |
| 1051 | } |
| 1052 | if (c > 0) |
| 1053 | { |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 1054 | c = plain_vgetc(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1055 | if (c != Ctrl_N && c != Ctrl_G) |
| 1056 | vungetc(c); |
| 1057 | else |
| 1058 | { |
| 1059 | ca.cmdchar = Ctrl_BSL; |
| 1060 | ca.nchar = c; |
| 1061 | idx = find_command(ca.cmdchar); |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | #ifdef FEAT_MBYTE |
| 1067 | /* When getting a text character and the next character is a |
| 1068 | * multi-byte character, it could be a composing character. |
Bram Moolenaar | 4f88062 | 2014-07-23 12:31:20 +0200 | [diff] [blame] | 1069 | * However, don't wait for it to arrive. Also, do enable mapping, |
| 1070 | * because if it's put back with vungetc() it's too late to apply |
| 1071 | * mapping. */ |
| 1072 | --no_mapping; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1073 | while (enc_utf8 && lang && (c = vpeekc()) > 0 |
| 1074 | && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) |
| 1075 | { |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 1076 | c = plain_vgetc(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1077 | if (!utf_iscomposing(c)) |
| 1078 | { |
| 1079 | vungetc(c); /* it wasn't, put it back */ |
| 1080 | break; |
| 1081 | } |
| 1082 | else if (ca.ncharC1 == 0) |
| 1083 | ca.ncharC1 = c; |
| 1084 | else |
| 1085 | ca.ncharC2 = c; |
| 1086 | } |
Bram Moolenaar | 4f88062 | 2014-07-23 12:31:20 +0200 | [diff] [blame] | 1087 | ++no_mapping; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1088 | #endif |
| 1089 | } |
| 1090 | --no_mapping; |
| 1091 | --allow_keys; |
| 1092 | } |
| 1093 | |
| 1094 | #ifdef FEAT_CMDL_INFO |
| 1095 | /* |
| 1096 | * Flush the showcmd characters onto the screen so we can see them while |
| 1097 | * the command is being executed. Only do this when the shown command was |
| 1098 | * actually displayed, otherwise this will slow down a lot when executing |
| 1099 | * mappings. |
| 1100 | */ |
| 1101 | if (need_flushbuf) |
| 1102 | out_flush(); |
| 1103 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 1104 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | d9205ca | 2008-10-02 20:55:54 +0000 | [diff] [blame] | 1105 | if (ca.cmdchar != K_IGNORE) |
| 1106 | did_cursorhold = FALSE; |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 1107 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1108 | |
| 1109 | State = NORMAL; |
| 1110 | |
| 1111 | if (ca.nchar == ESC) |
| 1112 | { |
| 1113 | clearop(oap); |
| 1114 | if (restart_edit == 0 && goto_im()) |
| 1115 | restart_edit = 'a'; |
| 1116 | goto normal_end; |
| 1117 | } |
| 1118 | |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1119 | if (ca.cmdchar != K_IGNORE) |
| 1120 | { |
| 1121 | msg_didout = FALSE; /* don't scroll screen up for normal command */ |
| 1122 | msg_col = 0; |
| 1123 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1124 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1125 | old_pos = curwin->w_cursor; /* remember where cursor was */ |
| 1126 | |
| 1127 | /* When 'keymodel' contains "startsel" some keys start Select/Visual |
| 1128 | * mode. */ |
| 1129 | if (!VIsual_active && km_startsel) |
| 1130 | { |
| 1131 | if (nv_cmds[idx].cmd_flags & NV_SS) |
| 1132 | { |
| 1133 | start_selection(); |
| 1134 | unshift_special(&ca); |
| 1135 | idx = find_command(ca.cmdchar); |
| 1136 | } |
| 1137 | else if ((nv_cmds[idx].cmd_flags & NV_SSS) |
| 1138 | && (mod_mask & MOD_MASK_SHIFT)) |
| 1139 | { |
| 1140 | start_selection(); |
| 1141 | mod_mask &= ~MOD_MASK_SHIFT; |
| 1142 | } |
| 1143 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1144 | |
| 1145 | /* |
| 1146 | * Execute the command! |
| 1147 | * Call the command function found in the commands table. |
| 1148 | */ |
| 1149 | ca.arg = nv_cmds[idx].cmd_arg; |
| 1150 | (nv_cmds[idx].cmd_func)(&ca); |
| 1151 | |
| 1152 | /* |
| 1153 | * If we didn't start or finish an operator, reset oap->regname, unless we |
| 1154 | * need it later. |
| 1155 | */ |
| 1156 | if (!finish_op |
| 1157 | && !oap->op_type |
| 1158 | && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) |
| 1159 | { |
| 1160 | clearop(oap); |
| 1161 | #ifdef FEAT_EVAL |
Bram Moolenaar | 536681b | 2011-05-10 16:12:45 +0200 | [diff] [blame] | 1162 | { |
| 1163 | int regname = 0; |
Bram Moolenaar | e2bdce3 | 2011-05-10 17:29:33 +0200 | [diff] [blame] | 1164 | |
Bram Moolenaar | 536681b | 2011-05-10 16:12:45 +0200 | [diff] [blame] | 1165 | /* Adjust the register according to 'clipboard', so that when |
| 1166 | * "unnamed" is present it becomes '*' or '+' instead of '"'. */ |
Bram Moolenaar | e2bdce3 | 2011-05-10 17:29:33 +0200 | [diff] [blame] | 1167 | # ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 536681b | 2011-05-10 16:12:45 +0200 | [diff] [blame] | 1168 | adjust_clip_reg(®name); |
Bram Moolenaar | e2bdce3 | 2011-05-10 17:29:33 +0200 | [diff] [blame] | 1169 | # endif |
Bram Moolenaar | 536681b | 2011-05-10 16:12:45 +0200 | [diff] [blame] | 1170 | set_reg_var(regname); |
| 1171 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1172 | #endif |
| 1173 | } |
| 1174 | |
Bram Moolenaar | c6039d8 | 2005-12-02 00:44:04 +0000 | [diff] [blame] | 1175 | /* Get the length of mapped chars again after typing a count, second |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1176 | * character or "z333<cr>". */ |
| 1177 | if (old_mapped_len > 0) |
| 1178 | old_mapped_len = typebuf_maplen(); |
| 1179 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1180 | /* |
| 1181 | * If an operation is pending, handle it... |
| 1182 | */ |
| 1183 | do_pending_operator(&ca, old_col, FALSE); |
| 1184 | |
| 1185 | /* |
| 1186 | * Wait for a moment when a message is displayed that will be overwritten |
| 1187 | * by the mode message. |
| 1188 | * In Visual mode and with "^O" in Insert mode, a short message will be |
| 1189 | * overwritten by the mode message. Wait a bit, until a key is hit. |
| 1190 | * In Visual mode, it's more important to keep the Visual area updated |
| 1191 | * than keeping a message (e.g. from a /pat search). |
| 1192 | * Only do this if the command was typed, not from a mapping. |
| 1193 | * Don't wait when emsg_silent is non-zero. |
| 1194 | * Also wait a bit after an error message, e.g. for "^O:". |
| 1195 | * Don't redraw the screen, it would remove the message. |
| 1196 | */ |
| 1197 | if ( ((p_smd |
Bram Moolenaar | 09df312 | 2006-01-23 22:23:09 +0000 | [diff] [blame] | 1198 | && msg_silent == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1199 | && (restart_edit != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1200 | || (VIsual_active |
| 1201 | && old_pos.lnum == curwin->w_cursor.lnum |
| 1202 | && old_pos.col == curwin->w_cursor.col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1203 | ) |
| 1204 | && (clear_cmdline |
| 1205 | || redraw_cmdline) |
| 1206 | && (msg_didout || (msg_didany && msg_scroll)) |
| 1207 | && !msg_nowait |
| 1208 | && KeyTyped) |
| 1209 | || (restart_edit != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1210 | && !VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1211 | && (msg_scroll |
| 1212 | || emsg_on_display))) |
| 1213 | && oap->regname == 0 |
| 1214 | && !(ca.retval & CA_COMMAND_BUSY) |
| 1215 | && stuff_empty() |
| 1216 | && typebuf_typed() |
| 1217 | && emsg_silent == 0 |
| 1218 | && !did_wait_return |
| 1219 | && oap->op_type == OP_NOP) |
| 1220 | { |
| 1221 | int save_State = State; |
| 1222 | |
| 1223 | /* Draw the cursor with the right shape here */ |
| 1224 | if (restart_edit != 0) |
| 1225 | State = INSERT; |
| 1226 | |
| 1227 | /* If need to redraw, and there is a "keep_msg", redraw before the |
| 1228 | * delay */ |
| 1229 | if (must_redraw && keep_msg != NULL && !emsg_on_display) |
| 1230 | { |
| 1231 | char_u *kmsg; |
| 1232 | |
| 1233 | kmsg = keep_msg; |
| 1234 | keep_msg = NULL; |
| 1235 | /* showmode() will clear keep_msg, but we want to use it anyway */ |
| 1236 | update_screen(0); |
| 1237 | /* now reset it, otherwise it's put in the history again */ |
| 1238 | keep_msg = kmsg; |
| 1239 | msg_attr(kmsg, keep_msg_attr); |
| 1240 | vim_free(kmsg); |
| 1241 | } |
| 1242 | setcursor(); |
| 1243 | cursor_on(); |
| 1244 | out_flush(); |
| 1245 | if (msg_scroll || emsg_on_display) |
| 1246 | ui_delay(1000L, TRUE); /* wait at least one second */ |
| 1247 | ui_delay(3000L, FALSE); /* wait up to three seconds */ |
| 1248 | State = save_State; |
| 1249 | |
| 1250 | msg_scroll = FALSE; |
| 1251 | emsg_on_display = FALSE; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * Finish up after executing a Normal mode command. |
| 1256 | */ |
| 1257 | normal_end: |
| 1258 | |
| 1259 | msg_nowait = FALSE; |
| 1260 | |
| 1261 | /* Reset finish_op, in case it was set */ |
| 1262 | #ifdef CURSOR_SHAPE |
| 1263 | c = finish_op; |
| 1264 | #endif |
| 1265 | finish_op = FALSE; |
| 1266 | #ifdef CURSOR_SHAPE |
| 1267 | /* Redraw the cursor with another shape, if we were in Operator-pending |
| 1268 | * mode or did a replace command. */ |
| 1269 | if (c || ca.cmdchar == 'r') |
| 1270 | { |
| 1271 | ui_cursor_shape(); /* may show different cursor shape */ |
| 1272 | # ifdef FEAT_MOUSESHAPE |
| 1273 | update_mouseshape(-1); |
| 1274 | # endif |
| 1275 | } |
| 1276 | #endif |
| 1277 | |
| 1278 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | a983fe9 | 2008-07-31 20:04:27 +0000 | [diff] [blame] | 1279 | if (oap->op_type == OP_NOP && oap->regname == 0 |
| 1280 | # ifdef FEAT_AUTOCMD |
| 1281 | && ca.cmdchar != K_CURSORHOLD |
| 1282 | # endif |
| 1283 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1284 | clear_showcmd(); |
| 1285 | #endif |
| 1286 | |
| 1287 | checkpcmark(); /* check if we moved since setting pcmark */ |
| 1288 | vim_free(ca.searchbuf); |
| 1289 | |
| 1290 | #ifdef FEAT_MBYTE |
| 1291 | if (has_mbyte) |
| 1292 | mb_adjust_cursor(); |
| 1293 | #endif |
| 1294 | |
| 1295 | #ifdef FEAT_SCROLLBIND |
| 1296 | if (curwin->w_p_scb && toplevel) |
| 1297 | { |
| 1298 | validate_cursor(); /* may need to update w_leftcol */ |
| 1299 | do_check_scrollbind(TRUE); |
| 1300 | } |
| 1301 | #endif |
| 1302 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1303 | #ifdef FEAT_CURSORBIND |
| 1304 | if (curwin->w_p_crb && toplevel) |
| 1305 | { |
| 1306 | validate_cursor(); /* may need to update w_leftcol */ |
| 1307 | do_check_cursorbind(); |
| 1308 | } |
| 1309 | #endif |
| 1310 | |
Bram Moolenaar | 6fe15bb | 2017-08-16 21:09:18 +0200 | [diff] [blame] | 1311 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | eef9add | 2017-09-16 15:38:04 +0200 | [diff] [blame] | 1312 | /* don't go to Insert mode if a terminal has a running job */ |
| 1313 | if (term_job_running(curbuf->b_term)) |
Bram Moolenaar | 6fe15bb | 2017-08-16 21:09:18 +0200 | [diff] [blame] | 1314 | restart_edit = 0; |
| 1315 | #endif |
| 1316 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1317 | /* |
| 1318 | * May restart edit(), if we got here with CTRL-O in Insert mode (but not |
| 1319 | * if still inside a mapping that started in Visual mode). |
| 1320 | * May switch from Visual to Select mode after CTRL-O command. |
| 1321 | */ |
| 1322 | if ( oap->op_type == OP_NOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1323 | && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
| 1324 | || restart_VIsual_select == 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1325 | && !(ca.retval & CA_COMMAND_BUSY) |
| 1326 | && stuff_empty() |
| 1327 | && oap->regname == 0) |
| 1328 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1329 | if (restart_VIsual_select == 1) |
| 1330 | { |
| 1331 | VIsual_select = TRUE; |
| 1332 | showmode(); |
| 1333 | restart_VIsual_select = 0; |
| 1334 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1335 | if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1336 | (void)edit(restart_edit, FALSE, 1L); |
| 1337 | } |
| 1338 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1339 | if (restart_VIsual_select == 2) |
| 1340 | restart_VIsual_select = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1341 | |
| 1342 | /* Save count before an operator for next time. */ |
| 1343 | opcount = ca.opcount; |
| 1344 | } |
| 1345 | |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 1346 | #ifdef FEAT_EVAL |
| 1347 | /* |
| 1348 | * Set v:count and v:count1 according to "cap". |
| 1349 | * Set v:prevcount only when "set_prevcount" is TRUE. |
| 1350 | */ |
| 1351 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1352 | set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 1353 | { |
| 1354 | long count = cap->count0; |
| 1355 | |
| 1356 | /* multiply with cap->opcount the same way as above */ |
| 1357 | if (cap->opcount != 0) |
| 1358 | count = cap->opcount * (count == 0 ? 1 : count); |
| 1359 | set_vcount(count, count == 0 ? 1 : count, *set_prevcount); |
| 1360 | *set_prevcount = FALSE; /* only set v:prevcount once */ |
| 1361 | } |
| 1362 | #endif |
| 1363 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1364 | /* |
| 1365 | * Handle an operator after visual mode or when the movement is finished |
| 1366 | */ |
| 1367 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1368 | do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1369 | { |
| 1370 | oparg_T *oap = cap->oap; |
| 1371 | pos_T old_cursor; |
| 1372 | int empty_region_error; |
| 1373 | int restart_edit_save; |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1374 | #ifdef FEAT_LINEBREAK |
| 1375 | int lbr_saved = curwin->w_p_lbr; |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1376 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1377 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1378 | /* The visual area is remembered for redo */ |
| 1379 | static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
| 1380 | static linenr_T redo_VIsual_line_count; /* number of lines */ |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1381 | static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1382 | static long redo_VIsual_count; /* count for Visual operator */ |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 1383 | static int redo_VIsual_arg; /* extra argument */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1384 | #ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1385 | int include_line_break = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1386 | #endif |
| 1387 | |
| 1388 | #if defined(FEAT_CLIPBOARD) |
| 1389 | /* |
| 1390 | * Yank the visual area into the GUI selection register before we operate |
| 1391 | * on it and lose it forever. |
| 1392 | * Don't do it if a specific register was specified, so that ""x"*P works. |
| 1393 | * This could call do_pending_operator() recursively, but that's OK |
| 1394 | * because gui_yank will be TRUE for the nested call. |
| 1395 | */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 1396 | if ((clip_star.available || clip_plus.available) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1397 | && oap->op_type != OP_NOP |
| 1398 | && !gui_yank |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1399 | && VIsual_active |
| 1400 | && !redo_VIsual_busy |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1401 | && oap->regname == 0) |
| 1402 | clip_auto_select(); |
| 1403 | #endif |
| 1404 | old_cursor = curwin->w_cursor; |
| 1405 | |
| 1406 | /* |
| 1407 | * If an operation is pending, handle it... |
| 1408 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1409 | if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1410 | { |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1411 | #ifdef FEAT_LINEBREAK |
| 1412 | /* Avoid a problem with unwanted linebreaks in block mode. */ |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 1413 | if (curwin->w_p_lbr) |
| 1414 | curwin->w_valid &= ~VALID_VIRTCOL; |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1415 | curwin->w_p_lbr = FALSE; |
| 1416 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1417 | oap->is_VIsual = VIsual_active; |
| 1418 | if (oap->motion_force == 'V') |
| 1419 | oap->motion_type = MLINE; |
| 1420 | else if (oap->motion_force == 'v') |
| 1421 | { |
| 1422 | /* If the motion was linewise, "inclusive" will not have been set. |
| 1423 | * Use "exclusive" to be consistent. Makes "dvj" work nice. */ |
| 1424 | if (oap->motion_type == MLINE) |
| 1425 | oap->inclusive = FALSE; |
| 1426 | /* If the motion already was characterwise, toggle "inclusive" */ |
| 1427 | else if (oap->motion_type == MCHAR) |
| 1428 | oap->inclusive = !oap->inclusive; |
| 1429 | oap->motion_type = MCHAR; |
| 1430 | } |
| 1431 | else if (oap->motion_force == Ctrl_V) |
| 1432 | { |
| 1433 | /* Change line- or characterwise motion into Visual block mode. */ |
| 1434 | VIsual_active = TRUE; |
| 1435 | VIsual = oap->start; |
| 1436 | VIsual_mode = Ctrl_V; |
| 1437 | VIsual_select = FALSE; |
| 1438 | VIsual_reselect = FALSE; |
| 1439 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1440 | |
Bram Moolenaar | 7afea82 | 2013-04-24 18:34:45 +0200 | [diff] [blame] | 1441 | /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
| 1442 | /* Never redo "zf" (define fold). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1443 | if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
Bram Moolenaar | 7afea82 | 2013-04-24 18:34:45 +0200 | [diff] [blame] | 1444 | && ((!VIsual_active || oap->motion_force) |
| 1445 | /* Also redo Operator-pending Visual mode mappings */ |
| 1446 | || (VIsual_active && cap->cmdchar == ':' |
| 1447 | && oap->op_type != OP_COLON)) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 1448 | && cap->cmdchar != 'D' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1449 | #ifdef FEAT_FOLDING |
| 1450 | && oap->op_type != OP_FOLD |
| 1451 | && oap->op_type != OP_FOLDOPEN |
| 1452 | && oap->op_type != OP_FOLDOPENREC |
| 1453 | && oap->op_type != OP_FOLDCLOSE |
| 1454 | && oap->op_type != OP_FOLDCLOSEREC |
| 1455 | && oap->op_type != OP_FOLDDEL |
| 1456 | && oap->op_type != OP_FOLDDELREC |
| 1457 | #endif |
| 1458 | ) |
| 1459 | { |
| 1460 | prep_redo(oap->regname, cap->count0, |
| 1461 | get_op_char(oap->op_type), get_extra_op_char(oap->op_type), |
| 1462 | oap->motion_force, cap->cmdchar, cap->nchar); |
| 1463 | if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ |
| 1464 | { |
| 1465 | /* |
| 1466 | * If 'cpoptions' does not contain 'r', insert the search |
| 1467 | * pattern to really repeat the same command. |
| 1468 | */ |
| 1469 | if (vim_strchr(p_cpo, CPO_REDO) == NULL) |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 1470 | AppendToRedobuffLit(cap->searchbuf, -1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1471 | AppendToRedobuff(NL_STR); |
| 1472 | } |
| 1473 | else if (cap->cmdchar == ':') |
| 1474 | { |
| 1475 | /* do_cmdline() has stored the first typed line in |
| 1476 | * "repeat_cmdline". When several lines are typed repeating |
| 1477 | * won't be possible. */ |
| 1478 | if (repeat_cmdline == NULL) |
| 1479 | ResetRedobuff(); |
| 1480 | else |
| 1481 | { |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 1482 | AppendToRedobuffLit(repeat_cmdline, -1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1483 | AppendToRedobuff(NL_STR); |
| 1484 | vim_free(repeat_cmdline); |
| 1485 | repeat_cmdline = NULL; |
| 1486 | } |
| 1487 | } |
| 1488 | } |
| 1489 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1490 | if (redo_VIsual_busy) |
| 1491 | { |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1492 | /* Redo of an operation on a Visual area. Use the same size from |
| 1493 | * redo_VIsual_line_count and redo_VIsual_vcol. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1494 | oap->start = curwin->w_cursor; |
| 1495 | curwin->w_cursor.lnum += redo_VIsual_line_count - 1; |
| 1496 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 1497 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 1498 | VIsual_mode = redo_VIsual_mode; |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1499 | if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1500 | { |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1501 | if (VIsual_mode == 'v') |
| 1502 | { |
| 1503 | if (redo_VIsual_line_count <= 1) |
| 1504 | { |
| 1505 | validate_virtcol(); |
| 1506 | curwin->w_curswant = |
| 1507 | curwin->w_virtcol + redo_VIsual_vcol - 1; |
| 1508 | } |
| 1509 | else |
| 1510 | curwin->w_curswant = redo_VIsual_vcol; |
| 1511 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1512 | else |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1513 | { |
| 1514 | curwin->w_curswant = MAXCOL; |
| 1515 | } |
| 1516 | coladvance(curwin->w_curswant); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1517 | } |
| 1518 | cap->count0 = redo_VIsual_count; |
| 1519 | if (redo_VIsual_count != 0) |
| 1520 | cap->count1 = redo_VIsual_count; |
| 1521 | else |
| 1522 | cap->count1 = 1; |
| 1523 | } |
| 1524 | else if (VIsual_active) |
| 1525 | { |
Bram Moolenaar | 6179c61 | 2006-10-10 11:26:53 +0000 | [diff] [blame] | 1526 | if (!gui_yank) |
| 1527 | { |
| 1528 | /* Save the current VIsual area for '< and '> marks, and "gv" */ |
| 1529 | curbuf->b_visual.vi_start = VIsual; |
| 1530 | curbuf->b_visual.vi_end = curwin->w_cursor; |
| 1531 | curbuf->b_visual.vi_mode = VIsual_mode; |
Bram Moolenaar | a390bb6 | 2013-03-13 19:02:41 +0100 | [diff] [blame] | 1532 | if (VIsual_mode_orig != NUL) |
| 1533 | { |
| 1534 | curbuf->b_visual.vi_mode = VIsual_mode_orig; |
| 1535 | VIsual_mode_orig = NUL; |
| 1536 | } |
Bram Moolenaar | 6179c61 | 2006-10-10 11:26:53 +0000 | [diff] [blame] | 1537 | curbuf->b_visual.vi_curswant = curwin->w_curswant; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1538 | # ifdef FEAT_EVAL |
Bram Moolenaar | 6179c61 | 2006-10-10 11:26:53 +0000 | [diff] [blame] | 1539 | curbuf->b_visual_mode_eval = VIsual_mode; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1540 | # endif |
Bram Moolenaar | 6179c61 | 2006-10-10 11:26:53 +0000 | [diff] [blame] | 1541 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1542 | |
| 1543 | /* In Select mode, a linewise selection is operated upon like a |
Bram Moolenaar | d009e86 | 2015-06-09 20:20:03 +0200 | [diff] [blame] | 1544 | * characterwise selection. |
| 1545 | * Special case: gH<Del> deletes the last line. */ |
| 1546 | if (VIsual_select && VIsual_mode == 'V' |
| 1547 | && cap->oap->op_type != OP_DELETE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1548 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1549 | if (LT_POS(VIsual, curwin->w_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1550 | { |
| 1551 | VIsual.col = 0; |
| 1552 | curwin->w_cursor.col = |
| 1553 | (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); |
| 1554 | } |
| 1555 | else |
| 1556 | { |
| 1557 | curwin->w_cursor.col = 0; |
| 1558 | VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); |
| 1559 | } |
| 1560 | VIsual_mode = 'v'; |
| 1561 | } |
| 1562 | /* If 'selection' is "exclusive", backup one character for |
| 1563 | * charwise selections. */ |
| 1564 | else if (VIsual_mode == 'v') |
| 1565 | { |
| 1566 | # ifdef FEAT_VIRTUALEDIT |
| 1567 | include_line_break = |
| 1568 | # endif |
| 1569 | unadjust_for_sel(); |
| 1570 | } |
| 1571 | |
| 1572 | oap->start = VIsual; |
| 1573 | if (VIsual_mode == 'V') |
Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 1574 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1575 | oap->start.col = 0; |
Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 1576 | # ifdef FEAT_VIRTUALEDIT |
| 1577 | oap->start.coladd = 0; |
| 1578 | # endif |
| 1579 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1580 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1581 | |
| 1582 | /* |
| 1583 | * Set oap->start to the first position of the operated text, oap->end |
| 1584 | * to the end of the operated text. w_cursor is equal to oap->start. |
| 1585 | */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1586 | if (LT_POS(oap->start, curwin->w_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1587 | { |
| 1588 | #ifdef FEAT_FOLDING |
| 1589 | /* Include folded lines completely. */ |
| 1590 | if (!VIsual_active) |
| 1591 | { |
| 1592 | if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) |
| 1593 | oap->start.col = 0; |
| 1594 | if (hasFolding(curwin->w_cursor.lnum, NULL, |
| 1595 | &curwin->w_cursor.lnum)) |
| 1596 | curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); |
| 1597 | } |
| 1598 | #endif |
| 1599 | oap->end = curwin->w_cursor; |
| 1600 | curwin->w_cursor = oap->start; |
| 1601 | |
| 1602 | /* w_virtcol may have been updated; if the cursor goes back to its |
| 1603 | * previous position w_virtcol becomes invalid and isn't updated |
| 1604 | * automatically. */ |
| 1605 | curwin->w_valid &= ~VALID_VIRTCOL; |
| 1606 | } |
| 1607 | else |
| 1608 | { |
| 1609 | #ifdef FEAT_FOLDING |
| 1610 | /* Include folded lines completely. */ |
| 1611 | if (!VIsual_active && oap->motion_type == MLINE) |
| 1612 | { |
| 1613 | if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, |
| 1614 | NULL)) |
| 1615 | curwin->w_cursor.col = 0; |
| 1616 | if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) |
| 1617 | oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); |
| 1618 | } |
| 1619 | #endif |
| 1620 | oap->end = oap->start; |
| 1621 | oap->start = curwin->w_cursor; |
| 1622 | } |
| 1623 | |
Bram Moolenaar | c4a908e | 2016-09-08 23:35:30 +0200 | [diff] [blame] | 1624 | /* Just in case lines were deleted that make the position invalid. */ |
| 1625 | check_pos(curwin->w_buffer, &oap->end); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1626 | oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
| 1627 | |
| 1628 | #ifdef FEAT_VIRTUALEDIT |
| 1629 | /* Set "virtual_op" before resetting VIsual_active. */ |
| 1630 | virtual_op = virtual_active(); |
| 1631 | #endif |
| 1632 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1633 | if (VIsual_active || redo_VIsual_busy) |
| 1634 | { |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 1635 | get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1636 | |
| 1637 | if (!redo_VIsual_busy && !gui_yank) |
| 1638 | { |
| 1639 | /* |
| 1640 | * Prepare to reselect and redo Visual: this is based on the |
| 1641 | * size of the Visual text |
| 1642 | */ |
| 1643 | resel_VIsual_mode = VIsual_mode; |
| 1644 | if (curwin->w_curswant == MAXCOL) |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1645 | resel_VIsual_vcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1646 | else |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1647 | { |
| 1648 | if (VIsual_mode != Ctrl_V) |
| 1649 | getvvcol(curwin, &(oap->end), |
| 1650 | NULL, NULL, &oap->end_vcol); |
| 1651 | if (VIsual_mode == Ctrl_V || oap->line_count <= 1) |
| 1652 | { |
| 1653 | if (VIsual_mode != Ctrl_V) |
| 1654 | getvvcol(curwin, &(oap->start), |
| 1655 | &oap->start_vcol, NULL, NULL); |
| 1656 | resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; |
| 1657 | } |
| 1658 | else |
| 1659 | resel_VIsual_vcol = oap->end_vcol; |
| 1660 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1661 | resel_VIsual_line_count = oap->line_count; |
| 1662 | } |
| 1663 | |
| 1664 | /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ |
| 1665 | if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
| 1666 | && oap->op_type != OP_COLON |
| 1667 | #ifdef FEAT_FOLDING |
| 1668 | && oap->op_type != OP_FOLD |
| 1669 | && oap->op_type != OP_FOLDOPEN |
| 1670 | && oap->op_type != OP_FOLDOPENREC |
| 1671 | && oap->op_type != OP_FOLDCLOSE |
| 1672 | && oap->op_type != OP_FOLDCLOSEREC |
| 1673 | && oap->op_type != OP_FOLDDEL |
| 1674 | && oap->op_type != OP_FOLDDELREC |
| 1675 | #endif |
| 1676 | && oap->motion_force == NUL |
| 1677 | ) |
| 1678 | { |
| 1679 | /* Prepare for redoing. Only use the nchar field for "r", |
| 1680 | * otherwise it might be the second char of the operator. */ |
Bram Moolenaar | 641e286 | 2012-07-25 15:06:34 +0200 | [diff] [blame] | 1681 | if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
| 1682 | || cap->nchar == 'N')) |
Bram Moolenaar | ba2d44f | 2013-11-28 19:27:30 +0100 | [diff] [blame] | 1683 | prep_redo(oap->regname, cap->count0, |
| 1684 | get_op_char(oap->op_type), get_extra_op_char(oap->op_type), |
| 1685 | oap->motion_force, cap->cmdchar, cap->nchar); |
Bram Moolenaar | 7afea82 | 2013-04-24 18:34:45 +0200 | [diff] [blame] | 1686 | else if (cap->cmdchar != ':') |
Bram Moolenaar | 641e286 | 2012-07-25 15:06:34 +0200 | [diff] [blame] | 1687 | prep_redo(oap->regname, 0L, NUL, 'v', |
| 1688 | get_op_char(oap->op_type), |
| 1689 | get_extra_op_char(oap->op_type), |
| 1690 | oap->op_type == OP_REPLACE |
| 1691 | ? cap->nchar : NUL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1692 | if (!redo_VIsual_busy) |
| 1693 | { |
| 1694 | redo_VIsual_mode = resel_VIsual_mode; |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 1695 | redo_VIsual_vcol = resel_VIsual_vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1696 | redo_VIsual_line_count = resel_VIsual_line_count; |
| 1697 | redo_VIsual_count = cap->count0; |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 1698 | redo_VIsual_arg = cap->arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | /* |
| 1703 | * oap->inclusive defaults to TRUE. |
| 1704 | * If oap->end is on a NUL (empty line) oap->inclusive becomes |
| 1705 | * FALSE. This makes "d}P" and "v}dP" work the same. |
| 1706 | */ |
| 1707 | if (oap->motion_force == NUL || oap->motion_type == MLINE) |
| 1708 | oap->inclusive = TRUE; |
| 1709 | if (VIsual_mode == 'V') |
| 1710 | oap->motion_type = MLINE; |
| 1711 | else |
| 1712 | { |
| 1713 | oap->motion_type = MCHAR; |
| 1714 | if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1715 | #ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1716 | && (include_line_break || !virtual_op) |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1717 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1718 | ) |
| 1719 | { |
| 1720 | oap->inclusive = FALSE; |
| 1721 | /* Try to include the newline, unless it's an operator |
Bram Moolenaar | 44286ca | 2011-07-15 17:51:34 +0200 | [diff] [blame] | 1722 | * that works on lines only. */ |
Bram Moolenaar | d009e86 | 2015-06-09 20:20:03 +0200 | [diff] [blame] | 1723 | if (*p_sel != 'o' |
| 1724 | && !op_on_lines(oap->op_type) |
| 1725 | && oap->end.lnum < curbuf->b_ml.ml_line_count) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1726 | { |
Bram Moolenaar | d009e86 | 2015-06-09 20:20:03 +0200 | [diff] [blame] | 1727 | ++oap->end.lnum; |
| 1728 | oap->end.col = 0; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1729 | #ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | d009e86 | 2015-06-09 20:20:03 +0200 | [diff] [blame] | 1730 | oap->end.coladd = 0; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1731 | #endif |
Bram Moolenaar | d009e86 | 2015-06-09 20:20:03 +0200 | [diff] [blame] | 1732 | ++oap->line_count; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | redo_VIsual_busy = FALSE; |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 1738 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1739 | /* |
| 1740 | * Switch Visual off now, so screen updating does |
| 1741 | * not show inverted text when the screen is redrawn. |
| 1742 | * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is |
| 1743 | * no screen redraw, so it is done here to remove the inverted |
| 1744 | * part. |
| 1745 | */ |
| 1746 | if (!gui_yank) |
| 1747 | { |
| 1748 | VIsual_active = FALSE; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1749 | #ifdef FEAT_MOUSE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1750 | setmouse(); |
| 1751 | mouse_dragging = 0; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1752 | #endif |
Bram Moolenaar | 0bbcb5c | 2015-08-04 19:18:52 +0200 | [diff] [blame] | 1753 | may_clear_cmdline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1754 | if ((oap->op_type == OP_YANK |
| 1755 | || oap->op_type == OP_COLON |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 1756 | || oap->op_type == OP_FUNCTION |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1757 | || oap->op_type == OP_FILTER) |
| 1758 | && oap->motion_force == NUL) |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1759 | { |
| 1760 | #ifdef FEAT_LINEBREAK |
| 1761 | /* make sure redrawing is correct */ |
| 1762 | curwin->w_p_lbr = lbr_saved; |
| 1763 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1764 | redraw_curbuf_later(INVERTED); |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1765 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1766 | } |
| 1767 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1768 | |
| 1769 | #ifdef FEAT_MBYTE |
| 1770 | /* Include the trailing byte of a multi-byte char. */ |
| 1771 | if (has_mbyte && oap->inclusive) |
| 1772 | { |
| 1773 | int l; |
| 1774 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 1775 | l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1776 | if (l > 1) |
| 1777 | oap->end.col += l - 1; |
| 1778 | } |
| 1779 | #endif |
| 1780 | curwin->w_set_curswant = TRUE; |
| 1781 | |
| 1782 | /* |
| 1783 | * oap->empty is set when start and end are the same. The inclusive |
| 1784 | * flag affects this too, unless yanking and the end is on a NUL. |
| 1785 | */ |
| 1786 | oap->empty = (oap->motion_type == MCHAR |
| 1787 | && (!oap->inclusive |
| 1788 | || (oap->op_type == OP_YANK |
| 1789 | && gchar_pos(&oap->end) == NUL)) |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1790 | && EQUAL_POS(oap->start, oap->end) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1791 | #ifdef FEAT_VIRTUALEDIT |
| 1792 | && !(virtual_op && oap->start.coladd != oap->end.coladd) |
| 1793 | #endif |
| 1794 | ); |
| 1795 | /* |
| 1796 | * For delete, change and yank, it's an error to operate on an |
| 1797 | * empty region, when 'E' included in 'cpoptions' (Vi compatible). |
| 1798 | */ |
| 1799 | empty_region_error = (oap->empty |
| 1800 | && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); |
| 1801 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1802 | /* Force a redraw when operating on an empty Visual region, when |
| 1803 | * 'modifiable is off or creating a fold. */ |
| 1804 | if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1805 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1806 | || oap->op_type == OP_FOLD |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1807 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1808 | )) |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1809 | { |
| 1810 | #ifdef FEAT_LINEBREAK |
| 1811 | curwin->w_p_lbr = lbr_saved; |
| 1812 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1813 | redraw_curbuf_later(INVERTED); |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1814 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1815 | |
| 1816 | /* |
| 1817 | * If the end of an operator is in column one while oap->motion_type |
| 1818 | * is MCHAR and oap->inclusive is FALSE, we put op_end after the last |
| 1819 | * character in the previous line. If op_start is on or before the |
| 1820 | * first non-blank in the line, the operator becomes linewise |
| 1821 | * (strange, but that's the way vi does it). |
| 1822 | */ |
| 1823 | if ( oap->motion_type == MCHAR |
| 1824 | && oap->inclusive == FALSE |
| 1825 | && !(cap->retval & CA_NO_ADJ_OP_END) |
| 1826 | && oap->end.col == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1827 | && (!oap->is_VIsual || *p_sel == 'o') |
Bram Moolenaar | 3411469 | 2005-01-02 11:28:13 +0000 | [diff] [blame] | 1828 | && !oap->block_mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1829 | && oap->line_count > 1) |
| 1830 | { |
| 1831 | oap->end_adjusted = TRUE; /* remember that we did this */ |
| 1832 | --oap->line_count; |
| 1833 | --oap->end.lnum; |
| 1834 | if (inindent(0)) |
| 1835 | oap->motion_type = MLINE; |
| 1836 | else |
| 1837 | { |
| 1838 | oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); |
| 1839 | if (oap->end.col) |
| 1840 | { |
| 1841 | --oap->end.col; |
| 1842 | oap->inclusive = TRUE; |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | else |
| 1847 | oap->end_adjusted = FALSE; |
| 1848 | |
| 1849 | switch (oap->op_type) |
| 1850 | { |
| 1851 | case OP_LSHIFT: |
| 1852 | case OP_RSHIFT: |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1853 | op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1854 | auto_format(FALSE, TRUE); |
| 1855 | break; |
| 1856 | |
| 1857 | case OP_JOIN_NS: |
| 1858 | case OP_JOIN: |
| 1859 | if (oap->line_count < 2) |
| 1860 | oap->line_count = 2; |
| 1861 | if (curwin->w_cursor.lnum + oap->line_count - 1 > |
| 1862 | curbuf->b_ml.ml_line_count) |
| 1863 | beep_flush(); |
| 1864 | else |
| 1865 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 1866 | (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
Bram Moolenaar | d69bd9a | 2014-04-29 12:15:40 +0200 | [diff] [blame] | 1867 | TRUE, TRUE, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1868 | auto_format(FALSE, TRUE); |
| 1869 | } |
| 1870 | break; |
| 1871 | |
| 1872 | case OP_DELETE: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1873 | VIsual_reselect = FALSE; /* don't reselect now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1874 | if (empty_region_error) |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1875 | { |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 1876 | vim_beep(BO_OPER); |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1877 | CancelRedo(); |
| 1878 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1879 | else |
| 1880 | { |
| 1881 | (void)op_delete(oap); |
| 1882 | if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) |
| 1883 | u_save_cursor(); /* cursor line wasn't saved yet */ |
| 1884 | auto_format(FALSE, TRUE); |
| 1885 | } |
| 1886 | break; |
| 1887 | |
| 1888 | case OP_YANK: |
| 1889 | if (empty_region_error) |
| 1890 | { |
| 1891 | if (!gui_yank) |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1892 | { |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 1893 | vim_beep(BO_OPER); |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1894 | CancelRedo(); |
| 1895 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1896 | } |
| 1897 | else |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1898 | { |
| 1899 | #ifdef FEAT_LINEBREAK |
| 1900 | curwin->w_p_lbr = lbr_saved; |
| 1901 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1902 | (void)op_yank(oap, FALSE, !gui_yank); |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1903 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1904 | check_cursor_col(); |
| 1905 | break; |
| 1906 | |
| 1907 | case OP_CHANGE: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1908 | VIsual_reselect = FALSE; /* don't reselect now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1909 | if (empty_region_error) |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1910 | { |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 1911 | vim_beep(BO_OPER); |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1912 | CancelRedo(); |
| 1913 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1914 | else |
| 1915 | { |
| 1916 | /* This is a new edit command, not a restart. Need to |
| 1917 | * remember it to make 'insertmode' work with mappings for |
| 1918 | * Visual mode. But do this only once and not when typed and |
| 1919 | * 'insertmode' isn't set. */ |
| 1920 | if (p_im || !KeyTyped) |
| 1921 | restart_edit_save = restart_edit; |
| 1922 | else |
| 1923 | restart_edit_save = 0; |
| 1924 | restart_edit = 0; |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1925 | #ifdef FEAT_LINEBREAK |
| 1926 | /* Restore linebreak, so that when the user edits it looks as |
| 1927 | * before. */ |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 1928 | if (curwin->w_p_lbr != lbr_saved) |
| 1929 | { |
| 1930 | curwin->w_p_lbr = lbr_saved; |
| 1931 | get_op_vcol(oap, redo_VIsual_mode, FALSE); |
| 1932 | } |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 1933 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1934 | /* Reset finish_op now, don't want it set inside edit(). */ |
| 1935 | finish_op = FALSE; |
| 1936 | if (op_change(oap)) /* will call edit() */ |
| 1937 | cap->retval |= CA_COMMAND_BUSY; |
| 1938 | if (restart_edit == 0) |
| 1939 | restart_edit = restart_edit_save; |
| 1940 | } |
| 1941 | break; |
| 1942 | |
| 1943 | case OP_FILTER: |
| 1944 | if (vim_strchr(p_cpo, CPO_FILTER) != NULL) |
| 1945 | AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ |
| 1946 | else |
| 1947 | bangredo = TRUE; /* do_bang() will put cmd in redo buffer */ |
| 1948 | |
| 1949 | case OP_INDENT: |
| 1950 | case OP_COLON: |
| 1951 | |
| 1952 | #if defined(FEAT_LISP) || defined(FEAT_CINDENT) |
| 1953 | /* |
| 1954 | * If 'equalprg' is empty, do the indenting internally. |
| 1955 | */ |
| 1956 | if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) |
| 1957 | { |
| 1958 | # ifdef FEAT_LISP |
| 1959 | if (curbuf->b_p_lisp) |
| 1960 | { |
| 1961 | op_reindent(oap, get_lisp_indent); |
| 1962 | break; |
| 1963 | } |
| 1964 | # endif |
| 1965 | # ifdef FEAT_CINDENT |
| 1966 | op_reindent(oap, |
| 1967 | # ifdef FEAT_EVAL |
| 1968 | *curbuf->b_p_inde != NUL ? get_expr_indent : |
| 1969 | # endif |
| 1970 | get_c_indent); |
| 1971 | break; |
| 1972 | # endif |
| 1973 | } |
| 1974 | #endif |
| 1975 | |
| 1976 | op_colon(oap); |
| 1977 | break; |
| 1978 | |
| 1979 | case OP_TILDE: |
| 1980 | case OP_UPPER: |
| 1981 | case OP_LOWER: |
| 1982 | case OP_ROT13: |
| 1983 | if (empty_region_error) |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1984 | { |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 1985 | vim_beep(BO_OPER); |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 1986 | CancelRedo(); |
| 1987 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1988 | else |
| 1989 | op_tilde(oap); |
| 1990 | check_cursor_col(); |
| 1991 | break; |
| 1992 | |
| 1993 | case OP_FORMAT: |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 1994 | #if defined(FEAT_EVAL) |
| 1995 | if (*curbuf->b_p_fex != NUL) |
| 1996 | op_formatexpr(oap); /* use expression */ |
| 1997 | else |
| 1998 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 1999 | if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2000 | op_colon(oap); /* use external command */ |
| 2001 | else |
| 2002 | op_format(oap, FALSE); /* use internal function */ |
| 2003 | break; |
| 2004 | |
| 2005 | case OP_FORMAT2: |
| 2006 | op_format(oap, TRUE); /* use internal function */ |
| 2007 | break; |
| 2008 | |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2009 | case OP_FUNCTION: |
Bram Moolenaar | 4a08b0d | 2016-11-05 21:55:13 +0100 | [diff] [blame] | 2010 | #ifdef FEAT_LINEBREAK |
| 2011 | /* Restore linebreak, so that when the user edits it looks as |
| 2012 | * before. */ |
| 2013 | curwin->w_p_lbr = lbr_saved; |
| 2014 | #endif |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2015 | op_function(oap); /* call 'operatorfunc' */ |
| 2016 | break; |
| 2017 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2018 | case OP_INSERT: |
| 2019 | case OP_APPEND: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2020 | VIsual_reselect = FALSE; /* don't reselect now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2021 | #ifdef FEAT_VISUALEXTRA |
| 2022 | if (empty_region_error) |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 2023 | { |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 2024 | vim_beep(BO_OPER); |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 2025 | CancelRedo(); |
| 2026 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2027 | else |
| 2028 | { |
| 2029 | /* This is a new edit command, not a restart. Need to |
| 2030 | * remember it to make 'insertmode' work with mappings for |
| 2031 | * Visual mode. But do this only once. */ |
| 2032 | restart_edit_save = restart_edit; |
| 2033 | restart_edit = 0; |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2034 | #ifdef FEAT_LINEBREAK |
| 2035 | /* Restore linebreak, so that when the user edits it looks as |
| 2036 | * before. */ |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 2037 | if (curwin->w_p_lbr != lbr_saved) |
| 2038 | { |
| 2039 | curwin->w_p_lbr = lbr_saved; |
| 2040 | get_op_vcol(oap, redo_VIsual_mode, FALSE); |
| 2041 | } |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2042 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2043 | op_insert(oap, cap->count1); |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2044 | #ifdef FEAT_LINEBREAK |
| 2045 | /* Reset linebreak, so that formatting works correctly. */ |
| 2046 | curwin->w_p_lbr = FALSE; |
| 2047 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2048 | |
| 2049 | /* TODO: when inserting in several lines, should format all |
| 2050 | * the lines. */ |
| 2051 | auto_format(FALSE, TRUE); |
| 2052 | |
| 2053 | if (restart_edit == 0) |
| 2054 | restart_edit = restart_edit_save; |
Bram Moolenaar | 0b5c93a | 2017-02-01 15:03:30 +0100 | [diff] [blame] | 2055 | else |
| 2056 | cap->retval |= CA_COMMAND_BUSY; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2057 | } |
| 2058 | #else |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 2059 | vim_beep(BO_OPER); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2060 | #endif |
| 2061 | break; |
| 2062 | |
| 2063 | case OP_REPLACE: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2064 | VIsual_reselect = FALSE; /* don't reselect now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2065 | #ifdef FEAT_VISUALEXTRA |
| 2066 | if (empty_region_error) |
| 2067 | #endif |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 2068 | { |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 2069 | vim_beep(BO_OPER); |
Bram Moolenaar | be094a1 | 2012-02-05 01:18:48 +0100 | [diff] [blame] | 2070 | CancelRedo(); |
| 2071 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2072 | #ifdef FEAT_VISUALEXTRA |
| 2073 | else |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2074 | { |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 2075 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2076 | /* Restore linebreak, so that when the user edits it looks as |
| 2077 | * before. */ |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 2078 | if (curwin->w_p_lbr != lbr_saved) |
| 2079 | { |
| 2080 | curwin->w_p_lbr = lbr_saved; |
| 2081 | get_op_vcol(oap, redo_VIsual_mode, FALSE); |
| 2082 | } |
| 2083 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2084 | op_replace(oap, cap->nchar); |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2085 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2086 | #endif |
| 2087 | break; |
| 2088 | |
| 2089 | #ifdef FEAT_FOLDING |
| 2090 | case OP_FOLD: |
| 2091 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 2092 | foldCreate(oap->start.lnum, oap->end.lnum); |
| 2093 | break; |
| 2094 | |
| 2095 | case OP_FOLDOPEN: |
| 2096 | case OP_FOLDOPENREC: |
| 2097 | case OP_FOLDCLOSE: |
| 2098 | case OP_FOLDCLOSEREC: |
| 2099 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 2100 | opFoldRange(oap->start.lnum, oap->end.lnum, |
| 2101 | oap->op_type == OP_FOLDOPEN |
| 2102 | || oap->op_type == OP_FOLDOPENREC, |
| 2103 | oap->op_type == OP_FOLDOPENREC |
| 2104 | || oap->op_type == OP_FOLDCLOSEREC, |
| 2105 | oap->is_VIsual); |
| 2106 | break; |
| 2107 | |
| 2108 | case OP_FOLDDEL: |
| 2109 | case OP_FOLDDELREC: |
| 2110 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 2111 | deleteFold(oap->start.lnum, oap->end.lnum, |
| 2112 | oap->op_type == OP_FOLDDELREC, oap->is_VIsual); |
| 2113 | break; |
| 2114 | #endif |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 2115 | case OP_NR_ADD: |
| 2116 | case OP_NR_SUB: |
| 2117 | if (empty_region_error) |
| 2118 | { |
| 2119 | vim_beep(BO_OPER); |
| 2120 | CancelRedo(); |
| 2121 | } |
| 2122 | else |
| 2123 | { |
| 2124 | VIsual_active = TRUE; |
| 2125 | #ifdef FEAT_LINEBREAK |
| 2126 | curwin->w_p_lbr = lbr_saved; |
| 2127 | #endif |
| 2128 | op_addsub(oap, cap->count1, redo_VIsual_arg); |
| 2129 | VIsual_active = FALSE; |
| 2130 | } |
| 2131 | check_cursor_col(); |
| 2132 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2133 | default: |
| 2134 | clearopbeep(oap); |
| 2135 | } |
| 2136 | #ifdef FEAT_VIRTUALEDIT |
| 2137 | virtual_op = MAYBE; |
| 2138 | #endif |
| 2139 | if (!gui_yank) |
| 2140 | { |
| 2141 | /* |
| 2142 | * if 'sol' not set, go back to old column for some commands |
| 2143 | */ |
| 2144 | if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted |
| 2145 | && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT |
| 2146 | || oap->op_type == OP_DELETE)) |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2147 | { |
| 2148 | #ifdef FEAT_LINEBREAK |
| 2149 | curwin->w_p_lbr = FALSE; |
| 2150 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2151 | coladvance(curwin->w_curswant = old_col); |
Bram Moolenaar | ba3f58e | 2015-01-14 17:52:30 +0100 | [diff] [blame] | 2152 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2153 | } |
| 2154 | else |
| 2155 | { |
| 2156 | curwin->w_cursor = old_cursor; |
| 2157 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2158 | oap->block_mode = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2159 | clearop(oap); |
| 2160 | } |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 2161 | #ifdef FEAT_LINEBREAK |
| 2162 | curwin->w_p_lbr = lbr_saved; |
| 2163 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | /* |
| 2167 | * Handle indent and format operators and visual mode ":". |
| 2168 | */ |
| 2169 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2170 | op_colon(oparg_T *oap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2171 | { |
| 2172 | stuffcharReadbuff(':'); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2173 | if (oap->is_VIsual) |
| 2174 | stuffReadbuff((char_u *)"'<,'>"); |
| 2175 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2176 | { |
| 2177 | /* |
| 2178 | * Make the range look nice, so it can be repeated. |
| 2179 | */ |
| 2180 | if (oap->start.lnum == curwin->w_cursor.lnum) |
| 2181 | stuffcharReadbuff('.'); |
| 2182 | else |
| 2183 | stuffnumReadbuff((long)oap->start.lnum); |
| 2184 | if (oap->end.lnum != oap->start.lnum) |
| 2185 | { |
| 2186 | stuffcharReadbuff(','); |
| 2187 | if (oap->end.lnum == curwin->w_cursor.lnum) |
| 2188 | stuffcharReadbuff('.'); |
| 2189 | else if (oap->end.lnum == curbuf->b_ml.ml_line_count) |
| 2190 | stuffcharReadbuff('$'); |
| 2191 | else if (oap->start.lnum == curwin->w_cursor.lnum) |
| 2192 | { |
| 2193 | stuffReadbuff((char_u *)".+"); |
| 2194 | stuffnumReadbuff((long)oap->line_count - 1); |
| 2195 | } |
| 2196 | else |
| 2197 | stuffnumReadbuff((long)oap->end.lnum); |
| 2198 | } |
| 2199 | } |
| 2200 | if (oap->op_type != OP_COLON) |
| 2201 | stuffReadbuff((char_u *)"!"); |
| 2202 | if (oap->op_type == OP_INDENT) |
| 2203 | { |
| 2204 | #ifndef FEAT_CINDENT |
| 2205 | if (*get_equalprg() == NUL) |
| 2206 | stuffReadbuff((char_u *)"indent"); |
| 2207 | else |
| 2208 | #endif |
| 2209 | stuffReadbuff(get_equalprg()); |
| 2210 | stuffReadbuff((char_u *)"\n"); |
| 2211 | } |
| 2212 | else if (oap->op_type == OP_FORMAT) |
| 2213 | { |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 2214 | if (*curbuf->b_p_fp != NUL) |
| 2215 | stuffReadbuff(curbuf->b_p_fp); |
| 2216 | else if (*p_fp != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2217 | stuffReadbuff(p_fp); |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 2218 | else |
| 2219 | stuffReadbuff((char_u *)"fmt"); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2220 | stuffReadbuff((char_u *)"\n']"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | /* |
| 2224 | * do_cmdline() does the rest |
| 2225 | */ |
| 2226 | } |
| 2227 | |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2228 | /* |
Bram Moolenaar | 12033fb | 2005-12-16 21:49:31 +0000 | [diff] [blame] | 2229 | * Handle the "g@" operator: call 'operatorfunc'. |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2230 | */ |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 2231 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2232 | op_function(oparg_T *oap UNUSED) |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2233 | { |
| 2234 | #ifdef FEAT_EVAL |
| 2235 | char_u *(argv[1]); |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 2236 | # ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 61d281a | 2012-03-28 12:59:57 +0200 | [diff] [blame] | 2237 | int save_virtual_op = virtual_op; |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 2238 | # endif |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2239 | |
| 2240 | if (*p_opfunc == NUL) |
| 2241 | EMSG(_("E774: 'operatorfunc' is empty")); |
| 2242 | else |
| 2243 | { |
| 2244 | /* Set '[ and '] marks to text to be operated on. */ |
| 2245 | curbuf->b_op_start = oap->start; |
| 2246 | curbuf->b_op_end = oap->end; |
| 2247 | if (oap->motion_type != MLINE && !oap->inclusive) |
| 2248 | /* Exclude the end position. */ |
| 2249 | decl(&curbuf->b_op_end); |
| 2250 | |
| 2251 | if (oap->block_mode) |
| 2252 | argv[0] = (char_u *)"block"; |
| 2253 | else if (oap->motion_type == MLINE) |
| 2254 | argv[0] = (char_u *)"line"; |
| 2255 | else |
| 2256 | argv[0] = (char_u *)"char"; |
Bram Moolenaar | 61d281a | 2012-03-28 12:59:57 +0200 | [diff] [blame] | 2257 | |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 2258 | # ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 61d281a | 2012-03-28 12:59:57 +0200 | [diff] [blame] | 2259 | /* Reset virtual_op so that 'virtualedit' can be changed in the |
| 2260 | * function. */ |
| 2261 | virtual_op = MAYBE; |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 2262 | # endif |
Bram Moolenaar | 61d281a | 2012-03-28 12:59:57 +0200 | [diff] [blame] | 2263 | |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2264 | (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
Bram Moolenaar | 61d281a | 2012-03-28 12:59:57 +0200 | [diff] [blame] | 2265 | |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 2266 | # ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 61d281a | 2012-03-28 12:59:57 +0200 | [diff] [blame] | 2267 | virtual_op = save_virtual_op; |
Bram Moolenaar | b2c5a5a | 2013-02-14 22:11:39 +0100 | [diff] [blame] | 2268 | # endif |
Bram Moolenaar | 5b962cf | 2005-12-12 21:58:40 +0000 | [diff] [blame] | 2269 | } |
| 2270 | #else |
| 2271 | EMSG(_("E775: Eval feature not available")); |
| 2272 | #endif |
| 2273 | } |
| 2274 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2275 | #if defined(FEAT_MOUSE) || defined(PROTO) |
| 2276 | /* |
| 2277 | * Do the appropriate action for the current mouse click in the current mode. |
| 2278 | * Not used for Command-line mode. |
| 2279 | * |
| 2280 | * Normal Mode: |
| 2281 | * event modi- position visual change action |
| 2282 | * fier cursor window |
| 2283 | * left press - yes end yes |
| 2284 | * left press C yes end yes "^]" (2) |
| 2285 | * left press S yes end yes "*" (2) |
| 2286 | * left drag - yes start if moved no |
| 2287 | * left relse - yes start if moved no |
| 2288 | * middle press - yes if not active no put register |
| 2289 | * middle press - yes if active no yank and put |
| 2290 | * right press - yes start or extend yes |
| 2291 | * right press S yes no change yes "#" (2) |
| 2292 | * right drag - yes extend no |
| 2293 | * right relse - yes extend no |
| 2294 | * |
| 2295 | * Insert or Replace Mode: |
| 2296 | * event modi- position visual change action |
| 2297 | * fier cursor window |
| 2298 | * left press - yes (cannot be active) yes |
| 2299 | * left press C yes (cannot be active) yes "CTRL-O^]" (2) |
| 2300 | * left press S yes (cannot be active) yes "CTRL-O*" (2) |
| 2301 | * left drag - yes start or extend (1) no CTRL-O (1) |
| 2302 | * left relse - yes start or extend (1) no CTRL-O (1) |
| 2303 | * middle press - no (cannot be active) no put register |
| 2304 | * right press - yes start or extend yes CTRL-O |
| 2305 | * right press S yes (cannot be active) yes "CTRL-O#" (2) |
| 2306 | * |
| 2307 | * (1) only if mouse pointer moved since press |
| 2308 | * (2) only if click is in same buffer |
| 2309 | * |
| 2310 | * Return TRUE if start_arrow() should be called for edit mode. |
| 2311 | */ |
| 2312 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2313 | do_mouse( |
| 2314 | oparg_T *oap, /* operator argument, can be NULL */ |
| 2315 | int c, /* K_LEFTMOUSE, etc */ |
| 2316 | int dir, /* Direction to 'put' if necessary */ |
| 2317 | long count, |
| 2318 | int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2319 | { |
| 2320 | static int do_always = FALSE; /* ignore 'mouse' setting next time */ |
| 2321 | static int got_click = FALSE; /* got a click some time back */ |
| 2322 | |
| 2323 | int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ |
| 2324 | int is_click; /* If FALSE it's a drag or release event */ |
| 2325 | int is_drag; /* If TRUE it's a drag event */ |
| 2326 | int jump_flags = 0; /* flags for jump_to_mouse() */ |
| 2327 | pos_T start_visual; |
| 2328 | int moved; /* Has cursor moved? */ |
| 2329 | int in_status_line; /* mouse in status line */ |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2330 | static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2331 | int in_sep_line; /* mouse in vertical separator line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2332 | int c1, c2; |
| 2333 | #if defined(FEAT_FOLDING) |
| 2334 | pos_T save_cursor; |
| 2335 | #endif |
| 2336 | win_T *old_curwin = curwin; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2337 | static pos_T orig_cursor; |
| 2338 | colnr_T leftcol, rightcol; |
| 2339 | pos_T end_visual; |
| 2340 | int diff; |
| 2341 | int old_active = VIsual_active; |
| 2342 | int old_mode = VIsual_mode; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2343 | int regname; |
| 2344 | |
| 2345 | #if defined(FEAT_FOLDING) |
| 2346 | save_cursor = curwin->w_cursor; |
| 2347 | #endif |
| 2348 | |
| 2349 | /* |
| 2350 | * When GUI is active, always recognize mouse events, otherwise: |
| 2351 | * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. |
| 2352 | * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. |
| 2353 | * - For command line and insert mode 'mouse' is checked before calling |
| 2354 | * do_mouse(). |
| 2355 | */ |
| 2356 | if (do_always) |
| 2357 | do_always = FALSE; |
| 2358 | else |
| 2359 | #ifdef FEAT_GUI |
| 2360 | if (!gui.in_use) |
| 2361 | #endif |
| 2362 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2363 | if (VIsual_active) |
| 2364 | { |
| 2365 | if (!mouse_has(MOUSE_VISUAL)) |
| 2366 | return FALSE; |
| 2367 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 2368 | else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2369 | return FALSE; |
| 2370 | } |
| 2371 | |
Bram Moolenaar | 2526ef2 | 2013-03-16 14:20:51 +0100 | [diff] [blame] | 2372 | for (;;) |
| 2373 | { |
| 2374 | which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); |
| 2375 | if (is_drag) |
| 2376 | { |
| 2377 | /* If the next character is the same mouse event then use that |
| 2378 | * one. Speeds up dragging the status line. */ |
| 2379 | if (vpeekc() != NUL) |
| 2380 | { |
| 2381 | int nc; |
| 2382 | int save_mouse_row = mouse_row; |
| 2383 | int save_mouse_col = mouse_col; |
| 2384 | |
| 2385 | /* Need to get the character, peeking doesn't get the actual |
| 2386 | * one. */ |
| 2387 | nc = safe_vgetc(); |
| 2388 | if (c == nc) |
| 2389 | continue; |
| 2390 | vungetc(nc); |
| 2391 | mouse_row = save_mouse_row; |
| 2392 | mouse_col = save_mouse_col; |
| 2393 | } |
| 2394 | } |
| 2395 | break; |
| 2396 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2397 | |
| 2398 | #ifdef FEAT_MOUSESHAPE |
| 2399 | /* May have stopped dragging the status or separator line. The pointer is |
| 2400 | * most likely still on the status or separator line. */ |
| 2401 | if (!is_drag && drag_status_line) |
| 2402 | { |
| 2403 | drag_status_line = FALSE; |
| 2404 | update_mouseshape(SHAPE_IDX_STATUS); |
| 2405 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2406 | if (!is_drag && drag_sep_line) |
| 2407 | { |
| 2408 | drag_sep_line = FALSE; |
| 2409 | update_mouseshape(SHAPE_IDX_VSEP); |
| 2410 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2411 | #endif |
| 2412 | |
| 2413 | /* |
| 2414 | * Ignore drag and release events if we didn't get a click. |
| 2415 | */ |
| 2416 | if (is_click) |
| 2417 | got_click = TRUE; |
| 2418 | else |
| 2419 | { |
| 2420 | if (!got_click) /* didn't get click, ignore */ |
| 2421 | return FALSE; |
| 2422 | if (!is_drag) /* release, reset got_click */ |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2423 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2424 | got_click = FALSE; |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2425 | if (in_tab_line) |
| 2426 | { |
| 2427 | in_tab_line = FALSE; |
| 2428 | return FALSE; |
| 2429 | } |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2430 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2433 | /* |
| 2434 | * CTRL right mouse button does CTRL-T |
| 2435 | */ |
| 2436 | if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) |
| 2437 | { |
| 2438 | if (State & INSERT) |
| 2439 | stuffcharReadbuff(Ctrl_O); |
| 2440 | if (count > 1) |
| 2441 | stuffnumReadbuff(count); |
| 2442 | stuffcharReadbuff(Ctrl_T); |
| 2443 | got_click = FALSE; /* ignore drag&release now */ |
| 2444 | return FALSE; |
| 2445 | } |
| 2446 | |
| 2447 | /* |
| 2448 | * CTRL only works with left mouse button |
| 2449 | */ |
| 2450 | if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) |
| 2451 | return FALSE; |
| 2452 | |
| 2453 | /* |
| 2454 | * When a modifier is down, ignore drag and release events, as well as |
| 2455 | * multiple clicks and the middle mouse button. |
| 2456 | * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". |
| 2457 | */ |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2458 | if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
| 2459 | | MOD_MASK_META)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2460 | && (!is_click |
| 2461 | || (mod_mask & MOD_MASK_MULTI_CLICK) |
| 2462 | || which_button == MOUSE_MIDDLE) |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 2463 | && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2464 | && mouse_model_popup() |
| 2465 | && which_button == MOUSE_LEFT) |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 2466 | && !((mod_mask & MOD_MASK_ALT) |
| 2467 | && !mouse_model_popup() |
| 2468 | && which_button == MOUSE_RIGHT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2469 | ) |
| 2470 | return FALSE; |
| 2471 | |
| 2472 | /* |
| 2473 | * If the button press was used as the movement command for an operator |
| 2474 | * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore |
| 2475 | * drag/release events. |
| 2476 | */ |
| 2477 | if (!is_click && which_button == MOUSE_MIDDLE) |
| 2478 | return FALSE; |
| 2479 | |
| 2480 | if (oap != NULL) |
| 2481 | regname = oap->regname; |
| 2482 | else |
| 2483 | regname = 0; |
| 2484 | |
| 2485 | /* |
| 2486 | * Middle mouse button does a 'put' of the selected text |
| 2487 | */ |
| 2488 | if (which_button == MOUSE_MIDDLE) |
| 2489 | { |
| 2490 | if (State == NORMAL) |
| 2491 | { |
| 2492 | /* |
| 2493 | * If an operator was pending, we don't know what the user wanted |
| 2494 | * to do. Go back to normal mode: Clear the operator and beep(). |
| 2495 | */ |
| 2496 | if (oap != NULL && oap->op_type != OP_NOP) |
| 2497 | { |
| 2498 | clearopbeep(oap); |
| 2499 | return FALSE; |
| 2500 | } |
| 2501 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2502 | /* |
| 2503 | * If visual was active, yank the highlighted text and put it |
| 2504 | * before the mouse pointer position. |
Bram Moolenaar | a350f4a | 2006-10-17 14:54:03 +0000 | [diff] [blame] | 2505 | * In Select mode replace the highlighted text with the clipboard. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2506 | */ |
| 2507 | if (VIsual_active) |
| 2508 | { |
Bram Moolenaar | a350f4a | 2006-10-17 14:54:03 +0000 | [diff] [blame] | 2509 | if (VIsual_select) |
| 2510 | { |
| 2511 | stuffcharReadbuff(Ctrl_G); |
Bram Moolenaar | 2d8b2d8 | 2006-10-17 20:38:28 +0000 | [diff] [blame] | 2512 | stuffReadbuff((char_u *)"\"+p"); |
Bram Moolenaar | a350f4a | 2006-10-17 14:54:03 +0000 | [diff] [blame] | 2513 | } |
| 2514 | else |
| 2515 | { |
| 2516 | stuffcharReadbuff('y'); |
| 2517 | stuffcharReadbuff(K_MIDDLEMOUSE); |
| 2518 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2519 | do_always = TRUE; /* ignore 'mouse' setting next time */ |
| 2520 | return FALSE; |
| 2521 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2522 | /* |
| 2523 | * The rest is below jump_to_mouse() |
| 2524 | */ |
| 2525 | } |
| 2526 | |
| 2527 | else if ((State & INSERT) == 0) |
| 2528 | return FALSE; |
| 2529 | |
| 2530 | /* |
| 2531 | * Middle click in insert mode doesn't move the mouse, just insert the |
| 2532 | * contents of a register. '.' register is special, can't insert that |
| 2533 | * with do_put(). |
| 2534 | * Also paste at the cursor if the current mode isn't in 'mouse' (only |
| 2535 | * happens for the GUI). |
| 2536 | */ |
| 2537 | if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) |
| 2538 | { |
| 2539 | if (regname == '.') |
| 2540 | insert_reg(regname, TRUE); |
| 2541 | else |
| 2542 | { |
| 2543 | #ifdef FEAT_CLIPBOARD |
| 2544 | if (clip_star.available && regname == 0) |
| 2545 | regname = '*'; |
| 2546 | #endif |
| 2547 | if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) |
| 2548 | insert_reg(regname, TRUE); |
| 2549 | else |
| 2550 | { |
| 2551 | do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); |
| 2552 | |
| 2553 | /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ |
| 2554 | AppendCharToRedobuff(Ctrl_R); |
| 2555 | AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); |
| 2556 | AppendCharToRedobuff(regname == 0 ? '"' : regname); |
| 2557 | } |
| 2558 | } |
| 2559 | return FALSE; |
| 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | /* When dragging or button-up stay in the same window. */ |
| 2564 | if (!is_click) |
| 2565 | jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; |
| 2566 | |
| 2567 | start_visual.lnum = 0; |
| 2568 | |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 2569 | /* Check for clicking in the tab page line. */ |
| 2570 | if (mouse_row == 0 && firstwin->w_winrow > 0) |
| 2571 | { |
Bram Moolenaar | a7241f5 | 2008-06-24 20:39:31 +0000 | [diff] [blame] | 2572 | if (is_drag) |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2573 | { |
| 2574 | if (in_tab_line) |
| 2575 | { |
| 2576 | c1 = TabPageIdxs[mouse_col]; |
Bram Moolenaar | 4a4b821 | 2015-09-08 17:50:41 +0200 | [diff] [blame] | 2577 | tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab) |
| 2578 | ? c1 - 1 : c1); |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2579 | } |
Bram Moolenaar | a7241f5 | 2008-06-24 20:39:31 +0000 | [diff] [blame] | 2580 | return FALSE; |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2581 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 2582 | |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 2583 | /* click in a tab selects that tab page */ |
| 2584 | if (is_click |
| 2585 | # ifdef FEAT_CMDWIN |
| 2586 | && cmdwin_type == 0 |
| 2587 | # endif |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2588 | && mouse_col < Columns) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 2589 | { |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2590 | in_tab_line = TRUE; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2591 | c1 = TabPageIdxs[mouse_col]; |
| 2592 | if (c1 >= 0) |
| 2593 | { |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 2594 | if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
| 2595 | { |
| 2596 | /* double click opens new page */ |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2597 | end_visual_mode(); |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 2598 | tabpage_new(); |
| 2599 | tabpage_move(c1 == 0 ? 9999 : c1 - 1); |
| 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | /* Go to specified tab page, or next one if not clicking |
| 2604 | * on a label. */ |
| 2605 | goto_tabpage(c1); |
| 2606 | |
| 2607 | /* It's like clicking on the status line of a window. */ |
| 2608 | if (curwin != old_curwin) |
| 2609 | end_visual_mode(); |
| 2610 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2611 | } |
| 2612 | else if (c1 < 0) |
| 2613 | { |
| 2614 | tabpage_T *tp; |
| 2615 | |
| 2616 | /* Close the current or specified tab page. */ |
| 2617 | if (c1 == -999) |
| 2618 | tp = curtab; |
| 2619 | else |
| 2620 | tp = find_tabpage(-c1); |
| 2621 | if (tp == curtab) |
| 2622 | { |
| 2623 | if (first_tabpage->tp_next != NULL) |
| 2624 | tabpage_close(FALSE); |
| 2625 | } |
| 2626 | else if (tp != NULL) |
| 2627 | tabpage_close_other(tp, FALSE); |
| 2628 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 2629 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2630 | return TRUE; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 2631 | } |
Bram Moolenaar | 58f0a1f | 2010-07-17 16:30:42 +0200 | [diff] [blame] | 2632 | else if (is_drag && in_tab_line) |
| 2633 | { |
| 2634 | c1 = TabPageIdxs[mouse_col]; |
| 2635 | tabpage_move(c1 <= 0 ? 9999 : c1 - 1); |
| 2636 | return FALSE; |
| 2637 | } |
| 2638 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2639 | /* |
| 2640 | * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: |
| 2641 | * right button up -> pop-up menu |
| 2642 | * shift-left button -> right button |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 2643 | * alt-left button -> alt-right button |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2644 | */ |
| 2645 | if (mouse_model_popup()) |
| 2646 | { |
| 2647 | if (which_button == MOUSE_RIGHT |
| 2648 | && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) |
| 2649 | { |
| 2650 | /* |
| 2651 | * NOTE: Ignore right button down and drag mouse events. |
| 2652 | * Windows only shows the popup menu on the button up event. |
| 2653 | */ |
Bram Moolenaar | 968bbbe | 2006-08-16 19:41:08 +0000 | [diff] [blame] | 2654 | #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
| 2655 | || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2656 | if (!is_click) |
| 2657 | return FALSE; |
| 2658 | #endif |
| 2659 | #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) |
| 2660 | if (is_click || is_drag) |
| 2661 | return FALSE; |
| 2662 | #endif |
Bram Moolenaar | cef9dcc | 2005-12-06 19:50:41 +0000 | [diff] [blame] | 2663 | #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2664 | || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
| 2665 | || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) |
| 2666 | if (gui.in_use) |
| 2667 | { |
| 2668 | jump_flags = 0; |
| 2669 | if (STRCMP(p_mousem, "popup_setpos") == 0) |
| 2670 | { |
| 2671 | /* First set the cursor position before showing the popup |
| 2672 | * menu. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2673 | if (VIsual_active) |
| 2674 | { |
| 2675 | pos_T m_pos; |
| 2676 | |
| 2677 | /* |
| 2678 | * set MOUSE_MAY_STOP_VIS if we are outside the |
| 2679 | * selection or the current window (might have false |
| 2680 | * negative here) |
| 2681 | */ |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 2682 | if (mouse_row < curwin->w_winrow |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2683 | || mouse_row |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 2684 | > (curwin->w_winrow + curwin->w_height)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2685 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2686 | else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER) |
| 2687 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2688 | else |
| 2689 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 2690 | if ((LT_POS(curwin->w_cursor, VIsual) |
| 2691 | && (LT_POS(m_pos, curwin->w_cursor) |
| 2692 | || LT_POS(VIsual, m_pos))) |
| 2693 | || (LT_POS(VIsual, curwin->w_cursor) |
| 2694 | && (LT_POS(m_pos, VIsual) |
| 2695 | || LT_POS(curwin->w_cursor, m_pos)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2696 | { |
| 2697 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2698 | } |
| 2699 | else if (VIsual_mode == Ctrl_V) |
| 2700 | { |
| 2701 | getvcols(curwin, &curwin->w_cursor, &VIsual, |
| 2702 | &leftcol, &rightcol); |
| 2703 | getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL); |
| 2704 | if (m_pos.col < leftcol || m_pos.col > rightcol) |
| 2705 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2706 | } |
| 2707 | } |
| 2708 | } |
| 2709 | else |
| 2710 | jump_flags = MOUSE_MAY_STOP_VIS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2711 | } |
| 2712 | if (jump_flags) |
| 2713 | { |
| 2714 | jump_flags = jump_to_mouse(jump_flags, NULL, which_button); |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 2715 | update_curbuf(VIsual_active ? INVERTED : VALID); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2716 | setcursor(); |
| 2717 | out_flush(); /* Update before showing popup menu */ |
| 2718 | } |
| 2719 | # ifdef FEAT_MENU |
| 2720 | gui_show_popupmenu(); |
| 2721 | # endif |
| 2722 | return (jump_flags & CURSOR_MOVED) != 0; |
| 2723 | } |
| 2724 | else |
| 2725 | return FALSE; |
| 2726 | #else |
| 2727 | return FALSE; |
| 2728 | #endif |
| 2729 | } |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 2730 | if (which_button == MOUSE_LEFT |
| 2731 | && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2732 | { |
| 2733 | which_button = MOUSE_RIGHT; |
| 2734 | mod_mask &= ~MOD_MASK_SHIFT; |
| 2735 | } |
| 2736 | } |
| 2737 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2738 | if ((State & (NORMAL | INSERT)) |
| 2739 | && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) |
| 2740 | { |
| 2741 | if (which_button == MOUSE_LEFT) |
| 2742 | { |
| 2743 | if (is_click) |
| 2744 | { |
| 2745 | /* stop Visual mode for a left click in a window, but not when |
| 2746 | * on a status line */ |
| 2747 | if (VIsual_active) |
| 2748 | jump_flags |= MOUSE_MAY_STOP_VIS; |
| 2749 | } |
| 2750 | else if (mouse_has(MOUSE_VISUAL)) |
| 2751 | jump_flags |= MOUSE_MAY_VIS; |
| 2752 | } |
| 2753 | else if (which_button == MOUSE_RIGHT) |
| 2754 | { |
| 2755 | if (is_click && VIsual_active) |
| 2756 | { |
| 2757 | /* |
| 2758 | * Remember the start and end of visual before moving the |
| 2759 | * cursor. |
| 2760 | */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 2761 | if (LT_POS(curwin->w_cursor, VIsual)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2762 | { |
| 2763 | start_visual = curwin->w_cursor; |
| 2764 | end_visual = VIsual; |
| 2765 | } |
| 2766 | else |
| 2767 | { |
| 2768 | start_visual = VIsual; |
| 2769 | end_visual = curwin->w_cursor; |
| 2770 | } |
| 2771 | } |
| 2772 | jump_flags |= MOUSE_FOCUS; |
| 2773 | if (mouse_has(MOUSE_VISUAL)) |
| 2774 | jump_flags |= MOUSE_MAY_VIS; |
| 2775 | } |
| 2776 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2777 | |
| 2778 | /* |
| 2779 | * If an operator is pending, ignore all drags and releases until the |
| 2780 | * next mouse click. |
| 2781 | */ |
| 2782 | if (!is_drag && oap != NULL && oap->op_type != OP_NOP) |
| 2783 | { |
| 2784 | got_click = FALSE; |
| 2785 | oap->motion_type = MCHAR; |
| 2786 | } |
| 2787 | |
| 2788 | /* When releasing the button let jump_to_mouse() know. */ |
| 2789 | if (!is_click && !is_drag) |
| 2790 | jump_flags |= MOUSE_RELEASED; |
| 2791 | |
| 2792 | /* |
| 2793 | * JUMP! |
| 2794 | */ |
| 2795 | jump_flags = jump_to_mouse(jump_flags, |
| 2796 | oap == NULL ? NULL : &(oap->inclusive), which_button); |
| 2797 | moved = (jump_flags & CURSOR_MOVED); |
| 2798 | in_status_line = (jump_flags & IN_STATUS_LINE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2799 | in_sep_line = (jump_flags & IN_SEP_LINE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2800 | |
| 2801 | #ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 2802 | if (isNetbeansBuffer(curbuf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2803 | && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
| 2804 | { |
| 2805 | int key = KEY2TERMCAP1(c); |
| 2806 | |
| 2807 | if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE |
| 2808 | || key == (int)KE_RIGHTRELEASE) |
| 2809 | netbeans_button_release(which_button); |
| 2810 | } |
| 2811 | #endif |
| 2812 | |
| 2813 | /* When jumping to another window, clear a pending operator. That's a bit |
| 2814 | * friendlier than beeping and not jumping to that window. */ |
| 2815 | if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) |
| 2816 | clearop(oap); |
| 2817 | |
| 2818 | #ifdef FEAT_FOLDING |
| 2819 | if (mod_mask == 0 |
| 2820 | && !is_drag |
| 2821 | && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) |
| 2822 | && which_button == MOUSE_LEFT) |
| 2823 | { |
| 2824 | /* open or close a fold at this line */ |
| 2825 | if (jump_flags & MOUSE_FOLD_OPEN) |
| 2826 | openFold(curwin->w_cursor.lnum, 1L); |
| 2827 | else |
| 2828 | closeFold(curwin->w_cursor.lnum, 1L); |
| 2829 | /* don't move the cursor if still in the same window */ |
| 2830 | if (curwin == old_curwin) |
| 2831 | curwin->w_cursor = save_cursor; |
| 2832 | } |
| 2833 | #endif |
| 2834 | |
| 2835 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) |
| 2836 | if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) |
| 2837 | { |
| 2838 | clip_modeless(which_button, is_click, is_drag); |
| 2839 | return FALSE; |
| 2840 | } |
| 2841 | #endif |
| 2842 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2843 | /* Set global flag that we are extending the Visual area with mouse |
Bram Moolenaar | f711faf | 2007-05-10 16:48:19 +0000 | [diff] [blame] | 2844 | * dragging; temporarily minimize 'scrolloff'. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2845 | if (VIsual_active && is_drag && p_so) |
| 2846 | { |
| 2847 | /* In the very first line, allow scrolling one line */ |
| 2848 | if (mouse_row == 0) |
| 2849 | mouse_dragging = 2; |
| 2850 | else |
| 2851 | mouse_dragging = 1; |
| 2852 | } |
| 2853 | |
| 2854 | /* When dragging the mouse above the window, scroll down. */ |
| 2855 | if (is_drag && mouse_row < 0 && !in_status_line) |
| 2856 | { |
| 2857 | scroll_redraw(FALSE, 1L); |
| 2858 | mouse_row = 0; |
| 2859 | } |
| 2860 | |
| 2861 | if (start_visual.lnum) /* right click in visual mode */ |
| 2862 | { |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 2863 | /* When ALT is pressed make Visual mode blockwise. */ |
| 2864 | if (mod_mask & MOD_MASK_ALT) |
| 2865 | VIsual_mode = Ctrl_V; |
| 2866 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2867 | /* |
| 2868 | * In Visual-block mode, divide the area in four, pick up the corner |
| 2869 | * that is in the quarter that the cursor is in. |
| 2870 | */ |
| 2871 | if (VIsual_mode == Ctrl_V) |
| 2872 | { |
| 2873 | getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); |
| 2874 | if (curwin->w_curswant > (leftcol + rightcol) / 2) |
| 2875 | end_visual.col = leftcol; |
| 2876 | else |
| 2877 | end_visual.col = rightcol; |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 2878 | if (curwin->w_cursor.lnum >= |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2879 | (start_visual.lnum + end_visual.lnum) / 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2880 | end_visual.lnum = start_visual.lnum; |
| 2881 | |
| 2882 | /* move VIsual to the right column */ |
| 2883 | start_visual = curwin->w_cursor; /* save the cursor pos */ |
| 2884 | curwin->w_cursor = end_visual; |
| 2885 | coladvance(end_visual.col); |
| 2886 | VIsual = curwin->w_cursor; |
| 2887 | curwin->w_cursor = start_visual; /* restore the cursor */ |
| 2888 | } |
| 2889 | else |
| 2890 | { |
| 2891 | /* |
| 2892 | * If the click is before the start of visual, change the start. |
| 2893 | * If the click is after the end of visual, change the end. If |
| 2894 | * the click is inside the visual, change the closest side. |
| 2895 | */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 2896 | if (LT_POS(curwin->w_cursor, start_visual)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2897 | VIsual = end_visual; |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 2898 | else if (LT_POS(end_visual, curwin->w_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2899 | VIsual = start_visual; |
| 2900 | else |
| 2901 | { |
| 2902 | /* In the same line, compare column number */ |
| 2903 | if (end_visual.lnum == start_visual.lnum) |
| 2904 | { |
| 2905 | if (curwin->w_cursor.col - start_visual.col > |
| 2906 | end_visual.col - curwin->w_cursor.col) |
| 2907 | VIsual = start_visual; |
| 2908 | else |
| 2909 | VIsual = end_visual; |
| 2910 | } |
| 2911 | |
| 2912 | /* In different lines, compare line number */ |
| 2913 | else |
| 2914 | { |
| 2915 | diff = (curwin->w_cursor.lnum - start_visual.lnum) - |
| 2916 | (end_visual.lnum - curwin->w_cursor.lnum); |
| 2917 | |
| 2918 | if (diff > 0) /* closest to end */ |
| 2919 | VIsual = start_visual; |
| 2920 | else if (diff < 0) /* closest to start */ |
| 2921 | VIsual = end_visual; |
| 2922 | else /* in the middle line */ |
| 2923 | { |
| 2924 | if (curwin->w_cursor.col < |
| 2925 | (start_visual.col + end_visual.col) / 2) |
| 2926 | VIsual = end_visual; |
| 2927 | else |
| 2928 | VIsual = start_visual; |
| 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | } |
| 2933 | } |
| 2934 | /* |
| 2935 | * If Visual mode started in insert mode, execute "CTRL-O" |
| 2936 | */ |
| 2937 | else if ((State & INSERT) && VIsual_active) |
| 2938 | stuffcharReadbuff(Ctrl_O); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2939 | |
| 2940 | /* |
| 2941 | * Middle mouse click: Put text before cursor. |
| 2942 | */ |
| 2943 | if (which_button == MOUSE_MIDDLE) |
| 2944 | { |
| 2945 | #ifdef FEAT_CLIPBOARD |
| 2946 | if (clip_star.available && regname == 0) |
| 2947 | regname = '*'; |
| 2948 | #endif |
| 2949 | if (yank_register_mline(regname)) |
| 2950 | { |
| 2951 | if (mouse_past_bottom) |
| 2952 | dir = FORWARD; |
| 2953 | } |
| 2954 | else if (mouse_past_eol) |
| 2955 | dir = FORWARD; |
| 2956 | |
| 2957 | if (fixindent) |
| 2958 | { |
| 2959 | c1 = (dir == BACKWARD) ? '[' : ']'; |
| 2960 | c2 = 'p'; |
| 2961 | } |
| 2962 | else |
| 2963 | { |
| 2964 | c1 = (dir == FORWARD) ? 'p' : 'P'; |
| 2965 | c2 = NUL; |
| 2966 | } |
| 2967 | prep_redo(regname, count, NUL, c1, NUL, c2, NUL); |
| 2968 | |
| 2969 | /* |
| 2970 | * Remember where the paste started, so in edit() Insstart can be set |
| 2971 | * to this position |
| 2972 | */ |
| 2973 | if (restart_edit != 0) |
| 2974 | where_paste_started = curwin->w_cursor; |
| 2975 | do_put(regname, dir, count, fixindent | PUT_CURSEND); |
| 2976 | } |
| 2977 | |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 2978 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2979 | /* |
| 2980 | * Ctrl-Mouse click or double click in a quickfix window jumps to the |
| 2981 | * error under the mouse pointer. |
| 2982 | */ |
| 2983 | else if (((mod_mask & MOD_MASK_CTRL) |
| 2984 | || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
| 2985 | && bt_quickfix(curbuf)) |
| 2986 | { |
Bram Moolenaar | 28c258f | 2006-01-25 22:02:51 +0000 | [diff] [blame] | 2987 | if (curwin->w_llist_ref == NULL) /* quickfix window */ |
Bram Moolenaar | 25b0e6b | 2017-01-20 21:51:53 +0100 | [diff] [blame] | 2988 | do_cmdline_cmd((char_u *)".cc"); |
Bram Moolenaar | 28c258f | 2006-01-25 22:02:51 +0000 | [diff] [blame] | 2989 | else /* location list window */ |
Bram Moolenaar | 25b0e6b | 2017-01-20 21:51:53 +0100 | [diff] [blame] | 2990 | do_cmdline_cmd((char_u *)".ll"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2991 | got_click = FALSE; /* ignore drag&release now */ |
| 2992 | } |
| 2993 | #endif |
| 2994 | |
| 2995 | /* |
| 2996 | * Ctrl-Mouse click (or double click in a help window) jumps to the tag |
| 2997 | * under the mouse pointer. |
| 2998 | */ |
| 2999 | else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help |
| 3000 | && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) |
| 3001 | { |
| 3002 | if (State & INSERT) |
| 3003 | stuffcharReadbuff(Ctrl_O); |
| 3004 | stuffcharReadbuff(Ctrl_RSB); |
| 3005 | got_click = FALSE; /* ignore drag&release now */ |
| 3006 | } |
| 3007 | |
| 3008 | /* |
| 3009 | * Shift-Mouse click searches for the next occurrence of the word under |
| 3010 | * the mouse pointer |
| 3011 | */ |
| 3012 | else if ((mod_mask & MOD_MASK_SHIFT)) |
| 3013 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3014 | if ((State & INSERT) || (VIsual_active && VIsual_select)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3015 | stuffcharReadbuff(Ctrl_O); |
| 3016 | if (which_button == MOUSE_LEFT) |
| 3017 | stuffcharReadbuff('*'); |
| 3018 | else /* MOUSE_RIGHT */ |
| 3019 | stuffcharReadbuff('#'); |
| 3020 | } |
| 3021 | |
| 3022 | /* Handle double clicks, unless on status line */ |
| 3023 | else if (in_status_line) |
| 3024 | { |
| 3025 | #ifdef FEAT_MOUSESHAPE |
| 3026 | if ((is_drag || is_click) && !drag_status_line) |
| 3027 | { |
| 3028 | drag_status_line = TRUE; |
| 3029 | update_mouseshape(-1); |
| 3030 | } |
| 3031 | #endif |
| 3032 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3033 | else if (in_sep_line) |
| 3034 | { |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3035 | #ifdef FEAT_MOUSESHAPE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3036 | if ((is_drag || is_click) && !drag_sep_line) |
| 3037 | { |
| 3038 | drag_sep_line = TRUE; |
| 3039 | update_mouseshape(-1); |
| 3040 | } |
Bram Moolenaar | 829c8e3 | 2016-03-19 23:07:23 +0100 | [diff] [blame] | 3041 | #endif |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3042 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3043 | else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
| 3044 | && mouse_has(MOUSE_VISUAL)) |
| 3045 | { |
| 3046 | if (is_click || !VIsual_active) |
| 3047 | { |
| 3048 | if (VIsual_active) |
| 3049 | orig_cursor = VIsual; |
| 3050 | else |
| 3051 | { |
| 3052 | check_visual_highlight(); |
| 3053 | VIsual = curwin->w_cursor; |
| 3054 | orig_cursor = VIsual; |
| 3055 | VIsual_active = TRUE; |
| 3056 | VIsual_reselect = TRUE; |
| 3057 | /* start Select mode if 'selectmode' contains "mouse" */ |
| 3058 | may_start_select('o'); |
| 3059 | setmouse(); |
| 3060 | } |
| 3061 | if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 3062 | { |
| 3063 | /* Double click with ALT pressed makes it blockwise. */ |
| 3064 | if (mod_mask & MOD_MASK_ALT) |
| 3065 | VIsual_mode = Ctrl_V; |
| 3066 | else |
| 3067 | VIsual_mode = 'v'; |
| 3068 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3069 | else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
| 3070 | VIsual_mode = 'V'; |
| 3071 | else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) |
| 3072 | VIsual_mode = Ctrl_V; |
| 3073 | #ifdef FEAT_CLIPBOARD |
| 3074 | /* Make sure the clipboard gets updated. Needed because start and |
| 3075 | * end may still be the same, and the selection needs to be owned */ |
| 3076 | clip_star.vmode = NUL; |
| 3077 | #endif |
| 3078 | } |
| 3079 | /* |
| 3080 | * A double click selects a word or a block. |
| 3081 | */ |
| 3082 | if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
| 3083 | { |
| 3084 | pos_T *pos = NULL; |
Bram Moolenaar | 51485f0 | 2005-06-04 21:55:20 +0000 | [diff] [blame] | 3085 | int gc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3086 | |
| 3087 | if (is_click) |
| 3088 | { |
| 3089 | /* If the character under the cursor (skipping white space) is |
| 3090 | * not a word character, try finding a match and select a (), |
| 3091 | * {}, [], #if/#endif, etc. block. */ |
| 3092 | end_visual = curwin->w_cursor; |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 3093 | while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3094 | inc(&end_visual); |
| 3095 | if (oap != NULL) |
| 3096 | oap->motion_type = MCHAR; |
| 3097 | if (oap != NULL |
| 3098 | && VIsual_mode == 'v' |
| 3099 | && !vim_iswordc(gchar_pos(&end_visual)) |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 3100 | && EQUAL_POS(curwin->w_cursor, VIsual) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3101 | && (pos = findmatch(oap, NUL)) != NULL) |
| 3102 | { |
| 3103 | curwin->w_cursor = *pos; |
| 3104 | if (oap->motion_type == MLINE) |
| 3105 | VIsual_mode = 'V'; |
| 3106 | else if (*p_sel == 'e') |
| 3107 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 3108 | if (LT_POS(curwin->w_cursor, VIsual)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3109 | ++VIsual.col; |
| 3110 | else |
| 3111 | ++curwin->w_cursor.col; |
| 3112 | } |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | if (pos == NULL && (is_click || is_drag)) |
| 3117 | { |
| 3118 | /* When not found a match or when dragging: extend to include |
| 3119 | * a word. */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 3120 | if (LT_POS(curwin->w_cursor, orig_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3121 | { |
| 3122 | find_start_of_word(&curwin->w_cursor); |
| 3123 | find_end_of_word(&VIsual); |
| 3124 | } |
| 3125 | else |
| 3126 | { |
| 3127 | find_start_of_word(&VIsual); |
| 3128 | if (*p_sel == 'e' && *ml_get_cursor() != NUL) |
| 3129 | #ifdef FEAT_MBYTE |
| 3130 | curwin->w_cursor.col += |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3131 | (*mb_ptr2len)(ml_get_cursor()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3132 | #else |
| 3133 | ++curwin->w_cursor.col; |
| 3134 | #endif |
| 3135 | find_end_of_word(&curwin->w_cursor); |
| 3136 | } |
| 3137 | } |
| 3138 | curwin->w_set_curswant = TRUE; |
| 3139 | } |
| 3140 | if (is_click) |
| 3141 | redraw_curbuf_later(INVERTED); /* update the inversion */ |
| 3142 | } |
| 3143 | else if (VIsual_active && !old_active) |
Bram Moolenaar | 6496966 | 2005-12-14 21:59:55 +0000 | [diff] [blame] | 3144 | { |
| 3145 | if (mod_mask & MOD_MASK_ALT) |
| 3146 | VIsual_mode = Ctrl_V; |
| 3147 | else |
| 3148 | VIsual_mode = 'v'; |
| 3149 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3150 | |
| 3151 | /* If Visual mode changed show it later. */ |
Bram Moolenaar | 28c258f | 2006-01-25 22:02:51 +0000 | [diff] [blame] | 3152 | if ((!VIsual_active && old_active && mode_displayed) |
| 3153 | || (VIsual_active && p_smd && msg_silent == 0 |
| 3154 | && (!old_active || VIsual_mode != old_mode))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3155 | redraw_cmdline = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3156 | |
| 3157 | return moved; |
| 3158 | } |
| 3159 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3160 | /* |
| 3161 | * Move "pos" back to the start of the word it's in. |
| 3162 | */ |
| 3163 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3164 | find_start_of_word(pos_T *pos) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3165 | { |
| 3166 | char_u *line; |
| 3167 | int cclass; |
| 3168 | int col; |
| 3169 | |
| 3170 | line = ml_get(pos->lnum); |
| 3171 | cclass = get_mouse_class(line + pos->col); |
| 3172 | |
| 3173 | while (pos->col > 0) |
| 3174 | { |
| 3175 | col = pos->col - 1; |
| 3176 | #ifdef FEAT_MBYTE |
| 3177 | col -= (*mb_head_off)(line, line + col); |
| 3178 | #endif |
| 3179 | if (get_mouse_class(line + col) != cclass) |
| 3180 | break; |
| 3181 | pos->col = col; |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | /* |
| 3186 | * Move "pos" forward to the end of the word it's in. |
| 3187 | * When 'selection' is "exclusive", the position is just after the word. |
| 3188 | */ |
| 3189 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3190 | find_end_of_word(pos_T *pos) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3191 | { |
| 3192 | char_u *line; |
| 3193 | int cclass; |
| 3194 | int col; |
| 3195 | |
| 3196 | line = ml_get(pos->lnum); |
| 3197 | if (*p_sel == 'e' && pos->col > 0) |
| 3198 | { |
| 3199 | --pos->col; |
| 3200 | #ifdef FEAT_MBYTE |
| 3201 | pos->col -= (*mb_head_off)(line, line + pos->col); |
| 3202 | #endif |
| 3203 | } |
| 3204 | cclass = get_mouse_class(line + pos->col); |
| 3205 | while (line[pos->col] != NUL) |
| 3206 | { |
| 3207 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3208 | col = pos->col + (*mb_ptr2len)(line + pos->col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3209 | #else |
| 3210 | col = pos->col + 1; |
| 3211 | #endif |
| 3212 | if (get_mouse_class(line + col) != cclass) |
| 3213 | { |
| 3214 | if (*p_sel == 'e') |
| 3215 | pos->col = col; |
| 3216 | break; |
| 3217 | } |
| 3218 | pos->col = col; |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | /* |
| 3223 | * Get class of a character for selection: same class means same word. |
| 3224 | * 0: blank |
| 3225 | * 1: punctuation groups |
| 3226 | * 2: normal word character |
| 3227 | * >2: multi-byte word character. |
| 3228 | */ |
| 3229 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3230 | get_mouse_class(char_u *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3231 | { |
| 3232 | int c; |
| 3233 | |
| 3234 | #ifdef FEAT_MBYTE |
| 3235 | if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) |
| 3236 | return mb_get_class(p); |
| 3237 | #endif |
| 3238 | |
| 3239 | c = *p; |
| 3240 | if (c == ' ' || c == '\t') |
| 3241 | return 0; |
| 3242 | |
| 3243 | if (vim_iswordc(c)) |
| 3244 | return 2; |
| 3245 | |
| 3246 | /* |
| 3247 | * There are a few special cases where we want certain combinations of |
| 3248 | * characters to be considered as a single word. These are things like |
| 3249 | * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each |
Bram Moolenaar | 5ea0ac7 | 2010-05-07 15:52:08 +0200 | [diff] [blame] | 3250 | * character is in its own class. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3251 | */ |
| 3252 | if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) |
| 3253 | return 1; |
| 3254 | return c; |
| 3255 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3256 | #endif /* FEAT_MOUSE */ |
| 3257 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3258 | /* |
| 3259 | * Check if highlighting for visual mode is possible, give a warning message |
| 3260 | * if not. |
| 3261 | */ |
| 3262 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3263 | check_visual_highlight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3264 | { |
| 3265 | static int did_check = FALSE; |
| 3266 | |
| 3267 | if (full_screen) |
| 3268 | { |
Bram Moolenaar | 8820b48 | 2017-03-16 17:23:31 +0100 | [diff] [blame] | 3269 | if (!did_check && HL_ATTR(HLF_V) == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3270 | MSG(_("Warning: terminal cannot highlight")); |
| 3271 | did_check = TRUE; |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | /* |
Bram Moolenaar | 66fa271 | 2006-01-22 23:22:22 +0000 | [diff] [blame] | 3276 | * End Visual mode. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3277 | * This function should ALWAYS be called to end Visual mode, except from |
| 3278 | * do_pending_operator(). |
| 3279 | */ |
| 3280 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3281 | end_visual_mode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3282 | { |
| 3283 | #ifdef FEAT_CLIPBOARD |
| 3284 | /* |
| 3285 | * If we are using the clipboard, then remember what was selected in case |
| 3286 | * we need to paste it somewhere while we still own the selection. |
| 3287 | * Only do this when the clipboard is already owned. Don't want to grab |
| 3288 | * the selection when hitting ESC. |
| 3289 | */ |
| 3290 | if (clip_star.available && clip_star.owned) |
| 3291 | clip_auto_select(); |
| 3292 | #endif |
| 3293 | |
| 3294 | VIsual_active = FALSE; |
| 3295 | #ifdef FEAT_MOUSE |
| 3296 | setmouse(); |
| 3297 | mouse_dragging = 0; |
| 3298 | #endif |
| 3299 | |
| 3300 | /* Save the current VIsual area for '< and '> marks, and "gv" */ |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 3301 | curbuf->b_visual.vi_mode = VIsual_mode; |
| 3302 | curbuf->b_visual.vi_start = VIsual; |
| 3303 | curbuf->b_visual.vi_end = curwin->w_cursor; |
| 3304 | curbuf->b_visual.vi_curswant = curwin->w_curswant; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3305 | #ifdef FEAT_EVAL |
| 3306 | curbuf->b_visual_mode_eval = VIsual_mode; |
| 3307 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3308 | #ifdef FEAT_VIRTUALEDIT |
| 3309 | if (!virtual_active()) |
| 3310 | curwin->w_cursor.coladd = 0; |
| 3311 | #endif |
Bram Moolenaar | 0bbcb5c | 2015-08-04 19:18:52 +0200 | [diff] [blame] | 3312 | may_clear_cmdline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3313 | |
Bram Moolenaar | f193fff | 2006-04-27 00:02:13 +0000 | [diff] [blame] | 3314 | adjust_cursor_eol(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | /* |
| 3318 | * Reset VIsual_active and VIsual_reselect. |
| 3319 | */ |
| 3320 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3321 | reset_VIsual_and_resel(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3322 | { |
| 3323 | if (VIsual_active) |
| 3324 | { |
| 3325 | end_visual_mode(); |
| 3326 | redraw_curbuf_later(INVERTED); /* delete the inversion later */ |
| 3327 | } |
| 3328 | VIsual_reselect = FALSE; |
| 3329 | } |
| 3330 | |
| 3331 | /* |
| 3332 | * Reset VIsual_active and VIsual_reselect if it's set. |
| 3333 | */ |
| 3334 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3335 | reset_VIsual(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3336 | { |
| 3337 | if (VIsual_active) |
| 3338 | { |
| 3339 | end_visual_mode(); |
| 3340 | redraw_curbuf_later(INVERTED); /* delete the inversion later */ |
| 3341 | VIsual_reselect = FALSE; |
| 3342 | } |
| 3343 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3344 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3345 | /* |
| 3346 | * Check for a balloon-eval special item to include when searching for an |
| 3347 | * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! |
| 3348 | * Returns TRUE if the character at "*ptr" should be included. |
| 3349 | * "dir" is FORWARD or BACKWARD, the direction of searching. |
| 3350 | * "*colp" is in/decremented if "ptr[-dir]" should also be included. |
| 3351 | * "bnp" points to a counter for square brackets. |
| 3352 | */ |
| 3353 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3354 | find_is_eval_item( |
| 3355 | char_u *ptr, |
| 3356 | int *colp, |
| 3357 | int *bnp, |
| 3358 | int dir) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3359 | { |
| 3360 | /* Accept everything inside []. */ |
| 3361 | if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) |
| 3362 | ++*bnp; |
| 3363 | if (*bnp > 0) |
| 3364 | { |
| 3365 | if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) |
| 3366 | --*bnp; |
| 3367 | return TRUE; |
| 3368 | } |
| 3369 | |
| 3370 | /* skip over "s.var" */ |
| 3371 | if (*ptr == '.') |
| 3372 | return TRUE; |
| 3373 | |
| 3374 | /* two-character item: s->var */ |
| 3375 | if (ptr[dir == BACKWARD ? 0 : 1] == '>' |
| 3376 | && ptr[dir == BACKWARD ? -1 : 0] == '-') |
| 3377 | { |
| 3378 | *colp += dir; |
| 3379 | return TRUE; |
| 3380 | } |
| 3381 | return FALSE; |
| 3382 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3383 | |
| 3384 | /* |
| 3385 | * Find the identifier under or to the right of the cursor. |
| 3386 | * "find_type" can have one of three values: |
| 3387 | * FIND_IDENT: find an identifier (keyword) |
| 3388 | * FIND_STRING: find any non-white string |
| 3389 | * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3390 | * FIND_EVAL: find text useful for C program debugging |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3391 | * |
| 3392 | * There are three steps: |
| 3393 | * 1. Search forward for the start of an identifier/string. Doesn't move if |
| 3394 | * already on one. |
| 3395 | * 2. Search backward for the start of this identifier/string. |
| 3396 | * This doesn't match the real Vi but I like it a little better and it |
| 3397 | * shouldn't bother anyone. |
| 3398 | * 3. Search forward to the end of this identifier/string. |
| 3399 | * When FIND_IDENT isn't defined, we backup until a blank. |
| 3400 | * |
| 3401 | * Returns the length of the string, or zero if no string is found. |
| 3402 | * If a string is found, a pointer to the string is put in "*string". This |
| 3403 | * string is not always NUL terminated. |
| 3404 | */ |
| 3405 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3406 | find_ident_under_cursor(char_u **string, int find_type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3407 | { |
| 3408 | return find_ident_at_pos(curwin, curwin->w_cursor.lnum, |
| 3409 | curwin->w_cursor.col, string, find_type); |
| 3410 | } |
| 3411 | |
| 3412 | /* |
| 3413 | * Like find_ident_under_cursor(), but for any window and any position. |
| 3414 | * However: Uses 'iskeyword' from the current window!. |
| 3415 | */ |
| 3416 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3417 | find_ident_at_pos( |
| 3418 | win_T *wp, |
| 3419 | linenr_T lnum, |
| 3420 | colnr_T startcol, |
| 3421 | char_u **string, |
| 3422 | int find_type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3423 | { |
| 3424 | char_u *ptr; |
| 3425 | int col = 0; /* init to shut up GCC */ |
| 3426 | int i; |
| 3427 | #ifdef FEAT_MBYTE |
| 3428 | int this_class = 0; |
| 3429 | int prev_class; |
| 3430 | int prevcol; |
| 3431 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3432 | int bn = 0; /* bracket nesting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3433 | |
| 3434 | /* |
| 3435 | * if i == 0: try to find an identifier |
| 3436 | * if i == 1: try to find any non-white string |
| 3437 | */ |
| 3438 | ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3439 | for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) |
| 3440 | { |
| 3441 | /* |
| 3442 | * 1. skip to start of identifier/string |
| 3443 | */ |
| 3444 | col = startcol; |
| 3445 | #ifdef FEAT_MBYTE |
| 3446 | if (has_mbyte) |
| 3447 | { |
| 3448 | while (ptr[col] != NUL) |
| 3449 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3450 | /* Stop at a ']' to evaluate "a[x]". */ |
| 3451 | if ((find_type & FIND_EVAL) && ptr[col] == ']') |
| 3452 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3453 | this_class = mb_get_class(ptr + col); |
| 3454 | if (this_class != 0 && (i == 1 || this_class != 1)) |
| 3455 | break; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3456 | col += (*mb_ptr2len)(ptr + col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3457 | } |
| 3458 | } |
| 3459 | else |
| 3460 | #endif |
| 3461 | while (ptr[col] != NUL |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 3462 | && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3463 | && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3464 | ) |
| 3465 | ++col; |
| 3466 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3467 | /* When starting on a ']' count it, so that we include the '['. */ |
| 3468 | bn = ptr[col] == ']'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3469 | |
| 3470 | /* |
| 3471 | * 2. Back up to start of identifier/string. |
| 3472 | */ |
| 3473 | #ifdef FEAT_MBYTE |
| 3474 | if (has_mbyte) |
| 3475 | { |
| 3476 | /* Remember class of character under cursor. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3477 | if ((find_type & FIND_EVAL) && ptr[col] == ']') |
| 3478 | this_class = mb_get_class((char_u *)"a"); |
| 3479 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3480 | this_class = mb_get_class(ptr + col); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3481 | while (col > 0 && this_class != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3482 | { |
| 3483 | prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); |
| 3484 | prev_class = mb_get_class(ptr + prevcol); |
| 3485 | if (this_class != prev_class |
| 3486 | && (i == 0 |
| 3487 | || prev_class == 0 |
| 3488 | || (find_type & FIND_IDENT)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3489 | && (!(find_type & FIND_EVAL) |
| 3490 | || prevcol == 0 |
| 3491 | || !find_is_eval_item(ptr + prevcol, &prevcol, |
| 3492 | &bn, BACKWARD)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3493 | ) |
| 3494 | break; |
| 3495 | col = prevcol; |
| 3496 | } |
| 3497 | |
| 3498 | /* If we don't want just any old string, or we've found an |
| 3499 | * identifier, stop searching. */ |
| 3500 | if (this_class > 2) |
| 3501 | this_class = 2; |
| 3502 | if (!(find_type & FIND_STRING) || this_class == 2) |
| 3503 | break; |
| 3504 | } |
| 3505 | else |
| 3506 | #endif |
| 3507 | { |
| 3508 | while (col > 0 |
| 3509 | && ((i == 0 |
| 3510 | ? vim_iswordc(ptr[col - 1]) |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 3511 | : (!VIM_ISWHITE(ptr[col - 1]) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3512 | && (!(find_type & FIND_IDENT) |
| 3513 | || !vim_iswordc(ptr[col - 1])))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3514 | || ((find_type & FIND_EVAL) |
| 3515 | && col > 1 |
| 3516 | && find_is_eval_item(ptr + col - 1, &col, |
| 3517 | &bn, BACKWARD)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3518 | )) |
| 3519 | --col; |
| 3520 | |
| 3521 | /* If we don't want just any old string, or we've found an |
| 3522 | * identifier, stop searching. */ |
| 3523 | if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) |
| 3524 | break; |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | if (ptr[col] == NUL || (i == 0 && ( |
| 3529 | #ifdef FEAT_MBYTE |
| 3530 | has_mbyte ? this_class != 2 : |
| 3531 | #endif |
| 3532 | !vim_iswordc(ptr[col])))) |
| 3533 | { |
| 3534 | /* |
| 3535 | * didn't find an identifier or string |
| 3536 | */ |
| 3537 | if (find_type & FIND_STRING) |
| 3538 | EMSG(_("E348: No string under cursor")); |
| 3539 | else |
Bram Moolenaar | 9fd01c6 | 2008-11-01 12:52:38 +0000 | [diff] [blame] | 3540 | EMSG(_(e_noident)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3541 | return 0; |
| 3542 | } |
| 3543 | ptr += col; |
| 3544 | *string = ptr; |
| 3545 | |
| 3546 | /* |
| 3547 | * 3. Find the end if the identifier/string. |
| 3548 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3549 | bn = 0; |
| 3550 | startcol -= col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3551 | col = 0; |
| 3552 | #ifdef FEAT_MBYTE |
| 3553 | if (has_mbyte) |
| 3554 | { |
| 3555 | /* Search for point of changing multibyte character class. */ |
| 3556 | this_class = mb_get_class(ptr); |
| 3557 | while (ptr[col] != NUL |
| 3558 | && ((i == 0 ? mb_get_class(ptr + col) == this_class |
| 3559 | : mb_get_class(ptr + col) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3560 | || ((find_type & FIND_EVAL) |
| 3561 | && col <= (int)startcol |
| 3562 | && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3563 | )) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3564 | col += (*mb_ptr2len)(ptr + col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3565 | } |
| 3566 | else |
| 3567 | #endif |
| 3568 | while ((i == 0 ? vim_iswordc(ptr[col]) |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 3569 | : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3570 | || ((find_type & FIND_EVAL) |
| 3571 | && col <= (int)startcol |
| 3572 | && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3573 | ) |
| 3574 | { |
| 3575 | ++col; |
| 3576 | } |
| 3577 | |
| 3578 | return col; |
| 3579 | } |
| 3580 | |
| 3581 | /* |
| 3582 | * Prepare for redo of a normal command. |
| 3583 | */ |
| 3584 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3585 | prep_redo_cmd(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3586 | { |
| 3587 | prep_redo(cap->oap->regname, cap->count0, |
| 3588 | NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
| 3589 | } |
| 3590 | |
| 3591 | /* |
| 3592 | * Prepare for redo of any command. |
| 3593 | * Note that only the last argument can be a multi-byte char. |
| 3594 | */ |
| 3595 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3596 | prep_redo( |
| 3597 | int regname, |
| 3598 | long num, |
| 3599 | int cmd1, |
| 3600 | int cmd2, |
| 3601 | int cmd3, |
| 3602 | int cmd4, |
| 3603 | int cmd5) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3604 | { |
| 3605 | ResetRedobuff(); |
| 3606 | if (regname != 0) /* yank from specified buffer */ |
| 3607 | { |
| 3608 | AppendCharToRedobuff('"'); |
| 3609 | AppendCharToRedobuff(regname); |
| 3610 | } |
| 3611 | if (num) |
| 3612 | AppendNumberToRedobuff(num); |
| 3613 | |
| 3614 | if (cmd1 != NUL) |
| 3615 | AppendCharToRedobuff(cmd1); |
| 3616 | if (cmd2 != NUL) |
| 3617 | AppendCharToRedobuff(cmd2); |
| 3618 | if (cmd3 != NUL) |
| 3619 | AppendCharToRedobuff(cmd3); |
| 3620 | if (cmd4 != NUL) |
| 3621 | AppendCharToRedobuff(cmd4); |
| 3622 | if (cmd5 != NUL) |
| 3623 | AppendCharToRedobuff(cmd5); |
| 3624 | } |
| 3625 | |
| 3626 | /* |
| 3627 | * check for operator active and clear it |
| 3628 | * |
| 3629 | * return TRUE if operator was active |
| 3630 | */ |
| 3631 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3632 | checkclearop(oparg_T *oap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3633 | { |
| 3634 | if (oap->op_type == OP_NOP) |
| 3635 | return FALSE; |
| 3636 | clearopbeep(oap); |
| 3637 | return TRUE; |
| 3638 | } |
| 3639 | |
| 3640 | /* |
Bram Moolenaar | c980de3 | 2007-05-06 11:59:04 +0000 | [diff] [blame] | 3641 | * Check for operator or Visual active. Clear active operator. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3642 | * |
Bram Moolenaar | c980de3 | 2007-05-06 11:59:04 +0000 | [diff] [blame] | 3643 | * Return TRUE if operator or Visual was active. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3644 | */ |
| 3645 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3646 | checkclearopq(oparg_T *oap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3647 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3648 | if (oap->op_type == OP_NOP && !VIsual_active) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3649 | return FALSE; |
| 3650 | clearopbeep(oap); |
| 3651 | return TRUE; |
| 3652 | } |
| 3653 | |
| 3654 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3655 | clearop(oparg_T *oap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3656 | { |
| 3657 | oap->op_type = OP_NOP; |
| 3658 | oap->regname = 0; |
| 3659 | oap->motion_force = NUL; |
| 3660 | oap->use_reg_one = FALSE; |
| 3661 | } |
| 3662 | |
| 3663 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3664 | clearopbeep(oparg_T *oap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3665 | { |
| 3666 | clearop(oap); |
| 3667 | beep_flush(); |
| 3668 | } |
| 3669 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3670 | /* |
| 3671 | * Remove the shift modifier from a special key. |
| 3672 | */ |
| 3673 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3674 | unshift_special(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3675 | { |
| 3676 | switch (cap->cmdchar) |
| 3677 | { |
| 3678 | case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; |
| 3679 | case K_S_LEFT: cap->cmdchar = K_LEFT; break; |
| 3680 | case K_S_UP: cap->cmdchar = K_UP; break; |
| 3681 | case K_S_DOWN: cap->cmdchar = K_DOWN; break; |
| 3682 | case K_S_HOME: cap->cmdchar = K_HOME; break; |
| 3683 | case K_S_END: cap->cmdchar = K_END; break; |
| 3684 | } |
| 3685 | cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); |
| 3686 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3687 | |
Bram Moolenaar | 0bbcb5c | 2015-08-04 19:18:52 +0200 | [diff] [blame] | 3688 | /* |
| 3689 | * If the mode is currently displayed clear the command line or update the |
| 3690 | * command displayed. |
| 3691 | */ |
| 3692 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3693 | may_clear_cmdline(void) |
Bram Moolenaar | 0bbcb5c | 2015-08-04 19:18:52 +0200 | [diff] [blame] | 3694 | { |
| 3695 | if (mode_displayed) |
| 3696 | clear_cmdline = TRUE; /* unshow visual mode later */ |
| 3697 | #ifdef FEAT_CMDL_INFO |
| 3698 | else |
| 3699 | clear_showcmd(); |
| 3700 | #endif |
| 3701 | } |
| 3702 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3703 | #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
| 3704 | /* |
| 3705 | * Routines for displaying a partly typed command |
| 3706 | */ |
| 3707 | |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3708 | #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3709 | static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
| 3710 | static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ |
| 3711 | static int showcmd_is_clear = TRUE; |
| 3712 | static int showcmd_visual = FALSE; |
| 3713 | |
Bram Moolenaar | 92b8b2d | 2016-01-29 22:36:45 +0100 | [diff] [blame] | 3714 | static void display_showcmd(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3715 | |
| 3716 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3717 | clear_showcmd(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3718 | { |
| 3719 | if (!p_sc) |
| 3720 | return; |
| 3721 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3722 | if (VIsual_active && !char_avail()) |
| 3723 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 3724 | int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3725 | long lines; |
| 3726 | colnr_T leftcol, rightcol; |
| 3727 | linenr_T top, bot; |
| 3728 | |
| 3729 | /* Show the size of the Visual area. */ |
Bram Moolenaar | 81d0007 | 2009-04-29 15:41:40 +0000 | [diff] [blame] | 3730 | if (cursor_bot) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3731 | { |
| 3732 | top = VIsual.lnum; |
| 3733 | bot = curwin->w_cursor.lnum; |
| 3734 | } |
| 3735 | else |
| 3736 | { |
| 3737 | top = curwin->w_cursor.lnum; |
| 3738 | bot = VIsual.lnum; |
| 3739 | } |
| 3740 | # ifdef FEAT_FOLDING |
| 3741 | /* Include closed folds as a whole. */ |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 3742 | (void)hasFolding(top, &top, NULL); |
| 3743 | (void)hasFolding(bot, NULL, &bot); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3744 | # endif |
| 3745 | lines = bot - top + 1; |
| 3746 | |
| 3747 | if (VIsual_mode == Ctrl_V) |
| 3748 | { |
Bram Moolenaar | fdf732e | 2010-07-18 14:20:35 +0200 | [diff] [blame] | 3749 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | 81d0007 | 2009-04-29 15:41:40 +0000 | [diff] [blame] | 3750 | char_u *saved_sbr = p_sbr; |
| 3751 | |
| 3752 | /* Make 'sbr' empty for a moment to get the correct size. */ |
| 3753 | p_sbr = empty_option; |
Bram Moolenaar | fdf732e | 2010-07-18 14:20:35 +0200 | [diff] [blame] | 3754 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3755 | getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); |
Bram Moolenaar | fdf732e | 2010-07-18 14:20:35 +0200 | [diff] [blame] | 3756 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | 81d0007 | 2009-04-29 15:41:40 +0000 | [diff] [blame] | 3757 | p_sbr = saved_sbr; |
Bram Moolenaar | fdf732e | 2010-07-18 14:20:35 +0200 | [diff] [blame] | 3758 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3759 | sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
| 3760 | (long)(rightcol - leftcol + 1)); |
| 3761 | } |
| 3762 | else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) |
| 3763 | sprintf((char *)showcmd_buf, "%ld", lines); |
| 3764 | else |
Bram Moolenaar | f91787c | 2010-07-17 12:47:16 +0200 | [diff] [blame] | 3765 | { |
| 3766 | char_u *s, *e; |
| 3767 | int l; |
| 3768 | int bytes = 0; |
| 3769 | int chars = 0; |
| 3770 | |
| 3771 | if (cursor_bot) |
| 3772 | { |
| 3773 | s = ml_get_pos(&VIsual); |
| 3774 | e = ml_get_cursor(); |
| 3775 | } |
| 3776 | else |
| 3777 | { |
| 3778 | s = ml_get_cursor(); |
| 3779 | e = ml_get_pos(&VIsual); |
| 3780 | } |
| 3781 | while ((*p_sel != 'e') ? s <= e : s < e) |
| 3782 | { |
Bram Moolenaar | fdf732e | 2010-07-18 14:20:35 +0200 | [diff] [blame] | 3783 | # ifdef FEAT_MBYTE |
Bram Moolenaar | f91787c | 2010-07-17 12:47:16 +0200 | [diff] [blame] | 3784 | l = (*mb_ptr2len)(s); |
Bram Moolenaar | fdf732e | 2010-07-18 14:20:35 +0200 | [diff] [blame] | 3785 | # else |
| 3786 | l = (*s == NUL) ? 0 : 1; |
| 3787 | # endif |
Bram Moolenaar | f91787c | 2010-07-17 12:47:16 +0200 | [diff] [blame] | 3788 | if (l == 0) |
| 3789 | { |
| 3790 | ++bytes; |
| 3791 | ++chars; |
| 3792 | break; /* end of line */ |
| 3793 | } |
| 3794 | bytes += l; |
| 3795 | ++chars; |
| 3796 | s += l; |
| 3797 | } |
| 3798 | if (bytes == chars) |
| 3799 | sprintf((char *)showcmd_buf, "%d", chars); |
| 3800 | else |
| 3801 | sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); |
| 3802 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3803 | showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
| 3804 | showcmd_visual = TRUE; |
| 3805 | } |
| 3806 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3807 | { |
| 3808 | showcmd_buf[0] = NUL; |
| 3809 | showcmd_visual = FALSE; |
| 3810 | |
| 3811 | /* Don't actually display something if there is nothing to clear. */ |
| 3812 | if (showcmd_is_clear) |
| 3813 | return; |
| 3814 | } |
| 3815 | |
| 3816 | display_showcmd(); |
| 3817 | } |
| 3818 | |
| 3819 | /* |
| 3820 | * Add 'c' to string of shown command chars. |
| 3821 | * Return TRUE if output has been written (and setcursor() has been called). |
| 3822 | */ |
| 3823 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3824 | add_to_showcmd(int c) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3825 | { |
| 3826 | char_u *p; |
| 3827 | int old_len; |
| 3828 | int extra_len; |
| 3829 | int overflow; |
| 3830 | #if defined(FEAT_MOUSE) |
| 3831 | int i; |
| 3832 | static int ignore[] = |
| 3833 | { |
Bram Moolenaar | cf0c554 | 2006-02-09 23:48:02 +0000 | [diff] [blame] | 3834 | # ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3835 | K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
| 3836 | K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, |
Bram Moolenaar | cf0c554 | 2006-02-09 23:48:02 +0000 | [diff] [blame] | 3837 | # endif |
Bram Moolenaar | ec2da36 | 2017-01-21 20:04:22 +0100 | [diff] [blame] | 3838 | K_IGNORE, K_PS, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3839 | K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, |
| 3840 | K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
| 3841 | K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE, |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3842 | K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3843 | K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
Bram Moolenaar | 05a7bb3 | 2006-01-19 22:09:32 +0000 | [diff] [blame] | 3844 | K_CURSORHOLD, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3845 | 0 |
| 3846 | }; |
| 3847 | #endif |
| 3848 | |
Bram Moolenaar | 09df312 | 2006-01-23 22:23:09 +0000 | [diff] [blame] | 3849 | if (!p_sc || msg_silent != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3850 | return FALSE; |
| 3851 | |
| 3852 | if (showcmd_visual) |
| 3853 | { |
| 3854 | showcmd_buf[0] = NUL; |
| 3855 | showcmd_visual = FALSE; |
| 3856 | } |
| 3857 | |
| 3858 | #if defined(FEAT_MOUSE) |
| 3859 | /* Ignore keys that are scrollbar updates and mouse clicks */ |
| 3860 | if (IS_SPECIAL(c)) |
| 3861 | for (i = 0; ignore[i] != 0; ++i) |
| 3862 | if (ignore[i] == c) |
| 3863 | return FALSE; |
| 3864 | #endif |
| 3865 | |
| 3866 | p = transchar(c); |
Bram Moolenaar | 7ba0741 | 2013-12-11 14:55:01 +0100 | [diff] [blame] | 3867 | if (*p == ' ') |
| 3868 | STRCPY(p, "<20>"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3869 | old_len = (int)STRLEN(showcmd_buf); |
| 3870 | extra_len = (int)STRLEN(p); |
| 3871 | overflow = old_len + extra_len - SHOWCMD_COLS; |
| 3872 | if (overflow > 0) |
Bram Moolenaar | b0db569 | 2007-08-14 20:54:49 +0000 | [diff] [blame] | 3873 | mch_memmove(showcmd_buf, showcmd_buf + overflow, |
| 3874 | old_len - overflow + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3875 | STRCAT(showcmd_buf, p); |
| 3876 | |
| 3877 | if (char_avail()) |
| 3878 | return FALSE; |
| 3879 | |
| 3880 | display_showcmd(); |
| 3881 | |
| 3882 | return TRUE; |
| 3883 | } |
| 3884 | |
| 3885 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3886 | add_to_showcmd_c(int c) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3887 | { |
| 3888 | if (!add_to_showcmd(c)) |
| 3889 | setcursor(); |
| 3890 | } |
| 3891 | |
| 3892 | /* |
| 3893 | * Delete 'len' characters from the end of the shown command. |
| 3894 | */ |
| 3895 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3896 | del_from_showcmd(int len) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3897 | { |
| 3898 | int old_len; |
| 3899 | |
| 3900 | if (!p_sc) |
| 3901 | return; |
| 3902 | |
| 3903 | old_len = (int)STRLEN(showcmd_buf); |
| 3904 | if (len > old_len) |
| 3905 | len = old_len; |
| 3906 | showcmd_buf[old_len - len] = NUL; |
| 3907 | |
| 3908 | if (!char_avail()) |
| 3909 | display_showcmd(); |
| 3910 | } |
| 3911 | |
| 3912 | /* |
| 3913 | * push_showcmd() and pop_showcmd() are used when waiting for the user to type |
| 3914 | * something and there is a partial mapping. |
| 3915 | */ |
| 3916 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3917 | push_showcmd(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3918 | { |
| 3919 | if (p_sc) |
| 3920 | STRCPY(old_showcmd_buf, showcmd_buf); |
| 3921 | } |
| 3922 | |
| 3923 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3924 | pop_showcmd(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3925 | { |
| 3926 | if (!p_sc) |
| 3927 | return; |
| 3928 | |
| 3929 | STRCPY(showcmd_buf, old_showcmd_buf); |
| 3930 | |
| 3931 | display_showcmd(); |
| 3932 | } |
| 3933 | |
| 3934 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3935 | display_showcmd(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3936 | { |
| 3937 | int len; |
| 3938 | |
| 3939 | cursor_off(); |
| 3940 | |
| 3941 | len = (int)STRLEN(showcmd_buf); |
| 3942 | if (len == 0) |
| 3943 | showcmd_is_clear = TRUE; |
| 3944 | else |
| 3945 | { |
| 3946 | screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); |
| 3947 | showcmd_is_clear = FALSE; |
| 3948 | } |
| 3949 | |
| 3950 | /* |
Bram Moolenaar | f711faf | 2007-05-10 16:48:19 +0000 | [diff] [blame] | 3951 | * clear the rest of an old message by outputting up to SHOWCMD_COLS |
| 3952 | * spaces |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3953 | */ |
| 3954 | screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); |
| 3955 | |
| 3956 | setcursor(); /* put cursor back where it belongs */ |
| 3957 | } |
| 3958 | #endif |
| 3959 | |
| 3960 | #ifdef FEAT_SCROLLBIND |
| 3961 | /* |
| 3962 | * When "check" is FALSE, prepare for commands that scroll the window. |
| 3963 | * When "check" is TRUE, take care of scroll-binding after the window has |
| 3964 | * scrolled. Called from normal_cmd() and edit(). |
| 3965 | */ |
| 3966 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3967 | do_check_scrollbind(int check) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3968 | { |
| 3969 | static win_T *old_curwin = NULL; |
| 3970 | static linenr_T old_topline = 0; |
| 3971 | #ifdef FEAT_DIFF |
| 3972 | static int old_topfill = 0; |
| 3973 | #endif |
| 3974 | static buf_T *old_buf = NULL; |
| 3975 | static colnr_T old_leftcol = 0; |
| 3976 | |
| 3977 | if (check && curwin->w_p_scb) |
| 3978 | { |
| 3979 | /* If a ":syncbind" command was just used, don't scroll, only reset |
| 3980 | * the values. */ |
| 3981 | if (did_syncbind) |
| 3982 | did_syncbind = FALSE; |
| 3983 | else if (curwin == old_curwin) |
| 3984 | { |
| 3985 | /* |
| 3986 | * Synchronize other windows, as necessary according to |
| 3987 | * 'scrollbind'. Don't do this after an ":edit" command, except |
| 3988 | * when 'diff' is set. |
| 3989 | */ |
| 3990 | if ((curwin->w_buffer == old_buf |
| 3991 | #ifdef FEAT_DIFF |
| 3992 | || curwin->w_p_diff |
| 3993 | #endif |
| 3994 | ) |
| 3995 | && (curwin->w_topline != old_topline |
| 3996 | #ifdef FEAT_DIFF |
| 3997 | || curwin->w_topfill != old_topfill |
| 3998 | #endif |
| 3999 | || curwin->w_leftcol != old_leftcol)) |
| 4000 | { |
| 4001 | check_scrollbind(curwin->w_topline - old_topline, |
| 4002 | (long)(curwin->w_leftcol - old_leftcol)); |
| 4003 | } |
| 4004 | } |
| 4005 | else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ |
| 4006 | { |
| 4007 | /* |
| 4008 | * When switching between windows, make sure that the relative |
| 4009 | * vertical offset is valid for the new window. The relative |
| 4010 | * offset is invalid whenever another 'scrollbind' window has |
| 4011 | * scrolled to a point that would force the current window to |
| 4012 | * scroll past the beginning or end of its buffer. When the |
| 4013 | * resync is performed, some of the other 'scrollbind' windows may |
| 4014 | * need to jump so that the current window's relative position is |
| 4015 | * visible on-screen. |
| 4016 | */ |
| 4017 | check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); |
| 4018 | } |
| 4019 | curwin->w_scbind_pos = curwin->w_topline; |
| 4020 | } |
| 4021 | |
| 4022 | old_curwin = curwin; |
| 4023 | old_topline = curwin->w_topline; |
| 4024 | #ifdef FEAT_DIFF |
| 4025 | old_topfill = curwin->w_topfill; |
| 4026 | #endif |
| 4027 | old_buf = curwin->w_buffer; |
| 4028 | old_leftcol = curwin->w_leftcol; |
| 4029 | } |
| 4030 | |
| 4031 | /* |
| 4032 | * Synchronize any windows that have "scrollbind" set, based on the |
| 4033 | * number of rows by which the current window has changed |
| 4034 | * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) |
| 4035 | */ |
| 4036 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4037 | check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4038 | { |
| 4039 | int want_ver; |
| 4040 | int want_hor; |
| 4041 | win_T *old_curwin = curwin; |
| 4042 | buf_T *old_curbuf = curbuf; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4043 | int old_VIsual_select = VIsual_select; |
| 4044 | int old_VIsual_active = VIsual_active; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4045 | colnr_T tgt_leftcol = curwin->w_leftcol; |
| 4046 | long topline; |
| 4047 | long y; |
| 4048 | |
| 4049 | /* |
| 4050 | * check 'scrollopt' string for vertical and horizontal scroll options |
| 4051 | */ |
| 4052 | want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); |
| 4053 | #ifdef FEAT_DIFF |
| 4054 | want_ver |= old_curwin->w_p_diff; |
| 4055 | #endif |
| 4056 | want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); |
| 4057 | |
| 4058 | /* |
| 4059 | * loop through the scrollbound windows and scroll accordingly |
| 4060 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4061 | VIsual_select = VIsual_active = 0; |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 4062 | FOR_ALL_WINDOWS(curwin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4063 | { |
| 4064 | curbuf = curwin->w_buffer; |
| 4065 | /* skip original window and windows with 'noscrollbind' */ |
| 4066 | if (curwin != old_curwin && curwin->w_p_scb) |
| 4067 | { |
| 4068 | /* |
| 4069 | * do the vertical scroll |
| 4070 | */ |
| 4071 | if (want_ver) |
| 4072 | { |
| 4073 | #ifdef FEAT_DIFF |
| 4074 | if (old_curwin->w_p_diff && curwin->w_p_diff) |
| 4075 | { |
| 4076 | diff_set_topline(old_curwin, curwin); |
| 4077 | } |
| 4078 | else |
| 4079 | #endif |
| 4080 | { |
| 4081 | curwin->w_scbind_pos += topline_diff; |
| 4082 | topline = curwin->w_scbind_pos; |
| 4083 | if (topline > curbuf->b_ml.ml_line_count) |
| 4084 | topline = curbuf->b_ml.ml_line_count; |
| 4085 | if (topline < 1) |
| 4086 | topline = 1; |
| 4087 | |
| 4088 | y = topline - curwin->w_topline; |
| 4089 | if (y > 0) |
| 4090 | scrollup(y, FALSE); |
| 4091 | else |
| 4092 | scrolldown(-y, FALSE); |
| 4093 | } |
| 4094 | |
| 4095 | redraw_later(VALID); |
| 4096 | cursor_correct(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4097 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /* |
| 4101 | * do the horizontal scroll |
| 4102 | */ |
| 4103 | if (want_hor && curwin->w_leftcol != tgt_leftcol) |
| 4104 | { |
| 4105 | curwin->w_leftcol = tgt_leftcol; |
| 4106 | leftcol_changed(); |
| 4107 | } |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | /* |
| 4112 | * reset current-window |
| 4113 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4114 | VIsual_select = old_VIsual_select; |
| 4115 | VIsual_active = old_VIsual_active; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4116 | curwin = old_curwin; |
| 4117 | curbuf = old_curbuf; |
| 4118 | } |
| 4119 | #endif /* #ifdef FEAT_SCROLLBIND */ |
| 4120 | |
| 4121 | /* |
| 4122 | * Command character that's ignored. |
| 4123 | * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use |
Bram Moolenaar | 5ea0ac7 | 2010-05-07 15:52:08 +0200 | [diff] [blame] | 4124 | * xon/xoff. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4125 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4126 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4127 | nv_ignore(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4128 | { |
Bram Moolenaar | fc73515 | 2005-03-22 22:54:12 +0000 | [diff] [blame] | 4129 | cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | /* |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 4133 | * Command character that doesn't do anything, but unlike nv_ignore() does |
| 4134 | * start edit(). Used for "startinsert" executed while starting up. |
| 4135 | */ |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 4136 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4137 | nv_nop(cmdarg_T *cap UNUSED) |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 4138 | { |
| 4139 | } |
| 4140 | |
| 4141 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4142 | * Command character doesn't exist. |
| 4143 | */ |
| 4144 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4145 | nv_error(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4146 | { |
| 4147 | clearopbeep(cap->oap); |
| 4148 | } |
| 4149 | |
| 4150 | /* |
| 4151 | * <Help> and <F1> commands. |
| 4152 | */ |
| 4153 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4154 | nv_help(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4155 | { |
| 4156 | if (!checkclearopq(cap->oap)) |
| 4157 | ex_help(NULL); |
| 4158 | } |
| 4159 | |
| 4160 | /* |
| 4161 | * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. |
| 4162 | */ |
| 4163 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4164 | nv_addsub(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4165 | { |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 4166 | if (!VIsual_active && cap->oap->op_type == OP_NOP) |
Bram Moolenaar | 9bb1930 | 2015-07-03 12:44:07 +0200 | [diff] [blame] | 4167 | { |
Bram Moolenaar | ef2b503 | 2016-01-12 22:20:58 +0100 | [diff] [blame] | 4168 | prep_redo_cmd(cap); |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 4169 | cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB; |
| 4170 | op_addsub(cap->oap, cap->count1, cap->arg); |
| 4171 | cap->oap->op_type = OP_NOP; |
Bram Moolenaar | 9bb1930 | 2015-07-03 12:44:07 +0200 | [diff] [blame] | 4172 | } |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 4173 | else if (VIsual_active) |
| 4174 | nv_operator(cap); |
Bram Moolenaar | 3a304b2 | 2015-06-25 13:57:36 +0200 | [diff] [blame] | 4175 | else |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 4176 | clearop(cap->oap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | /* |
| 4180 | * CTRL-F, CTRL-B, etc: Scroll page up or down. |
| 4181 | */ |
| 4182 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4183 | nv_page(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4184 | { |
| 4185 | if (!checkclearop(cap->oap)) |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4186 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4187 | if (mod_mask & MOD_MASK_CTRL) |
| 4188 | { |
| 4189 | /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ |
| 4190 | if (cap->arg == BACKWARD) |
| 4191 | goto_tabpage(-(int)cap->count1); |
| 4192 | else |
| 4193 | goto_tabpage((int)cap->count0); |
| 4194 | } |
| 4195 | else |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 4196 | (void)onepage(cap->arg, cap->count1); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4197 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | /* |
| 4201 | * Implementation of "gd" and "gD" command. |
| 4202 | */ |
| 4203 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4204 | nv_gd( |
| 4205 | oparg_T *oap, |
| 4206 | int nchar, |
| 4207 | int thisblock) /* 1 for "1gd" and "1gD" */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4208 | { |
| 4209 | int len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4210 | char_u *ptr; |
| 4211 | |
Bram Moolenaar | d9d3058 | 2005-05-18 22:10:28 +0000 | [diff] [blame] | 4212 | if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0 |
Bram Moolenaar | 1538fc3 | 2016-04-16 09:13:34 +0200 | [diff] [blame] | 4213 | || find_decl(ptr, len, nchar == 'd', thisblock, SEARCH_START) |
| 4214 | == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4215 | clearopbeep(oap); |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4216 | #ifdef FEAT_FOLDING |
| 4217 | else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) |
| 4218 | foldOpenCursor(); |
| 4219 | #endif |
| 4220 | } |
| 4221 | |
| 4222 | /* |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4223 | * Return TRUE if line[offset] is not inside a C-style comment or string, FALSE |
| 4224 | * otherwise. |
| 4225 | */ |
| 4226 | static int |
| 4227 | is_ident(char_u *line, int offset) |
| 4228 | { |
| 4229 | int i; |
| 4230 | int incomment = FALSE; |
| 4231 | int instring = 0; |
| 4232 | int prev = 0; |
| 4233 | |
| 4234 | for (i = 0; i < offset && line[i] != NUL; i++) |
| 4235 | { |
| 4236 | if (instring != 0) |
| 4237 | { |
| 4238 | if (prev != '\\' && line[i] == instring) |
| 4239 | instring = 0; |
| 4240 | } |
| 4241 | else if ((line[i] == '"' || line[i] == '\'') && !incomment) |
| 4242 | { |
| 4243 | instring = line[i]; |
| 4244 | } |
| 4245 | else |
| 4246 | { |
| 4247 | if (incomment) |
| 4248 | { |
| 4249 | if (prev == '*' && line[i] == '/') |
| 4250 | incomment = FALSE; |
| 4251 | } |
| 4252 | else if (prev == '/' && line[i] == '*') |
| 4253 | { |
| 4254 | incomment = TRUE; |
| 4255 | } |
| 4256 | else if (prev == '/' && line[i] == '/') |
| 4257 | { |
| 4258 | return FALSE; |
| 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | prev = line[i]; |
| 4263 | } |
| 4264 | |
| 4265 | return incomment == FALSE && instring == 0; |
| 4266 | } |
| 4267 | |
| 4268 | /* |
Bram Moolenaar | f75a963 | 2005-09-13 21:20:47 +0000 | [diff] [blame] | 4269 | * Search for variable declaration of "ptr[len]". |
| 4270 | * When "locally" is TRUE in the current function ("gd"), otherwise in the |
| 4271 | * current file ("gD"). |
| 4272 | * When "thisblock" is TRUE check the {} block scope. |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4273 | * Return FAIL when not found. |
| 4274 | */ |
| 4275 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4276 | find_decl( |
| 4277 | char_u *ptr, |
| 4278 | int len, |
| 4279 | int locally, |
| 4280 | int thisblock, |
Bram Moolenaar | 23c60f2 | 2016-06-15 22:03:48 +0200 | [diff] [blame] | 4281 | int flags_arg) /* flags passed to searchit() */ |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4282 | { |
| 4283 | char_u *pat; |
| 4284 | pos_T old_pos; |
| 4285 | pos_T par_pos; |
| 4286 | pos_T found_pos; |
| 4287 | int t; |
| 4288 | int save_p_ws; |
| 4289 | int save_p_scs; |
| 4290 | int retval = OK; |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 4291 | int incll; |
Bram Moolenaar | 23c60f2 | 2016-06-15 22:03:48 +0200 | [diff] [blame] | 4292 | int searchflags = flags_arg; |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4293 | int valid; |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4294 | |
| 4295 | if ((pat = alloc(len + 7)) == NULL) |
| 4296 | return FAIL; |
Bram Moolenaar | d9d3058 | 2005-05-18 22:10:28 +0000 | [diff] [blame] | 4297 | |
| 4298 | /* Put "\V" before the pattern to avoid that the special meaning of "." |
| 4299 | * and "~" causes trouble. */ |
| 4300 | sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", |
| 4301 | len, ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4302 | old_pos = curwin->w_cursor; |
| 4303 | save_p_ws = p_ws; |
| 4304 | save_p_scs = p_scs; |
| 4305 | p_ws = FALSE; /* don't wrap around end of file now */ |
| 4306 | p_scs = FALSE; /* don't switch ignorecase off now */ |
| 4307 | |
| 4308 | /* |
| 4309 | * With "gD" go to line 1. |
| 4310 | * With "gd" Search back for the start of the current function, then go |
| 4311 | * back until a blank line. If this fails go to line 1. |
| 4312 | */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 4313 | if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4314 | { |
| 4315 | setpcmark(); /* Set in findpar() otherwise */ |
| 4316 | curwin->w_cursor.lnum = 1; |
Bram Moolenaar | bb15b65 | 2005-10-03 21:52:09 +0000 | [diff] [blame] | 4317 | par_pos = curwin->w_cursor; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4318 | } |
| 4319 | else |
| 4320 | { |
Bram Moolenaar | bb15b65 | 2005-10-03 21:52:09 +0000 | [diff] [blame] | 4321 | par_pos = curwin->w_cursor; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4322 | while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
| 4323 | --curwin->w_cursor.lnum; |
| 4324 | } |
| 4325 | curwin->w_cursor.col = 0; |
| 4326 | |
| 4327 | /* Search forward for the identifier, ignore comment lines. */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 4328 | CLEAR_POS(&found_pos); |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4329 | for (;;) |
| 4330 | { |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4331 | valid = FALSE; |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4332 | t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD, |
Bram Moolenaar | fbd0b0a | 2017-06-17 18:44:21 +0200 | [diff] [blame] | 4333 | pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4334 | if (curwin->w_cursor.lnum >= old_pos.lnum) |
| 4335 | t = FAIL; /* match after start is failure too */ |
Bram Moolenaar | f75a963 | 2005-09-13 21:20:47 +0000 | [diff] [blame] | 4336 | |
Bram Moolenaar | 0fd9289 | 2006-03-09 22:27:48 +0000 | [diff] [blame] | 4337 | if (thisblock && t != FAIL) |
Bram Moolenaar | f75a963 | 2005-09-13 21:20:47 +0000 | [diff] [blame] | 4338 | { |
| 4339 | pos_T *pos; |
| 4340 | |
| 4341 | /* Check that the block the match is in doesn't end before the |
| 4342 | * position where we started the search from. */ |
| 4343 | if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, |
| 4344 | (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL |
| 4345 | && pos->lnum < old_pos.lnum) |
Bram Moolenaar | 60402d6 | 2017-04-20 18:54:50 +0200 | [diff] [blame] | 4346 | { |
| 4347 | /* There can't be a useful match before the end of this block. |
| 4348 | * Skip to the end. */ |
| 4349 | curwin->w_cursor = *pos; |
Bram Moolenaar | f75a963 | 2005-09-13 21:20:47 +0000 | [diff] [blame] | 4350 | continue; |
Bram Moolenaar | 60402d6 | 2017-04-20 18:54:50 +0200 | [diff] [blame] | 4351 | } |
Bram Moolenaar | f75a963 | 2005-09-13 21:20:47 +0000 | [diff] [blame] | 4352 | } |
| 4353 | |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4354 | if (t == FAIL) |
| 4355 | { |
| 4356 | /* If we previously found a valid position, use it. */ |
| 4357 | if (found_pos.lnum != 0) |
| 4358 | { |
| 4359 | curwin->w_cursor = found_pos; |
| 4360 | t = OK; |
| 4361 | } |
| 4362 | break; |
| 4363 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4364 | #ifdef FEAT_COMMENTS |
Bram Moolenaar | 8134039 | 2012-06-06 16:12:59 +0200 | [diff] [blame] | 4365 | if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4366 | { |
| 4367 | /* Ignore this line, continue at start of next line. */ |
| 4368 | ++curwin->w_cursor.lnum; |
| 4369 | curwin->w_cursor.col = 0; |
| 4370 | continue; |
| 4371 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4372 | #endif |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4373 | valid = is_ident(ml_get_curline(), curwin->w_cursor.col); |
| 4374 | |
| 4375 | /* If the current position is not a valid identifier and a previous |
| 4376 | * match is present, favor that one instead. */ |
| 4377 | if (!valid && found_pos.lnum != 0) |
| 4378 | { |
| 4379 | curwin->w_cursor = found_pos; |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4380 | break; |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | /* Global search: use first valid match found */ |
| 4384 | if (valid && !locally) |
| 4385 | break; |
| 4386 | if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4387 | { |
| 4388 | /* If we previously found a valid position, use it. */ |
| 4389 | if (found_pos.lnum != 0) |
| 4390 | curwin->w_cursor = found_pos; |
| 4391 | break; |
| 4392 | } |
| 4393 | |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4394 | /* For finding a local variable and the match is before the "{" or |
| 4395 | * inside a comment, continue searching. For K&R style function |
| 4396 | * declarations this skips the function header without types. */ |
| 4397 | if (!valid) |
| 4398 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 4399 | CLEAR_POS(&found_pos); |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4400 | } |
| 4401 | else |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4402 | found_pos = curwin->w_cursor; |
Bram Moolenaar | 226630a | 2016-10-08 19:21:31 +0200 | [diff] [blame] | 4403 | /* Remove SEARCH_START from flags to avoid getting stuck at one |
| 4404 | * position. */ |
Bram Moolenaar | 23c60f2 | 2016-06-15 22:03:48 +0200 | [diff] [blame] | 4405 | searchflags &= ~SEARCH_START; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4406 | } |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4407 | |
| 4408 | if (t == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4409 | { |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4410 | retval = FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4411 | curwin->w_cursor = old_pos; |
| 4412 | } |
| 4413 | else |
| 4414 | { |
| 4415 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4416 | /* "n" searches forward now */ |
| 4417 | reset_search_dir(); |
| 4418 | } |
| 4419 | |
| 4420 | vim_free(pat); |
| 4421 | p_ws = save_p_ws; |
| 4422 | p_scs = save_p_scs; |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 4423 | |
| 4424 | return retval; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | /* |
| 4428 | * Move 'dist' lines in direction 'dir', counting lines by *screen* |
| 4429 | * lines rather than lines in the file. |
| 4430 | * 'dist' must be positive. |
| 4431 | * |
| 4432 | * Return OK if able to move cursor, FAIL otherwise. |
| 4433 | */ |
| 4434 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4435 | nv_screengo(oparg_T *oap, int dir, long dist) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4436 | { |
| 4437 | int linelen = linetabsize(ml_get_curline()); |
| 4438 | int retval = OK; |
| 4439 | int atend = FALSE; |
| 4440 | int n; |
| 4441 | int col_off1; /* margin offset for first screen line */ |
| 4442 | int col_off2; /* margin offset for wrapped screen line */ |
| 4443 | int width1; /* text width for first screen line */ |
| 4444 | int width2; /* test width for wrapped screen line */ |
| 4445 | |
| 4446 | oap->motion_type = MCHAR; |
Bram Moolenaar | 91b2bdb | 2013-07-14 13:32:15 +0200 | [diff] [blame] | 4447 | oap->inclusive = (curwin->w_curswant == MAXCOL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4448 | |
| 4449 | col_off1 = curwin_col_off(); |
| 4450 | col_off2 = col_off1 - curwin_col_off2(); |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 4451 | width1 = curwin->w_width - col_off1; |
| 4452 | width2 = curwin->w_width - col_off2; |
Bram Moolenaar | 7cc8ec4 | 2015-01-27 20:59:31 +0100 | [diff] [blame] | 4453 | if (width2 == 0) |
| 4454 | width2 = 1; /* avoid divide by zero */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4455 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4456 | if (curwin->w_width != 0) |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 4457 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4458 | /* |
| 4459 | * Instead of sticking at the last character of the buffer line we |
| 4460 | * try to stick in the last column of the screen. |
| 4461 | */ |
| 4462 | if (curwin->w_curswant == MAXCOL) |
| 4463 | { |
| 4464 | atend = TRUE; |
| 4465 | validate_virtcol(); |
| 4466 | if (width1 <= 0) |
| 4467 | curwin->w_curswant = 0; |
| 4468 | else |
| 4469 | { |
| 4470 | curwin->w_curswant = width1 - 1; |
| 4471 | if (curwin->w_virtcol > curwin->w_curswant) |
| 4472 | curwin->w_curswant += ((curwin->w_virtcol |
| 4473 | - curwin->w_curswant - 1) / width2 + 1) * width2; |
| 4474 | } |
| 4475 | } |
| 4476 | else |
| 4477 | { |
| 4478 | if (linelen > width1) |
| 4479 | n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; |
| 4480 | else |
| 4481 | n = width1; |
| 4482 | if (curwin->w_curswant > (colnr_T)n + 1) |
| 4483 | curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) |
| 4484 | * width2; |
| 4485 | } |
| 4486 | |
| 4487 | while (dist--) |
| 4488 | { |
| 4489 | if (dir == BACKWARD) |
| 4490 | { |
| 4491 | if ((long)curwin->w_curswant >= width2) |
| 4492 | /* move back within line */ |
| 4493 | curwin->w_curswant -= width2; |
| 4494 | else |
| 4495 | { |
| 4496 | /* to previous line */ |
| 4497 | if (curwin->w_cursor.lnum == 1) |
| 4498 | { |
| 4499 | retval = FAIL; |
| 4500 | break; |
| 4501 | } |
| 4502 | --curwin->w_cursor.lnum; |
| 4503 | #ifdef FEAT_FOLDING |
| 4504 | /* Move to the start of a closed fold. Don't do that when |
| 4505 | * 'foldopen' contains "all": it will open in a moment. */ |
| 4506 | if (!(fdo_flags & FDO_ALL)) |
| 4507 | (void)hasFolding(curwin->w_cursor.lnum, |
| 4508 | &curwin->w_cursor.lnum, NULL); |
| 4509 | #endif |
| 4510 | linelen = linetabsize(ml_get_curline()); |
| 4511 | if (linelen > width1) |
| 4512 | curwin->w_curswant += (((linelen - width1 - 1) / width2) |
| 4513 | + 1) * width2; |
| 4514 | } |
| 4515 | } |
| 4516 | else /* dir == FORWARD */ |
| 4517 | { |
| 4518 | if (linelen > width1) |
| 4519 | n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; |
| 4520 | else |
| 4521 | n = width1; |
| 4522 | if (curwin->w_curswant + width2 < (colnr_T)n) |
| 4523 | /* move forward within line */ |
| 4524 | curwin->w_curswant += width2; |
| 4525 | else |
| 4526 | { |
| 4527 | /* to next line */ |
| 4528 | #ifdef FEAT_FOLDING |
| 4529 | /* Move to the end of a closed fold. */ |
| 4530 | (void)hasFolding(curwin->w_cursor.lnum, NULL, |
| 4531 | &curwin->w_cursor.lnum); |
| 4532 | #endif |
| 4533 | if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) |
| 4534 | { |
| 4535 | retval = FAIL; |
| 4536 | break; |
| 4537 | } |
| 4538 | curwin->w_cursor.lnum++; |
| 4539 | curwin->w_curswant %= width2; |
Bram Moolenaar | 914968e | 2011-06-20 00:45:58 +0200 | [diff] [blame] | 4540 | linelen = linetabsize(ml_get_curline()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4541 | } |
| 4542 | } |
| 4543 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4544 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4545 | |
Bram Moolenaar | 6cd3aee | 2014-01-14 13:18:58 +0100 | [diff] [blame] | 4546 | if (virtual_active() && atend) |
| 4547 | coladvance(MAXCOL); |
| 4548 | else |
| 4549 | coladvance(curwin->w_curswant); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4550 | |
| 4551 | #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
| 4552 | if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
| 4553 | { |
Bram Moolenaar | 773b158 | 2014-08-29 14:20:51 +0200 | [diff] [blame] | 4554 | colnr_T virtcol; |
| 4555 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4556 | /* |
| 4557 | * Check for landing on a character that got split at the end of the |
| 4558 | * last line. We want to advance a screenline, not end up in the same |
| 4559 | * screenline or move two screenlines. |
| 4560 | */ |
| 4561 | validate_virtcol(); |
Bram Moolenaar | 773b158 | 2014-08-29 14:20:51 +0200 | [diff] [blame] | 4562 | virtcol = curwin->w_virtcol; |
Bram Moolenaar | 84d8cdd | 2014-08-30 13:32:06 +0200 | [diff] [blame] | 4563 | # if defined(FEAT_LINEBREAK) |
Bram Moolenaar | 773b158 | 2014-08-29 14:20:51 +0200 | [diff] [blame] | 4564 | if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
| 4565 | virtcol -= vim_strsize(p_sbr); |
Bram Moolenaar | 84d8cdd | 2014-08-30 13:32:06 +0200 | [diff] [blame] | 4566 | # endif |
Bram Moolenaar | 773b158 | 2014-08-29 14:20:51 +0200 | [diff] [blame] | 4567 | |
| 4568 | if (virtcol > curwin->w_curswant |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4569 | && (curwin->w_curswant < (colnr_T)width1 |
| 4570 | ? (curwin->w_curswant > (colnr_T)width1 / 2) |
| 4571 | : ((curwin->w_curswant - width1) % width2 |
| 4572 | > (colnr_T)width2 / 2))) |
| 4573 | --curwin->w_cursor.col; |
| 4574 | } |
| 4575 | #endif |
| 4576 | |
| 4577 | if (atend) |
| 4578 | curwin->w_curswant = MAXCOL; /* stick in the last column */ |
| 4579 | |
| 4580 | return retval; |
| 4581 | } |
| 4582 | |
| 4583 | #ifdef FEAT_MOUSE |
| 4584 | /* |
| 4585 | * Mouse scroll wheel: Default action is to scroll three lines, or one page |
| 4586 | * when Shift or Ctrl is used. |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4587 | * K_MOUSEUP (cap->arg == 1) or K_MOUSEDOWN (cap->arg == 0) or |
| 4588 | * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4589 | */ |
| 4590 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4591 | nv_mousescroll(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4592 | { |
Bram Moolenaar | 989a70c | 2017-08-16 22:46:01 +0200 | [diff] [blame] | 4593 | win_T *old_curwin = curwin, *wp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4594 | |
Bram Moolenaar | 40cf4b4 | 2013-02-26 13:30:32 +0100 | [diff] [blame] | 4595 | if (mouse_row >= 0 && mouse_col >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4596 | { |
| 4597 | int row, col; |
| 4598 | |
| 4599 | row = mouse_row; |
| 4600 | col = mouse_col; |
| 4601 | |
| 4602 | /* find the window at the pointer coordinates */ |
Bram Moolenaar | 989a70c | 2017-08-16 22:46:01 +0200 | [diff] [blame] | 4603 | wp = mouse_find_win(&row, &col); |
| 4604 | if (wp == NULL) |
| 4605 | return; |
| 4606 | curwin = wp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4607 | curbuf = curwin->w_buffer; |
| 4608 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4609 | |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4610 | if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4611 | { |
Bram Moolenaar | 98fd66d | 2017-08-05 19:34:47 +0200 | [diff] [blame] | 4612 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d81974 | 2017-08-06 14:57:49 +0200 | [diff] [blame] | 4613 | if (term_use_loop()) |
Bram Moolenaar | 98fd66d | 2017-08-05 19:34:47 +0200 | [diff] [blame] | 4614 | send_keys_to_term(curbuf->b_term, cap->cmdchar, TRUE); |
| 4615 | else |
| 4616 | # endif |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4617 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
| 4618 | { |
| 4619 | (void)onepage(cap->arg ? FORWARD : BACKWARD, 1L); |
| 4620 | } |
| 4621 | else |
| 4622 | { |
| 4623 | cap->count1 = 3; |
| 4624 | cap->count0 = 3; |
| 4625 | nv_scroll_line(cap); |
| 4626 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4627 | } |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4628 | # ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4629 | else |
| 4630 | { |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4631 | /* Horizontal scroll - only allowed when 'wrap' is disabled */ |
| 4632 | if (!curwin->w_p_wrap) |
| 4633 | { |
| 4634 | int val, step = 6; |
Bram Moolenaar | 5e109c4 | 2010-07-26 22:51:28 +0200 | [diff] [blame] | 4635 | |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4636 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 4637 | step = curwin->w_width; |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4638 | val = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step); |
| 4639 | if (val < 0) |
| 4640 | val = 0; |
| 4641 | |
| 4642 | gui_do_horiz_scroll(val, TRUE); |
| 4643 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4644 | } |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 4645 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4646 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4647 | curwin->w_redr_status = TRUE; |
| 4648 | |
| 4649 | curwin = old_curwin; |
| 4650 | curbuf = curwin->w_buffer; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | /* |
| 4654 | * Mouse clicks and drags. |
| 4655 | */ |
| 4656 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4657 | nv_mouse(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4658 | { |
| 4659 | (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); |
| 4660 | } |
| 4661 | #endif |
| 4662 | |
| 4663 | /* |
| 4664 | * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. |
| 4665 | * cap->arg must be TRUE for CTRL-E. |
| 4666 | */ |
| 4667 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4668 | nv_scroll_line(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4669 | { |
| 4670 | if (!checkclearop(cap->oap)) |
| 4671 | scroll_redraw(cap->arg, cap->count1); |
| 4672 | } |
| 4673 | |
| 4674 | /* |
| 4675 | * Scroll "count" lines up or down, and redraw. |
| 4676 | */ |
| 4677 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4678 | scroll_redraw(int up, long count) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4679 | { |
| 4680 | linenr_T prev_topline = curwin->w_topline; |
| 4681 | #ifdef FEAT_DIFF |
| 4682 | int prev_topfill = curwin->w_topfill; |
| 4683 | #endif |
| 4684 | linenr_T prev_lnum = curwin->w_cursor.lnum; |
| 4685 | |
| 4686 | if (up) |
| 4687 | scrollup(count, TRUE); |
| 4688 | else |
| 4689 | scrolldown(count, TRUE); |
| 4690 | if (p_so) |
| 4691 | { |
| 4692 | /* Adjust the cursor position for 'scrolloff'. Mark w_topline as |
| 4693 | * valid, otherwise the screen jumps back at the end of the file. */ |
| 4694 | cursor_correct(); |
| 4695 | check_cursor_moved(curwin); |
| 4696 | curwin->w_valid |= VALID_TOPLINE; |
| 4697 | |
| 4698 | /* If moved back to where we were, at least move the cursor, otherwise |
| 4699 | * we get stuck at one position. Don't move the cursor up if the |
| 4700 | * first line of the buffer is already on the screen */ |
| 4701 | while (curwin->w_topline == prev_topline |
| 4702 | #ifdef FEAT_DIFF |
| 4703 | && curwin->w_topfill == prev_topfill |
| 4704 | #endif |
| 4705 | ) |
| 4706 | { |
| 4707 | if (up) |
| 4708 | { |
| 4709 | if (curwin->w_cursor.lnum > prev_lnum |
| 4710 | || cursor_down(1L, FALSE) == FAIL) |
| 4711 | break; |
| 4712 | } |
| 4713 | else |
| 4714 | { |
| 4715 | if (curwin->w_cursor.lnum < prev_lnum |
| 4716 | || prev_topline == 1L |
| 4717 | || cursor_up(1L, FALSE) == FAIL) |
| 4718 | break; |
| 4719 | } |
| 4720 | /* Mark w_topline as valid, otherwise the screen jumps back at the |
| 4721 | * end of the file. */ |
| 4722 | check_cursor_moved(curwin); |
| 4723 | curwin->w_valid |= VALID_TOPLINE; |
| 4724 | } |
| 4725 | } |
| 4726 | if (curwin->w_cursor.lnum != prev_lnum) |
| 4727 | coladvance(curwin->w_curswant); |
| 4728 | redraw_later(VALID); |
| 4729 | } |
| 4730 | |
| 4731 | /* |
| 4732 | * Commands that start with "z". |
| 4733 | */ |
| 4734 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4735 | nv_zet(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4736 | { |
| 4737 | long n; |
| 4738 | colnr_T col; |
| 4739 | int nchar = cap->nchar; |
| 4740 | #ifdef FEAT_FOLDING |
| 4741 | long old_fdl = curwin->w_p_fdl; |
| 4742 | int old_fen = curwin->w_p_fen; |
| 4743 | #endif |
Bram Moolenaar | f71a3db | 2006-03-12 21:50:18 +0000 | [diff] [blame] | 4744 | #ifdef FEAT_SPELL |
Bram Moolenaar | d0131a8 | 2006-03-04 21:46:13 +0000 | [diff] [blame] | 4745 | int undo = FALSE; |
| 4746 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4747 | |
| 4748 | if (VIM_ISDIGIT(nchar)) |
| 4749 | { |
| 4750 | /* |
| 4751 | * "z123{nchar}": edit the count before obtaining {nchar} |
| 4752 | */ |
| 4753 | if (checkclearop(cap->oap)) |
| 4754 | return; |
| 4755 | n = nchar - '0'; |
| 4756 | for (;;) |
| 4757 | { |
| 4758 | #ifdef USE_ON_FLY_SCROLL |
| 4759 | dont_scroll = TRUE; /* disallow scrolling here */ |
| 4760 | #endif |
| 4761 | ++no_mapping; |
| 4762 | ++allow_keys; /* no mapping for nchar, but allow key codes */ |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 4763 | nchar = plain_vgetc(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4764 | LANGMAP_ADJUST(nchar, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4765 | --no_mapping; |
| 4766 | --allow_keys; |
| 4767 | #ifdef FEAT_CMDL_INFO |
| 4768 | (void)add_to_showcmd(nchar); |
| 4769 | #endif |
| 4770 | if (nchar == K_DEL || nchar == K_KDEL) |
| 4771 | n /= 10; |
| 4772 | else if (VIM_ISDIGIT(nchar)) |
| 4773 | n = n * 10 + (nchar - '0'); |
| 4774 | else if (nchar == CAR) |
| 4775 | { |
| 4776 | #ifdef FEAT_GUI |
| 4777 | need_mouse_correct = TRUE; |
| 4778 | #endif |
| 4779 | win_setheight((int)n); |
| 4780 | break; |
| 4781 | } |
| 4782 | else if (nchar == 'l' |
| 4783 | || nchar == 'h' |
| 4784 | || nchar == K_LEFT |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 4785 | || nchar == K_RIGHT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4786 | { |
| 4787 | cap->count1 = n ? n * cap->count1 : cap->count1; |
| 4788 | goto dozet; |
| 4789 | } |
| 4790 | else |
| 4791 | { |
| 4792 | clearopbeep(cap->oap); |
| 4793 | break; |
| 4794 | } |
| 4795 | } |
| 4796 | cap->oap->op_type = OP_NOP; |
| 4797 | return; |
| 4798 | } |
| 4799 | |
| 4800 | dozet: |
| 4801 | if ( |
| 4802 | #ifdef FEAT_FOLDING |
| 4803 | /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" |
| 4804 | * and "zC" only in Visual mode. "zj" and "zk" are motion |
| 4805 | * commands. */ |
| 4806 | cap->nchar != 'f' && cap->nchar != 'F' |
| 4807 | && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) |
| 4808 | && cap->nchar != 'j' && cap->nchar != 'k' |
| 4809 | && |
| 4810 | #endif |
| 4811 | checkclearop(cap->oap)) |
| 4812 | return; |
| 4813 | |
| 4814 | /* |
| 4815 | * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": |
| 4816 | * If line number given, set cursor. |
| 4817 | */ |
| 4818 | if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) |
| 4819 | && cap->count0 |
| 4820 | && cap->count0 != curwin->w_cursor.lnum) |
| 4821 | { |
| 4822 | setpcmark(); |
| 4823 | if (cap->count0 > curbuf->b_ml.ml_line_count) |
| 4824 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 4825 | else |
| 4826 | curwin->w_cursor.lnum = cap->count0; |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 4827 | check_cursor_col(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | switch (nchar) |
| 4831 | { |
| 4832 | /* "z+", "z<CR>" and "zt": put cursor at top of screen */ |
| 4833 | case '+': |
| 4834 | if (cap->count0 == 0) |
| 4835 | { |
| 4836 | /* No count given: put cursor at the line below screen */ |
| 4837 | validate_botline(); /* make sure w_botline is valid */ |
| 4838 | if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
| 4839 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 4840 | else |
| 4841 | curwin->w_cursor.lnum = curwin->w_botline; |
| 4842 | } |
| 4843 | /* FALLTHROUGH */ |
| 4844 | case NL: |
| 4845 | case CAR: |
| 4846 | case K_KENTER: |
| 4847 | beginline(BL_WHITE | BL_FIX); |
| 4848 | /* FALLTHROUGH */ |
| 4849 | |
| 4850 | case 't': scroll_cursor_top(0, TRUE); |
| 4851 | redraw_later(VALID); |
Bram Moolenaar | 9dc2ce3 | 2015-12-05 19:47:04 +0100 | [diff] [blame] | 4852 | set_fraction(curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4853 | break; |
| 4854 | |
| 4855 | /* "z." and "zz": put cursor in middle of screen */ |
| 4856 | case '.': beginline(BL_WHITE | BL_FIX); |
| 4857 | /* FALLTHROUGH */ |
| 4858 | |
| 4859 | case 'z': scroll_cursor_halfway(TRUE); |
| 4860 | redraw_later(VALID); |
Bram Moolenaar | 9dc2ce3 | 2015-12-05 19:47:04 +0100 | [diff] [blame] | 4861 | set_fraction(curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4862 | break; |
| 4863 | |
| 4864 | /* "z^", "z-" and "zb": put cursor at bottom of screen */ |
| 4865 | case '^': /* Strange Vi behavior: <count>z^ finds line at top of window |
| 4866 | * when <count> is at bottom of window, and puts that one at |
| 4867 | * bottom of window. */ |
| 4868 | if (cap->count0 != 0) |
| 4869 | { |
| 4870 | scroll_cursor_bot(0, TRUE); |
| 4871 | curwin->w_cursor.lnum = curwin->w_topline; |
| 4872 | } |
| 4873 | else if (curwin->w_topline == 1) |
| 4874 | curwin->w_cursor.lnum = 1; |
| 4875 | else |
| 4876 | curwin->w_cursor.lnum = curwin->w_topline - 1; |
| 4877 | /* FALLTHROUGH */ |
| 4878 | case '-': |
| 4879 | beginline(BL_WHITE | BL_FIX); |
| 4880 | /* FALLTHROUGH */ |
| 4881 | |
| 4882 | case 'b': scroll_cursor_bot(0, TRUE); |
| 4883 | redraw_later(VALID); |
Bram Moolenaar | 9dc2ce3 | 2015-12-05 19:47:04 +0100 | [diff] [blame] | 4884 | set_fraction(curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4885 | break; |
| 4886 | |
| 4887 | /* "zH" - scroll screen right half-page */ |
| 4888 | case 'H': |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 4889 | cap->count1 *= curwin->w_width / 2; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4890 | /* FALLTHROUGH */ |
| 4891 | |
| 4892 | /* "zh" - scroll screen to the right */ |
| 4893 | case 'h': |
| 4894 | case K_LEFT: |
| 4895 | if (!curwin->w_p_wrap) |
| 4896 | { |
| 4897 | if ((colnr_T)cap->count1 > curwin->w_leftcol) |
| 4898 | curwin->w_leftcol = 0; |
| 4899 | else |
| 4900 | curwin->w_leftcol -= (colnr_T)cap->count1; |
| 4901 | leftcol_changed(); |
| 4902 | } |
| 4903 | break; |
| 4904 | |
| 4905 | /* "zL" - scroll screen left half-page */ |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 4906 | case 'L': cap->count1 *= curwin->w_width / 2; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4907 | /* FALLTHROUGH */ |
| 4908 | |
| 4909 | /* "zl" - scroll screen to the left */ |
| 4910 | case 'l': |
| 4911 | case K_RIGHT: |
| 4912 | if (!curwin->w_p_wrap) |
| 4913 | { |
| 4914 | /* scroll the window left */ |
| 4915 | curwin->w_leftcol += (colnr_T)cap->count1; |
| 4916 | leftcol_changed(); |
| 4917 | } |
| 4918 | break; |
| 4919 | |
| 4920 | /* "zs" - scroll screen, cursor at the start */ |
| 4921 | case 's': if (!curwin->w_p_wrap) |
| 4922 | { |
| 4923 | #ifdef FEAT_FOLDING |
| 4924 | if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 4925 | col = 0; /* like the cursor is in col 0 */ |
| 4926 | else |
| 4927 | #endif |
| 4928 | getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); |
| 4929 | if ((long)col > p_siso) |
| 4930 | col -= p_siso; |
| 4931 | else |
| 4932 | col = 0; |
| 4933 | if (curwin->w_leftcol != col) |
| 4934 | { |
| 4935 | curwin->w_leftcol = col; |
| 4936 | redraw_later(NOT_VALID); |
| 4937 | } |
| 4938 | } |
| 4939 | break; |
| 4940 | |
| 4941 | /* "ze" - scroll screen, cursor at the end */ |
| 4942 | case 'e': if (!curwin->w_p_wrap) |
| 4943 | { |
| 4944 | #ifdef FEAT_FOLDING |
| 4945 | if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 4946 | col = 0; /* like the cursor is in col 0 */ |
| 4947 | else |
| 4948 | #endif |
| 4949 | getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 4950 | n = curwin->w_width - curwin_col_off(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4951 | if ((long)col + p_siso < n) |
| 4952 | col = 0; |
| 4953 | else |
| 4954 | col = col + p_siso - n + 1; |
| 4955 | if (curwin->w_leftcol != col) |
| 4956 | { |
| 4957 | curwin->w_leftcol = col; |
| 4958 | redraw_later(NOT_VALID); |
| 4959 | } |
| 4960 | } |
| 4961 | break; |
| 4962 | |
| 4963 | #ifdef FEAT_FOLDING |
| 4964 | /* "zF": create fold command */ |
| 4965 | /* "zf": create fold operator */ |
| 4966 | case 'F': |
| 4967 | case 'f': if (foldManualAllowed(TRUE)) |
| 4968 | { |
| 4969 | cap->nchar = 'f'; |
| 4970 | nv_operator(cap); |
| 4971 | curwin->w_p_fen = TRUE; |
| 4972 | |
| 4973 | /* "zF" is like "zfzf" */ |
| 4974 | if (nchar == 'F' && cap->oap->op_type == OP_FOLD) |
| 4975 | { |
| 4976 | nv_operator(cap); |
| 4977 | finish_op = TRUE; |
| 4978 | } |
| 4979 | } |
| 4980 | else |
| 4981 | clearopbeep(cap->oap); |
| 4982 | break; |
| 4983 | |
| 4984 | /* "zd": delete fold at cursor */ |
| 4985 | /* "zD": delete fold at cursor recursively */ |
| 4986 | case 'd': |
| 4987 | case 'D': if (foldManualAllowed(FALSE)) |
| 4988 | { |
| 4989 | if (VIsual_active) |
| 4990 | nv_operator(cap); |
| 4991 | else |
| 4992 | deleteFold(curwin->w_cursor.lnum, |
| 4993 | curwin->w_cursor.lnum, nchar == 'D', FALSE); |
| 4994 | } |
| 4995 | break; |
| 4996 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4997 | /* "zE": erase all folds */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4998 | case 'E': if (foldmethodIsManual(curwin)) |
| 4999 | { |
| 5000 | clearFolding(curwin); |
| 5001 | changed_window_setting(); |
| 5002 | } |
| 5003 | else if (foldmethodIsMarker(curwin)) |
| 5004 | deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, |
| 5005 | TRUE, FALSE); |
| 5006 | else |
| 5007 | EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); |
| 5008 | break; |
| 5009 | |
| 5010 | /* "zn": fold none: reset 'foldenable' */ |
| 5011 | case 'n': curwin->w_p_fen = FALSE; |
| 5012 | break; |
| 5013 | |
| 5014 | /* "zN": fold Normal: set 'foldenable' */ |
| 5015 | case 'N': curwin->w_p_fen = TRUE; |
| 5016 | break; |
| 5017 | |
| 5018 | /* "zi": invert folding: toggle 'foldenable' */ |
| 5019 | case 'i': curwin->w_p_fen = !curwin->w_p_fen; |
| 5020 | break; |
| 5021 | |
| 5022 | /* "za": open closed fold or close open fold at cursor */ |
| 5023 | case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 5024 | openFold(curwin->w_cursor.lnum, cap->count1); |
| 5025 | else |
| 5026 | { |
| 5027 | closeFold(curwin->w_cursor.lnum, cap->count1); |
| 5028 | curwin->w_p_fen = TRUE; |
| 5029 | } |
| 5030 | break; |
| 5031 | |
| 5032 | /* "zA": open fold at cursor recursively */ |
| 5033 | case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 5034 | openFoldRecurse(curwin->w_cursor.lnum); |
| 5035 | else |
| 5036 | { |
| 5037 | closeFoldRecurse(curwin->w_cursor.lnum); |
| 5038 | curwin->w_p_fen = TRUE; |
| 5039 | } |
| 5040 | break; |
| 5041 | |
| 5042 | /* "zo": open fold at cursor or Visual area */ |
| 5043 | case 'o': if (VIsual_active) |
| 5044 | nv_operator(cap); |
| 5045 | else |
| 5046 | openFold(curwin->w_cursor.lnum, cap->count1); |
| 5047 | break; |
| 5048 | |
| 5049 | /* "zO": open fold recursively */ |
| 5050 | case 'O': if (VIsual_active) |
| 5051 | nv_operator(cap); |
| 5052 | else |
| 5053 | openFoldRecurse(curwin->w_cursor.lnum); |
| 5054 | break; |
| 5055 | |
| 5056 | /* "zc": close fold at cursor or Visual area */ |
| 5057 | case 'c': if (VIsual_active) |
| 5058 | nv_operator(cap); |
| 5059 | else |
| 5060 | closeFold(curwin->w_cursor.lnum, cap->count1); |
| 5061 | curwin->w_p_fen = TRUE; |
| 5062 | break; |
| 5063 | |
| 5064 | /* "zC": close fold recursively */ |
| 5065 | case 'C': if (VIsual_active) |
| 5066 | nv_operator(cap); |
| 5067 | else |
| 5068 | closeFoldRecurse(curwin->w_cursor.lnum); |
| 5069 | curwin->w_p_fen = TRUE; |
| 5070 | break; |
| 5071 | |
| 5072 | /* "zv": open folds at the cursor */ |
| 5073 | case 'v': foldOpenCursor(); |
| 5074 | break; |
| 5075 | |
| 5076 | /* "zx": re-apply 'foldlevel' and open folds at the cursor */ |
| 5077 | case 'x': curwin->w_p_fen = TRUE; |
Bram Moolenaar | 38ab0e2 | 2010-05-13 17:35:59 +0200 | [diff] [blame] | 5078 | curwin->w_foldinvalid = TRUE; /* recompute folds */ |
| 5079 | newFoldLevel(); /* update right now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5080 | foldOpenCursor(); |
| 5081 | break; |
| 5082 | |
| 5083 | /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ |
| 5084 | case 'X': curwin->w_p_fen = TRUE; |
Bram Moolenaar | 38ab0e2 | 2010-05-13 17:35:59 +0200 | [diff] [blame] | 5085 | curwin->w_foldinvalid = TRUE; /* recompute folds */ |
| 5086 | old_fdl = -1; /* force an update */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5087 | break; |
| 5088 | |
| 5089 | /* "zm": fold more */ |
| 5090 | case 'm': if (curwin->w_p_fdl > 0) |
Bram Moolenaar | 7d2757a | 2015-03-31 17:46:22 +0200 | [diff] [blame] | 5091 | { |
| 5092 | curwin->w_p_fdl -= cap->count1; |
| 5093 | if (curwin->w_p_fdl < 0) |
| 5094 | curwin->w_p_fdl = 0; |
| 5095 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5096 | old_fdl = -1; /* force an update */ |
| 5097 | curwin->w_p_fen = TRUE; |
| 5098 | break; |
| 5099 | |
| 5100 | /* "zM": close all folds */ |
| 5101 | case 'M': curwin->w_p_fdl = 0; |
| 5102 | old_fdl = -1; /* force an update */ |
| 5103 | curwin->w_p_fen = TRUE; |
| 5104 | break; |
| 5105 | |
| 5106 | /* "zr": reduce folding */ |
Bram Moolenaar | 7d2757a | 2015-03-31 17:46:22 +0200 | [diff] [blame] | 5107 | case 'r': curwin->w_p_fdl += cap->count1; |
| 5108 | { |
| 5109 | int d = getDeepestNesting(); |
| 5110 | |
| 5111 | if (curwin->w_p_fdl >= d) |
| 5112 | curwin->w_p_fdl = d; |
| 5113 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5114 | break; |
| 5115 | |
| 5116 | /* "zR": open all folds */ |
| 5117 | case 'R': curwin->w_p_fdl = getDeepestNesting(); |
| 5118 | old_fdl = -1; /* force an update */ |
| 5119 | break; |
| 5120 | |
| 5121 | case 'j': /* "zj" move to next fold downwards */ |
| 5122 | case 'k': /* "zk" move to next fold upwards */ |
| 5123 | if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, |
| 5124 | cap->count1) == FAIL) |
| 5125 | clearopbeep(cap->oap); |
| 5126 | break; |
| 5127 | |
| 5128 | #endif /* FEAT_FOLDING */ |
| 5129 | |
Bram Moolenaar | f71a3db | 2006-03-12 21:50:18 +0000 | [diff] [blame] | 5130 | #ifdef FEAT_SPELL |
Bram Moolenaar | d0131a8 | 2006-03-04 21:46:13 +0000 | [diff] [blame] | 5131 | case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
| 5132 | ++no_mapping; |
| 5133 | ++allow_keys; /* no mapping for nchar, but allow key codes */ |
Bram Moolenaar | 61abfd1 | 2007-09-13 16:26:47 +0000 | [diff] [blame] | 5134 | nchar = plain_vgetc(); |
Bram Moolenaar | d0131a8 | 2006-03-04 21:46:13 +0000 | [diff] [blame] | 5135 | LANGMAP_ADJUST(nchar, TRUE); |
Bram Moolenaar | d0131a8 | 2006-03-04 21:46:13 +0000 | [diff] [blame] | 5136 | --no_mapping; |
| 5137 | --allow_keys; |
| 5138 | #ifdef FEAT_CMDL_INFO |
| 5139 | (void)add_to_showcmd(nchar); |
| 5140 | #endif |
| 5141 | if (vim_strchr((char_u *)"gGwW", nchar) == NULL) |
| 5142 | { |
| 5143 | clearopbeep(cap->oap); |
| 5144 | break; |
| 5145 | } |
| 5146 | undo = TRUE; |
| 5147 | /*FALLTHROUGH*/ |
| 5148 | |
Bram Moolenaar | b765d63 | 2005-06-07 21:00:02 +0000 | [diff] [blame] | 5149 | case 'g': /* "zg": add good word to word list */ |
| 5150 | case 'w': /* "zw": add wrong word to word list */ |
Bram Moolenaar | 7887d88 | 2005-07-01 22:33:52 +0000 | [diff] [blame] | 5151 | case 'G': /* "zG": add good word to temp word list */ |
| 5152 | case 'W': /* "zW": add wrong word to temp word list */ |
Bram Moolenaar | b765d63 | 2005-06-07 21:00:02 +0000 | [diff] [blame] | 5153 | { |
| 5154 | char_u *ptr = NULL; |
| 5155 | int len; |
| 5156 | |
| 5157 | if (checkclearop(cap->oap)) |
| 5158 | break; |
Bram Moolenaar | b765d63 | 2005-06-07 21:00:02 +0000 | [diff] [blame] | 5159 | if (VIsual_active && get_visual_text(cap, &ptr, &len) |
| 5160 | == FAIL) |
| 5161 | return; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 5162 | if (ptr == NULL) |
| 5163 | { |
| 5164 | pos_T pos = curwin->w_cursor; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 5165 | |
Bram Moolenaar | 134bf07 | 2013-09-25 18:54:24 +0200 | [diff] [blame] | 5166 | /* Find bad word under the cursor. When 'spell' is |
| 5167 | * off this fails and find_ident_under_cursor() is |
| 5168 | * used below. */ |
| 5169 | emsg_off++; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 5170 | len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
Bram Moolenaar | 134bf07 | 2013-09-25 18:54:24 +0200 | [diff] [blame] | 5171 | emsg_off--; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 5172 | if (len != 0 && curwin->w_cursor.col <= pos.col) |
| 5173 | ptr = ml_get_pos(&curwin->w_cursor); |
| 5174 | curwin->w_cursor = pos; |
| 5175 | } |
| 5176 | |
Bram Moolenaar | b765d63 | 2005-06-07 21:00:02 +0000 | [diff] [blame] | 5177 | if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
| 5178 | FIND_IDENT)) == 0) |
| 5179 | return; |
Bram Moolenaar | 7887d88 | 2005-07-01 22:33:52 +0000 | [diff] [blame] | 5180 | spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
Bram Moolenaar | d0131a8 | 2006-03-04 21:46:13 +0000 | [diff] [blame] | 5181 | (nchar == 'G' || nchar == 'W') |
| 5182 | ? 0 : (int)cap->count1, |
| 5183 | undo); |
Bram Moolenaar | b765d63 | 2005-06-07 21:00:02 +0000 | [diff] [blame] | 5184 | } |
Bram Moolenaar | 3982c54 | 2005-06-08 21:56:31 +0000 | [diff] [blame] | 5185 | break; |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 5186 | |
Bram Moolenaar | 43abc52 | 2005-12-10 20:15:02 +0000 | [diff] [blame] | 5187 | case '=': /* "z=": suggestions for a badly spelled word */ |
Bram Moolenaar | 66fa271 | 2006-01-22 23:22:22 +0000 | [diff] [blame] | 5188 | if (!checkclearop(cap->oap)) |
Bram Moolenaar | d12a132 | 2005-08-21 22:08:24 +0000 | [diff] [blame] | 5189 | spell_suggest((int)cap->count0); |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 5190 | break; |
Bram Moolenaar | b765d63 | 2005-06-07 21:00:02 +0000 | [diff] [blame] | 5191 | #endif |
| 5192 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5193 | default: clearopbeep(cap->oap); |
| 5194 | } |
| 5195 | |
| 5196 | #ifdef FEAT_FOLDING |
| 5197 | /* Redraw when 'foldenable' changed */ |
| 5198 | if (old_fen != curwin->w_p_fen) |
| 5199 | { |
| 5200 | # ifdef FEAT_DIFF |
| 5201 | win_T *wp; |
| 5202 | |
| 5203 | if (foldmethodIsDiff(curwin) && curwin->w_p_scb) |
| 5204 | { |
| 5205 | /* Adjust 'foldenable' in diff-synced windows. */ |
| 5206 | FOR_ALL_WINDOWS(wp) |
| 5207 | { |
| 5208 | if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) |
| 5209 | { |
| 5210 | wp->w_p_fen = curwin->w_p_fen; |
| 5211 | changed_window_setting_win(wp); |
| 5212 | } |
| 5213 | } |
| 5214 | } |
| 5215 | # endif |
| 5216 | changed_window_setting(); |
| 5217 | } |
| 5218 | |
| 5219 | /* Redraw when 'foldlevel' changed. */ |
| 5220 | if (old_fdl != curwin->w_p_fdl) |
| 5221 | newFoldLevel(); |
| 5222 | #endif |
| 5223 | } |
| 5224 | |
| 5225 | #ifdef FEAT_GUI |
| 5226 | /* |
| 5227 | * Vertical scrollbar movement. |
| 5228 | */ |
| 5229 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5230 | nv_ver_scrollbar(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5231 | { |
| 5232 | if (cap->oap->op_type != OP_NOP) |
| 5233 | clearopbeep(cap->oap); |
| 5234 | |
| 5235 | /* Even if an operator was pending, we still want to scroll */ |
| 5236 | gui_do_scroll(); |
| 5237 | } |
| 5238 | |
| 5239 | /* |
| 5240 | * Horizontal scrollbar movement. |
| 5241 | */ |
| 5242 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5243 | nv_hor_scrollbar(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5244 | { |
| 5245 | if (cap->oap->op_type != OP_NOP) |
| 5246 | clearopbeep(cap->oap); |
| 5247 | |
| 5248 | /* Even if an operator was pending, we still want to scroll */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 5249 | gui_do_horiz_scroll(scrollbar_value, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5250 | } |
| 5251 | #endif |
| 5252 | |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 5253 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 5254 | /* |
| 5255 | * Click in GUI tab. |
| 5256 | */ |
| 5257 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5258 | nv_tabline(cmdarg_T *cap) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 5259 | { |
| 5260 | if (cap->oap->op_type != OP_NOP) |
| 5261 | clearopbeep(cap->oap); |
| 5262 | |
| 5263 | /* Even if an operator was pending, we still want to jump tabs. */ |
| 5264 | goto_tabpage(current_tab); |
| 5265 | } |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 5266 | |
| 5267 | /* |
| 5268 | * Selected item in tab line menu. |
| 5269 | */ |
| 5270 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5271 | nv_tabmenu(cmdarg_T *cap) |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 5272 | { |
| 5273 | if (cap->oap->op_type != OP_NOP) |
| 5274 | clearopbeep(cap->oap); |
| 5275 | |
| 5276 | /* Even if an operator was pending, we still want to jump tabs. */ |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 5277 | handle_tabmenu(); |
| 5278 | } |
| 5279 | |
| 5280 | /* |
| 5281 | * Handle selecting an item of the GUI tab line menu. |
| 5282 | * Used in Normal and Insert mode. |
| 5283 | */ |
| 5284 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5285 | handle_tabmenu(void) |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 5286 | { |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 5287 | switch (current_tabmenu) |
| 5288 | { |
| 5289 | case TABLINE_MENU_CLOSE: |
| 5290 | if (current_tab == 0) |
| 5291 | do_cmdline_cmd((char_u *)"tabclose"); |
| 5292 | else |
| 5293 | { |
| 5294 | vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", |
| 5295 | current_tab); |
| 5296 | do_cmdline_cmd(IObuff); |
| 5297 | } |
| 5298 | break; |
| 5299 | |
| 5300 | case TABLINE_MENU_NEW: |
Bram Moolenaar | dfd7691 | 2015-02-27 15:03:58 +0100 | [diff] [blame] | 5301 | if (current_tab == 0) |
| 5302 | do_cmdline_cmd((char_u *)"$tabnew"); |
| 5303 | else |
| 5304 | { |
| 5305 | vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", |
| 5306 | current_tab - 1); |
| 5307 | do_cmdline_cmd(IObuff); |
| 5308 | } |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 5309 | break; |
| 5310 | |
| 5311 | case TABLINE_MENU_OPEN: |
Bram Moolenaar | dfd7691 | 2015-02-27 15:03:58 +0100 | [diff] [blame] | 5312 | if (current_tab == 0) |
| 5313 | do_cmdline_cmd((char_u *)"browse $tabnew"); |
| 5314 | else |
| 5315 | { |
| 5316 | vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", |
| 5317 | current_tab - 1); |
| 5318 | do_cmdline_cmd(IObuff); |
| 5319 | } |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 5320 | break; |
| 5321 | } |
| 5322 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 5323 | #endif |
| 5324 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5325 | /* |
| 5326 | * "Q" command. |
| 5327 | */ |
| 5328 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5329 | nv_exmode(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5330 | { |
| 5331 | /* |
| 5332 | * Ignore 'Q' in Visual mode, just give a beep. |
| 5333 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5334 | if (VIsual_active) |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 5335 | vim_beep(BO_EX); |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5336 | else if (!checkclearop(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5337 | do_exmode(FALSE); |
| 5338 | } |
| 5339 | |
| 5340 | /* |
| 5341 | * Handle a ":" command. |
| 5342 | */ |
| 5343 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5344 | nv_colon(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5345 | { |
| 5346 | int old_p_im; |
Bram Moolenaar | d7fbfe1 | 2013-04-05 17:43:14 +0200 | [diff] [blame] | 5347 | int cmd_result; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5348 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5349 | if (VIsual_active) |
| 5350 | nv_operator(cap); |
| 5351 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5352 | { |
| 5353 | if (cap->oap->op_type != OP_NOP) |
| 5354 | { |
| 5355 | /* Using ":" as a movement is characterwise exclusive. */ |
| 5356 | cap->oap->motion_type = MCHAR; |
| 5357 | cap->oap->inclusive = FALSE; |
| 5358 | } |
| 5359 | else if (cap->count0) |
| 5360 | { |
| 5361 | /* translate "count:" into ":.,.+(count - 1)" */ |
| 5362 | stuffcharReadbuff('.'); |
| 5363 | if (cap->count0 > 1) |
| 5364 | { |
| 5365 | stuffReadbuff((char_u *)",.+"); |
| 5366 | stuffnumReadbuff((long)cap->count0 - 1L); |
| 5367 | } |
| 5368 | } |
| 5369 | |
| 5370 | /* When typing, don't type below an old message */ |
| 5371 | if (KeyTyped) |
| 5372 | compute_cmdrow(); |
| 5373 | |
| 5374 | old_p_im = p_im; |
| 5375 | |
| 5376 | /* get a command line and execute it */ |
Bram Moolenaar | d7fbfe1 | 2013-04-05 17:43:14 +0200 | [diff] [blame] | 5377 | cmd_result = do_cmdline(NULL, getexline, NULL, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5378 | cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
| 5379 | |
| 5380 | /* If 'insertmode' changed, enter or exit Insert mode */ |
| 5381 | if (p_im != old_p_im) |
| 5382 | { |
| 5383 | if (p_im) |
| 5384 | restart_edit = 'i'; |
| 5385 | else |
| 5386 | restart_edit = 0; |
| 5387 | } |
| 5388 | |
Bram Moolenaar | d7fbfe1 | 2013-04-05 17:43:14 +0200 | [diff] [blame] | 5389 | if (cmd_result == FAIL) |
| 5390 | /* The Ex command failed, do not execute the operator. */ |
| 5391 | clearop(cap->oap); |
| 5392 | else if (cap->oap->op_type != OP_NOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5393 | && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
| 5394 | || cap->oap->start.col > |
Bram Moolenaar | d7fbfe1 | 2013-04-05 17:43:14 +0200 | [diff] [blame] | 5395 | (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
| 5396 | || did_emsg |
| 5397 | )) |
| 5398 | /* The start of the operator has become invalid by the Ex command. |
| 5399 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5400 | clearopbeep(cap->oap); |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | /* |
| 5405 | * Handle CTRL-G command. |
| 5406 | */ |
| 5407 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5408 | nv_ctrlg(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5409 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5410 | if (VIsual_active) /* toggle Selection/Visual mode */ |
| 5411 | { |
| 5412 | VIsual_select = !VIsual_select; |
| 5413 | showmode(); |
| 5414 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5415 | else if (!checkclearop(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5416 | /* print full name if count given or :cd used */ |
| 5417 | fileinfo((int)cap->count0, FALSE, TRUE); |
| 5418 | } |
| 5419 | |
| 5420 | /* |
| 5421 | * Handle CTRL-H <Backspace> command. |
| 5422 | */ |
| 5423 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5424 | nv_ctrlh(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5425 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5426 | if (VIsual_active && VIsual_select) |
| 5427 | { |
| 5428 | cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ |
| 5429 | v_visop(cap); |
| 5430 | } |
| 5431 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5432 | nv_left(cap); |
| 5433 | } |
| 5434 | |
| 5435 | /* |
| 5436 | * CTRL-L: clear screen and redraw. |
| 5437 | */ |
| 5438 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5439 | nv_clear(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5440 | { |
| 5441 | if (!checkclearop(cap->oap)) |
| 5442 | { |
| 5443 | #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT |
| 5444 | /* |
| 5445 | * Right now, the BeBox doesn't seem to have an easy way to detect |
| 5446 | * window resizing, so we cheat and make the user detect it |
| 5447 | * manually with CTRL-L instead |
| 5448 | */ |
| 5449 | ui_get_shellsize(); |
| 5450 | #endif |
| 5451 | #ifdef FEAT_SYN_HL |
| 5452 | /* Clear all syntax states to force resyncing. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5453 | syn_stack_free_all(curwin->w_s); |
Bram Moolenaar | 06f1ed2 | 2017-06-18 22:41:03 +0200 | [diff] [blame] | 5454 | # ifdef FEAT_RELTIME |
| 5455 | { |
| 5456 | win_T *wp; |
| 5457 | |
| 5458 | FOR_ALL_WINDOWS(wp) |
| 5459 | wp->w_s->b_syn_slow = FALSE; |
| 5460 | } |
| 5461 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5462 | #endif |
| 5463 | redraw_later(CLEAR); |
| 5464 | } |
| 5465 | } |
| 5466 | |
| 5467 | /* |
| 5468 | * CTRL-O: In Select mode: switch to Visual mode for one command. |
| 5469 | * Otherwise: Go to older pcmark. |
| 5470 | */ |
| 5471 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5472 | nv_ctrlo(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5473 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5474 | if (VIsual_active && VIsual_select) |
| 5475 | { |
| 5476 | VIsual_select = FALSE; |
| 5477 | showmode(); |
| 5478 | restart_VIsual_select = 2; /* restart Select mode later */ |
| 5479 | } |
| 5480 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5481 | { |
| 5482 | cap->count1 = -cap->count1; |
| 5483 | nv_pcmark(cap); |
| 5484 | } |
| 5485 | } |
| 5486 | |
| 5487 | /* |
| 5488 | * CTRL-^ command, short for ":e #" |
| 5489 | */ |
| 5490 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5491 | nv_hat(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5492 | { |
| 5493 | if (!checkclearopq(cap->oap)) |
| 5494 | (void)buflist_getfile((int)cap->count0, (linenr_T)0, |
| 5495 | GETF_SETMARK|GETF_ALT, FALSE); |
| 5496 | } |
| 5497 | |
| 5498 | /* |
| 5499 | * "Z" commands. |
| 5500 | */ |
| 5501 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5502 | nv_Zet(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5503 | { |
| 5504 | if (!checkclearopq(cap->oap)) |
| 5505 | { |
| 5506 | switch (cap->nchar) |
| 5507 | { |
| 5508 | /* "ZZ": equivalent to ":x". */ |
| 5509 | case 'Z': do_cmdline_cmd((char_u *)"x"); |
| 5510 | break; |
| 5511 | |
| 5512 | /* "ZQ": equivalent to ":q!" (Elvis compatible). */ |
| 5513 | case 'Q': do_cmdline_cmd((char_u *)"q!"); |
| 5514 | break; |
| 5515 | |
| 5516 | default: clearopbeep(cap->oap); |
| 5517 | } |
| 5518 | } |
| 5519 | } |
| 5520 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5521 | /* |
| 5522 | * Call nv_ident() as if "c1" was used, with "c2" as next character. |
| 5523 | */ |
| 5524 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5525 | do_nv_ident(int c1, int c2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5526 | { |
| 5527 | oparg_T oa; |
| 5528 | cmdarg_T ca; |
| 5529 | |
| 5530 | clear_oparg(&oa); |
| 5531 | vim_memset(&ca, 0, sizeof(ca)); |
| 5532 | ca.oap = &oa; |
| 5533 | ca.cmdchar = c1; |
| 5534 | ca.nchar = c2; |
| 5535 | nv_ident(&ca); |
| 5536 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5537 | |
| 5538 | /* |
| 5539 | * Handle the commands that use the word under the cursor. |
| 5540 | * [g] CTRL-] :ta to current identifier |
| 5541 | * [g] 'K' run program for current identifier |
| 5542 | * [g] '*' / to current identifier or string |
| 5543 | * [g] '#' ? to current identifier or string |
| 5544 | * g ']' :tselect for current identifier |
| 5545 | */ |
| 5546 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5547 | nv_ident(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5548 | { |
| 5549 | char_u *ptr = NULL; |
| 5550 | char_u *buf; |
Bram Moolenaar | 2ff8b64 | 2016-05-24 10:46:45 +0200 | [diff] [blame] | 5551 | unsigned buflen; |
Bram Moolenaar | 0bc380a | 2010-07-10 13:52:13 +0200 | [diff] [blame] | 5552 | char_u *newbuf; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5553 | char_u *p; |
| 5554 | char_u *kp; /* value of 'keywordprg' */ |
Bram Moolenaar | 2ff8b64 | 2016-05-24 10:46:45 +0200 | [diff] [blame] | 5555 | int kp_help; /* 'keywordprg' is ":he" */ |
| 5556 | int kp_ex; /* 'keywordprg' starts with ":" */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5557 | int n = 0; /* init for GCC */ |
| 5558 | int cmdchar; |
| 5559 | int g_cmd; /* "g" command */ |
Bram Moolenaar | 6d8027a | 2010-01-19 15:24:27 +0100 | [diff] [blame] | 5560 | int tag_cmd = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5561 | char_u *aux_ptr; |
| 5562 | int isman; |
| 5563 | int isman_s; |
| 5564 | |
| 5565 | if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ |
| 5566 | { |
| 5567 | cmdchar = cap->nchar; |
| 5568 | g_cmd = TRUE; |
| 5569 | } |
| 5570 | else |
| 5571 | { |
| 5572 | cmdchar = cap->cmdchar; |
| 5573 | g_cmd = FALSE; |
| 5574 | } |
| 5575 | |
| 5576 | if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ |
| 5577 | cmdchar = '#'; |
| 5578 | |
| 5579 | /* |
| 5580 | * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. |
| 5581 | */ |
| 5582 | if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') |
| 5583 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5584 | if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) |
| 5585 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5586 | if (checkclearopq(cap->oap)) |
| 5587 | return; |
| 5588 | } |
| 5589 | |
| 5590 | if (ptr == NULL && (n = find_ident_under_cursor(&ptr, |
| 5591 | (cmdchar == '*' || cmdchar == '#') |
| 5592 | ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) |
| 5593 | { |
| 5594 | clearop(cap->oap); |
| 5595 | return; |
| 5596 | } |
| 5597 | |
| 5598 | /* Allocate buffer to put the command in. Inserting backslashes can |
| 5599 | * double the length of the word. p_kp / curbuf->b_p_kp could be added |
| 5600 | * and some numbers. */ |
| 5601 | kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); |
| 5602 | kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 |
| 5603 | || STRCMP(kp, ":help") == 0); |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 5604 | if (kp_help && *skipwhite(ptr) == NUL) |
| 5605 | { |
| 5606 | EMSG(_(e_noident)); /* found white space only */ |
| 5607 | return; |
| 5608 | } |
Bram Moolenaar | 2ff8b64 | 2016-05-24 10:46:45 +0200 | [diff] [blame] | 5609 | kp_ex = (*kp == ':'); |
| 5610 | buflen = (unsigned)(n * 2 + 30 + STRLEN(kp)); |
| 5611 | buf = alloc(buflen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5612 | if (buf == NULL) |
| 5613 | return; |
| 5614 | buf[0] = NUL; |
| 5615 | |
| 5616 | switch (cmdchar) |
| 5617 | { |
| 5618 | case '*': |
| 5619 | case '#': |
| 5620 | /* |
| 5621 | * Put cursor at start of word, makes search skip the word |
| 5622 | * under the cursor. |
| 5623 | * Call setpcmark() first, so "*``" puts the cursor back where |
| 5624 | * it was. |
| 5625 | */ |
| 5626 | setpcmark(); |
| 5627 | curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); |
| 5628 | |
| 5629 | if (!g_cmd && vim_iswordp(ptr)) |
| 5630 | STRCPY(buf, "\\<"); |
| 5631 | no_smartcase = TRUE; /* don't use 'smartcase' now */ |
| 5632 | break; |
| 5633 | |
| 5634 | case 'K': |
| 5635 | if (kp_help) |
| 5636 | STRCPY(buf, "he! "); |
Bram Moolenaar | 2ff8b64 | 2016-05-24 10:46:45 +0200 | [diff] [blame] | 5637 | else if (kp_ex) |
| 5638 | { |
| 5639 | if (cap->count0 != 0) |
| 5640 | vim_snprintf((char *)buf, buflen, "%s %ld", |
| 5641 | kp, cap->count0); |
| 5642 | else |
| 5643 | STRCPY(buf, kp); |
| 5644 | STRCAT(buf, " "); |
| 5645 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5646 | else |
| 5647 | { |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5648 | /* An external command will probably use an argument starting |
| 5649 | * with "-" as an option. To avoid trouble we skip the "-". */ |
Bram Moolenaar | 9fd01c6 | 2008-11-01 12:52:38 +0000 | [diff] [blame] | 5650 | while (*ptr == '-' && n > 0) |
| 5651 | { |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5652 | ++ptr; |
Bram Moolenaar | 9fd01c6 | 2008-11-01 12:52:38 +0000 | [diff] [blame] | 5653 | --n; |
| 5654 | } |
| 5655 | if (n == 0) |
| 5656 | { |
| 5657 | EMSG(_(e_noident)); /* found dashes only */ |
| 5658 | vim_free(buf); |
| 5659 | return; |
| 5660 | } |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5661 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5662 | /* When a count is given, turn it into a range. Is this |
| 5663 | * really what we want? */ |
| 5664 | isman = (STRCMP(kp, "man") == 0); |
| 5665 | isman_s = (STRCMP(kp, "man -s") == 0); |
| 5666 | if (cap->count0 != 0 && !(isman || isman_s)) |
| 5667 | sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); |
| 5668 | |
| 5669 | STRCAT(buf, "! "); |
| 5670 | if (cap->count0 == 0 && isman_s) |
| 5671 | STRCAT(buf, "man"); |
| 5672 | else |
| 5673 | STRCAT(buf, kp); |
| 5674 | STRCAT(buf, " "); |
| 5675 | if (cap->count0 != 0 && (isman || isman_s)) |
| 5676 | { |
| 5677 | sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); |
| 5678 | STRCAT(buf, " "); |
| 5679 | } |
| 5680 | } |
| 5681 | break; |
| 5682 | |
| 5683 | case ']': |
Bram Moolenaar | 6d8027a | 2010-01-19 15:24:27 +0100 | [diff] [blame] | 5684 | tag_cmd = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5685 | #ifdef FEAT_CSCOPE |
| 5686 | if (p_cst) |
| 5687 | STRCPY(buf, "cstag "); |
| 5688 | else |
| 5689 | #endif |
| 5690 | STRCPY(buf, "ts "); |
| 5691 | break; |
| 5692 | |
| 5693 | default: |
Bram Moolenaar | 97e7a84 | 2010-03-17 13:07:08 +0100 | [diff] [blame] | 5694 | tag_cmd = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5695 | if (curbuf->b_help) |
| 5696 | STRCPY(buf, "he! "); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5697 | else |
Bram Moolenaar | 6d8027a | 2010-01-19 15:24:27 +0100 | [diff] [blame] | 5698 | { |
Bram Moolenaar | 6d8027a | 2010-01-19 15:24:27 +0100 | [diff] [blame] | 5699 | if (g_cmd) |
| 5700 | STRCPY(buf, "tj "); |
| 5701 | else |
| 5702 | sprintf((char *)buf, "%ldta ", cap->count0); |
| 5703 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | /* |
| 5707 | * Now grab the chars in the identifier |
| 5708 | */ |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5709 | if (cmdchar == 'K' && !kp_help) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5710 | { |
Bram Moolenaar | 9fd01c6 | 2008-11-01 12:52:38 +0000 | [diff] [blame] | 5711 | ptr = vim_strnsave(ptr, n); |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 5712 | if (kp_ex) |
| 5713 | /* Escape the argument properly for an Ex command */ |
| 5714 | p = vim_strsave_fnameescape(ptr, FALSE); |
| 5715 | else |
| 5716 | /* Escape the argument properly for a shell command */ |
| 5717 | p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
Bram Moolenaar | 9fd01c6 | 2008-11-01 12:52:38 +0000 | [diff] [blame] | 5718 | vim_free(ptr); |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5719 | if (p == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5720 | { |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5721 | vim_free(buf); |
| 5722 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5723 | } |
Bram Moolenaar | 0bc380a | 2010-07-10 13:52:13 +0200 | [diff] [blame] | 5724 | newbuf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1); |
| 5725 | if (newbuf == NULL) |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5726 | { |
| 5727 | vim_free(buf); |
| 5728 | vim_free(p); |
| 5729 | return; |
| 5730 | } |
Bram Moolenaar | 0bc380a | 2010-07-10 13:52:13 +0200 | [diff] [blame] | 5731 | buf = newbuf; |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5732 | STRCAT(buf, p); |
| 5733 | vim_free(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5734 | } |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5735 | else |
| 5736 | { |
| 5737 | if (cmdchar == '*') |
| 5738 | aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); |
| 5739 | else if (cmdchar == '#') |
| 5740 | aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); |
Bram Moolenaar | 6d8027a | 2010-01-19 15:24:27 +0100 | [diff] [blame] | 5741 | else if (tag_cmd) |
Bram Moolenaar | 77a0aa4 | 2010-10-13 18:06:47 +0200 | [diff] [blame] | 5742 | { |
| 5743 | if (curbuf->b_help) |
| 5744 | /* ":help" handles unescaped argument */ |
| 5745 | aux_ptr = (char_u *)""; |
| 5746 | else |
| 5747 | aux_ptr = (char_u *)"\\|\"\n["; |
| 5748 | } |
Bram Moolenaar | 6d8027a | 2010-01-19 15:24:27 +0100 | [diff] [blame] | 5749 | else |
Bram Moolenaar | 3094a9e | 2008-09-06 14:44:59 +0000 | [diff] [blame] | 5750 | aux_ptr = (char_u *)"\\|\"\n*?["; |
| 5751 | |
| 5752 | p = buf + STRLEN(buf); |
| 5753 | while (n-- > 0) |
| 5754 | { |
| 5755 | /* put a backslash before \ and some others */ |
| 5756 | if (vim_strchr(aux_ptr, *ptr) != NULL) |
| 5757 | *p++ = '\\'; |
| 5758 | #ifdef FEAT_MBYTE |
| 5759 | /* When current byte is a part of multibyte character, copy all |
| 5760 | * bytes of that character. */ |
| 5761 | if (has_mbyte) |
| 5762 | { |
| 5763 | int i; |
| 5764 | int len = (*mb_ptr2len)(ptr) - 1; |
| 5765 | |
| 5766 | for (i = 0; i < len && n >= 1; ++i, --n) |
| 5767 | *p++ = *ptr++; |
| 5768 | } |
| 5769 | #endif |
| 5770 | *p++ = *ptr++; |
| 5771 | } |
| 5772 | *p = NUL; |
| 5773 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5774 | |
| 5775 | /* |
| 5776 | * Execute the command. |
| 5777 | */ |
| 5778 | if (cmdchar == '*' || cmdchar == '#') |
| 5779 | { |
| 5780 | if (!g_cmd && ( |
| 5781 | #ifdef FEAT_MBYTE |
| 5782 | has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : |
| 5783 | #endif |
| 5784 | vim_iswordc(ptr[-1]))) |
| 5785 | STRCAT(buf, "\\>"); |
| 5786 | #ifdef FEAT_CMDHIST |
| 5787 | /* put pattern in search history */ |
Bram Moolenaar | c7be3f3 | 2009-12-24 14:01:12 +0000 | [diff] [blame] | 5788 | init_history(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5789 | add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
| 5790 | #endif |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 5791 | (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5792 | } |
| 5793 | else |
| 5794 | do_cmdline_cmd(buf); |
| 5795 | |
| 5796 | vim_free(buf); |
| 5797 | } |
| 5798 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5799 | /* |
| 5800 | * Get visually selected text, within one line only. |
| 5801 | * Returns FAIL if more than one line selected. |
| 5802 | */ |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 5803 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5804 | get_visual_text( |
| 5805 | cmdarg_T *cap, |
| 5806 | char_u **pp, /* return: start of selected text */ |
| 5807 | int *lenp) /* return: length of selected text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5808 | { |
| 5809 | if (VIsual_mode != 'V') |
| 5810 | unadjust_for_sel(); |
| 5811 | if (VIsual.lnum != curwin->w_cursor.lnum) |
| 5812 | { |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 5813 | if (cap != NULL) |
| 5814 | clearopbeep(cap->oap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5815 | return FAIL; |
| 5816 | } |
| 5817 | if (VIsual_mode == 'V') |
| 5818 | { |
| 5819 | *pp = ml_get_curline(); |
| 5820 | *lenp = (int)STRLEN(*pp); |
| 5821 | } |
| 5822 | else |
| 5823 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 5824 | if (LT_POS(curwin->w_cursor, VIsual)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5825 | { |
| 5826 | *pp = ml_get_pos(&curwin->w_cursor); |
| 5827 | *lenp = VIsual.col - curwin->w_cursor.col + 1; |
| 5828 | } |
| 5829 | else |
| 5830 | { |
| 5831 | *pp = ml_get_pos(&VIsual); |
| 5832 | *lenp = curwin->w_cursor.col - VIsual.col + 1; |
| 5833 | } |
| 5834 | #ifdef FEAT_MBYTE |
| 5835 | if (has_mbyte) |
| 5836 | /* Correct the length to include the whole last character. */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5837 | *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5838 | #endif |
| 5839 | } |
| 5840 | reset_VIsual_and_resel(); |
| 5841 | return OK; |
| 5842 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5843 | |
| 5844 | /* |
| 5845 | * CTRL-T: backwards in tag stack |
| 5846 | */ |
| 5847 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5848 | nv_tagpop(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5849 | { |
| 5850 | if (!checkclearopq(cap->oap)) |
| 5851 | do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); |
| 5852 | } |
| 5853 | |
| 5854 | /* |
| 5855 | * Handle scrolling command 'H', 'L' and 'M'. |
| 5856 | */ |
| 5857 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5858 | nv_scroll(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5859 | { |
| 5860 | int used = 0; |
| 5861 | long n; |
| 5862 | #ifdef FEAT_FOLDING |
| 5863 | linenr_T lnum; |
| 5864 | #endif |
| 5865 | int half; |
| 5866 | |
| 5867 | cap->oap->motion_type = MLINE; |
| 5868 | setpcmark(); |
| 5869 | |
| 5870 | if (cap->cmdchar == 'L') |
| 5871 | { |
| 5872 | validate_botline(); /* make sure curwin->w_botline is valid */ |
| 5873 | curwin->w_cursor.lnum = curwin->w_botline - 1; |
| 5874 | if (cap->count1 - 1 >= curwin->w_cursor.lnum) |
| 5875 | curwin->w_cursor.lnum = 1; |
| 5876 | else |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5877 | { |
| 5878 | #ifdef FEAT_FOLDING |
| 5879 | if (hasAnyFolding(curwin)) |
| 5880 | { |
| 5881 | /* Count a fold for one screen line. */ |
| 5882 | for (n = cap->count1 - 1; n > 0 |
| 5883 | && curwin->w_cursor.lnum > curwin->w_topline; --n) |
| 5884 | { |
| 5885 | (void)hasFolding(curwin->w_cursor.lnum, |
| 5886 | &curwin->w_cursor.lnum, NULL); |
| 5887 | --curwin->w_cursor.lnum; |
| 5888 | } |
| 5889 | } |
| 5890 | else |
| 5891 | #endif |
| 5892 | curwin->w_cursor.lnum -= cap->count1 - 1; |
| 5893 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5894 | } |
| 5895 | else |
| 5896 | { |
| 5897 | if (cap->cmdchar == 'M') |
| 5898 | { |
| 5899 | #ifdef FEAT_DIFF |
| 5900 | /* Don't count filler lines above the window. */ |
| 5901 | used -= diff_check_fill(curwin, curwin->w_topline) |
| 5902 | - curwin->w_topfill; |
| 5903 | #endif |
| 5904 | validate_botline(); /* make sure w_empty_rows is valid */ |
| 5905 | half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; |
| 5906 | for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) |
| 5907 | { |
| 5908 | #ifdef FEAT_DIFF |
| 5909 | /* Count half he number of filler lines to be "below this |
| 5910 | * line" and half to be "above the next line". */ |
| 5911 | if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline |
| 5912 | + n) / 2 >= half) |
| 5913 | { |
| 5914 | --n; |
| 5915 | break; |
| 5916 | } |
| 5917 | #endif |
| 5918 | used += plines(curwin->w_topline + n); |
| 5919 | if (used >= half) |
| 5920 | break; |
| 5921 | #ifdef FEAT_FOLDING |
| 5922 | if (hasFolding(curwin->w_topline + n, NULL, &lnum)) |
| 5923 | n = lnum - curwin->w_topline; |
| 5924 | #endif |
| 5925 | } |
| 5926 | if (n > 0 && used > curwin->w_height) |
| 5927 | --n; |
| 5928 | } |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5929 | else /* (cap->cmdchar == 'H') */ |
| 5930 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5931 | n = cap->count1 - 1; |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5932 | #ifdef FEAT_FOLDING |
| 5933 | if (hasAnyFolding(curwin)) |
| 5934 | { |
| 5935 | /* Count a fold for one screen line. */ |
| 5936 | lnum = curwin->w_topline; |
| 5937 | while (n-- > 0 && lnum < curwin->w_botline - 1) |
| 5938 | { |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 5939 | (void)hasFolding(lnum, NULL, &lnum); |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5940 | ++lnum; |
| 5941 | } |
| 5942 | n = lnum - curwin->w_topline; |
| 5943 | } |
| 5944 | #endif |
| 5945 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5946 | curwin->w_cursor.lnum = curwin->w_topline + n; |
| 5947 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 5948 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 5949 | } |
| 5950 | |
| 5951 | cursor_correct(); /* correct for 'so' */ |
| 5952 | beginline(BL_SOL | BL_FIX); |
| 5953 | } |
| 5954 | |
| 5955 | /* |
| 5956 | * Cursor right commands. |
| 5957 | */ |
| 5958 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5959 | nv_right(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5960 | { |
| 5961 | long n; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5962 | int past_line; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5963 | |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5964 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
| 5965 | { |
| 5966 | /* <C-Right> and <S-Right> move a word or WORD right */ |
| 5967 | if (mod_mask & MOD_MASK_CTRL) |
| 5968 | cap->arg = TRUE; |
| 5969 | nv_wordcmd(cap); |
| 5970 | return; |
| 5971 | } |
| 5972 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5973 | cap->oap->motion_type = MCHAR; |
| 5974 | cap->oap->inclusive = FALSE; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5975 | past_line = (VIsual_active && *p_sel != 'o'); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5976 | |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5977 | #ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5978 | /* |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5979 | * In virtual edit mode, there's no such thing as "past_line", as lines |
| 5980 | * are (theoretically) infinitely long. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5981 | */ |
| 5982 | if (virtual_active()) |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5983 | past_line = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5984 | #endif |
| 5985 | |
| 5986 | for (n = cap->count1; n > 0; --n) |
| 5987 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 5988 | if ((!past_line && oneright() == FAIL) |
| 5989 | || (past_line && *ml_get_cursor() == NUL) |
Bram Moolenaar | 78a1531 | 2009-05-15 19:33:18 +0000 | [diff] [blame] | 5990 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5991 | { |
| 5992 | /* |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5993 | * <Space> wraps to next line if 'whichwrap' has 's'. |
| 5994 | * 'l' wraps to next line if 'whichwrap' has 'l'. |
| 5995 | * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5996 | */ |
| 5997 | if ( ((cap->cmdchar == ' ' |
| 5998 | && vim_strchr(p_ww, 's') != NULL) |
| 5999 | || (cap->cmdchar == 'l' |
| 6000 | && vim_strchr(p_ww, 'l') != NULL) |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 6001 | || (cap->cmdchar == K_RIGHT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6002 | && vim_strchr(p_ww, '>') != NULL)) |
| 6003 | && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
| 6004 | { |
| 6005 | /* When deleting we also count the NL as a character. |
| 6006 | * Set cap->oap->inclusive when last char in the line is |
| 6007 | * included, move to next line after that */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6008 | if ( cap->oap->op_type != OP_NOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6009 | && !cap->oap->inclusive |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6010 | && !LINEEMPTY(curwin->w_cursor.lnum)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6011 | cap->oap->inclusive = TRUE; |
| 6012 | else |
| 6013 | { |
| 6014 | ++curwin->w_cursor.lnum; |
| 6015 | curwin->w_cursor.col = 0; |
| 6016 | #ifdef FEAT_VIRTUALEDIT |
| 6017 | curwin->w_cursor.coladd = 0; |
| 6018 | #endif |
| 6019 | curwin->w_set_curswant = TRUE; |
| 6020 | cap->oap->inclusive = FALSE; |
| 6021 | } |
| 6022 | continue; |
| 6023 | } |
| 6024 | if (cap->oap->op_type == OP_NOP) |
| 6025 | { |
| 6026 | /* Only beep and flush if not moved at all */ |
| 6027 | if (n == cap->count1) |
| 6028 | beep_flush(); |
| 6029 | } |
| 6030 | else |
| 6031 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6032 | if (!LINEEMPTY(curwin->w_cursor.lnum)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6033 | cap->oap->inclusive = TRUE; |
| 6034 | } |
| 6035 | break; |
| 6036 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 6037 | else if (past_line) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6038 | { |
| 6039 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 6040 | #ifdef FEAT_VIRTUALEDIT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6041 | if (virtual_active()) |
| 6042 | oneright(); |
| 6043 | else |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 6044 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6045 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 6046 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6047 | if (has_mbyte) |
| 6048 | curwin->w_cursor.col += |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6049 | (*mb_ptr2len)(ml_get_cursor()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6050 | else |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 6051 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6052 | ++curwin->w_cursor.col; |
| 6053 | } |
| 6054 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6055 | } |
| 6056 | #ifdef FEAT_FOLDING |
| 6057 | if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped |
| 6058 | && cap->oap->op_type == OP_NOP) |
| 6059 | foldOpenCursor(); |
| 6060 | #endif |
| 6061 | } |
| 6062 | |
| 6063 | /* |
| 6064 | * Cursor left commands. |
| 6065 | * |
| 6066 | * Returns TRUE when operator end should not be adjusted. |
| 6067 | */ |
| 6068 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6069 | nv_left(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6070 | { |
| 6071 | long n; |
| 6072 | |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 6073 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
| 6074 | { |
| 6075 | /* <C-Left> and <S-Left> move a word or WORD left */ |
| 6076 | if (mod_mask & MOD_MASK_CTRL) |
| 6077 | cap->arg = 1; |
| 6078 | nv_bck_word(cap); |
| 6079 | return; |
| 6080 | } |
| 6081 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6082 | cap->oap->motion_type = MCHAR; |
| 6083 | cap->oap->inclusive = FALSE; |
| 6084 | for (n = cap->count1; n > 0; --n) |
| 6085 | { |
| 6086 | if (oneleft() == FAIL) |
| 6087 | { |
| 6088 | /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. |
| 6089 | * 'h' wraps to previous line if 'whichwrap' has 'h'. |
| 6090 | * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. |
| 6091 | */ |
| 6092 | if ( (((cap->cmdchar == K_BS |
| 6093 | || cap->cmdchar == Ctrl_H) |
| 6094 | && vim_strchr(p_ww, 'b') != NULL) |
| 6095 | || (cap->cmdchar == 'h' |
| 6096 | && vim_strchr(p_ww, 'h') != NULL) |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 6097 | || (cap->cmdchar == K_LEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6098 | && vim_strchr(p_ww, '<') != NULL)) |
| 6099 | && curwin->w_cursor.lnum > 1) |
| 6100 | { |
| 6101 | --(curwin->w_cursor.lnum); |
| 6102 | coladvance((colnr_T)MAXCOL); |
| 6103 | curwin->w_set_curswant = TRUE; |
| 6104 | |
| 6105 | /* When the NL before the first char has to be deleted we |
| 6106 | * put the cursor on the NUL after the previous line. |
| 6107 | * This is a very special case, be careful! |
Bram Moolenaar | ad8958b | 2008-01-02 15:26:04 +0000 | [diff] [blame] | 6108 | * Don't adjust op_end now, otherwise it won't work. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6109 | if ( (cap->oap->op_type == OP_DELETE |
| 6110 | || cap->oap->op_type == OP_CHANGE) |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6111 | && !LINEEMPTY(curwin->w_cursor.lnum)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6112 | { |
Bram Moolenaar | 7d311c5 | 2014-02-22 23:49:35 +0100 | [diff] [blame] | 6113 | char_u *cp = ml_get_cursor(); |
| 6114 | |
| 6115 | if (*cp != NUL) |
| 6116 | { |
| 6117 | #ifdef FEAT_MBYTE |
| 6118 | if (has_mbyte) |
| 6119 | curwin->w_cursor.col += (*mb_ptr2len)(cp); |
| 6120 | else |
| 6121 | #endif |
| 6122 | ++curwin->w_cursor.col; |
| 6123 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6124 | cap->retval |= CA_NO_ADJ_OP_END; |
| 6125 | } |
| 6126 | continue; |
| 6127 | } |
| 6128 | /* Only beep and flush if not moved at all */ |
| 6129 | else if (cap->oap->op_type == OP_NOP && n == cap->count1) |
| 6130 | beep_flush(); |
| 6131 | break; |
| 6132 | } |
| 6133 | } |
| 6134 | #ifdef FEAT_FOLDING |
| 6135 | if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped |
| 6136 | && cap->oap->op_type == OP_NOP) |
| 6137 | foldOpenCursor(); |
| 6138 | #endif |
| 6139 | } |
| 6140 | |
| 6141 | /* |
| 6142 | * Cursor up commands. |
| 6143 | * cap->arg is TRUE for "-": Move cursor to first non-blank. |
| 6144 | */ |
| 6145 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6146 | nv_up(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6147 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 6148 | if (mod_mask & MOD_MASK_SHIFT) |
| 6149 | { |
| 6150 | /* <S-Up> is page up */ |
| 6151 | cap->arg = BACKWARD; |
| 6152 | nv_page(cap); |
| 6153 | } |
| 6154 | else |
| 6155 | { |
| 6156 | cap->oap->motion_type = MLINE; |
| 6157 | if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) |
| 6158 | clearopbeep(cap->oap); |
| 6159 | else if (cap->arg) |
| 6160 | beginline(BL_WHITE | BL_FIX); |
| 6161 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | /* |
| 6165 | * Cursor down commands. |
| 6166 | * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. |
| 6167 | */ |
| 6168 | static void |
Bram Moolenaar | 1b01005 | 2016-09-12 12:24:11 +0200 | [diff] [blame] | 6169 | nv_down(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6170 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 6171 | if (mod_mask & MOD_MASK_SHIFT) |
| 6172 | { |
| 6173 | /* <S-Down> is page down */ |
| 6174 | cap->arg = FORWARD; |
| 6175 | nv_page(cap); |
| 6176 | } |
| 6177 | else |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 6178 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6179 | /* In a quickfix window a <CR> jumps to the error under the cursor. */ |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 6180 | if (bt_quickfix(curbuf) && cap->cmdchar == CAR) |
Bram Moolenaar | 74a4716 | 2017-02-26 19:09:05 +0100 | [diff] [blame] | 6181 | { |
Bram Moolenaar | 28c258f | 2006-01-25 22:02:51 +0000 | [diff] [blame] | 6182 | if (curwin->w_llist_ref == NULL) |
| 6183 | do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ |
| 6184 | else |
| 6185 | do_cmdline_cmd((char_u *)".ll"); /* location list window */ |
Bram Moolenaar | 74a4716 | 2017-02-26 19:09:05 +0100 | [diff] [blame] | 6186 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6187 | else |
| 6188 | #endif |
| 6189 | { |
| 6190 | #ifdef FEAT_CMDWIN |
| 6191 | /* In the cmdline window a <CR> executes the command. */ |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 6192 | if (cmdwin_type != 0 && cap->cmdchar == CAR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6193 | cmdwin_result = CAR; |
| 6194 | else |
| 6195 | #endif |
| 6196 | { |
| 6197 | cap->oap->motion_type = MLINE; |
| 6198 | if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) |
| 6199 | clearopbeep(cap->oap); |
| 6200 | else if (cap->arg) |
| 6201 | beginline(BL_WHITE | BL_FIX); |
| 6202 | } |
| 6203 | } |
| 6204 | } |
| 6205 | |
| 6206 | #ifdef FEAT_SEARCHPATH |
| 6207 | /* |
| 6208 | * Grab the file name under the cursor and edit it. |
| 6209 | */ |
| 6210 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6211 | nv_gotofile(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6212 | { |
| 6213 | char_u *ptr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6214 | linenr_T lnum = -1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6215 | |
Bram Moolenaar | 2d3f489 | 2006-01-20 23:02:51 +0000 | [diff] [blame] | 6216 | if (text_locked()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6217 | { |
| 6218 | clearopbeep(cap->oap); |
Bram Moolenaar | 2d3f489 | 2006-01-20 23:02:51 +0000 | [diff] [blame] | 6219 | text_locked_msg(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6220 | return; |
| 6221 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6222 | #ifdef FEAT_AUTOCMD |
| 6223 | if (curbuf_locked()) |
| 6224 | { |
| 6225 | clearop(cap->oap); |
| 6226 | return; |
| 6227 | } |
| 6228 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6229 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6230 | ptr = grab_file_name(cap->count1, &lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6231 | |
| 6232 | if (ptr != NULL) |
| 6233 | { |
| 6234 | /* do autowrite if necessary */ |
Bram Moolenaar | eb44a68 | 2017-08-03 22:44:55 +0200 | [diff] [blame] | 6235 | if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 6236 | (void)autowrite(curbuf, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6237 | setpcmark(); |
Bram Moolenaar | 2a79ed2 | 2017-05-24 09:51:39 +0200 | [diff] [blame] | 6238 | if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST, |
Bram Moolenaar | eb44a68 | 2017-08-03 22:44:55 +0200 | [diff] [blame] | 6239 | buf_hide(curbuf) ? ECMD_HIDE : 0, curwin) == OK |
Bram Moolenaar | 2a79ed2 | 2017-05-24 09:51:39 +0200 | [diff] [blame] | 6240 | && cap->nchar == 'F' && lnum >= 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6241 | { |
| 6242 | curwin->w_cursor.lnum = lnum; |
| 6243 | check_cursor_lnum(); |
| 6244 | beginline(BL_SOL | BL_FIX); |
| 6245 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6246 | vim_free(ptr); |
| 6247 | } |
| 6248 | else |
| 6249 | clearop(cap->oap); |
| 6250 | } |
| 6251 | #endif |
| 6252 | |
| 6253 | /* |
| 6254 | * <End> command: to end of current line or last line. |
| 6255 | */ |
| 6256 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6257 | nv_end(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6258 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 6259 | if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6260 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 6261 | cap->arg = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6262 | nv_goto(cap); |
| 6263 | cap->count1 = 1; /* to end of current line */ |
| 6264 | } |
| 6265 | nv_dollar(cap); |
| 6266 | } |
| 6267 | |
| 6268 | /* |
| 6269 | * Handle the "$" command. |
| 6270 | */ |
| 6271 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6272 | nv_dollar(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6273 | { |
| 6274 | cap->oap->motion_type = MCHAR; |
| 6275 | cap->oap->inclusive = TRUE; |
| 6276 | #ifdef FEAT_VIRTUALEDIT |
| 6277 | /* In virtual mode when off the edge of a line and an operator |
| 6278 | * is pending (whew!) keep the cursor where it is. |
| 6279 | * Otherwise, send it to the end of the line. */ |
| 6280 | if (!virtual_active() || gchar_cursor() != NUL |
| 6281 | || cap->oap->op_type == OP_NOP) |
| 6282 | #endif |
| 6283 | curwin->w_curswant = MAXCOL; /* so we stay at the end */ |
| 6284 | if (cursor_down((long)(cap->count1 - 1), |
| 6285 | cap->oap->op_type == OP_NOP) == FAIL) |
| 6286 | clearopbeep(cap->oap); |
| 6287 | #ifdef FEAT_FOLDING |
| 6288 | else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6289 | foldOpenCursor(); |
| 6290 | #endif |
| 6291 | } |
| 6292 | |
| 6293 | /* |
| 6294 | * Implementation of '?' and '/' commands. |
| 6295 | * If cap->arg is TRUE don't set PC mark. |
| 6296 | */ |
| 6297 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6298 | nv_search(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6299 | { |
| 6300 | oparg_T *oap = cap->oap; |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 6301 | pos_T save_cursor = curwin->w_cursor; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6302 | |
| 6303 | if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) |
| 6304 | { |
| 6305 | /* Translate "g??" to "g?g?" */ |
| 6306 | cap->cmdchar = 'g'; |
| 6307 | cap->nchar = '?'; |
| 6308 | nv_operator(cap); |
| 6309 | return; |
| 6310 | } |
| 6311 | |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 6312 | /* When using 'incsearch' the cursor may be moved to set a different search |
| 6313 | * start position. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6314 | cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
| 6315 | |
| 6316 | if (cap->searchbuf == NULL) |
| 6317 | { |
| 6318 | clearop(oap); |
| 6319 | return; |
| 6320 | } |
| 6321 | |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 6322 | (void)normal_search(cap, cap->cmdchar, cap->searchbuf, |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6323 | (cap->arg || !EQUAL_POS(save_cursor, curwin->w_cursor)) |
Bram Moolenaar | dda933d | 2016-09-03 21:04:58 +0200 | [diff] [blame] | 6324 | ? 0 : SEARCH_MARK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | /* |
| 6328 | * Handle "N" and "n" commands. |
| 6329 | * cap->arg is SEARCH_REV for "N", 0 for "n". |
| 6330 | */ |
| 6331 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6332 | nv_next(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6333 | { |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 6334 | pos_T old = curwin->w_cursor; |
| 6335 | int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); |
| 6336 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6337 | if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 6338 | { |
| 6339 | /* Avoid getting stuck on the current cursor position, which can |
| 6340 | * happen when an offset is given and the cursor is on the last char |
| 6341 | * in the buffer: Repeat with count + 1. */ |
| 6342 | cap->count1 += 1; |
| 6343 | (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); |
| 6344 | cap->count1 -= 1; |
| 6345 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | /* |
| 6349 | * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). |
| 6350 | * Uses only cap->count1 and cap->oap from "cap". |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 6351 | * Return 0 for failure, 1 for found, 2 for found and line offset added. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6352 | */ |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 6353 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6354 | normal_search( |
| 6355 | cmdarg_T *cap, |
| 6356 | int dir, |
| 6357 | char_u *pat, |
| 6358 | int opt) /* extra flags for do_search() */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6359 | { |
| 6360 | int i; |
| 6361 | |
| 6362 | cap->oap->motion_type = MCHAR; |
| 6363 | cap->oap->inclusive = FALSE; |
| 6364 | cap->oap->use_reg_one = TRUE; |
| 6365 | curwin->w_set_curswant = TRUE; |
| 6366 | |
| 6367 | i = do_search(cap->oap, dir, pat, cap->count1, |
Bram Moolenaar | fbd0b0a | 2017-06-17 18:44:21 +0200 | [diff] [blame] | 6368 | opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6369 | if (i == 0) |
| 6370 | clearop(cap->oap); |
| 6371 | else |
| 6372 | { |
| 6373 | if (i == 2) |
| 6374 | cap->oap->motion_type = MLINE; |
| 6375 | #ifdef FEAT_VIRTUALEDIT |
| 6376 | curwin->w_cursor.coladd = 0; |
| 6377 | #endif |
| 6378 | #ifdef FEAT_FOLDING |
| 6379 | if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) |
| 6380 | foldOpenCursor(); |
| 6381 | #endif |
| 6382 | } |
| 6383 | |
| 6384 | /* "/$" will put the cursor after the end of the line, may need to |
| 6385 | * correct that here */ |
| 6386 | check_cursor(); |
Bram Moolenaar | 4653911 | 2015-02-17 15:43:57 +0100 | [diff] [blame] | 6387 | return i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | /* |
| 6391 | * Character search commands. |
| 6392 | * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for |
| 6393 | * ',' and FALSE for ';'. |
| 6394 | * cap->nchar is NUL for ',' and ';' (repeat the search) |
| 6395 | */ |
| 6396 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6397 | nv_csearch(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6398 | { |
| 6399 | int t_cmd; |
| 6400 | |
| 6401 | if (cap->cmdchar == 't' || cap->cmdchar == 'T') |
| 6402 | t_cmd = TRUE; |
| 6403 | else |
| 6404 | t_cmd = FALSE; |
| 6405 | |
| 6406 | cap->oap->motion_type = MCHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6407 | if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) |
| 6408 | clearopbeep(cap->oap); |
| 6409 | else |
| 6410 | { |
| 6411 | curwin->w_set_curswant = TRUE; |
| 6412 | #ifdef FEAT_VIRTUALEDIT |
| 6413 | /* Include a Tab for "tx" and for "dfx". */ |
| 6414 | if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD |
| 6415 | && (t_cmd || cap->oap->op_type != OP_NOP)) |
| 6416 | { |
| 6417 | colnr_T scol, ecol; |
| 6418 | |
| 6419 | getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); |
| 6420 | curwin->w_cursor.coladd = ecol - scol; |
| 6421 | } |
| 6422 | else |
| 6423 | curwin->w_cursor.coladd = 0; |
| 6424 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6425 | adjust_for_sel(cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6426 | #ifdef FEAT_FOLDING |
| 6427 | if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6428 | foldOpenCursor(); |
| 6429 | #endif |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | /* |
| 6434 | * "[" and "]" commands. |
| 6435 | * cap->arg is BACKWARD for "[" and FORWARD for "]". |
| 6436 | */ |
| 6437 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6438 | nv_brackets(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6439 | { |
Bram Moolenaar | a9d52e3 | 2010-07-31 16:44:19 +0200 | [diff] [blame] | 6440 | pos_T new_pos = INIT_POS_T(0, 0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6441 | pos_T prev_pos; |
| 6442 | pos_T *pos = NULL; /* init for GCC */ |
| 6443 | pos_T old_pos; /* cursor position before command */ |
| 6444 | int flag; |
| 6445 | long n; |
| 6446 | int findc; |
| 6447 | int c; |
| 6448 | |
| 6449 | cap->oap->motion_type = MCHAR; |
| 6450 | cap->oap->inclusive = FALSE; |
| 6451 | old_pos = curwin->w_cursor; |
| 6452 | #ifdef FEAT_VIRTUALEDIT |
| 6453 | curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ |
| 6454 | #endif |
| 6455 | |
| 6456 | #ifdef FEAT_SEARCHPATH |
| 6457 | /* |
| 6458 | * "[f" or "]f" : Edit file under the cursor (same as "gf") |
| 6459 | */ |
| 6460 | if (cap->nchar == 'f') |
| 6461 | nv_gotofile(cap); |
| 6462 | else |
| 6463 | #endif |
| 6464 | |
| 6465 | #ifdef FEAT_FIND_ID |
| 6466 | /* |
Bram Moolenaar | f711faf | 2007-05-10 16:48:19 +0000 | [diff] [blame] | 6467 | * Find the occurrence(s) of the identifier or define under cursor |
| 6468 | * in current and included files or jump to the first occurrence. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6469 | * |
| 6470 | * search list jump |
| 6471 | * fwd bwd fwd bwd fwd bwd |
| 6472 | * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" |
| 6473 | * define "]d" "[d" "]D" "[D" "]^D" "[^D" |
| 6474 | */ |
| 6475 | if (vim_strchr((char_u *) |
| 6476 | #ifdef EBCDIC |
| 6477 | "iI\005dD\067", |
| 6478 | #else |
| 6479 | "iI\011dD\004", |
| 6480 | #endif |
| 6481 | cap->nchar) != NULL) |
| 6482 | { |
| 6483 | char_u *ptr; |
| 6484 | int len; |
| 6485 | |
| 6486 | if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) |
| 6487 | clearop(cap->oap); |
| 6488 | else |
| 6489 | { |
| 6490 | find_pattern_in_path(ptr, 0, len, TRUE, |
| 6491 | cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, |
| 6492 | ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, |
| 6493 | cap->count1, |
| 6494 | isupper(cap->nchar) ? ACTION_SHOW_ALL : |
| 6495 | islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, |
| 6496 | cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, |
| 6497 | (linenr_T)MAXLNUM); |
| 6498 | curwin->w_set_curswant = TRUE; |
| 6499 | } |
| 6500 | } |
| 6501 | else |
| 6502 | #endif |
| 6503 | |
| 6504 | /* |
| 6505 | * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' |
| 6506 | * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. |
| 6507 | * "[/", "[*", "]/", "]*": go to Nth comment start/end. |
| 6508 | * "[m" or "]m" search for prev/next start of (Java) method. |
| 6509 | * "[M" or "]M" search for prev/next end of (Java) method. |
| 6510 | */ |
| 6511 | if ( (cap->cmdchar == '[' |
| 6512 | && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) |
| 6513 | || (cap->cmdchar == ']' |
| 6514 | && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) |
| 6515 | { |
| 6516 | if (cap->nchar == '*') |
| 6517 | cap->nchar = '/'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6518 | prev_pos.lnum = 0; |
| 6519 | if (cap->nchar == 'm' || cap->nchar == 'M') |
| 6520 | { |
| 6521 | if (cap->cmdchar == '[') |
| 6522 | findc = '{'; |
| 6523 | else |
| 6524 | findc = '}'; |
| 6525 | n = 9999; |
| 6526 | } |
| 6527 | else |
| 6528 | { |
| 6529 | findc = cap->nchar; |
| 6530 | n = cap->count1; |
| 6531 | } |
| 6532 | for ( ; n > 0; --n) |
| 6533 | { |
| 6534 | if ((pos = findmatchlimit(cap->oap, findc, |
| 6535 | (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) |
| 6536 | { |
| 6537 | if (new_pos.lnum == 0) /* nothing found */ |
| 6538 | { |
| 6539 | if (cap->nchar != 'm' && cap->nchar != 'M') |
| 6540 | clearopbeep(cap->oap); |
| 6541 | } |
| 6542 | else |
| 6543 | pos = &new_pos; /* use last one found */ |
| 6544 | break; |
| 6545 | } |
| 6546 | prev_pos = new_pos; |
| 6547 | curwin->w_cursor = *pos; |
| 6548 | new_pos = *pos; |
| 6549 | } |
| 6550 | curwin->w_cursor = old_pos; |
| 6551 | |
| 6552 | /* |
| 6553 | * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only |
| 6554 | * brought us to the match for "[m" and "]M" when inside a method. |
| 6555 | * Try finding the '{' or '}' we want to be at. |
| 6556 | * Also repeat for the given count. |
| 6557 | */ |
| 6558 | if (cap->nchar == 'm' || cap->nchar == 'M') |
| 6559 | { |
| 6560 | /* norm is TRUE for "]M" and "[m" */ |
| 6561 | int norm = ((findc == '{') == (cap->nchar == 'm')); |
| 6562 | |
| 6563 | n = cap->count1; |
| 6564 | /* found a match: we were inside a method */ |
| 6565 | if (prev_pos.lnum != 0) |
| 6566 | { |
| 6567 | pos = &prev_pos; |
| 6568 | curwin->w_cursor = prev_pos; |
| 6569 | if (norm) |
| 6570 | --n; |
| 6571 | } |
| 6572 | else |
| 6573 | pos = NULL; |
| 6574 | while (n > 0) |
| 6575 | { |
| 6576 | for (;;) |
| 6577 | { |
| 6578 | if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) |
| 6579 | { |
| 6580 | /* if not found anything, that's an error */ |
| 6581 | if (pos == NULL) |
| 6582 | clearopbeep(cap->oap); |
| 6583 | n = 0; |
| 6584 | break; |
| 6585 | } |
| 6586 | c = gchar_cursor(); |
| 6587 | if (c == '{' || c == '}') |
| 6588 | { |
| 6589 | /* Must have found end/start of class: use it. |
| 6590 | * Or found the place to be at. */ |
| 6591 | if ((c == findc && norm) || (n == 1 && !norm)) |
| 6592 | { |
| 6593 | new_pos = curwin->w_cursor; |
| 6594 | pos = &new_pos; |
| 6595 | n = 0; |
| 6596 | } |
| 6597 | /* if no match found at all, we started outside of the |
| 6598 | * class and we're inside now. Just go on. */ |
| 6599 | else if (new_pos.lnum == 0) |
| 6600 | { |
| 6601 | new_pos = curwin->w_cursor; |
| 6602 | pos = &new_pos; |
| 6603 | } |
| 6604 | /* found start/end of other method: go to match */ |
| 6605 | else if ((pos = findmatchlimit(cap->oap, findc, |
| 6606 | (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, |
| 6607 | 0)) == NULL) |
| 6608 | n = 0; |
| 6609 | else |
| 6610 | curwin->w_cursor = *pos; |
| 6611 | break; |
| 6612 | } |
| 6613 | } |
| 6614 | --n; |
| 6615 | } |
| 6616 | curwin->w_cursor = old_pos; |
| 6617 | if (pos == NULL && new_pos.lnum != 0) |
| 6618 | clearopbeep(cap->oap); |
| 6619 | } |
| 6620 | if (pos != NULL) |
| 6621 | { |
| 6622 | setpcmark(); |
| 6623 | curwin->w_cursor = *pos; |
| 6624 | curwin->w_set_curswant = TRUE; |
| 6625 | #ifdef FEAT_FOLDING |
| 6626 | if ((fdo_flags & FDO_BLOCK) && KeyTyped |
| 6627 | && cap->oap->op_type == OP_NOP) |
| 6628 | foldOpenCursor(); |
| 6629 | #endif |
| 6630 | } |
| 6631 | } |
| 6632 | |
| 6633 | /* |
| 6634 | * "[[", "[]", "]]" and "][": move to start or end of function |
| 6635 | */ |
| 6636 | else if (cap->nchar == '[' || cap->nchar == ']') |
| 6637 | { |
| 6638 | if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ |
| 6639 | flag = '{'; |
| 6640 | else |
| 6641 | flag = '}'; /* "][" or "[]" */ |
| 6642 | |
| 6643 | curwin->w_set_curswant = TRUE; |
| 6644 | /* |
| 6645 | * Imitate strange Vi behaviour: When using "]]" with an operator |
| 6646 | * we also stop at '}'. |
| 6647 | */ |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 6648 | if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6649 | (cap->oap->op_type != OP_NOP |
| 6650 | && cap->arg == FORWARD && flag == '{'))) |
| 6651 | clearopbeep(cap->oap); |
| 6652 | else |
| 6653 | { |
| 6654 | if (cap->oap->op_type == OP_NOP) |
| 6655 | beginline(BL_WHITE | BL_FIX); |
| 6656 | #ifdef FEAT_FOLDING |
| 6657 | if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6658 | foldOpenCursor(); |
| 6659 | #endif |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | /* |
| 6664 | * "[p", "[P", "]P" and "]p": put with indent adjustment |
| 6665 | */ |
| 6666 | else if (cap->nchar == 'p' || cap->nchar == 'P') |
| 6667 | { |
Bram Moolenaar | 78f6f7e | 2007-07-10 12:03:33 +0000 | [diff] [blame] | 6668 | if (!checkclearop(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6669 | { |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6670 | int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
| 6671 | ? FORWARD : BACKWARD; |
| 6672 | int regname = cap->oap->regname; |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6673 | int was_visual = VIsual_active; |
| 6674 | int line_count = curbuf->b_ml.ml_line_count; |
| 6675 | pos_T start, end; |
| 6676 | |
| 6677 | if (VIsual_active) |
| 6678 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6679 | start = LTOREQ_POS(VIsual, curwin->w_cursor) |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6680 | ? VIsual : curwin->w_cursor; |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 6681 | end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6682 | curwin->w_cursor = (dir == BACKWARD ? start : end); |
| 6683 | } |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6684 | # ifdef FEAT_CLIPBOARD |
| 6685 | adjust_clip_reg(®name); |
| 6686 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6687 | prep_redo_cmd(cap); |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6688 | |
| 6689 | do_put(regname, dir, cap->count1, PUT_FIXINDENT); |
Bram Moolenaar | 27bed20 | 2014-03-12 17:42:04 +0100 | [diff] [blame] | 6690 | if (was_visual) |
| 6691 | { |
| 6692 | VIsual = start; |
| 6693 | curwin->w_cursor = end; |
| 6694 | if (dir == BACKWARD) |
| 6695 | { |
| 6696 | /* adjust lines */ |
| 6697 | VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; |
| 6698 | curwin->w_cursor.lnum += |
| 6699 | curbuf->b_ml.ml_line_count - line_count; |
| 6700 | } |
| 6701 | |
| 6702 | VIsual_active = TRUE; |
| 6703 | if (VIsual_mode == 'V') |
| 6704 | { |
| 6705 | /* delete visually selected lines */ |
| 6706 | cap->cmdchar = 'd'; |
| 6707 | cap->nchar = NUL; |
| 6708 | cap->oap->regname = regname; |
| 6709 | nv_operator(cap); |
| 6710 | do_pending_operator(cap, 0, FALSE); |
| 6711 | } |
| 6712 | if (VIsual_active) |
| 6713 | { |
| 6714 | end_visual_mode(); |
| 6715 | redraw_later(SOME_VALID); |
| 6716 | } |
| 6717 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6718 | } |
| 6719 | } |
| 6720 | |
| 6721 | /* |
| 6722 | * "['", "[`", "]'" and "]`": jump to next mark |
| 6723 | */ |
| 6724 | else if (cap->nchar == '\'' || cap->nchar == '`') |
| 6725 | { |
| 6726 | pos = &curwin->w_cursor; |
| 6727 | for (n = cap->count1; n > 0; --n) |
| 6728 | { |
| 6729 | prev_pos = *pos; |
| 6730 | pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, |
| 6731 | cap->nchar == '\''); |
| 6732 | if (pos == NULL) |
| 6733 | break; |
| 6734 | } |
| 6735 | if (pos == NULL) |
| 6736 | pos = &prev_pos; |
| 6737 | nv_cursormark(cap, cap->nchar == '\'', pos); |
| 6738 | } |
| 6739 | |
| 6740 | #ifdef FEAT_MOUSE |
| 6741 | /* |
| 6742 | * [ or ] followed by a middle mouse click: put selected text with |
| 6743 | * indent adjustment. Any other button just does as usual. |
| 6744 | */ |
Bram Moolenaar | 5ea0ac7 | 2010-05-07 15:52:08 +0200 | [diff] [blame] | 6745 | else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6746 | { |
| 6747 | (void)do_mouse(cap->oap, cap->nchar, |
| 6748 | (cap->cmdchar == ']') ? FORWARD : BACKWARD, |
| 6749 | cap->count1, PUT_FIXINDENT); |
| 6750 | } |
| 6751 | #endif /* FEAT_MOUSE */ |
| 6752 | |
| 6753 | #ifdef FEAT_FOLDING |
| 6754 | /* |
| 6755 | * "[z" and "]z": move to start or end of open fold. |
| 6756 | */ |
| 6757 | else if (cap->nchar == 'z') |
| 6758 | { |
| 6759 | if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
| 6760 | cap->count1) == FAIL) |
| 6761 | clearopbeep(cap->oap); |
| 6762 | } |
| 6763 | #endif |
| 6764 | |
| 6765 | #ifdef FEAT_DIFF |
| 6766 | /* |
| 6767 | * "[c" and "]c": move to next or previous diff-change. |
| 6768 | */ |
| 6769 | else if (cap->nchar == 'c') |
| 6770 | { |
| 6771 | if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, |
| 6772 | cap->count1) == FAIL) |
| 6773 | clearopbeep(cap->oap); |
| 6774 | } |
| 6775 | #endif |
| 6776 | |
Bram Moolenaar | f71a3db | 2006-03-12 21:50:18 +0000 | [diff] [blame] | 6777 | #ifdef FEAT_SPELL |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6778 | /* |
| 6779 | * "[s", "[S", "]s" and "]S": move to next spell error. |
| 6780 | */ |
| 6781 | else if (cap->nchar == 's' || cap->nchar == 'S') |
| 6782 | { |
Bram Moolenaar | 2cf8b30 | 2005-04-20 19:37:22 +0000 | [diff] [blame] | 6783 | setpcmark(); |
| 6784 | for (n = 0; n < cap->count1; ++n) |
Bram Moolenaar | 9552956 | 2005-08-25 21:21:38 +0000 | [diff] [blame] | 6785 | if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
| 6786 | cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) |
Bram Moolenaar | 2cf8b30 | 2005-04-20 19:37:22 +0000 | [diff] [blame] | 6787 | { |
| 6788 | clearopbeep(cap->oap); |
| 6789 | break; |
| 6790 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6791 | # ifdef FEAT_FOLDING |
| 6792 | if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) |
| 6793 | foldOpenCursor(); |
| 6794 | # endif |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6795 | } |
| 6796 | #endif |
| 6797 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6798 | /* Not a valid cap->nchar. */ |
| 6799 | else |
| 6800 | clearopbeep(cap->oap); |
| 6801 | } |
| 6802 | |
| 6803 | /* |
| 6804 | * Handle Normal mode "%" command. |
| 6805 | */ |
| 6806 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6807 | nv_percent(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6808 | { |
| 6809 | pos_T *pos; |
Bram Moolenaar | b2c0350 | 2010-07-02 20:20:09 +0200 | [diff] [blame] | 6810 | #if defined(FEAT_FOLDING) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6811 | linenr_T lnum = curwin->w_cursor.lnum; |
| 6812 | #endif |
| 6813 | |
| 6814 | cap->oap->inclusive = TRUE; |
| 6815 | if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ |
| 6816 | { |
| 6817 | if (cap->count0 > 100) |
| 6818 | clearopbeep(cap->oap); |
| 6819 | else |
| 6820 | { |
| 6821 | cap->oap->motion_type = MLINE; |
| 6822 | setpcmark(); |
| 6823 | /* Round up, so CTRL-G will give same value. Watch out for a |
| 6824 | * large line count, the line number must not go negative! */ |
| 6825 | if (curbuf->b_ml.ml_line_count > 1000000) |
| 6826 | curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) |
| 6827 | / 100L * cap->count0; |
| 6828 | else |
| 6829 | curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * |
| 6830 | cap->count0 + 99L) / 100L; |
| 6831 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 6832 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 6833 | beginline(BL_SOL | BL_FIX); |
| 6834 | } |
| 6835 | } |
| 6836 | else /* "%" : go to matching paren */ |
| 6837 | { |
| 6838 | cap->oap->motion_type = MCHAR; |
| 6839 | cap->oap->use_reg_one = TRUE; |
| 6840 | if ((pos = findmatch(cap->oap, NUL)) == NULL) |
| 6841 | clearopbeep(cap->oap); |
| 6842 | else |
| 6843 | { |
| 6844 | setpcmark(); |
| 6845 | curwin->w_cursor = *pos; |
| 6846 | curwin->w_set_curswant = TRUE; |
| 6847 | #ifdef FEAT_VIRTUALEDIT |
| 6848 | curwin->w_cursor.coladd = 0; |
| 6849 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6850 | adjust_for_sel(cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6851 | } |
| 6852 | } |
| 6853 | #ifdef FEAT_FOLDING |
| 6854 | if (cap->oap->op_type == OP_NOP |
| 6855 | && lnum != curwin->w_cursor.lnum |
| 6856 | && (fdo_flags & FDO_PERCENT) |
| 6857 | && KeyTyped) |
| 6858 | foldOpenCursor(); |
| 6859 | #endif |
| 6860 | } |
| 6861 | |
| 6862 | /* |
| 6863 | * Handle "(" and ")" commands. |
| 6864 | * cap->arg is BACKWARD for "(" and FORWARD for ")". |
| 6865 | */ |
| 6866 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6867 | nv_brace(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6868 | { |
| 6869 | cap->oap->motion_type = MCHAR; |
| 6870 | cap->oap->use_reg_one = TRUE; |
Bram Moolenaar | ebefac6 | 2005-12-28 22:39:57 +0000 | [diff] [blame] | 6871 | /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
| 6872 | cap->oap->inclusive = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6873 | curwin->w_set_curswant = TRUE; |
| 6874 | |
| 6875 | if (findsent(cap->arg, cap->count1) == FAIL) |
| 6876 | clearopbeep(cap->oap); |
| 6877 | else |
| 6878 | { |
Bram Moolenaar | 1f14d57 | 2008-01-12 16:12:10 +0000 | [diff] [blame] | 6879 | /* Don't leave the cursor on the NUL past end of line. */ |
| 6880 | adjust_cursor(cap->oap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6881 | #ifdef FEAT_VIRTUALEDIT |
| 6882 | curwin->w_cursor.coladd = 0; |
| 6883 | #endif |
| 6884 | #ifdef FEAT_FOLDING |
| 6885 | if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6886 | foldOpenCursor(); |
| 6887 | #endif |
| 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | /* |
| 6892 | * "m" command: Mark a position. |
| 6893 | */ |
| 6894 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6895 | nv_mark(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6896 | { |
| 6897 | if (!checkclearop(cap->oap)) |
| 6898 | { |
| 6899 | if (setmark(cap->nchar) == FAIL) |
| 6900 | clearopbeep(cap->oap); |
| 6901 | } |
| 6902 | } |
| 6903 | |
| 6904 | /* |
| 6905 | * "{" and "}" commands. |
| 6906 | * cmd->arg is BACKWARD for "{" and FORWARD for "}". |
| 6907 | */ |
| 6908 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6909 | nv_findpar(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6910 | { |
| 6911 | cap->oap->motion_type = MCHAR; |
| 6912 | cap->oap->inclusive = FALSE; |
| 6913 | cap->oap->use_reg_one = TRUE; |
| 6914 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 8b96d64 | 2005-09-05 22:05:30 +0000 | [diff] [blame] | 6915 | if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6916 | clearopbeep(cap->oap); |
| 6917 | else |
| 6918 | { |
| 6919 | #ifdef FEAT_VIRTUALEDIT |
| 6920 | curwin->w_cursor.coladd = 0; |
| 6921 | #endif |
| 6922 | #ifdef FEAT_FOLDING |
| 6923 | if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6924 | foldOpenCursor(); |
| 6925 | #endif |
| 6926 | } |
| 6927 | } |
| 6928 | |
| 6929 | /* |
| 6930 | * "u" command: Undo or make lower case. |
| 6931 | */ |
| 6932 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6933 | nv_undo(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6934 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 6935 | if (cap->oap->op_type == OP_LOWER || VIsual_active) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6936 | { |
| 6937 | /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ |
| 6938 | cap->cmdchar = 'g'; |
| 6939 | cap->nchar = 'u'; |
| 6940 | nv_operator(cap); |
| 6941 | } |
| 6942 | else |
| 6943 | nv_kundo(cap); |
| 6944 | } |
| 6945 | |
| 6946 | /* |
| 6947 | * <Undo> command. |
| 6948 | */ |
| 6949 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6950 | nv_kundo(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6951 | { |
| 6952 | if (!checkclearopq(cap->oap)) |
| 6953 | { |
| 6954 | u_undo((int)cap->count1); |
| 6955 | curwin->w_set_curswant = TRUE; |
| 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | /* |
| 6960 | * Handle the "r" command. |
| 6961 | */ |
| 6962 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6963 | nv_replace(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6964 | { |
| 6965 | char_u *ptr; |
| 6966 | int had_ctrl_v; |
| 6967 | long n; |
| 6968 | |
| 6969 | if (checkclearop(cap->oap)) |
| 6970 | return; |
| 6971 | |
| 6972 | /* get another character */ |
| 6973 | if (cap->nchar == Ctrl_V) |
| 6974 | { |
| 6975 | had_ctrl_v = Ctrl_V; |
| 6976 | cap->nchar = get_literal(); |
| 6977 | /* Don't redo a multibyte character with CTRL-V. */ |
| 6978 | if (cap->nchar > DEL) |
| 6979 | had_ctrl_v = NUL; |
| 6980 | } |
| 6981 | else |
| 6982 | had_ctrl_v = NUL; |
| 6983 | |
Bram Moolenaar | c2f5abc | 2007-08-08 19:42:05 +0000 | [diff] [blame] | 6984 | /* Abort if the character is a special key. */ |
| 6985 | if (IS_SPECIAL(cap->nchar)) |
| 6986 | { |
| 6987 | clearopbeep(cap->oap); |
| 6988 | return; |
| 6989 | } |
| 6990 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6991 | /* Visual mode "r" */ |
| 6992 | if (VIsual_active) |
| 6993 | { |
Bram Moolenaar | 57fb0da | 2009-02-04 10:46:25 +0000 | [diff] [blame] | 6994 | if (got_int) |
| 6995 | reset_VIsual(); |
Bram Moolenaar | d982053 | 2013-11-04 01:41:17 +0100 | [diff] [blame] | 6996 | if (had_ctrl_v) |
| 6997 | { |
| 6998 | if (cap->nchar == '\r') |
| 6999 | cap->nchar = -1; |
| 7000 | else if (cap->nchar == '\n') |
| 7001 | cap->nchar = -2; |
| 7002 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7003 | nv_operator(cap); |
| 7004 | return; |
| 7005 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7006 | |
| 7007 | #ifdef FEAT_VIRTUALEDIT |
| 7008 | /* Break tabs, etc. */ |
| 7009 | if (virtual_active()) |
| 7010 | { |
| 7011 | if (u_save_cursor() == FAIL) |
| 7012 | return; |
| 7013 | if (gchar_cursor() == NUL) |
| 7014 | { |
| 7015 | /* Add extra space and put the cursor on the first one. */ |
| 7016 | coladvance_force((colnr_T)(getviscol() + cap->count1)); |
| 7017 | curwin->w_cursor.col -= cap->count1; |
| 7018 | } |
| 7019 | else if (gchar_cursor() == TAB) |
| 7020 | coladvance_force(getviscol()); |
| 7021 | } |
| 7022 | #endif |
| 7023 | |
Bram Moolenaar | c2f5abc | 2007-08-08 19:42:05 +0000 | [diff] [blame] | 7024 | /* Abort if not enough characters to replace. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7025 | ptr = ml_get_cursor(); |
Bram Moolenaar | c2f5abc | 2007-08-08 19:42:05 +0000 | [diff] [blame] | 7026 | if (STRLEN(ptr) < (unsigned)cap->count1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7027 | #ifdef FEAT_MBYTE |
| 7028 | || (has_mbyte && mb_charlen(ptr) < cap->count1) |
| 7029 | #endif |
| 7030 | ) |
| 7031 | { |
| 7032 | clearopbeep(cap->oap); |
| 7033 | return; |
| 7034 | } |
| 7035 | |
| 7036 | /* |
| 7037 | * Replacing with a TAB is done by edit() when it is complicated because |
| 7038 | * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. |
| 7039 | * Other characters are done below to avoid problems with things like |
| 7040 | * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). |
| 7041 | */ |
| 7042 | if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) |
| 7043 | { |
| 7044 | stuffnumReadbuff(cap->count1); |
| 7045 | stuffcharReadbuff('R'); |
| 7046 | stuffcharReadbuff('\t'); |
| 7047 | stuffcharReadbuff(ESC); |
| 7048 | return; |
| 7049 | } |
| 7050 | |
| 7051 | /* save line for undo */ |
| 7052 | if (u_save_cursor() == FAIL) |
| 7053 | return; |
| 7054 | |
| 7055 | if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) |
| 7056 | { |
| 7057 | /* |
| 7058 | * Replace character(s) by a single newline. |
| 7059 | * Strange vi behaviour: Only one newline is inserted. |
| 7060 | * Delete the characters here. |
| 7061 | * Insert the newline with an insert command, takes care of |
| 7062 | * autoindent. The insert command depends on being on the last |
| 7063 | * character of a line or not. |
| 7064 | */ |
| 7065 | #ifdef FEAT_MBYTE |
| 7066 | (void)del_chars(cap->count1, FALSE); /* delete the characters */ |
| 7067 | #else |
Bram Moolenaar | da1b1a7 | 2005-12-18 21:59:16 +0000 | [diff] [blame] | 7068 | (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7069 | #endif |
| 7070 | stuffcharReadbuff('\r'); |
| 7071 | stuffcharReadbuff(ESC); |
| 7072 | |
| 7073 | /* Give 'r' to edit(), to get the redo command right. */ |
| 7074 | invoke_edit(cap, TRUE, 'r', FALSE); |
| 7075 | } |
| 7076 | else |
| 7077 | { |
| 7078 | prep_redo(cap->oap->regname, cap->count1, |
| 7079 | NUL, 'r', NUL, had_ctrl_v, cap->nchar); |
| 7080 | |
| 7081 | curbuf->b_op_start = curwin->w_cursor; |
| 7082 | #ifdef FEAT_MBYTE |
| 7083 | if (has_mbyte) |
| 7084 | { |
| 7085 | int old_State = State; |
| 7086 | |
| 7087 | if (cap->ncharC1 != 0) |
| 7088 | AppendCharToRedobuff(cap->ncharC1); |
| 7089 | if (cap->ncharC2 != 0) |
| 7090 | AppendCharToRedobuff(cap->ncharC2); |
| 7091 | |
| 7092 | /* This is slow, but it handles replacing a single-byte with a |
| 7093 | * multi-byte and the other way around. Also handles adding |
| 7094 | * composing characters for utf-8. */ |
| 7095 | for (n = cap->count1; n > 0; --n) |
| 7096 | { |
| 7097 | State = REPLACE; |
Bram Moolenaar | 8320da4 | 2012-04-30 18:18:47 +0200 | [diff] [blame] | 7098 | if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
| 7099 | { |
| 7100 | int c = ins_copychar(curwin->w_cursor.lnum |
| 7101 | + (cap->nchar == Ctrl_Y ? -1 : 1)); |
| 7102 | if (c != NUL) |
| 7103 | ins_char(c); |
| 7104 | else |
| 7105 | /* will be decremented further down */ |
| 7106 | ++curwin->w_cursor.col; |
| 7107 | } |
| 7108 | else |
| 7109 | ins_char(cap->nchar); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7110 | State = old_State; |
| 7111 | if (cap->ncharC1 != 0) |
| 7112 | ins_char(cap->ncharC1); |
| 7113 | if (cap->ncharC2 != 0) |
| 7114 | ins_char(cap->ncharC2); |
| 7115 | } |
| 7116 | } |
| 7117 | else |
| 7118 | #endif |
| 7119 | { |
| 7120 | /* |
| 7121 | * Replace the characters within one line. |
| 7122 | */ |
| 7123 | for (n = cap->count1; n > 0; --n) |
| 7124 | { |
| 7125 | /* |
| 7126 | * Get ptr again, because u_save and/or showmatch() will have |
| 7127 | * released the line. At the same time we let know that the |
| 7128 | * line will be changed. |
| 7129 | */ |
| 7130 | ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); |
Bram Moolenaar | 8320da4 | 2012-04-30 18:18:47 +0200 | [diff] [blame] | 7131 | if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
| 7132 | { |
| 7133 | int c = ins_copychar(curwin->w_cursor.lnum |
| 7134 | + (cap->nchar == Ctrl_Y ? -1 : 1)); |
| 7135 | if (c != NUL) |
| 7136 | ptr[curwin->w_cursor.col] = c; |
| 7137 | } |
| 7138 | else |
| 7139 | ptr[curwin->w_cursor.col] = cap->nchar; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7140 | if (p_sm && msg_silent == 0) |
| 7141 | showmatch(cap->nchar); |
| 7142 | ++curwin->w_cursor.col; |
| 7143 | } |
| 7144 | #ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 7145 | if (netbeans_active()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7146 | { |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 7147 | colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7148 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 7149 | netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 7150 | (long)cap->count1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7151 | netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 7152 | &ptr[start], (int)cap->count1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7153 | } |
| 7154 | #endif |
| 7155 | |
| 7156 | /* mark the buffer as changed and prepare for displaying */ |
| 7157 | changed_bytes(curwin->w_cursor.lnum, |
| 7158 | (colnr_T)(curwin->w_cursor.col - cap->count1)); |
| 7159 | } |
| 7160 | --curwin->w_cursor.col; /* cursor on the last replaced char */ |
| 7161 | #ifdef FEAT_MBYTE |
| 7162 | /* if the character on the left of the current cursor is a multi-byte |
| 7163 | * character, move two characters left */ |
| 7164 | if (has_mbyte) |
| 7165 | mb_adjust_cursor(); |
| 7166 | #endif |
| 7167 | curbuf->b_op_end = curwin->w_cursor; |
| 7168 | curwin->w_set_curswant = TRUE; |
| 7169 | set_last_insert(cap->nchar); |
| 7170 | } |
| 7171 | } |
| 7172 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7173 | /* |
| 7174 | * 'o': Exchange start and end of Visual area. |
| 7175 | * 'O': same, but in block mode exchange left and right corners. |
| 7176 | */ |
| 7177 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7178 | v_swap_corners(int cmdchar) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7179 | { |
| 7180 | pos_T old_cursor; |
| 7181 | colnr_T left, right; |
| 7182 | |
| 7183 | if (cmdchar == 'O' && VIsual_mode == Ctrl_V) |
| 7184 | { |
| 7185 | old_cursor = curwin->w_cursor; |
| 7186 | getvcols(curwin, &old_cursor, &VIsual, &left, &right); |
| 7187 | curwin->w_cursor.lnum = VIsual.lnum; |
| 7188 | coladvance(left); |
| 7189 | VIsual = curwin->w_cursor; |
| 7190 | |
| 7191 | curwin->w_cursor.lnum = old_cursor.lnum; |
| 7192 | curwin->w_curswant = right; |
| 7193 | /* 'selection "exclusive" and cursor at right-bottom corner: move it |
| 7194 | * right one column */ |
| 7195 | if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') |
| 7196 | ++curwin->w_curswant; |
| 7197 | coladvance(curwin->w_curswant); |
| 7198 | if (curwin->w_cursor.col == old_cursor.col |
| 7199 | #ifdef FEAT_VIRTUALEDIT |
| 7200 | && (!virtual_active() |
| 7201 | || curwin->w_cursor.coladd == old_cursor.coladd) |
| 7202 | #endif |
| 7203 | ) |
| 7204 | { |
| 7205 | curwin->w_cursor.lnum = VIsual.lnum; |
| 7206 | if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') |
| 7207 | ++right; |
| 7208 | coladvance(right); |
| 7209 | VIsual = curwin->w_cursor; |
| 7210 | |
| 7211 | curwin->w_cursor.lnum = old_cursor.lnum; |
| 7212 | coladvance(left); |
| 7213 | curwin->w_curswant = left; |
| 7214 | } |
| 7215 | } |
| 7216 | else |
| 7217 | { |
| 7218 | old_cursor = curwin->w_cursor; |
| 7219 | curwin->w_cursor = VIsual; |
| 7220 | VIsual = old_cursor; |
| 7221 | curwin->w_set_curswant = TRUE; |
| 7222 | } |
| 7223 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7224 | |
| 7225 | /* |
| 7226 | * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). |
| 7227 | */ |
| 7228 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7229 | nv_Replace(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7230 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7231 | if (VIsual_active) /* "R" is replace lines */ |
| 7232 | { |
| 7233 | cap->cmdchar = 'c'; |
| 7234 | cap->nchar = NUL; |
Bram Moolenaar | a390bb6 | 2013-03-13 19:02:41 +0100 | [diff] [blame] | 7235 | VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7236 | VIsual_mode = 'V'; |
| 7237 | nv_operator(cap); |
| 7238 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 7239 | else if (!checkclearopq(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7240 | { |
| 7241 | if (!curbuf->b_p_ma) |
| 7242 | EMSG(_(e_modifiable)); |
| 7243 | else |
| 7244 | { |
| 7245 | #ifdef FEAT_VIRTUALEDIT |
| 7246 | if (virtual_active()) |
| 7247 | coladvance(getviscol()); |
| 7248 | #endif |
| 7249 | invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); |
| 7250 | } |
| 7251 | } |
| 7252 | } |
| 7253 | |
| 7254 | #ifdef FEAT_VREPLACE |
| 7255 | /* |
| 7256 | * "gr". |
| 7257 | */ |
| 7258 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7259 | nv_vreplace(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7260 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7261 | if (VIsual_active) |
| 7262 | { |
| 7263 | cap->cmdchar = 'r'; |
| 7264 | cap->nchar = cap->extra_char; |
| 7265 | nv_replace(cap); /* Do same as "r" in Visual mode for now */ |
| 7266 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 7267 | else if (!checkclearopq(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7268 | { |
| 7269 | if (!curbuf->b_p_ma) |
| 7270 | EMSG(_(e_modifiable)); |
| 7271 | else |
| 7272 | { |
| 7273 | if (cap->extra_char == Ctrl_V) /* get another character */ |
| 7274 | cap->extra_char = get_literal(); |
| 7275 | stuffcharReadbuff(cap->extra_char); |
| 7276 | stuffcharReadbuff(ESC); |
| 7277 | # ifdef FEAT_VIRTUALEDIT |
| 7278 | if (virtual_active()) |
| 7279 | coladvance(getviscol()); |
| 7280 | # endif |
| 7281 | invoke_edit(cap, TRUE, 'v', FALSE); |
| 7282 | } |
| 7283 | } |
| 7284 | } |
| 7285 | #endif |
| 7286 | |
| 7287 | /* |
| 7288 | * Swap case for "~" command, when it does not work like an operator. |
| 7289 | */ |
| 7290 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7291 | n_swapchar(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7292 | { |
| 7293 | long n; |
| 7294 | pos_T startpos; |
| 7295 | int did_change = 0; |
| 7296 | #ifdef FEAT_NETBEANS_INTG |
| 7297 | pos_T pos; |
| 7298 | char_u *ptr; |
| 7299 | int count; |
| 7300 | #endif |
| 7301 | |
| 7302 | if (checkclearopq(cap->oap)) |
| 7303 | return; |
| 7304 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 7305 | if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7306 | { |
| 7307 | clearopbeep(cap->oap); |
| 7308 | return; |
| 7309 | } |
| 7310 | |
| 7311 | prep_redo_cmd(cap); |
| 7312 | |
| 7313 | if (u_save_cursor() == FAIL) |
| 7314 | return; |
| 7315 | |
| 7316 | startpos = curwin->w_cursor; |
| 7317 | #ifdef FEAT_NETBEANS_INTG |
| 7318 | pos = startpos; |
| 7319 | #endif |
| 7320 | for (n = cap->count1; n > 0; --n) |
| 7321 | { |
| 7322 | did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); |
| 7323 | inc_cursor(); |
| 7324 | if (gchar_cursor() == NUL) |
| 7325 | { |
| 7326 | if (vim_strchr(p_ww, '~') != NULL |
| 7327 | && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
| 7328 | { |
| 7329 | #ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 7330 | if (netbeans_active()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7331 | { |
| 7332 | if (did_change) |
| 7333 | { |
| 7334 | ptr = ml_get(pos.lnum); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 7335 | count = (int)STRLEN(ptr) - pos.col; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 7336 | netbeans_removed(curbuf, pos.lnum, pos.col, |
| 7337 | (long)count); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7338 | netbeans_inserted(curbuf, pos.lnum, pos.col, |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 7339 | &ptr[pos.col], count); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7340 | } |
| 7341 | pos.col = 0; |
| 7342 | pos.lnum++; |
| 7343 | } |
| 7344 | #endif |
| 7345 | ++curwin->w_cursor.lnum; |
| 7346 | curwin->w_cursor.col = 0; |
| 7347 | if (n > 1) |
| 7348 | { |
| 7349 | if (u_savesub(curwin->w_cursor.lnum) == FAIL) |
| 7350 | break; |
| 7351 | u_clearline(); |
| 7352 | } |
| 7353 | } |
| 7354 | else |
| 7355 | break; |
| 7356 | } |
| 7357 | } |
| 7358 | #ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 7359 | if (did_change && netbeans_active()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7360 | { |
| 7361 | ptr = ml_get(pos.lnum); |
| 7362 | count = curwin->w_cursor.col - pos.col; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 7363 | netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
| 7364 | netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7365 | } |
| 7366 | #endif |
| 7367 | |
| 7368 | |
| 7369 | check_cursor(); |
| 7370 | curwin->w_set_curswant = TRUE; |
| 7371 | if (did_change) |
| 7372 | { |
| 7373 | changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, |
| 7374 | 0L); |
| 7375 | curbuf->b_op_start = startpos; |
| 7376 | curbuf->b_op_end = curwin->w_cursor; |
| 7377 | if (curbuf->b_op_end.col > 0) |
| 7378 | --curbuf->b_op_end.col; |
| 7379 | } |
| 7380 | } |
| 7381 | |
| 7382 | /* |
| 7383 | * Move cursor to mark. |
| 7384 | */ |
| 7385 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7386 | nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7387 | { |
| 7388 | if (check_mark(pos) == FAIL) |
| 7389 | clearop(cap->oap); |
| 7390 | else |
| 7391 | { |
| 7392 | if (cap->cmdchar == '\'' |
| 7393 | || cap->cmdchar == '`' |
| 7394 | || cap->cmdchar == '[' |
| 7395 | || cap->cmdchar == ']') |
| 7396 | setpcmark(); |
| 7397 | curwin->w_cursor = *pos; |
| 7398 | if (flag) |
| 7399 | beginline(BL_WHITE | BL_FIX); |
| 7400 | else |
| 7401 | check_cursor(); |
| 7402 | } |
| 7403 | cap->oap->motion_type = flag ? MLINE : MCHAR; |
| 7404 | if (cap->cmdchar == '`') |
| 7405 | cap->oap->use_reg_one = TRUE; |
| 7406 | cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ |
| 7407 | curwin->w_set_curswant = TRUE; |
| 7408 | } |
| 7409 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7410 | /* |
| 7411 | * Handle commands that are operators in Visual mode. |
| 7412 | */ |
| 7413 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7414 | v_visop(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7415 | { |
| 7416 | static char_u trans[] = "YyDdCcxdXdAAIIrr"; |
| 7417 | |
| 7418 | /* Uppercase means linewise, except in block mode, then "D" deletes till |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 7419 | * the end of the line, and "C" replaces till EOL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7420 | if (isupper(cap->cmdchar)) |
| 7421 | { |
| 7422 | if (VIsual_mode != Ctrl_V) |
Bram Moolenaar | a390bb6 | 2013-03-13 19:02:41 +0100 | [diff] [blame] | 7423 | { |
| 7424 | VIsual_mode_orig = VIsual_mode; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7425 | VIsual_mode = 'V'; |
Bram Moolenaar | a390bb6 | 2013-03-13 19:02:41 +0100 | [diff] [blame] | 7426 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7427 | else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
| 7428 | curwin->w_curswant = MAXCOL; |
| 7429 | } |
| 7430 | cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); |
| 7431 | nv_operator(cap); |
| 7432 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7433 | |
| 7434 | /* |
| 7435 | * "s" and "S" commands. |
| 7436 | */ |
| 7437 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7438 | nv_subst(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7439 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7440 | if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
| 7441 | { |
| 7442 | if (cap->cmdchar == 'S') |
Bram Moolenaar | a390bb6 | 2013-03-13 19:02:41 +0100 | [diff] [blame] | 7443 | { |
| 7444 | VIsual_mode_orig = VIsual_mode; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7445 | VIsual_mode = 'V'; |
Bram Moolenaar | a390bb6 | 2013-03-13 19:02:41 +0100 | [diff] [blame] | 7446 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7447 | cap->cmdchar = 'c'; |
| 7448 | nv_operator(cap); |
| 7449 | } |
| 7450 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7451 | nv_optrans(cap); |
| 7452 | } |
| 7453 | |
| 7454 | /* |
| 7455 | * Abbreviated commands. |
| 7456 | */ |
| 7457 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7458 | nv_abbrev(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7459 | { |
| 7460 | if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) |
| 7461 | cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ |
| 7462 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7463 | /* in Visual mode these commands are operators */ |
| 7464 | if (VIsual_active) |
| 7465 | v_visop(cap); |
| 7466 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7467 | nv_optrans(cap); |
| 7468 | } |
| 7469 | |
| 7470 | /* |
| 7471 | * Translate a command into another command. |
| 7472 | */ |
| 7473 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7474 | nv_optrans(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7475 | { |
| 7476 | static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", |
| 7477 | (char_u *)"d$", (char_u *)"c$", |
| 7478 | (char_u *)"cl", (char_u *)"cc", |
| 7479 | (char_u *)"yy", (char_u *)":s\r"}; |
| 7480 | static char_u *str = (char_u *)"xXDCsSY&"; |
| 7481 | |
| 7482 | if (!checkclearopq(cap->oap)) |
| 7483 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 7484 | /* In Vi "2D" doesn't delete the next line. Can't translate it |
| 7485 | * either, because "2." should also not use the count. */ |
| 7486 | if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) |
| 7487 | { |
| 7488 | cap->oap->start = curwin->w_cursor; |
| 7489 | cap->oap->op_type = OP_DELETE; |
Bram Moolenaar | 8af1fbf | 2008-01-05 12:35:21 +0000 | [diff] [blame] | 7490 | #ifdef FEAT_EVAL |
| 7491 | set_op_var(OP_DELETE); |
| 7492 | #endif |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 7493 | cap->count1 = 1; |
| 7494 | nv_dollar(cap); |
| 7495 | finish_op = TRUE; |
| 7496 | ResetRedobuff(); |
| 7497 | AppendCharToRedobuff('D'); |
| 7498 | } |
| 7499 | else |
| 7500 | { |
| 7501 | if (cap->count0) |
| 7502 | stuffnumReadbuff(cap->count0); |
| 7503 | stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); |
| 7504 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7505 | } |
| 7506 | cap->opcount = 0; |
| 7507 | } |
| 7508 | |
| 7509 | /* |
| 7510 | * "'" and "`" commands. Also for "g'" and "g`". |
| 7511 | * cap->arg is TRUE for "'" and "g'". |
| 7512 | */ |
| 7513 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7514 | nv_gomark(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7515 | { |
| 7516 | pos_T *pos; |
| 7517 | int c; |
| 7518 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 8754deb | 2013-01-17 13:24:08 +0100 | [diff] [blame] | 7519 | pos_T old_cursor = curwin->w_cursor; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7520 | int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
| 7521 | #endif |
| 7522 | |
| 7523 | if (cap->cmdchar == 'g') |
| 7524 | c = cap->extra_char; |
| 7525 | else |
| 7526 | c = cap->nchar; |
| 7527 | pos = getmark(c, (cap->oap->op_type == OP_NOP)); |
| 7528 | if (pos == (pos_T *)-1) /* jumped to other file */ |
| 7529 | { |
| 7530 | if (cap->arg) |
| 7531 | { |
| 7532 | check_cursor_lnum(); |
| 7533 | beginline(BL_WHITE | BL_FIX); |
| 7534 | } |
| 7535 | else |
| 7536 | check_cursor(); |
| 7537 | } |
| 7538 | else |
| 7539 | nv_cursormark(cap, cap->arg, pos); |
| 7540 | |
| 7541 | #ifdef FEAT_VIRTUALEDIT |
| 7542 | /* May need to clear the coladd that a mark includes. */ |
| 7543 | if (!virtual_active()) |
| 7544 | curwin->w_cursor.coladd = 0; |
| 7545 | #endif |
Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 7546 | check_cursor_col(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7547 | #ifdef FEAT_FOLDING |
| 7548 | if (cap->oap->op_type == OP_NOP |
Bram Moolenaar | 15364d7 | 2013-01-24 21:00:20 +0100 | [diff] [blame] | 7549 | && pos != NULL |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 7550 | && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7551 | && (fdo_flags & FDO_MARK) |
| 7552 | && old_KeyTyped) |
| 7553 | foldOpenCursor(); |
| 7554 | #endif |
| 7555 | } |
| 7556 | |
| 7557 | /* |
| 7558 | * Handle CTRL-O, CTRL-I, "g;" and "g," commands. |
| 7559 | */ |
| 7560 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7561 | nv_pcmark(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7562 | { |
| 7563 | #ifdef FEAT_JUMPLIST |
| 7564 | pos_T *pos; |
| 7565 | # ifdef FEAT_FOLDING |
| 7566 | linenr_T lnum = curwin->w_cursor.lnum; |
| 7567 | int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
| 7568 | # endif |
| 7569 | |
| 7570 | if (!checkclearopq(cap->oap)) |
| 7571 | { |
| 7572 | if (cap->cmdchar == 'g') |
| 7573 | pos = movechangelist((int)cap->count1); |
| 7574 | else |
| 7575 | pos = movemark((int)cap->count1); |
| 7576 | if (pos == (pos_T *)-1) /* jump to other file */ |
| 7577 | { |
| 7578 | curwin->w_set_curswant = TRUE; |
| 7579 | check_cursor(); |
| 7580 | } |
| 7581 | else if (pos != NULL) /* can jump */ |
| 7582 | nv_cursormark(cap, FALSE, pos); |
| 7583 | else if (cap->cmdchar == 'g') |
| 7584 | { |
| 7585 | if (curbuf->b_changelistlen == 0) |
| 7586 | EMSG(_("E664: changelist is empty")); |
| 7587 | else if (cap->count1 < 0) |
| 7588 | EMSG(_("E662: At start of changelist")); |
| 7589 | else |
| 7590 | EMSG(_("E663: At end of changelist")); |
| 7591 | } |
| 7592 | else |
| 7593 | clearopbeep(cap->oap); |
| 7594 | # ifdef FEAT_FOLDING |
| 7595 | if (cap->oap->op_type == OP_NOP |
| 7596 | && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) |
| 7597 | && (fdo_flags & FDO_MARK) |
| 7598 | && old_KeyTyped) |
| 7599 | foldOpenCursor(); |
| 7600 | # endif |
| 7601 | } |
| 7602 | #else |
| 7603 | clearopbeep(cap->oap); |
| 7604 | #endif |
| 7605 | } |
| 7606 | |
| 7607 | /* |
| 7608 | * Handle '"' command. |
| 7609 | */ |
| 7610 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7611 | nv_regname(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7612 | { |
| 7613 | if (checkclearop(cap->oap)) |
| 7614 | return; |
| 7615 | #ifdef FEAT_EVAL |
| 7616 | if (cap->nchar == '=') |
| 7617 | cap->nchar = get_expr_register(); |
| 7618 | #endif |
| 7619 | if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) |
| 7620 | { |
| 7621 | cap->oap->regname = cap->nchar; |
| 7622 | cap->opcount = cap->count0; /* remember count before '"' */ |
| 7623 | #ifdef FEAT_EVAL |
| 7624 | set_reg_var(cap->oap->regname); |
| 7625 | #endif |
| 7626 | } |
| 7627 | else |
| 7628 | clearopbeep(cap->oap); |
| 7629 | } |
| 7630 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7631 | /* |
| 7632 | * Handle "v", "V" and "CTRL-V" commands. |
| 7633 | * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg |
| 7634 | * is TRUE. |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 7635 | * Handle CTRL-Q just like CTRL-V. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7636 | */ |
| 7637 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7638 | nv_visual(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7639 | { |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 7640 | if (cap->cmdchar == Ctrl_Q) |
| 7641 | cap->cmdchar = Ctrl_V; |
| 7642 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7643 | /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
| 7644 | * characterwise, linewise, or blockwise. */ |
| 7645 | if (cap->oap->op_type != OP_NOP) |
| 7646 | { |
| 7647 | cap->oap->motion_force = cap->cmdchar; |
| 7648 | finish_op = FALSE; /* operator doesn't finish now but later */ |
| 7649 | return; |
| 7650 | } |
| 7651 | |
| 7652 | VIsual_select = cap->arg; |
| 7653 | if (VIsual_active) /* change Visual mode */ |
| 7654 | { |
| 7655 | if (VIsual_mode == cap->cmdchar) /* stop visual mode */ |
| 7656 | end_visual_mode(); |
| 7657 | else /* toggle char/block mode */ |
| 7658 | { /* or char/line mode */ |
| 7659 | VIsual_mode = cap->cmdchar; |
| 7660 | showmode(); |
| 7661 | } |
| 7662 | redraw_curbuf_later(INVERTED); /* update the inversion */ |
| 7663 | } |
| 7664 | else /* start Visual mode */ |
| 7665 | { |
| 7666 | check_visual_highlight(); |
Bram Moolenaar | 6057b9c | 2012-05-25 13:12:36 +0200 | [diff] [blame] | 7667 | if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7668 | { |
Bram Moolenaar | 6057b9c | 2012-05-25 13:12:36 +0200 | [diff] [blame] | 7669 | /* use previously selected part */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7670 | VIsual = curwin->w_cursor; |
| 7671 | |
| 7672 | VIsual_active = TRUE; |
| 7673 | VIsual_reselect = TRUE; |
| 7674 | if (!cap->arg) |
| 7675 | /* start Select mode when 'selectmode' contains "cmd" */ |
| 7676 | may_start_select('c'); |
| 7677 | #ifdef FEAT_MOUSE |
| 7678 | setmouse(); |
| 7679 | #endif |
Bram Moolenaar | 09df312 | 2006-01-23 22:23:09 +0000 | [diff] [blame] | 7680 | if (p_smd && msg_silent == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7681 | redraw_cmdline = TRUE; /* show visual mode later */ |
| 7682 | /* |
| 7683 | * For V and ^V, we multiply the number of lines even if there |
| 7684 | * was only one -- webb |
| 7685 | */ |
| 7686 | if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) |
| 7687 | { |
| 7688 | curwin->w_cursor.lnum += |
| 7689 | resel_VIsual_line_count * cap->count0 - 1; |
| 7690 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 7691 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 7692 | } |
| 7693 | VIsual_mode = resel_VIsual_mode; |
| 7694 | if (VIsual_mode == 'v') |
| 7695 | { |
| 7696 | if (resel_VIsual_line_count <= 1) |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 7697 | { |
| 7698 | validate_virtcol(); |
| 7699 | curwin->w_curswant = curwin->w_virtcol |
| 7700 | + resel_VIsual_vcol * cap->count0 - 1; |
| 7701 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7702 | else |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 7703 | curwin->w_curswant = resel_VIsual_vcol; |
| 7704 | coladvance(curwin->w_curswant); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7705 | } |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 7706 | if (resel_VIsual_vcol == MAXCOL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7707 | { |
| 7708 | curwin->w_curswant = MAXCOL; |
| 7709 | coladvance((colnr_T)MAXCOL); |
| 7710 | } |
| 7711 | else if (VIsual_mode == Ctrl_V) |
| 7712 | { |
| 7713 | validate_virtcol(); |
| 7714 | curwin->w_curswant = curwin->w_virtcol |
Bram Moolenaar | ca0c9fc | 2011-10-04 21:22:44 +0200 | [diff] [blame] | 7715 | + resel_VIsual_vcol * cap->count0 - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7716 | coladvance(curwin->w_curswant); |
| 7717 | } |
| 7718 | else |
| 7719 | curwin->w_set_curswant = TRUE; |
| 7720 | redraw_curbuf_later(INVERTED); /* show the inversion */ |
| 7721 | } |
| 7722 | else |
| 7723 | { |
| 7724 | if (!cap->arg) |
| 7725 | /* start Select mode when 'selectmode' contains "cmd" */ |
| 7726 | may_start_select('c'); |
| 7727 | n_start_visual_mode(cap->cmdchar); |
Bram Moolenaar | 6057b9c | 2012-05-25 13:12:36 +0200 | [diff] [blame] | 7728 | if (VIsual_mode != 'V' && *p_sel == 'e') |
| 7729 | ++cap->count1; /* include one more char */ |
| 7730 | if (cap->count0 > 0 && --cap->count1 > 0) |
| 7731 | { |
| 7732 | /* With a count select that many characters or lines. */ |
| 7733 | if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) |
| 7734 | nv_right(cap); |
| 7735 | else if (VIsual_mode == 'V') |
| 7736 | nv_down(cap); |
| 7737 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7738 | } |
| 7739 | } |
| 7740 | } |
| 7741 | |
| 7742 | /* |
| 7743 | * Start selection for Shift-movement keys. |
| 7744 | */ |
| 7745 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7746 | start_selection(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7747 | { |
| 7748 | /* if 'selectmode' contains "key", start Select mode */ |
| 7749 | may_start_select('k'); |
| 7750 | n_start_visual_mode('v'); |
| 7751 | } |
| 7752 | |
| 7753 | /* |
| 7754 | * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. |
| 7755 | */ |
| 7756 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7757 | may_start_select(int c) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7758 | { |
| 7759 | VIsual_select = (stuff_empty() && typebuf_typed() |
| 7760 | && (vim_strchr(p_slm, c) != NULL)); |
| 7761 | } |
| 7762 | |
| 7763 | /* |
| 7764 | * Start Visual mode "c". |
| 7765 | * Should set VIsual_select before calling this. |
| 7766 | */ |
| 7767 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7768 | n_start_visual_mode(int c) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7769 | { |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 7770 | #ifdef FEAT_CONCEAL |
| 7771 | /* Check for redraw before changing the state. */ |
Bram Moolenaar | 8e46927 | 2010-07-28 19:38:16 +0200 | [diff] [blame] | 7772 | conceal_check_cursur_line(); |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 7773 | #endif |
| 7774 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7775 | VIsual_mode = c; |
| 7776 | VIsual_active = TRUE; |
| 7777 | VIsual_reselect = TRUE; |
| 7778 | #ifdef FEAT_VIRTUALEDIT |
| 7779 | /* Corner case: the 0 position in a tab may change when going into |
| 7780 | * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. |
| 7781 | */ |
| 7782 | if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) |
Bram Moolenaar | 2dac213 | 2012-08-15 13:31:00 +0200 | [diff] [blame] | 7783 | { |
| 7784 | validate_virtcol(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7785 | coladvance(curwin->w_virtcol); |
Bram Moolenaar | 2dac213 | 2012-08-15 13:31:00 +0200 | [diff] [blame] | 7786 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7787 | #endif |
| 7788 | VIsual = curwin->w_cursor; |
| 7789 | |
| 7790 | #ifdef FEAT_FOLDING |
| 7791 | foldAdjustVisual(); |
| 7792 | #endif |
| 7793 | |
| 7794 | #ifdef FEAT_MOUSE |
| 7795 | setmouse(); |
| 7796 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 7797 | #ifdef FEAT_CONCEAL |
| 7798 | /* Check for redraw after changing the state. */ |
Bram Moolenaar | 8e46927 | 2010-07-28 19:38:16 +0200 | [diff] [blame] | 7799 | conceal_check_cursur_line(); |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 7800 | #endif |
| 7801 | |
Bram Moolenaar | 09df312 | 2006-01-23 22:23:09 +0000 | [diff] [blame] | 7802 | if (p_smd && msg_silent == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7803 | redraw_cmdline = TRUE; /* show visual mode later */ |
| 7804 | #ifdef FEAT_CLIPBOARD |
| 7805 | /* Make sure the clipboard gets updated. Needed because start and |
| 7806 | * end may still be the same, and the selection needs to be owned */ |
| 7807 | clip_star.vmode = NUL; |
| 7808 | #endif |
| 7809 | |
| 7810 | /* Only need to redraw this line, unless still need to redraw an old |
| 7811 | * Visual area (when 'lazyredraw' is set). */ |
| 7812 | if (curwin->w_redr_type < INVERTED) |
| 7813 | { |
| 7814 | curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 7815 | curwin->w_old_visual_lnum = curwin->w_cursor.lnum; |
| 7816 | } |
| 7817 | } |
| 7818 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7819 | |
| 7820 | /* |
| 7821 | * CTRL-W: Window commands |
| 7822 | */ |
| 7823 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7824 | nv_window(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7825 | { |
Bram Moolenaar | 938783d | 2017-07-16 20:13:26 +0200 | [diff] [blame] | 7826 | if (cap->nchar == ':') |
| 7827 | /* "CTRL-W :" is the same as typing ":"; useful in a terminal window */ |
| 7828 | nv_colon(cap); |
| 7829 | else if (!checkclearop(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7830 | do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7831 | } |
| 7832 | |
| 7833 | /* |
| 7834 | * CTRL-Z: Suspend |
| 7835 | */ |
| 7836 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7837 | nv_suspend(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7838 | { |
| 7839 | clearop(cap->oap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7840 | if (VIsual_active) |
| 7841 | end_visual_mode(); /* stop Visual mode */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7842 | do_cmdline_cmd((char_u *)"st"); |
| 7843 | } |
| 7844 | |
| 7845 | /* |
| 7846 | * Commands starting with "g". |
| 7847 | */ |
| 7848 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7849 | nv_g_cmd(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7850 | { |
| 7851 | oparg_T *oap = cap->oap; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7852 | pos_T tpos; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7853 | int i; |
| 7854 | int flag = FALSE; |
| 7855 | |
| 7856 | switch (cap->nchar) |
| 7857 | { |
Bram Moolenaar | 3a304b2 | 2015-06-25 13:57:36 +0200 | [diff] [blame] | 7858 | case Ctrl_A: |
| 7859 | case Ctrl_X: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7860 | #ifdef MEM_PROFILE |
| 7861 | /* |
| 7862 | * "g^A": dump log of used memory. |
| 7863 | */ |
Bram Moolenaar | 3a304b2 | 2015-06-25 13:57:36 +0200 | [diff] [blame] | 7864 | if (!VIsual_active && cap->nchar == Ctrl_A) |
| 7865 | vim_mem_profile_dump(); |
| 7866 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7867 | #endif |
Bram Moolenaar | 3a304b2 | 2015-06-25 13:57:36 +0200 | [diff] [blame] | 7868 | /* |
| 7869 | * "g^A/g^X": sequentially increment visually selected region |
| 7870 | */ |
| 7871 | if (VIsual_active) |
| 7872 | { |
| 7873 | cap->arg = TRUE; |
| 7874 | cap->cmdchar = cap->nchar; |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 7875 | cap->nchar = NUL; |
Bram Moolenaar | 3a304b2 | 2015-06-25 13:57:36 +0200 | [diff] [blame] | 7876 | nv_addsub(cap); |
| 7877 | } |
| 7878 | else |
| 7879 | clearopbeep(oap); |
| 7880 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7881 | |
| 7882 | #ifdef FEAT_VREPLACE |
| 7883 | /* |
| 7884 | * "gR": Enter virtual replace mode. |
| 7885 | */ |
| 7886 | case 'R': |
| 7887 | cap->arg = TRUE; |
| 7888 | nv_Replace(cap); |
| 7889 | break; |
| 7890 | |
| 7891 | case 'r': |
| 7892 | nv_vreplace(cap); |
| 7893 | break; |
| 7894 | #endif |
| 7895 | |
| 7896 | case '&': |
| 7897 | do_cmdline_cmd((char_u *)"%s//~/&"); |
| 7898 | break; |
| 7899 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7900 | /* |
| 7901 | * "gv": Reselect the previous Visual area. If Visual already active, |
| 7902 | * exchange previous and current Visual area. |
| 7903 | */ |
| 7904 | case 'v': |
| 7905 | if (checkclearop(oap)) |
| 7906 | break; |
| 7907 | |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 7908 | if ( curbuf->b_visual.vi_start.lnum == 0 |
| 7909 | || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count |
| 7910 | || curbuf->b_visual.vi_end.lnum == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7911 | beep_flush(); |
| 7912 | else |
| 7913 | { |
| 7914 | /* set w_cursor to the start of the Visual area, tpos to the end */ |
| 7915 | if (VIsual_active) |
| 7916 | { |
| 7917 | i = VIsual_mode; |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 7918 | VIsual_mode = curbuf->b_visual.vi_mode; |
| 7919 | curbuf->b_visual.vi_mode = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7920 | # ifdef FEAT_EVAL |
| 7921 | curbuf->b_visual_mode_eval = i; |
| 7922 | # endif |
| 7923 | i = curwin->w_curswant; |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 7924 | curwin->w_curswant = curbuf->b_visual.vi_curswant; |
| 7925 | curbuf->b_visual.vi_curswant = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7926 | |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 7927 | tpos = curbuf->b_visual.vi_end; |
| 7928 | curbuf->b_visual.vi_end = curwin->w_cursor; |
| 7929 | curwin->w_cursor = curbuf->b_visual.vi_start; |
| 7930 | curbuf->b_visual.vi_start = VIsual; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7931 | } |
| 7932 | else |
| 7933 | { |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 7934 | VIsual_mode = curbuf->b_visual.vi_mode; |
| 7935 | curwin->w_curswant = curbuf->b_visual.vi_curswant; |
| 7936 | tpos = curbuf->b_visual.vi_end; |
| 7937 | curwin->w_cursor = curbuf->b_visual.vi_start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7938 | } |
| 7939 | |
| 7940 | VIsual_active = TRUE; |
| 7941 | VIsual_reselect = TRUE; |
| 7942 | |
| 7943 | /* Set Visual to the start and w_cursor to the end of the Visual |
| 7944 | * area. Make sure they are on an existing character. */ |
| 7945 | check_cursor(); |
| 7946 | VIsual = curwin->w_cursor; |
| 7947 | curwin->w_cursor = tpos; |
| 7948 | check_cursor(); |
| 7949 | update_topline(); |
| 7950 | /* |
| 7951 | * When called from normal "g" command: start Select mode when |
| 7952 | * 'selectmode' contains "cmd". When called for K_SELECT, always |
| 7953 | * start Select mode. |
| 7954 | */ |
| 7955 | if (cap->arg) |
| 7956 | VIsual_select = TRUE; |
| 7957 | else |
| 7958 | may_start_select('c'); |
| 7959 | #ifdef FEAT_MOUSE |
| 7960 | setmouse(); |
| 7961 | #endif |
| 7962 | #ifdef FEAT_CLIPBOARD |
| 7963 | /* Make sure the clipboard gets updated. Needed because start and |
| 7964 | * end are still the same, and the selection needs to be owned */ |
| 7965 | clip_star.vmode = NUL; |
| 7966 | #endif |
| 7967 | redraw_curbuf_later(INVERTED); |
| 7968 | showmode(); |
| 7969 | } |
| 7970 | break; |
| 7971 | /* |
| 7972 | * "gV": Don't reselect the previous Visual area after a Select mode |
| 7973 | * mapping of menu. |
| 7974 | */ |
| 7975 | case 'V': |
| 7976 | VIsual_reselect = FALSE; |
| 7977 | break; |
| 7978 | |
| 7979 | /* |
| 7980 | * "gh": start Select mode. |
| 7981 | * "gH": start Select line mode. |
| 7982 | * "g^H": start Select block mode. |
| 7983 | */ |
| 7984 | case K_BS: |
| 7985 | cap->nchar = Ctrl_H; |
| 7986 | /* FALLTHROUGH */ |
| 7987 | case 'h': |
| 7988 | case 'H': |
| 7989 | case Ctrl_H: |
| 7990 | # ifdef EBCDIC |
| 7991 | /* EBCDIC: 'v'-'h' != '^v'-'^h' */ |
| 7992 | if (cap->nchar == Ctrl_H) |
| 7993 | cap->cmdchar = Ctrl_V; |
| 7994 | else |
| 7995 | # endif |
| 7996 | cap->cmdchar = cap->nchar + ('v' - 'h'); |
| 7997 | cap->arg = TRUE; |
| 7998 | nv_visual(cap); |
| 7999 | break; |
Bram Moolenaar | 641e286 | 2012-07-25 15:06:34 +0200 | [diff] [blame] | 8000 | |
| 8001 | /* "gn", "gN" visually select next/previous search match |
| 8002 | * "gn" selects next match |
| 8003 | * "gN" selects previous match |
| 8004 | */ |
| 8005 | case 'N': |
| 8006 | case 'n': |
| 8007 | if (!current_search(cap->count1, cap->nchar == 'n')) |
Bram Moolenaar | f00dc26 | 2012-10-21 03:54:33 +0200 | [diff] [blame] | 8008 | clearopbeep(oap); |
Bram Moolenaar | 641e286 | 2012-07-25 15:06:34 +0200 | [diff] [blame] | 8009 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8010 | |
| 8011 | /* |
| 8012 | * "gj" and "gk" two new funny movement keys -- up and down |
| 8013 | * movement based on *screen* line rather than *file* line. |
| 8014 | */ |
| 8015 | case 'j': |
| 8016 | case K_DOWN: |
| 8017 | /* with 'nowrap' it works just like the normal "j" command; also when |
| 8018 | * in a closed fold */ |
| 8019 | if (!curwin->w_p_wrap |
| 8020 | #ifdef FEAT_FOLDING |
| 8021 | || hasFolding(curwin->w_cursor.lnum, NULL, NULL) |
| 8022 | #endif |
| 8023 | ) |
| 8024 | { |
| 8025 | oap->motion_type = MLINE; |
| 8026 | i = cursor_down(cap->count1, oap->op_type == OP_NOP); |
| 8027 | } |
| 8028 | else |
| 8029 | i = nv_screengo(oap, FORWARD, cap->count1); |
| 8030 | if (i == FAIL) |
| 8031 | clearopbeep(oap); |
| 8032 | break; |
| 8033 | |
| 8034 | case 'k': |
| 8035 | case K_UP: |
| 8036 | /* with 'nowrap' it works just like the normal "k" command; also when |
| 8037 | * in a closed fold */ |
| 8038 | if (!curwin->w_p_wrap |
| 8039 | #ifdef FEAT_FOLDING |
| 8040 | || hasFolding(curwin->w_cursor.lnum, NULL, NULL) |
| 8041 | #endif |
| 8042 | ) |
| 8043 | { |
| 8044 | oap->motion_type = MLINE; |
| 8045 | i = cursor_up(cap->count1, oap->op_type == OP_NOP); |
| 8046 | } |
| 8047 | else |
| 8048 | i = nv_screengo(oap, BACKWARD, cap->count1); |
| 8049 | if (i == FAIL) |
| 8050 | clearopbeep(oap); |
| 8051 | break; |
| 8052 | |
| 8053 | /* |
| 8054 | * "gJ": join two lines without inserting a space. |
| 8055 | */ |
| 8056 | case 'J': |
| 8057 | nv_join(cap); |
| 8058 | break; |
| 8059 | |
| 8060 | /* |
| 8061 | * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. |
| 8062 | * "gm": middle of "g0" and "g$". |
| 8063 | */ |
| 8064 | case '^': |
| 8065 | flag = TRUE; |
| 8066 | /* FALLTHROUGH */ |
| 8067 | |
| 8068 | case '0': |
| 8069 | case 'm': |
| 8070 | case K_HOME: |
| 8071 | case K_KHOME: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8072 | oap->motion_type = MCHAR; |
| 8073 | oap->inclusive = FALSE; |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 8074 | if (curwin->w_p_wrap && curwin->w_width != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8075 | { |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 8076 | int width1 = curwin->w_width - curwin_col_off(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8077 | int width2 = width1 + curwin_col_off2(); |
| 8078 | |
| 8079 | validate_virtcol(); |
| 8080 | i = 0; |
| 8081 | if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) |
| 8082 | i = (curwin->w_virtcol - width1) / width2 * width2 + width1; |
| 8083 | } |
| 8084 | else |
| 8085 | i = curwin->w_leftcol; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 8086 | /* Go to the middle of the screen line. When 'number' or |
| 8087 | * 'relativenumber' is on and lines are wrapping the middle can be more |
| 8088 | * to the left. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8089 | if (cap->nchar == 'm') |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 8090 | i += (curwin->w_width - curwin_col_off() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8091 | + ((curwin->w_p_wrap && i > 0) |
| 8092 | ? curwin_col_off2() : 0)) / 2; |
| 8093 | coladvance((colnr_T)i); |
| 8094 | if (flag) |
| 8095 | { |
| 8096 | do |
| 8097 | i = gchar_cursor(); |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 8098 | while (VIM_ISWHITE(i) && oneright() == OK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8099 | } |
| 8100 | curwin->w_set_curswant = TRUE; |
| 8101 | break; |
| 8102 | |
| 8103 | case '_': |
| 8104 | /* "g_": to the last non-blank character in the line or <count> lines |
| 8105 | * downward. */ |
| 8106 | cap->oap->motion_type = MCHAR; |
| 8107 | cap->oap->inclusive = TRUE; |
| 8108 | curwin->w_curswant = MAXCOL; |
| 8109 | if (cursor_down((long)(cap->count1 - 1), |
| 8110 | cap->oap->op_type == OP_NOP) == FAIL) |
| 8111 | clearopbeep(cap->oap); |
| 8112 | else |
| 8113 | { |
| 8114 | char_u *ptr = ml_get_curline(); |
| 8115 | |
| 8116 | /* In Visual mode we may end up after the line. */ |
| 8117 | if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) |
| 8118 | --curwin->w_cursor.col; |
| 8119 | |
| 8120 | /* Decrease the cursor column until it's on a non-blank. */ |
| 8121 | while (curwin->w_cursor.col > 0 |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 8122 | && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8123 | --curwin->w_cursor.col; |
| 8124 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 5890b2c | 2010-01-12 15:42:37 +0100 | [diff] [blame] | 8125 | adjust_for_sel(cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8126 | } |
| 8127 | break; |
| 8128 | |
| 8129 | case '$': |
| 8130 | case K_END: |
| 8131 | case K_KEND: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8132 | { |
| 8133 | int col_off = curwin_col_off(); |
| 8134 | |
| 8135 | oap->motion_type = MCHAR; |
| 8136 | oap->inclusive = TRUE; |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 8137 | if (curwin->w_p_wrap && curwin->w_width != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8138 | { |
| 8139 | curwin->w_curswant = MAXCOL; /* so we stay at the end */ |
| 8140 | if (cap->count1 == 1) |
| 8141 | { |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 8142 | int width1 = curwin->w_width - col_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8143 | int width2 = width1 + curwin_col_off2(); |
| 8144 | |
| 8145 | validate_virtcol(); |
| 8146 | i = width1 - 1; |
| 8147 | if (curwin->w_virtcol >= (colnr_T)width1) |
| 8148 | i += ((curwin->w_virtcol - width1) / width2 + 1) |
| 8149 | * width2; |
| 8150 | coladvance((colnr_T)i); |
Bram Moolenaar | b69510e | 2013-07-09 17:08:29 +0200 | [diff] [blame] | 8151 | |
| 8152 | /* Make sure we stick in this column. */ |
| 8153 | validate_virtcol(); |
| 8154 | curwin->w_curswant = curwin->w_virtcol; |
| 8155 | curwin->w_set_curswant = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8156 | #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
| 8157 | if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
| 8158 | { |
| 8159 | /* |
| 8160 | * Check for landing on a character that got split at |
| 8161 | * the end of the line. We do not want to advance to |
| 8162 | * the next screen line. |
| 8163 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8164 | if (curwin->w_virtcol > (colnr_T)i) |
| 8165 | --curwin->w_cursor.col; |
| 8166 | } |
| 8167 | #endif |
| 8168 | } |
| 8169 | else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) |
| 8170 | clearopbeep(oap); |
| 8171 | } |
| 8172 | else |
| 8173 | { |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 8174 | i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8175 | coladvance((colnr_T)i); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 8176 | |
| 8177 | /* Make sure we stick in this column. */ |
| 8178 | validate_virtcol(); |
| 8179 | curwin->w_curswant = curwin->w_virtcol; |
| 8180 | curwin->w_set_curswant = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8181 | } |
| 8182 | } |
| 8183 | break; |
| 8184 | |
| 8185 | /* |
| 8186 | * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" |
| 8187 | */ |
| 8188 | case '*': |
| 8189 | case '#': |
| 8190 | #if POUND != '#' |
| 8191 | case POUND: /* pound sign (sometimes equal to '#') */ |
| 8192 | #endif |
| 8193 | case Ctrl_RSB: /* :tag or :tselect for current identifier */ |
| 8194 | case ']': /* :tselect for current identifier */ |
| 8195 | nv_ident(cap); |
| 8196 | break; |
| 8197 | |
| 8198 | /* |
| 8199 | * ge and gE: go back to end of word |
| 8200 | */ |
| 8201 | case 'e': |
| 8202 | case 'E': |
| 8203 | oap->motion_type = MCHAR; |
| 8204 | curwin->w_set_curswant = TRUE; |
| 8205 | oap->inclusive = TRUE; |
| 8206 | if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) |
| 8207 | clearopbeep(oap); |
| 8208 | break; |
| 8209 | |
| 8210 | /* |
| 8211 | * "g CTRL-G": display info about cursor position |
| 8212 | */ |
| 8213 | case Ctrl_G: |
Bram Moolenaar | ed767a2 | 2016-01-03 22:49:16 +0100 | [diff] [blame] | 8214 | cursor_pos_info(NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8215 | break; |
| 8216 | |
| 8217 | /* |
| 8218 | * "gi": start Insert at the last position. |
| 8219 | */ |
| 8220 | case 'i': |
| 8221 | if (curbuf->b_last_insert.lnum != 0) |
| 8222 | { |
| 8223 | curwin->w_cursor = curbuf->b_last_insert; |
| 8224 | check_cursor_lnum(); |
| 8225 | i = (int)STRLEN(ml_get_curline()); |
| 8226 | if (curwin->w_cursor.col > (colnr_T)i) |
| 8227 | { |
| 8228 | #ifdef FEAT_VIRTUALEDIT |
| 8229 | if (virtual_active()) |
| 8230 | curwin->w_cursor.coladd += curwin->w_cursor.col - i; |
| 8231 | #endif |
| 8232 | curwin->w_cursor.col = i; |
| 8233 | } |
| 8234 | } |
| 8235 | cap->cmdchar = 'i'; |
| 8236 | nv_edit(cap); |
| 8237 | break; |
| 8238 | |
| 8239 | /* |
| 8240 | * "gI": Start insert in column 1. |
| 8241 | */ |
| 8242 | case 'I': |
| 8243 | beginline(0); |
| 8244 | if (!checkclearopq(oap)) |
| 8245 | invoke_edit(cap, FALSE, 'g', FALSE); |
| 8246 | break; |
| 8247 | |
| 8248 | #ifdef FEAT_SEARCHPATH |
| 8249 | /* |
| 8250 | * "gf": goto file, edit file under cursor |
| 8251 | * "]f" and "[f": can also be used. |
| 8252 | */ |
| 8253 | case 'f': |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8254 | case 'F': |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8255 | nv_gotofile(cap); |
| 8256 | break; |
| 8257 | #endif |
| 8258 | |
| 8259 | /* "g'm" and "g`m": jump to mark without setting pcmark */ |
| 8260 | case '\'': |
| 8261 | cap->arg = TRUE; |
| 8262 | /*FALLTHROUGH*/ |
| 8263 | case '`': |
| 8264 | nv_gomark(cap); |
| 8265 | break; |
| 8266 | |
| 8267 | /* |
| 8268 | * "gs": Goto sleep. |
| 8269 | */ |
| 8270 | case 's': |
| 8271 | do_sleep(cap->count1 * 1000L); |
| 8272 | break; |
| 8273 | |
| 8274 | /* |
| 8275 | * "ga": Display the ascii value of the character under the |
| 8276 | * cursor. It is displayed in decimal, hex, and octal. -- webb |
| 8277 | */ |
| 8278 | case 'a': |
| 8279 | do_ascii(NULL); |
| 8280 | break; |
| 8281 | |
| 8282 | #ifdef FEAT_MBYTE |
| 8283 | /* |
| 8284 | * "g8": Display the bytes used for the UTF-8 character under the |
| 8285 | * cursor. It is displayed in hex. |
Bram Moolenaar | a83c3e0 | 2006-03-17 23:10:44 +0000 | [diff] [blame] | 8286 | * "8g8" finds illegal byte sequence. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8287 | */ |
| 8288 | case '8': |
Bram Moolenaar | a83c3e0 | 2006-03-17 23:10:44 +0000 | [diff] [blame] | 8289 | if (cap->count0 == 8) |
| 8290 | utf_find_illegal(); |
| 8291 | else |
| 8292 | show_utf8(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8293 | break; |
| 8294 | #endif |
| 8295 | |
Bram Moolenaar | 60402d6 | 2017-04-20 18:54:50 +0200 | [diff] [blame] | 8296 | /* "g<": show scrollback text */ |
Bram Moolenaar | cfc7d63 | 2005-07-28 22:28:16 +0000 | [diff] [blame] | 8297 | case '<': |
| 8298 | show_sb_text(); |
| 8299 | break; |
| 8300 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8301 | /* |
| 8302 | * "gg": Goto the first line in file. With a count it goes to |
| 8303 | * that line number like for "G". -- webb |
| 8304 | */ |
| 8305 | case 'g': |
| 8306 | cap->arg = FALSE; |
| 8307 | nv_goto(cap); |
| 8308 | break; |
| 8309 | |
| 8310 | /* |
| 8311 | * Two-character operators: |
| 8312 | * "gq" Format text |
| 8313 | * "gw" Format text and keep cursor position |
| 8314 | * "g~" Toggle the case of the text. |
| 8315 | * "gu" Change text to lower case. |
| 8316 | * "gU" Change text to upper case. |
| 8317 | * "g?" rot13 encoding |
Bram Moolenaar | 12033fb | 2005-12-16 21:49:31 +0000 | [diff] [blame] | 8318 | * "g@" call 'operatorfunc' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8319 | */ |
| 8320 | case 'q': |
| 8321 | case 'w': |
| 8322 | oap->cursor_start = curwin->w_cursor; |
| 8323 | /*FALLTHROUGH*/ |
| 8324 | case '~': |
| 8325 | case 'u': |
| 8326 | case 'U': |
| 8327 | case '?': |
Bram Moolenaar | 12033fb | 2005-12-16 21:49:31 +0000 | [diff] [blame] | 8328 | case '@': |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8329 | nv_operator(cap); |
| 8330 | break; |
| 8331 | |
| 8332 | /* |
Bram Moolenaar | f711faf | 2007-05-10 16:48:19 +0000 | [diff] [blame] | 8333 | * "gd": Find first occurrence of pattern under the cursor in the |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8334 | * current function |
| 8335 | * "gD": idem, but in the current file. |
| 8336 | */ |
| 8337 | case 'd': |
| 8338 | case 'D': |
Bram Moolenaar | f75a963 | 2005-09-13 21:20:47 +0000 | [diff] [blame] | 8339 | nv_gd(oap, cap->nchar, (int)cap->count0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8340 | break; |
| 8341 | |
| 8342 | #ifdef FEAT_MOUSE |
| 8343 | /* |
| 8344 | * g<*Mouse> : <C-*mouse> |
| 8345 | */ |
| 8346 | case K_MIDDLEMOUSE: |
| 8347 | case K_MIDDLEDRAG: |
| 8348 | case K_MIDDLERELEASE: |
| 8349 | case K_LEFTMOUSE: |
| 8350 | case K_LEFTDRAG: |
| 8351 | case K_LEFTRELEASE: |
| 8352 | case K_RIGHTMOUSE: |
| 8353 | case K_RIGHTDRAG: |
| 8354 | case K_RIGHTRELEASE: |
| 8355 | case K_X1MOUSE: |
| 8356 | case K_X1DRAG: |
| 8357 | case K_X1RELEASE: |
| 8358 | case K_X2MOUSE: |
| 8359 | case K_X2DRAG: |
| 8360 | case K_X2RELEASE: |
| 8361 | mod_mask = MOD_MASK_CTRL; |
| 8362 | (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); |
| 8363 | break; |
| 8364 | #endif |
| 8365 | |
| 8366 | case K_IGNORE: |
| 8367 | break; |
| 8368 | |
| 8369 | /* |
| 8370 | * "gP" and "gp": same as "P" and "p" but leave cursor just after new text |
| 8371 | */ |
| 8372 | case 'p': |
| 8373 | case 'P': |
| 8374 | nv_put(cap); |
| 8375 | break; |
| 8376 | |
| 8377 | #ifdef FEAT_BYTEOFF |
| 8378 | /* "go": goto byte count from start of buffer */ |
| 8379 | case 'o': |
| 8380 | goto_byte(cap->count0); |
| 8381 | break; |
| 8382 | #endif |
| 8383 | |
| 8384 | /* "gQ": improved Ex mode */ |
| 8385 | case 'Q': |
Bram Moolenaar | 2d3f489 | 2006-01-20 23:02:51 +0000 | [diff] [blame] | 8386 | if (text_locked()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8387 | { |
| 8388 | clearopbeep(cap->oap); |
Bram Moolenaar | 2d3f489 | 2006-01-20 23:02:51 +0000 | [diff] [blame] | 8389 | text_locked_msg(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8390 | break; |
| 8391 | } |
Bram Moolenaar | 05a7bb3 | 2006-01-19 22:09:32 +0000 | [diff] [blame] | 8392 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8393 | if (!checkclearopq(oap)) |
| 8394 | do_exmode(TRUE); |
| 8395 | break; |
| 8396 | |
| 8397 | #ifdef FEAT_JUMPLIST |
| 8398 | case ',': |
| 8399 | nv_pcmark(cap); |
| 8400 | break; |
| 8401 | |
| 8402 | case ';': |
| 8403 | cap->count1 = -cap->count1; |
| 8404 | nv_pcmark(cap); |
| 8405 | break; |
| 8406 | #endif |
| 8407 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8408 | case 't': |
Bram Moolenaar | 89f940f | 2012-06-29 13:56:06 +0200 | [diff] [blame] | 8409 | if (!checkclearop(oap)) |
| 8410 | goto_tabpage((int)cap->count0); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8411 | break; |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 8412 | case 'T': |
Bram Moolenaar | 89f940f | 2012-06-29 13:56:06 +0200 | [diff] [blame] | 8413 | if (!checkclearop(oap)) |
| 8414 | goto_tabpage(-(int)cap->count1); |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 8415 | break; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8416 | |
Bram Moolenaar | 35a2e19 | 2006-03-13 22:07:11 +0000 | [diff] [blame] | 8417 | case '+': |
| 8418 | case '-': /* "g+" and "g-": undo or redo along the timeline */ |
| 8419 | if (!checkclearopq(oap)) |
Bram Moolenaar | d3667a2 | 2006-03-16 21:35:52 +0000 | [diff] [blame] | 8420 | undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1, |
Bram Moolenaar | 730cde9 | 2010-06-27 05:18:54 +0200 | [diff] [blame] | 8421 | FALSE, FALSE, FALSE); |
Bram Moolenaar | 35a2e19 | 2006-03-13 22:07:11 +0000 | [diff] [blame] | 8422 | break; |
| 8423 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8424 | default: |
| 8425 | clearopbeep(oap); |
| 8426 | break; |
| 8427 | } |
| 8428 | } |
| 8429 | |
| 8430 | /* |
| 8431 | * Handle "o" and "O" commands. |
| 8432 | */ |
| 8433 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8434 | n_opencmd(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8435 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 8436 | #ifdef FEAT_CONCEAL |
| 8437 | linenr_T oldline = curwin->w_cursor.lnum; |
| 8438 | #endif |
| 8439 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8440 | if (!checkclearopq(cap->oap)) |
| 8441 | { |
| 8442 | #ifdef FEAT_FOLDING |
| 8443 | if (cap->cmdchar == 'O') |
| 8444 | /* Open above the first line of a folded sequence of lines */ |
| 8445 | (void)hasFolding(curwin->w_cursor.lnum, |
| 8446 | &curwin->w_cursor.lnum, NULL); |
| 8447 | else |
| 8448 | /* Open below the last line of a folded sequence of lines */ |
| 8449 | (void)hasFolding(curwin->w_cursor.lnum, |
| 8450 | NULL, &curwin->w_cursor.lnum); |
| 8451 | #endif |
| 8452 | if (u_save((linenr_T)(curwin->w_cursor.lnum - |
| 8453 | (cap->cmdchar == 'O' ? 1 : 0)), |
| 8454 | (linenr_T)(curwin->w_cursor.lnum + |
| 8455 | (cap->cmdchar == 'o' ? 1 : 0)) |
| 8456 | ) == OK |
| 8457 | && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, |
| 8458 | #ifdef FEAT_COMMENTS |
| 8459 | has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : |
| 8460 | #endif |
| 8461 | 0, 0)) |
| 8462 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 8463 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 8464 | if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 8465 | update_single_line(curwin, oldline); |
| 8466 | #endif |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 8467 | /* When '#' is in 'cpoptions' ignore the count. */ |
| 8468 | if (vim_strchr(p_cpo, CPO_HASH) != NULL) |
| 8469 | cap->count1 = 1; |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 8470 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | d0d0fe0 | 2015-06-09 19:23:46 +0200 | [diff] [blame] | 8471 | if (curwin->w_p_cul) |
| 8472 | /* force redraw of cursorline */ |
| 8473 | curwin->w_valid &= ~VALID_CROW; |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 8474 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8475 | invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
| 8476 | } |
| 8477 | } |
| 8478 | } |
| 8479 | |
| 8480 | /* |
| 8481 | * "." command: redo last change. |
| 8482 | */ |
| 8483 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8484 | nv_dot(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8485 | { |
| 8486 | if (!checkclearopq(cap->oap)) |
| 8487 | { |
| 8488 | /* |
| 8489 | * If "restart_edit" is TRUE, the last but one command is repeated |
| 8490 | * instead of the last command (inserting text). This is used for |
| 8491 | * CTRL-O <.> in insert mode. |
| 8492 | */ |
| 8493 | if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) |
| 8494 | clearopbeep(cap->oap); |
| 8495 | } |
| 8496 | } |
| 8497 | |
| 8498 | /* |
| 8499 | * CTRL-R: undo undo |
| 8500 | */ |
| 8501 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8502 | nv_redo(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8503 | { |
| 8504 | if (!checkclearopq(cap->oap)) |
| 8505 | { |
| 8506 | u_redo((int)cap->count1); |
| 8507 | curwin->w_set_curswant = TRUE; |
| 8508 | } |
| 8509 | } |
| 8510 | |
| 8511 | /* |
| 8512 | * Handle "U" command. |
| 8513 | */ |
| 8514 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8515 | nv_Undo(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8516 | { |
| 8517 | /* In Visual mode and typing "gUU" triggers an operator */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 8518 | if (cap->oap->op_type == OP_UPPER || VIsual_active) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8519 | { |
| 8520 | /* translate "gUU" to "gUgU" */ |
| 8521 | cap->cmdchar = 'g'; |
| 8522 | cap->nchar = 'U'; |
| 8523 | nv_operator(cap); |
| 8524 | } |
| 8525 | else if (!checkclearopq(cap->oap)) |
| 8526 | { |
| 8527 | u_undoline(); |
| 8528 | curwin->w_set_curswant = TRUE; |
| 8529 | } |
| 8530 | } |
| 8531 | |
| 8532 | /* |
| 8533 | * '~' command: If tilde is not an operator and Visual is off: swap case of a |
| 8534 | * single character. |
| 8535 | */ |
| 8536 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8537 | nv_tilde(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8538 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 8539 | if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8540 | n_swapchar(cap); |
| 8541 | else |
| 8542 | nv_operator(cap); |
| 8543 | } |
| 8544 | |
| 8545 | /* |
| 8546 | * Handle an operator command. |
| 8547 | * The actual work is done by do_pending_operator(). |
| 8548 | */ |
| 8549 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8550 | nv_operator(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8551 | { |
| 8552 | int op_type; |
| 8553 | |
| 8554 | op_type = get_op_type(cap->cmdchar, cap->nchar); |
| 8555 | |
| 8556 | if (op_type == cap->oap->op_type) /* double operator works on lines */ |
| 8557 | nv_lineop(cap); |
| 8558 | else if (!checkclearop(cap->oap)) |
| 8559 | { |
| 8560 | cap->oap->start = curwin->w_cursor; |
| 8561 | cap->oap->op_type = op_type; |
Bram Moolenaar | 8af1fbf | 2008-01-05 12:35:21 +0000 | [diff] [blame] | 8562 | #ifdef FEAT_EVAL |
| 8563 | set_op_var(op_type); |
| 8564 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8565 | } |
| 8566 | } |
| 8567 | |
Bram Moolenaar | 8af1fbf | 2008-01-05 12:35:21 +0000 | [diff] [blame] | 8568 | #ifdef FEAT_EVAL |
| 8569 | /* |
| 8570 | * Set v:operator to the characters for "optype". |
| 8571 | */ |
| 8572 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8573 | set_op_var(int optype) |
Bram Moolenaar | 8af1fbf | 2008-01-05 12:35:21 +0000 | [diff] [blame] | 8574 | { |
| 8575 | char_u opchars[3]; |
| 8576 | |
| 8577 | if (optype == OP_NOP) |
| 8578 | set_vim_var_string(VV_OP, NULL, 0); |
| 8579 | else |
| 8580 | { |
| 8581 | opchars[0] = get_op_char(optype); |
| 8582 | opchars[1] = get_extra_op_char(optype); |
| 8583 | opchars[2] = NUL; |
| 8584 | set_vim_var_string(VV_OP, opchars, -1); |
| 8585 | } |
| 8586 | } |
| 8587 | #endif |
| 8588 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8589 | /* |
| 8590 | * Handle linewise operator "dd", "yy", etc. |
| 8591 | * |
| 8592 | * "_" is is a strange motion command that helps make operators more logical. |
| 8593 | * It is actually implemented, but not documented in the real Vi. This motion |
| 8594 | * command actually refers to "the current line". Commands like "dd" and "yy" |
| 8595 | * are really an alternate form of "d_" and "y_". It does accept a count, so |
| 8596 | * "d3_" works to delete 3 lines. |
| 8597 | */ |
| 8598 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8599 | nv_lineop(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8600 | { |
| 8601 | cap->oap->motion_type = MLINE; |
| 8602 | if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) |
| 8603 | clearopbeep(cap->oap); |
Bram Moolenaar | 83dadaf | 2012-12-12 17:33:32 +0100 | [diff] [blame] | 8604 | else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
| 8605 | && cap->oap->motion_force != 'v' |
| 8606 | && cap->oap->motion_force != Ctrl_V) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8607 | || cap->oap->op_type == OP_LSHIFT |
| 8608 | || cap->oap->op_type == OP_RSHIFT) |
| 8609 | beginline(BL_SOL | BL_FIX); |
| 8610 | else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ |
| 8611 | beginline(BL_WHITE | BL_FIX); |
| 8612 | } |
| 8613 | |
| 8614 | /* |
| 8615 | * <Home> command. |
| 8616 | */ |
| 8617 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8618 | nv_home(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8619 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 8620 | /* CTRL-HOME is like "gg" */ |
| 8621 | if (mod_mask & MOD_MASK_CTRL) |
| 8622 | nv_goto(cap); |
| 8623 | else |
| 8624 | { |
| 8625 | cap->count0 = 1; |
| 8626 | nv_pipe(cap); |
| 8627 | } |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 8628 | ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
| 8629 | one-character line). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8630 | } |
| 8631 | |
| 8632 | /* |
| 8633 | * "|" command. |
| 8634 | */ |
| 8635 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8636 | nv_pipe(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8637 | { |
| 8638 | cap->oap->motion_type = MCHAR; |
| 8639 | cap->oap->inclusive = FALSE; |
| 8640 | beginline(0); |
| 8641 | if (cap->count0 > 0) |
| 8642 | { |
| 8643 | coladvance((colnr_T)(cap->count0 - 1)); |
| 8644 | curwin->w_curswant = (colnr_T)(cap->count0 - 1); |
| 8645 | } |
| 8646 | else |
| 8647 | curwin->w_curswant = 0; |
| 8648 | /* keep curswant at the column where we wanted to go, not where |
Bram Moolenaar | f82a2d2 | 2010-12-17 18:53:01 +0100 | [diff] [blame] | 8649 | * we ended; differs if line is too short */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8650 | curwin->w_set_curswant = FALSE; |
| 8651 | } |
| 8652 | |
| 8653 | /* |
| 8654 | * Handle back-word command "b" and "B". |
| 8655 | * cap->arg is 1 for "B" |
| 8656 | */ |
| 8657 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8658 | nv_bck_word(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8659 | { |
| 8660 | cap->oap->motion_type = MCHAR; |
| 8661 | cap->oap->inclusive = FALSE; |
| 8662 | curwin->w_set_curswant = TRUE; |
| 8663 | if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) |
| 8664 | clearopbeep(cap->oap); |
| 8665 | #ifdef FEAT_FOLDING |
| 8666 | else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 8667 | foldOpenCursor(); |
| 8668 | #endif |
| 8669 | } |
| 8670 | |
| 8671 | /* |
| 8672 | * Handle word motion commands "e", "E", "w" and "W". |
| 8673 | * cap->arg is TRUE for "E" and "W". |
| 8674 | */ |
| 8675 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8676 | nv_wordcmd(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8677 | { |
| 8678 | int n; |
| 8679 | int word_end; |
| 8680 | int flag = FALSE; |
Bram Moolenaar | dfefb98 | 2008-04-01 10:06:39 +0000 | [diff] [blame] | 8681 | pos_T startpos = curwin->w_cursor; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8682 | |
| 8683 | /* |
| 8684 | * Set inclusive for the "E" and "e" command. |
| 8685 | */ |
| 8686 | if (cap->cmdchar == 'e' || cap->cmdchar == 'E') |
| 8687 | word_end = TRUE; |
| 8688 | else |
| 8689 | word_end = FALSE; |
| 8690 | cap->oap->inclusive = word_end; |
| 8691 | |
| 8692 | /* |
| 8693 | * "cw" and "cW" are a special case. |
| 8694 | */ |
| 8695 | if (!word_end && cap->oap->op_type == OP_CHANGE) |
| 8696 | { |
| 8697 | n = gchar_cursor(); |
| 8698 | if (n != NUL) /* not an empty line */ |
| 8699 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 8700 | if (VIM_ISWHITE(n)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8701 | { |
| 8702 | /* |
| 8703 | * Reproduce a funny Vi behaviour: "cw" on a blank only |
| 8704 | * changes one character, not all blanks until the start of |
| 8705 | * the next word. Only do this when the 'w' flag is included |
| 8706 | * in 'cpoptions'. |
| 8707 | */ |
| 8708 | if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) |
| 8709 | { |
| 8710 | cap->oap->inclusive = TRUE; |
| 8711 | cap->oap->motion_type = MCHAR; |
| 8712 | return; |
| 8713 | } |
| 8714 | } |
| 8715 | else |
| 8716 | { |
| 8717 | /* |
| 8718 | * This is a little strange. To match what the real Vi does, |
| 8719 | * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided |
| 8720 | * that we are not on a space or a TAB. This seems impolite |
| 8721 | * at first, but it's really more what we mean when we say |
| 8722 | * 'cw'. |
| 8723 | * Another strangeness: When standing on the end of a word |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 8724 | * "ce" will change until the end of the next word, but "cw" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8725 | * will change only one character! This is done by setting |
| 8726 | * flag. |
| 8727 | */ |
| 8728 | cap->oap->inclusive = TRUE; |
| 8729 | word_end = TRUE; |
| 8730 | flag = TRUE; |
| 8731 | } |
| 8732 | } |
| 8733 | } |
| 8734 | |
| 8735 | cap->oap->motion_type = MCHAR; |
| 8736 | curwin->w_set_curswant = TRUE; |
| 8737 | if (word_end) |
| 8738 | n = end_word(cap->count1, cap->arg, flag, FALSE); |
| 8739 | else |
| 8740 | n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); |
| 8741 | |
Bram Moolenaar | dfefb98 | 2008-04-01 10:06:39 +0000 | [diff] [blame] | 8742 | /* Don't leave the cursor on the NUL past the end of line. Unless we |
| 8743 | * didn't move it forward. */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 8744 | if (LT_POS(startpos, curwin->w_cursor)) |
Bram Moolenaar | 1f14d57 | 2008-01-12 16:12:10 +0000 | [diff] [blame] | 8745 | adjust_cursor(cap->oap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8746 | |
| 8747 | if (n == FAIL && cap->oap->op_type == OP_NOP) |
| 8748 | clearopbeep(cap->oap); |
| 8749 | else |
| 8750 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8751 | adjust_for_sel(cap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8752 | #ifdef FEAT_FOLDING |
| 8753 | if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 8754 | foldOpenCursor(); |
| 8755 | #endif |
| 8756 | } |
| 8757 | } |
| 8758 | |
| 8759 | /* |
Bram Moolenaar | 1f14d57 | 2008-01-12 16:12:10 +0000 | [diff] [blame] | 8760 | * Used after a movement command: If the cursor ends up on the NUL after the |
| 8761 | * end of the line, may move it back to the last character and make the motion |
| 8762 | * inclusive. |
| 8763 | */ |
| 8764 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8765 | adjust_cursor(oparg_T *oap) |
Bram Moolenaar | 1f14d57 | 2008-01-12 16:12:10 +0000 | [diff] [blame] | 8766 | { |
| 8767 | /* The cursor cannot remain on the NUL when: |
| 8768 | * - the column is > 0 |
| 8769 | * - not in Visual mode or 'selection' is "o" |
| 8770 | * - 'virtualedit' is not "all" and not "onemore". |
| 8771 | */ |
| 8772 | if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL |
Bram Moolenaar | 1f14d57 | 2008-01-12 16:12:10 +0000 | [diff] [blame] | 8773 | && (!VIsual_active || *p_sel == 'o') |
Bram Moolenaar | 1f14d57 | 2008-01-12 16:12:10 +0000 | [diff] [blame] | 8774 | #ifdef FEAT_VIRTUALEDIT |
| 8775 | && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 |
| 8776 | #endif |
| 8777 | ) |
| 8778 | { |
| 8779 | --curwin->w_cursor.col; |
| 8780 | #ifdef FEAT_MBYTE |
| 8781 | /* prevent cursor from moving on the trail byte */ |
| 8782 | if (has_mbyte) |
| 8783 | mb_adjust_cursor(); |
| 8784 | #endif |
| 8785 | oap->inclusive = TRUE; |
| 8786 | } |
| 8787 | } |
| 8788 | |
| 8789 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8790 | * "0" and "^" commands. |
| 8791 | * cap->arg is the argument for beginline(). |
| 8792 | */ |
| 8793 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8794 | nv_beginline(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8795 | { |
| 8796 | cap->oap->motion_type = MCHAR; |
| 8797 | cap->oap->inclusive = FALSE; |
| 8798 | beginline(cap->arg); |
| 8799 | #ifdef FEAT_FOLDING |
| 8800 | if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 8801 | foldOpenCursor(); |
| 8802 | #endif |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 8803 | ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
| 8804 | one-character line). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8805 | } |
| 8806 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8807 | /* |
| 8808 | * In exclusive Visual mode, may include the last character. |
| 8809 | */ |
| 8810 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8811 | adjust_for_sel(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8812 | { |
| 8813 | if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 8814 | && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8815 | { |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 8816 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8817 | if (has_mbyte) |
| 8818 | inc_cursor(); |
| 8819 | else |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 8820 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8821 | ++curwin->w_cursor.col; |
| 8822 | cap->oap->inclusive = FALSE; |
| 8823 | } |
| 8824 | } |
| 8825 | |
| 8826 | /* |
| 8827 | * Exclude last character at end of Visual area for 'selection' == "exclusive". |
| 8828 | * Should check VIsual_mode before calling this. |
| 8829 | * Returns TRUE when backed up to the previous line. |
| 8830 | */ |
| 8831 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8832 | unadjust_for_sel(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8833 | { |
| 8834 | pos_T *pp; |
| 8835 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 8836 | if (*p_sel == 'e' && !EQUAL_POS(VIsual, curwin->w_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8837 | { |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 8838 | if (LT_POS(VIsual, curwin->w_cursor)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8839 | pp = &curwin->w_cursor; |
| 8840 | else |
| 8841 | pp = &VIsual; |
| 8842 | #ifdef FEAT_VIRTUALEDIT |
| 8843 | if (pp->coladd > 0) |
| 8844 | --pp->coladd; |
| 8845 | else |
| 8846 | #endif |
| 8847 | if (pp->col > 0) |
| 8848 | { |
| 8849 | --pp->col; |
| 8850 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 03a807a | 2011-07-07 15:08:58 +0200 | [diff] [blame] | 8851 | mb_adjustpos(curbuf, pp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8852 | #endif |
| 8853 | } |
| 8854 | else if (pp->lnum > 1) |
| 8855 | { |
| 8856 | --pp->lnum; |
| 8857 | pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); |
| 8858 | return TRUE; |
| 8859 | } |
| 8860 | } |
| 8861 | return FALSE; |
| 8862 | } |
| 8863 | |
| 8864 | /* |
| 8865 | * SELECT key in Normal or Visual mode: end of Select mode mapping. |
| 8866 | */ |
| 8867 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8868 | nv_select(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8869 | { |
| 8870 | if (VIsual_active) |
| 8871 | VIsual_select = TRUE; |
| 8872 | else if (VIsual_reselect) |
| 8873 | { |
| 8874 | cap->nchar = 'v'; /* fake "gv" command */ |
| 8875 | cap->arg = TRUE; |
| 8876 | nv_g_cmd(cap); |
| 8877 | } |
| 8878 | } |
| 8879 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8880 | |
| 8881 | /* |
| 8882 | * "G", "gg", CTRL-END, CTRL-HOME. |
| 8883 | * cap->arg is TRUE for "G". |
| 8884 | */ |
| 8885 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8886 | nv_goto(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8887 | { |
| 8888 | linenr_T lnum; |
| 8889 | |
| 8890 | if (cap->arg) |
| 8891 | lnum = curbuf->b_ml.ml_line_count; |
| 8892 | else |
| 8893 | lnum = 1L; |
| 8894 | cap->oap->motion_type = MLINE; |
| 8895 | setpcmark(); |
| 8896 | |
| 8897 | /* When a count is given, use it instead of the default lnum */ |
| 8898 | if (cap->count0 != 0) |
| 8899 | lnum = cap->count0; |
| 8900 | if (lnum < 1L) |
| 8901 | lnum = 1L; |
| 8902 | else if (lnum > curbuf->b_ml.ml_line_count) |
| 8903 | lnum = curbuf->b_ml.ml_line_count; |
| 8904 | curwin->w_cursor.lnum = lnum; |
| 8905 | beginline(BL_SOL | BL_FIX); |
| 8906 | #ifdef FEAT_FOLDING |
| 8907 | if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 8908 | foldOpenCursor(); |
| 8909 | #endif |
| 8910 | } |
| 8911 | |
| 8912 | /* |
| 8913 | * CTRL-\ in Normal mode. |
| 8914 | */ |
| 8915 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8916 | nv_normal(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8917 | { |
| 8918 | if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) |
| 8919 | { |
| 8920 | clearop(cap->oap); |
Bram Moolenaar | 28c258f | 2006-01-25 22:02:51 +0000 | [diff] [blame] | 8921 | if (restart_edit != 0 && mode_displayed) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8922 | clear_cmdline = TRUE; /* unshow mode later */ |
| 8923 | restart_edit = 0; |
| 8924 | #ifdef FEAT_CMDWIN |
| 8925 | if (cmdwin_type != 0) |
| 8926 | cmdwin_result = Ctrl_C; |
| 8927 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8928 | if (VIsual_active) |
| 8929 | { |
| 8930 | end_visual_mode(); /* stop Visual */ |
| 8931 | redraw_curbuf_later(INVERTED); |
| 8932 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8933 | /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ |
| 8934 | if (cap->nchar == Ctrl_G && p_im) |
| 8935 | restart_edit = 'a'; |
| 8936 | } |
| 8937 | else |
| 8938 | clearopbeep(cap->oap); |
| 8939 | } |
| 8940 | |
| 8941 | /* |
| 8942 | * ESC in Normal mode: beep, but don't flush buffers. |
| 8943 | * Don't even beep if we are canceling a command. |
| 8944 | */ |
| 8945 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8946 | nv_esc(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8947 | { |
| 8948 | int no_reason; |
| 8949 | |
| 8950 | no_reason = (cap->oap->op_type == OP_NOP |
| 8951 | && cap->opcount == 0 |
| 8952 | && cap->count0 == 0 |
| 8953 | && cap->oap->regname == 0 |
| 8954 | && !p_im); |
| 8955 | |
| 8956 | if (cap->arg) /* TRUE for CTRL-C */ |
| 8957 | { |
| 8958 | if (restart_edit == 0 |
| 8959 | #ifdef FEAT_CMDWIN |
| 8960 | && cmdwin_type == 0 |
| 8961 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8962 | && !VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8963 | && no_reason) |
Bram Moolenaar | 28a8193 | 2017-06-04 15:33:48 +0200 | [diff] [blame] | 8964 | MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8965 | |
| 8966 | /* Don't reset "restart_edit" when 'insertmode' is set, it won't be |
| 8967 | * set again below when halfway a mapping. */ |
| 8968 | if (!p_im) |
| 8969 | restart_edit = 0; |
| 8970 | #ifdef FEAT_CMDWIN |
| 8971 | if (cmdwin_type != 0) |
| 8972 | { |
| 8973 | cmdwin_result = K_IGNORE; |
| 8974 | got_int = FALSE; /* don't stop executing autocommands et al. */ |
| 8975 | return; |
| 8976 | } |
| 8977 | #endif |
| 8978 | } |
| 8979 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8980 | if (VIsual_active) |
| 8981 | { |
| 8982 | end_visual_mode(); /* stop Visual */ |
| 8983 | check_cursor_col(); /* make sure cursor is not beyond EOL */ |
| 8984 | curwin->w_set_curswant = TRUE; |
| 8985 | redraw_curbuf_later(INVERTED); |
| 8986 | } |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 8987 | else if (no_reason) |
Bram Moolenaar | 165bc69 | 2015-07-21 17:53:25 +0200 | [diff] [blame] | 8988 | vim_beep(BO_ESC); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8989 | clearop(cap->oap); |
| 8990 | |
| 8991 | /* A CTRL-C is often used at the start of a menu. When 'insertmode' is |
| 8992 | * set return to Insert mode afterwards. */ |
Bram Moolenaar | e2c3810 | 2016-01-31 14:55:40 +0100 | [diff] [blame] | 8993 | if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8994 | restart_edit = 'a'; |
| 8995 | } |
| 8996 | |
| 8997 | /* |
| 8998 | * Handle "A", "a", "I", "i" and <Insert> commands. |
Bram Moolenaar | ec2da36 | 2017-01-21 20:04:22 +0100 | [diff] [blame] | 8999 | * Also handle K_PS, start bracketed paste. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9000 | */ |
| 9001 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9002 | nv_edit(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9003 | { |
| 9004 | /* <Insert> is equal to "i" */ |
| 9005 | if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) |
| 9006 | cap->cmdchar = 'i'; |
| 9007 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9008 | /* in Visual mode "A" and "I" are an operator */ |
| 9009 | if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) |
Bram Moolenaar | eef9add | 2017-09-16 15:38:04 +0200 | [diff] [blame] | 9010 | { |
| 9011 | #ifdef FEAT_TERMINAL |
| 9012 | if (term_in_normal_mode()) |
| 9013 | { |
| 9014 | end_visual_mode(); |
| 9015 | clearop(cap->oap); |
| 9016 | term_enter_job_mode(); |
| 9017 | return; |
| 9018 | } |
| 9019 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9020 | v_visop(cap); |
Bram Moolenaar | eef9add | 2017-09-16 15:38:04 +0200 | [diff] [blame] | 9021 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9022 | |
| 9023 | /* in Visual mode and after an operator "a" and "i" are for text objects */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9024 | else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
| 9025 | && (cap->oap->op_type != OP_NOP || VIsual_active)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9026 | { |
| 9027 | #ifdef FEAT_TEXTOBJ |
| 9028 | nv_object(cap); |
| 9029 | #else |
| 9030 | clearopbeep(cap->oap); |
| 9031 | #endif |
| 9032 | } |
Bram Moolenaar | 662d938 | 2017-07-31 22:56:24 +0200 | [diff] [blame] | 9033 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d81974 | 2017-08-06 14:57:49 +0200 | [diff] [blame] | 9034 | else if (term_in_normal_mode()) |
Bram Moolenaar | 662d938 | 2017-07-31 22:56:24 +0200 | [diff] [blame] | 9035 | { |
| 9036 | clearop(cap->oap); |
Bram Moolenaar | 6d81974 | 2017-08-06 14:57:49 +0200 | [diff] [blame] | 9037 | term_enter_job_mode(); |
Bram Moolenaar | 662d938 | 2017-07-31 22:56:24 +0200 | [diff] [blame] | 9038 | return; |
| 9039 | } |
| 9040 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9041 | else if (!curbuf->b_p_ma && !p_im) |
| 9042 | { |
| 9043 | /* Only give this error when 'insertmode' is off. */ |
| 9044 | EMSG(_(e_modifiable)); |
| 9045 | clearop(cap->oap); |
Bram Moolenaar | ec2da36 | 2017-01-21 20:04:22 +0100 | [diff] [blame] | 9046 | if (cap->cmdchar == K_PS) |
| 9047 | /* drop the pasted text */ |
| 9048 | bracketed_paste(PASTE_INSERT, TRUE, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9049 | } |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 9050 | else if (cap->cmdchar == K_PS && VIsual_active) |
| 9051 | { |
| 9052 | pos_T old_pos = curwin->w_cursor; |
| 9053 | pos_T old_visual = VIsual; |
| 9054 | |
| 9055 | /* In Visual mode the selected text is deleted. */ |
| 9056 | if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum) |
| 9057 | { |
| 9058 | shift_delete_registers(); |
| 9059 | cap->oap->regname = '1'; |
| 9060 | } |
| 9061 | else |
| 9062 | cap->oap->regname = '-'; |
| 9063 | cap->cmdchar = 'd'; |
| 9064 | cap->nchar = NUL; |
| 9065 | nv_operator(cap); |
| 9066 | do_pending_operator(cap, 0, FALSE); |
| 9067 | cap->cmdchar = K_PS; |
| 9068 | |
| 9069 | /* When the last char in the line was deleted then append. Detect this |
| 9070 | * by checking if the cursor moved to before the Visual area. */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 9071 | if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos) |
| 9072 | && LT_POS(curwin->w_cursor, old_visual)) |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 9073 | inc_cursor(); |
| 9074 | |
| 9075 | /* Insert to replace the deleted text with the pasted text. */ |
| 9076 | invoke_edit(cap, FALSE, cap->cmdchar, FALSE); |
| 9077 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9078 | else if (!checkclearopq(cap->oap)) |
| 9079 | { |
| 9080 | switch (cap->cmdchar) |
| 9081 | { |
| 9082 | case 'A': /* "A"ppend after the line */ |
| 9083 | curwin->w_set_curswant = TRUE; |
| 9084 | #ifdef FEAT_VIRTUALEDIT |
| 9085 | if (ve_flags == VE_ALL) |
| 9086 | { |
| 9087 | int save_State = State; |
| 9088 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 9089 | /* Pretend Insert mode here to allow the cursor on the |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9090 | * character past the end of the line */ |
| 9091 | State = INSERT; |
| 9092 | coladvance((colnr_T)MAXCOL); |
| 9093 | State = save_State; |
| 9094 | } |
| 9095 | else |
| 9096 | #endif |
| 9097 | curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); |
| 9098 | break; |
| 9099 | |
| 9100 | case 'I': /* "I"nsert before the first non-blank */ |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 9101 | if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
| 9102 | beginline(BL_WHITE); |
| 9103 | else |
| 9104 | beginline(BL_WHITE|BL_FIX); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9105 | break; |
| 9106 | |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 9107 | case K_PS: |
| 9108 | /* Bracketed paste works like "a"ppend, unless the cursor is in |
| 9109 | * the first column, then it inserts. */ |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 9110 | if (curwin->w_cursor.col == 0) |
| 9111 | break; |
| 9112 | /*FALLTHROUGH*/ |
| 9113 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9114 | case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
| 9115 | #ifdef FEAT_VIRTUALEDIT |
| 9116 | /* increment coladd when in virtual space, increment the |
| 9117 | * column otherwise, also to append after an unprintable char */ |
| 9118 | if (virtual_active() |
| 9119 | && (curwin->w_cursor.coladd > 0 |
| 9120 | || *ml_get_cursor() == NUL |
| 9121 | || *ml_get_cursor() == TAB)) |
| 9122 | curwin->w_cursor.coladd++; |
| 9123 | else |
| 9124 | #endif |
| 9125 | if (*ml_get_cursor() != NUL) |
| 9126 | inc_cursor(); |
| 9127 | break; |
| 9128 | } |
| 9129 | |
| 9130 | #ifdef FEAT_VIRTUALEDIT |
| 9131 | if (curwin->w_cursor.coladd && cap->cmdchar != 'A') |
| 9132 | { |
| 9133 | int save_State = State; |
| 9134 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 9135 | /* Pretend Insert mode here to allow the cursor on the |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9136 | * character past the end of the line */ |
| 9137 | State = INSERT; |
| 9138 | coladvance(getviscol()); |
| 9139 | State = save_State; |
| 9140 | } |
| 9141 | #endif |
| 9142 | |
| 9143 | invoke_edit(cap, FALSE, cap->cmdchar, FALSE); |
| 9144 | } |
Bram Moolenaar | ec2da36 | 2017-01-21 20:04:22 +0100 | [diff] [blame] | 9145 | else if (cap->cmdchar == K_PS) |
| 9146 | /* drop the pasted text */ |
| 9147 | bracketed_paste(PASTE_INSERT, TRUE, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9148 | } |
| 9149 | |
| 9150 | /* |
| 9151 | * Invoke edit() and take care of "restart_edit" and the return value. |
| 9152 | */ |
| 9153 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9154 | invoke_edit( |
| 9155 | cmdarg_T *cap, |
| 9156 | int repl, /* "r" or "gr" command */ |
| 9157 | int cmd, |
| 9158 | int startln) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9159 | { |
| 9160 | int restart_edit_save = 0; |
| 9161 | |
| 9162 | /* Complicated: When the user types "a<C-O>a" we don't want to do Insert |
| 9163 | * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow |
| 9164 | * it. */ |
| 9165 | if (repl || !stuff_empty()) |
| 9166 | restart_edit_save = restart_edit; |
| 9167 | else |
| 9168 | restart_edit_save = 0; |
| 9169 | |
| 9170 | /* Always reset "restart_edit", this is not a restarted edit. */ |
| 9171 | restart_edit = 0; |
| 9172 | |
| 9173 | if (edit(cmd, startln, cap->count1)) |
| 9174 | cap->retval |= CA_COMMAND_BUSY; |
| 9175 | |
| 9176 | if (restart_edit == 0) |
| 9177 | restart_edit = restart_edit_save; |
| 9178 | } |
| 9179 | |
| 9180 | #ifdef FEAT_TEXTOBJ |
| 9181 | /* |
| 9182 | * "a" or "i" while an operator is pending or in Visual mode: object motion. |
| 9183 | */ |
| 9184 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9185 | nv_object( |
| 9186 | cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9187 | { |
| 9188 | int flag; |
| 9189 | int include; |
| 9190 | char_u *mps_save; |
| 9191 | |
| 9192 | if (cap->cmdchar == 'i') |
| 9193 | include = FALSE; /* "ix" = inner object: exclude white space */ |
| 9194 | else |
| 9195 | include = TRUE; /* "ax" = an object: include white space */ |
| 9196 | |
| 9197 | /* Make sure (), [], {} and <> are in 'matchpairs' */ |
| 9198 | mps_save = curbuf->b_p_mps; |
| 9199 | curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; |
| 9200 | |
| 9201 | switch (cap->nchar) |
| 9202 | { |
| 9203 | case 'w': /* "aw" = a word */ |
| 9204 | flag = current_word(cap->oap, cap->count1, include, FALSE); |
| 9205 | break; |
| 9206 | case 'W': /* "aW" = a WORD */ |
| 9207 | flag = current_word(cap->oap, cap->count1, include, TRUE); |
| 9208 | break; |
| 9209 | case 'b': /* "ab" = a braces block */ |
| 9210 | case '(': |
| 9211 | case ')': |
| 9212 | flag = current_block(cap->oap, cap->count1, include, '(', ')'); |
| 9213 | break; |
| 9214 | case 'B': /* "aB" = a Brackets block */ |
| 9215 | case '{': |
| 9216 | case '}': |
| 9217 | flag = current_block(cap->oap, cap->count1, include, '{', '}'); |
| 9218 | break; |
| 9219 | case '[': /* "a[" = a [] block */ |
| 9220 | case ']': |
| 9221 | flag = current_block(cap->oap, cap->count1, include, '[', ']'); |
| 9222 | break; |
| 9223 | case '<': /* "a<" = a <> block */ |
| 9224 | case '>': |
| 9225 | flag = current_block(cap->oap, cap->count1, include, '<', '>'); |
| 9226 | break; |
Bram Moolenaar | f8c07b2 | 2005-07-19 22:10:03 +0000 | [diff] [blame] | 9227 | case 't': /* "at" = a tag block (xml and html) */ |
Bram Moolenaar | b6c2735 | 2015-03-05 19:57:49 +0100 | [diff] [blame] | 9228 | /* Do not adjust oap->end in do_pending_operator() |
| 9229 | * otherwise there are different results for 'dit' |
| 9230 | * (note leading whitespace in last line): |
| 9231 | * 1) <b> 2) <b> |
| 9232 | * foobar foobar |
| 9233 | * </b> </b> |
| 9234 | */ |
| 9235 | cap->retval |= CA_NO_ADJ_OP_END; |
Bram Moolenaar | f8c07b2 | 2005-07-19 22:10:03 +0000 | [diff] [blame] | 9236 | flag = current_tagblock(cap->oap, cap->count1, include); |
| 9237 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9238 | case 'p': /* "ap" = a paragraph */ |
| 9239 | flag = current_par(cap->oap, cap->count1, include, 'p'); |
| 9240 | break; |
| 9241 | case 's': /* "as" = a sentence */ |
| 9242 | flag = current_sent(cap->oap, cap->count1, include); |
| 9243 | break; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 9244 | case '"': /* "a"" = a double quoted string */ |
| 9245 | case '\'': /* "a'" = a single quoted string */ |
| 9246 | case '`': /* "a`" = a backtick quoted string */ |
| 9247 | flag = current_quote(cap->oap, cap->count1, include, |
| 9248 | cap->nchar); |
| 9249 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9250 | #if 0 /* TODO */ |
| 9251 | case 'S': /* "aS" = a section */ |
| 9252 | case 'f': /* "af" = a filename */ |
| 9253 | case 'u': /* "au" = a URL */ |
| 9254 | #endif |
| 9255 | default: |
| 9256 | flag = FAIL; |
| 9257 | break; |
| 9258 | } |
| 9259 | |
| 9260 | curbuf->b_p_mps = mps_save; |
| 9261 | if (flag == FAIL) |
| 9262 | clearopbeep(cap->oap); |
| 9263 | adjust_cursor_col(); |
| 9264 | curwin->w_set_curswant = TRUE; |
| 9265 | } |
| 9266 | #endif |
| 9267 | |
| 9268 | /* |
| 9269 | * "q" command: Start/stop recording. |
| 9270 | * "q:", "q/", "q?": edit command-line in command-line window. |
| 9271 | */ |
| 9272 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9273 | nv_record(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9274 | { |
| 9275 | if (cap->oap->op_type == OP_FORMAT) |
| 9276 | { |
| 9277 | /* "gqq" is the same as "gqgq": format line */ |
| 9278 | cap->cmdchar = 'g'; |
| 9279 | cap->nchar = 'q'; |
| 9280 | nv_operator(cap); |
| 9281 | } |
| 9282 | else if (!checkclearop(cap->oap)) |
| 9283 | { |
| 9284 | #ifdef FEAT_CMDWIN |
| 9285 | if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') |
| 9286 | { |
| 9287 | stuffcharReadbuff(cap->nchar); |
| 9288 | stuffcharReadbuff(K_CMDWIN); |
| 9289 | } |
| 9290 | else |
| 9291 | #endif |
| 9292 | /* (stop) recording into a named register, unless executing a |
| 9293 | * register */ |
| 9294 | if (!Exec_reg && do_record(cap->nchar) == FAIL) |
| 9295 | clearopbeep(cap->oap); |
| 9296 | } |
| 9297 | } |
| 9298 | |
| 9299 | /* |
| 9300 | * Handle the "@r" command. |
| 9301 | */ |
| 9302 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9303 | nv_at(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9304 | { |
| 9305 | if (checkclearop(cap->oap)) |
| 9306 | return; |
| 9307 | #ifdef FEAT_EVAL |
| 9308 | if (cap->nchar == '=') |
| 9309 | { |
| 9310 | if (get_expr_register() == NUL) |
| 9311 | return; |
| 9312 | } |
| 9313 | #endif |
| 9314 | while (cap->count1-- && !got_int) |
| 9315 | { |
Bram Moolenaar | d333d1e | 2006-11-07 17:43:47 +0000 | [diff] [blame] | 9316 | if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9317 | { |
| 9318 | clearopbeep(cap->oap); |
| 9319 | break; |
| 9320 | } |
| 9321 | line_breakcheck(); |
| 9322 | } |
| 9323 | } |
| 9324 | |
| 9325 | /* |
| 9326 | * Handle the CTRL-U and CTRL-D commands. |
| 9327 | */ |
| 9328 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9329 | nv_halfpage(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9330 | { |
| 9331 | if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) |
| 9332 | || (cap->cmdchar == Ctrl_D |
| 9333 | && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) |
| 9334 | clearopbeep(cap->oap); |
| 9335 | else if (!checkclearop(cap->oap)) |
| 9336 | halfpage(cap->cmdchar == Ctrl_D, cap->count0); |
| 9337 | } |
| 9338 | |
| 9339 | /* |
| 9340 | * Handle "J" or "gJ" command. |
| 9341 | */ |
| 9342 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9343 | nv_join(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9344 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9345 | if (VIsual_active) /* join the visual lines */ |
| 9346 | nv_operator(cap); |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9347 | else if (!checkclearop(cap->oap)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9348 | { |
| 9349 | if (cap->count0 <= 1) |
| 9350 | cap->count0 = 2; /* default for join is two lines! */ |
| 9351 | if (curwin->w_cursor.lnum + cap->count0 - 1 > |
| 9352 | curbuf->b_ml.ml_line_count) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9353 | { |
Bram Moolenaar | 41e0f2f | 2016-03-08 14:44:42 +0100 | [diff] [blame] | 9354 | /* can't join when on the last line */ |
| 9355 | if (cap->count0 <= 2) |
| 9356 | { |
| 9357 | clearopbeep(cap->oap); |
| 9358 | return; |
| 9359 | } |
| 9360 | cap->count0 = curbuf->b_ml.ml_line_count |
| 9361 | - curwin->w_cursor.lnum + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9362 | } |
Bram Moolenaar | 41e0f2f | 2016-03-08 14:44:42 +0100 | [diff] [blame] | 9363 | |
| 9364 | prep_redo(cap->oap->regname, cap->count0, |
| 9365 | NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
| 9366 | (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9367 | } |
| 9368 | } |
| 9369 | |
| 9370 | /* |
| 9371 | * "P", "gP", "p" and "gp" commands. |
| 9372 | */ |
| 9373 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9374 | nv_put(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9375 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9376 | int regname = 0; |
| 9377 | void *reg1 = NULL, *reg2 = NULL; |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 9378 | int empty = FALSE; |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9379 | int was_visual = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9380 | int dir; |
| 9381 | int flags = 0; |
| 9382 | |
| 9383 | if (cap->oap->op_type != OP_NOP) |
| 9384 | { |
| 9385 | #ifdef FEAT_DIFF |
| 9386 | /* "dp" is ":diffput" */ |
| 9387 | if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') |
| 9388 | { |
| 9389 | clearop(cap->oap); |
Bram Moolenaar | 6a64365 | 2014-10-31 13:54:25 +0100 | [diff] [blame] | 9390 | nv_diffgetput(TRUE, cap->opcount); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9391 | } |
| 9392 | else |
| 9393 | #endif |
| 9394 | clearopbeep(cap->oap); |
| 9395 | } |
| 9396 | else |
| 9397 | { |
| 9398 | dir = (cap->cmdchar == 'P' |
| 9399 | || (cap->cmdchar == 'g' && cap->nchar == 'P')) |
| 9400 | ? BACKWARD : FORWARD; |
| 9401 | prep_redo_cmd(cap); |
| 9402 | if (cap->cmdchar == 'g') |
| 9403 | flags |= PUT_CURSEND; |
| 9404 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9405 | if (VIsual_active) |
| 9406 | { |
| 9407 | /* Putting in Visual mode: The put text replaces the selected |
| 9408 | * text. First delete the selected text, then put the new text. |
| 9409 | * Need to save and restore the registers that the delete |
| 9410 | * overwrites if the old contents is being put. |
| 9411 | */ |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9412 | was_visual = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9413 | regname = cap->oap->regname; |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9414 | #ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9415 | adjust_clip_reg(®name); |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9416 | #endif |
Bram Moolenaar | 7d311c5 | 2014-02-22 23:49:35 +0100 | [diff] [blame] | 9417 | if (regname == 0 || regname == '"' |
Bram Moolenaar | ba6e858 | 2012-12-12 18:20:32 +0100 | [diff] [blame] | 9418 | || VIM_ISDIGIT(regname) || regname == '-' |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9419 | #ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9420 | || (clip_unnamed && (regname == '*' || regname == '+')) |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 9421 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9422 | |
| 9423 | ) |
| 9424 | { |
Bram Moolenaar | ba6e858 | 2012-12-12 18:20:32 +0100 | [diff] [blame] | 9425 | /* The delete is going to overwrite the register we want to |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9426 | * put, save it first. */ |
| 9427 | reg1 = get_register(regname, TRUE); |
| 9428 | } |
| 9429 | |
| 9430 | /* Now delete the selected text. */ |
| 9431 | cap->cmdchar = 'd'; |
| 9432 | cap->nchar = NUL; |
| 9433 | cap->oap->regname = NUL; |
| 9434 | nv_operator(cap); |
| 9435 | do_pending_operator(cap, 0, FALSE); |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 9436 | empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9437 | |
| 9438 | /* delete PUT_LINE_BACKWARD; */ |
| 9439 | cap->oap->regname = regname; |
| 9440 | |
| 9441 | if (reg1 != NULL) |
| 9442 | { |
| 9443 | /* Delete probably changed the register we want to put, save |
| 9444 | * it first. Then put back what was there before the delete. */ |
| 9445 | reg2 = get_register(regname, FALSE); |
| 9446 | put_register(regname, reg1); |
| 9447 | } |
| 9448 | |
| 9449 | /* When deleted a linewise Visual area, put the register as |
| 9450 | * lines to avoid it joined with the next line. When deletion was |
| 9451 | * characterwise, split a line when putting lines. */ |
| 9452 | if (VIsual_mode == 'V') |
| 9453 | flags |= PUT_LINE; |
| 9454 | else if (VIsual_mode == 'v') |
| 9455 | flags |= PUT_LINE_SPLIT; |
| 9456 | if (VIsual_mode == Ctrl_V && dir == FORWARD) |
| 9457 | flags |= PUT_LINE_FORWARD; |
| 9458 | dir = BACKWARD; |
| 9459 | if ((VIsual_mode != 'V' |
| 9460 | && curwin->w_cursor.col < curbuf->b_op_start.col) |
| 9461 | || (VIsual_mode == 'V' |
| 9462 | && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) |
| 9463 | /* cursor is at the end of the line or end of file, put |
| 9464 | * forward. */ |
| 9465 | dir = FORWARD; |
Bram Moolenaar | ec11aef | 2013-09-22 15:23:44 +0200 | [diff] [blame] | 9466 | /* May have been reset in do_put(). */ |
| 9467 | VIsual_active = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9468 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9469 | do_put(cap->oap->regname, dir, cap->count1, flags); |
| 9470 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9471 | /* If a register was saved, put it back now. */ |
| 9472 | if (reg2 != NULL) |
| 9473 | put_register(regname, reg2); |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9474 | |
| 9475 | /* What to reselect with "gv"? Selecting the just put text seems to |
| 9476 | * be the most useful, since the original text was removed. */ |
| 9477 | if (was_visual) |
| 9478 | { |
Bram Moolenaar | a226a6d | 2006-02-26 23:59:20 +0000 | [diff] [blame] | 9479 | curbuf->b_visual.vi_start = curbuf->b_op_start; |
| 9480 | curbuf->b_visual.vi_end = curbuf->b_op_end; |
Bram Moolenaar | d29c6fe | 2015-11-19 20:11:54 +0100 | [diff] [blame] | 9481 | /* need to adjust cursor position */ |
| 9482 | if (*p_sel == 'e') |
| 9483 | inc(&curbuf->b_visual.vi_end); |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9484 | } |
| 9485 | |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 9486 | /* When all lines were selected and deleted do_put() leaves an empty |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9487 | * line that needs to be deleted now. */ |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 9488 | if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
Bram Moolenaar | 86ca6e3 | 2006-03-29 21:06:37 +0000 | [diff] [blame] | 9489 | { |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 9490 | ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
Bram Moolenaar | 86ca6e3 | 2006-03-29 21:06:37 +0000 | [diff] [blame] | 9491 | |
| 9492 | /* If the cursor was in that line, move it to the end of the last |
| 9493 | * line. */ |
| 9494 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 9495 | { |
| 9496 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 9497 | coladvance((colnr_T)MAXCOL); |
| 9498 | } |
| 9499 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9500 | auto_format(FALSE, TRUE); |
| 9501 | } |
| 9502 | } |
| 9503 | |
| 9504 | /* |
| 9505 | * "o" and "O" commands. |
| 9506 | */ |
| 9507 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9508 | nv_open(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9509 | { |
| 9510 | #ifdef FEAT_DIFF |
| 9511 | /* "do" is ":diffget" */ |
| 9512 | if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') |
| 9513 | { |
| 9514 | clearop(cap->oap); |
Bram Moolenaar | 6a64365 | 2014-10-31 13:54:25 +0100 | [diff] [blame] | 9515 | nv_diffgetput(FALSE, cap->opcount); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9516 | } |
| 9517 | else |
| 9518 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9519 | if (VIsual_active) /* switch start and end of visual */ |
| 9520 | v_swap_corners(cap->cmdchar); |
| 9521 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9522 | n_opencmd(cap); |
| 9523 | } |
| 9524 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9525 | #ifdef FEAT_NETBEANS_INTG |
| 9526 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9527 | nv_nbcmd(cmdarg_T *cap) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9528 | { |
| 9529 | netbeans_keycommand(cap->nchar); |
| 9530 | } |
| 9531 | #endif |
| 9532 | |
| 9533 | #ifdef FEAT_DND |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9534 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9535 | nv_drop(cmdarg_T *cap UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9536 | { |
| 9537 | do_put('~', BACKWARD, 1L, PUT_CURSEND); |
| 9538 | } |
| 9539 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 9540 | |
| 9541 | #ifdef FEAT_AUTOCMD |
| 9542 | /* |
| 9543 | * Trigger CursorHold event. |
| 9544 | * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the |
| 9545 | * input buffer. "did_cursorhold" is set to avoid retriggering. |
| 9546 | */ |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 9547 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9548 | nv_cursorhold(cmdarg_T *cap) |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 9549 | { |
| 9550 | apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); |
| 9551 | did_cursorhold = TRUE; |
Bram Moolenaar | fc73515 | 2005-03-22 22:54:12 +0000 | [diff] [blame] | 9552 | cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 9553 | } |
| 9554 | #endif |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9555 | |
| 9556 | /* |
Bram Moolenaar | 89c17c0 | 2015-08-11 17:46:36 +0200 | [diff] [blame] | 9557 | * Calculate start/end virtual columns for operating in block mode. |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9558 | */ |
| 9559 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 9560 | get_op_vcol( |
| 9561 | oparg_T *oap, |
| 9562 | colnr_T redo_VIsual_vcol, |
| 9563 | int initial) /* when TRUE adjust position for 'selectmode' */ |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9564 | { |
| 9565 | colnr_T start, end; |
| 9566 | |
Bram Moolenaar | 89c17c0 | 2015-08-11 17:46:36 +0200 | [diff] [blame] | 9567 | if (VIsual_mode != Ctrl_V |
Bram Moolenaar | 0263146 | 2017-09-22 15:20:32 +0200 | [diff] [blame] | 9568 | || (!initial && oap->end.col < curwin->w_width)) |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9569 | return; |
| 9570 | |
Bram Moolenaar | 10ad1d9 | 2015-09-25 19:35:02 +0200 | [diff] [blame] | 9571 | oap->block_mode = TRUE; |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9572 | |
| 9573 | #ifdef FEAT_MBYTE |
| 9574 | /* prevent from moving onto a trail byte */ |
| 9575 | if (has_mbyte) |
| 9576 | mb_adjustpos(curwin->w_buffer, &oap->end); |
| 9577 | #endif |
| 9578 | |
| 9579 | getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9580 | |
Bram Moolenaar | 31b259b | 2015-07-28 11:21:32 +0200 | [diff] [blame] | 9581 | if (!redo_VIsual_busy) |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9582 | { |
Bram Moolenaar | 31b259b | 2015-07-28 11:21:32 +0200 | [diff] [blame] | 9583 | getvvcol(curwin, &(oap->end), &start, NULL, &end); |
| 9584 | |
| 9585 | if (start < oap->start_vcol) |
| 9586 | oap->start_vcol = start; |
| 9587 | if (end > oap->end_vcol) |
| 9588 | { |
| 9589 | if (initial && *p_sel == 'e' && start >= 1 |
| 9590 | && start - 1 >= oap->end_vcol) |
| 9591 | oap->end_vcol = start - 1; |
| 9592 | else |
| 9593 | oap->end_vcol = end; |
| 9594 | } |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9595 | } |
Bram Moolenaar | 31b259b | 2015-07-28 11:21:32 +0200 | [diff] [blame] | 9596 | |
Bram Moolenaar | 74db34c | 2015-06-25 13:30:46 +0200 | [diff] [blame] | 9597 | /* if '$' was used, get oap->end_vcol from longest line */ |
| 9598 | if (curwin->w_curswant == MAXCOL) |
| 9599 | { |
| 9600 | curwin->w_cursor.col = MAXCOL; |
| 9601 | oap->end_vcol = 0; |
| 9602 | for (curwin->w_cursor.lnum = oap->start.lnum; |
| 9603 | curwin->w_cursor.lnum <= oap->end.lnum; |
| 9604 | ++curwin->w_cursor.lnum) |
| 9605 | { |
| 9606 | getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); |
| 9607 | if (end > oap->end_vcol) |
| 9608 | oap->end_vcol = end; |
| 9609 | } |
| 9610 | } |
| 9611 | else if (redo_VIsual_busy) |
| 9612 | oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; |
| 9613 | /* |
| 9614 | * Correct oap->end.col and oap->start.col to be the |
| 9615 | * upper-left and lower-right corner of the block area. |
| 9616 | * |
| 9617 | * (Actually, this does convert column positions into character |
| 9618 | * positions) |
| 9619 | */ |
| 9620 | curwin->w_cursor.lnum = oap->end.lnum; |
| 9621 | coladvance(oap->end_vcol); |
| 9622 | oap->end = curwin->w_cursor; |
| 9623 | |
| 9624 | curwin->w_cursor = oap->start; |
| 9625 | coladvance(oap->start_vcol); |
| 9626 | oap->start = curwin->w_cursor; |
| 9627 | } |