1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
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.
10 * normal.c: Contains the main routine for processing characters in command
11 * mode. Communicates closely with the code in ops.c to handle
19 * The Visual area is remembered for reselection.
21 static int resel_VIsual_mode
= NUL
; /* 'v', 'V', or Ctrl-V */
22 static linenr_T resel_VIsual_line_count
; /* number of lines */
23 static colnr_T resel_VIsual_col
; /* nr of cols or end col */
25 static int restart_VIsual_select
= 0;
32 nv_compare
__ARGS((const void *s1
, const void *s2
));
33 static int find_command
__ARGS((int cmdchar
));
34 static void op_colon
__ARGS((oparg_T
*oap
));
35 static void op_function
__ARGS((oparg_T
*oap
));
36 #if defined(FEAT_MOUSE) && defined(FEAT_VISUAL)
37 static void find_start_of_word
__ARGS((pos_T
*));
38 static void find_end_of_word
__ARGS((pos_T
*));
39 static int get_mouse_class
__ARGS((char_u
*p
));
41 static void prep_redo_cmd
__ARGS((cmdarg_T
*cap
));
42 static void prep_redo
__ARGS((int regname
, long, int, int, int, int, int));
43 static int checkclearop
__ARGS((oparg_T
*oap
));
44 static int checkclearopq
__ARGS((oparg_T
*oap
));
45 static void clearop
__ARGS((oparg_T
*oap
));
46 static void clearopbeep
__ARGS((oparg_T
*oap
));
48 static void unshift_special
__ARGS((cmdarg_T
*cap
));
51 static void del_from_showcmd
__ARGS((int));
55 * nv_*(): functions called to handle Normal and Visual mode commands.
56 * n_*(): functions called to handle Normal mode commands.
57 * v_*(): functions called to handle Visual mode commands.
59 static void nv_ignore
__ARGS((cmdarg_T
*cap
));
60 static void nv_nop
__ARGS((cmdarg_T
*cap
));
61 static void nv_error
__ARGS((cmdarg_T
*cap
));
62 static void nv_help
__ARGS((cmdarg_T
*cap
));
63 static void nv_addsub
__ARGS((cmdarg_T
*cap
));
64 static void nv_page
__ARGS((cmdarg_T
*cap
));
65 static void nv_gd
__ARGS((oparg_T
*oap
, int nchar
, int thisblock
));
66 static int nv_screengo
__ARGS((oparg_T
*oap
, int dir
, long dist
));
68 static void nv_mousescroll
__ARGS((cmdarg_T
*cap
));
69 static void nv_mouse
__ARGS((cmdarg_T
*cap
));
71 static void nv_scroll_line
__ARGS((cmdarg_T
*cap
));
72 static void nv_zet
__ARGS((cmdarg_T
*cap
));
74 static void nv_ver_scrollbar
__ARGS((cmdarg_T
*cap
));
75 static void nv_hor_scrollbar
__ARGS((cmdarg_T
*cap
));
77 #ifdef FEAT_GUI_TABLINE
78 static void nv_tabline
__ARGS((cmdarg_T
*cap
));
79 static void nv_tabmenu
__ARGS((cmdarg_T
*cap
));
81 static void nv_exmode
__ARGS((cmdarg_T
*cap
));
82 static void nv_colon
__ARGS((cmdarg_T
*cap
));
83 static void nv_ctrlg
__ARGS((cmdarg_T
*cap
));
84 static void nv_ctrlh
__ARGS((cmdarg_T
*cap
));
85 static void nv_clear
__ARGS((cmdarg_T
*cap
));
86 static void nv_ctrlo
__ARGS((cmdarg_T
*cap
));
87 static void nv_hat
__ARGS((cmdarg_T
*cap
));
88 static void nv_Zet
__ARGS((cmdarg_T
*cap
));
89 static void nv_ident
__ARGS((cmdarg_T
*cap
));
90 static void nv_tagpop
__ARGS((cmdarg_T
*cap
));
91 static void nv_scroll
__ARGS((cmdarg_T
*cap
));
92 static void nv_right
__ARGS((cmdarg_T
*cap
));
93 static void nv_left
__ARGS((cmdarg_T
*cap
));
94 static void nv_up
__ARGS((cmdarg_T
*cap
));
95 static void nv_down
__ARGS((cmdarg_T
*cap
));
96 #ifdef FEAT_SEARCHPATH
97 static void nv_gotofile
__ARGS((cmdarg_T
*cap
));
99 static void nv_end
__ARGS((cmdarg_T
*cap
));
100 static void nv_dollar
__ARGS((cmdarg_T
*cap
));
101 static void nv_search
__ARGS((cmdarg_T
*cap
));
102 static void nv_next
__ARGS((cmdarg_T
*cap
));
103 static void normal_search
__ARGS((cmdarg_T
*cap
, int dir
, char_u
*pat
, int opt
));
104 static void nv_csearch
__ARGS((cmdarg_T
*cap
));
105 static void nv_brackets
__ARGS((cmdarg_T
*cap
));
106 static void nv_percent
__ARGS((cmdarg_T
*cap
));
107 static void nv_brace
__ARGS((cmdarg_T
*cap
));
108 static void nv_mark
__ARGS((cmdarg_T
*cap
));
109 static void nv_findpar
__ARGS((cmdarg_T
*cap
));
110 static void nv_undo
__ARGS((cmdarg_T
*cap
));
111 static void nv_kundo
__ARGS((cmdarg_T
*cap
));
112 static void nv_Replace
__ARGS((cmdarg_T
*cap
));
114 static void nv_vreplace
__ARGS((cmdarg_T
*cap
));
117 static void v_swap_corners
__ARGS((int cmdchar
));
119 static void nv_replace
__ARGS((cmdarg_T
*cap
));
120 static void n_swapchar
__ARGS((cmdarg_T
*cap
));
121 static void nv_cursormark
__ARGS((cmdarg_T
*cap
, int flag
, pos_T
*pos
));
123 static void v_visop
__ARGS((cmdarg_T
*cap
));
125 static void nv_subst
__ARGS((cmdarg_T
*cap
));
126 static void nv_abbrev
__ARGS((cmdarg_T
*cap
));
127 static void nv_optrans
__ARGS((cmdarg_T
*cap
));
128 static void nv_gomark
__ARGS((cmdarg_T
*cap
));
129 static void nv_pcmark
__ARGS((cmdarg_T
*cap
));
130 static void nv_regname
__ARGS((cmdarg_T
*cap
));
132 static void nv_visual
__ARGS((cmdarg_T
*cap
));
133 static void n_start_visual_mode
__ARGS((int c
));
135 static void nv_window
__ARGS((cmdarg_T
*cap
));
136 static void nv_suspend
__ARGS((cmdarg_T
*cap
));
137 static void nv_g_cmd
__ARGS((cmdarg_T
*cap
));
138 static void n_opencmd
__ARGS((cmdarg_T
*cap
));
139 static void nv_dot
__ARGS((cmdarg_T
*cap
));
140 static void nv_redo
__ARGS((cmdarg_T
*cap
));
141 static void nv_Undo
__ARGS((cmdarg_T
*cap
));
142 static void nv_tilde
__ARGS((cmdarg_T
*cap
));
143 static void nv_operator
__ARGS((cmdarg_T
*cap
));
145 static void set_op_var
__ARGS((int optype
));
147 static void nv_lineop
__ARGS((cmdarg_T
*cap
));
148 static void nv_home
__ARGS((cmdarg_T
*cap
));
149 static void nv_pipe
__ARGS((cmdarg_T
*cap
));
150 static void nv_bck_word
__ARGS((cmdarg_T
*cap
));
151 static void nv_wordcmd
__ARGS((cmdarg_T
*cap
));
152 static void nv_beginline
__ARGS((cmdarg_T
*cap
));
153 static void adjust_cursor
__ARGS((oparg_T
*oap
));
155 static void adjust_for_sel
__ARGS((cmdarg_T
*cap
));
156 static int unadjust_for_sel
__ARGS((void));
157 static void nv_select
__ARGS((cmdarg_T
*cap
));
159 static void nv_goto
__ARGS((cmdarg_T
*cap
));
160 static void nv_normal
__ARGS((cmdarg_T
*cap
));
161 static void nv_esc
__ARGS((cmdarg_T
*oap
));
162 static void nv_edit
__ARGS((cmdarg_T
*cap
));
163 static void invoke_edit
__ARGS((cmdarg_T
*cap
, int repl
, int cmd
, int startln
));
165 static void nv_object
__ARGS((cmdarg_T
*cap
));
167 static void nv_record
__ARGS((cmdarg_T
*cap
));
168 static void nv_at
__ARGS((cmdarg_T
*cap
));
169 static void nv_halfpage
__ARGS((cmdarg_T
*cap
));
170 static void nv_join
__ARGS((cmdarg_T
*cap
));
171 static void nv_put
__ARGS((cmdarg_T
*cap
));
172 static void nv_open
__ARGS((cmdarg_T
*cap
));
174 static void nv_sniff
__ARGS((cmdarg_T
*cap
));
176 #ifdef FEAT_NETBEANS_INTG
177 static void nv_nbcmd
__ARGS((cmdarg_T
*cap
));
180 static void nv_drop
__ARGS((cmdarg_T
*cap
));
183 static void nv_cursorhold
__ARGS((cmdarg_T
*cap
));
186 static char *e_noident
= N_("E349: No identifier under cursor");
189 * Function to be called for a Normal or Visual mode command.
190 * The argument is a cmdarg_T.
192 typedef void (*nv_func_T
) __ARGS((cmdarg_T
*cap
));
194 /* Values for cmd_flags. */
195 #define NV_NCH 0x01 /* may need to get a second char */
196 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */
197 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */
198 #define NV_LANG 0x08 /* second char needs language adjustment */
200 #define NV_SS 0x10 /* may start selection */
201 #define NV_SSS 0x20 /* may start selection with shift modifier */
202 #define NV_STS 0x40 /* may stop selection without shift modif. */
203 #define NV_RL 0x80 /* 'rightleft' modifies command */
204 #define NV_KEEPREG 0x100 /* don't clear regname */
205 #define NV_NCW 0x200 /* not allowed in command-line window */
208 * Generally speaking, every Normal mode command should either clear any
209 * pending operator (with *clearop*()), or set the motion type variable
212 * When a cursor motion command is made, it is marked as being a character or
213 * line oriented motion. Then, if an operator is in effect, the operation
214 * becomes character or line oriented accordingly.
218 * This table contains one entry for every Normal or Visual mode command.
219 * The order doesn't matter, init_normal_cmds() will create a sorted index.
220 * It is faster when all keys from zero to '~' are present.
222 static const struct nv_cmd
224 int cmd_char
; /* (first) command character */
225 nv_func_T cmd_func
; /* function for this command */
226 short_u cmd_flags
; /* NV_ flags */
227 short cmd_arg
; /* value for ca.arg */
230 {NUL
, nv_error
, 0, 0},
231 {Ctrl_A
, nv_addsub
, 0, 0},
232 {Ctrl_B
, nv_page
, NV_STS
, BACKWARD
},
233 {Ctrl_C
, nv_esc
, 0, TRUE
},
234 {Ctrl_D
, nv_halfpage
, 0, 0},
235 {Ctrl_E
, nv_scroll_line
, 0, TRUE
},
236 {Ctrl_F
, nv_page
, NV_STS
, FORWARD
},
237 {Ctrl_G
, nv_ctrlg
, 0, 0},
238 {Ctrl_H
, nv_ctrlh
, 0, 0},
239 {Ctrl_I
, nv_pcmark
, 0, 0},
240 {NL
, nv_down
, 0, FALSE
},
241 {Ctrl_K
, nv_error
, 0, 0},
242 {Ctrl_L
, nv_clear
, 0, 0},
243 {Ctrl_M
, nv_down
, 0, TRUE
},
244 {Ctrl_N
, nv_down
, NV_STS
, FALSE
},
245 {Ctrl_O
, nv_ctrlo
, 0, 0},
246 {Ctrl_P
, nv_up
, NV_STS
, FALSE
},
248 {Ctrl_Q
, nv_visual
, 0, FALSE
},
250 {Ctrl_Q
, nv_ignore
, 0, 0},
252 {Ctrl_R
, nv_redo
, 0, 0},
253 {Ctrl_S
, nv_ignore
, 0, 0},
254 {Ctrl_T
, nv_tagpop
, NV_NCW
, 0},
255 {Ctrl_U
, nv_halfpage
, 0, 0},
257 {Ctrl_V
, nv_visual
, 0, FALSE
},
258 {'V', nv_visual
, 0, FALSE
},
259 {'v', nv_visual
, 0, FALSE
},
261 {Ctrl_V
, nv_error
, 0, 0},
262 {'V', nv_error
, 0, 0},
263 {'v', nv_error
, 0, 0},
265 {Ctrl_W
, nv_window
, 0, 0},
266 {Ctrl_X
, nv_addsub
, 0, 0},
267 {Ctrl_Y
, nv_scroll_line
, 0, FALSE
},
268 {Ctrl_Z
, nv_suspend
, 0, 0},
269 {ESC
, nv_esc
, 0, FALSE
},
270 {Ctrl_BSL
, nv_normal
, NV_NCH_ALW
, 0},
271 {Ctrl_RSB
, nv_ident
, NV_NCW
, 0},
272 {Ctrl_HAT
, nv_hat
, NV_NCW
, 0},
273 {Ctrl__
, nv_error
, 0, 0},
274 {' ', nv_right
, 0, 0},
275 {'!', nv_operator
, 0, 0},
276 {'"', nv_regname
, NV_NCH_NOP
|NV_KEEPREG
, 0},
277 {'#', nv_ident
, 0, 0},
278 {'$', nv_dollar
, 0, 0},
279 {'%', nv_percent
, 0, 0},
280 {'&', nv_optrans
, 0, 0},
281 {'\'', nv_gomark
, NV_NCH_ALW
, TRUE
},
282 {'(', nv_brace
, 0, BACKWARD
},
283 {')', nv_brace
, 0, FORWARD
},
284 {'*', nv_ident
, 0, 0},
285 {'+', nv_down
, 0, TRUE
},
286 {',', nv_csearch
, 0, TRUE
},
287 {'-', nv_up
, 0, TRUE
},
288 {'.', nv_dot
, NV_KEEPREG
, 0},
289 {'/', nv_search
, 0, FALSE
},
290 {'0', nv_beginline
, 0, 0},
291 {'1', nv_ignore
, 0, 0},
292 {'2', nv_ignore
, 0, 0},
293 {'3', nv_ignore
, 0, 0},
294 {'4', nv_ignore
, 0, 0},
295 {'5', nv_ignore
, 0, 0},
296 {'6', nv_ignore
, 0, 0},
297 {'7', nv_ignore
, 0, 0},
298 {'8', nv_ignore
, 0, 0},
299 {'9', nv_ignore
, 0, 0},
300 {':', nv_colon
, 0, 0},
301 {';', nv_csearch
, 0, FALSE
},
302 {'<', nv_operator
, NV_RL
, 0},
303 {'=', nv_operator
, 0, 0},
304 {'>', nv_operator
, NV_RL
, 0},
305 {'?', nv_search
, 0, FALSE
},
306 {'@', nv_at
, NV_NCH_NOP
, FALSE
},
307 {'A', nv_edit
, 0, 0},
308 {'B', nv_bck_word
, 0, 1},
309 {'C', nv_abbrev
, NV_KEEPREG
, 0},
310 {'D', nv_abbrev
, NV_KEEPREG
, 0},
311 {'E', nv_wordcmd
, 0, TRUE
},
312 {'F', nv_csearch
, NV_NCH_ALW
|NV_LANG
, BACKWARD
},
313 {'G', nv_goto
, 0, TRUE
},
314 {'H', nv_scroll
, 0, 0},
315 {'I', nv_edit
, 0, 0},
316 {'J', nv_join
, 0, 0},
317 {'K', nv_ident
, 0, 0},
318 {'L', nv_scroll
, 0, 0},
319 {'M', nv_scroll
, 0, 0},
320 {'N', nv_next
, 0, SEARCH_REV
},
321 {'O', nv_open
, 0, 0},
323 {'Q', nv_exmode
, NV_NCW
, 0},
324 {'R', nv_Replace
, 0, FALSE
},
325 {'S', nv_subst
, NV_KEEPREG
, 0},
326 {'T', nv_csearch
, NV_NCH_ALW
|NV_LANG
, BACKWARD
},
327 {'U', nv_Undo
, 0, 0},
328 {'W', nv_wordcmd
, 0, TRUE
},
329 {'X', nv_abbrev
, NV_KEEPREG
, 0},
330 {'Y', nv_abbrev
, NV_KEEPREG
, 0},
331 {'Z', nv_Zet
, NV_NCH_NOP
|NV_NCW
, 0},
332 {'[', nv_brackets
, NV_NCH_ALW
, BACKWARD
},
333 {'\\', nv_error
, 0, 0},
334 {']', nv_brackets
, NV_NCH_ALW
, FORWARD
},
335 {'^', nv_beginline
, 0, BL_WHITE
| BL_FIX
},
336 {'_', nv_lineop
, 0, 0},
337 {'`', nv_gomark
, NV_NCH_ALW
, FALSE
},
338 {'a', nv_edit
, NV_NCH
, 0},
339 {'b', nv_bck_word
, 0, 0},
340 {'c', nv_operator
, 0, 0},
341 {'d', nv_operator
, 0, 0},
342 {'e', nv_wordcmd
, 0, FALSE
},
343 {'f', nv_csearch
, NV_NCH_ALW
|NV_LANG
, FORWARD
},
344 {'g', nv_g_cmd
, NV_NCH_ALW
, FALSE
},
345 {'h', nv_left
, NV_RL
, 0},
346 {'i', nv_edit
, NV_NCH
, 0},
347 {'j', nv_down
, 0, FALSE
},
348 {'k', nv_up
, 0, FALSE
},
349 {'l', nv_right
, NV_RL
, 0},
350 {'m', nv_mark
, NV_NCH_NOP
, 0},
351 {'n', nv_next
, 0, 0},
352 {'o', nv_open
, 0, 0},
354 {'q', nv_record
, NV_NCH
, 0},
355 {'r', nv_replace
, NV_NCH_NOP
|NV_LANG
, 0},
356 {'s', nv_subst
, NV_KEEPREG
, 0},
357 {'t', nv_csearch
, NV_NCH_ALW
|NV_LANG
, FORWARD
},
358 {'u', nv_undo
, 0, 0},
359 {'w', nv_wordcmd
, 0, FALSE
},
360 {'x', nv_abbrev
, NV_KEEPREG
, 0},
361 {'y', nv_operator
, 0, 0},
362 {'z', nv_zet
, NV_NCH_ALW
, 0},
363 {'{', nv_findpar
, 0, BACKWARD
},
364 {'|', nv_pipe
, 0, 0},
365 {'}', nv_findpar
, 0, FORWARD
},
366 {'~', nv_tilde
, 0, 0},
369 {POUND
, nv_ident
, 0, 0},
371 {K_MOUSEUP
, nv_mousescroll
, 0, TRUE
},
372 {K_MOUSEDOWN
, nv_mousescroll
, 0, FALSE
},
373 {K_LEFTMOUSE
, nv_mouse
, 0, 0},
374 {K_LEFTMOUSE_NM
, nv_mouse
, 0, 0},
375 {K_LEFTDRAG
, nv_mouse
, 0, 0},
376 {K_LEFTRELEASE
, nv_mouse
, 0, 0},
377 {K_LEFTRELEASE_NM
, nv_mouse
, 0, 0},
378 {K_MIDDLEMOUSE
, nv_mouse
, 0, 0},
379 {K_MIDDLEDRAG
, nv_mouse
, 0, 0},
380 {K_MIDDLERELEASE
, nv_mouse
, 0, 0},
381 {K_RIGHTMOUSE
, nv_mouse
, 0, 0},
382 {K_RIGHTDRAG
, nv_mouse
, 0, 0},
383 {K_RIGHTRELEASE
, nv_mouse
, 0, 0},
384 {K_X1MOUSE
, nv_mouse
, 0, 0},
385 {K_X1DRAG
, nv_mouse
, 0, 0},
386 {K_X1RELEASE
, nv_mouse
, 0, 0},
387 {K_X2MOUSE
, nv_mouse
, 0, 0},
388 {K_X2DRAG
, nv_mouse
, 0, 0},
389 {K_X2RELEASE
, nv_mouse
, 0, 0},
391 {K_IGNORE
, nv_ignore
, NV_KEEPREG
, 0},
392 {K_NOP
, nv_nop
, 0, 0},
393 {K_INS
, nv_edit
, 0, 0},
394 {K_KINS
, nv_edit
, 0, 0},
395 {K_BS
, nv_ctrlh
, 0, 0},
396 {K_UP
, nv_up
, NV_SSS
|NV_STS
, FALSE
},
397 {K_S_UP
, nv_page
, NV_SS
, BACKWARD
},
398 {K_DOWN
, nv_down
, NV_SSS
|NV_STS
, FALSE
},
399 {K_S_DOWN
, nv_page
, NV_SS
, FORWARD
},
400 {K_LEFT
, nv_left
, NV_SSS
|NV_STS
|NV_RL
, 0},
401 {K_S_LEFT
, nv_bck_word
, NV_SS
|NV_RL
, 0},
402 {K_C_LEFT
, nv_bck_word
, NV_SSS
|NV_RL
|NV_STS
, 1},
403 {K_RIGHT
, nv_right
, NV_SSS
|NV_STS
|NV_RL
, 0},
404 {K_S_RIGHT
, nv_wordcmd
, NV_SS
|NV_RL
, FALSE
},
405 {K_C_RIGHT
, nv_wordcmd
, NV_SSS
|NV_RL
|NV_STS
, TRUE
},
406 {K_PAGEUP
, nv_page
, NV_SSS
|NV_STS
, BACKWARD
},
407 {K_KPAGEUP
, nv_page
, NV_SSS
|NV_STS
, BACKWARD
},
408 {K_PAGEDOWN
, nv_page
, NV_SSS
|NV_STS
, FORWARD
},
409 {K_KPAGEDOWN
, nv_page
, NV_SSS
|NV_STS
, FORWARD
},
410 {K_END
, nv_end
, NV_SSS
|NV_STS
, FALSE
},
411 {K_KEND
, nv_end
, NV_SSS
|NV_STS
, FALSE
},
412 {K_S_END
, nv_end
, NV_SS
, FALSE
},
413 {K_C_END
, nv_end
, NV_SSS
|NV_STS
, TRUE
},
414 {K_HOME
, nv_home
, NV_SSS
|NV_STS
, 0},
415 {K_KHOME
, nv_home
, NV_SSS
|NV_STS
, 0},
416 {K_S_HOME
, nv_home
, NV_SS
, 0},
417 {K_C_HOME
, nv_goto
, NV_SSS
|NV_STS
, FALSE
},
418 {K_DEL
, nv_abbrev
, 0, 0},
419 {K_KDEL
, nv_abbrev
, 0, 0},
420 {K_UNDO
, nv_kundo
, 0, 0},
421 {K_HELP
, nv_help
, NV_NCW
, 0},
422 {K_F1
, nv_help
, NV_NCW
, 0},
423 {K_XF1
, nv_help
, NV_NCW
, 0},
425 {K_SELECT
, nv_select
, 0, 0},
428 {K_VER_SCROLLBAR
, nv_ver_scrollbar
, 0, 0},
429 {K_HOR_SCROLLBAR
, nv_hor_scrollbar
, 0, 0},
431 #ifdef FEAT_GUI_TABLINE
432 {K_TABLINE
, nv_tabline
, 0, 0},
433 {K_TABMENU
, nv_tabmenu
, 0, 0},
436 {K_F8
, farsi_fkey
, 0, 0},
437 {K_F9
, farsi_fkey
, 0, 0},
440 {K_SNIFF
, nv_sniff
, 0, 0},
442 #ifdef FEAT_NETBEANS_INTG
443 {K_F21
, nv_nbcmd
, NV_NCH_ALW
, 0},
446 {K_DROP
, nv_drop
, NV_STS
, 0},
449 {K_CURSORHOLD
, nv_cursorhold
, NV_KEEPREG
, 0},
453 /* Number of commands in nv_cmds[]. */
454 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd))
456 /* Sorted index of commands in nv_cmds[]. */
457 static short nv_cmd_idx
[NV_CMDS_SIZE
];
459 /* The highest index for which
460 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */
461 static int nv_max_linear
;
464 * Compare functions for qsort() below, that checks the command character
465 * through the index in nv_cmd_idx[].
477 /* The commands are sorted on absolute value. */
478 c1
= nv_cmds
[*(const short *)s1
].cmd_char
;
479 c2
= nv_cmds
[*(const short *)s2
].cmd_char
;
488 * Initialize the nv_cmd_idx[] table.
495 /* Fill the index table with a one to one relation. */
496 for (i
= 0; i
< NV_CMDS_SIZE
; ++i
)
499 /* Sort the commands by the command character. */
500 qsort((void *)&nv_cmd_idx
, (size_t)NV_CMDS_SIZE
, sizeof(short), nv_compare
);
502 /* Find the first entry that can't be indexed by the command character. */
503 for (i
= 0; i
< NV_CMDS_SIZE
; ++i
)
504 if (i
!= nv_cmds
[nv_cmd_idx
[i
]].cmd_char
)
506 nv_max_linear
= i
- 1;
510 * Search for a command in the commands table.
511 * Returns -1 for invalid command.
514 find_command(cmdchar
)
523 /* A multi-byte character is never a command. */
524 if (cmdchar
>= 0x100)
528 /* We use the absolute value of the character. Special keys have a
529 * negative value, but are sorted on their absolute value. */
533 /* If the character is in the first part: The character is the index into
535 if (cmdchar
<= nv_max_linear
)
536 return nv_cmd_idx
[cmdchar
];
538 /* Perform a binary search. */
539 bot
= nv_max_linear
+ 1;
540 top
= NV_CMDS_SIZE
- 1;
545 c
= nv_cmds
[nv_cmd_idx
[i
]].cmd_char
;
562 * Execute a command in Normal mode.
566 normal_cmd(oap
, toplevel
)
568 int toplevel
; /* TRUE when called from main() */
570 cmdarg_T ca
; /* command arguments */
572 int ctrl_w
= FALSE
; /* got CTRL-W command */
573 int old_col
= curwin
->w_curswant
;
574 #ifdef FEAT_CMDL_INFO
575 int need_flushbuf
; /* need to call out_flush() */
578 pos_T old_pos
; /* cursor position before command */
580 static int old_mapped_len
= 0;
584 int set_prevcount
= FALSE
;
587 vim_memset(&ca
, 0, sizeof(ca
)); /* also resets ca.retval */
590 /* Use a count remembered from before entering an operator. After typing
591 * "3d" we return from normal_cmd() and come back here, the "3" is
592 * remembered in "opcount". */
593 ca
.opcount
= opcount
;
596 want_sniff_request
= sniff_connected
;
600 * If there is an operator pending, then the command we take this time
601 * will terminate it. Finish_op tells us to finish the operation before
602 * returning this time (unless the operation was cancelled).
607 finish_op
= (oap
->op_type
!= OP_NOP
);
611 ui_cursor_shape(); /* may show different cursor shape */
612 # ifdef FEAT_MOUSESHAPE
613 update_mouseshape(-1);
618 /* When not finishing an operator and no register name typed, reset the
620 if (!finish_op
&& !oap
->regname
)
624 set_prevcount
= TRUE
;
629 /* Restore counts from before receiving K_CURSORHOLD. This means after
630 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not
632 if (oap
->prev_opcount
> 0 || oap
->prev_count0
> 0)
634 ca
.opcount
= oap
->prev_opcount
;
635 ca
.count0
= oap
->prev_count0
;
636 oap
->prev_opcount
= 0;
637 oap
->prev_count0
= 0;
642 mapped_len
= typebuf_maplen();
646 #ifdef USE_ON_FLY_SCROLL
647 dont_scroll
= FALSE
; /* allow scrolling here */
651 * Get the command character from the user.
654 LANGMAP_ADJUST(c
, TRUE
);
658 * If a mapping was started in Visual or Select mode, remember the length
659 * of the mapping. This is used below to not return to Insert mode for as
660 * long as the mapping is being executed.
662 if (restart_edit
== 0)
664 else if (old_mapped_len
665 || (VIsual_active
&& mapped_len
== 0 && typebuf_maplen() > 0))
666 old_mapped_len
= typebuf_maplen();
674 * In Select mode, typed text replaces the selection.
678 && (vim_isprintc(c
) || c
== NL
|| c
== CAR
|| c
== K_KENTER
))
680 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because
681 * 'insertmode' is set) fake a "d"elete command, Insert mode will
682 * restart automatically.
683 * Insert the typed character in the typeahead buffer, so that it can
684 * be mapped in Insert mode. Required for ":lmap" to work. */
686 if (restart_edit
!= 0)
690 msg_nowait
= TRUE
; /* don't delay going to insert mode */
694 #ifdef FEAT_CMDL_INFO
695 need_flushbuf
= add_to_showcmd(c
);
700 if (!(VIsual_active
&& VIsual_select
))
704 * Handle a count before a command and compute ca.count0.
705 * Note that '0' is a command and not the start of a count, but it's
706 * part of a count after other digits.
708 while ( (c
>= '1' && c
<= '9')
709 || (ca
.count0
!= 0 && (c
== K_DEL
|| c
== K_KDEL
|| c
== '0')))
711 if (c
== K_DEL
|| c
== K_KDEL
)
714 #ifdef FEAT_CMDL_INFO
715 del_from_showcmd(4); /* delete the digit and ~@% */
719 ca
.count0
= ca
.count0
* 10 + (c
- '0');
720 if (ca
.count0
< 0) /* got too large! */
721 ca
.count0
= 999999999L;
723 /* Set v:count here, when called from main() and not a stuffed
724 * command, so that v:count can be used in an expression mapping
725 * right after the count. */
726 if (toplevel
&& stuff_empty())
728 long count
= ca
.count0
;
730 /* multiply with ca.opcount the same way as below */
732 count
= ca
.opcount
* (count
== 0 ? 1 : count
);
733 set_vcount(count
, count
== 0 ? 1 : count
, set_prevcount
);
734 set_prevcount
= FALSE
; /* only set v:prevcount once */
740 ++allow_keys
; /* no mapping for nchar, but keys */
742 ++no_zero_mapping
; /* don't map zero here */
744 LANGMAP_ADJUST(c
, TRUE
);
751 #ifdef FEAT_CMDL_INFO
752 need_flushbuf
|= add_to_showcmd(c
);
757 * If we got CTRL-W there may be a/another count
759 if (c
== Ctrl_W
&& !ctrl_w
&& oap
->op_type
== OP_NOP
)
762 ca
.opcount
= ca
.count0
; /* remember first count */
765 ++allow_keys
; /* no mapping for nchar, but keys */
766 c
= plain_vgetc(); /* get next character */
767 LANGMAP_ADJUST(c
, TRUE
);
770 #ifdef FEAT_CMDL_INFO
771 need_flushbuf
|= add_to_showcmd(c
);
773 goto getcount
; /* jump back */
778 if (c
== K_CURSORHOLD
)
780 /* Save the count values so that ca.opcount and ca.count0 are exactly
781 * the same when coming back here after handling K_CURSORHOLD. */
782 oap
->prev_opcount
= ca
.opcount
;
783 oap
->prev_count0
= ca
.count0
;
790 * If we're in the middle of an operator (including after entering a
791 * yank buffer with '"') AND we had a count before the operator, then
792 * that count overrides the current value of ca.count0.
793 * What this means effectively, is that commands like "3dw" get turned
794 * into "d3w" which makes things fall into place pretty neatly.
795 * If you give a count before AND after the operator, they are
799 ca
.count0
*= ca
.opcount
;
801 ca
.count0
= ca
.opcount
;
805 * Always remember the count. It will be set to zero (on the next call,
806 * above) when there is no pending operator.
807 * When called from main(), save the count for use by the "count" built-in
810 ca
.opcount
= ca
.count0
;
811 ca
.count1
= (ca
.count0
== 0 ? 1 : ca
.count0
);
815 * Only set v:count when called from main() and not a stuffed command.
817 if (toplevel
&& stuff_empty())
818 set_vcount(ca
.count0
, ca
.count1
, set_prevcount
);
822 * Find the command character in the table of commands.
823 * For CTRL-W we already got nchar when looking for a count.
832 idx
= find_command(ca
.cmdchar
);
835 /* Not a known command: beep. */
840 if (text_locked() && (nv_cmds
[idx
].cmd_flags
& NV_NCW
))
842 /* This command is not allowed while editing a ccmdline: beep. */
848 if ((nv_cmds
[idx
].cmd_flags
& NV_NCW
) && curbuf_locked())
854 * In Visual/Select mode, a few keys are handled in a special way.
858 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */
860 && (nv_cmds
[idx
].cmd_flags
& NV_STS
)
861 && !(mod_mask
& MOD_MASK_SHIFT
))
864 redraw_curbuf_later(INVERTED
);
867 /* Keys that work different when 'keymodel' contains "startsel" */
870 if (nv_cmds
[idx
].cmd_flags
& NV_SS
)
872 unshift_special(&ca
);
873 idx
= find_command(ca
.cmdchar
);
881 else if ((nv_cmds
[idx
].cmd_flags
& NV_SSS
)
882 && (mod_mask
& MOD_MASK_SHIFT
))
884 mod_mask
&= ~MOD_MASK_SHIFT
;
890 #ifdef FEAT_RIGHTLEFT
891 if (curwin
->w_p_rl
&& KeyTyped
&& !KeyStuffed
892 && (nv_cmds
[idx
].cmd_flags
& NV_RL
))
894 /* Invert horizontal movements and operations. Only when typed by the
895 * user directly, not when the result of a mapping or "x" translated
899 case 'l': ca
.cmdchar
= 'h'; break;
900 case K_RIGHT
: ca
.cmdchar
= K_LEFT
; break;
901 case K_S_RIGHT
: ca
.cmdchar
= K_S_LEFT
; break;
902 case K_C_RIGHT
: ca
.cmdchar
= K_C_LEFT
; break;
903 case 'h': ca
.cmdchar
= 'l'; break;
904 case K_LEFT
: ca
.cmdchar
= K_RIGHT
; break;
905 case K_S_LEFT
: ca
.cmdchar
= K_S_RIGHT
; break;
906 case K_C_LEFT
: ca
.cmdchar
= K_C_RIGHT
; break;
907 case '>': ca
.cmdchar
= '<'; break;
908 case '<': ca
.cmdchar
= '>'; break;
910 idx
= find_command(ca
.cmdchar
);
915 * Get an additional character if we need one.
917 if ((nv_cmds
[idx
].cmd_flags
& NV_NCH
)
918 && (((nv_cmds
[idx
].cmd_flags
& NV_NCH_NOP
) == NV_NCH_NOP
919 && oap
->op_type
== OP_NOP
)
920 || (nv_cmds
[idx
].cmd_flags
& NV_NCH_ALW
) == NV_NCH_ALW
921 || (ca
.cmdchar
== 'q'
922 && oap
->op_type
== OP_NOP
925 || ((ca
.cmdchar
== 'a' || ca
.cmdchar
== 'i')
926 && (oap
->op_type
!= OP_NOP
933 int repl
= FALSE
; /* get character for replace mode */
934 int lit
= FALSE
; /* get extra character literally */
935 int langmap_active
= FALSE
; /* using :lmap mappings */
936 int lang
; /* getting a text character */
937 #ifdef USE_IM_CONTROL
938 int save_smd
; /* saved value of p_smd */
942 ++allow_keys
; /* no mapping for nchar, but allow key codes */
944 /* Don't generate a CursorHold event here, most commands can't handle
945 * it, e.g., nv_replace(), nv_csearch(). */
946 did_cursorhold
= TRUE
;
948 if (ca
.cmdchar
== 'g')
951 * For 'g' get the next character now, so that we can check for
952 * "gr", "g'" and "g`".
954 ca
.nchar
= plain_vgetc();
955 LANGMAP_ADJUST(ca
.nchar
, TRUE
);
956 #ifdef FEAT_CMDL_INFO
957 need_flushbuf
|= add_to_showcmd(ca
.nchar
);
959 if (ca
.nchar
== 'r' || ca
.nchar
== '\'' || ca
.nchar
== '`'
960 || ca
.nchar
== Ctrl_BSL
)
962 cp
= &ca
.extra_char
; /* need to get a third character */
964 lit
= TRUE
; /* get it literally */
966 repl
= TRUE
; /* get it in replace mode */
969 cp
= NULL
; /* no third character needed */
973 if (ca
.cmdchar
== 'r') /* get it in replace mode */
977 lang
= (repl
|| (nv_cmds
[idx
].cmd_flags
& NV_LANG
));
980 * Get a second or third character.
987 State
= REPLACE
; /* pretend Replace mode */
988 ui_cursor_shape(); /* show different cursor shape */
991 if (lang
&& curbuf
->b_p_iminsert
== B_IMODE_LMAP
)
993 /* Allow mappings defined with ":lmap". */
1000 langmap_active
= TRUE
;
1002 #ifdef USE_IM_CONTROL
1004 p_smd
= FALSE
; /* Don't let the IM code show the mode here */
1005 if (lang
&& curbuf
->b_p_iminsert
== B_IMODE_IM
)
1006 im_set_active(TRUE
);
1009 *cp
= plain_vgetc();
1013 /* Undo the decrement done above */
1016 State
= NORMAL_BUSY
;
1018 #ifdef USE_IM_CONTROL
1021 if (curbuf
->b_p_iminsert
!= B_IMODE_LMAP
)
1022 im_save_status(&curbuf
->b_p_iminsert
);
1023 im_set_active(FALSE
);
1028 State
= NORMAL_BUSY
;
1030 #ifdef FEAT_CMDL_INFO
1031 need_flushbuf
|= add_to_showcmd(*cp
);
1036 #ifdef FEAT_DIGRAPHS
1037 /* Typing CTRL-K gets a digraph. */
1039 && ((nv_cmds
[idx
].cmd_flags
& NV_LANG
)
1040 || cp
== &ca
.extra_char
)
1041 && vim_strchr(p_cpo
, CPO_DIGRAPH
) == NULL
)
1043 c
= get_digraph(FALSE
);
1047 # ifdef FEAT_CMDL_INFO
1048 /* Guessing how to update showcmd here... */
1049 del_from_showcmd(3);
1050 need_flushbuf
|= add_to_showcmd(*cp
);
1056 /* adjust chars > 127, except after "tTfFr" commands */
1057 LANGMAP_ADJUST(*cp
, !lang
);
1058 #ifdef FEAT_RIGHTLEFT
1059 /* adjust Hebrew mapped char */
1060 if (p_hkmap
&& lang
&& KeyTyped
)
1063 /* adjust Farsi mapped char */
1064 if (p_fkmap
&& lang
&& KeyTyped
)
1071 * When the next character is CTRL-\ a following CTRL-N means the
1072 * command is aborted and we go to Normal mode.
1074 if (cp
== &ca
.extra_char
1075 && ca
.nchar
== Ctrl_BSL
1076 && (ca
.extra_char
== Ctrl_N
|| ca
.extra_char
== Ctrl_G
))
1078 ca
.cmdchar
= Ctrl_BSL
;
1079 ca
.nchar
= ca
.extra_char
;
1080 idx
= find_command(ca
.cmdchar
);
1082 else if (*cp
== Ctrl_BSL
)
1084 long towait
= (p_ttm
>= 0 ? p_ttm
: p_tm
);
1086 /* There is a busy wait here when typing "f<C-\>" and then
1087 * something different from CTRL-N. Can't be avoided. */
1088 while ((c
= vpeekc()) <= 0 && towait
> 0L)
1090 do_sleep(towait
> 50L ? 50L : towait
);
1096 if (c
!= Ctrl_N
&& c
!= Ctrl_G
)
1100 ca
.cmdchar
= Ctrl_BSL
;
1102 idx
= find_command(ca
.cmdchar
);
1108 /* When getting a text character and the next character is a
1109 * multi-byte character, it could be a composing character.
1110 * However, don't wait for it to arrive. */
1111 while (enc_utf8
&& lang
&& (c
= vpeekc()) > 0
1112 && (c
>= 0x100 || MB_BYTE2LEN(vpeekc()) > 1))
1115 if (!utf_iscomposing(c
))
1117 vungetc(c
); /* it wasn't, put it back */
1120 else if (ca
.ncharC1
== 0)
1131 #ifdef FEAT_CMDL_INFO
1133 * Flush the showcmd characters onto the screen so we can see them while
1134 * the command is being executed. Only do this when the shown command was
1135 * actually displayed, otherwise this will slow down a lot when executing
1142 if (ca
.cmdchar
!= K_IGNORE
)
1143 did_cursorhold
= FALSE
;
1148 if (ca
.nchar
== ESC
)
1151 if (restart_edit
== 0 && goto_im())
1156 if (ca
.cmdchar
!= K_IGNORE
)
1158 msg_didout
= FALSE
; /* don't scroll screen up for normal command */
1163 old_pos
= curwin
->w_cursor
; /* remember where cursor was */
1165 /* When 'keymodel' contains "startsel" some keys start Select/Visual
1167 if (!VIsual_active
&& km_startsel
)
1169 if (nv_cmds
[idx
].cmd_flags
& NV_SS
)
1172 unshift_special(&ca
);
1173 idx
= find_command(ca
.cmdchar
);
1175 else if ((nv_cmds
[idx
].cmd_flags
& NV_SSS
)
1176 && (mod_mask
& MOD_MASK_SHIFT
))
1179 mod_mask
&= ~MOD_MASK_SHIFT
;
1185 * Execute the command!
1186 * Call the command function found in the commands table.
1188 ca
.arg
= nv_cmds
[idx
].cmd_arg
;
1189 (nv_cmds
[idx
].cmd_func
)(&ca
);
1192 * If we didn't start or finish an operator, reset oap->regname, unless we
1197 && (idx
< 0 || !(nv_cmds
[idx
].cmd_flags
& NV_KEEPREG
)))
1206 /* Get the length of mapped chars again after typing a count, second
1207 * character or "z333<cr>". */
1208 if (old_mapped_len
> 0)
1209 old_mapped_len
= typebuf_maplen();
1213 * If an operation is pending, handle it...
1215 do_pending_operator(&ca
, old_col
, FALSE
);
1218 * Wait for a moment when a message is displayed that will be overwritten
1219 * by the mode message.
1220 * In Visual mode and with "^O" in Insert mode, a short message will be
1221 * overwritten by the mode message. Wait a bit, until a key is hit.
1222 * In Visual mode, it's more important to keep the Visual area updated
1223 * than keeping a message (e.g. from a /pat search).
1224 * Only do this if the command was typed, not from a mapping.
1225 * Don't wait when emsg_silent is non-zero.
1226 * Also wait a bit after an error message, e.g. for "^O:".
1227 * Don't redraw the screen, it would remove the message.
1231 && (restart_edit
!= 0
1234 && old_pos
.lnum
== curwin
->w_cursor
.lnum
1235 && old_pos
.col
== curwin
->w_cursor
.col
)
1240 && (msg_didout
|| (msg_didany
&& msg_scroll
))
1243 || (restart_edit
!= 0
1248 || emsg_on_display
)))
1249 && oap
->regname
== 0
1250 && !(ca
.retval
& CA_COMMAND_BUSY
)
1255 && oap
->op_type
== OP_NOP
)
1257 int save_State
= State
;
1259 /* Draw the cursor with the right shape here */
1260 if (restart_edit
!= 0)
1263 /* If need to redraw, and there is a "keep_msg", redraw before the
1265 if (must_redraw
&& keep_msg
!= NULL
&& !emsg_on_display
)
1271 /* showmode() will clear keep_msg, but we want to use it anyway */
1273 /* now reset it, otherwise it's put in the history again */
1275 msg_attr(kmsg
, keep_msg_attr
);
1281 if (msg_scroll
|| emsg_on_display
)
1282 ui_delay(1000L, TRUE
); /* wait at least one second */
1283 ui_delay(3000L, FALSE
); /* wait up to three seconds */
1287 emsg_on_display
= FALSE
;
1291 * Finish up after executing a Normal mode command.
1297 /* Reset finish_op, in case it was set */
1303 /* Redraw the cursor with another shape, if we were in Operator-pending
1304 * mode or did a replace command. */
1305 if (c
|| ca
.cmdchar
== 'r')
1307 ui_cursor_shape(); /* may show different cursor shape */
1308 # ifdef FEAT_MOUSESHAPE
1309 update_mouseshape(-1);
1314 #ifdef FEAT_CMDL_INFO
1315 if (oap
->op_type
== OP_NOP
&& oap
->regname
== 0
1316 # ifdef FEAT_AUTOCMD
1317 && ca
.cmdchar
!= K_CURSORHOLD
1323 checkpcmark(); /* check if we moved since setting pcmark */
1324 vim_free(ca
.searchbuf
);
1331 #ifdef FEAT_SCROLLBIND
1332 if (curwin
->w_p_scb
&& toplevel
)
1334 validate_cursor(); /* may need to update w_leftcol */
1335 do_check_scrollbind(TRUE
);
1340 * May restart edit(), if we got here with CTRL-O in Insert mode (but not
1341 * if still inside a mapping that started in Visual mode).
1342 * May switch from Visual to Select mode after CTRL-O command.
1344 if ( oap
->op_type
== OP_NOP
1346 && ((restart_edit
!= 0 && !VIsual_active
&& old_mapped_len
== 0)
1347 || restart_VIsual_select
== 1)
1349 && restart_edit
!= 0
1351 && !(ca
.retval
& CA_COMMAND_BUSY
)
1353 && oap
->regname
== 0)
1356 if (restart_VIsual_select
== 1)
1358 VIsual_select
= TRUE
;
1360 restart_VIsual_select
= 0;
1363 if (restart_edit
!= 0
1365 && !VIsual_active
&& old_mapped_len
== 0
1368 (void)edit(restart_edit
, FALSE
, 1L);
1372 if (restart_VIsual_select
== 2)
1373 restart_VIsual_select
= 1;
1376 /* Save count before an operator for next time. */
1377 opcount
= ca
.opcount
;
1381 * Handle an operator after visual mode or when the movement is finished
1384 do_pending_operator(cap
, old_col
, gui_yank
)
1389 oparg_T
*oap
= cap
->oap
;
1391 int empty_region_error
;
1392 int restart_edit_save
;
1395 /* The visual area is remembered for redo */
1396 static int redo_VIsual_mode
= NUL
; /* 'v', 'V', or Ctrl-V */
1397 static linenr_T redo_VIsual_line_count
; /* number of lines */
1398 static colnr_T redo_VIsual_col
; /* number of cols or end column */
1399 static long redo_VIsual_count
; /* count for Visual operator */
1400 # ifdef FEAT_VIRTUALEDIT
1401 int include_line_break
= FALSE
;
1405 #if defined(FEAT_CLIPBOARD)
1407 * Yank the visual area into the GUI selection register before we operate
1408 * on it and lose it forever.
1409 * Don't do it if a specific register was specified, so that ""x"*P works.
1410 * This could call do_pending_operator() recursively, but that's OK
1411 * because gui_yank will be TRUE for the nested call.
1413 if (clip_star
.available
1414 && oap
->op_type
!= OP_NOP
1418 && !redo_VIsual_busy
1420 && oap
->regname
== 0)
1423 old_cursor
= curwin
->w_cursor
;
1426 * If an operation is pending, handle it...
1432 ) && oap
->op_type
!= OP_NOP
)
1435 oap
->is_VIsual
= VIsual_active
;
1436 if (oap
->motion_force
== 'V')
1437 oap
->motion_type
= MLINE
;
1438 else if (oap
->motion_force
== 'v')
1440 /* If the motion was linewise, "inclusive" will not have been set.
1441 * Use "exclusive" to be consistent. Makes "dvj" work nice. */
1442 if (oap
->motion_type
== MLINE
)
1443 oap
->inclusive
= FALSE
;
1444 /* If the motion already was characterwise, toggle "inclusive" */
1445 else if (oap
->motion_type
== MCHAR
)
1446 oap
->inclusive
= !oap
->inclusive
;
1447 oap
->motion_type
= MCHAR
;
1449 else if (oap
->motion_force
== Ctrl_V
)
1451 /* Change line- or characterwise motion into Visual block mode. */
1452 VIsual_active
= TRUE
;
1453 VIsual
= oap
->start
;
1454 VIsual_mode
= Ctrl_V
;
1455 VIsual_select
= FALSE
;
1456 VIsual_reselect
= FALSE
;
1460 /* only redo yank when 'y' flag is in 'cpoptions' */
1461 /* never redo "zf" (define fold) */
1462 if ((vim_strchr(p_cpo
, CPO_YANK
) != NULL
|| oap
->op_type
!= OP_YANK
)
1464 && (!VIsual_active
|| oap
->motion_force
)
1466 && cap
->cmdchar
!= 'D'
1468 && oap
->op_type
!= OP_FOLD
1469 && oap
->op_type
!= OP_FOLDOPEN
1470 && oap
->op_type
!= OP_FOLDOPENREC
1471 && oap
->op_type
!= OP_FOLDCLOSE
1472 && oap
->op_type
!= OP_FOLDCLOSEREC
1473 && oap
->op_type
!= OP_FOLDDEL
1474 && oap
->op_type
!= OP_FOLDDELREC
1478 prep_redo(oap
->regname
, cap
->count0
,
1479 get_op_char(oap
->op_type
), get_extra_op_char(oap
->op_type
),
1480 oap
->motion_force
, cap
->cmdchar
, cap
->nchar
);
1481 if (cap
->cmdchar
== '/' || cap
->cmdchar
== '?') /* was a search */
1484 * If 'cpoptions' does not contain 'r', insert the search
1485 * pattern to really repeat the same command.
1487 if (vim_strchr(p_cpo
, CPO_REDO
) == NULL
)
1488 AppendToRedobuffLit(cap
->searchbuf
, -1);
1489 AppendToRedobuff(NL_STR
);
1491 else if (cap
->cmdchar
== ':')
1493 /* do_cmdline() has stored the first typed line in
1494 * "repeat_cmdline". When several lines are typed repeating
1495 * won't be possible. */
1496 if (repeat_cmdline
== NULL
)
1500 AppendToRedobuffLit(repeat_cmdline
, -1);
1501 AppendToRedobuff(NL_STR
);
1502 vim_free(repeat_cmdline
);
1503 repeat_cmdline
= NULL
;
1509 if (redo_VIsual_busy
)
1511 oap
->start
= curwin
->w_cursor
;
1512 curwin
->w_cursor
.lnum
+= redo_VIsual_line_count
- 1;
1513 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
1514 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
1515 VIsual_mode
= redo_VIsual_mode
;
1516 if (VIsual_mode
== 'v')
1518 if (redo_VIsual_line_count
<= 1)
1519 curwin
->w_cursor
.col
+= redo_VIsual_col
- 1;
1521 curwin
->w_cursor
.col
= redo_VIsual_col
;
1523 if (redo_VIsual_col
== MAXCOL
)
1525 curwin
->w_curswant
= MAXCOL
;
1526 coladvance((colnr_T
)MAXCOL
);
1528 cap
->count0
= redo_VIsual_count
;
1529 if (redo_VIsual_count
!= 0)
1530 cap
->count1
= redo_VIsual_count
;
1534 else if (VIsual_active
)
1538 /* Save the current VIsual area for '< and '> marks, and "gv" */
1539 curbuf
->b_visual
.vi_start
= VIsual
;
1540 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
1541 curbuf
->b_visual
.vi_mode
= VIsual_mode
;
1542 curbuf
->b_visual
.vi_curswant
= curwin
->w_curswant
;
1544 curbuf
->b_visual_mode_eval
= VIsual_mode
;
1548 /* In Select mode, a linewise selection is operated upon like a
1549 * characterwise selection. */
1550 if (VIsual_select
&& VIsual_mode
== 'V')
1552 if (lt(VIsual
, curwin
->w_cursor
))
1555 curwin
->w_cursor
.col
=
1556 (colnr_T
)STRLEN(ml_get(curwin
->w_cursor
.lnum
));
1560 curwin
->w_cursor
.col
= 0;
1561 VIsual
.col
= (colnr_T
)STRLEN(ml_get(VIsual
.lnum
));
1565 /* If 'selection' is "exclusive", backup one character for
1566 * charwise selections. */
1567 else if (VIsual_mode
== 'v')
1569 # ifdef FEAT_VIRTUALEDIT
1570 include_line_break
=
1575 oap
->start
= VIsual
;
1576 if (VIsual_mode
== 'V')
1579 #endif /* FEAT_VISUAL */
1582 * Set oap->start to the first position of the operated text, oap->end
1583 * to the end of the operated text. w_cursor is equal to oap->start.
1585 if (lt(oap
->start
, curwin
->w_cursor
))
1588 /* Include folded lines completely. */
1591 if (hasFolding(oap
->start
.lnum
, &oap
->start
.lnum
, NULL
))
1593 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
,
1594 &curwin
->w_cursor
.lnum
))
1595 curwin
->w_cursor
.col
= (colnr_T
)STRLEN(ml_get_curline());
1598 oap
->end
= curwin
->w_cursor
;
1599 curwin
->w_cursor
= oap
->start
;
1601 /* w_virtcol may have been updated; if the cursor goes back to its
1602 * previous position w_virtcol becomes invalid and isn't updated
1604 curwin
->w_valid
&= ~VALID_VIRTCOL
;
1609 /* Include folded lines completely. */
1610 if (!VIsual_active
&& oap
->motion_type
== MLINE
)
1612 if (hasFolding(curwin
->w_cursor
.lnum
, &curwin
->w_cursor
.lnum
,
1614 curwin
->w_cursor
.col
= 0;
1615 if (hasFolding(oap
->start
.lnum
, NULL
, &oap
->start
.lnum
))
1616 oap
->start
.col
= (colnr_T
)STRLEN(ml_get(oap
->start
.lnum
));
1619 oap
->end
= oap
->start
;
1620 oap
->start
= curwin
->w_cursor
;
1623 oap
->line_count
= oap
->end
.lnum
- oap
->start
.lnum
+ 1;
1625 #ifdef FEAT_VIRTUALEDIT
1626 /* Set "virtual_op" before resetting VIsual_active. */
1627 virtual_op
= virtual_active();
1631 if (VIsual_active
|| redo_VIsual_busy
)
1633 if (VIsual_mode
== Ctrl_V
) /* block mode */
1637 oap
->block_mode
= TRUE
;
1639 getvvcol(curwin
, &(oap
->start
),
1640 &oap
->start_vcol
, NULL
, &oap
->end_vcol
);
1641 if (!redo_VIsual_busy
)
1643 getvvcol(curwin
, &(oap
->end
), &start
, NULL
, &end
);
1645 if (start
< oap
->start_vcol
)
1646 oap
->start_vcol
= start
;
1647 if (end
> oap
->end_vcol
)
1649 if (*p_sel
== 'e' && start
>= 1
1650 && start
- 1 >= oap
->end_vcol
)
1651 oap
->end_vcol
= start
- 1;
1653 oap
->end_vcol
= end
;
1657 /* if '$' was used, get oap->end_vcol from longest line */
1658 if (curwin
->w_curswant
== MAXCOL
)
1660 curwin
->w_cursor
.col
= MAXCOL
;
1662 for (curwin
->w_cursor
.lnum
= oap
->start
.lnum
;
1663 curwin
->w_cursor
.lnum
<= oap
->end
.lnum
;
1664 ++curwin
->w_cursor
.lnum
)
1666 getvvcol(curwin
, &curwin
->w_cursor
, NULL
, NULL
, &end
);
1667 if (end
> oap
->end_vcol
)
1668 oap
->end_vcol
= end
;
1671 else if (redo_VIsual_busy
)
1672 oap
->end_vcol
= oap
->start_vcol
+ redo_VIsual_col
- 1;
1674 * Correct oap->end.col and oap->start.col to be the
1675 * upper-left and lower-right corner of the block area.
1677 * (Actually, this does convert column positions into character
1680 curwin
->w_cursor
.lnum
= oap
->end
.lnum
;
1681 coladvance(oap
->end_vcol
);
1682 oap
->end
= curwin
->w_cursor
;
1684 curwin
->w_cursor
= oap
->start
;
1685 coladvance(oap
->start_vcol
);
1686 oap
->start
= curwin
->w_cursor
;
1689 if (!redo_VIsual_busy
&& !gui_yank
)
1692 * Prepare to reselect and redo Visual: this is based on the
1693 * size of the Visual text
1695 resel_VIsual_mode
= VIsual_mode
;
1696 if (curwin
->w_curswant
== MAXCOL
)
1697 resel_VIsual_col
= MAXCOL
;
1698 else if (VIsual_mode
== Ctrl_V
)
1699 resel_VIsual_col
= oap
->end_vcol
- oap
->start_vcol
+ 1;
1700 else if (oap
->line_count
> 1)
1701 resel_VIsual_col
= oap
->end
.col
;
1703 resel_VIsual_col
= oap
->end
.col
- oap
->start
.col
+ 1;
1704 resel_VIsual_line_count
= oap
->line_count
;
1707 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */
1708 if ((vim_strchr(p_cpo
, CPO_YANK
) != NULL
|| oap
->op_type
!= OP_YANK
)
1709 && oap
->op_type
!= OP_COLON
1711 && oap
->op_type
!= OP_FOLD
1712 && oap
->op_type
!= OP_FOLDOPEN
1713 && oap
->op_type
!= OP_FOLDOPENREC
1714 && oap
->op_type
!= OP_FOLDCLOSE
1715 && oap
->op_type
!= OP_FOLDCLOSEREC
1716 && oap
->op_type
!= OP_FOLDDEL
1717 && oap
->op_type
!= OP_FOLDDELREC
1719 && oap
->motion_force
== NUL
1722 /* Prepare for redoing. Only use the nchar field for "r",
1723 * otherwise it might be the second char of the operator. */
1724 prep_redo(oap
->regname
, 0L, NUL
, 'v',
1725 get_op_char(oap
->op_type
),
1726 get_extra_op_char(oap
->op_type
),
1727 oap
->op_type
== OP_REPLACE
? cap
->nchar
: NUL
);
1728 if (!redo_VIsual_busy
)
1730 redo_VIsual_mode
= resel_VIsual_mode
;
1731 redo_VIsual_col
= resel_VIsual_col
;
1732 redo_VIsual_line_count
= resel_VIsual_line_count
;
1733 redo_VIsual_count
= cap
->count0
;
1738 * oap->inclusive defaults to TRUE.
1739 * If oap->end is on a NUL (empty line) oap->inclusive becomes
1740 * FALSE. This makes "d}P" and "v}dP" work the same.
1742 if (oap
->motion_force
== NUL
|| oap
->motion_type
== MLINE
)
1743 oap
->inclusive
= TRUE
;
1744 if (VIsual_mode
== 'V')
1745 oap
->motion_type
= MLINE
;
1748 oap
->motion_type
= MCHAR
;
1749 if (VIsual_mode
!= Ctrl_V
&& *ml_get_pos(&(oap
->end
)) == NUL
1750 # ifdef FEAT_VIRTUALEDIT
1751 && (include_line_break
|| !virtual_op
)
1755 oap
->inclusive
= FALSE
;
1756 /* Try to include the newline, unless it's an operator
1757 * that works on lines only */
1759 && !op_on_lines(oap
->op_type
)
1760 && oap
->end
.lnum
< curbuf
->b_ml
.ml_line_count
)
1764 # ifdef FEAT_VIRTUALEDIT
1765 oap
->end
.coladd
= 0;
1772 redo_VIsual_busy
= FALSE
;
1775 * Switch Visual off now, so screen updating does
1776 * not show inverted text when the screen is redrawn.
1777 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is
1778 * no screen redraw, so it is done here to remove the inverted
1783 VIsual_active
= FALSE
;
1789 clear_cmdline
= TRUE
; /* unshow visual mode later */
1790 #ifdef FEAT_CMDL_INFO
1794 if ((oap
->op_type
== OP_YANK
1795 || oap
->op_type
== OP_COLON
1796 || oap
->op_type
== OP_FUNCTION
1797 || oap
->op_type
== OP_FILTER
)
1798 && oap
->motion_force
== NUL
)
1799 redraw_curbuf_later(INVERTED
);
1805 /* Include the trailing byte of a multi-byte char. */
1806 if (has_mbyte
&& oap
->inclusive
)
1810 l
= (*mb_ptr2len
)(ml_get_pos(&oap
->end
));
1812 oap
->end
.col
+= l
- 1;
1815 curwin
->w_set_curswant
= TRUE
;
1818 * oap->empty is set when start and end are the same. The inclusive
1819 * flag affects this too, unless yanking and the end is on a NUL.
1821 oap
->empty
= (oap
->motion_type
== MCHAR
1823 || (oap
->op_type
== OP_YANK
1824 && gchar_pos(&oap
->end
) == NUL
))
1825 && equalpos(oap
->start
, oap
->end
)
1826 #ifdef FEAT_VIRTUALEDIT
1827 && !(virtual_op
&& oap
->start
.coladd
!= oap
->end
.coladd
)
1831 * For delete, change and yank, it's an error to operate on an
1832 * empty region, when 'E' included in 'cpoptions' (Vi compatible).
1834 empty_region_error
= (oap
->empty
1835 && vim_strchr(p_cpo
, CPO_EMPTYREGION
) != NULL
);
1838 /* Force a redraw when operating on an empty Visual region, when
1839 * 'modifiable is off or creating a fold. */
1840 if (oap
->is_VIsual
&& (oap
->empty
|| !curbuf
->b_p_ma
1841 # ifdef FEAT_FOLDING
1842 || oap
->op_type
== OP_FOLD
1845 redraw_curbuf_later(INVERTED
);
1849 * If the end of an operator is in column one while oap->motion_type
1850 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last
1851 * character in the previous line. If op_start is on or before the
1852 * first non-blank in the line, the operator becomes linewise
1853 * (strange, but that's the way vi does it).
1855 if ( oap
->motion_type
== MCHAR
1856 && oap
->inclusive
== FALSE
1857 && !(cap
->retval
& CA_NO_ADJ_OP_END
)
1858 && oap
->end
.col
== 0
1860 && (!oap
->is_VIsual
|| *p_sel
== 'o')
1863 && oap
->line_count
> 1)
1865 oap
->end_adjusted
= TRUE
; /* remember that we did this */
1869 oap
->motion_type
= MLINE
;
1872 oap
->end
.col
= (colnr_T
)STRLEN(ml_get(oap
->end
.lnum
));
1876 oap
->inclusive
= TRUE
;
1881 oap
->end_adjusted
= FALSE
;
1883 switch (oap
->op_type
)
1889 oap
->is_VIsual
? (int)cap
->count1
:
1892 auto_format(FALSE
, TRUE
);
1897 if (oap
->line_count
< 2)
1898 oap
->line_count
= 2;
1899 if (curwin
->w_cursor
.lnum
+ oap
->line_count
- 1 >
1900 curbuf
->b_ml
.ml_line_count
)
1904 do_do_join(oap
->line_count
, oap
->op_type
== OP_JOIN
);
1905 auto_format(FALSE
, TRUE
);
1911 VIsual_reselect
= FALSE
; /* don't reselect now */
1913 if (empty_region_error
)
1917 (void)op_delete(oap
);
1918 if (oap
->motion_type
== MLINE
&& has_format_option(FO_AUTO
))
1919 u_save_cursor(); /* cursor line wasn't saved yet */
1920 auto_format(FALSE
, TRUE
);
1925 if (empty_region_error
)
1931 (void)op_yank(oap
, FALSE
, !gui_yank
);
1937 VIsual_reselect
= FALSE
; /* don't reselect now */
1939 if (empty_region_error
)
1943 /* This is a new edit command, not a restart. Need to
1944 * remember it to make 'insertmode' work with mappings for
1945 * Visual mode. But do this only once and not when typed and
1946 * 'insertmode' isn't set. */
1947 if (p_im
|| !KeyTyped
)
1948 restart_edit_save
= restart_edit
;
1950 restart_edit_save
= 0;
1952 /* Reset finish_op now, don't want it set inside edit(). */
1954 if (op_change(oap
)) /* will call edit() */
1955 cap
->retval
|= CA_COMMAND_BUSY
;
1956 if (restart_edit
== 0)
1957 restart_edit
= restart_edit_save
;
1962 if (vim_strchr(p_cpo
, CPO_FILTER
) != NULL
)
1963 AppendToRedobuff((char_u
*)"!\r"); /* use any last used !cmd */
1965 bangredo
= TRUE
; /* do_bang() will put cmd in redo buffer */
1970 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
1972 * If 'equalprg' is empty, do the indenting internally.
1974 if (oap
->op_type
== OP_INDENT
&& *get_equalprg() == NUL
)
1977 if (curbuf
->b_p_lisp
)
1979 op_reindent(oap
, get_lisp_indent
);
1983 # ifdef FEAT_CINDENT
1986 *curbuf
->b_p_inde
!= NUL
? get_expr_indent
:
2001 if (empty_region_error
)
2009 #if defined(FEAT_EVAL)
2010 if (*curbuf
->b_p_fex
!= NUL
)
2011 op_formatexpr(oap
); /* use expression */
2015 op_colon(oap
); /* use external command */
2017 op_format(oap
, FALSE
); /* use internal function */
2021 op_format(oap
, TRUE
); /* use internal function */
2025 op_function(oap
); /* call 'operatorfunc' */
2031 VIsual_reselect
= FALSE
; /* don't reselect now */
2033 #ifdef FEAT_VISUALEXTRA
2034 if (empty_region_error
)
2038 /* This is a new edit command, not a restart. Need to
2039 * remember it to make 'insertmode' work with mappings for
2040 * Visual mode. But do this only once. */
2041 restart_edit_save
= restart_edit
;
2044 op_insert(oap
, cap
->count1
);
2046 /* TODO: when inserting in several lines, should format all
2048 auto_format(FALSE
, TRUE
);
2050 if (restart_edit
== 0)
2051 restart_edit
= restart_edit_save
;
2060 VIsual_reselect
= FALSE
; /* don't reselect now */
2062 #ifdef FEAT_VISUALEXTRA
2063 if (empty_region_error
)
2066 #ifdef FEAT_VISUALEXTRA
2068 op_replace(oap
, cap
->nchar
);
2074 VIsual_reselect
= FALSE
; /* don't reselect now */
2075 foldCreate(oap
->start
.lnum
, oap
->end
.lnum
);
2079 case OP_FOLDOPENREC
:
2081 case OP_FOLDCLOSEREC
:
2082 VIsual_reselect
= FALSE
; /* don't reselect now */
2083 opFoldRange(oap
->start
.lnum
, oap
->end
.lnum
,
2084 oap
->op_type
== OP_FOLDOPEN
2085 || oap
->op_type
== OP_FOLDOPENREC
,
2086 oap
->op_type
== OP_FOLDOPENREC
2087 || oap
->op_type
== OP_FOLDCLOSEREC
,
2093 VIsual_reselect
= FALSE
; /* don't reselect now */
2094 deleteFold(oap
->start
.lnum
, oap
->end
.lnum
,
2095 oap
->op_type
== OP_FOLDDELREC
, oap
->is_VIsual
);
2101 #ifdef FEAT_VIRTUALEDIT
2107 * if 'sol' not set, go back to old column for some commands
2109 if (!p_sol
&& oap
->motion_type
== MLINE
&& !oap
->end_adjusted
2110 && (oap
->op_type
== OP_LSHIFT
|| oap
->op_type
== OP_RSHIFT
2111 || oap
->op_type
== OP_DELETE
))
2112 coladvance(curwin
->w_curswant
= old_col
);
2116 curwin
->w_cursor
= old_cursor
;
2119 oap
->block_mode
= FALSE
;
2126 * Handle indent and format operators and visual mode ":".
2132 stuffcharReadbuff(':');
2135 stuffReadbuff((char_u
*)"'<,'>");
2140 * Make the range look nice, so it can be repeated.
2142 if (oap
->start
.lnum
== curwin
->w_cursor
.lnum
)
2143 stuffcharReadbuff('.');
2145 stuffnumReadbuff((long)oap
->start
.lnum
);
2146 if (oap
->end
.lnum
!= oap
->start
.lnum
)
2148 stuffcharReadbuff(',');
2149 if (oap
->end
.lnum
== curwin
->w_cursor
.lnum
)
2150 stuffcharReadbuff('.');
2151 else if (oap
->end
.lnum
== curbuf
->b_ml
.ml_line_count
)
2152 stuffcharReadbuff('$');
2153 else if (oap
->start
.lnum
== curwin
->w_cursor
.lnum
)
2155 stuffReadbuff((char_u
*)".+");
2156 stuffnumReadbuff((long)oap
->line_count
- 1);
2159 stuffnumReadbuff((long)oap
->end
.lnum
);
2162 if (oap
->op_type
!= OP_COLON
)
2163 stuffReadbuff((char_u
*)"!");
2164 if (oap
->op_type
== OP_INDENT
)
2166 #ifndef FEAT_CINDENT
2167 if (*get_equalprg() == NUL
)
2168 stuffReadbuff((char_u
*)"indent");
2171 stuffReadbuff(get_equalprg());
2172 stuffReadbuff((char_u
*)"\n");
2174 else if (oap
->op_type
== OP_FORMAT
)
2177 stuffReadbuff((char_u
*)"fmt");
2179 stuffReadbuff(p_fp
);
2180 stuffReadbuff((char_u
*)"\n']");
2184 * do_cmdline() does the rest
2189 * Handle the "g@" operator: call 'operatorfunc'.
2199 if (*p_opfunc
== NUL
)
2200 EMSG(_("E774: 'operatorfunc' is empty"));
2203 /* Set '[ and '] marks to text to be operated on. */
2204 curbuf
->b_op_start
= oap
->start
;
2205 curbuf
->b_op_end
= oap
->end
;
2206 if (oap
->motion_type
!= MLINE
&& !oap
->inclusive
)
2207 /* Exclude the end position. */
2208 decl(&curbuf
->b_op_end
);
2210 if (oap
->block_mode
)
2211 argv
[0] = (char_u
*)"block";
2212 else if (oap
->motion_type
== MLINE
)
2213 argv
[0] = (char_u
*)"line";
2215 argv
[0] = (char_u
*)"char";
2216 (void)call_func_retnr(p_opfunc
, 1, argv
, FALSE
);
2219 EMSG(_("E775: Eval feature not available"));
2223 #if defined(FEAT_MOUSE) || defined(PROTO)
2225 * Do the appropriate action for the current mouse click in the current mode.
2226 * Not used for Command-line mode.
2229 * event modi- position visual change action
2230 * fier cursor window
2231 * left press - yes end yes
2232 * left press C yes end yes "^]" (2)
2233 * left press S yes end yes "*" (2)
2234 * left drag - yes start if moved no
2235 * left relse - yes start if moved no
2236 * middle press - yes if not active no put register
2237 * middle press - yes if active no yank and put
2238 * right press - yes start or extend yes
2239 * right press S yes no change yes "#" (2)
2240 * right drag - yes extend no
2241 * right relse - yes extend no
2243 * Insert or Replace Mode:
2244 * event modi- position visual change action
2245 * fier cursor window
2246 * left press - yes (cannot be active) yes
2247 * left press C yes (cannot be active) yes "CTRL-O^]" (2)
2248 * left press S yes (cannot be active) yes "CTRL-O*" (2)
2249 * left drag - yes start or extend (1) no CTRL-O (1)
2250 * left relse - yes start or extend (1) no CTRL-O (1)
2251 * middle press - no (cannot be active) no put register
2252 * right press - yes start or extend yes CTRL-O
2253 * right press S yes (cannot be active) yes "CTRL-O#" (2)
2255 * (1) only if mouse pointer moved since press
2256 * (2) only if click is in same buffer
2258 * Return TRUE if start_arrow() should be called for edit mode.
2261 do_mouse(oap
, c
, dir
, count
, fixindent
)
2262 oparg_T
*oap
; /* operator argument, can be NULL */
2263 int c
; /* K_LEFTMOUSE, etc */
2264 int dir
; /* Direction to 'put' if necessary */
2266 int fixindent
; /* PUT_FIXINDENT if fixing indent necessary */
2268 static int do_always
= FALSE
; /* ignore 'mouse' setting next time */
2269 static int got_click
= FALSE
; /* got a click some time back */
2271 int which_button
; /* MOUSE_LEFT, _MIDDLE or _RIGHT */
2272 int is_click
; /* If FALSE it's a drag or release event */
2273 int is_drag
; /* If TRUE it's a drag event */
2274 int jump_flags
= 0; /* flags for jump_to_mouse() */
2276 int moved
; /* Has cursor moved? */
2277 int in_status_line
; /* mouse in status line */
2278 #ifdef FEAT_VERTSPLIT
2279 int in_sep_line
; /* mouse in vertical separator line */
2282 #if defined(FEAT_FOLDING)
2285 win_T
*old_curwin
= curwin
;
2287 static pos_T orig_cursor
;
2288 colnr_T leftcol
, rightcol
;
2291 int old_active
= VIsual_active
;
2292 int old_mode
= VIsual_mode
;
2296 #if defined(FEAT_FOLDING)
2297 save_cursor
= curwin
->w_cursor
;
2301 * When GUI is active, always recognize mouse events, otherwise:
2302 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
2303 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
2304 * - For command line and insert mode 'mouse' is checked before calling
2317 if (!mouse_has(MOUSE_VISUAL
))
2322 if (State
== NORMAL
&& !mouse_has(MOUSE_NORMAL
))
2326 which_button
= get_mouse_button(KEY2TERMCAP1(c
), &is_click
, &is_drag
);
2328 #ifdef FEAT_MOUSESHAPE
2329 /* May have stopped dragging the status or separator line. The pointer is
2330 * most likely still on the status or separator line. */
2331 if (!is_drag
&& drag_status_line
)
2333 drag_status_line
= FALSE
;
2334 update_mouseshape(SHAPE_IDX_STATUS
);
2336 # ifdef FEAT_VERTSPLIT
2337 if (!is_drag
&& drag_sep_line
)
2339 drag_sep_line
= FALSE
;
2340 update_mouseshape(SHAPE_IDX_VSEP
);
2346 * Ignore drag and release events if we didn't get a click.
2352 if (!got_click
) /* didn't get click, ignore */
2354 if (!is_drag
) /* release, reset got_click */
2360 * ALT is only used for starging/extending Visual mode.
2362 if ((mod_mask
& MOD_MASK_ALT
))
2367 * CTRL right mouse button does CTRL-T
2369 if (is_click
&& (mod_mask
& MOD_MASK_CTRL
) && which_button
== MOUSE_RIGHT
)
2372 stuffcharReadbuff(Ctrl_O
);
2374 stuffnumReadbuff(count
);
2375 stuffcharReadbuff(Ctrl_T
);
2376 got_click
= FALSE
; /* ignore drag&release now */
2381 * CTRL only works with left mouse button
2383 if ((mod_mask
& MOD_MASK_CTRL
) && which_button
!= MOUSE_LEFT
)
2387 * When a modifier is down, ignore drag and release events, as well as
2388 * multiple clicks and the middle mouse button.
2389 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
2391 if ((mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
| MOD_MASK_ALT
2394 || (mod_mask
& MOD_MASK_MULTI_CLICK
)
2395 || which_button
== MOUSE_MIDDLE
)
2396 && !((mod_mask
& (MOD_MASK_SHIFT
|MOD_MASK_ALT
))
2397 && mouse_model_popup()
2398 && which_button
== MOUSE_LEFT
)
2399 && !((mod_mask
& MOD_MASK_ALT
)
2400 && !mouse_model_popup()
2401 && which_button
== MOUSE_RIGHT
)
2406 * If the button press was used as the movement command for an operator
2407 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
2408 * drag/release events.
2410 if (!is_click
&& which_button
== MOUSE_MIDDLE
)
2414 regname
= oap
->regname
;
2419 * Middle mouse button does a 'put' of the selected text
2421 if (which_button
== MOUSE_MIDDLE
)
2423 if (State
== NORMAL
)
2426 * If an operator was pending, we don't know what the user wanted
2427 * to do. Go back to normal mode: Clear the operator and beep().
2429 if (oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2437 * If visual was active, yank the highlighted text and put it
2438 * before the mouse pointer position.
2439 * In Select mode replace the highlighted text with the clipboard.
2445 stuffcharReadbuff(Ctrl_G
);
2446 stuffReadbuff((char_u
*)"\"+p");
2450 stuffcharReadbuff('y');
2451 stuffcharReadbuff(K_MIDDLEMOUSE
);
2453 do_always
= TRUE
; /* ignore 'mouse' setting next time */
2458 * The rest is below jump_to_mouse()
2462 else if ((State
& INSERT
) == 0)
2466 * Middle click in insert mode doesn't move the mouse, just insert the
2467 * contents of a register. '.' register is special, can't insert that
2469 * Also paste at the cursor if the current mode isn't in 'mouse' (only
2470 * happens for the GUI).
2472 if ((State
& INSERT
) || !mouse_has(MOUSE_NORMAL
))
2475 insert_reg(regname
, TRUE
);
2478 #ifdef FEAT_CLIPBOARD
2479 if (clip_star
.available
&& regname
== 0)
2482 if ((State
& REPLACE_FLAG
) && !yank_register_mline(regname
))
2483 insert_reg(regname
, TRUE
);
2486 do_put(regname
, BACKWARD
, 1L, fixindent
| PUT_CURSEND
);
2488 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */
2489 AppendCharToRedobuff(Ctrl_R
);
2490 AppendCharToRedobuff(fixindent
? Ctrl_P
: Ctrl_O
);
2491 AppendCharToRedobuff(regname
== 0 ? '"' : regname
);
2498 /* When dragging or button-up stay in the same window. */
2500 jump_flags
|= MOUSE_FOCUS
| MOUSE_DID_MOVE
;
2502 start_visual
.lnum
= 0;
2505 /* Check for clicking in the tab page line. */
2506 if (mouse_row
== 0 && firstwin
->w_winrow
> 0)
2510 got_click
= FALSE
; /* ignore mouse-up and drag events */
2512 /* click in a tab selects that tab page */
2517 && mouse_col
< Columns
)
2519 c1
= TabPageIdxs
[mouse_col
];
2522 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2524 /* double click opens new page */
2527 tabpage_move(c1
== 0 ? 9999 : c1
- 1);
2531 /* Go to specified tab page, or next one if not clicking
2535 /* It's like clicking on the status line of a window. */
2536 if (curwin
!= old_curwin
)
2544 /* Close the current or specified tab page. */
2548 tp
= find_tabpage(-c1
);
2551 if (first_tabpage
->tp_next
!= NULL
)
2552 tabpage_close(FALSE
);
2554 else if (tp
!= NULL
)
2555 tabpage_close_other(tp
, FALSE
);
2563 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
2564 * right button up -> pop-up menu
2565 * shift-left button -> right button
2566 * alt-left button -> alt-right button
2568 if (mouse_model_popup())
2570 if (which_button
== MOUSE_RIGHT
2571 && !(mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
)))
2574 * NOTE: Ignore right button down and drag mouse events.
2575 * Windows only shows the popup menu on the button up event.
2577 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2578 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) \
2579 || defined(FEAT_GUI_MACVIM)
2583 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN)
2584 if (is_click
|| is_drag
)
2587 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2588 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
2589 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) \
2590 || defined(FEAT_GUI_MACVIM)
2594 if (STRCMP(p_mousem
, "popup_setpos") == 0)
2596 /* First set the cursor position before showing the popup
2604 * set MOUSE_MAY_STOP_VIS if we are outside the
2605 * selection or the current window (might have false
2608 if (mouse_row
< W_WINROW(curwin
)
2610 > (W_WINROW(curwin
) + curwin
->w_height
))
2611 jump_flags
= MOUSE_MAY_STOP_VIS
;
2612 else if (get_fpos_of_mouse(&m_pos
) != IN_BUFFER
)
2613 jump_flags
= MOUSE_MAY_STOP_VIS
;
2616 if ((lt(curwin
->w_cursor
, VIsual
)
2617 && (lt(m_pos
, curwin
->w_cursor
)
2618 || lt(VIsual
, m_pos
)))
2619 || (lt(VIsual
, curwin
->w_cursor
)
2620 && (lt(m_pos
, VIsual
)
2621 || lt(curwin
->w_cursor
, m_pos
))))
2623 jump_flags
= MOUSE_MAY_STOP_VIS
;
2625 else if (VIsual_mode
== Ctrl_V
)
2627 getvcols(curwin
, &curwin
->w_cursor
, &VIsual
,
2628 &leftcol
, &rightcol
);
2629 getvcol(curwin
, &m_pos
, NULL
, &m_pos
.col
, NULL
);
2630 if (m_pos
.col
< leftcol
|| m_pos
.col
> rightcol
)
2631 jump_flags
= MOUSE_MAY_STOP_VIS
;
2636 jump_flags
= MOUSE_MAY_STOP_VIS
;
2641 jump_flags
= jump_to_mouse(jump_flags
, NULL
, which_button
);
2644 VIsual_active
? INVERTED
:
2648 out_flush(); /* Update before showing popup menu */
2651 gui_show_popupmenu();
2653 return (jump_flags
& CURSOR_MOVED
) != 0;
2661 if (which_button
== MOUSE_LEFT
2662 && (mod_mask
& (MOD_MASK_SHIFT
|MOD_MASK_ALT
)))
2664 which_button
= MOUSE_RIGHT
;
2665 mod_mask
&= ~MOD_MASK_SHIFT
;
2670 if ((State
& (NORMAL
| INSERT
))
2671 && !(mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
)))
2673 if (which_button
== MOUSE_LEFT
)
2677 /* stop Visual mode for a left click in a window, but not when
2678 * on a status line */
2680 jump_flags
|= MOUSE_MAY_STOP_VIS
;
2682 else if (mouse_has(MOUSE_VISUAL
))
2683 jump_flags
|= MOUSE_MAY_VIS
;
2685 else if (which_button
== MOUSE_RIGHT
)
2687 if (is_click
&& VIsual_active
)
2690 * Remember the start and end of visual before moving the
2693 if (lt(curwin
->w_cursor
, VIsual
))
2695 start_visual
= curwin
->w_cursor
;
2696 end_visual
= VIsual
;
2700 start_visual
= VIsual
;
2701 end_visual
= curwin
->w_cursor
;
2704 jump_flags
|= MOUSE_FOCUS
;
2705 if (mouse_has(MOUSE_VISUAL
))
2706 jump_flags
|= MOUSE_MAY_VIS
;
2712 * If an operator is pending, ignore all drags and releases until the
2715 if (!is_drag
&& oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2718 oap
->motion_type
= MCHAR
;
2721 /* When releasing the button let jump_to_mouse() know. */
2722 if (!is_click
&& !is_drag
)
2723 jump_flags
|= MOUSE_RELEASED
;
2728 jump_flags
= jump_to_mouse(jump_flags
,
2729 oap
== NULL
? NULL
: &(oap
->inclusive
), which_button
);
2730 moved
= (jump_flags
& CURSOR_MOVED
);
2731 in_status_line
= (jump_flags
& IN_STATUS_LINE
);
2732 #ifdef FEAT_VERTSPLIT
2733 in_sep_line
= (jump_flags
& IN_SEP_LINE
);
2736 #ifdef FEAT_NETBEANS_INTG
2737 if (usingNetbeans
&& isNetbeansBuffer(curbuf
)
2738 && !(jump_flags
& (IN_STATUS_LINE
| IN_SEP_LINE
)))
2740 int key
= KEY2TERMCAP1(c
);
2742 if (key
== (int)KE_LEFTRELEASE
|| key
== (int)KE_MIDDLERELEASE
2743 || key
== (int)KE_RIGHTRELEASE
)
2744 netbeans_button_release(which_button
);
2748 /* When jumping to another window, clear a pending operator. That's a bit
2749 * friendlier than beeping and not jumping to that window. */
2750 if (curwin
!= old_curwin
&& oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2756 && (jump_flags
& (MOUSE_FOLD_CLOSE
| MOUSE_FOLD_OPEN
))
2757 && which_button
== MOUSE_LEFT
)
2759 /* open or close a fold at this line */
2760 if (jump_flags
& MOUSE_FOLD_OPEN
)
2761 openFold(curwin
->w_cursor
.lnum
, 1L);
2763 closeFold(curwin
->w_cursor
.lnum
, 1L);
2764 /* don't move the cursor if still in the same window */
2765 if (curwin
== old_curwin
)
2766 curwin
->w_cursor
= save_cursor
;
2770 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
2771 if ((jump_flags
& IN_OTHER_WIN
) && !VIsual_active
&& clip_star
.available
)
2773 clip_modeless(which_button
, is_click
, is_drag
);
2779 /* Set global flag that we are extending the Visual area with mouse
2780 * dragging; temporarily minimize 'scrolloff'. */
2781 if (VIsual_active
&& is_drag
&& p_so
)
2783 /* In the very first line, allow scrolling one line */
2790 /* When dragging the mouse above the window, scroll down. */
2791 if (is_drag
&& mouse_row
< 0 && !in_status_line
)
2793 scroll_redraw(FALSE
, 1L);
2797 if (start_visual
.lnum
) /* right click in visual mode */
2799 /* When ALT is pressed make Visual mode blockwise. */
2800 if (mod_mask
& MOD_MASK_ALT
)
2801 VIsual_mode
= Ctrl_V
;
2804 * In Visual-block mode, divide the area in four, pick up the corner
2805 * that is in the quarter that the cursor is in.
2807 if (VIsual_mode
== Ctrl_V
)
2809 getvcols(curwin
, &start_visual
, &end_visual
, &leftcol
, &rightcol
);
2810 if (curwin
->w_curswant
> (leftcol
+ rightcol
) / 2)
2811 end_visual
.col
= leftcol
;
2813 end_visual
.col
= rightcol
;
2814 if (curwin
->w_cursor
.lnum
<
2815 (start_visual
.lnum
+ end_visual
.lnum
) / 2)
2816 end_visual
.lnum
= end_visual
.lnum
;
2818 end_visual
.lnum
= start_visual
.lnum
;
2820 /* move VIsual to the right column */
2821 start_visual
= curwin
->w_cursor
; /* save the cursor pos */
2822 curwin
->w_cursor
= end_visual
;
2823 coladvance(end_visual
.col
);
2824 VIsual
= curwin
->w_cursor
;
2825 curwin
->w_cursor
= start_visual
; /* restore the cursor */
2830 * If the click is before the start of visual, change the start.
2831 * If the click is after the end of visual, change the end. If
2832 * the click is inside the visual, change the closest side.
2834 if (lt(curwin
->w_cursor
, start_visual
))
2835 VIsual
= end_visual
;
2836 else if (lt(end_visual
, curwin
->w_cursor
))
2837 VIsual
= start_visual
;
2840 /* In the same line, compare column number */
2841 if (end_visual
.lnum
== start_visual
.lnum
)
2843 if (curwin
->w_cursor
.col
- start_visual
.col
>
2844 end_visual
.col
- curwin
->w_cursor
.col
)
2845 VIsual
= start_visual
;
2847 VIsual
= end_visual
;
2850 /* In different lines, compare line number */
2853 diff
= (curwin
->w_cursor
.lnum
- start_visual
.lnum
) -
2854 (end_visual
.lnum
- curwin
->w_cursor
.lnum
);
2856 if (diff
> 0) /* closest to end */
2857 VIsual
= start_visual
;
2858 else if (diff
< 0) /* closest to start */
2859 VIsual
= end_visual
;
2860 else /* in the middle line */
2862 if (curwin
->w_cursor
.col
<
2863 (start_visual
.col
+ end_visual
.col
) / 2)
2864 VIsual
= end_visual
;
2866 VIsual
= start_visual
;
2873 * If Visual mode started in insert mode, execute "CTRL-O"
2875 else if ((State
& INSERT
) && VIsual_active
)
2876 stuffcharReadbuff(Ctrl_O
);
2880 * Middle mouse click: Put text before cursor.
2882 if (which_button
== MOUSE_MIDDLE
)
2884 #ifdef FEAT_CLIPBOARD
2885 if (clip_star
.available
&& regname
== 0)
2888 if (yank_register_mline(regname
))
2890 if (mouse_past_bottom
)
2893 else if (mouse_past_eol
)
2898 c1
= (dir
== BACKWARD
) ? '[' : ']';
2903 c1
= (dir
== FORWARD
) ? 'p' : 'P';
2906 prep_redo(regname
, count
, NUL
, c1
, NUL
, c2
, NUL
);
2909 * Remember where the paste started, so in edit() Insstart can be set
2912 if (restart_edit
!= 0)
2913 where_paste_started
= curwin
->w_cursor
;
2914 do_put(regname
, dir
, count
, fixindent
| PUT_CURSEND
);
2917 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2919 * Ctrl-Mouse click or double click in a quickfix window jumps to the
2920 * error under the mouse pointer.
2922 else if (((mod_mask
& MOD_MASK_CTRL
)
2923 || (mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2924 && bt_quickfix(curbuf
))
2927 stuffcharReadbuff(Ctrl_O
);
2928 if (curwin
->w_llist_ref
== NULL
) /* quickfix window */
2929 stuffReadbuff((char_u
*)":.cc\n");
2930 else /* location list window */
2931 stuffReadbuff((char_u
*)":.ll\n");
2932 got_click
= FALSE
; /* ignore drag&release now */
2937 * Ctrl-Mouse click (or double click in a help window) jumps to the tag
2938 * under the mouse pointer.
2940 else if ((mod_mask
& MOD_MASK_CTRL
) || (curbuf
->b_help
2941 && (mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
))
2944 stuffcharReadbuff(Ctrl_O
);
2945 stuffcharReadbuff(Ctrl_RSB
);
2946 got_click
= FALSE
; /* ignore drag&release now */
2950 * Shift-Mouse click searches for the next occurrence of the word under
2953 else if ((mod_mask
& MOD_MASK_SHIFT
))
2957 || (VIsual_active
&& VIsual_select
)
2960 stuffcharReadbuff(Ctrl_O
);
2961 if (which_button
== MOUSE_LEFT
)
2962 stuffcharReadbuff('*');
2963 else /* MOUSE_RIGHT */
2964 stuffcharReadbuff('#');
2967 /* Handle double clicks, unless on status line */
2968 else if (in_status_line
)
2970 #ifdef FEAT_MOUSESHAPE
2971 if ((is_drag
|| is_click
) && !drag_status_line
)
2973 drag_status_line
= TRUE
;
2974 update_mouseshape(-1);
2978 #ifdef FEAT_VERTSPLIT
2979 else if (in_sep_line
)
2981 # ifdef FEAT_MOUSESHAPE
2982 if ((is_drag
|| is_click
) && !drag_sep_line
)
2984 drag_sep_line
= TRUE
;
2985 update_mouseshape(-1);
2991 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) && (State
& (NORMAL
| INSERT
))
2992 && mouse_has(MOUSE_VISUAL
))
2994 if (is_click
|| !VIsual_active
)
2997 orig_cursor
= VIsual
;
3000 check_visual_highlight();
3001 VIsual
= curwin
->w_cursor
;
3002 orig_cursor
= VIsual
;
3003 VIsual_active
= TRUE
;
3004 VIsual_reselect
= TRUE
;
3005 /* start Select mode if 'selectmode' contains "mouse" */
3006 may_start_select('o');
3009 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
3011 /* Double click with ALT pressed makes it blockwise. */
3012 if (mod_mask
& MOD_MASK_ALT
)
3013 VIsual_mode
= Ctrl_V
;
3017 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_3CLICK
)
3019 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_4CLICK
)
3020 VIsual_mode
= Ctrl_V
;
3021 #ifdef FEAT_CLIPBOARD
3022 /* Make sure the clipboard gets updated. Needed because start and
3023 * end may still be the same, and the selection needs to be owned */
3024 clip_star
.vmode
= NUL
;
3028 * A double click selects a word or a block.
3030 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
3037 /* If the character under the cursor (skipping white space) is
3038 * not a word character, try finding a match and select a (),
3039 * {}, [], #if/#endif, etc. block. */
3040 end_visual
= curwin
->w_cursor
;
3041 while (gc
= gchar_pos(&end_visual
), vim_iswhite(gc
))
3044 oap
->motion_type
= MCHAR
;
3046 && VIsual_mode
== 'v'
3047 && !vim_iswordc(gchar_pos(&end_visual
))
3048 && equalpos(curwin
->w_cursor
, VIsual
)
3049 && (pos
= findmatch(oap
, NUL
)) != NULL
)
3051 curwin
->w_cursor
= *pos
;
3052 if (oap
->motion_type
== MLINE
)
3054 else if (*p_sel
== 'e')
3056 if (lt(curwin
->w_cursor
, VIsual
))
3059 ++curwin
->w_cursor
.col
;
3064 if (pos
== NULL
&& (is_click
|| is_drag
))
3066 /* When not found a match or when dragging: extend to include
3068 if (lt(curwin
->w_cursor
, orig_cursor
))
3070 find_start_of_word(&curwin
->w_cursor
);
3071 find_end_of_word(&VIsual
);
3075 find_start_of_word(&VIsual
);
3076 if (*p_sel
== 'e' && *ml_get_cursor() != NUL
)
3078 curwin
->w_cursor
.col
+=
3079 (*mb_ptr2len
)(ml_get_cursor());
3081 ++curwin
->w_cursor
.col
;
3083 find_end_of_word(&curwin
->w_cursor
);
3086 curwin
->w_set_curswant
= TRUE
;
3089 redraw_curbuf_later(INVERTED
); /* update the inversion */
3091 else if (VIsual_active
&& !old_active
)
3093 if (mod_mask
& MOD_MASK_ALT
)
3094 VIsual_mode
= Ctrl_V
;
3099 /* If Visual mode changed show it later. */
3100 if ((!VIsual_active
&& old_active
&& mode_displayed
)
3101 || (VIsual_active
&& p_smd
&& msg_silent
== 0
3102 && (!old_active
|| VIsual_mode
!= old_mode
)))
3103 redraw_cmdline
= TRUE
;
3111 * Move "pos" back to the start of the word it's in.
3114 find_start_of_word(pos
)
3121 line
= ml_get(pos
->lnum
);
3122 cclass
= get_mouse_class(line
+ pos
->col
);
3124 while (pos
->col
> 0)
3128 col
-= (*mb_head_off
)(line
, line
+ col
);
3130 if (get_mouse_class(line
+ col
) != cclass
)
3137 * Move "pos" forward to the end of the word it's in.
3138 * When 'selection' is "exclusive", the position is just after the word.
3141 find_end_of_word(pos
)
3148 line
= ml_get(pos
->lnum
);
3149 if (*p_sel
== 'e' && pos
->col
> 0)
3153 pos
->col
-= (*mb_head_off
)(line
, line
+ pos
->col
);
3156 cclass
= get_mouse_class(line
+ pos
->col
);
3157 while (line
[pos
->col
] != NUL
)
3160 col
= pos
->col
+ (*mb_ptr2len
)(line
+ pos
->col
);
3164 if (get_mouse_class(line
+ col
) != cclass
)
3175 * Get class of a character for selection: same class means same word.
3177 * 1: punctuation groups
3178 * 2: normal word character
3179 * >2: multi-byte word character.
3188 if (has_mbyte
&& MB_BYTE2LEN(p
[0]) > 1)
3189 return mb_get_class(p
);
3193 if (c
== ' ' || c
== '\t')
3200 * There are a few special cases where we want certain combinations of
3201 * characters to be considered as a single word. These are things like
3202 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
3203 * character is in it's own class.
3205 if (c
!= NUL
&& vim_strchr((char_u
*)"-+*/%<>&|^!=", c
) != NULL
)
3209 #endif /* FEAT_VISUAL */
3210 #endif /* FEAT_MOUSE */
3212 #if defined(FEAT_VISUAL) || defined(PROTO)
3214 * Check if highlighting for visual mode is possible, give a warning message
3218 check_visual_highlight()
3220 static int did_check
= FALSE
;
3224 if (!did_check
&& hl_attr(HLF_V
) == 0)
3225 MSG(_("Warning: terminal cannot highlight"));
3232 * This function should ALWAYS be called to end Visual mode, except from
3233 * do_pending_operator().
3238 #ifdef FEAT_CLIPBOARD
3240 * If we are using the clipboard, then remember what was selected in case
3241 * we need to paste it somewhere while we still own the selection.
3242 * Only do this when the clipboard is already owned. Don't want to grab
3243 * the selection when hitting ESC.
3245 if (clip_star
.available
&& clip_star
.owned
)
3249 VIsual_active
= FALSE
;
3255 /* Save the current VIsual area for '< and '> marks, and "gv" */
3256 curbuf
->b_visual
.vi_mode
= VIsual_mode
;
3257 curbuf
->b_visual
.vi_start
= VIsual
;
3258 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
3259 curbuf
->b_visual
.vi_curswant
= curwin
->w_curswant
;
3261 curbuf
->b_visual_mode_eval
= VIsual_mode
;
3263 #ifdef FEAT_VIRTUALEDIT
3264 if (!virtual_active())
3265 curwin
->w_cursor
.coladd
= 0;
3269 clear_cmdline
= TRUE
; /* unshow visual mode later */
3270 #ifdef FEAT_CMDL_INFO
3275 adjust_cursor_eol();
3279 * Reset VIsual_active and VIsual_reselect.
3282 reset_VIsual_and_resel()
3287 redraw_curbuf_later(INVERTED
); /* delete the inversion later */
3289 VIsual_reselect
= FALSE
;
3293 * Reset VIsual_active and VIsual_reselect if it's set.
3301 redraw_curbuf_later(INVERTED
); /* delete the inversion later */
3302 VIsual_reselect
= FALSE
;
3305 #endif /* FEAT_VISUAL */
3307 #if defined(FEAT_BEVAL)
3308 static int find_is_eval_item
__ARGS((char_u
*ptr
, int *colp
, int *nbp
, int dir
));
3311 * Check for a balloon-eval special item to include when searching for an
3312 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid!
3313 * Returns TRUE if the character at "*ptr" should be included.
3314 * "dir" is FORWARD or BACKWARD, the direction of searching.
3315 * "*colp" is in/decremented if "ptr[-dir]" should also be included.
3316 * "bnp" points to a counter for square brackets.
3319 find_is_eval_item(ptr
, colp
, bnp
, dir
)
3325 /* Accept everything inside []. */
3326 if ((*ptr
== ']' && dir
== BACKWARD
) || (*ptr
== '[' && dir
== FORWARD
))
3330 if ((*ptr
== '[' && dir
== BACKWARD
) || (*ptr
== ']' && dir
== FORWARD
))
3335 /* skip over "s.var" */
3339 /* two-character item: s->var */
3340 if (ptr
[dir
== BACKWARD
? 0 : 1] == '>'
3341 && ptr
[dir
== BACKWARD
? -1 : 0] == '-')
3351 * Find the identifier under or to the right of the cursor.
3352 * "find_type" can have one of three values:
3353 * FIND_IDENT: find an identifier (keyword)
3354 * FIND_STRING: find any non-white string
3355 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred.
3356 * FIND_EVAL: find text useful for C program debugging
3358 * There are three steps:
3359 * 1. Search forward for the start of an identifier/string. Doesn't move if
3361 * 2. Search backward for the start of this identifier/string.
3362 * This doesn't match the real Vi but I like it a little better and it
3363 * shouldn't bother anyone.
3364 * 3. Search forward to the end of this identifier/string.
3365 * When FIND_IDENT isn't defined, we backup until a blank.
3367 * Returns the length of the string, or zero if no string is found.
3368 * If a string is found, a pointer to the string is put in "*string". This
3369 * string is not always NUL terminated.
3372 find_ident_under_cursor(string
, find_type
)
3376 return find_ident_at_pos(curwin
, curwin
->w_cursor
.lnum
,
3377 curwin
->w_cursor
.col
, string
, find_type
);
3381 * Like find_ident_under_cursor(), but for any window and any position.
3382 * However: Uses 'iskeyword' from the current window!.
3385 find_ident_at_pos(wp
, lnum
, startcol
, string
, find_type
)
3393 int col
= 0; /* init to shut up GCC */
3400 #if defined(FEAT_BEVAL)
3401 int bn
= 0; /* bracket nesting */
3405 * if i == 0: try to find an identifier
3406 * if i == 1: try to find any non-white string
3408 ptr
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3409 for (i
= (find_type
& FIND_IDENT
) ? 0 : 1; i
< 2; ++i
)
3412 * 1. skip to start of identifier/string
3418 while (ptr
[col
] != NUL
)
3420 # if defined(FEAT_BEVAL)
3421 /* Stop at a ']' to evaluate "a[x]". */
3422 if ((find_type
& FIND_EVAL
) && ptr
[col
] == ']')
3425 this_class
= mb_get_class(ptr
+ col
);
3426 if (this_class
!= 0 && (i
== 1 || this_class
!= 1))
3428 col
+= (*mb_ptr2len
)(ptr
+ col
);
3433 while (ptr
[col
] != NUL
3434 && (i
== 0 ? !vim_iswordc(ptr
[col
]) : vim_iswhite(ptr
[col
]))
3435 # if defined(FEAT_BEVAL)
3436 && (!(find_type
& FIND_EVAL
) || ptr
[col
] != ']')
3441 #if defined(FEAT_BEVAL)
3442 /* When starting on a ']' count it, so that we include the '['. */
3443 bn
= ptr
[col
] == ']';
3447 * 2. Back up to start of identifier/string.
3452 /* Remember class of character under cursor. */
3453 # if defined(FEAT_BEVAL)
3454 if ((find_type
& FIND_EVAL
) && ptr
[col
] == ']')
3455 this_class
= mb_get_class((char_u
*)"a");
3458 this_class
= mb_get_class(ptr
+ col
);
3459 while (col
> 0 && this_class
!= 0)
3461 prevcol
= col
- 1 - (*mb_head_off
)(ptr
, ptr
+ col
- 1);
3462 prev_class
= mb_get_class(ptr
+ prevcol
);
3463 if (this_class
!= prev_class
3466 || (find_type
& FIND_IDENT
))
3467 # if defined(FEAT_BEVAL)
3468 && (!(find_type
& FIND_EVAL
)
3470 || !find_is_eval_item(ptr
+ prevcol
, &prevcol
,
3478 /* If we don't want just any old string, or we've found an
3479 * identifier, stop searching. */
3482 if (!(find_type
& FIND_STRING
) || this_class
== 2)
3490 ? vim_iswordc(ptr
[col
- 1])
3491 : (!vim_iswhite(ptr
[col
- 1])
3492 && (!(find_type
& FIND_IDENT
)
3493 || !vim_iswordc(ptr
[col
- 1]))))
3494 #if defined(FEAT_BEVAL)
3495 || ((find_type
& FIND_EVAL
)
3497 && find_is_eval_item(ptr
+ col
- 1, &col
,
3503 /* If we don't want just any old string, or we've found an
3504 * identifier, stop searching. */
3505 if (!(find_type
& FIND_STRING
) || vim_iswordc(ptr
[col
]))
3510 if (ptr
[col
] == NUL
|| (i
== 0 && (
3512 has_mbyte
? this_class
!= 2 :
3514 !vim_iswordc(ptr
[col
]))))
3517 * didn't find an identifier or string
3519 if (find_type
& FIND_STRING
)
3520 EMSG(_("E348: No string under cursor"));
3529 * 3. Find the end if the identifier/string.
3531 #if defined(FEAT_BEVAL)
3539 /* Search for point of changing multibyte character class. */
3540 this_class
= mb_get_class(ptr
);
3541 while (ptr
[col
] != NUL
3542 && ((i
== 0 ? mb_get_class(ptr
+ col
) == this_class
3543 : mb_get_class(ptr
+ col
) != 0)
3544 # if defined(FEAT_BEVAL)
3545 || ((find_type
& FIND_EVAL
)
3546 && col
<= (int)startcol
3547 && find_is_eval_item(ptr
+ col
, &col
, &bn
, FORWARD
))
3550 col
+= (*mb_ptr2len
)(ptr
+ col
);
3554 while ((i
== 0 ? vim_iswordc(ptr
[col
])
3555 : (ptr
[col
] != NUL
&& !vim_iswhite(ptr
[col
])))
3556 # if defined(FEAT_BEVAL)
3557 || ((find_type
& FIND_EVAL
)
3558 && col
<= (int)startcol
3559 && find_is_eval_item(ptr
+ col
, &col
, &bn
, FORWARD
))
3570 * Prepare for redo of a normal command.
3576 prep_redo(cap
->oap
->regname
, cap
->count0
,
3577 NUL
, cap
->cmdchar
, NUL
, NUL
, cap
->nchar
);
3581 * Prepare for redo of any command.
3582 * Note that only the last argument can be a multi-byte char.
3585 prep_redo(regname
, num
, cmd1
, cmd2
, cmd3
, cmd4
, cmd5
)
3595 if (regname
!= 0) /* yank from specified buffer */
3597 AppendCharToRedobuff('"');
3598 AppendCharToRedobuff(regname
);
3601 AppendNumberToRedobuff(num
);
3604 AppendCharToRedobuff(cmd1
);
3606 AppendCharToRedobuff(cmd2
);
3608 AppendCharToRedobuff(cmd3
);
3610 AppendCharToRedobuff(cmd4
);
3612 AppendCharToRedobuff(cmd5
);
3616 * check for operator active and clear it
3618 * return TRUE if operator was active
3624 if (oap
->op_type
== OP_NOP
)
3631 * Check for operator or Visual active. Clear active operator.
3633 * Return TRUE if operator or Visual was active.
3639 if (oap
->op_type
== OP_NOP
3653 oap
->op_type
= OP_NOP
;
3655 oap
->motion_force
= NUL
;
3656 oap
->use_reg_one
= FALSE
;
3669 * Remove the shift modifier from a special key.
3672 unshift_special(cap
)
3675 switch (cap
->cmdchar
)
3677 case K_S_RIGHT
: cap
->cmdchar
= K_RIGHT
; break;
3678 case K_S_LEFT
: cap
->cmdchar
= K_LEFT
; break;
3679 case K_S_UP
: cap
->cmdchar
= K_UP
; break;
3680 case K_S_DOWN
: cap
->cmdchar
= K_DOWN
; break;
3681 case K_S_HOME
: cap
->cmdchar
= K_HOME
; break;
3682 case K_S_END
: cap
->cmdchar
= K_END
; break;
3684 cap
->cmdchar
= simplify_key(cap
->cmdchar
, &mod_mask
);
3688 #if defined(FEAT_CMDL_INFO) || defined(PROTO)
3690 * Routines for displaying a partly typed command
3693 #ifdef FEAT_VISUAL /* need room for size of Visual area */
3694 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30
3696 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1
3698 static char_u showcmd_buf
[SHOWCMD_BUFLEN
];
3699 static char_u old_showcmd_buf
[SHOWCMD_BUFLEN
]; /* For push_showcmd() */
3700 static int showcmd_is_clear
= TRUE
;
3701 static int showcmd_visual
= FALSE
;
3703 static void display_showcmd
__ARGS((void));
3712 if (VIsual_active
&& !char_avail())
3714 int i
= lt(VIsual
, curwin
->w_cursor
);
3716 colnr_T leftcol
, rightcol
;
3719 /* Show the size of the Visual area. */
3723 bot
= curwin
->w_cursor
.lnum
;
3727 top
= curwin
->w_cursor
.lnum
;
3730 # ifdef FEAT_FOLDING
3731 /* Include closed folds as a whole. */
3732 hasFolding(top
, &top
, NULL
);
3733 hasFolding(bot
, NULL
, &bot
);
3735 lines
= bot
- top
+ 1;
3737 if (VIsual_mode
== Ctrl_V
)
3739 getvcols(curwin
, &curwin
->w_cursor
, &VIsual
, &leftcol
, &rightcol
);
3740 sprintf((char *)showcmd_buf
, "%ldx%ld", lines
,
3741 (long)(rightcol
- leftcol
+ 1));
3743 else if (VIsual_mode
== 'V' || VIsual
.lnum
!= curwin
->w_cursor
.lnum
)
3744 sprintf((char *)showcmd_buf
, "%ld", lines
);
3746 sprintf((char *)showcmd_buf
, "%ld", (long)(i
3747 ? curwin
->w_cursor
.col
- VIsual
.col
3748 : VIsual
.col
- curwin
->w_cursor
.col
) + (*p_sel
!= 'e'));
3749 showcmd_buf
[SHOWCMD_COLS
] = NUL
; /* truncate */
3750 showcmd_visual
= TRUE
;
3755 showcmd_buf
[0] = NUL
;
3756 showcmd_visual
= FALSE
;
3758 /* Don't actually display something if there is nothing to clear. */
3759 if (showcmd_is_clear
)
3767 * Add 'c' to string of shown command chars.
3768 * Return TRUE if output has been written (and setcursor() has been called).
3778 #if defined(FEAT_MOUSE)
3780 static int ignore
[] =
3783 K_VER_SCROLLBAR
, K_HOR_SCROLLBAR
,
3784 K_LEFTMOUSE_NM
, K_LEFTRELEASE_NM
,
3787 K_LEFTMOUSE
, K_LEFTDRAG
, K_LEFTRELEASE
,
3788 K_MIDDLEMOUSE
, K_MIDDLEDRAG
, K_MIDDLERELEASE
,
3789 K_RIGHTMOUSE
, K_RIGHTDRAG
, K_RIGHTRELEASE
,
3790 K_MOUSEDOWN
, K_MOUSEUP
,
3791 K_X1MOUSE
, K_X1DRAG
, K_X1RELEASE
, K_X2MOUSE
, K_X2DRAG
, K_X2RELEASE
,
3797 if (!p_sc
|| msg_silent
!= 0)
3802 showcmd_buf
[0] = NUL
;
3803 showcmd_visual
= FALSE
;
3806 #if defined(FEAT_MOUSE)
3807 /* Ignore keys that are scrollbar updates and mouse clicks */
3809 for (i
= 0; ignore
[i
] != 0; ++i
)
3815 old_len
= (int)STRLEN(showcmd_buf
);
3816 extra_len
= (int)STRLEN(p
);
3817 overflow
= old_len
+ extra_len
- SHOWCMD_COLS
;
3819 mch_memmove(showcmd_buf
, showcmd_buf
+ overflow
,
3820 old_len
- overflow
+ 1);
3821 STRCAT(showcmd_buf
, p
);
3835 if (!add_to_showcmd(c
))
3840 * Delete 'len' characters from the end of the shown command.
3843 del_from_showcmd(len
)
3851 old_len
= (int)STRLEN(showcmd_buf
);
3854 showcmd_buf
[old_len
- len
] = NUL
;
3861 * push_showcmd() and pop_showcmd() are used when waiting for the user to type
3862 * something and there is a partial mapping.
3868 STRCPY(old_showcmd_buf
, showcmd_buf
);
3877 STRCPY(showcmd_buf
, old_showcmd_buf
);
3889 len
= (int)STRLEN(showcmd_buf
);
3891 showcmd_is_clear
= TRUE
;
3894 screen_puts(showcmd_buf
, (int)Rows
- 1, sc_col
, 0);
3895 showcmd_is_clear
= FALSE
;
3899 * clear the rest of an old message by outputting up to SHOWCMD_COLS
3902 screen_puts((char_u
*)" " + len
, (int)Rows
- 1, sc_col
+ len
, 0);
3904 setcursor(); /* put cursor back where it belongs */
3908 #ifdef FEAT_SCROLLBIND
3910 * When "check" is FALSE, prepare for commands that scroll the window.
3911 * When "check" is TRUE, take care of scroll-binding after the window has
3912 * scrolled. Called from normal_cmd() and edit().
3915 do_check_scrollbind(check
)
3918 static win_T
*old_curwin
= NULL
;
3919 static linenr_T old_topline
= 0;
3921 static int old_topfill
= 0;
3923 static buf_T
*old_buf
= NULL
;
3924 static colnr_T old_leftcol
= 0;
3926 if (check
&& curwin
->w_p_scb
)
3928 /* If a ":syncbind" command was just used, don't scroll, only reset
3931 did_syncbind
= FALSE
;
3932 else if (curwin
== old_curwin
)
3935 * Synchronize other windows, as necessary according to
3936 * 'scrollbind'. Don't do this after an ":edit" command, except
3937 * when 'diff' is set.
3939 if ((curwin
->w_buffer
== old_buf
3944 && (curwin
->w_topline
!= old_topline
3946 || curwin
->w_topfill
!= old_topfill
3948 || curwin
->w_leftcol
!= old_leftcol
))
3950 check_scrollbind(curwin
->w_topline
- old_topline
,
3951 (long)(curwin
->w_leftcol
- old_leftcol
));
3954 else if (vim_strchr(p_sbo
, 'j')) /* jump flag set in 'scrollopt' */
3957 * When switching between windows, make sure that the relative
3958 * vertical offset is valid for the new window. The relative
3959 * offset is invalid whenever another 'scrollbind' window has
3960 * scrolled to a point that would force the current window to
3961 * scroll past the beginning or end of its buffer. When the
3962 * resync is performed, some of the other 'scrollbind' windows may
3963 * need to jump so that the current window's relative position is
3964 * visible on-screen.
3966 check_scrollbind(curwin
->w_topline
- curwin
->w_scbind_pos
, 0L);
3968 curwin
->w_scbind_pos
= curwin
->w_topline
;
3971 old_curwin
= curwin
;
3972 old_topline
= curwin
->w_topline
;
3974 old_topfill
= curwin
->w_topfill
;
3976 old_buf
= curwin
->w_buffer
;
3977 old_leftcol
= curwin
->w_leftcol
;
3981 * Synchronize any windows that have "scrollbind" set, based on the
3982 * number of rows by which the current window has changed
3983 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
3986 check_scrollbind(topline_diff
, leftcol_diff
)
3987 linenr_T topline_diff
;
3992 win_T
*old_curwin
= curwin
;
3993 buf_T
*old_curbuf
= curbuf
;
3995 int old_VIsual_select
= VIsual_select
;
3996 int old_VIsual_active
= VIsual_active
;
3998 colnr_T tgt_leftcol
= curwin
->w_leftcol
;
4003 * check 'scrollopt' string for vertical and horizontal scroll options
4005 want_ver
= (vim_strchr(p_sbo
, 'v') && topline_diff
!= 0);
4007 want_ver
|= old_curwin
->w_p_diff
;
4009 want_hor
= (vim_strchr(p_sbo
, 'h') && (leftcol_diff
|| topline_diff
!= 0));
4012 * loop through the scrollbound windows and scroll accordingly
4015 VIsual_select
= VIsual_active
= 0;
4017 for (curwin
= firstwin
; curwin
; curwin
= curwin
->w_next
)
4019 curbuf
= curwin
->w_buffer
;
4020 /* skip original window and windows with 'noscrollbind' */
4021 if (curwin
!= old_curwin
&& curwin
->w_p_scb
)
4024 * do the vertical scroll
4029 if (old_curwin
->w_p_diff
&& curwin
->w_p_diff
)
4031 diff_set_topline(old_curwin
, curwin
);
4036 curwin
->w_scbind_pos
+= topline_diff
;
4037 topline
= curwin
->w_scbind_pos
;
4038 if (topline
> curbuf
->b_ml
.ml_line_count
)
4039 topline
= curbuf
->b_ml
.ml_line_count
;
4043 y
= topline
- curwin
->w_topline
;
4047 scrolldown(-y
, FALSE
);
4050 redraw_later(VALID
);
4053 curwin
->w_redr_status
= TRUE
;
4058 * do the horizontal scroll
4060 if (want_hor
&& curwin
->w_leftcol
!= tgt_leftcol
)
4062 curwin
->w_leftcol
= tgt_leftcol
;
4069 * reset current-window
4072 VIsual_select
= old_VIsual_select
;
4073 VIsual_active
= old_VIsual_active
;
4075 curwin
= old_curwin
;
4076 curbuf
= old_curbuf
;
4078 #endif /* #ifdef FEAT_SCROLLBIND */
4081 * Command character that's ignored.
4082 * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use
4089 cap
->retval
|= CA_COMMAND_BUSY
; /* don't call edit() now */
4093 * Command character that doesn't do anything, but unlike nv_ignore() does
4094 * start edit(). Used for "startinsert" executed while starting up.
4104 * Command character doesn't exist.
4110 clearopbeep(cap
->oap
);
4114 * <Help> and <F1> commands.
4120 if (!checkclearopq(cap
->oap
))
4125 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor.
4131 if (!checkclearopq(cap
->oap
)
4132 && do_addsub((int)cap
->cmdchar
, cap
->count1
) == OK
)
4137 * CTRL-F, CTRL-B, etc: Scroll page up or down.
4143 if (!checkclearop(cap
->oap
))
4146 if (mod_mask
& MOD_MASK_CTRL
)
4148 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */
4149 if (cap
->arg
== BACKWARD
)
4150 goto_tabpage(-(int)cap
->count1
);
4152 goto_tabpage((int)cap
->count0
);
4156 (void)onepage(cap
->arg
, cap
->count1
);
4161 * Implementation of "gd" and "gD" command.
4164 nv_gd(oap
, nchar
, thisblock
)
4167 int thisblock
; /* 1 for "1gd" and "1gD" */
4172 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0
4173 || find_decl(ptr
, len
, nchar
== 'd', thisblock
, 0) == FAIL
)
4176 else if ((fdo_flags
& FDO_SEARCH
) && KeyTyped
&& oap
->op_type
== OP_NOP
)
4182 * Search for variable declaration of "ptr[len]".
4183 * When "locally" is TRUE in the current function ("gd"), otherwise in the
4184 * current file ("gD").
4185 * When "thisblock" is TRUE check the {} block scope.
4186 * Return FAIL when not found.
4189 find_decl(ptr
, len
, locally
, thisblock
, searchflags
)
4194 int searchflags
; /* flags passed to searchit() */
4206 if ((pat
= alloc(len
+ 7)) == NULL
)
4209 /* Put "\V" before the pattern to avoid that the special meaning of "."
4210 * and "~" causes trouble. */
4211 sprintf((char *)pat
, vim_iswordp(ptr
) ? "\\V\\<%.*s\\>" : "\\V%.*s",
4213 old_pos
= curwin
->w_cursor
;
4216 p_ws
= FALSE
; /* don't wrap around end of file now */
4217 p_scs
= FALSE
; /* don't switch ignorecase off now */
4220 * With "gD" go to line 1.
4221 * With "gd" Search back for the start of the current function, then go
4222 * back until a blank line. If this fails go to line 1.
4224 if (!locally
|| !findpar(&incll
, BACKWARD
, 1L, '{', FALSE
))
4226 setpcmark(); /* Set in findpar() otherwise */
4227 curwin
->w_cursor
.lnum
= 1;
4228 par_pos
= curwin
->w_cursor
;
4232 par_pos
= curwin
->w_cursor
;
4233 while (curwin
->w_cursor
.lnum
> 1 && *skipwhite(ml_get_curline()) != NUL
)
4234 --curwin
->w_cursor
.lnum
;
4236 curwin
->w_cursor
.col
= 0;
4238 /* Search forward for the identifier, ignore comment lines. */
4239 clearpos(&found_pos
);
4242 t
= searchit(curwin
, curbuf
, &curwin
->w_cursor
, FORWARD
,
4243 pat
, 1L, searchflags
, RE_LAST
, (linenr_T
)0, NULL
);
4244 if (curwin
->w_cursor
.lnum
>= old_pos
.lnum
)
4245 t
= FAIL
; /* match after start is failure too */
4247 if (thisblock
&& t
!= FAIL
)
4251 /* Check that the block the match is in doesn't end before the
4252 * position where we started the search from. */
4253 if ((pos
= findmatchlimit(NULL
, '}', FM_FORWARD
,
4254 (int)(old_pos
.lnum
- curwin
->w_cursor
.lnum
+ 1))) != NULL
4255 && pos
->lnum
< old_pos
.lnum
)
4261 /* If we previously found a valid position, use it. */
4262 if (found_pos
.lnum
!= 0)
4264 curwin
->w_cursor
= found_pos
;
4269 #ifdef FEAT_COMMENTS
4270 if (get_leader_len(ml_get_curline(), NULL
, FALSE
) > 0)
4272 /* Ignore this line, continue at start of next line. */
4273 ++curwin
->w_cursor
.lnum
;
4274 curwin
->w_cursor
.col
= 0;
4278 if (!locally
) /* global search: use first match found */
4280 if (curwin
->w_cursor
.lnum
>= par_pos
.lnum
)
4282 /* If we previously found a valid position, use it. */
4283 if (found_pos
.lnum
!= 0)
4284 curwin
->w_cursor
= found_pos
;
4288 /* For finding a local variable and the match is before the "{" search
4289 * to find a later match. For K&R style function declarations this
4290 * skips the function header without types. */
4291 found_pos
= curwin
->w_cursor
;
4297 curwin
->w_cursor
= old_pos
;
4301 curwin
->w_set_curswant
= TRUE
;
4302 /* "n" searches forward now */
4314 * Move 'dist' lines in direction 'dir', counting lines by *screen*
4315 * lines rather than lines in the file.
4316 * 'dist' must be positive.
4318 * Return OK if able to move cursor, FAIL otherwise.
4321 nv_screengo(oap
, dir
, dist
)
4326 int linelen
= linetabsize(ml_get_curline());
4330 int col_off1
; /* margin offset for first screen line */
4331 int col_off2
; /* margin offset for wrapped screen line */
4332 int width1
; /* text width for first screen line */
4333 int width2
; /* test width for wrapped screen line */
4335 oap
->motion_type
= MCHAR
;
4336 oap
->inclusive
= FALSE
;
4338 col_off1
= curwin_col_off();
4339 col_off2
= col_off1
- curwin_col_off2();
4340 width1
= W_WIDTH(curwin
) - col_off1
;
4341 width2
= W_WIDTH(curwin
) - col_off2
;
4343 #ifdef FEAT_VERTSPLIT
4344 if (curwin
->w_width
!= 0)
4348 * Instead of sticking at the last character of the buffer line we
4349 * try to stick in the last column of the screen.
4351 if (curwin
->w_curswant
== MAXCOL
)
4356 curwin
->w_curswant
= 0;
4359 curwin
->w_curswant
= width1
- 1;
4360 if (curwin
->w_virtcol
> curwin
->w_curswant
)
4361 curwin
->w_curswant
+= ((curwin
->w_virtcol
4362 - curwin
->w_curswant
- 1) / width2
+ 1) * width2
;
4367 if (linelen
> width1
)
4368 n
= ((linelen
- width1
- 1) / width2
+ 1) * width2
+ width1
;
4371 if (curwin
->w_curswant
> (colnr_T
)n
+ 1)
4372 curwin
->w_curswant
-= ((curwin
->w_curswant
- n
) / width2
+ 1)
4378 if (dir
== BACKWARD
)
4380 if ((long)curwin
->w_curswant
>= width2
)
4381 /* move back within line */
4382 curwin
->w_curswant
-= width2
;
4385 /* to previous line */
4386 if (curwin
->w_cursor
.lnum
== 1)
4391 --curwin
->w_cursor
.lnum
;
4393 /* Move to the start of a closed fold. Don't do that when
4394 * 'foldopen' contains "all": it will open in a moment. */
4395 if (!(fdo_flags
& FDO_ALL
))
4396 (void)hasFolding(curwin
->w_cursor
.lnum
,
4397 &curwin
->w_cursor
.lnum
, NULL
);
4399 linelen
= linetabsize(ml_get_curline());
4400 if (linelen
> width1
)
4401 curwin
->w_curswant
+= (((linelen
- width1
- 1) / width2
)
4405 else /* dir == FORWARD */
4407 if (linelen
> width1
)
4408 n
= ((linelen
- width1
- 1) / width2
+ 1) * width2
+ width1
;
4411 if (curwin
->w_curswant
+ width2
< (colnr_T
)n
)
4412 /* move forward within line */
4413 curwin
->w_curswant
+= width2
;
4418 /* Move to the end of a closed fold. */
4419 (void)hasFolding(curwin
->w_cursor
.lnum
, NULL
,
4420 &curwin
->w_cursor
.lnum
);
4422 if (curwin
->w_cursor
.lnum
== curbuf
->b_ml
.ml_line_count
)
4427 curwin
->w_cursor
.lnum
++;
4428 curwin
->w_curswant
%= width2
;
4432 #ifdef FEAT_VERTSPLIT
4436 coladvance(curwin
->w_curswant
);
4438 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
4439 if (curwin
->w_cursor
.col
> 0 && curwin
->w_p_wrap
)
4442 * Check for landing on a character that got split at the end of the
4443 * last line. We want to advance a screenline, not end up in the same
4444 * screenline or move two screenlines.
4447 if (curwin
->w_virtcol
> curwin
->w_curswant
4448 && (curwin
->w_curswant
< (colnr_T
)width1
4449 ? (curwin
->w_curswant
> (colnr_T
)width1
/ 2)
4450 : ((curwin
->w_curswant
- width1
) % width2
4451 > (colnr_T
)width2
/ 2)))
4452 --curwin
->w_cursor
.col
;
4457 curwin
->w_curswant
= MAXCOL
; /* stick in the last column */
4464 * Mouse scroll wheel: Default action is to scroll three lines, or one page
4465 * when Shift or Ctrl is used.
4466 * K_MOUSEUP (cap->arg == TRUE) or K_MOUSEDOWN (cap->arg == FALSE)
4472 # ifdef FEAT_GUI_SCROLL_WHEEL_FORCE
4473 int scroll_wheel_force
= 0;
4475 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
4476 win_T
*old_curwin
= curwin
;
4478 /* Currently we only get the mouse coordinates in the GUI. */
4479 if (gui
.in_use
&& mouse_row
>= 0 && mouse_col
>= 0)
4486 /* find the window at the pointer coordinates */
4487 curwin
= mouse_find_win(&row
, &col
);
4488 curbuf
= curwin
->w_buffer
;
4492 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
4494 (void)onepage(cap
->arg
? FORWARD
: BACKWARD
, 1L);
4498 # ifdef FEAT_GUI_SCROLL_WHEEL_FORCE
4499 if (gui
.in_use
&& gui
.scroll_wheel_force
>= 1) {
4500 scroll_wheel_force
= gui
.scroll_wheel_force
;
4501 if (scroll_wheel_force
> 1000)
4502 scroll_wheel_force
= 1000;
4504 cap
->count1
= scroll_wheel_force
;
4505 cap
->count0
= scroll_wheel_force
;
4514 nv_scroll_line(cap
);
4517 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
4518 curwin
->w_redr_status
= TRUE
;
4520 curwin
= old_curwin
;
4521 curbuf
= curwin
->w_buffer
;
4526 * Mouse clicks and drags.
4532 (void)do_mouse(cap
->oap
, cap
->cmdchar
, BACKWARD
, cap
->count1
, 0);
4537 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down.
4538 * cap->arg must be TRUE for CTRL-E.
4544 if (!checkclearop(cap
->oap
))
4545 scroll_redraw(cap
->arg
, cap
->count1
);
4549 * Scroll "count" lines up or down, and redraw.
4552 scroll_redraw(up
, count
)
4556 linenr_T prev_topline
= curwin
->w_topline
;
4558 int prev_topfill
= curwin
->w_topfill
;
4560 linenr_T prev_lnum
= curwin
->w_cursor
.lnum
;
4563 scrollup(count
, TRUE
);
4565 scrolldown(count
, TRUE
);
4568 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as
4569 * valid, otherwise the screen jumps back at the end of the file. */
4571 check_cursor_moved(curwin
);
4572 curwin
->w_valid
|= VALID_TOPLINE
;
4574 /* If moved back to where we were, at least move the cursor, otherwise
4575 * we get stuck at one position. Don't move the cursor up if the
4576 * first line of the buffer is already on the screen */
4577 while (curwin
->w_topline
== prev_topline
4579 && curwin
->w_topfill
== prev_topfill
4585 if (curwin
->w_cursor
.lnum
> prev_lnum
4586 || cursor_down(1L, FALSE
) == FAIL
)
4591 if (curwin
->w_cursor
.lnum
< prev_lnum
4592 || prev_topline
== 1L
4593 || cursor_up(1L, FALSE
) == FAIL
)
4596 /* Mark w_topline as valid, otherwise the screen jumps back at the
4597 * end of the file. */
4598 check_cursor_moved(curwin
);
4599 curwin
->w_valid
|= VALID_TOPLINE
;
4602 if (curwin
->w_cursor
.lnum
!= prev_lnum
)
4603 coladvance(curwin
->w_curswant
);
4604 redraw_later(VALID
);
4608 * Commands that start with "z".
4616 int nchar
= cap
->nchar
;
4618 long old_fdl
= curwin
->w_p_fdl
;
4619 int old_fen
= curwin
->w_p_fen
;
4625 if (VIM_ISDIGIT(nchar
))
4628 * "z123{nchar}": edit the count before obtaining {nchar}
4630 if (checkclearop(cap
->oap
))
4635 #ifdef USE_ON_FLY_SCROLL
4636 dont_scroll
= TRUE
; /* disallow scrolling here */
4639 ++allow_keys
; /* no mapping for nchar, but allow key codes */
4640 nchar
= plain_vgetc();
4641 LANGMAP_ADJUST(nchar
, TRUE
);
4644 #ifdef FEAT_CMDL_INFO
4645 (void)add_to_showcmd(nchar
);
4647 if (nchar
== K_DEL
|| nchar
== K_KDEL
)
4649 else if (VIM_ISDIGIT(nchar
))
4650 n
= n
* 10 + (nchar
- '0');
4651 else if (nchar
== CAR
)
4654 need_mouse_correct
= TRUE
;
4656 win_setheight((int)n
);
4659 else if (nchar
== 'l'
4662 || nchar
== K_RIGHT
)
4664 cap
->count1
= n
? n
* cap
->count1
: cap
->count1
;
4669 clearopbeep(cap
->oap
);
4673 cap
->oap
->op_type
= OP_NOP
;
4680 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc"
4681 * and "zC" only in Visual mode. "zj" and "zk" are motion
4683 cap
->nchar
!= 'f' && cap
->nchar
!= 'F'
4684 && !(VIsual_active
&& vim_strchr((char_u
*)"dcCoO", cap
->nchar
))
4685 && cap
->nchar
!= 'j' && cap
->nchar
!= 'k'
4688 checkclearop(cap
->oap
))
4692 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb":
4693 * If line number given, set cursor.
4695 if ((vim_strchr((char_u
*)"+\r\nt.z^-b", nchar
) != NULL
)
4697 && cap
->count0
!= curwin
->w_cursor
.lnum
)
4700 if (cap
->count0
> curbuf
->b_ml
.ml_line_count
)
4701 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
4703 curwin
->w_cursor
.lnum
= cap
->count0
;
4709 /* "z+", "z<CR>" and "zt": put cursor at top of screen */
4711 if (cap
->count0
== 0)
4713 /* No count given: put cursor at the line below screen */
4714 validate_botline(); /* make sure w_botline is valid */
4715 if (curwin
->w_botline
> curbuf
->b_ml
.ml_line_count
)
4716 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
4718 curwin
->w_cursor
.lnum
= curwin
->w_botline
;
4724 beginline(BL_WHITE
| BL_FIX
);
4727 case 't': scroll_cursor_top(0, TRUE
);
4728 redraw_later(VALID
);
4731 /* "z." and "zz": put cursor in middle of screen */
4732 case '.': beginline(BL_WHITE
| BL_FIX
);
4735 case 'z': scroll_cursor_halfway(TRUE
);
4736 redraw_later(VALID
);
4739 /* "z^", "z-" and "zb": put cursor at bottom of screen */
4740 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window
4741 * when <count> is at bottom of window, and puts that one at
4742 * bottom of window. */
4743 if (cap
->count0
!= 0)
4745 scroll_cursor_bot(0, TRUE
);
4746 curwin
->w_cursor
.lnum
= curwin
->w_topline
;
4748 else if (curwin
->w_topline
== 1)
4749 curwin
->w_cursor
.lnum
= 1;
4751 curwin
->w_cursor
.lnum
= curwin
->w_topline
- 1;
4754 beginline(BL_WHITE
| BL_FIX
);
4757 case 'b': scroll_cursor_bot(0, TRUE
);
4758 redraw_later(VALID
);
4761 /* "zH" - scroll screen right half-page */
4763 cap
->count1
*= W_WIDTH(curwin
) / 2;
4766 /* "zh" - scroll screen to the right */
4769 if (!curwin
->w_p_wrap
)
4771 if ((colnr_T
)cap
->count1
> curwin
->w_leftcol
)
4772 curwin
->w_leftcol
= 0;
4774 curwin
->w_leftcol
-= (colnr_T
)cap
->count1
;
4779 /* "zL" - scroll screen left half-page */
4780 case 'L': cap
->count1
*= W_WIDTH(curwin
) / 2;
4783 /* "zl" - scroll screen to the left */
4786 if (!curwin
->w_p_wrap
)
4788 /* scroll the window left */
4789 curwin
->w_leftcol
+= (colnr_T
)cap
->count1
;
4794 /* "zs" - scroll screen, cursor at the start */
4795 case 's': if (!curwin
->w_p_wrap
)
4798 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4799 col
= 0; /* like the cursor is in col 0 */
4802 getvcol(curwin
, &curwin
->w_cursor
, &col
, NULL
, NULL
);
4803 if ((long)col
> p_siso
)
4807 if (curwin
->w_leftcol
!= col
)
4809 curwin
->w_leftcol
= col
;
4810 redraw_later(NOT_VALID
);
4815 /* "ze" - scroll screen, cursor at the end */
4816 case 'e': if (!curwin
->w_p_wrap
)
4819 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4820 col
= 0; /* like the cursor is in col 0 */
4823 getvcol(curwin
, &curwin
->w_cursor
, NULL
, NULL
, &col
);
4824 n
= W_WIDTH(curwin
) - curwin_col_off();
4825 if ((long)col
+ p_siso
< n
)
4828 col
= col
+ p_siso
- n
+ 1;
4829 if (curwin
->w_leftcol
!= col
)
4831 curwin
->w_leftcol
= col
;
4832 redraw_later(NOT_VALID
);
4838 /* "zF": create fold command */
4839 /* "zf": create fold operator */
4841 case 'f': if (foldManualAllowed(TRUE
))
4845 curwin
->w_p_fen
= TRUE
;
4847 /* "zF" is like "zfzf" */
4848 if (nchar
== 'F' && cap
->oap
->op_type
== OP_FOLD
)
4855 clearopbeep(cap
->oap
);
4858 /* "zd": delete fold at cursor */
4859 /* "zD": delete fold at cursor recursively */
4861 case 'D': if (foldManualAllowed(FALSE
))
4866 deleteFold(curwin
->w_cursor
.lnum
,
4867 curwin
->w_cursor
.lnum
, nchar
== 'D', FALSE
);
4871 /* "zE": erease all folds */
4872 case 'E': if (foldmethodIsManual(curwin
))
4874 clearFolding(curwin
);
4875 changed_window_setting();
4877 else if (foldmethodIsMarker(curwin
))
4878 deleteFold((linenr_T
)1, curbuf
->b_ml
.ml_line_count
,
4881 EMSG(_("E352: Cannot erase folds with current 'foldmethod'"));
4884 /* "zn": fold none: reset 'foldenable' */
4885 case 'n': curwin
->w_p_fen
= FALSE
;
4888 /* "zN": fold Normal: set 'foldenable' */
4889 case 'N': curwin
->w_p_fen
= TRUE
;
4892 /* "zi": invert folding: toggle 'foldenable' */
4893 case 'i': curwin
->w_p_fen
= !curwin
->w_p_fen
;
4896 /* "za": open closed fold or close open fold at cursor */
4897 case 'a': if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4898 openFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4901 closeFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4902 curwin
->w_p_fen
= TRUE
;
4906 /* "zA": open fold at cursor recursively */
4907 case 'A': if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4908 openFoldRecurse(curwin
->w_cursor
.lnum
);
4911 closeFoldRecurse(curwin
->w_cursor
.lnum
);
4912 curwin
->w_p_fen
= TRUE
;
4916 /* "zo": open fold at cursor or Visual area */
4917 case 'o': if (VIsual_active
)
4920 openFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4923 /* "zO": open fold recursively */
4924 case 'O': if (VIsual_active
)
4927 openFoldRecurse(curwin
->w_cursor
.lnum
);
4930 /* "zc": close fold at cursor or Visual area */
4931 case 'c': if (VIsual_active
)
4934 closeFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4935 curwin
->w_p_fen
= TRUE
;
4938 /* "zC": close fold recursively */
4939 case 'C': if (VIsual_active
)
4942 closeFoldRecurse(curwin
->w_cursor
.lnum
);
4943 curwin
->w_p_fen
= TRUE
;
4946 /* "zv": open folds at the cursor */
4947 case 'v': foldOpenCursor();
4950 /* "zx": re-apply 'foldlevel' and open folds at the cursor */
4951 case 'x': curwin
->w_p_fen
= TRUE
;
4952 newFoldLevel(); /* update right now */
4956 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */
4957 case 'X': curwin
->w_p_fen
= TRUE
;
4958 old_fdl
= -1; /* force an update */
4961 /* "zm": fold more */
4962 case 'm': if (curwin
->w_p_fdl
> 0)
4964 old_fdl
= -1; /* force an update */
4965 curwin
->w_p_fen
= TRUE
;
4968 /* "zM": close all folds */
4969 case 'M': curwin
->w_p_fdl
= 0;
4970 old_fdl
= -1; /* force an update */
4971 curwin
->w_p_fen
= TRUE
;
4974 /* "zr": reduce folding */
4975 case 'r': ++curwin
->w_p_fdl
;
4978 /* "zR": open all folds */
4979 case 'R': curwin
->w_p_fdl
= getDeepestNesting();
4980 old_fdl
= -1; /* force an update */
4983 case 'j': /* "zj" move to next fold downwards */
4984 case 'k': /* "zk" move to next fold upwards */
4985 if (foldMoveTo(TRUE
, nchar
== 'j' ? FORWARD
: BACKWARD
,
4986 cap
->count1
) == FAIL
)
4987 clearopbeep(cap
->oap
);
4990 #endif /* FEAT_FOLDING */
4993 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */
4995 ++allow_keys
; /* no mapping for nchar, but allow key codes */
4996 nchar
= plain_vgetc();
4997 LANGMAP_ADJUST(nchar
, TRUE
);
5000 #ifdef FEAT_CMDL_INFO
5001 (void)add_to_showcmd(nchar
);
5003 if (vim_strchr((char_u
*)"gGwW", nchar
) == NULL
)
5005 clearopbeep(cap
->oap
);
5011 case 'g': /* "zg": add good word to word list */
5012 case 'w': /* "zw": add wrong word to word list */
5013 case 'G': /* "zG": add good word to temp word list */
5014 case 'W': /* "zW": add wrong word to temp word list */
5019 if (checkclearop(cap
->oap
))
5022 if (VIsual_active
&& get_visual_text(cap
, &ptr
, &len
)
5028 pos_T pos
= curwin
->w_cursor
;
5030 /* Find bad word under the cursor. */
5031 len
= spell_move_to(curwin
, FORWARD
, TRUE
, TRUE
, NULL
);
5032 if (len
!= 0 && curwin
->w_cursor
.col
<= pos
.col
)
5033 ptr
= ml_get_pos(&curwin
->w_cursor
);
5034 curwin
->w_cursor
= pos
;
5037 if (ptr
== NULL
&& (len
= find_ident_under_cursor(&ptr
,
5040 spell_add_word(ptr
, len
, nchar
== 'w' || nchar
== 'W',
5041 (nchar
== 'G' || nchar
== 'W')
5042 ? 0 : (int)cap
->count1
,
5047 case '=': /* "z=": suggestions for a badly spelled word */
5048 if (!checkclearop(cap
->oap
))
5049 spell_suggest((int)cap
->count0
);
5053 default: clearopbeep(cap
->oap
);
5057 /* Redraw when 'foldenable' changed */
5058 if (old_fen
!= curwin
->w_p_fen
)
5063 if (foldmethodIsDiff(curwin
) && curwin
->w_p_scb
)
5065 /* Adjust 'foldenable' in diff-synced windows. */
5068 if (wp
!= curwin
&& foldmethodIsDiff(wp
) && wp
->w_p_scb
)
5070 wp
->w_p_fen
= curwin
->w_p_fen
;
5071 changed_window_setting_win(wp
);
5076 changed_window_setting();
5079 /* Redraw when 'foldlevel' changed. */
5080 if (old_fdl
!= curwin
->w_p_fdl
)
5087 * Vertical scrollbar movement.
5090 nv_ver_scrollbar(cap
)
5093 if (cap
->oap
->op_type
!= OP_NOP
)
5094 clearopbeep(cap
->oap
);
5096 /* Even if an operator was pending, we still want to scroll */
5101 * Horizontal scrollbar movement.
5104 nv_hor_scrollbar(cap
)
5107 if (cap
->oap
->op_type
!= OP_NOP
)
5108 clearopbeep(cap
->oap
);
5110 /* Even if an operator was pending, we still want to scroll */
5111 gui_do_horiz_scroll();
5115 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
5123 if (cap
->oap
->op_type
!= OP_NOP
)
5124 clearopbeep(cap
->oap
);
5126 /* Even if an operator was pending, we still want to jump tabs. */
5127 goto_tabpage(current_tab
);
5131 * Selected item in tab line menu.
5137 if (cap
->oap
->op_type
!= OP_NOP
)
5138 clearopbeep(cap
->oap
);
5140 /* Even if an operator was pending, we still want to jump tabs. */
5145 * Handle selecting an item of the GUI tab line menu.
5146 * Used in Normal and Insert mode.
5151 switch (current_tabmenu
)
5153 case TABLINE_MENU_CLOSE
:
5154 if (current_tab
== 0)
5155 #ifdef FEAT_GUI_MACVIM
5156 do_cmdline_cmd((char_u
*)"conf tabclose");
5158 do_cmdline_cmd((char_u
*)"tabclose");
5162 #ifdef FEAT_GUI_MACVIM
5163 vim_snprintf((char *)IObuff
, IOSIZE
, "conf tabclose %d",
5166 vim_snprintf((char *)IObuff
, IOSIZE
, "tabclose %d",
5169 do_cmdline_cmd(IObuff
);
5173 case TABLINE_MENU_NEW
:
5174 vim_snprintf((char *)IObuff
, IOSIZE
, "%dtabnew",
5175 current_tab
> 0 ? current_tab
- 1 : 999);
5176 do_cmdline_cmd(IObuff
);
5179 case TABLINE_MENU_OPEN
:
5180 vim_snprintf((char *)IObuff
, IOSIZE
, "browse %dtabnew",
5181 current_tab
> 0 ? current_tab
- 1 : 999);
5182 do_cmdline_cmd(IObuff
);
5196 * Ignore 'Q' in Visual mode, just give a beep.
5203 if (!checkclearop(cap
->oap
))
5208 * Handle a ":" command.
5222 if (cap
->oap
->op_type
!= OP_NOP
)
5224 /* Using ":" as a movement is characterwise exclusive. */
5225 cap
->oap
->motion_type
= MCHAR
;
5226 cap
->oap
->inclusive
= FALSE
;
5228 else if (cap
->count0
)
5230 /* translate "count:" into ":.,.+(count - 1)" */
5231 stuffcharReadbuff('.');
5232 if (cap
->count0
> 1)
5234 stuffReadbuff((char_u
*)",.+");
5235 stuffnumReadbuff((long)cap
->count0
- 1L);
5239 /* When typing, don't type below an old message */
5245 /* get a command line and execute it */
5246 do_cmdline(NULL
, getexline
, NULL
,
5247 cap
->oap
->op_type
!= OP_NOP
? DOCMD_KEEPLINE
: 0);
5249 /* If 'insertmode' changed, enter or exit Insert mode */
5250 if (p_im
!= old_p_im
)
5258 /* The start of the operator may have become invalid by the Ex
5260 if (cap
->oap
->op_type
!= OP_NOP
5261 && (cap
->oap
->start
.lnum
> curbuf
->b_ml
.ml_line_count
5262 || cap
->oap
->start
.col
>
5263 STRLEN(ml_get(cap
->oap
->start
.lnum
))))
5264 clearopbeep(cap
->oap
);
5269 * Handle CTRL-G command.
5276 if (VIsual_active
) /* toggle Selection/Visual mode */
5278 VIsual_select
= !VIsual_select
;
5283 if (!checkclearop(cap
->oap
))
5284 /* print full name if count given or :cd used */
5285 fileinfo((int)cap
->count0
, FALSE
, TRUE
);
5289 * Handle CTRL-H <Backspace> command.
5296 if (VIsual_active
&& VIsual_select
)
5298 cap
->cmdchar
= 'x'; /* BS key behaves like 'x' in Select mode */
5307 * CTRL-L: clear screen and redraw.
5313 if (!checkclearop(cap
->oap
))
5315 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT
5317 * Right now, the BeBox doesn't seem to have an easy way to detect
5318 * window resizing, so we cheat and make the user detect it
5319 * manually with CTRL-L instead
5324 /* Clear all syntax states to force resyncing. */
5325 syn_stack_free_all(curbuf
);
5327 redraw_later(CLEAR
);
5332 * CTRL-O: In Select mode: switch to Visual mode for one command.
5333 * Otherwise: Go to older pcmark.
5340 if (VIsual_active
&& VIsual_select
)
5342 VIsual_select
= FALSE
;
5344 restart_VIsual_select
= 2; /* restart Select mode later */
5349 cap
->count1
= -cap
->count1
;
5355 * CTRL-^ command, short for ":e #"
5361 if (!checkclearopq(cap
->oap
))
5362 (void)buflist_getfile((int)cap
->count0
, (linenr_T
)0,
5363 GETF_SETMARK
|GETF_ALT
, FALSE
);
5373 if (!checkclearopq(cap
->oap
))
5377 /* "ZZ": equivalent to ":x". */
5378 case 'Z': do_cmdline_cmd((char_u
*)"x");
5381 /* "ZQ": equivalent to ":q!" (Elvis compatible). */
5382 case 'Q': do_cmdline_cmd((char_u
*)"q!");
5385 default: clearopbeep(cap
->oap
);
5390 #if defined(FEAT_WINDOWS) || defined(PROTO)
5392 * Call nv_ident() as if "c1" was used, with "c2" as next character.
5403 vim_memset(&ca
, 0, sizeof(ca
));
5412 * Handle the commands that use the word under the cursor.
5413 * [g] CTRL-] :ta to current identifier
5414 * [g] 'K' run program for current identifier
5415 * [g] '*' / to current identifier or string
5416 * [g] '#' ? to current identifier or string
5417 * g ']' :tselect for current identifier
5426 char_u
*kp
; /* value of 'keywordprg' */
5427 int kp_help
; /* 'keywordprg' is ":help" */
5428 int n
= 0; /* init for GCC */
5430 int g_cmd
; /* "g" command */
5435 if (cap
->cmdchar
== 'g') /* "g*", "g#", "g]" and "gCTRL-]" */
5437 cmdchar
= cap
->nchar
;
5442 cmdchar
= cap
->cmdchar
;
5446 if (cmdchar
== POUND
) /* the pound sign, '#' for English keyboards */
5450 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode.
5452 if (cmdchar
== ']' || cmdchar
== Ctrl_RSB
|| cmdchar
== 'K')
5455 if (VIsual_active
&& get_visual_text(cap
, &ptr
, &n
) == FAIL
)
5458 if (checkclearopq(cap
->oap
))
5462 if (ptr
== NULL
&& (n
= find_ident_under_cursor(&ptr
,
5463 (cmdchar
== '*' || cmdchar
== '#')
5464 ? FIND_IDENT
|FIND_STRING
: FIND_IDENT
)) == 0)
5470 /* Allocate buffer to put the command in. Inserting backslashes can
5471 * double the length of the word. p_kp / curbuf->b_p_kp could be added
5472 * and some numbers. */
5473 kp
= (*curbuf
->b_p_kp
== NUL
? p_kp
: curbuf
->b_p_kp
);
5474 kp_help
= (*kp
== NUL
|| STRCMP(kp
, ":he") == 0
5475 || STRCMP(kp
, ":help") == 0);
5476 buf
= alloc((unsigned)(n
* 2 + 30 + STRLEN(kp
)));
5486 * Put cursor at start of word, makes search skip the word
5488 * Call setpcmark() first, so "*``" puts the cursor back where
5492 curwin
->w_cursor
.col
= (colnr_T
) (ptr
- ml_get_curline());
5494 if (!g_cmd
&& vim_iswordp(ptr
))
5496 no_smartcase
= TRUE
; /* don't use 'smartcase' now */
5501 STRCPY(buf
, "he! ");
5504 /* An external command will probably use an argument starting
5505 * with "-" as an option. To avoid trouble we skip the "-". */
5506 while (*ptr
== '-' && n
> 0)
5513 EMSG(_(e_noident
)); /* found dashes only */
5518 /* When a count is given, turn it into a range. Is this
5519 * really what we want? */
5520 isman
= (STRCMP(kp
, "man") == 0);
5521 isman_s
= (STRCMP(kp
, "man -s") == 0);
5522 if (cap
->count0
!= 0 && !(isman
|| isman_s
))
5523 sprintf((char *)buf
, ".,.+%ld", cap
->count0
- 1);
5526 if (cap
->count0
== 0 && isman_s
)
5531 if (cap
->count0
!= 0 && (isman
|| isman_s
))
5533 sprintf((char *)buf
+ STRLEN(buf
), "%ld", cap
->count0
);
5542 STRCPY(buf
, "cstag ");
5550 STRCPY(buf
, "he! ");
5554 sprintf((char *)buf
, "%ldta ", cap
->count0
);
5558 * Now grab the chars in the identifier
5560 if (cmdchar
== 'K' && !kp_help
)
5562 /* Escape the argument properly for a shell command */
5563 ptr
= vim_strnsave(ptr
, n
);
5564 p
= vim_strsave_shellescape(ptr
, TRUE
);
5571 buf
= (char_u
*)vim_realloc(buf
, STRLEN(buf
) + STRLEN(p
) + 1);
5584 aux_ptr
= (char_u
*)(p_magic
? "/.*~[^$\\" : "/^$\\");
5585 else if (cmdchar
== '#')
5586 aux_ptr
= (char_u
*)(p_magic
? "/?.*~[^$\\" : "/?^$\\");
5588 /* Don't escape spaces and Tabs in a tag with a backslash */
5589 aux_ptr
= (char_u
*)"\\|\"\n*?[";
5591 p
= buf
+ STRLEN(buf
);
5594 /* put a backslash before \ and some others */
5595 if (vim_strchr(aux_ptr
, *ptr
) != NULL
)
5598 /* When current byte is a part of multibyte character, copy all
5599 * bytes of that character. */
5603 int len
= (*mb_ptr2len
)(ptr
) - 1;
5605 for (i
= 0; i
< len
&& n
>= 1; ++i
, --n
)
5615 * Execute the command.
5617 if (cmdchar
== '*' || cmdchar
== '#')
5621 has_mbyte
? vim_iswordp(mb_prevptr(ml_get_curline(), ptr
)) :
5623 vim_iswordc(ptr
[-1])))
5626 /* put pattern in search history */
5627 add_to_history(HIST_SEARCH
, buf
, TRUE
, NUL
);
5629 normal_search(cap
, cmdchar
== '*' ? '/' : '?', buf
, 0);
5632 do_cmdline_cmd(buf
);
5637 #if defined(FEAT_VISUAL) || defined(PROTO)
5639 * Get visually selected text, within one line only.
5640 * Returns FAIL if more than one line selected.
5643 get_visual_text(cap
, pp
, lenp
)
5645 char_u
**pp
; /* return: start of selected text */
5646 int *lenp
; /* return: length of selected text */
5648 if (VIsual_mode
!= 'V')
5650 if (VIsual
.lnum
!= curwin
->w_cursor
.lnum
)
5653 clearopbeep(cap
->oap
);
5656 if (VIsual_mode
== 'V')
5658 *pp
= ml_get_curline();
5659 *lenp
= (int)STRLEN(*pp
);
5663 if (lt(curwin
->w_cursor
, VIsual
))
5665 *pp
= ml_get_pos(&curwin
->w_cursor
);
5666 *lenp
= VIsual
.col
- curwin
->w_cursor
.col
+ 1;
5670 *pp
= ml_get_pos(&VIsual
);
5671 *lenp
= curwin
->w_cursor
.col
- VIsual
.col
+ 1;
5675 /* Correct the length to include the whole last character. */
5676 *lenp
+= (*mb_ptr2len
)(*pp
+ (*lenp
- 1)) - 1;
5679 reset_VIsual_and_resel();
5685 * CTRL-T: backwards in tag stack
5691 if (!checkclearopq(cap
->oap
))
5692 do_tag((char_u
*)"", DT_POP
, (int)cap
->count1
, FALSE
, TRUE
);
5696 * Handle scrolling command 'H', 'L' and 'M'.
5709 cap
->oap
->motion_type
= MLINE
;
5712 if (cap
->cmdchar
== 'L')
5714 validate_botline(); /* make sure curwin->w_botline is valid */
5715 curwin
->w_cursor
.lnum
= curwin
->w_botline
- 1;
5716 if (cap
->count1
- 1 >= curwin
->w_cursor
.lnum
)
5717 curwin
->w_cursor
.lnum
= 1;
5721 if (hasAnyFolding(curwin
))
5723 /* Count a fold for one screen line. */
5724 for (n
= cap
->count1
- 1; n
> 0
5725 && curwin
->w_cursor
.lnum
> curwin
->w_topline
; --n
)
5727 (void)hasFolding(curwin
->w_cursor
.lnum
,
5728 &curwin
->w_cursor
.lnum
, NULL
);
5729 --curwin
->w_cursor
.lnum
;
5734 curwin
->w_cursor
.lnum
-= cap
->count1
- 1;
5739 if (cap
->cmdchar
== 'M')
5742 /* Don't count filler lines above the window. */
5743 used
-= diff_check_fill(curwin
, curwin
->w_topline
)
5744 - curwin
->w_topfill
;
5746 validate_botline(); /* make sure w_empty_rows is valid */
5747 half
= (curwin
->w_height
- curwin
->w_empty_rows
+ 1) / 2;
5748 for (n
= 0; curwin
->w_topline
+ n
< curbuf
->b_ml
.ml_line_count
; ++n
)
5751 /* Count half he number of filler lines to be "below this
5752 * line" and half to be "above the next line". */
5753 if (n
> 0 && used
+ diff_check_fill(curwin
, curwin
->w_topline
5760 used
+= plines(curwin
->w_topline
+ n
);
5764 if (hasFolding(curwin
->w_topline
+ n
, NULL
, &lnum
))
5765 n
= lnum
- curwin
->w_topline
;
5768 if (n
> 0 && used
> curwin
->w_height
)
5771 else /* (cap->cmdchar == 'H') */
5773 n
= cap
->count1
- 1;
5775 if (hasAnyFolding(curwin
))
5777 /* Count a fold for one screen line. */
5778 lnum
= curwin
->w_topline
;
5779 while (n
-- > 0 && lnum
< curwin
->w_botline
- 1)
5781 hasFolding(lnum
, NULL
, &lnum
);
5784 n
= lnum
- curwin
->w_topline
;
5788 curwin
->w_cursor
.lnum
= curwin
->w_topline
+ n
;
5789 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
5790 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
5793 cursor_correct(); /* correct for 'so' */
5794 beginline(BL_SOL
| BL_FIX
);
5798 * Cursor right commands.
5808 # define PAST_LINE 0
5811 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
5813 /* <C-Right> and <S-Right> move a word or WORD right */
5814 if (mod_mask
& MOD_MASK_CTRL
)
5820 cap
->oap
->motion_type
= MCHAR
;
5821 cap
->oap
->inclusive
= FALSE
;
5823 PAST_LINE
= (VIsual_active
&& *p_sel
!= 'o');
5825 # ifdef FEAT_VIRTUALEDIT
5827 * In virtual mode, there's no such thing as "PAST_LINE", as lines are
5828 * (theoretically) infinitely long.
5830 if (virtual_active())
5835 for (n
= cap
->count1
; n
> 0; --n
)
5837 if ((!PAST_LINE
&& oneright() == FAIL
)
5838 || (PAST_LINE
&& *ml_get_cursor() == NUL
))
5841 * <Space> wraps to next line if 'whichwrap' has 's'.
5842 * 'l' wraps to next line if 'whichwrap' has 'l'.
5843 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'.
5845 if ( ((cap
->cmdchar
== ' '
5846 && vim_strchr(p_ww
, 's') != NULL
)
5847 || (cap
->cmdchar
== 'l'
5848 && vim_strchr(p_ww
, 'l') != NULL
)
5849 || (cap
->cmdchar
== K_RIGHT
5850 && vim_strchr(p_ww
, '>') != NULL
))
5851 && curwin
->w_cursor
.lnum
< curbuf
->b_ml
.ml_line_count
)
5853 /* When deleting we also count the NL as a character.
5854 * Set cap->oap->inclusive when last char in the line is
5855 * included, move to next line after that */
5856 if ( cap
->oap
->op_type
!= OP_NOP
5857 && !cap
->oap
->inclusive
5858 && !lineempty(curwin
->w_cursor
.lnum
))
5859 cap
->oap
->inclusive
= TRUE
;
5862 ++curwin
->w_cursor
.lnum
;
5863 curwin
->w_cursor
.col
= 0;
5864 #ifdef FEAT_VIRTUALEDIT
5865 curwin
->w_cursor
.coladd
= 0;
5867 curwin
->w_set_curswant
= TRUE
;
5868 cap
->oap
->inclusive
= FALSE
;
5872 if (cap
->oap
->op_type
== OP_NOP
)
5874 /* Only beep and flush if not moved at all */
5875 if (n
== cap
->count1
)
5880 if (!lineempty(curwin
->w_cursor
.lnum
))
5881 cap
->oap
->inclusive
= TRUE
;
5888 curwin
->w_set_curswant
= TRUE
;
5889 # ifdef FEAT_VIRTUALEDIT
5890 if (virtual_active())
5897 curwin
->w_cursor
.col
+=
5898 (*mb_ptr2len
)(ml_get_cursor());
5901 ++curwin
->w_cursor
.col
;
5907 if (n
!= cap
->count1
&& (fdo_flags
& FDO_HOR
) && KeyTyped
5908 && cap
->oap
->op_type
== OP_NOP
)
5914 * Cursor left commands.
5916 * Returns TRUE when operator end should not be adjusted.
5924 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
5926 /* <C-Left> and <S-Left> move a word or WORD left */
5927 if (mod_mask
& MOD_MASK_CTRL
)
5933 cap
->oap
->motion_type
= MCHAR
;
5934 cap
->oap
->inclusive
= FALSE
;
5935 for (n
= cap
->count1
; n
> 0; --n
)
5937 if (oneleft() == FAIL
)
5939 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'.
5940 * 'h' wraps to previous line if 'whichwrap' has 'h'.
5941 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'.
5943 if ( (((cap
->cmdchar
== K_BS
5944 || cap
->cmdchar
== Ctrl_H
)
5945 && vim_strchr(p_ww
, 'b') != NULL
)
5946 || (cap
->cmdchar
== 'h'
5947 && vim_strchr(p_ww
, 'h') != NULL
)
5948 || (cap
->cmdchar
== K_LEFT
5949 && vim_strchr(p_ww
, '<') != NULL
))
5950 && curwin
->w_cursor
.lnum
> 1)
5952 --(curwin
->w_cursor
.lnum
);
5953 coladvance((colnr_T
)MAXCOL
);
5954 curwin
->w_set_curswant
= TRUE
;
5956 /* When the NL before the first char has to be deleted we
5957 * put the cursor on the NUL after the previous line.
5958 * This is a very special case, be careful!
5959 * Don't adjust op_end now, otherwise it won't work. */
5960 if ( (cap
->oap
->op_type
== OP_DELETE
5961 || cap
->oap
->op_type
== OP_CHANGE
)
5962 && !lineempty(curwin
->w_cursor
.lnum
))
5964 if (*ml_get_cursor() != NUL
)
5965 ++curwin
->w_cursor
.col
;
5966 cap
->retval
|= CA_NO_ADJ_OP_END
;
5970 /* Only beep and flush if not moved at all */
5971 else if (cap
->oap
->op_type
== OP_NOP
&& n
== cap
->count1
)
5977 if (n
!= cap
->count1
&& (fdo_flags
& FDO_HOR
) && KeyTyped
5978 && cap
->oap
->op_type
== OP_NOP
)
5984 * Cursor up commands.
5985 * cap->arg is TRUE for "-": Move cursor to first non-blank.
5991 if (mod_mask
& MOD_MASK_SHIFT
)
5993 /* <S-Up> is page up */
5994 cap
->arg
= BACKWARD
;
5999 cap
->oap
->motion_type
= MLINE
;
6000 if (cursor_up(cap
->count1
, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
6001 clearopbeep(cap
->oap
);
6003 beginline(BL_WHITE
| BL_FIX
);
6008 * Cursor down commands.
6009 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank.
6015 if (mod_mask
& MOD_MASK_SHIFT
)
6017 /* <S-Down> is page down */
6022 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6023 /* In a quickfix window a <CR> jumps to the error under the cursor. */
6024 if (bt_quickfix(curbuf
) && cap
->cmdchar
== CAR
)
6025 if (curwin
->w_llist_ref
== NULL
)
6026 do_cmdline_cmd((char_u
*)".cc"); /* quickfix window */
6028 do_cmdline_cmd((char_u
*)".ll"); /* location list window */
6033 /* In the cmdline window a <CR> executes the command. */
6034 if (cmdwin_type
!= 0 && cap
->cmdchar
== CAR
)
6035 cmdwin_result
= CAR
;
6039 cap
->oap
->motion_type
= MLINE
;
6040 if (cursor_down(cap
->count1
, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
6041 clearopbeep(cap
->oap
);
6043 beginline(BL_WHITE
| BL_FIX
);
6048 #ifdef FEAT_SEARCHPATH
6050 * Grab the file name under the cursor and edit it.
6061 clearopbeep(cap
->oap
);
6066 if (curbuf_locked())
6073 ptr
= grab_file_name(cap
->count1
, &lnum
);
6077 /* do autowrite if necessary */
6078 if (curbufIsChanged() && curbuf
->b_nwindows
<= 1 && !P_HID(curbuf
))
6079 autowrite(curbuf
, FALSE
);
6081 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LAST
,
6082 P_HID(curbuf
) ? ECMD_HIDE
: 0, curwin
);
6083 if (cap
->nchar
== 'F' && lnum
>= 0)
6085 curwin
->w_cursor
.lnum
= lnum
;
6086 check_cursor_lnum();
6087 beginline(BL_SOL
| BL_FIX
);
6097 * <End> command: to end of current line or last line.
6103 if (cap
->arg
|| (mod_mask
& MOD_MASK_CTRL
)) /* CTRL-END = goto last line */
6107 cap
->count1
= 1; /* to end of current line */
6113 * Handle the "$" command.
6119 cap
->oap
->motion_type
= MCHAR
;
6120 cap
->oap
->inclusive
= TRUE
;
6121 #ifdef FEAT_VIRTUALEDIT
6122 /* In virtual mode when off the edge of a line and an operator
6123 * is pending (whew!) keep the cursor where it is.
6124 * Otherwise, send it to the end of the line. */
6125 if (!virtual_active() || gchar_cursor() != NUL
6126 || cap
->oap
->op_type
== OP_NOP
)
6128 curwin
->w_curswant
= MAXCOL
; /* so we stay at the end */
6129 if (cursor_down((long)(cap
->count1
- 1),
6130 cap
->oap
->op_type
== OP_NOP
) == FAIL
)
6131 clearopbeep(cap
->oap
);
6133 else if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6139 * Implementation of '?' and '/' commands.
6140 * If cap->arg is TRUE don't set PC mark.
6146 oparg_T
*oap
= cap
->oap
;
6148 if (cap
->cmdchar
== '?' && cap
->oap
->op_type
== OP_ROT13
)
6150 /* Translate "g??" to "g?g?" */
6158 cap
->searchbuf
= getcmdline(cap
->cmdchar
,
6159 (cap
->nchar
== 'g' ? -cap
->count1
: cap
->count1
), 0);
6161 cap
->searchbuf
= getcmdline(cap
->cmdchar
, cap
->count1
, 0);
6164 if (cap
->searchbuf
== NULL
)
6170 normal_search(cap
, cap
->cmdchar
, cap
->searchbuf
,
6172 (cap
->nchar
== 'g' ? SEARCH_MIGEMO
: 0) |
6174 (cap
->arg
? 0 : SEARCH_MARK
));
6178 * Handle "N" and "n" commands.
6179 * cap->arg is SEARCH_REV for "N", 0 for "n".
6185 normal_search(cap
, 0, NULL
, SEARCH_MARK
| cap
->arg
);
6189 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
6190 * Uses only cap->count1 and cap->oap from "cap".
6193 normal_search(cap
, dir
, pat
, opt
)
6197 int opt
; /* extra flags for do_search() */
6201 cap
->oap
->motion_type
= MCHAR
;
6202 cap
->oap
->inclusive
= FALSE
;
6203 cap
->oap
->use_reg_one
= TRUE
;
6204 curwin
->w_set_curswant
= TRUE
;
6206 i
= do_search(cap
->oap
, dir
, pat
, cap
->count1
,
6207 opt
| SEARCH_OPT
| SEARCH_ECHO
| SEARCH_MSG
, NULL
);
6213 cap
->oap
->motion_type
= MLINE
;
6214 #ifdef FEAT_VIRTUALEDIT
6215 curwin
->w_cursor
.coladd
= 0;
6218 if (cap
->oap
->op_type
== OP_NOP
&& (fdo_flags
& FDO_SEARCH
) && KeyTyped
)
6223 /* "/$" will put the cursor after the end of the line, may need to
6224 * correct that here */
6229 * Character search commands.
6230 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for
6231 * ',' and FALSE for ';'.
6232 * cap->nchar is NUL for ',' and ';' (repeat the search)
6240 if (cap
->cmdchar
== 't' || cap
->cmdchar
== 'T')
6245 cap
->oap
->motion_type
= MCHAR
;
6246 if (IS_SPECIAL(cap
->nchar
) || searchc(cap
, t_cmd
) == FAIL
)
6247 clearopbeep(cap
->oap
);
6250 curwin
->w_set_curswant
= TRUE
;
6251 #ifdef FEAT_VIRTUALEDIT
6252 /* Include a Tab for "tx" and for "dfx". */
6253 if (gchar_cursor() == TAB
&& virtual_active() && cap
->arg
== FORWARD
6254 && (t_cmd
|| cap
->oap
->op_type
!= OP_NOP
))
6258 getvcol(curwin
, &curwin
->w_cursor
, &scol
, NULL
, &ecol
);
6259 curwin
->w_cursor
.coladd
= ecol
- scol
;
6262 curwin
->w_cursor
.coladd
= 0;
6265 adjust_for_sel(cap
);
6268 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6275 * "[" and "]" commands.
6276 * cap->arg is BACKWARD for "[" and FORWARD for "]".
6284 pos_T
*pos
= NULL
; /* init for GCC */
6285 pos_T old_pos
; /* cursor position before command */
6291 cap
->oap
->motion_type
= MCHAR
;
6292 cap
->oap
->inclusive
= FALSE
;
6293 old_pos
= curwin
->w_cursor
;
6294 #ifdef FEAT_VIRTUALEDIT
6295 curwin
->w_cursor
.coladd
= 0; /* TODO: don't do this for an error. */
6298 #ifdef FEAT_SEARCHPATH
6300 * "[f" or "]f" : Edit file under the cursor (same as "gf")
6302 if (cap
->nchar
== 'f')
6309 * Find the occurrence(s) of the identifier or define under cursor
6310 * in current and included files or jump to the first occurrence.
6313 * fwd bwd fwd bwd fwd bwd
6314 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
6315 * define "]d" "[d" "]D" "[D" "]^D" "[^D"
6317 if (vim_strchr((char_u
*)
6323 cap
->nchar
) != NULL
)
6328 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
6332 find_pattern_in_path(ptr
, 0, len
, TRUE
,
6333 cap
->count0
== 0 ? !isupper(cap
->nchar
) : FALSE
,
6334 ((cap
->nchar
& 0xf) == ('d' & 0xf)) ? FIND_DEFINE
: FIND_ANY
,
6336 isupper(cap
->nchar
) ? ACTION_SHOW_ALL
:
6337 islower(cap
->nchar
) ? ACTION_SHOW
: ACTION_GOTO
,
6338 cap
->cmdchar
== ']' ? curwin
->w_cursor
.lnum
+ 1 : (linenr_T
)1,
6340 curwin
->w_set_curswant
= TRUE
;
6347 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')'
6348 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct.
6349 * "[/", "[*", "]/", "]*": go to Nth comment start/end.
6350 * "[m" or "]m" search for prev/next start of (Java) method.
6351 * "[M" or "]M" search for prev/next end of (Java) method.
6353 if ( (cap
->cmdchar
== '['
6354 && vim_strchr((char_u
*)"{(*/#mM", cap
->nchar
) != NULL
)
6355 || (cap
->cmdchar
== ']'
6356 && vim_strchr((char_u
*)"})*/#mM", cap
->nchar
) != NULL
))
6358 if (cap
->nchar
== '*')
6362 if (cap
->nchar
== 'm' || cap
->nchar
== 'M')
6364 if (cap
->cmdchar
== '[')
6377 if ((pos
= findmatchlimit(cap
->oap
, findc
,
6378 (cap
->cmdchar
== '[') ? FM_BACKWARD
: FM_FORWARD
, 0)) == NULL
)
6380 if (new_pos
.lnum
== 0) /* nothing found */
6382 if (cap
->nchar
!= 'm' && cap
->nchar
!= 'M')
6383 clearopbeep(cap
->oap
);
6386 pos
= &new_pos
; /* use last one found */
6390 curwin
->w_cursor
= *pos
;
6393 curwin
->w_cursor
= old_pos
;
6396 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only
6397 * brought us to the match for "[m" and "]M" when inside a method.
6398 * Try finding the '{' or '}' we want to be at.
6399 * Also repeat for the given count.
6401 if (cap
->nchar
== 'm' || cap
->nchar
== 'M')
6403 /* norm is TRUE for "]M" and "[m" */
6404 int norm
= ((findc
== '{') == (cap
->nchar
== 'm'));
6407 /* found a match: we were inside a method */
6408 if (prev_pos
.lnum
!= 0)
6411 curwin
->w_cursor
= prev_pos
;
6421 if ((findc
== '{' ? dec_cursor() : inc_cursor()) < 0)
6423 /* if not found anything, that's an error */
6425 clearopbeep(cap
->oap
);
6430 if (c
== '{' || c
== '}')
6432 /* Must have found end/start of class: use it.
6433 * Or found the place to be at. */
6434 if ((c
== findc
&& norm
) || (n
== 1 && !norm
))
6436 new_pos
= curwin
->w_cursor
;
6440 /* if no match found at all, we started outside of the
6441 * class and we're inside now. Just go on. */
6442 else if (new_pos
.lnum
== 0)
6444 new_pos
= curwin
->w_cursor
;
6447 /* found start/end of other method: go to match */
6448 else if ((pos
= findmatchlimit(cap
->oap
, findc
,
6449 (cap
->cmdchar
== '[') ? FM_BACKWARD
: FM_FORWARD
,
6453 curwin
->w_cursor
= *pos
;
6459 curwin
->w_cursor
= old_pos
;
6460 if (pos
== NULL
&& new_pos
.lnum
!= 0)
6461 clearopbeep(cap
->oap
);
6466 curwin
->w_cursor
= *pos
;
6467 curwin
->w_set_curswant
= TRUE
;
6469 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
6470 && cap
->oap
->op_type
== OP_NOP
)
6477 * "[[", "[]", "]]" and "][": move to start or end of function
6479 else if (cap
->nchar
== '[' || cap
->nchar
== ']')
6481 if (cap
->nchar
== cap
->cmdchar
) /* "]]" or "[[" */
6484 flag
= '}'; /* "][" or "[]" */
6486 curwin
->w_set_curswant
= TRUE
;
6488 * Imitate strange Vi behaviour: When using "]]" with an operator
6489 * we also stop at '}'.
6491 if (!findpar(&cap
->oap
->inclusive
, cap
->arg
, cap
->count1
, flag
,
6492 (cap
->oap
->op_type
!= OP_NOP
6493 && cap
->arg
== FORWARD
&& flag
== '{')))
6494 clearopbeep(cap
->oap
);
6497 if (cap
->oap
->op_type
== OP_NOP
)
6498 beginline(BL_WHITE
| BL_FIX
);
6500 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6507 * "[p", "[P", "]P" and "]p": put with indent adjustment
6509 else if (cap
->nchar
== 'p' || cap
->nchar
== 'P')
6511 if (!checkclearop(cap
->oap
))
6514 do_put(cap
->oap
->regname
,
6515 (cap
->cmdchar
== ']' && cap
->nchar
== 'p') ? FORWARD
: BACKWARD
,
6516 cap
->count1
, PUT_FIXINDENT
);
6521 * "['", "[`", "]'" and "]`": jump to next mark
6523 else if (cap
->nchar
== '\'' || cap
->nchar
== '`')
6525 pos
= &curwin
->w_cursor
;
6526 for (n
= cap
->count1
; n
> 0; --n
)
6529 pos
= getnextmark(pos
, cap
->cmdchar
== '[' ? BACKWARD
: FORWARD
,
6530 cap
->nchar
== '\'');
6536 nv_cursormark(cap
, cap
->nchar
== '\'', pos
);
6541 * [ or ] followed by a middle mouse click: put selected text with
6542 * indent adjustment. Any other button just does as usual.
6544 else if (cap
->nchar
>= K_LEFTMOUSE
&& cap
->nchar
<= K_RIGHTRELEASE
)
6546 (void)do_mouse(cap
->oap
, cap
->nchar
,
6547 (cap
->cmdchar
== ']') ? FORWARD
: BACKWARD
,
6548 cap
->count1
, PUT_FIXINDENT
);
6550 #endif /* FEAT_MOUSE */
6554 * "[z" and "]z": move to start or end of open fold.
6556 else if (cap
->nchar
== 'z')
6558 if (foldMoveTo(FALSE
, cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6559 cap
->count1
) == FAIL
)
6560 clearopbeep(cap
->oap
);
6566 * "[c" and "]c": move to next or previous diff-change.
6568 else if (cap
->nchar
== 'c')
6570 if (diff_move_to(cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6571 cap
->count1
) == FAIL
)
6572 clearopbeep(cap
->oap
);
6578 * "[s", "[S", "]s" and "]S": move to next spell error.
6580 else if (cap
->nchar
== 's' || cap
->nchar
== 'S')
6583 for (n
= 0; n
< cap
->count1
; ++n
)
6584 if (spell_move_to(curwin
, cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6585 cap
->nchar
== 's' ? TRUE
: FALSE
, FALSE
, NULL
) == 0)
6587 clearopbeep(cap
->oap
);
6590 # ifdef FEAT_FOLDING
6591 if (cap
->oap
->op_type
== OP_NOP
&& (fdo_flags
& FDO_SEARCH
) && KeyTyped
)
6597 /* Not a valid cap->nchar. */
6599 clearopbeep(cap
->oap
);
6603 * Handle Normal mode "%" command.
6611 linenr_T lnum
= curwin
->w_cursor
.lnum
;
6614 cap
->oap
->inclusive
= TRUE
;
6615 if (cap
->count0
) /* {cnt}% : goto {cnt} percentage in file */
6617 if (cap
->count0
> 100)
6618 clearopbeep(cap
->oap
);
6621 cap
->oap
->motion_type
= MLINE
;
6623 /* Round up, so CTRL-G will give same value. Watch out for a
6624 * large line count, the line number must not go negative! */
6625 if (curbuf
->b_ml
.ml_line_count
> 1000000)
6626 curwin
->w_cursor
.lnum
= (curbuf
->b_ml
.ml_line_count
+ 99L)
6627 / 100L * cap
->count0
;
6629 curwin
->w_cursor
.lnum
= (curbuf
->b_ml
.ml_line_count
*
6630 cap
->count0
+ 99L) / 100L;
6631 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6632 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6633 beginline(BL_SOL
| BL_FIX
);
6636 else /* "%" : go to matching paren */
6638 cap
->oap
->motion_type
= MCHAR
;
6639 cap
->oap
->use_reg_one
= TRUE
;
6640 if ((pos
= findmatch(cap
->oap
, NUL
)) == NULL
)
6641 clearopbeep(cap
->oap
);
6645 curwin
->w_cursor
= *pos
;
6646 curwin
->w_set_curswant
= TRUE
;
6647 #ifdef FEAT_VIRTUALEDIT
6648 curwin
->w_cursor
.coladd
= 0;
6651 adjust_for_sel(cap
);
6656 if (cap
->oap
->op_type
== OP_NOP
6657 && lnum
!= curwin
->w_cursor
.lnum
6658 && (fdo_flags
& FDO_PERCENT
)
6665 * Handle "(" and ")" commands.
6666 * cap->arg is BACKWARD for "(" and FORWARD for ")".
6672 cap
->oap
->motion_type
= MCHAR
;
6673 cap
->oap
->use_reg_one
= TRUE
;
6674 /* The motion used to be inclusive for "(", but that is not what Vi does. */
6675 cap
->oap
->inclusive
= FALSE
;
6676 curwin
->w_set_curswant
= TRUE
;
6678 if (findsent(cap
->arg
, cap
->count1
) == FAIL
)
6679 clearopbeep(cap
->oap
);
6682 /* Don't leave the cursor on the NUL past end of line. */
6683 adjust_cursor(cap
->oap
);
6684 #ifdef FEAT_VIRTUALEDIT
6685 curwin
->w_cursor
.coladd
= 0;
6688 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6695 * "m" command: Mark a position.
6701 if (!checkclearop(cap
->oap
))
6703 if (setmark(cap
->nchar
) == FAIL
)
6704 clearopbeep(cap
->oap
);
6709 * "{" and "}" commands.
6710 * cmd->arg is BACKWARD for "{" and FORWARD for "}".
6716 cap
->oap
->motion_type
= MCHAR
;
6717 cap
->oap
->inclusive
= FALSE
;
6718 cap
->oap
->use_reg_one
= TRUE
;
6719 curwin
->w_set_curswant
= TRUE
;
6720 if (!findpar(&cap
->oap
->inclusive
, cap
->arg
, cap
->count1
, NUL
, FALSE
))
6721 clearopbeep(cap
->oap
);
6724 #ifdef FEAT_VIRTUALEDIT
6725 curwin
->w_cursor
.coladd
= 0;
6728 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6735 * "u" command: Undo or make lower case.
6741 if (cap
->oap
->op_type
== OP_LOWER
6747 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */
6763 if (!checkclearopq(cap
->oap
))
6765 u_undo((int)cap
->count1
);
6766 curwin
->w_set_curswant
= TRUE
;
6771 * Handle the "r" command.
6781 if (checkclearop(cap
->oap
))
6784 /* get another character */
6785 if (cap
->nchar
== Ctrl_V
)
6787 had_ctrl_v
= Ctrl_V
;
6788 cap
->nchar
= get_literal();
6789 /* Don't redo a multibyte character with CTRL-V. */
6790 if (cap
->nchar
> DEL
)
6796 /* Abort if the character is a special key. */
6797 if (IS_SPECIAL(cap
->nchar
))
6799 clearopbeep(cap
->oap
);
6804 /* Visual mode "r" */
6814 #ifdef FEAT_VIRTUALEDIT
6815 /* Break tabs, etc. */
6816 if (virtual_active())
6818 if (u_save_cursor() == FAIL
)
6820 if (gchar_cursor() == NUL
)
6822 /* Add extra space and put the cursor on the first one. */
6823 coladvance_force((colnr_T
)(getviscol() + cap
->count1
));
6824 curwin
->w_cursor
.col
-= cap
->count1
;
6826 else if (gchar_cursor() == TAB
)
6827 coladvance_force(getviscol());
6831 /* Abort if not enough characters to replace. */
6832 ptr
= ml_get_cursor();
6833 if (STRLEN(ptr
) < (unsigned)cap
->count1
6835 || (has_mbyte
&& mb_charlen(ptr
) < cap
->count1
)
6839 clearopbeep(cap
->oap
);
6844 * Replacing with a TAB is done by edit() when it is complicated because
6845 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB.
6846 * Other characters are done below to avoid problems with things like
6847 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC).
6849 if (had_ctrl_v
!= Ctrl_V
&& cap
->nchar
== '\t' && (curbuf
->b_p_et
|| p_sta
))
6851 stuffnumReadbuff(cap
->count1
);
6852 stuffcharReadbuff('R');
6853 stuffcharReadbuff('\t');
6854 stuffcharReadbuff(ESC
);
6858 /* save line for undo */
6859 if (u_save_cursor() == FAIL
)
6862 if (had_ctrl_v
!= Ctrl_V
&& (cap
->nchar
== '\r' || cap
->nchar
== '\n'))
6865 * Replace character(s) by a single newline.
6866 * Strange vi behaviour: Only one newline is inserted.
6867 * Delete the characters here.
6868 * Insert the newline with an insert command, takes care of
6869 * autoindent. The insert command depends on being on the last
6870 * character of a line or not.
6873 (void)del_chars(cap
->count1
, FALSE
); /* delete the characters */
6875 (void)del_bytes(cap
->count1
, FALSE
, FALSE
); /* delete the characters */
6877 stuffcharReadbuff('\r');
6878 stuffcharReadbuff(ESC
);
6880 /* Give 'r' to edit(), to get the redo command right. */
6881 invoke_edit(cap
, TRUE
, 'r', FALSE
);
6885 prep_redo(cap
->oap
->regname
, cap
->count1
,
6886 NUL
, 'r', NUL
, had_ctrl_v
, cap
->nchar
);
6888 curbuf
->b_op_start
= curwin
->w_cursor
;
6892 int old_State
= State
;
6894 if (cap
->ncharC1
!= 0)
6895 AppendCharToRedobuff(cap
->ncharC1
);
6896 if (cap
->ncharC2
!= 0)
6897 AppendCharToRedobuff(cap
->ncharC2
);
6899 /* This is slow, but it handles replacing a single-byte with a
6900 * multi-byte and the other way around. Also handles adding
6901 * composing characters for utf-8. */
6902 for (n
= cap
->count1
; n
> 0; --n
)
6905 ins_char(cap
->nchar
);
6907 if (cap
->ncharC1
!= 0)
6908 ins_char(cap
->ncharC1
);
6909 if (cap
->ncharC2
!= 0)
6910 ins_char(cap
->ncharC2
);
6917 * Replace the characters within one line.
6919 for (n
= cap
->count1
; n
> 0; --n
)
6922 * Get ptr again, because u_save and/or showmatch() will have
6923 * released the line. At the same time we let know that the
6924 * line will be changed.
6926 ptr
= ml_get_buf(curbuf
, curwin
->w_cursor
.lnum
, TRUE
);
6927 ptr
[curwin
->w_cursor
.col
] = cap
->nchar
;
6928 if (p_sm
&& msg_silent
== 0)
6929 showmatch(cap
->nchar
);
6930 ++curwin
->w_cursor
.col
;
6932 #ifdef FEAT_NETBEANS_INTG
6935 colnr_T start
= (colnr_T
)(curwin
->w_cursor
.col
- cap
->count1
);
6937 netbeans_removed(curbuf
, curwin
->w_cursor
.lnum
, start
,
6939 netbeans_inserted(curbuf
, curwin
->w_cursor
.lnum
, start
,
6940 &ptr
[start
], (int)cap
->count1
);
6944 /* mark the buffer as changed and prepare for displaying */
6945 changed_bytes(curwin
->w_cursor
.lnum
,
6946 (colnr_T
)(curwin
->w_cursor
.col
- cap
->count1
));
6948 --curwin
->w_cursor
.col
; /* cursor on the last replaced char */
6950 /* if the character on the left of the current cursor is a multi-byte
6951 * character, move two characters left */
6955 curbuf
->b_op_end
= curwin
->w_cursor
;
6956 curwin
->w_set_curswant
= TRUE
;
6957 set_last_insert(cap
->nchar
);
6963 * 'o': Exchange start and end of Visual area.
6964 * 'O': same, but in block mode exchange left and right corners.
6967 v_swap_corners(cmdchar
)
6971 colnr_T left
, right
;
6973 if (cmdchar
== 'O' && VIsual_mode
== Ctrl_V
)
6975 old_cursor
= curwin
->w_cursor
;
6976 getvcols(curwin
, &old_cursor
, &VIsual
, &left
, &right
);
6977 curwin
->w_cursor
.lnum
= VIsual
.lnum
;
6979 VIsual
= curwin
->w_cursor
;
6981 curwin
->w_cursor
.lnum
= old_cursor
.lnum
;
6982 curwin
->w_curswant
= right
;
6983 /* 'selection "exclusive" and cursor at right-bottom corner: move it
6984 * right one column */
6985 if (old_cursor
.lnum
>= VIsual
.lnum
&& *p_sel
== 'e')
6986 ++curwin
->w_curswant
;
6987 coladvance(curwin
->w_curswant
);
6988 if (curwin
->w_cursor
.col
== old_cursor
.col
6989 #ifdef FEAT_VIRTUALEDIT
6990 && (!virtual_active()
6991 || curwin
->w_cursor
.coladd
== old_cursor
.coladd
)
6995 curwin
->w_cursor
.lnum
= VIsual
.lnum
;
6996 if (old_cursor
.lnum
<= VIsual
.lnum
&& *p_sel
== 'e')
6999 VIsual
= curwin
->w_cursor
;
7001 curwin
->w_cursor
.lnum
= old_cursor
.lnum
;
7003 curwin
->w_curswant
= left
;
7008 old_cursor
= curwin
->w_cursor
;
7009 curwin
->w_cursor
= VIsual
;
7010 VIsual
= old_cursor
;
7011 curwin
->w_set_curswant
= TRUE
;
7014 #endif /* FEAT_VISUAL */
7017 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE).
7024 if (VIsual_active
) /* "R" is replace lines */
7033 if (!checkclearopq(cap
->oap
))
7035 if (!curbuf
->b_p_ma
)
7036 EMSG(_(e_modifiable
));
7039 #ifdef FEAT_VIRTUALEDIT
7040 if (virtual_active())
7041 coladvance(getviscol());
7043 invoke_edit(cap
, FALSE
, cap
->arg
? 'V' : 'R', FALSE
);
7048 #ifdef FEAT_VREPLACE
7060 cap
->nchar
= cap
->extra_char
;
7061 nv_replace(cap
); /* Do same as "r" in Visual mode for now */
7065 if (!checkclearopq(cap
->oap
))
7067 if (!curbuf
->b_p_ma
)
7068 EMSG(_(e_modifiable
));
7071 if (cap
->extra_char
== Ctrl_V
) /* get another character */
7072 cap
->extra_char
= get_literal();
7073 stuffcharReadbuff(cap
->extra_char
);
7074 stuffcharReadbuff(ESC
);
7075 # ifdef FEAT_VIRTUALEDIT
7076 if (virtual_active())
7077 coladvance(getviscol());
7079 invoke_edit(cap
, TRUE
, 'v', FALSE
);
7086 * Swap case for "~" command, when it does not work like an operator.
7095 #ifdef FEAT_NETBEANS_INTG
7101 if (checkclearopq(cap
->oap
))
7104 if (lineempty(curwin
->w_cursor
.lnum
) && vim_strchr(p_ww
, '~') == NULL
)
7106 clearopbeep(cap
->oap
);
7112 if (u_save_cursor() == FAIL
)
7115 startpos
= curwin
->w_cursor
;
7116 #ifdef FEAT_NETBEANS_INTG
7119 for (n
= cap
->count1
; n
> 0; --n
)
7121 did_change
|= swapchar(cap
->oap
->op_type
, &curwin
->w_cursor
);
7123 if (gchar_cursor() == NUL
)
7125 if (vim_strchr(p_ww
, '~') != NULL
7126 && curwin
->w_cursor
.lnum
< curbuf
->b_ml
.ml_line_count
)
7128 #ifdef FEAT_NETBEANS_INTG
7133 ptr
= ml_get(pos
.lnum
);
7134 count
= (int)STRLEN(ptr
) - pos
.col
;
7135 netbeans_removed(curbuf
, pos
.lnum
, pos
.col
,
7137 netbeans_inserted(curbuf
, pos
.lnum
, pos
.col
,
7138 &ptr
[pos
.col
], count
);
7144 ++curwin
->w_cursor
.lnum
;
7145 curwin
->w_cursor
.col
= 0;
7148 if (u_savesub(curwin
->w_cursor
.lnum
) == FAIL
)
7157 #ifdef FEAT_NETBEANS_INTG
7158 if (did_change
&& usingNetbeans
)
7160 ptr
= ml_get(pos
.lnum
);
7161 count
= curwin
->w_cursor
.col
- pos
.col
;
7162 netbeans_removed(curbuf
, pos
.lnum
, pos
.col
, (long)count
);
7163 netbeans_inserted(curbuf
, pos
.lnum
, pos
.col
, &ptr
[pos
.col
], count
);
7169 curwin
->w_set_curswant
= TRUE
;
7172 changed_lines(startpos
.lnum
, startpos
.col
, curwin
->w_cursor
.lnum
+ 1,
7174 curbuf
->b_op_start
= startpos
;
7175 curbuf
->b_op_end
= curwin
->w_cursor
;
7176 if (curbuf
->b_op_end
.col
> 0)
7177 --curbuf
->b_op_end
.col
;
7182 * Move cursor to mark.
7185 nv_cursormark(cap
, flag
, pos
)
7190 if (check_mark(pos
) == FAIL
)
7194 if (cap
->cmdchar
== '\''
7195 || cap
->cmdchar
== '`'
7196 || cap
->cmdchar
== '['
7197 || cap
->cmdchar
== ']')
7199 curwin
->w_cursor
= *pos
;
7201 beginline(BL_WHITE
| BL_FIX
);
7205 cap
->oap
->motion_type
= flag
? MLINE
: MCHAR
;
7206 if (cap
->cmdchar
== '`')
7207 cap
->oap
->use_reg_one
= TRUE
;
7208 cap
->oap
->inclusive
= FALSE
; /* ignored if not MCHAR */
7209 curwin
->w_set_curswant
= TRUE
;
7214 * Handle commands that are operators in Visual mode.
7220 static char_u trans
[] = "YyDdCcxdXdAAIIrr";
7222 /* Uppercase means linewise, except in block mode, then "D" deletes till
7223 * the end of the line, and "C" replaces til EOL */
7224 if (isupper(cap
->cmdchar
))
7226 if (VIsual_mode
!= Ctrl_V
)
7228 else if (cap
->cmdchar
== 'C' || cap
->cmdchar
== 'D')
7229 curwin
->w_curswant
= MAXCOL
;
7231 cap
->cmdchar
= *(vim_strchr(trans
, cap
->cmdchar
) + 1);
7237 * "s" and "S" commands.
7244 if (VIsual_active
) /* "vs" and "vS" are the same as "vc" */
7246 if (cap
->cmdchar
== 'S')
7257 * Abbreviated commands.
7263 if (cap
->cmdchar
== K_DEL
|| cap
->cmdchar
== K_KDEL
)
7264 cap
->cmdchar
= 'x'; /* DEL key behaves like 'x' */
7267 /* in Visual mode these commands are operators */
7276 * Translate a command into another command.
7282 static char_u
*(ar
[8]) = {(char_u
*)"dl", (char_u
*)"dh",
7283 (char_u
*)"d$", (char_u
*)"c$",
7284 (char_u
*)"cl", (char_u
*)"cc",
7285 (char_u
*)"yy", (char_u
*)":s\r"};
7286 static char_u
*str
= (char_u
*)"xXDCsSY&";
7288 if (!checkclearopq(cap
->oap
))
7290 /* In Vi "2D" doesn't delete the next line. Can't translate it
7291 * either, because "2." should also not use the count. */
7292 if (cap
->cmdchar
== 'D' && vim_strchr(p_cpo
, CPO_HASH
) != NULL
)
7294 cap
->oap
->start
= curwin
->w_cursor
;
7295 cap
->oap
->op_type
= OP_DELETE
;
7297 set_op_var(OP_DELETE
);
7303 AppendCharToRedobuff('D');
7308 stuffnumReadbuff(cap
->count0
);
7309 stuffReadbuff(ar
[(int)(vim_strchr(str
, cap
->cmdchar
) - str
)]);
7316 * "'" and "`" commands. Also for "g'" and "g`".
7317 * cap->arg is TRUE for "'" and "g'".
7326 linenr_T lnum
= curwin
->w_cursor
.lnum
;
7327 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
7330 if (cap
->cmdchar
== 'g')
7331 c
= cap
->extra_char
;
7334 pos
= getmark(c
, (cap
->oap
->op_type
== OP_NOP
));
7335 if (pos
== (pos_T
*)-1) /* jumped to other file */
7339 check_cursor_lnum();
7340 beginline(BL_WHITE
| BL_FIX
);
7346 nv_cursormark(cap
, cap
->arg
, pos
);
7348 #ifdef FEAT_VIRTUALEDIT
7349 /* May need to clear the coladd that a mark includes. */
7350 if (!virtual_active())
7351 curwin
->w_cursor
.coladd
= 0;
7354 if (cap
->oap
->op_type
== OP_NOP
7355 && (pos
== (pos_T
*)-1 || lnum
!= curwin
->w_cursor
.lnum
)
7356 && (fdo_flags
& FDO_MARK
)
7363 * Handle CTRL-O, CTRL-I, "g;" and "g," commands.
7369 #ifdef FEAT_JUMPLIST
7371 # ifdef FEAT_FOLDING
7372 linenr_T lnum
= curwin
->w_cursor
.lnum
;
7373 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
7376 if (!checkclearopq(cap
->oap
))
7378 if (cap
->cmdchar
== 'g')
7379 pos
= movechangelist((int)cap
->count1
);
7381 pos
= movemark((int)cap
->count1
);
7382 if (pos
== (pos_T
*)-1) /* jump to other file */
7384 curwin
->w_set_curswant
= TRUE
;
7387 else if (pos
!= NULL
) /* can jump */
7388 nv_cursormark(cap
, FALSE
, pos
);
7389 else if (cap
->cmdchar
== 'g')
7391 if (curbuf
->b_changelistlen
== 0)
7392 EMSG(_("E664: changelist is empty"));
7393 else if (cap
->count1
< 0)
7394 EMSG(_("E662: At start of changelist"));
7396 EMSG(_("E663: At end of changelist"));
7399 clearopbeep(cap
->oap
);
7400 # ifdef FEAT_FOLDING
7401 if (cap
->oap
->op_type
== OP_NOP
7402 && (pos
== (pos_T
*)-1 || lnum
!= curwin
->w_cursor
.lnum
)
7403 && (fdo_flags
& FDO_MARK
)
7409 clearopbeep(cap
->oap
);
7414 * Handle '"' command.
7420 if (checkclearop(cap
->oap
))
7423 if (cap
->nchar
== '=')
7424 cap
->nchar
= get_expr_register();
7426 if (cap
->nchar
!= NUL
&& valid_yank_reg(cap
->nchar
, FALSE
))
7428 cap
->oap
->regname
= cap
->nchar
;
7429 cap
->opcount
= cap
->count0
; /* remember count before '"' */
7431 set_reg_var(cap
->oap
->regname
);
7435 clearopbeep(cap
->oap
);
7440 * Handle "v", "V" and "CTRL-V" commands.
7441 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg
7443 * Handle CTRL-Q just like CTRL-V.
7449 if (cap
->cmdchar
== Ctrl_Q
)
7450 cap
->cmdchar
= Ctrl_V
;
7452 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it
7453 * characterwise, linewise, or blockwise. */
7454 if (cap
->oap
->op_type
!= OP_NOP
)
7456 cap
->oap
->motion_force
= cap
->cmdchar
;
7457 finish_op
= FALSE
; /* operator doesn't finish now but later */
7461 VIsual_select
= cap
->arg
;
7462 if (VIsual_active
) /* change Visual mode */
7464 if (VIsual_mode
== cap
->cmdchar
) /* stop visual mode */
7466 else /* toggle char/block mode */
7467 { /* or char/line mode */
7468 VIsual_mode
= cap
->cmdchar
;
7471 redraw_curbuf_later(INVERTED
); /* update the inversion */
7473 else /* start Visual mode */
7475 check_visual_highlight();
7476 if (cap
->count0
) /* use previously selected part */
7478 if (resel_VIsual_mode
== NUL
) /* there is none */
7483 VIsual
= curwin
->w_cursor
;
7485 VIsual_active
= TRUE
;
7486 VIsual_reselect
= TRUE
;
7488 /* start Select mode when 'selectmode' contains "cmd" */
7489 may_start_select('c');
7493 if (p_smd
&& msg_silent
== 0)
7494 redraw_cmdline
= TRUE
; /* show visual mode later */
7496 * For V and ^V, we multiply the number of lines even if there
7497 * was only one -- webb
7499 if (resel_VIsual_mode
!= 'v' || resel_VIsual_line_count
> 1)
7501 curwin
->w_cursor
.lnum
+=
7502 resel_VIsual_line_count
* cap
->count0
- 1;
7503 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
7504 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
7506 VIsual_mode
= resel_VIsual_mode
;
7507 if (VIsual_mode
== 'v')
7509 if (resel_VIsual_line_count
<= 1)
7510 curwin
->w_cursor
.col
+= resel_VIsual_col
* cap
->count0
- 1;
7512 curwin
->w_cursor
.col
= resel_VIsual_col
;
7515 if (resel_VIsual_col
== MAXCOL
)
7517 curwin
->w_curswant
= MAXCOL
;
7518 coladvance((colnr_T
)MAXCOL
);
7520 else if (VIsual_mode
== Ctrl_V
)
7523 curwin
->w_curswant
= curwin
->w_virtcol
7524 + resel_VIsual_col
* cap
->count0
- 1;
7525 coladvance(curwin
->w_curswant
);
7528 curwin
->w_set_curswant
= TRUE
;
7529 redraw_curbuf_later(INVERTED
); /* show the inversion */
7534 /* start Select mode when 'selectmode' contains "cmd" */
7535 may_start_select('c');
7536 n_start_visual_mode(cap
->cmdchar
);
7542 * Start selection for Shift-movement keys.
7547 /* if 'selectmode' contains "key", start Select mode */
7548 may_start_select('k');
7549 n_start_visual_mode('v');
7553 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu.
7559 VIsual_select
= (stuff_empty() && typebuf_typed()
7560 && (vim_strchr(p_slm
, c
) != NULL
));
7564 * Start Visual mode "c".
7565 * Should set VIsual_select before calling this.
7568 n_start_visual_mode(c
)
7572 VIsual_active
= TRUE
;
7573 VIsual_reselect
= TRUE
;
7574 #ifdef FEAT_VIRTUALEDIT
7575 /* Corner case: the 0 position in a tab may change when going into
7576 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting.
7578 if (c
== Ctrl_V
&& (ve_flags
& VE_BLOCK
) && gchar_cursor() == TAB
)
7579 coladvance(curwin
->w_virtcol
);
7581 VIsual
= curwin
->w_cursor
;
7590 if (p_smd
&& msg_silent
== 0)
7591 redraw_cmdline
= TRUE
; /* show visual mode later */
7592 #ifdef FEAT_CLIPBOARD
7593 /* Make sure the clipboard gets updated. Needed because start and
7594 * end may still be the same, and the selection needs to be owned */
7595 clip_star
.vmode
= NUL
;
7598 /* Only need to redraw this line, unless still need to redraw an old
7599 * Visual area (when 'lazyredraw' is set). */
7600 if (curwin
->w_redr_type
< INVERTED
)
7602 curwin
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
7603 curwin
->w_old_visual_lnum
= curwin
->w_cursor
.lnum
;
7607 #endif /* FEAT_VISUAL */
7610 * CTRL-W: Window commands
7617 if (!checkclearop(cap
->oap
))
7618 do_window(cap
->nchar
, cap
->count0
, NUL
); /* everything is in window.c */
7620 (void)checkclearop(cap
->oap
);
7634 end_visual_mode(); /* stop Visual mode */
7636 do_cmdline_cmd((char_u
*)"st");
7640 * Commands starting with "g".
7646 oparg_T
*oap
= cap
->oap
;
7657 * "g^A": dump log of used memory.
7660 vim_mem_profile_dump();
7664 #ifdef FEAT_VREPLACE
7666 * "gR": Enter virtual replace mode.
7679 do_cmdline_cmd((char_u
*)"%s//~/&");
7684 * "gv": Reselect the previous Visual area. If Visual already active,
7685 * exchange previous and current Visual area.
7688 if (checkclearop(oap
))
7691 if ( curbuf
->b_visual
.vi_start
.lnum
== 0
7692 || curbuf
->b_visual
.vi_start
.lnum
> curbuf
->b_ml
.ml_line_count
7693 || curbuf
->b_visual
.vi_end
.lnum
== 0)
7697 /* set w_cursor to the start of the Visual area, tpos to the end */
7701 VIsual_mode
= curbuf
->b_visual
.vi_mode
;
7702 curbuf
->b_visual
.vi_mode
= i
;
7704 curbuf
->b_visual_mode_eval
= i
;
7706 i
= curwin
->w_curswant
;
7707 curwin
->w_curswant
= curbuf
->b_visual
.vi_curswant
;
7708 curbuf
->b_visual
.vi_curswant
= i
;
7710 tpos
= curbuf
->b_visual
.vi_end
;
7711 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
7712 curwin
->w_cursor
= curbuf
->b_visual
.vi_start
;
7713 curbuf
->b_visual
.vi_start
= VIsual
;
7717 VIsual_mode
= curbuf
->b_visual
.vi_mode
;
7718 curwin
->w_curswant
= curbuf
->b_visual
.vi_curswant
;
7719 tpos
= curbuf
->b_visual
.vi_end
;
7720 curwin
->w_cursor
= curbuf
->b_visual
.vi_start
;
7723 VIsual_active
= TRUE
;
7724 VIsual_reselect
= TRUE
;
7726 /* Set Visual to the start and w_cursor to the end of the Visual
7727 * area. Make sure they are on an existing character. */
7729 VIsual
= curwin
->w_cursor
;
7730 curwin
->w_cursor
= tpos
;
7734 * When called from normal "g" command: start Select mode when
7735 * 'selectmode' contains "cmd". When called for K_SELECT, always
7736 * start Select mode.
7739 VIsual_select
= TRUE
;
7741 may_start_select('c');
7745 #ifdef FEAT_CLIPBOARD
7746 /* Make sure the clipboard gets updated. Needed because start and
7747 * end are still the same, and the selection needs to be owned */
7748 clip_star
.vmode
= NUL
;
7750 redraw_curbuf_later(INVERTED
);
7755 * "gV": Don't reselect the previous Visual area after a Select mode
7759 VIsual_reselect
= FALSE
;
7763 * "gh": start Select mode.
7764 * "gH": start Select line mode.
7765 * "g^H": start Select block mode.
7768 cap
->nchar
= Ctrl_H
;
7774 /* EBCDIC: 'v'-'h' != '^v'-'^h' */
7775 if (cap
->nchar
== Ctrl_H
)
7776 cap
->cmdchar
= Ctrl_V
;
7779 cap
->cmdchar
= cap
->nchar
+ ('v' - 'h');
7783 #endif /* FEAT_VISUAL */
7786 * "gj" and "gk" two new funny movement keys -- up and down
7787 * movement based on *screen* line rather than *file* line.
7791 /* with 'nowrap' it works just like the normal "j" command; also when
7792 * in a closed fold */
7793 if (!curwin
->w_p_wrap
7795 || hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
)
7799 oap
->motion_type
= MLINE
;
7800 i
= cursor_down(cap
->count1
, oap
->op_type
== OP_NOP
);
7803 i
= nv_screengo(oap
, FORWARD
, cap
->count1
);
7810 /* with 'nowrap' it works just like the normal "k" command; also when
7811 * in a closed fold */
7812 if (!curwin
->w_p_wrap
7814 || hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
)
7818 oap
->motion_type
= MLINE
;
7819 i
= cursor_up(cap
->count1
, oap
->op_type
== OP_NOP
);
7822 i
= nv_screengo(oap
, BACKWARD
, cap
->count1
);
7828 * "gJ": join two lines without inserting a space.
7835 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines.
7836 * "gm": middle of "g0" and "g$".
7846 oap
->motion_type
= MCHAR
;
7847 oap
->inclusive
= FALSE
;
7848 if (curwin
->w_p_wrap
7849 #ifdef FEAT_VERTSPLIT
7850 && curwin
->w_width
!= 0
7854 int width1
= W_WIDTH(curwin
) - curwin_col_off();
7855 int width2
= width1
+ curwin_col_off2();
7859 if (curwin
->w_virtcol
>= (colnr_T
)width1
&& width2
> 0)
7860 i
= (curwin
->w_virtcol
- width1
) / width2
* width2
+ width1
;
7863 i
= curwin
->w_leftcol
;
7864 /* Go to the middle of the screen line. When 'number' is on and lines
7865 * are wrapping the middle can be more to the left. */
7866 if (cap
->nchar
== 'm')
7867 i
+= (W_WIDTH(curwin
) - curwin_col_off()
7868 + ((curwin
->w_p_wrap
&& i
> 0)
7869 ? curwin_col_off2() : 0)) / 2;
7870 coladvance((colnr_T
)i
);
7875 while (vim_iswhite(i
) && oneright() == OK
);
7877 curwin
->w_set_curswant
= TRUE
;
7881 /* "g_": to the last non-blank character in the line or <count> lines
7883 cap
->oap
->motion_type
= MCHAR
;
7884 cap
->oap
->inclusive
= TRUE
;
7885 curwin
->w_curswant
= MAXCOL
;
7886 if (cursor_down((long)(cap
->count1
- 1),
7887 cap
->oap
->op_type
== OP_NOP
) == FAIL
)
7888 clearopbeep(cap
->oap
);
7891 char_u
*ptr
= ml_get_curline();
7893 /* In Visual mode we may end up after the line. */
7894 if (curwin
->w_cursor
.col
> 0 && ptr
[curwin
->w_cursor
.col
] == NUL
)
7895 --curwin
->w_cursor
.col
;
7897 /* Decrease the cursor column until it's on a non-blank. */
7898 while (curwin
->w_cursor
.col
> 0
7899 && vim_iswhite(ptr
[curwin
->w_cursor
.col
]))
7900 --curwin
->w_cursor
.col
;
7901 curwin
->w_set_curswant
= TRUE
;
7909 int col_off
= curwin_col_off();
7911 oap
->motion_type
= MCHAR
;
7912 oap
->inclusive
= TRUE
;
7913 if (curwin
->w_p_wrap
7914 #ifdef FEAT_VERTSPLIT
7915 && curwin
->w_width
!= 0
7919 curwin
->w_curswant
= MAXCOL
; /* so we stay at the end */
7920 if (cap
->count1
== 1)
7922 int width1
= W_WIDTH(curwin
) - col_off
;
7923 int width2
= width1
+ curwin_col_off2();
7927 if (curwin
->w_virtcol
>= (colnr_T
)width1
)
7928 i
+= ((curwin
->w_virtcol
- width1
) / width2
+ 1)
7930 coladvance((colnr_T
)i
);
7931 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
7932 if (curwin
->w_cursor
.col
> 0 && curwin
->w_p_wrap
)
7935 * Check for landing on a character that got split at
7936 * the end of the line. We do not want to advance to
7937 * the next screen line.
7940 if (curwin
->w_virtcol
> (colnr_T
)i
)
7941 --curwin
->w_cursor
.col
;
7945 else if (nv_screengo(oap
, FORWARD
, cap
->count1
- 1) == FAIL
)
7950 i
= curwin
->w_leftcol
+ W_WIDTH(curwin
) - col_off
- 1;
7951 coladvance((colnr_T
)i
);
7953 /* Make sure we stick in this column. */
7955 curwin
->w_curswant
= curwin
->w_virtcol
;
7956 curwin
->w_set_curswant
= FALSE
;
7962 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>"
7967 case POUND
: /* pound sign (sometimes equal to '#') */
7969 case Ctrl_RSB
: /* :tag or :tselect for current identifier */
7970 case ']': /* :tselect for current identifier */
7975 * ge and gE: go back to end of word
7979 oap
->motion_type
= MCHAR
;
7980 curwin
->w_set_curswant
= TRUE
;
7981 oap
->inclusive
= TRUE
;
7982 if (bckend_word(cap
->count1
, cap
->nchar
== 'E', FALSE
) == FAIL
)
7987 * "g CTRL-G": display info about cursor position
7994 * "gi": start Insert at the last position.
7997 if (curbuf
->b_last_insert
.lnum
!= 0)
7999 curwin
->w_cursor
= curbuf
->b_last_insert
;
8000 check_cursor_lnum();
8001 i
= (int)STRLEN(ml_get_curline());
8002 if (curwin
->w_cursor
.col
> (colnr_T
)i
)
8004 #ifdef FEAT_VIRTUALEDIT
8005 if (virtual_active())
8006 curwin
->w_cursor
.coladd
+= curwin
->w_cursor
.col
- i
;
8008 curwin
->w_cursor
.col
= i
;
8016 * "gI": Start insert in column 1.
8020 if (!checkclearopq(oap
))
8021 invoke_edit(cap
, FALSE
, 'g', FALSE
);
8024 #ifdef FEAT_SEARCHPATH
8026 * "gf": goto file, edit file under cursor
8027 * "]f" and "[f": can also be used.
8035 /* "g'm" and "g`m": jump to mark without setting pcmark */
8047 do_sleep(cap
->count1
* 1000L);
8051 * "ga": Display the ascii value of the character under the
8052 * cursor. It is displayed in decimal, hex, and octal. -- webb
8060 * "g8": Display the bytes used for the UTF-8 character under the
8061 * cursor. It is displayed in hex.
8062 * "8g8" finds illegal byte sequence.
8065 if (cap
->count0
== 8)
8077 * "gg": Goto the first line in file. With a count it goes to
8078 * that line number like for "G". -- webb
8086 * Two-character operators:
8088 * "gw" Format text and keep cursor position
8089 * "g~" Toggle the case of the text.
8090 * "gu" Change text to lower case.
8091 * "gU" Change text to upper case.
8092 * "g?" rot13 encoding
8093 * "g@" call 'operatorfunc'
8097 oap
->cursor_start
= curwin
->w_cursor
;
8110 * "gd": Find first occurrence of pattern under the cursor in the
8112 * "gD": idem, but in the current file.
8116 nv_gd(oap
, cap
->nchar
, (int)cap
->count0
);
8121 * g<*Mouse> : <C-*mouse>
8125 case K_MIDDLERELEASE
:
8131 case K_RIGHTRELEASE
:
8138 mod_mask
= MOD_MASK_CTRL
;
8139 (void)do_mouse(oap
, cap
->nchar
, BACKWARD
, cap
->count1
, 0);
8147 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text
8155 /* "go": goto byte count from start of buffer */
8157 goto_byte(cap
->count0
);
8161 /* "gQ": improved Ex mode */
8165 clearopbeep(cap
->oap
);
8170 if (!checkclearopq(oap
))
8174 #ifdef FEAT_JUMPLIST
8180 cap
->count1
= -cap
->count1
;
8187 goto_tabpage((int)cap
->count0
);
8190 goto_tabpage(-(int)cap
->count1
);
8195 case '-': /* "g+" and "g-": undo or redo along the timeline */
8196 if (!checkclearopq(oap
))
8197 undo_time(cap
->nchar
== '-' ? -cap
->count1
: cap
->count1
,
8209 if (curbuf
->b_p_migemo
)
8227 * Handle "o" and "O" commands.
8233 if (!checkclearopq(cap
->oap
))
8236 if (cap
->cmdchar
== 'O')
8237 /* Open above the first line of a folded sequence of lines */
8238 (void)hasFolding(curwin
->w_cursor
.lnum
,
8239 &curwin
->w_cursor
.lnum
, NULL
);
8241 /* Open below the last line of a folded sequence of lines */
8242 (void)hasFolding(curwin
->w_cursor
.lnum
,
8243 NULL
, &curwin
->w_cursor
.lnum
);
8245 if (u_save((linenr_T
)(curwin
->w_cursor
.lnum
-
8246 (cap
->cmdchar
== 'O' ? 1 : 0)),
8247 (linenr_T
)(curwin
->w_cursor
.lnum
+
8248 (cap
->cmdchar
== 'o' ? 1 : 0))
8250 && open_line(cap
->cmdchar
== 'O' ? BACKWARD
: FORWARD
,
8251 #ifdef FEAT_COMMENTS
8252 has_format_option(FO_OPEN_COMS
) ? OPENLINE_DO_COM
:
8256 /* When '#' is in 'cpoptions' ignore the count. */
8257 if (vim_strchr(p_cpo
, CPO_HASH
) != NULL
)
8259 invoke_edit(cap
, FALSE
, cap
->cmdchar
, TRUE
);
8265 * "." command: redo last change.
8271 if (!checkclearopq(cap
->oap
))
8274 * If "restart_edit" is TRUE, the last but one command is repeated
8275 * instead of the last command (inserting text). This is used for
8276 * CTRL-O <.> in insert mode.
8278 if (start_redo(cap
->count0
, restart_edit
!= 0 && !arrow_used
) == FAIL
)
8279 clearopbeep(cap
->oap
);
8290 if (!checkclearopq(cap
->oap
))
8292 u_redo((int)cap
->count1
);
8293 curwin
->w_set_curswant
= TRUE
;
8298 * Handle "U" command.
8304 /* In Visual mode and typing "gUU" triggers an operator */
8305 if (cap
->oap
->op_type
== OP_UPPER
8311 /* translate "gUU" to "gUgU" */
8316 else if (!checkclearopq(cap
->oap
))
8319 curwin
->w_set_curswant
= TRUE
;
8324 * '~' command: If tilde is not an operator and Visual is off: swap case of a
8335 && cap
->oap
->op_type
!= OP_TILDE
)
8342 * Handle an operator command.
8343 * The actual work is done by do_pending_operator().
8351 op_type
= get_op_type(cap
->cmdchar
, cap
->nchar
);
8353 if (op_type
== cap
->oap
->op_type
) /* double operator works on lines */
8355 else if (!checkclearop(cap
->oap
))
8357 cap
->oap
->start
= curwin
->w_cursor
;
8358 cap
->oap
->op_type
= op_type
;
8360 set_op_var(op_type
);
8367 * Set v:operator to the characters for "optype".
8375 if (optype
== OP_NOP
)
8376 set_vim_var_string(VV_OP
, NULL
, 0);
8379 opchars
[0] = get_op_char(optype
);
8380 opchars
[1] = get_extra_op_char(optype
);
8382 set_vim_var_string(VV_OP
, opchars
, -1);
8388 * Handle linewise operator "dd", "yy", etc.
8390 * "_" is is a strange motion command that helps make operators more logical.
8391 * It is actually implemented, but not documented in the real Vi. This motion
8392 * command actually refers to "the current line". Commands like "dd" and "yy"
8393 * are really an alternate form of "d_" and "y_". It does accept a count, so
8394 * "d3_" works to delete 3 lines.
8400 cap
->oap
->motion_type
= MLINE
;
8401 if (cursor_down(cap
->count1
- 1L, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
8402 clearopbeep(cap
->oap
);
8403 else if ( cap
->oap
->op_type
== OP_DELETE
8404 || cap
->oap
->op_type
== OP_LSHIFT
8405 || cap
->oap
->op_type
== OP_RSHIFT
)
8406 beginline(BL_SOL
| BL_FIX
);
8407 else if (cap
->oap
->op_type
!= OP_YANK
) /* 'Y' does not move cursor */
8408 beginline(BL_WHITE
| BL_FIX
);
8418 /* CTRL-HOME is like "gg" */
8419 if (mod_mask
& MOD_MASK_CTRL
)
8426 ins_at_eol
= FALSE
; /* Don't move cursor past eol (only necessary in a
8427 one-character line). */
8437 cap
->oap
->motion_type
= MCHAR
;
8438 cap
->oap
->inclusive
= FALSE
;
8440 if (cap
->count0
> 0)
8442 coladvance((colnr_T
)(cap
->count0
- 1));
8443 curwin
->w_curswant
= (colnr_T
)(cap
->count0
- 1);
8446 curwin
->w_curswant
= 0;
8447 /* keep curswant at the column where we wanted to go, not where
8448 we ended; differs if line is too short */
8449 curwin
->w_set_curswant
= FALSE
;
8453 * Handle back-word command "b" and "B".
8454 * cap->arg is 1 for "B"
8460 cap
->oap
->motion_type
= MCHAR
;
8461 cap
->oap
->inclusive
= FALSE
;
8462 curwin
->w_set_curswant
= TRUE
;
8463 if (bck_word(cap
->count1
, cap
->arg
, FALSE
) == FAIL
)
8464 clearopbeep(cap
->oap
);
8466 else if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8472 * Handle word motion commands "e", "E", "w" and "W".
8473 * cap->arg is TRUE for "E" and "W".
8482 pos_T startpos
= curwin
->w_cursor
;
8485 * Set inclusive for the "E" and "e" command.
8487 if (cap
->cmdchar
== 'e' || cap
->cmdchar
== 'E')
8491 cap
->oap
->inclusive
= word_end
;
8494 * "cw" and "cW" are a special case.
8496 if (!word_end
&& cap
->oap
->op_type
== OP_CHANGE
)
8499 if (n
!= NUL
) /* not an empty line */
8504 * Reproduce a funny Vi behaviour: "cw" on a blank only
8505 * changes one character, not all blanks until the start of
8506 * the next word. Only do this when the 'w' flag is included
8509 if (cap
->count1
== 1 && vim_strchr(p_cpo
, CPO_CW
) != NULL
)
8511 cap
->oap
->inclusive
= TRUE
;
8512 cap
->oap
->motion_type
= MCHAR
;
8519 * This is a little strange. To match what the real Vi does,
8520 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided
8521 * that we are not on a space or a TAB. This seems impolite
8522 * at first, but it's really more what we mean when we say
8524 * Another strangeness: When standing on the end of a word
8525 * "ce" will change until the end of the next wordt, but "cw"
8526 * will change only one character! This is done by setting
8529 cap
->oap
->inclusive
= TRUE
;
8536 cap
->oap
->motion_type
= MCHAR
;
8537 curwin
->w_set_curswant
= TRUE
;
8539 n
= end_word(cap
->count1
, cap
->arg
, flag
, FALSE
);
8541 n
= fwd_word(cap
->count1
, cap
->arg
, cap
->oap
->op_type
!= OP_NOP
);
8543 /* Don't leave the cursor on the NUL past the end of line. Unless we
8544 * didn't move it forward. */
8545 if (lt(startpos
, curwin
->w_cursor
))
8546 adjust_cursor(cap
->oap
);
8548 if (n
== FAIL
&& cap
->oap
->op_type
== OP_NOP
)
8549 clearopbeep(cap
->oap
);
8553 adjust_for_sel(cap
);
8556 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8563 * Used after a movement command: If the cursor ends up on the NUL after the
8564 * end of the line, may move it back to the last character and make the motion
8571 /* The cursor cannot remain on the NUL when:
8572 * - the column is > 0
8573 * - not in Visual mode or 'selection' is "o"
8574 * - 'virtualedit' is not "all" and not "onemore".
8576 if (curwin
->w_cursor
.col
> 0 && gchar_cursor() == NUL
8578 && (!VIsual_active
|| *p_sel
== 'o')
8580 #ifdef FEAT_VIRTUALEDIT
8581 && !virtual_active() && (ve_flags
& VE_ONEMORE
) == 0
8585 --curwin
->w_cursor
.col
;
8587 /* prevent cursor from moving on the trail byte */
8591 oap
->inclusive
= TRUE
;
8596 * "0" and "^" commands.
8597 * cap->arg is the argument for beginline().
8603 cap
->oap
->motion_type
= MCHAR
;
8604 cap
->oap
->inclusive
= FALSE
;
8605 beginline(cap
->arg
);
8607 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8610 ins_at_eol
= FALSE
; /* Don't move cursor past eol (only necessary in a
8611 one-character line). */
8616 * In exclusive Visual mode, may include the last character.
8622 if (VIsual_active
&& cap
->oap
->inclusive
&& *p_sel
== 'e'
8623 && gchar_cursor() != NUL
&& lt(VIsual
, curwin
->w_cursor
))
8630 ++curwin
->w_cursor
.col
;
8631 cap
->oap
->inclusive
= FALSE
;
8636 * Exclude last character at end of Visual area for 'selection' == "exclusive".
8637 * Should check VIsual_mode before calling this.
8638 * Returns TRUE when backed up to the previous line.
8645 if (*p_sel
== 'e' && !equalpos(VIsual
, curwin
->w_cursor
))
8647 if (lt(VIsual
, curwin
->w_cursor
))
8648 pp
= &curwin
->w_cursor
;
8651 #ifdef FEAT_VIRTUALEDIT
8663 else if (pp
->lnum
> 1)
8666 pp
->col
= (colnr_T
)STRLEN(ml_get(pp
->lnum
));
8674 * SELECT key in Normal or Visual mode: end of Select mode mapping.
8681 VIsual_select
= TRUE
;
8682 else if (VIsual_reselect
)
8684 cap
->nchar
= 'v'; /* fake "gv" command */
8693 * "G", "gg", CTRL-END, CTRL-HOME.
8694 * cap->arg is TRUE for "G".
8703 lnum
= curbuf
->b_ml
.ml_line_count
;
8706 cap
->oap
->motion_type
= MLINE
;
8709 /* When a count is given, use it instead of the default lnum */
8710 if (cap
->count0
!= 0)
8714 else if (lnum
> curbuf
->b_ml
.ml_line_count
)
8715 lnum
= curbuf
->b_ml
.ml_line_count
;
8716 curwin
->w_cursor
.lnum
= lnum
;
8717 beginline(BL_SOL
| BL_FIX
);
8719 if ((fdo_flags
& FDO_JUMP
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8725 * CTRL-\ in Normal mode.
8731 if (cap
->nchar
== Ctrl_N
|| cap
->nchar
== Ctrl_G
)
8734 if (restart_edit
!= 0 && mode_displayed
)
8735 clear_cmdline
= TRUE
; /* unshow mode later */
8738 if (cmdwin_type
!= 0)
8739 cmdwin_result
= Ctrl_C
;
8744 end_visual_mode(); /* stop Visual */
8745 redraw_curbuf_later(INVERTED
);
8748 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */
8749 if (cap
->nchar
== Ctrl_G
&& p_im
)
8753 clearopbeep(cap
->oap
);
8757 * ESC in Normal mode: beep, but don't flush buffers.
8758 * Don't even beep if we are canceling a command.
8766 no_reason
= (cap
->oap
->op_type
== OP_NOP
8767 && cap
->opcount
== 0
8769 && cap
->oap
->regname
== 0
8772 if (cap
->arg
) /* TRUE for CTRL-C */
8774 if (restart_edit
== 0
8782 MSG(_("Type :quit<Enter> to exit Vim"));
8784 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be
8785 * set again below when halfway a mapping. */
8789 if (cmdwin_type
!= 0)
8791 cmdwin_result
= K_IGNORE
;
8792 got_int
= FALSE
; /* don't stop executing autocommands et al. */
8801 end_visual_mode(); /* stop Visual */
8802 check_cursor_col(); /* make sure cursor is not beyond EOL */
8803 curwin
->w_set_curswant
= TRUE
;
8804 redraw_curbuf_later(INVERTED
);
8812 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is
8813 * set return to Insert mode afterwards. */
8814 if (restart_edit
== 0 && goto_im()
8815 #ifdef FEAT_EX_EXTRA
8816 && ex_normal_busy
== 0
8823 * Handle "A", "a", "I", "i" and <Insert> commands.
8829 /* <Insert> is equal to "i" */
8830 if (cap
->cmdchar
== K_INS
|| cap
->cmdchar
== K_KINS
)
8834 /* in Visual mode "A" and "I" are an operator */
8835 if (VIsual_active
&& (cap
->cmdchar
== 'A' || cap
->cmdchar
== 'I'))
8838 /* in Visual mode and after an operator "a" and "i" are for text objects */
8841 if ((cap
->cmdchar
== 'a' || cap
->cmdchar
== 'i')
8842 && (cap
->oap
->op_type
!= OP_NOP
8851 clearopbeep(cap
->oap
);
8854 else if (!curbuf
->b_p_ma
&& !p_im
)
8856 /* Only give this error when 'insertmode' is off. */
8857 EMSG(_(e_modifiable
));
8860 else if (!checkclearopq(cap
->oap
))
8862 switch (cap
->cmdchar
)
8864 case 'A': /* "A"ppend after the line */
8865 curwin
->w_set_curswant
= TRUE
;
8866 #ifdef FEAT_VIRTUALEDIT
8867 if (ve_flags
== VE_ALL
)
8869 int save_State
= State
;
8871 /* Pretent Insert mode here to allow the cursor on the
8872 * character past the end of the line */
8874 coladvance((colnr_T
)MAXCOL
);
8879 curwin
->w_cursor
.col
+= (colnr_T
)STRLEN(ml_get_cursor());
8882 case 'I': /* "I"nsert before the first non-blank */
8883 if (vim_strchr(p_cpo
, CPO_INSEND
) == NULL
)
8884 beginline(BL_WHITE
);
8886 beginline(BL_WHITE
|BL_FIX
);
8889 case 'a': /* "a"ppend is like "i"nsert on the next character. */
8890 #ifdef FEAT_VIRTUALEDIT
8891 /* increment coladd when in virtual space, increment the
8892 * column otherwise, also to append after an unprintable char */
8893 if (virtual_active()
8894 && (curwin
->w_cursor
.coladd
> 0
8895 || *ml_get_cursor() == NUL
8896 || *ml_get_cursor() == TAB
))
8897 curwin
->w_cursor
.coladd
++;
8900 if (*ml_get_cursor() != NUL
)
8905 #ifdef FEAT_VIRTUALEDIT
8906 if (curwin
->w_cursor
.coladd
&& cap
->cmdchar
!= 'A')
8908 int save_State
= State
;
8910 /* Pretent Insert mode here to allow the cursor on the
8911 * character past the end of the line */
8913 coladvance(getviscol());
8918 invoke_edit(cap
, FALSE
, cap
->cmdchar
, FALSE
);
8923 * Invoke edit() and take care of "restart_edit" and the return value.
8926 invoke_edit(cap
, repl
, cmd
, startln
)
8928 int repl
; /* "r" or "gr" command */
8932 int restart_edit_save
= 0;
8934 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert
8935 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow
8937 if (repl
|| !stuff_empty())
8938 restart_edit_save
= restart_edit
;
8940 restart_edit_save
= 0;
8942 /* Always reset "restart_edit", this is not a restarted edit. */
8945 if (edit(cmd
, startln
, cap
->count1
))
8946 cap
->retval
|= CA_COMMAND_BUSY
;
8948 if (restart_edit
== 0)
8949 restart_edit
= restart_edit_save
;
8954 * "a" or "i" while an operator is pending or in Visual mode: object motion.
8964 if (cap
->cmdchar
== 'i')
8965 include
= FALSE
; /* "ix" = inner object: exclude white space */
8967 include
= TRUE
; /* "ax" = an object: include white space */
8969 /* Make sure (), [], {} and <> are in 'matchpairs' */
8970 mps_save
= curbuf
->b_p_mps
;
8971 curbuf
->b_p_mps
= (char_u
*)"(:),{:},[:],<:>";
8975 case 'w': /* "aw" = a word */
8976 flag
= current_word(cap
->oap
, cap
->count1
, include
, FALSE
);
8978 case 'W': /* "aW" = a WORD */
8979 flag
= current_word(cap
->oap
, cap
->count1
, include
, TRUE
);
8981 case 'b': /* "ab" = a braces block */
8984 flag
= current_block(cap
->oap
, cap
->count1
, include
, '(', ')');
8986 case 'B': /* "aB" = a Brackets block */
8989 flag
= current_block(cap
->oap
, cap
->count1
, include
, '{', '}');
8991 case '[': /* "a[" = a [] block */
8993 flag
= current_block(cap
->oap
, cap
->count1
, include
, '[', ']');
8995 case '<': /* "a<" = a <> block */
8997 flag
= current_block(cap
->oap
, cap
->count1
, include
, '<', '>');
8999 case 't': /* "at" = a tag block (xml and html) */
9000 flag
= current_tagblock(cap
->oap
, cap
->count1
, include
);
9002 case 'p': /* "ap" = a paragraph */
9003 flag
= current_par(cap
->oap
, cap
->count1
, include
, 'p');
9005 case 's': /* "as" = a sentence */
9006 flag
= current_sent(cap
->oap
, cap
->count1
, include
);
9008 case '"': /* "a"" = a double quoted string */
9009 case '\'': /* "a'" = a single quoted string */
9010 case '`': /* "a`" = a backtick quoted string */
9011 flag
= current_quote(cap
->oap
, cap
->count1
, include
,
9015 case 'S': /* "aS" = a section */
9016 case 'f': /* "af" = a filename */
9017 case 'u': /* "au" = a URL */
9024 curbuf
->b_p_mps
= mps_save
;
9026 clearopbeep(cap
->oap
);
9027 adjust_cursor_col();
9028 curwin
->w_set_curswant
= TRUE
;
9033 * "q" command: Start/stop recording.
9034 * "q:", "q/", "q?": edit command-line in command-line window.
9040 if (cap
->oap
->op_type
== OP_FORMAT
)
9042 /* "gqq" is the same as "gqgq": format line */
9047 else if (!checkclearop(cap
->oap
))
9050 if (cap
->nchar
== ':' || cap
->nchar
== '/' || cap
->nchar
== '?')
9052 stuffcharReadbuff(cap
->nchar
);
9053 stuffcharReadbuff(K_CMDWIN
);
9057 /* (stop) recording into a named register, unless executing a
9059 if (!Exec_reg
&& do_record(cap
->nchar
) == FAIL
)
9060 clearopbeep(cap
->oap
);
9065 * Handle the "@r" command.
9071 if (checkclearop(cap
->oap
))
9074 if (cap
->nchar
== '=')
9076 if (get_expr_register() == NUL
)
9080 while (cap
->count1
-- && !got_int
)
9082 if (do_execreg(cap
->nchar
, FALSE
, FALSE
, FALSE
) == FAIL
)
9084 clearopbeep(cap
->oap
);
9092 * Handle the CTRL-U and CTRL-D commands.
9098 if ((cap
->cmdchar
== Ctrl_U
&& curwin
->w_cursor
.lnum
== 1)
9099 || (cap
->cmdchar
== Ctrl_D
9100 && curwin
->w_cursor
.lnum
== curbuf
->b_ml
.ml_line_count
))
9101 clearopbeep(cap
->oap
);
9102 else if (!checkclearop(cap
->oap
))
9103 halfpage(cap
->cmdchar
== Ctrl_D
, cap
->count0
);
9107 * Handle "J" or "gJ" command.
9114 if (VIsual_active
) /* join the visual lines */
9118 if (!checkclearop(cap
->oap
))
9120 if (cap
->count0
<= 1)
9121 cap
->count0
= 2; /* default for join is two lines! */
9122 if (curwin
->w_cursor
.lnum
+ cap
->count0
- 1 >
9123 curbuf
->b_ml
.ml_line_count
)
9124 clearopbeep(cap
->oap
); /* beyond last line */
9127 prep_redo(cap
->oap
->regname
, cap
->count0
,
9128 NUL
, cap
->cmdchar
, NUL
, NUL
, cap
->nchar
);
9129 do_do_join(cap
->count0
, cap
->nchar
== NUL
);
9135 * "P", "gP", "p" and "gp" commands.
9143 void *reg1
= NULL
, *reg2
= NULL
;
9145 int was_visual
= FALSE
;
9150 if (cap
->oap
->op_type
!= OP_NOP
)
9153 /* "dp" is ":diffput" */
9154 if (cap
->oap
->op_type
== OP_DELETE
&& cap
->cmdchar
== 'p')
9157 nv_diffgetput(TRUE
);
9161 clearopbeep(cap
->oap
);
9165 dir
= (cap
->cmdchar
== 'P'
9166 || (cap
->cmdchar
== 'g' && cap
->nchar
== 'P'))
9167 ? BACKWARD
: FORWARD
;
9169 if (cap
->cmdchar
== 'g')
9170 flags
|= PUT_CURSEND
;
9175 /* Putting in Visual mode: The put text replaces the selected
9176 * text. First delete the selected text, then put the new text.
9177 * Need to save and restore the registers that the delete
9178 * overwrites if the old contents is being put.
9181 regname
= cap
->oap
->regname
;
9182 # ifdef FEAT_CLIPBOARD
9183 adjust_clip_reg(®name
);
9185 if (regname
== 0 || VIM_ISDIGIT(regname
)
9186 # ifdef FEAT_CLIPBOARD
9187 || (clip_unnamed
&& (regname
== '*' || regname
== '+'))
9192 /* the delete is going to overwrite the register we want to
9193 * put, save it first. */
9194 reg1
= get_register(regname
, TRUE
);
9197 /* Now delete the selected text. */
9200 cap
->oap
->regname
= NUL
;
9202 do_pending_operator(cap
, 0, FALSE
);
9203 empty
= (curbuf
->b_ml
.ml_flags
& ML_EMPTY
);
9205 /* delete PUT_LINE_BACKWARD; */
9206 cap
->oap
->regname
= regname
;
9210 /* Delete probably changed the register we want to put, save
9211 * it first. Then put back what was there before the delete. */
9212 reg2
= get_register(regname
, FALSE
);
9213 put_register(regname
, reg1
);
9216 /* When deleted a linewise Visual area, put the register as
9217 * lines to avoid it joined with the next line. When deletion was
9218 * characterwise, split a line when putting lines. */
9219 if (VIsual_mode
== 'V')
9221 else if (VIsual_mode
== 'v')
9222 flags
|= PUT_LINE_SPLIT
;
9223 if (VIsual_mode
== Ctrl_V
&& dir
== FORWARD
)
9224 flags
|= PUT_LINE_FORWARD
;
9226 if ((VIsual_mode
!= 'V'
9227 && curwin
->w_cursor
.col
< curbuf
->b_op_start
.col
)
9228 || (VIsual_mode
== 'V'
9229 && curwin
->w_cursor
.lnum
< curbuf
->b_op_start
.lnum
))
9230 /* cursor is at the end of the line or end of file, put
9235 do_put(cap
->oap
->regname
, dir
, cap
->count1
, flags
);
9238 /* If a register was saved, put it back now. */
9240 put_register(regname
, reg2
);
9242 /* What to reselect with "gv"? Selecting the just put text seems to
9243 * be the most useful, since the original text was removed. */
9246 curbuf
->b_visual
.vi_start
= curbuf
->b_op_start
;
9247 curbuf
->b_visual
.vi_end
= curbuf
->b_op_end
;
9250 /* When all lines were selected and deleted do_put() leaves an empty
9251 * line that needs to be deleted now. */
9252 if (empty
&& *ml_get(curbuf
->b_ml
.ml_line_count
) == NUL
)
9254 ml_delete(curbuf
->b_ml
.ml_line_count
, TRUE
);
9256 /* If the cursor was in that line, move it to the end of the last
9258 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
9260 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
9261 coladvance((colnr_T
)MAXCOL
);
9265 auto_format(FALSE
, TRUE
);
9270 * "o" and "O" commands.
9277 /* "do" is ":diffget" */
9278 if (cap
->oap
->op_type
== OP_DELETE
&& cap
->cmdchar
== 'o')
9281 nv_diffgetput(FALSE
);
9286 if (VIsual_active
) /* switch start and end of visual */
9287 v_swap_corners(cap
->cmdchar
);
9299 ProcessSniffRequests();
9303 #ifdef FEAT_NETBEANS_INTG
9308 netbeans_keycommand(cap
->nchar
);
9318 do_put('~', BACKWARD
, 1L, PUT_CURSEND
);
9324 * Trigger CursorHold event.
9325 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the
9326 * input buffer. "did_cursorhold" is set to avoid retriggering.
9333 apply_autocmds(EVENT_CURSORHOLD
, NULL
, NULL
, FALSE
, curbuf
);
9334 did_cursorhold
= TRUE
;
9335 cap
->retval
|= CA_COMMAND_BUSY
; /* don't call edit() now */