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
));
187 * Function to be called for a Normal or Visual mode command.
188 * The argument is a cmdarg_T.
190 typedef void (*nv_func_T
) __ARGS((cmdarg_T
*cap
));
192 /* Values for cmd_flags. */
193 #define NV_NCH 0x01 /* may need to get a second char */
194 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */
195 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */
196 #define NV_LANG 0x08 /* second char needs language adjustment */
198 #define NV_SS 0x10 /* may start selection */
199 #define NV_SSS 0x20 /* may start selection with shift modifier */
200 #define NV_STS 0x40 /* may stop selection without shift modif. */
201 #define NV_RL 0x80 /* 'rightleft' modifies command */
202 #define NV_KEEPREG 0x100 /* don't clear regname */
203 #define NV_NCW 0x200 /* not allowed in command-line window */
206 * Generally speaking, every Normal mode command should either clear any
207 * pending operator (with *clearop*()), or set the motion type variable
210 * When a cursor motion command is made, it is marked as being a character or
211 * line oriented motion. Then, if an operator is in effect, the operation
212 * becomes character or line oriented accordingly.
216 * This table contains one entry for every Normal or Visual mode command.
217 * The order doesn't matter, init_normal_cmds() will create a sorted index.
218 * It is faster when all keys from zero to '~' are present.
220 static const struct nv_cmd
222 int cmd_char
; /* (first) command character */
223 nv_func_T cmd_func
; /* function for this command */
224 short_u cmd_flags
; /* NV_ flags */
225 short cmd_arg
; /* value for ca.arg */
228 {NUL
, nv_error
, 0, 0},
229 {Ctrl_A
, nv_addsub
, 0, 0},
230 {Ctrl_B
, nv_page
, NV_STS
, BACKWARD
},
231 {Ctrl_C
, nv_esc
, 0, TRUE
},
232 {Ctrl_D
, nv_halfpage
, 0, 0},
233 {Ctrl_E
, nv_scroll_line
, 0, TRUE
},
234 {Ctrl_F
, nv_page
, NV_STS
, FORWARD
},
235 {Ctrl_G
, nv_ctrlg
, 0, 0},
236 {Ctrl_H
, nv_ctrlh
, 0, 0},
237 {Ctrl_I
, nv_pcmark
, 0, 0},
238 {NL
, nv_down
, 0, FALSE
},
239 {Ctrl_K
, nv_error
, 0, 0},
240 {Ctrl_L
, nv_clear
, 0, 0},
241 {Ctrl_M
, nv_down
, 0, TRUE
},
242 {Ctrl_N
, nv_down
, NV_STS
, FALSE
},
243 {Ctrl_O
, nv_ctrlo
, 0, 0},
244 {Ctrl_P
, nv_up
, NV_STS
, FALSE
},
246 {Ctrl_Q
, nv_visual
, 0, FALSE
},
248 {Ctrl_Q
, nv_ignore
, 0, 0},
250 {Ctrl_R
, nv_redo
, 0, 0},
251 {Ctrl_S
, nv_ignore
, 0, 0},
252 {Ctrl_T
, nv_tagpop
, NV_NCW
, 0},
253 {Ctrl_U
, nv_halfpage
, 0, 0},
255 {Ctrl_V
, nv_visual
, 0, FALSE
},
256 {'V', nv_visual
, 0, FALSE
},
257 {'v', nv_visual
, 0, FALSE
},
259 {Ctrl_V
, nv_error
, 0, 0},
260 {'V', nv_error
, 0, 0},
261 {'v', nv_error
, 0, 0},
263 {Ctrl_W
, nv_window
, 0, 0},
264 {Ctrl_X
, nv_addsub
, 0, 0},
265 {Ctrl_Y
, nv_scroll_line
, 0, FALSE
},
266 {Ctrl_Z
, nv_suspend
, 0, 0},
267 {ESC
, nv_esc
, 0, FALSE
},
268 {Ctrl_BSL
, nv_normal
, NV_NCH_ALW
, 0},
269 {Ctrl_RSB
, nv_ident
, NV_NCW
, 0},
270 {Ctrl_HAT
, nv_hat
, NV_NCW
, 0},
271 {Ctrl__
, nv_error
, 0, 0},
272 {' ', nv_right
, 0, 0},
273 {'!', nv_operator
, 0, 0},
274 {'"', nv_regname
, NV_NCH_NOP
|NV_KEEPREG
, 0},
275 {'#', nv_ident
, 0, 0},
276 {'$', nv_dollar
, 0, 0},
277 {'%', nv_percent
, 0, 0},
278 {'&', nv_optrans
, 0, 0},
279 {'\'', nv_gomark
, NV_NCH_ALW
, TRUE
},
280 {'(', nv_brace
, 0, BACKWARD
},
281 {')', nv_brace
, 0, FORWARD
},
282 {'*', nv_ident
, 0, 0},
283 {'+', nv_down
, 0, TRUE
},
284 {',', nv_csearch
, 0, TRUE
},
285 {'-', nv_up
, 0, TRUE
},
286 {'.', nv_dot
, NV_KEEPREG
, 0},
287 {'/', nv_search
, 0, FALSE
},
288 {'0', nv_beginline
, 0, 0},
289 {'1', nv_ignore
, 0, 0},
290 {'2', nv_ignore
, 0, 0},
291 {'3', nv_ignore
, 0, 0},
292 {'4', nv_ignore
, 0, 0},
293 {'5', nv_ignore
, 0, 0},
294 {'6', nv_ignore
, 0, 0},
295 {'7', nv_ignore
, 0, 0},
296 {'8', nv_ignore
, 0, 0},
297 {'9', nv_ignore
, 0, 0},
298 {':', nv_colon
, 0, 0},
299 {';', nv_csearch
, 0, FALSE
},
300 {'<', nv_operator
, NV_RL
, 0},
301 {'=', nv_operator
, 0, 0},
302 {'>', nv_operator
, NV_RL
, 0},
303 {'?', nv_search
, 0, FALSE
},
304 {'@', nv_at
, NV_NCH_NOP
, FALSE
},
305 {'A', nv_edit
, 0, 0},
306 {'B', nv_bck_word
, 0, 1},
307 {'C', nv_abbrev
, NV_KEEPREG
, 0},
308 {'D', nv_abbrev
, NV_KEEPREG
, 0},
309 {'E', nv_wordcmd
, 0, TRUE
},
310 {'F', nv_csearch
, NV_NCH_ALW
|NV_LANG
, BACKWARD
},
311 {'G', nv_goto
, 0, TRUE
},
312 {'H', nv_scroll
, 0, 0},
313 {'I', nv_edit
, 0, 0},
314 {'J', nv_join
, 0, 0},
315 {'K', nv_ident
, 0, 0},
316 {'L', nv_scroll
, 0, 0},
317 {'M', nv_scroll
, 0, 0},
318 {'N', nv_next
, 0, SEARCH_REV
},
319 {'O', nv_open
, 0, 0},
321 {'Q', nv_exmode
, NV_NCW
, 0},
322 {'R', nv_Replace
, 0, FALSE
},
323 {'S', nv_subst
, NV_KEEPREG
, 0},
324 {'T', nv_csearch
, NV_NCH_ALW
|NV_LANG
, BACKWARD
},
325 {'U', nv_Undo
, 0, 0},
326 {'W', nv_wordcmd
, 0, TRUE
},
327 {'X', nv_abbrev
, NV_KEEPREG
, 0},
328 {'Y', nv_abbrev
, NV_KEEPREG
, 0},
329 {'Z', nv_Zet
, NV_NCH_NOP
|NV_NCW
, 0},
330 {'[', nv_brackets
, NV_NCH_ALW
, BACKWARD
},
331 {'\\', nv_error
, 0, 0},
332 {']', nv_brackets
, NV_NCH_ALW
, FORWARD
},
333 {'^', nv_beginline
, 0, BL_WHITE
| BL_FIX
},
334 {'_', nv_lineop
, 0, 0},
335 {'`', nv_gomark
, NV_NCH_ALW
, FALSE
},
336 {'a', nv_edit
, NV_NCH
, 0},
337 {'b', nv_bck_word
, 0, 0},
338 {'c', nv_operator
, 0, 0},
339 {'d', nv_operator
, 0, 0},
340 {'e', nv_wordcmd
, 0, FALSE
},
341 {'f', nv_csearch
, NV_NCH_ALW
|NV_LANG
, FORWARD
},
342 {'g', nv_g_cmd
, NV_NCH_ALW
, FALSE
},
343 {'h', nv_left
, NV_RL
, 0},
344 {'i', nv_edit
, NV_NCH
, 0},
345 {'j', nv_down
, 0, FALSE
},
346 {'k', nv_up
, 0, FALSE
},
347 {'l', nv_right
, NV_RL
, 0},
348 {'m', nv_mark
, NV_NCH_NOP
, 0},
349 {'n', nv_next
, 0, 0},
350 {'o', nv_open
, 0, 0},
352 {'q', nv_record
, NV_NCH
, 0},
353 {'r', nv_replace
, NV_NCH_NOP
|NV_LANG
, 0},
354 {'s', nv_subst
, NV_KEEPREG
, 0},
355 {'t', nv_csearch
, NV_NCH_ALW
|NV_LANG
, FORWARD
},
356 {'u', nv_undo
, 0, 0},
357 {'w', nv_wordcmd
, 0, FALSE
},
358 {'x', nv_abbrev
, NV_KEEPREG
, 0},
359 {'y', nv_operator
, 0, 0},
360 {'z', nv_zet
, NV_NCH_ALW
, 0},
361 {'{', nv_findpar
, 0, BACKWARD
},
362 {'|', nv_pipe
, 0, 0},
363 {'}', nv_findpar
, 0, FORWARD
},
364 {'~', nv_tilde
, 0, 0},
367 {POUND
, nv_ident
, 0, 0},
369 {K_MOUSEUP
, nv_mousescroll
, 0, TRUE
},
370 {K_MOUSEDOWN
, nv_mousescroll
, 0, FALSE
},
371 {K_LEFTMOUSE
, nv_mouse
, 0, 0},
372 {K_LEFTMOUSE_NM
, nv_mouse
, 0, 0},
373 {K_LEFTDRAG
, nv_mouse
, 0, 0},
374 {K_LEFTRELEASE
, nv_mouse
, 0, 0},
375 {K_LEFTRELEASE_NM
, nv_mouse
, 0, 0},
376 {K_MIDDLEMOUSE
, nv_mouse
, 0, 0},
377 {K_MIDDLEDRAG
, nv_mouse
, 0, 0},
378 {K_MIDDLERELEASE
, nv_mouse
, 0, 0},
379 {K_RIGHTMOUSE
, nv_mouse
, 0, 0},
380 {K_RIGHTDRAG
, nv_mouse
, 0, 0},
381 {K_RIGHTRELEASE
, nv_mouse
, 0, 0},
382 {K_X1MOUSE
, nv_mouse
, 0, 0},
383 {K_X1DRAG
, nv_mouse
, 0, 0},
384 {K_X1RELEASE
, nv_mouse
, 0, 0},
385 {K_X2MOUSE
, nv_mouse
, 0, 0},
386 {K_X2DRAG
, nv_mouse
, 0, 0},
387 {K_X2RELEASE
, nv_mouse
, 0, 0},
389 {K_IGNORE
, nv_ignore
, NV_KEEPREG
, 0},
390 {K_NOP
, nv_nop
, 0, 0},
391 {K_INS
, nv_edit
, 0, 0},
392 {K_KINS
, nv_edit
, 0, 0},
393 {K_BS
, nv_ctrlh
, 0, 0},
394 {K_UP
, nv_up
, NV_SSS
|NV_STS
, FALSE
},
395 {K_S_UP
, nv_page
, NV_SS
, BACKWARD
},
396 {K_DOWN
, nv_down
, NV_SSS
|NV_STS
, FALSE
},
397 {K_S_DOWN
, nv_page
, NV_SS
, FORWARD
},
398 {K_LEFT
, nv_left
, NV_SSS
|NV_STS
|NV_RL
, 0},
399 {K_S_LEFT
, nv_bck_word
, NV_SS
|NV_RL
, 0},
400 {K_C_LEFT
, nv_bck_word
, NV_SSS
|NV_RL
|NV_STS
, 1},
401 {K_RIGHT
, nv_right
, NV_SSS
|NV_STS
|NV_RL
, 0},
402 {K_S_RIGHT
, nv_wordcmd
, NV_SS
|NV_RL
, FALSE
},
403 {K_C_RIGHT
, nv_wordcmd
, NV_SSS
|NV_RL
|NV_STS
, TRUE
},
404 {K_PAGEUP
, nv_page
, NV_SSS
|NV_STS
, BACKWARD
},
405 {K_KPAGEUP
, nv_page
, NV_SSS
|NV_STS
, BACKWARD
},
406 {K_PAGEDOWN
, nv_page
, NV_SSS
|NV_STS
, FORWARD
},
407 {K_KPAGEDOWN
, nv_page
, NV_SSS
|NV_STS
, FORWARD
},
408 {K_END
, nv_end
, NV_SSS
|NV_STS
, FALSE
},
409 {K_KEND
, nv_end
, NV_SSS
|NV_STS
, FALSE
},
410 {K_S_END
, nv_end
, NV_SS
, FALSE
},
411 {K_C_END
, nv_end
, NV_SSS
|NV_STS
, TRUE
},
412 {K_HOME
, nv_home
, NV_SSS
|NV_STS
, 0},
413 {K_KHOME
, nv_home
, NV_SSS
|NV_STS
, 0},
414 {K_S_HOME
, nv_home
, NV_SS
, 0},
415 {K_C_HOME
, nv_goto
, NV_SSS
|NV_STS
, FALSE
},
416 {K_DEL
, nv_abbrev
, 0, 0},
417 {K_KDEL
, nv_abbrev
, 0, 0},
418 {K_UNDO
, nv_kundo
, 0, 0},
419 {K_HELP
, nv_help
, NV_NCW
, 0},
420 {K_F1
, nv_help
, NV_NCW
, 0},
421 {K_XF1
, nv_help
, NV_NCW
, 0},
423 {K_SELECT
, nv_select
, 0, 0},
426 {K_VER_SCROLLBAR
, nv_ver_scrollbar
, 0, 0},
427 {K_HOR_SCROLLBAR
, nv_hor_scrollbar
, 0, 0},
429 #ifdef FEAT_GUI_TABLINE
430 {K_TABLINE
, nv_tabline
, 0, 0},
431 {K_TABMENU
, nv_tabmenu
, 0, 0},
434 {K_F8
, farsi_fkey
, 0, 0},
435 {K_F9
, farsi_fkey
, 0, 0},
438 {K_SNIFF
, nv_sniff
, 0, 0},
440 #ifdef FEAT_NETBEANS_INTG
441 {K_F21
, nv_nbcmd
, NV_NCH_ALW
, 0},
444 {K_DROP
, nv_drop
, NV_STS
, 0},
447 {K_CURSORHOLD
, nv_cursorhold
, NV_KEEPREG
, 0},
451 /* Number of commands in nv_cmds[]. */
452 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd))
454 /* Sorted index of commands in nv_cmds[]. */
455 static short nv_cmd_idx
[NV_CMDS_SIZE
];
457 /* The highest index for which
458 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */
459 static int nv_max_linear
;
462 * Compare functions for qsort() below, that checks the command character
463 * through the index in nv_cmd_idx[].
475 /* The commands are sorted on absolute value. */
476 c1
= nv_cmds
[*(const short *)s1
].cmd_char
;
477 c2
= nv_cmds
[*(const short *)s2
].cmd_char
;
486 * Initialize the nv_cmd_idx[] table.
493 /* Fill the index table with a one to one relation. */
494 for (i
= 0; i
< NV_CMDS_SIZE
; ++i
)
497 /* Sort the commands by the command character. */
498 qsort((void *)&nv_cmd_idx
, (size_t)NV_CMDS_SIZE
, sizeof(short), nv_compare
);
500 /* Find the first entry that can't be indexed by the command character. */
501 for (i
= 0; i
< NV_CMDS_SIZE
; ++i
)
502 if (i
!= nv_cmds
[nv_cmd_idx
[i
]].cmd_char
)
504 nv_max_linear
= i
- 1;
508 * Search for a command in the commands table.
509 * Returns -1 for invalid command.
512 find_command(cmdchar
)
521 /* A multi-byte character is never a command. */
522 if (cmdchar
>= 0x100)
526 /* We use the absolute value of the character. Special keys have a
527 * negative value, but are sorted on their absolute value. */
531 /* If the character is in the first part: The character is the index into
533 if (cmdchar
<= nv_max_linear
)
534 return nv_cmd_idx
[cmdchar
];
536 /* Perform a binary search. */
537 bot
= nv_max_linear
+ 1;
538 top
= NV_CMDS_SIZE
- 1;
543 c
= nv_cmds
[nv_cmd_idx
[i
]].cmd_char
;
560 * Execute a command in Normal mode.
564 normal_cmd(oap
, toplevel
)
566 int toplevel
; /* TRUE when called from main() */
568 cmdarg_T ca
; /* command arguments */
570 int ctrl_w
= FALSE
; /* got CTRL-W command */
571 int old_col
= curwin
->w_curswant
;
572 #ifdef FEAT_CMDL_INFO
573 int need_flushbuf
; /* need to call out_flush() */
576 pos_T old_pos
; /* cursor position before command */
578 static int old_mapped_len
= 0;
582 vim_memset(&ca
, 0, sizeof(ca
)); /* also resets ca.retval */
585 /* Use a count remembered from before entering an operator. After typing
586 * "3d" we return from normal_cmd() and come back here, the "3" is
587 * remembered in "opcount". */
588 ca
.opcount
= opcount
;
591 want_sniff_request
= sniff_connected
;
595 * If there is an operator pending, then the command we take this time
596 * will terminate it. Finish_op tells us to finish the operation before
597 * returning this time (unless the operation was cancelled).
602 finish_op
= (oap
->op_type
!= OP_NOP
);
606 ui_cursor_shape(); /* may show different cursor shape */
607 # ifdef FEAT_MOUSESHAPE
608 update_mouseshape(-1);
613 /* When not finishing an operator and no register name typed, reset the
615 if (!finish_op
&& !oap
->regname
)
619 /* Restore counts from before receiving K_CURSORHOLD. This means after
620 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not
622 if (oap
->prev_opcount
> 0 || oap
->prev_count0
> 0)
624 ca
.opcount
= oap
->prev_opcount
;
625 ca
.count0
= oap
->prev_count0
;
626 oap
->prev_opcount
= 0;
627 oap
->prev_count0
= 0;
632 mapped_len
= typebuf_maplen();
636 #ifdef USE_ON_FLY_SCROLL
637 dont_scroll
= FALSE
; /* allow scrolling here */
641 * Get the command character from the user.
646 LANGMAP_ADJUST(c
, TRUE
);
651 * If a mapping was started in Visual or Select mode, remember the length
652 * of the mapping. This is used below to not return to Insert mode for as
653 * long as the mapping is being executed.
655 if (restart_edit
== 0)
657 else if (old_mapped_len
658 || (VIsual_active
&& mapped_len
== 0 && typebuf_maplen() > 0))
659 old_mapped_len
= typebuf_maplen();
667 * In Select mode, typed text replaces the selection.
671 && (vim_isprintc(c
) || c
== NL
|| c
== CAR
|| c
== K_KENTER
))
673 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because
674 * 'insertmode' is set) fake a "d"elete command, Insert mode will
675 * restart automatically.
676 * Insert the typed character in the typeahead buffer, so that it can
677 * be mapped in Insert mode. Required for ":lmap" to work. */
679 if (restart_edit
!= 0)
683 msg_nowait
= TRUE
; /* don't delay going to insert mode */
687 #ifdef FEAT_CMDL_INFO
688 need_flushbuf
= add_to_showcmd(c
);
693 if (!(VIsual_active
&& VIsual_select
))
697 * Handle a count before a command and compute ca.count0.
698 * Note that '0' is a command and not the start of a count, but it's
699 * part of a count after other digits.
701 while ( (c
>= '1' && c
<= '9')
702 || (ca
.count0
!= 0 && (c
== K_DEL
|| c
== K_KDEL
|| c
== '0')))
704 if (c
== K_DEL
|| c
== K_KDEL
)
707 #ifdef FEAT_CMDL_INFO
708 del_from_showcmd(4); /* delete the digit and ~@% */
712 ca
.count0
= ca
.count0
* 10 + (c
- '0');
713 if (ca
.count0
< 0) /* got too large! */
714 ca
.count0
= 999999999L;
716 /* Set v:count here, when called from main() and not a stuffed
717 * command, so that v:count can be used in an expression mapping
718 * right after the count. */
719 if (toplevel
&& stuff_empty())
720 set_vcount(ca
.count0
, ca
.count0
== 0 ? 1 : ca
.count0
);
725 ++allow_keys
; /* no mapping for nchar, but keys */
727 ++no_zero_mapping
; /* don't map zero here */
730 LANGMAP_ADJUST(c
, TRUE
);
738 #ifdef FEAT_CMDL_INFO
739 need_flushbuf
|= add_to_showcmd(c
);
744 * If we got CTRL-W there may be a/another count
746 if (c
== Ctrl_W
&& !ctrl_w
&& oap
->op_type
== OP_NOP
)
749 ca
.opcount
= ca
.count0
; /* remember first count */
752 ++allow_keys
; /* no mapping for nchar, but keys */
753 c
= plain_vgetc(); /* get next character */
755 LANGMAP_ADJUST(c
, TRUE
);
759 #ifdef FEAT_CMDL_INFO
760 need_flushbuf
|= add_to_showcmd(c
);
762 goto getcount
; /* jump back */
767 if (c
== K_CURSORHOLD
)
769 /* Save the count values so that ca.opcount and ca.count0 are exactly
770 * the same when coming back here after handling K_CURSORHOLD. */
771 oap
->prev_opcount
= ca
.opcount
;
772 oap
->prev_count0
= ca
.count0
;
779 * If we're in the middle of an operator (including after entering a
780 * yank buffer with '"') AND we had a count before the operator, then
781 * that count overrides the current value of ca.count0.
782 * What this means effectively, is that commands like "3dw" get turned
783 * into "d3w" which makes things fall into place pretty neatly.
784 * If you give a count before AND after the operator, they are
788 ca
.count0
*= ca
.opcount
;
790 ca
.count0
= ca
.opcount
;
794 * Always remember the count. It will be set to zero (on the next call,
795 * above) when there is no pending operator.
796 * When called from main(), save the count for use by the "count" built-in
799 ca
.opcount
= ca
.count0
;
800 ca
.count1
= (ca
.count0
== 0 ? 1 : ca
.count0
);
804 * Only set v:count when called from main() and not a stuffed command.
806 if (toplevel
&& stuff_empty())
807 set_vcount(ca
.count0
, ca
.count1
);
811 * Find the command character in the table of commands.
812 * For CTRL-W we already got nchar when looking for a count.
821 idx
= find_command(ca
.cmdchar
);
824 /* Not a known command: beep. */
829 if (text_locked() && (nv_cmds
[idx
].cmd_flags
& NV_NCW
))
831 /* This command is not allowed while editing a ccmdline: beep. */
837 if ((nv_cmds
[idx
].cmd_flags
& NV_NCW
) && curbuf_locked())
843 * In Visual/Select mode, a few keys are handled in a special way.
847 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */
849 && (nv_cmds
[idx
].cmd_flags
& NV_STS
)
850 && !(mod_mask
& MOD_MASK_SHIFT
))
853 redraw_curbuf_later(INVERTED
);
856 /* Keys that work different when 'keymodel' contains "startsel" */
859 if (nv_cmds
[idx
].cmd_flags
& NV_SS
)
861 unshift_special(&ca
);
862 idx
= find_command(ca
.cmdchar
);
870 else if ((nv_cmds
[idx
].cmd_flags
& NV_SSS
)
871 && (mod_mask
& MOD_MASK_SHIFT
))
873 mod_mask
&= ~MOD_MASK_SHIFT
;
879 #ifdef FEAT_RIGHTLEFT
880 if (curwin
->w_p_rl
&& KeyTyped
&& !KeyStuffed
881 && (nv_cmds
[idx
].cmd_flags
& NV_RL
))
883 /* Invert horizontal movements and operations. Only when typed by the
884 * user directly, not when the result of a mapping or "x" translated
888 case 'l': ca
.cmdchar
= 'h'; break;
889 case K_RIGHT
: ca
.cmdchar
= K_LEFT
; break;
890 case K_S_RIGHT
: ca
.cmdchar
= K_S_LEFT
; break;
891 case K_C_RIGHT
: ca
.cmdchar
= K_C_LEFT
; break;
892 case 'h': ca
.cmdchar
= 'l'; break;
893 case K_LEFT
: ca
.cmdchar
= K_RIGHT
; break;
894 case K_S_LEFT
: ca
.cmdchar
= K_S_RIGHT
; break;
895 case K_C_LEFT
: ca
.cmdchar
= K_C_RIGHT
; break;
896 case '>': ca
.cmdchar
= '<'; break;
897 case '<': ca
.cmdchar
= '>'; break;
899 idx
= find_command(ca
.cmdchar
);
904 * Get an additional character if we need one.
906 if ((nv_cmds
[idx
].cmd_flags
& NV_NCH
)
907 && (((nv_cmds
[idx
].cmd_flags
& NV_NCH_NOP
) == NV_NCH_NOP
908 && oap
->op_type
== OP_NOP
)
909 || (nv_cmds
[idx
].cmd_flags
& NV_NCH_ALW
) == NV_NCH_ALW
910 || (ca
.cmdchar
== 'q'
911 && oap
->op_type
== OP_NOP
914 || ((ca
.cmdchar
== 'a' || ca
.cmdchar
== 'i')
915 && (oap
->op_type
!= OP_NOP
922 int repl
= FALSE
; /* get character for replace mode */
923 int lit
= FALSE
; /* get extra character literally */
924 int langmap_active
= FALSE
; /* using :lmap mappings */
925 int lang
; /* getting a text character */
926 #ifdef USE_IM_CONTROL
927 int save_smd
; /* saved value of p_smd */
931 ++allow_keys
; /* no mapping for nchar, but allow key codes */
933 /* Don't generate a CursorHold event here, most commands can't handle
934 * it, e.g., nv_replace(), nv_csearch(). */
935 did_cursorhold
= TRUE
;
937 if (ca
.cmdchar
== 'g')
940 * For 'g' get the next character now, so that we can check for
941 * "gr", "g'" and "g`".
943 ca
.nchar
= plain_vgetc();
945 LANGMAP_ADJUST(ca
.nchar
, TRUE
);
947 #ifdef FEAT_CMDL_INFO
948 need_flushbuf
|= add_to_showcmd(ca
.nchar
);
950 if (ca
.nchar
== 'r' || ca
.nchar
== '\'' || ca
.nchar
== '`'
951 || ca
.nchar
== Ctrl_BSL
)
953 cp
= &ca
.extra_char
; /* need to get a third character */
955 lit
= TRUE
; /* get it literally */
957 repl
= TRUE
; /* get it in replace mode */
960 cp
= NULL
; /* no third character needed */
964 if (ca
.cmdchar
== 'r') /* get it in replace mode */
968 lang
= (repl
|| (nv_cmds
[idx
].cmd_flags
& NV_LANG
));
971 * Get a second or third character.
978 State
= REPLACE
; /* pretend Replace mode */
979 ui_cursor_shape(); /* show different cursor shape */
982 if (lang
&& curbuf
->b_p_iminsert
== B_IMODE_LMAP
)
984 /* Allow mappings defined with ":lmap". */
991 langmap_active
= TRUE
;
993 #ifdef USE_IM_CONTROL
995 p_smd
= FALSE
; /* Don't let the IM code show the mode here */
996 if (lang
&& curbuf
->b_p_iminsert
== B_IMODE_IM
)
1000 *cp
= plain_vgetc();
1004 /* Undo the decrement done above */
1007 State
= NORMAL_BUSY
;
1009 #ifdef USE_IM_CONTROL
1012 if (curbuf
->b_p_iminsert
!= B_IMODE_LMAP
)
1013 im_save_status(&curbuf
->b_p_iminsert
);
1014 im_set_active(FALSE
);
1019 State
= NORMAL_BUSY
;
1021 #ifdef FEAT_CMDL_INFO
1022 need_flushbuf
|= add_to_showcmd(*cp
);
1027 #ifdef FEAT_DIGRAPHS
1028 /* Typing CTRL-K gets a digraph. */
1030 && ((nv_cmds
[idx
].cmd_flags
& NV_LANG
)
1031 || cp
== &ca
.extra_char
)
1032 && vim_strchr(p_cpo
, CPO_DIGRAPH
) == NULL
)
1034 c
= get_digraph(FALSE
);
1038 # ifdef FEAT_CMDL_INFO
1039 /* Guessing how to update showcmd here... */
1040 del_from_showcmd(3);
1041 need_flushbuf
|= add_to_showcmd(*cp
);
1048 /* adjust chars > 127, except after "tTfFr" commands */
1049 LANGMAP_ADJUST(*cp
, !lang
);
1051 #ifdef FEAT_RIGHTLEFT
1052 /* adjust Hebrew mapped char */
1053 if (p_hkmap
&& lang
&& KeyTyped
)
1056 /* adjust Farsi mapped char */
1057 if (p_fkmap
&& lang
&& KeyTyped
)
1064 * When the next character is CTRL-\ a following CTRL-N means the
1065 * command is aborted and we go to Normal mode.
1067 if (cp
== &ca
.extra_char
1068 && ca
.nchar
== Ctrl_BSL
1069 && (ca
.extra_char
== Ctrl_N
|| ca
.extra_char
== Ctrl_G
))
1071 ca
.cmdchar
= Ctrl_BSL
;
1072 ca
.nchar
= ca
.extra_char
;
1073 idx
= find_command(ca
.cmdchar
);
1075 else if (*cp
== Ctrl_BSL
)
1077 long towait
= (p_ttm
>= 0 ? p_ttm
: p_tm
);
1079 /* There is a busy wait here when typing "f<C-\>" and then
1080 * something different from CTRL-N. Can't be avoided. */
1081 while ((c
= vpeekc()) <= 0 && towait
> 0L)
1083 do_sleep(towait
> 50L ? 50L : towait
);
1089 if (c
!= Ctrl_N
&& c
!= Ctrl_G
)
1093 ca
.cmdchar
= Ctrl_BSL
;
1095 idx
= find_command(ca
.cmdchar
);
1101 /* When getting a text character and the next character is a
1102 * multi-byte character, it could be a composing character.
1103 * However, don't wait for it to arrive. */
1104 while (enc_utf8
&& lang
&& (c
= vpeekc()) > 0
1105 && (c
>= 0x100 || MB_BYTE2LEN(vpeekc()) > 1))
1108 if (!utf_iscomposing(c
))
1110 vungetc(c
); /* it wasn't, put it back */
1113 else if (ca
.ncharC1
== 0)
1124 #ifdef FEAT_CMDL_INFO
1126 * Flush the showcmd characters onto the screen so we can see them while
1127 * the command is being executed. Only do this when the shown command was
1128 * actually displayed, otherwise this will slow down a lot when executing
1135 did_cursorhold
= FALSE
;
1140 if (ca
.nchar
== ESC
)
1143 if (restart_edit
== 0 && goto_im())
1148 if (ca
.cmdchar
!= K_IGNORE
)
1150 msg_didout
= FALSE
; /* don't scroll screen up for normal command */
1155 old_pos
= curwin
->w_cursor
; /* remember where cursor was */
1157 /* When 'keymodel' contains "startsel" some keys start Select/Visual
1159 if (!VIsual_active
&& km_startsel
)
1161 if (nv_cmds
[idx
].cmd_flags
& NV_SS
)
1164 unshift_special(&ca
);
1165 idx
= find_command(ca
.cmdchar
);
1167 else if ((nv_cmds
[idx
].cmd_flags
& NV_SSS
)
1168 && (mod_mask
& MOD_MASK_SHIFT
))
1171 mod_mask
&= ~MOD_MASK_SHIFT
;
1177 * Execute the command!
1178 * Call the command function found in the commands table.
1180 ca
.arg
= nv_cmds
[idx
].cmd_arg
;
1181 (nv_cmds
[idx
].cmd_func
)(&ca
);
1184 * If we didn't start or finish an operator, reset oap->regname, unless we
1189 && (idx
< 0 || !(nv_cmds
[idx
].cmd_flags
& NV_KEEPREG
)))
1198 /* Get the length of mapped chars again after typing a count, second
1199 * character or "z333<cr>". */
1200 if (old_mapped_len
> 0)
1201 old_mapped_len
= typebuf_maplen();
1205 * If an operation is pending, handle it...
1207 do_pending_operator(&ca
, old_col
, FALSE
);
1210 * Wait for a moment when a message is displayed that will be overwritten
1211 * by the mode message.
1212 * In Visual mode and with "^O" in Insert mode, a short message will be
1213 * overwritten by the mode message. Wait a bit, until a key is hit.
1214 * In Visual mode, it's more important to keep the Visual area updated
1215 * than keeping a message (e.g. from a /pat search).
1216 * Only do this if the command was typed, not from a mapping.
1217 * Don't wait when emsg_silent is non-zero.
1218 * Also wait a bit after an error message, e.g. for "^O:".
1219 * Don't redraw the screen, it would remove the message.
1223 && (restart_edit
!= 0
1226 && old_pos
.lnum
== curwin
->w_cursor
.lnum
1227 && old_pos
.col
== curwin
->w_cursor
.col
)
1232 && (msg_didout
|| (msg_didany
&& msg_scroll
))
1235 || (restart_edit
!= 0
1240 || emsg_on_display
)))
1241 && oap
->regname
== 0
1242 && !(ca
.retval
& CA_COMMAND_BUSY
)
1247 && oap
->op_type
== OP_NOP
)
1249 int save_State
= State
;
1251 /* Draw the cursor with the right shape here */
1252 if (restart_edit
!= 0)
1255 /* If need to redraw, and there is a "keep_msg", redraw before the
1257 if (must_redraw
&& keep_msg
!= NULL
&& !emsg_on_display
)
1263 /* showmode() will clear keep_msg, but we want to use it anyway */
1265 /* now reset it, otherwise it's put in the history again */
1267 msg_attr(kmsg
, keep_msg_attr
);
1273 if (msg_scroll
|| emsg_on_display
)
1274 ui_delay(1000L, TRUE
); /* wait at least one second */
1275 ui_delay(3000L, FALSE
); /* wait up to three seconds */
1279 emsg_on_display
= FALSE
;
1283 * Finish up after executing a Normal mode command.
1289 /* Reset finish_op, in case it was set */
1295 /* Redraw the cursor with another shape, if we were in Operator-pending
1296 * mode or did a replace command. */
1297 if (c
|| ca
.cmdchar
== 'r')
1299 ui_cursor_shape(); /* may show different cursor shape */
1300 # ifdef FEAT_MOUSESHAPE
1301 update_mouseshape(-1);
1306 #ifdef FEAT_CMDL_INFO
1307 if (oap
->op_type
== OP_NOP
&& oap
->regname
== 0
1308 # ifdef FEAT_AUTOCMD
1309 && ca
.cmdchar
!= K_CURSORHOLD
1315 checkpcmark(); /* check if we moved since setting pcmark */
1316 vim_free(ca
.searchbuf
);
1323 #ifdef FEAT_SCROLLBIND
1324 if (curwin
->w_p_scb
&& toplevel
)
1326 validate_cursor(); /* may need to update w_leftcol */
1327 do_check_scrollbind(TRUE
);
1332 * May restart edit(), if we got here with CTRL-O in Insert mode (but not
1333 * if still inside a mapping that started in Visual mode).
1334 * May switch from Visual to Select mode after CTRL-O command.
1336 if ( oap
->op_type
== OP_NOP
1338 && ((restart_edit
!= 0 && !VIsual_active
&& old_mapped_len
== 0)
1339 || restart_VIsual_select
== 1)
1341 && restart_edit
!= 0
1343 && !(ca
.retval
& CA_COMMAND_BUSY
)
1345 && oap
->regname
== 0)
1348 if (restart_VIsual_select
== 1)
1350 VIsual_select
= TRUE
;
1352 restart_VIsual_select
= 0;
1355 if (restart_edit
!= 0
1357 && !VIsual_active
&& old_mapped_len
== 0
1360 (void)edit(restart_edit
, FALSE
, 1L);
1364 if (restart_VIsual_select
== 2)
1365 restart_VIsual_select
= 1;
1368 /* Save count before an operator for next time. */
1369 opcount
= ca
.opcount
;
1373 * Handle an operator after visual mode or when the movement is finished
1376 do_pending_operator(cap
, old_col
, gui_yank
)
1381 oparg_T
*oap
= cap
->oap
;
1383 int empty_region_error
;
1384 int restart_edit_save
;
1387 /* The visual area is remembered for redo */
1388 static int redo_VIsual_mode
= NUL
; /* 'v', 'V', or Ctrl-V */
1389 static linenr_T redo_VIsual_line_count
; /* number of lines */
1390 static colnr_T redo_VIsual_col
; /* number of cols or end column */
1391 static long redo_VIsual_count
; /* count for Visual operator */
1392 # ifdef FEAT_VIRTUALEDIT
1393 int include_line_break
= FALSE
;
1397 #if defined(FEAT_CLIPBOARD)
1399 * Yank the visual area into the GUI selection register before we operate
1400 * on it and lose it forever.
1401 * Don't do it if a specific register was specified, so that ""x"*P works.
1402 * This could call do_pending_operator() recursively, but that's OK
1403 * because gui_yank will be TRUE for the nested call.
1405 if (clip_star
.available
1406 && oap
->op_type
!= OP_NOP
1410 && !redo_VIsual_busy
1412 && oap
->regname
== 0)
1415 old_cursor
= curwin
->w_cursor
;
1418 * If an operation is pending, handle it...
1424 ) && oap
->op_type
!= OP_NOP
)
1427 oap
->is_VIsual
= VIsual_active
;
1428 if (oap
->motion_force
== 'V')
1429 oap
->motion_type
= MLINE
;
1430 else if (oap
->motion_force
== 'v')
1432 /* If the motion was linewise, "inclusive" will not have been set.
1433 * Use "exclusive" to be consistent. Makes "dvj" work nice. */
1434 if (oap
->motion_type
== MLINE
)
1435 oap
->inclusive
= FALSE
;
1436 /* If the motion already was characterwise, toggle "inclusive" */
1437 else if (oap
->motion_type
== MCHAR
)
1438 oap
->inclusive
= !oap
->inclusive
;
1439 oap
->motion_type
= MCHAR
;
1441 else if (oap
->motion_force
== Ctrl_V
)
1443 /* Change line- or characterwise motion into Visual block mode. */
1444 VIsual_active
= TRUE
;
1445 VIsual
= oap
->start
;
1446 VIsual_mode
= Ctrl_V
;
1447 VIsual_select
= FALSE
;
1448 VIsual_reselect
= FALSE
;
1452 /* only redo yank when 'y' flag is in 'cpoptions' */
1453 /* never redo "zf" (define fold) */
1454 if ((vim_strchr(p_cpo
, CPO_YANK
) != NULL
|| oap
->op_type
!= OP_YANK
)
1456 && (!VIsual_active
|| oap
->motion_force
)
1458 && cap
->cmdchar
!= 'D'
1460 && oap
->op_type
!= OP_FOLD
1461 && oap
->op_type
!= OP_FOLDOPEN
1462 && oap
->op_type
!= OP_FOLDOPENREC
1463 && oap
->op_type
!= OP_FOLDCLOSE
1464 && oap
->op_type
!= OP_FOLDCLOSEREC
1465 && oap
->op_type
!= OP_FOLDDEL
1466 && oap
->op_type
!= OP_FOLDDELREC
1470 prep_redo(oap
->regname
, cap
->count0
,
1471 get_op_char(oap
->op_type
), get_extra_op_char(oap
->op_type
),
1472 oap
->motion_force
, cap
->cmdchar
, cap
->nchar
);
1473 if (cap
->cmdchar
== '/' || cap
->cmdchar
== '?') /* was a search */
1476 * If 'cpoptions' does not contain 'r', insert the search
1477 * pattern to really repeat the same command.
1479 if (vim_strchr(p_cpo
, CPO_REDO
) == NULL
)
1480 AppendToRedobuffLit(cap
->searchbuf
, -1);
1481 AppendToRedobuff(NL_STR
);
1483 else if (cap
->cmdchar
== ':')
1485 /* do_cmdline() has stored the first typed line in
1486 * "repeat_cmdline". When several lines are typed repeating
1487 * won't be possible. */
1488 if (repeat_cmdline
== NULL
)
1492 AppendToRedobuffLit(repeat_cmdline
, -1);
1493 AppendToRedobuff(NL_STR
);
1494 vim_free(repeat_cmdline
);
1495 repeat_cmdline
= NULL
;
1501 if (redo_VIsual_busy
)
1503 oap
->start
= curwin
->w_cursor
;
1504 curwin
->w_cursor
.lnum
+= redo_VIsual_line_count
- 1;
1505 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
1506 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
1507 VIsual_mode
= redo_VIsual_mode
;
1508 if (VIsual_mode
== 'v')
1510 if (redo_VIsual_line_count
<= 1)
1511 curwin
->w_cursor
.col
+= redo_VIsual_col
- 1;
1513 curwin
->w_cursor
.col
= redo_VIsual_col
;
1515 if (redo_VIsual_col
== MAXCOL
)
1517 curwin
->w_curswant
= MAXCOL
;
1518 coladvance((colnr_T
)MAXCOL
);
1520 cap
->count0
= redo_VIsual_count
;
1521 if (redo_VIsual_count
!= 0)
1522 cap
->count1
= redo_VIsual_count
;
1526 else if (VIsual_active
)
1530 /* Save the current VIsual area for '< and '> marks, and "gv" */
1531 curbuf
->b_visual
.vi_start
= VIsual
;
1532 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
1533 curbuf
->b_visual
.vi_mode
= VIsual_mode
;
1534 curbuf
->b_visual
.vi_curswant
= curwin
->w_curswant
;
1536 curbuf
->b_visual_mode_eval
= VIsual_mode
;
1540 /* In Select mode, a linewise selection is operated upon like a
1541 * characterwise selection. */
1542 if (VIsual_select
&& VIsual_mode
== 'V')
1544 if (lt(VIsual
, curwin
->w_cursor
))
1547 curwin
->w_cursor
.col
=
1548 (colnr_T
)STRLEN(ml_get(curwin
->w_cursor
.lnum
));
1552 curwin
->w_cursor
.col
= 0;
1553 VIsual
.col
= (colnr_T
)STRLEN(ml_get(VIsual
.lnum
));
1557 /* If 'selection' is "exclusive", backup one character for
1558 * charwise selections. */
1559 else if (VIsual_mode
== 'v')
1561 # ifdef FEAT_VIRTUALEDIT
1562 include_line_break
=
1567 oap
->start
= VIsual
;
1568 if (VIsual_mode
== 'V')
1571 #endif /* FEAT_VISUAL */
1574 * Set oap->start to the first position of the operated text, oap->end
1575 * to the end of the operated text. w_cursor is equal to oap->start.
1577 if (lt(oap
->start
, curwin
->w_cursor
))
1580 /* Include folded lines completely. */
1583 if (hasFolding(oap
->start
.lnum
, &oap
->start
.lnum
, NULL
))
1585 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
,
1586 &curwin
->w_cursor
.lnum
))
1587 curwin
->w_cursor
.col
= (colnr_T
)STRLEN(ml_get_curline());
1590 oap
->end
= curwin
->w_cursor
;
1591 curwin
->w_cursor
= oap
->start
;
1593 /* w_virtcol may have been updated; if the cursor goes back to its
1594 * previous position w_virtcol becomes invalid and isn't updated
1596 curwin
->w_valid
&= ~VALID_VIRTCOL
;
1601 /* Include folded lines completely. */
1602 if (!VIsual_active
&& oap
->motion_type
== MLINE
)
1604 if (hasFolding(curwin
->w_cursor
.lnum
, &curwin
->w_cursor
.lnum
,
1606 curwin
->w_cursor
.col
= 0;
1607 if (hasFolding(oap
->start
.lnum
, NULL
, &oap
->start
.lnum
))
1608 oap
->start
.col
= (colnr_T
)STRLEN(ml_get(oap
->start
.lnum
));
1611 oap
->end
= oap
->start
;
1612 oap
->start
= curwin
->w_cursor
;
1615 oap
->line_count
= oap
->end
.lnum
- oap
->start
.lnum
+ 1;
1617 #ifdef FEAT_VIRTUALEDIT
1618 /* Set "virtual_op" before resetting VIsual_active. */
1619 virtual_op
= virtual_active();
1623 if (VIsual_active
|| redo_VIsual_busy
)
1625 if (VIsual_mode
== Ctrl_V
) /* block mode */
1629 oap
->block_mode
= TRUE
;
1631 getvvcol(curwin
, &(oap
->start
),
1632 &oap
->start_vcol
, NULL
, &oap
->end_vcol
);
1633 if (!redo_VIsual_busy
)
1635 getvvcol(curwin
, &(oap
->end
), &start
, NULL
, &end
);
1637 if (start
< oap
->start_vcol
)
1638 oap
->start_vcol
= start
;
1639 if (end
> oap
->end_vcol
)
1641 if (*p_sel
== 'e' && start
>= 1
1642 && start
- 1 >= oap
->end_vcol
)
1643 oap
->end_vcol
= start
- 1;
1645 oap
->end_vcol
= end
;
1649 /* if '$' was used, get oap->end_vcol from longest line */
1650 if (curwin
->w_curswant
== MAXCOL
)
1652 curwin
->w_cursor
.col
= MAXCOL
;
1654 for (curwin
->w_cursor
.lnum
= oap
->start
.lnum
;
1655 curwin
->w_cursor
.lnum
<= oap
->end
.lnum
;
1656 ++curwin
->w_cursor
.lnum
)
1658 getvvcol(curwin
, &curwin
->w_cursor
, NULL
, NULL
, &end
);
1659 if (end
> oap
->end_vcol
)
1660 oap
->end_vcol
= end
;
1663 else if (redo_VIsual_busy
)
1664 oap
->end_vcol
= oap
->start_vcol
+ redo_VIsual_col
- 1;
1666 * Correct oap->end.col and oap->start.col to be the
1667 * upper-left and lower-right corner of the block area.
1669 * (Actually, this does convert column positions into character
1672 curwin
->w_cursor
.lnum
= oap
->end
.lnum
;
1673 coladvance(oap
->end_vcol
);
1674 oap
->end
= curwin
->w_cursor
;
1676 curwin
->w_cursor
= oap
->start
;
1677 coladvance(oap
->start_vcol
);
1678 oap
->start
= curwin
->w_cursor
;
1681 if (!redo_VIsual_busy
&& !gui_yank
)
1684 * Prepare to reselect and redo Visual: this is based on the
1685 * size of the Visual text
1687 resel_VIsual_mode
= VIsual_mode
;
1688 if (curwin
->w_curswant
== MAXCOL
)
1689 resel_VIsual_col
= MAXCOL
;
1690 else if (VIsual_mode
== Ctrl_V
)
1691 resel_VIsual_col
= oap
->end_vcol
- oap
->start_vcol
+ 1;
1692 else if (oap
->line_count
> 1)
1693 resel_VIsual_col
= oap
->end
.col
;
1695 resel_VIsual_col
= oap
->end
.col
- oap
->start
.col
+ 1;
1696 resel_VIsual_line_count
= oap
->line_count
;
1699 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */
1700 if ((vim_strchr(p_cpo
, CPO_YANK
) != NULL
|| oap
->op_type
!= OP_YANK
)
1701 && oap
->op_type
!= OP_COLON
1703 && oap
->op_type
!= OP_FOLD
1704 && oap
->op_type
!= OP_FOLDOPEN
1705 && oap
->op_type
!= OP_FOLDOPENREC
1706 && oap
->op_type
!= OP_FOLDCLOSE
1707 && oap
->op_type
!= OP_FOLDCLOSEREC
1708 && oap
->op_type
!= OP_FOLDDEL
1709 && oap
->op_type
!= OP_FOLDDELREC
1711 && oap
->motion_force
== NUL
1714 /* Prepare for redoing. Only use the nchar field for "r",
1715 * otherwise it might be the second char of the operator. */
1716 prep_redo(oap
->regname
, 0L, NUL
, 'v',
1717 get_op_char(oap
->op_type
),
1718 get_extra_op_char(oap
->op_type
),
1719 oap
->op_type
== OP_REPLACE
? cap
->nchar
: NUL
);
1720 if (!redo_VIsual_busy
)
1722 redo_VIsual_mode
= resel_VIsual_mode
;
1723 redo_VIsual_col
= resel_VIsual_col
;
1724 redo_VIsual_line_count
= resel_VIsual_line_count
;
1725 redo_VIsual_count
= cap
->count0
;
1730 * oap->inclusive defaults to TRUE.
1731 * If oap->end is on a NUL (empty line) oap->inclusive becomes
1732 * FALSE. This makes "d}P" and "v}dP" work the same.
1734 if (oap
->motion_force
== NUL
|| oap
->motion_type
== MLINE
)
1735 oap
->inclusive
= TRUE
;
1736 if (VIsual_mode
== 'V')
1737 oap
->motion_type
= MLINE
;
1740 oap
->motion_type
= MCHAR
;
1741 if (VIsual_mode
!= Ctrl_V
&& *ml_get_pos(&(oap
->end
)) == NUL
1742 # ifdef FEAT_VIRTUALEDIT
1743 && (include_line_break
|| !virtual_op
)
1747 oap
->inclusive
= FALSE
;
1748 /* Try to include the newline, unless it's an operator
1749 * that works on lines only */
1751 && !op_on_lines(oap
->op_type
)
1752 && oap
->end
.lnum
< curbuf
->b_ml
.ml_line_count
)
1756 # ifdef FEAT_VIRTUALEDIT
1757 oap
->end
.coladd
= 0;
1764 redo_VIsual_busy
= FALSE
;
1767 * Switch Visual off now, so screen updating does
1768 * not show inverted text when the screen is redrawn.
1769 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is
1770 * no screen redraw, so it is done here to remove the inverted
1775 VIsual_active
= FALSE
;
1781 clear_cmdline
= TRUE
; /* unshow visual mode later */
1782 #ifdef FEAT_CMDL_INFO
1786 if ((oap
->op_type
== OP_YANK
1787 || oap
->op_type
== OP_COLON
1788 || oap
->op_type
== OP_FUNCTION
1789 || oap
->op_type
== OP_FILTER
)
1790 && oap
->motion_force
== NUL
)
1791 redraw_curbuf_later(INVERTED
);
1797 /* Include the trailing byte of a multi-byte char. */
1798 if (has_mbyte
&& oap
->inclusive
)
1802 l
= (*mb_ptr2len
)(ml_get_pos(&oap
->end
));
1804 oap
->end
.col
+= l
- 1;
1807 curwin
->w_set_curswant
= TRUE
;
1810 * oap->empty is set when start and end are the same. The inclusive
1811 * flag affects this too, unless yanking and the end is on a NUL.
1813 oap
->empty
= (oap
->motion_type
== MCHAR
1815 || (oap
->op_type
== OP_YANK
1816 && gchar_pos(&oap
->end
) == NUL
))
1817 && equalpos(oap
->start
, oap
->end
)
1818 #ifdef FEAT_VIRTUALEDIT
1819 && !(virtual_op
&& oap
->start
.coladd
!= oap
->end
.coladd
)
1823 * For delete, change and yank, it's an error to operate on an
1824 * empty region, when 'E' included in 'cpoptions' (Vi compatible).
1826 empty_region_error
= (oap
->empty
1827 && vim_strchr(p_cpo
, CPO_EMPTYREGION
) != NULL
);
1830 /* Force a redraw when operating on an empty Visual region, when
1831 * 'modifiable is off or creating a fold. */
1832 if (oap
->is_VIsual
&& (oap
->empty
|| !curbuf
->b_p_ma
1833 # ifdef FEAT_FOLDING
1834 || oap
->op_type
== OP_FOLD
1837 redraw_curbuf_later(INVERTED
);
1841 * If the end of an operator is in column one while oap->motion_type
1842 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last
1843 * character in the previous line. If op_start is on or before the
1844 * first non-blank in the line, the operator becomes linewise
1845 * (strange, but that's the way vi does it).
1847 if ( oap
->motion_type
== MCHAR
1848 && oap
->inclusive
== FALSE
1849 && !(cap
->retval
& CA_NO_ADJ_OP_END
)
1850 && oap
->end
.col
== 0
1852 && (!oap
->is_VIsual
|| *p_sel
== 'o')
1855 && oap
->line_count
> 1)
1857 oap
->end_adjusted
= TRUE
; /* remember that we did this */
1861 oap
->motion_type
= MLINE
;
1864 oap
->end
.col
= (colnr_T
)STRLEN(ml_get(oap
->end
.lnum
));
1868 oap
->inclusive
= TRUE
;
1873 oap
->end_adjusted
= FALSE
;
1875 switch (oap
->op_type
)
1881 oap
->is_VIsual
? (int)cap
->count1
:
1884 auto_format(FALSE
, TRUE
);
1889 if (oap
->line_count
< 2)
1890 oap
->line_count
= 2;
1891 if (curwin
->w_cursor
.lnum
+ oap
->line_count
- 1 >
1892 curbuf
->b_ml
.ml_line_count
)
1896 do_do_join(oap
->line_count
, oap
->op_type
== OP_JOIN
);
1897 auto_format(FALSE
, TRUE
);
1903 VIsual_reselect
= FALSE
; /* don't reselect now */
1905 if (empty_region_error
)
1909 (void)op_delete(oap
);
1910 if (oap
->motion_type
== MLINE
&& has_format_option(FO_AUTO
))
1911 u_save_cursor(); /* cursor line wasn't saved yet */
1912 auto_format(FALSE
, TRUE
);
1917 if (empty_region_error
)
1923 (void)op_yank(oap
, FALSE
, !gui_yank
);
1929 VIsual_reselect
= FALSE
; /* don't reselect now */
1931 if (empty_region_error
)
1935 /* This is a new edit command, not a restart. Need to
1936 * remember it to make 'insertmode' work with mappings for
1937 * Visual mode. But do this only once and not when typed and
1938 * 'insertmode' isn't set. */
1939 if (p_im
|| !KeyTyped
)
1940 restart_edit_save
= restart_edit
;
1942 restart_edit_save
= 0;
1944 /* Reset finish_op now, don't want it set inside edit(). */
1946 if (op_change(oap
)) /* will call edit() */
1947 cap
->retval
|= CA_COMMAND_BUSY
;
1948 if (restart_edit
== 0)
1949 restart_edit
= restart_edit_save
;
1954 if (vim_strchr(p_cpo
, CPO_FILTER
) != NULL
)
1955 AppendToRedobuff((char_u
*)"!\r"); /* use any last used !cmd */
1957 bangredo
= TRUE
; /* do_bang() will put cmd in redo buffer */
1962 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
1964 * If 'equalprg' is empty, do the indenting internally.
1966 if (oap
->op_type
== OP_INDENT
&& *get_equalprg() == NUL
)
1969 if (curbuf
->b_p_lisp
)
1971 op_reindent(oap
, get_lisp_indent
);
1975 # ifdef FEAT_CINDENT
1978 *curbuf
->b_p_inde
!= NUL
? get_expr_indent
:
1993 if (empty_region_error
)
2001 #if defined(FEAT_EVAL)
2002 if (*curbuf
->b_p_fex
!= NUL
)
2003 op_formatexpr(oap
); /* use expression */
2007 op_colon(oap
); /* use external command */
2009 op_format(oap
, FALSE
); /* use internal function */
2013 op_format(oap
, TRUE
); /* use internal function */
2017 op_function(oap
); /* call 'operatorfunc' */
2023 VIsual_reselect
= FALSE
; /* don't reselect now */
2025 #ifdef FEAT_VISUALEXTRA
2026 if (empty_region_error
)
2030 /* This is a new edit command, not a restart. Need to
2031 * remember it to make 'insertmode' work with mappings for
2032 * Visual mode. But do this only once. */
2033 restart_edit_save
= restart_edit
;
2036 op_insert(oap
, cap
->count1
);
2038 /* TODO: when inserting in several lines, should format all
2040 auto_format(FALSE
, TRUE
);
2042 if (restart_edit
== 0)
2043 restart_edit
= restart_edit_save
;
2052 VIsual_reselect
= FALSE
; /* don't reselect now */
2054 #ifdef FEAT_VISUALEXTRA
2055 if (empty_region_error
)
2058 #ifdef FEAT_VISUALEXTRA
2060 op_replace(oap
, cap
->nchar
);
2066 VIsual_reselect
= FALSE
; /* don't reselect now */
2067 foldCreate(oap
->start
.lnum
, oap
->end
.lnum
);
2071 case OP_FOLDOPENREC
:
2073 case OP_FOLDCLOSEREC
:
2074 VIsual_reselect
= FALSE
; /* don't reselect now */
2075 opFoldRange(oap
->start
.lnum
, oap
->end
.lnum
,
2076 oap
->op_type
== OP_FOLDOPEN
2077 || oap
->op_type
== OP_FOLDOPENREC
,
2078 oap
->op_type
== OP_FOLDOPENREC
2079 || oap
->op_type
== OP_FOLDCLOSEREC
,
2085 VIsual_reselect
= FALSE
; /* don't reselect now */
2086 deleteFold(oap
->start
.lnum
, oap
->end
.lnum
,
2087 oap
->op_type
== OP_FOLDDELREC
, oap
->is_VIsual
);
2093 #ifdef FEAT_VIRTUALEDIT
2099 * if 'sol' not set, go back to old column for some commands
2101 if (!p_sol
&& oap
->motion_type
== MLINE
&& !oap
->end_adjusted
2102 && (oap
->op_type
== OP_LSHIFT
|| oap
->op_type
== OP_RSHIFT
2103 || oap
->op_type
== OP_DELETE
))
2104 coladvance(curwin
->w_curswant
= old_col
);
2108 curwin
->w_cursor
= old_cursor
;
2111 oap
->block_mode
= FALSE
;
2118 * Handle indent and format operators and visual mode ":".
2124 stuffcharReadbuff(':');
2127 stuffReadbuff((char_u
*)"'<,'>");
2132 * Make the range look nice, so it can be repeated.
2134 if (oap
->start
.lnum
== curwin
->w_cursor
.lnum
)
2135 stuffcharReadbuff('.');
2137 stuffnumReadbuff((long)oap
->start
.lnum
);
2138 if (oap
->end
.lnum
!= oap
->start
.lnum
)
2140 stuffcharReadbuff(',');
2141 if (oap
->end
.lnum
== curwin
->w_cursor
.lnum
)
2142 stuffcharReadbuff('.');
2143 else if (oap
->end
.lnum
== curbuf
->b_ml
.ml_line_count
)
2144 stuffcharReadbuff('$');
2145 else if (oap
->start
.lnum
== curwin
->w_cursor
.lnum
)
2147 stuffReadbuff((char_u
*)".+");
2148 stuffnumReadbuff((long)oap
->line_count
- 1);
2151 stuffnumReadbuff((long)oap
->end
.lnum
);
2154 if (oap
->op_type
!= OP_COLON
)
2155 stuffReadbuff((char_u
*)"!");
2156 if (oap
->op_type
== OP_INDENT
)
2158 #ifndef FEAT_CINDENT
2159 if (*get_equalprg() == NUL
)
2160 stuffReadbuff((char_u
*)"indent");
2163 stuffReadbuff(get_equalprg());
2164 stuffReadbuff((char_u
*)"\n");
2166 else if (oap
->op_type
== OP_FORMAT
)
2169 stuffReadbuff((char_u
*)"fmt");
2171 stuffReadbuff(p_fp
);
2172 stuffReadbuff((char_u
*)"\n']");
2176 * do_cmdline() does the rest
2181 * Handle the "g@" operator: call 'operatorfunc'.
2191 if (*p_opfunc
== NUL
)
2192 EMSG(_("E774: 'operatorfunc' is empty"));
2195 /* Set '[ and '] marks to text to be operated on. */
2196 curbuf
->b_op_start
= oap
->start
;
2197 curbuf
->b_op_end
= oap
->end
;
2198 if (oap
->motion_type
!= MLINE
&& !oap
->inclusive
)
2199 /* Exclude the end position. */
2200 decl(&curbuf
->b_op_end
);
2202 if (oap
->block_mode
)
2203 argv
[0] = (char_u
*)"block";
2204 else if (oap
->motion_type
== MLINE
)
2205 argv
[0] = (char_u
*)"line";
2207 argv
[0] = (char_u
*)"char";
2208 (void)call_func_retnr(p_opfunc
, 1, argv
, FALSE
);
2211 EMSG(_("E775: Eval feature not available"));
2215 #if defined(FEAT_MOUSE) || defined(PROTO)
2217 * Do the appropriate action for the current mouse click in the current mode.
2218 * Not used for Command-line mode.
2221 * event modi- position visual change action
2222 * fier cursor window
2223 * left press - yes end yes
2224 * left press C yes end yes "^]" (2)
2225 * left press S yes end yes "*" (2)
2226 * left drag - yes start if moved no
2227 * left relse - yes start if moved no
2228 * middle press - yes if not active no put register
2229 * middle press - yes if active no yank and put
2230 * right press - yes start or extend yes
2231 * right press S yes no change yes "#" (2)
2232 * right drag - yes extend no
2233 * right relse - yes extend no
2235 * Insert or Replace Mode:
2236 * event modi- position visual change action
2237 * fier cursor window
2238 * left press - yes (cannot be active) yes
2239 * left press C yes (cannot be active) yes "CTRL-O^]" (2)
2240 * left press S yes (cannot be active) yes "CTRL-O*" (2)
2241 * left drag - yes start or extend (1) no CTRL-O (1)
2242 * left relse - yes start or extend (1) no CTRL-O (1)
2243 * middle press - no (cannot be active) no put register
2244 * right press - yes start or extend yes CTRL-O
2245 * right press S yes (cannot be active) yes "CTRL-O#" (2)
2247 * (1) only if mouse pointer moved since press
2248 * (2) only if click is in same buffer
2250 * Return TRUE if start_arrow() should be called for edit mode.
2253 do_mouse(oap
, c
, dir
, count
, fixindent
)
2254 oparg_T
*oap
; /* operator argument, can be NULL */
2255 int c
; /* K_LEFTMOUSE, etc */
2256 int dir
; /* Direction to 'put' if necessary */
2258 int fixindent
; /* PUT_FIXINDENT if fixing indent necessary */
2260 static int do_always
= FALSE
; /* ignore 'mouse' setting next time */
2261 static int got_click
= FALSE
; /* got a click some time back */
2263 int which_button
; /* MOUSE_LEFT, _MIDDLE or _RIGHT */
2264 int is_click
; /* If FALSE it's a drag or release event */
2265 int is_drag
; /* If TRUE it's a drag event */
2266 int jump_flags
= 0; /* flags for jump_to_mouse() */
2268 int moved
; /* Has cursor moved? */
2269 int in_status_line
; /* mouse in status line */
2270 #ifdef FEAT_VERTSPLIT
2271 int in_sep_line
; /* mouse in vertical separator line */
2274 #if defined(FEAT_FOLDING)
2277 win_T
*old_curwin
= curwin
;
2279 static pos_T orig_cursor
;
2280 colnr_T leftcol
, rightcol
;
2283 int old_active
= VIsual_active
;
2284 int old_mode
= VIsual_mode
;
2288 #if defined(FEAT_FOLDING)
2289 save_cursor
= curwin
->w_cursor
;
2293 * When GUI is active, always recognize mouse events, otherwise:
2294 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
2295 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
2296 * - For command line and insert mode 'mouse' is checked before calling
2309 if (!mouse_has(MOUSE_VISUAL
))
2314 if (State
== NORMAL
&& !mouse_has(MOUSE_NORMAL
))
2318 which_button
= get_mouse_button(KEY2TERMCAP1(c
), &is_click
, &is_drag
);
2320 #ifdef FEAT_MOUSESHAPE
2321 /* May have stopped dragging the status or separator line. The pointer is
2322 * most likely still on the status or separator line. */
2323 if (!is_drag
&& drag_status_line
)
2325 drag_status_line
= FALSE
;
2326 update_mouseshape(SHAPE_IDX_STATUS
);
2328 # ifdef FEAT_VERTSPLIT
2329 if (!is_drag
&& drag_sep_line
)
2331 drag_sep_line
= FALSE
;
2332 update_mouseshape(SHAPE_IDX_VSEP
);
2338 * Ignore drag and release events if we didn't get a click.
2344 if (!got_click
) /* didn't get click, ignore */
2346 if (!is_drag
) /* release, reset got_click */
2352 * ALT is only used for starging/extending Visual mode.
2354 if ((mod_mask
& MOD_MASK_ALT
))
2359 * CTRL right mouse button does CTRL-T
2361 if (is_click
&& (mod_mask
& MOD_MASK_CTRL
) && which_button
== MOUSE_RIGHT
)
2364 stuffcharReadbuff(Ctrl_O
);
2366 stuffnumReadbuff(count
);
2367 stuffcharReadbuff(Ctrl_T
);
2368 got_click
= FALSE
; /* ignore drag&release now */
2373 * CTRL only works with left mouse button
2375 if ((mod_mask
& MOD_MASK_CTRL
) && which_button
!= MOUSE_LEFT
)
2379 * When a modifier is down, ignore drag and release events, as well as
2380 * multiple clicks and the middle mouse button.
2381 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
2383 if ((mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
| MOD_MASK_ALT
2386 || (mod_mask
& MOD_MASK_MULTI_CLICK
)
2387 || which_button
== MOUSE_MIDDLE
)
2388 && !((mod_mask
& (MOD_MASK_SHIFT
|MOD_MASK_ALT
))
2389 && mouse_model_popup()
2390 && which_button
== MOUSE_LEFT
)
2391 && !((mod_mask
& MOD_MASK_ALT
)
2392 && !mouse_model_popup()
2393 && which_button
== MOUSE_RIGHT
)
2398 * If the button press was used as the movement command for an operator
2399 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
2400 * drag/release events.
2402 if (!is_click
&& which_button
== MOUSE_MIDDLE
)
2406 regname
= oap
->regname
;
2411 * Middle mouse button does a 'put' of the selected text
2413 if (which_button
== MOUSE_MIDDLE
)
2415 if (State
== NORMAL
)
2418 * If an operator was pending, we don't know what the user wanted
2419 * to do. Go back to normal mode: Clear the operator and beep().
2421 if (oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2429 * If visual was active, yank the highlighted text and put it
2430 * before the mouse pointer position.
2431 * In Select mode replace the highlighted text with the clipboard.
2437 stuffcharReadbuff(Ctrl_G
);
2438 stuffReadbuff((char_u
*)"\"+p");
2442 stuffcharReadbuff('y');
2443 stuffcharReadbuff(K_MIDDLEMOUSE
);
2445 do_always
= TRUE
; /* ignore 'mouse' setting next time */
2450 * The rest is below jump_to_mouse()
2454 else if ((State
& INSERT
) == 0)
2458 * Middle click in insert mode doesn't move the mouse, just insert the
2459 * contents of a register. '.' register is special, can't insert that
2461 * Also paste at the cursor if the current mode isn't in 'mouse' (only
2462 * happens for the GUI).
2464 if ((State
& INSERT
) || !mouse_has(MOUSE_NORMAL
))
2467 insert_reg(regname
, TRUE
);
2470 #ifdef FEAT_CLIPBOARD
2471 if (clip_star
.available
&& regname
== 0)
2474 if ((State
& REPLACE_FLAG
) && !yank_register_mline(regname
))
2475 insert_reg(regname
, TRUE
);
2478 do_put(regname
, BACKWARD
, 1L, fixindent
| PUT_CURSEND
);
2480 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */
2481 AppendCharToRedobuff(Ctrl_R
);
2482 AppendCharToRedobuff(fixindent
? Ctrl_P
: Ctrl_O
);
2483 AppendCharToRedobuff(regname
== 0 ? '"' : regname
);
2490 /* When dragging or button-up stay in the same window. */
2492 jump_flags
|= MOUSE_FOCUS
| MOUSE_DID_MOVE
;
2494 start_visual
.lnum
= 0;
2497 /* Check for clicking in the tab page line. */
2498 if (mouse_row
== 0 && firstwin
->w_winrow
> 0)
2502 got_click
= FALSE
; /* ignore mouse-up and drag events */
2504 /* click in a tab selects that tab page */
2509 && mouse_col
< Columns
)
2511 c1
= TabPageIdxs
[mouse_col
];
2514 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2516 /* double click opens new page */
2519 tabpage_move(c1
== 0 ? 9999 : c1
- 1);
2523 /* Go to specified tab page, or next one if not clicking
2527 /* It's like clicking on the status line of a window. */
2528 if (curwin
!= old_curwin
)
2536 /* Close the current or specified tab page. */
2540 tp
= find_tabpage(-c1
);
2543 if (first_tabpage
->tp_next
!= NULL
)
2544 tabpage_close(FALSE
);
2546 else if (tp
!= NULL
)
2547 tabpage_close_other(tp
, FALSE
);
2555 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
2556 * right button up -> pop-up menu
2557 * shift-left button -> right button
2558 * alt-left button -> alt-right button
2560 if (mouse_model_popup())
2562 if (which_button
== MOUSE_RIGHT
2563 && !(mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
)))
2566 * NOTE: Ignore right button down and drag mouse events.
2567 * Windows only shows the popup menu on the button up event.
2569 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2570 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC)
2574 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN)
2575 if (is_click
|| is_drag
)
2578 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2579 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
2580 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON)
2584 if (STRCMP(p_mousem
, "popup_setpos") == 0)
2586 /* First set the cursor position before showing the popup
2594 * set MOUSE_MAY_STOP_VIS if we are outside the
2595 * selection or the current window (might have false
2598 if (mouse_row
< W_WINROW(curwin
)
2600 > (W_WINROW(curwin
) + curwin
->w_height
))
2601 jump_flags
= MOUSE_MAY_STOP_VIS
;
2602 else if (get_fpos_of_mouse(&m_pos
) != IN_BUFFER
)
2603 jump_flags
= MOUSE_MAY_STOP_VIS
;
2606 if ((lt(curwin
->w_cursor
, VIsual
)
2607 && (lt(m_pos
, curwin
->w_cursor
)
2608 || lt(VIsual
, m_pos
)))
2609 || (lt(VIsual
, curwin
->w_cursor
)
2610 && (lt(m_pos
, VIsual
)
2611 || lt(curwin
->w_cursor
, m_pos
))))
2613 jump_flags
= MOUSE_MAY_STOP_VIS
;
2615 else if (VIsual_mode
== Ctrl_V
)
2617 getvcols(curwin
, &curwin
->w_cursor
, &VIsual
,
2618 &leftcol
, &rightcol
);
2619 getvcol(curwin
, &m_pos
, NULL
, &m_pos
.col
, NULL
);
2620 if (m_pos
.col
< leftcol
|| m_pos
.col
> rightcol
)
2621 jump_flags
= MOUSE_MAY_STOP_VIS
;
2626 jump_flags
= MOUSE_MAY_STOP_VIS
;
2631 jump_flags
= jump_to_mouse(jump_flags
, NULL
, which_button
);
2634 VIsual_active
? INVERTED
:
2638 out_flush(); /* Update before showing popup menu */
2641 gui_show_popupmenu();
2643 return (jump_flags
& CURSOR_MOVED
) != 0;
2651 if (which_button
== MOUSE_LEFT
2652 && (mod_mask
& (MOD_MASK_SHIFT
|MOD_MASK_ALT
)))
2654 which_button
= MOUSE_RIGHT
;
2655 mod_mask
&= ~MOD_MASK_SHIFT
;
2660 if ((State
& (NORMAL
| INSERT
))
2661 && !(mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
)))
2663 if (which_button
== MOUSE_LEFT
)
2667 /* stop Visual mode for a left click in a window, but not when
2668 * on a status line */
2670 jump_flags
|= MOUSE_MAY_STOP_VIS
;
2672 else if (mouse_has(MOUSE_VISUAL
))
2673 jump_flags
|= MOUSE_MAY_VIS
;
2675 else if (which_button
== MOUSE_RIGHT
)
2677 if (is_click
&& VIsual_active
)
2680 * Remember the start and end of visual before moving the
2683 if (lt(curwin
->w_cursor
, VIsual
))
2685 start_visual
= curwin
->w_cursor
;
2686 end_visual
= VIsual
;
2690 start_visual
= VIsual
;
2691 end_visual
= curwin
->w_cursor
;
2694 jump_flags
|= MOUSE_FOCUS
;
2695 if (mouse_has(MOUSE_VISUAL
))
2696 jump_flags
|= MOUSE_MAY_VIS
;
2702 * If an operator is pending, ignore all drags and releases until the
2705 if (!is_drag
&& oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2708 oap
->motion_type
= MCHAR
;
2711 /* When releasing the button let jump_to_mouse() know. */
2712 if (!is_click
&& !is_drag
)
2713 jump_flags
|= MOUSE_RELEASED
;
2718 jump_flags
= jump_to_mouse(jump_flags
,
2719 oap
== NULL
? NULL
: &(oap
->inclusive
), which_button
);
2720 moved
= (jump_flags
& CURSOR_MOVED
);
2721 in_status_line
= (jump_flags
& IN_STATUS_LINE
);
2722 #ifdef FEAT_VERTSPLIT
2723 in_sep_line
= (jump_flags
& IN_SEP_LINE
);
2726 #ifdef FEAT_NETBEANS_INTG
2727 if (usingNetbeans
&& isNetbeansBuffer(curbuf
)
2728 && !(jump_flags
& (IN_STATUS_LINE
| IN_SEP_LINE
)))
2730 int key
= KEY2TERMCAP1(c
);
2732 if (key
== (int)KE_LEFTRELEASE
|| key
== (int)KE_MIDDLERELEASE
2733 || key
== (int)KE_RIGHTRELEASE
)
2734 netbeans_button_release(which_button
);
2738 /* When jumping to another window, clear a pending operator. That's a bit
2739 * friendlier than beeping and not jumping to that window. */
2740 if (curwin
!= old_curwin
&& oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2746 && (jump_flags
& (MOUSE_FOLD_CLOSE
| MOUSE_FOLD_OPEN
))
2747 && which_button
== MOUSE_LEFT
)
2749 /* open or close a fold at this line */
2750 if (jump_flags
& MOUSE_FOLD_OPEN
)
2751 openFold(curwin
->w_cursor
.lnum
, 1L);
2753 closeFold(curwin
->w_cursor
.lnum
, 1L);
2754 /* don't move the cursor if still in the same window */
2755 if (curwin
== old_curwin
)
2756 curwin
->w_cursor
= save_cursor
;
2760 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
2761 if ((jump_flags
& IN_OTHER_WIN
) && !VIsual_active
&& clip_star
.available
)
2763 clip_modeless(which_button
, is_click
, is_drag
);
2769 /* Set global flag that we are extending the Visual area with mouse
2770 * dragging; temporarily minimize 'scrolloff'. */
2771 if (VIsual_active
&& is_drag
&& p_so
)
2773 /* In the very first line, allow scrolling one line */
2780 /* When dragging the mouse above the window, scroll down. */
2781 if (is_drag
&& mouse_row
< 0 && !in_status_line
)
2783 scroll_redraw(FALSE
, 1L);
2787 if (start_visual
.lnum
) /* right click in visual mode */
2789 /* When ALT is pressed make Visual mode blockwise. */
2790 if (mod_mask
& MOD_MASK_ALT
)
2791 VIsual_mode
= Ctrl_V
;
2794 * In Visual-block mode, divide the area in four, pick up the corner
2795 * that is in the quarter that the cursor is in.
2797 if (VIsual_mode
== Ctrl_V
)
2799 getvcols(curwin
, &start_visual
, &end_visual
, &leftcol
, &rightcol
);
2800 if (curwin
->w_curswant
> (leftcol
+ rightcol
) / 2)
2801 end_visual
.col
= leftcol
;
2803 end_visual
.col
= rightcol
;
2804 if (curwin
->w_cursor
.lnum
<
2805 (start_visual
.lnum
+ end_visual
.lnum
) / 2)
2806 end_visual
.lnum
= end_visual
.lnum
;
2808 end_visual
.lnum
= start_visual
.lnum
;
2810 /* move VIsual to the right column */
2811 start_visual
= curwin
->w_cursor
; /* save the cursor pos */
2812 curwin
->w_cursor
= end_visual
;
2813 coladvance(end_visual
.col
);
2814 VIsual
= curwin
->w_cursor
;
2815 curwin
->w_cursor
= start_visual
; /* restore the cursor */
2820 * If the click is before the start of visual, change the start.
2821 * If the click is after the end of visual, change the end. If
2822 * the click is inside the visual, change the closest side.
2824 if (lt(curwin
->w_cursor
, start_visual
))
2825 VIsual
= end_visual
;
2826 else if (lt(end_visual
, curwin
->w_cursor
))
2827 VIsual
= start_visual
;
2830 /* In the same line, compare column number */
2831 if (end_visual
.lnum
== start_visual
.lnum
)
2833 if (curwin
->w_cursor
.col
- start_visual
.col
>
2834 end_visual
.col
- curwin
->w_cursor
.col
)
2835 VIsual
= start_visual
;
2837 VIsual
= end_visual
;
2840 /* In different lines, compare line number */
2843 diff
= (curwin
->w_cursor
.lnum
- start_visual
.lnum
) -
2844 (end_visual
.lnum
- curwin
->w_cursor
.lnum
);
2846 if (diff
> 0) /* closest to end */
2847 VIsual
= start_visual
;
2848 else if (diff
< 0) /* closest to start */
2849 VIsual
= end_visual
;
2850 else /* in the middle line */
2852 if (curwin
->w_cursor
.col
<
2853 (start_visual
.col
+ end_visual
.col
) / 2)
2854 VIsual
= end_visual
;
2856 VIsual
= start_visual
;
2863 * If Visual mode started in insert mode, execute "CTRL-O"
2865 else if ((State
& INSERT
) && VIsual_active
)
2866 stuffcharReadbuff(Ctrl_O
);
2870 * Middle mouse click: Put text before cursor.
2872 if (which_button
== MOUSE_MIDDLE
)
2874 #ifdef FEAT_CLIPBOARD
2875 if (clip_star
.available
&& regname
== 0)
2878 if (yank_register_mline(regname
))
2880 if (mouse_past_bottom
)
2883 else if (mouse_past_eol
)
2888 c1
= (dir
== BACKWARD
) ? '[' : ']';
2893 c1
= (dir
== FORWARD
) ? 'p' : 'P';
2896 prep_redo(regname
, count
, NUL
, c1
, NUL
, c2
, NUL
);
2899 * Remember where the paste started, so in edit() Insstart can be set
2902 if (restart_edit
!= 0)
2903 where_paste_started
= curwin
->w_cursor
;
2904 do_put(regname
, dir
, count
, fixindent
| PUT_CURSEND
);
2907 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2909 * Ctrl-Mouse click or double click in a quickfix window jumps to the
2910 * error under the mouse pointer.
2912 else if (((mod_mask
& MOD_MASK_CTRL
)
2913 || (mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2914 && bt_quickfix(curbuf
))
2917 stuffcharReadbuff(Ctrl_O
);
2918 if (curwin
->w_llist_ref
== NULL
) /* quickfix window */
2919 stuffReadbuff((char_u
*)":.cc\n");
2920 else /* location list window */
2921 stuffReadbuff((char_u
*)":.ll\n");
2922 got_click
= FALSE
; /* ignore drag&release now */
2927 * Ctrl-Mouse click (or double click in a help window) jumps to the tag
2928 * under the mouse pointer.
2930 else if ((mod_mask
& MOD_MASK_CTRL
) || (curbuf
->b_help
2931 && (mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
))
2934 stuffcharReadbuff(Ctrl_O
);
2935 stuffcharReadbuff(Ctrl_RSB
);
2936 got_click
= FALSE
; /* ignore drag&release now */
2940 * Shift-Mouse click searches for the next occurrence of the word under
2943 else if ((mod_mask
& MOD_MASK_SHIFT
))
2947 || (VIsual_active
&& VIsual_select
)
2950 stuffcharReadbuff(Ctrl_O
);
2951 if (which_button
== MOUSE_LEFT
)
2952 stuffcharReadbuff('*');
2953 else /* MOUSE_RIGHT */
2954 stuffcharReadbuff('#');
2957 /* Handle double clicks, unless on status line */
2958 else if (in_status_line
)
2960 #ifdef FEAT_MOUSESHAPE
2961 if ((is_drag
|| is_click
) && !drag_status_line
)
2963 drag_status_line
= TRUE
;
2964 update_mouseshape(-1);
2968 #ifdef FEAT_VERTSPLIT
2969 else if (in_sep_line
)
2971 # ifdef FEAT_MOUSESHAPE
2972 if ((is_drag
|| is_click
) && !drag_sep_line
)
2974 drag_sep_line
= TRUE
;
2975 update_mouseshape(-1);
2981 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) && (State
& (NORMAL
| INSERT
))
2982 && mouse_has(MOUSE_VISUAL
))
2984 if (is_click
|| !VIsual_active
)
2987 orig_cursor
= VIsual
;
2990 check_visual_highlight();
2991 VIsual
= curwin
->w_cursor
;
2992 orig_cursor
= VIsual
;
2993 VIsual_active
= TRUE
;
2994 VIsual_reselect
= TRUE
;
2995 /* start Select mode if 'selectmode' contains "mouse" */
2996 may_start_select('o');
2999 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
3001 /* Double click with ALT pressed makes it blockwise. */
3002 if (mod_mask
& MOD_MASK_ALT
)
3003 VIsual_mode
= Ctrl_V
;
3007 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_3CLICK
)
3009 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_4CLICK
)
3010 VIsual_mode
= Ctrl_V
;
3011 #ifdef FEAT_CLIPBOARD
3012 /* Make sure the clipboard gets updated. Needed because start and
3013 * end may still be the same, and the selection needs to be owned */
3014 clip_star
.vmode
= NUL
;
3018 * A double click selects a word or a block.
3020 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
3027 /* If the character under the cursor (skipping white space) is
3028 * not a word character, try finding a match and select a (),
3029 * {}, [], #if/#endif, etc. block. */
3030 end_visual
= curwin
->w_cursor
;
3031 while (gc
= gchar_pos(&end_visual
), vim_iswhite(gc
))
3034 oap
->motion_type
= MCHAR
;
3036 && VIsual_mode
== 'v'
3037 && !vim_iswordc(gchar_pos(&end_visual
))
3038 && equalpos(curwin
->w_cursor
, VIsual
)
3039 && (pos
= findmatch(oap
, NUL
)) != NULL
)
3041 curwin
->w_cursor
= *pos
;
3042 if (oap
->motion_type
== MLINE
)
3044 else if (*p_sel
== 'e')
3046 if (lt(curwin
->w_cursor
, VIsual
))
3049 ++curwin
->w_cursor
.col
;
3054 if (pos
== NULL
&& (is_click
|| is_drag
))
3056 /* When not found a match or when dragging: extend to include
3058 if (lt(curwin
->w_cursor
, orig_cursor
))
3060 find_start_of_word(&curwin
->w_cursor
);
3061 find_end_of_word(&VIsual
);
3065 find_start_of_word(&VIsual
);
3066 if (*p_sel
== 'e' && *ml_get_cursor() != NUL
)
3068 curwin
->w_cursor
.col
+=
3069 (*mb_ptr2len
)(ml_get_cursor());
3071 ++curwin
->w_cursor
.col
;
3073 find_end_of_word(&curwin
->w_cursor
);
3076 curwin
->w_set_curswant
= TRUE
;
3079 redraw_curbuf_later(INVERTED
); /* update the inversion */
3081 else if (VIsual_active
&& !old_active
)
3083 if (mod_mask
& MOD_MASK_ALT
)
3084 VIsual_mode
= Ctrl_V
;
3089 /* If Visual mode changed show it later. */
3090 if ((!VIsual_active
&& old_active
&& mode_displayed
)
3091 || (VIsual_active
&& p_smd
&& msg_silent
== 0
3092 && (!old_active
|| VIsual_mode
!= old_mode
)))
3093 redraw_cmdline
= TRUE
;
3101 * Move "pos" back to the start of the word it's in.
3104 find_start_of_word(pos
)
3111 line
= ml_get(pos
->lnum
);
3112 cclass
= get_mouse_class(line
+ pos
->col
);
3114 while (pos
->col
> 0)
3118 col
-= (*mb_head_off
)(line
, line
+ col
);
3120 if (get_mouse_class(line
+ col
) != cclass
)
3127 * Move "pos" forward to the end of the word it's in.
3128 * When 'selection' is "exclusive", the position is just after the word.
3131 find_end_of_word(pos
)
3138 line
= ml_get(pos
->lnum
);
3139 if (*p_sel
== 'e' && pos
->col
> 0)
3143 pos
->col
-= (*mb_head_off
)(line
, line
+ pos
->col
);
3146 cclass
= get_mouse_class(line
+ pos
->col
);
3147 while (line
[pos
->col
] != NUL
)
3150 col
= pos
->col
+ (*mb_ptr2len
)(line
+ pos
->col
);
3154 if (get_mouse_class(line
+ col
) != cclass
)
3165 * Get class of a character for selection: same class means same word.
3167 * 1: punctuation groups
3168 * 2: normal word character
3169 * >2: multi-byte word character.
3178 if (has_mbyte
&& MB_BYTE2LEN(p
[0]) > 1)
3179 return mb_get_class(p
);
3183 if (c
== ' ' || c
== '\t')
3190 * There are a few special cases where we want certain combinations of
3191 * characters to be considered as a single word. These are things like
3192 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
3193 * character is in it's own class.
3195 if (c
!= NUL
&& vim_strchr((char_u
*)"-+*/%<>&|^!=", c
) != NULL
)
3199 #endif /* FEAT_VISUAL */
3200 #endif /* FEAT_MOUSE */
3202 #if defined(FEAT_VISUAL) || defined(PROTO)
3204 * Check if highlighting for visual mode is possible, give a warning message
3208 check_visual_highlight()
3210 static int did_check
= FALSE
;
3214 if (!did_check
&& hl_attr(HLF_V
) == 0)
3215 MSG(_("Warning: terminal cannot highlight"));
3222 * This function should ALWAYS be called to end Visual mode, except from
3223 * do_pending_operator().
3228 #ifdef FEAT_CLIPBOARD
3230 * If we are using the clipboard, then remember what was selected in case
3231 * we need to paste it somewhere while we still own the selection.
3232 * Only do this when the clipboard is already owned. Don't want to grab
3233 * the selection when hitting ESC.
3235 if (clip_star
.available
&& clip_star
.owned
)
3239 VIsual_active
= FALSE
;
3245 /* Save the current VIsual area for '< and '> marks, and "gv" */
3246 curbuf
->b_visual
.vi_mode
= VIsual_mode
;
3247 curbuf
->b_visual
.vi_start
= VIsual
;
3248 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
3249 curbuf
->b_visual
.vi_curswant
= curwin
->w_curswant
;
3251 curbuf
->b_visual_mode_eval
= VIsual_mode
;
3253 #ifdef FEAT_VIRTUALEDIT
3254 if (!virtual_active())
3255 curwin
->w_cursor
.coladd
= 0;
3259 clear_cmdline
= TRUE
; /* unshow visual mode later */
3260 #ifdef FEAT_CMDL_INFO
3265 adjust_cursor_eol();
3269 * Reset VIsual_active and VIsual_reselect.
3272 reset_VIsual_and_resel()
3277 redraw_curbuf_later(INVERTED
); /* delete the inversion later */
3279 VIsual_reselect
= FALSE
;
3283 * Reset VIsual_active and VIsual_reselect if it's set.
3291 redraw_curbuf_later(INVERTED
); /* delete the inversion later */
3292 VIsual_reselect
= FALSE
;
3295 #endif /* FEAT_VISUAL */
3297 #if defined(FEAT_BEVAL)
3298 static int find_is_eval_item
__ARGS((char_u
*ptr
, int *colp
, int *nbp
, int dir
));
3301 * Check for a balloon-eval special item to include when searching for an
3302 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid!
3303 * Returns TRUE if the character at "*ptr" should be included.
3304 * "dir" is FORWARD or BACKWARD, the direction of searching.
3305 * "*colp" is in/decremented if "ptr[-dir]" should also be included.
3306 * "bnp" points to a counter for square brackets.
3309 find_is_eval_item(ptr
, colp
, bnp
, dir
)
3315 /* Accept everything inside []. */
3316 if ((*ptr
== ']' && dir
== BACKWARD
) || (*ptr
== '[' && dir
== FORWARD
))
3320 if ((*ptr
== '[' && dir
== BACKWARD
) || (*ptr
== ']' && dir
== FORWARD
))
3325 /* skip over "s.var" */
3329 /* two-character item: s->var */
3330 if (ptr
[dir
== BACKWARD
? 0 : 1] == '>'
3331 && ptr
[dir
== BACKWARD
? -1 : 0] == '-')
3341 * Find the identifier under or to the right of the cursor.
3342 * "find_type" can have one of three values:
3343 * FIND_IDENT: find an identifier (keyword)
3344 * FIND_STRING: find any non-white string
3345 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred.
3346 * FIND_EVAL: find text useful for C program debugging
3348 * There are three steps:
3349 * 1. Search forward for the start of an identifier/string. Doesn't move if
3351 * 2. Search backward for the start of this identifier/string.
3352 * This doesn't match the real Vi but I like it a little better and it
3353 * shouldn't bother anyone.
3354 * 3. Search forward to the end of this identifier/string.
3355 * When FIND_IDENT isn't defined, we backup until a blank.
3357 * Returns the length of the string, or zero if no string is found.
3358 * If a string is found, a pointer to the string is put in "*string". This
3359 * string is not always NUL terminated.
3362 find_ident_under_cursor(string
, find_type
)
3366 return find_ident_at_pos(curwin
, curwin
->w_cursor
.lnum
,
3367 curwin
->w_cursor
.col
, string
, find_type
);
3371 * Like find_ident_under_cursor(), but for any window and any position.
3372 * However: Uses 'iskeyword' from the current window!.
3375 find_ident_at_pos(wp
, lnum
, startcol
, string
, find_type
)
3383 int col
= 0; /* init to shut up GCC */
3390 #if defined(FEAT_BEVAL)
3391 int bn
= 0; /* bracket nesting */
3395 * if i == 0: try to find an identifier
3396 * if i == 1: try to find any non-white string
3398 ptr
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3399 for (i
= (find_type
& FIND_IDENT
) ? 0 : 1; i
< 2; ++i
)
3402 * 1. skip to start of identifier/string
3408 while (ptr
[col
] != NUL
)
3410 # if defined(FEAT_BEVAL)
3411 /* Stop at a ']' to evaluate "a[x]". */
3412 if ((find_type
& FIND_EVAL
) && ptr
[col
] == ']')
3415 this_class
= mb_get_class(ptr
+ col
);
3416 if (this_class
!= 0 && (i
== 1 || this_class
!= 1))
3418 col
+= (*mb_ptr2len
)(ptr
+ col
);
3423 while (ptr
[col
] != NUL
3424 && (i
== 0 ? !vim_iswordc(ptr
[col
]) : vim_iswhite(ptr
[col
]))
3425 # if defined(FEAT_BEVAL)
3426 && (!(find_type
& FIND_EVAL
) || ptr
[col
] != ']')
3431 #if defined(FEAT_BEVAL)
3432 /* When starting on a ']' count it, so that we include the '['. */
3433 bn
= ptr
[col
] == ']';
3437 * 2. Back up to start of identifier/string.
3442 /* Remember class of character under cursor. */
3443 # if defined(FEAT_BEVAL)
3444 if ((find_type
& FIND_EVAL
) && ptr
[col
] == ']')
3445 this_class
= mb_get_class((char_u
*)"a");
3448 this_class
= mb_get_class(ptr
+ col
);
3449 while (col
> 0 && this_class
!= 0)
3451 prevcol
= col
- 1 - (*mb_head_off
)(ptr
, ptr
+ col
- 1);
3452 prev_class
= mb_get_class(ptr
+ prevcol
);
3453 if (this_class
!= prev_class
3456 || (find_type
& FIND_IDENT
))
3457 # if defined(FEAT_BEVAL)
3458 && (!(find_type
& FIND_EVAL
)
3460 || !find_is_eval_item(ptr
+ prevcol
, &prevcol
,
3468 /* If we don't want just any old string, or we've found an
3469 * identifier, stop searching. */
3472 if (!(find_type
& FIND_STRING
) || this_class
== 2)
3480 ? vim_iswordc(ptr
[col
- 1])
3481 : (!vim_iswhite(ptr
[col
- 1])
3482 && (!(find_type
& FIND_IDENT
)
3483 || !vim_iswordc(ptr
[col
- 1]))))
3484 #if defined(FEAT_BEVAL)
3485 || ((find_type
& FIND_EVAL
)
3487 && find_is_eval_item(ptr
+ col
- 1, &col
,
3493 /* If we don't want just any old string, or we've found an
3494 * identifier, stop searching. */
3495 if (!(find_type
& FIND_STRING
) || vim_iswordc(ptr
[col
]))
3500 if (ptr
[col
] == NUL
|| (i
== 0 && (
3502 has_mbyte
? this_class
!= 2 :
3504 !vim_iswordc(ptr
[col
]))))
3507 * didn't find an identifier or string
3509 if (find_type
& FIND_STRING
)
3510 EMSG(_("E348: No string under cursor"));
3512 EMSG(_("E349: No identifier under cursor"));
3519 * 3. Find the end if the identifier/string.
3521 #if defined(FEAT_BEVAL)
3529 /* Search for point of changing multibyte character class. */
3530 this_class
= mb_get_class(ptr
);
3531 while (ptr
[col
] != NUL
3532 && ((i
== 0 ? mb_get_class(ptr
+ col
) == this_class
3533 : mb_get_class(ptr
+ col
) != 0)
3534 # if defined(FEAT_BEVAL)
3535 || ((find_type
& FIND_EVAL
)
3536 && col
<= (int)startcol
3537 && find_is_eval_item(ptr
+ col
, &col
, &bn
, FORWARD
))
3540 col
+= (*mb_ptr2len
)(ptr
+ col
);
3544 while ((i
== 0 ? vim_iswordc(ptr
[col
])
3545 : (ptr
[col
] != NUL
&& !vim_iswhite(ptr
[col
])))
3546 # if defined(FEAT_BEVAL)
3547 || ((find_type
& FIND_EVAL
)
3548 && col
<= (int)startcol
3549 && find_is_eval_item(ptr
+ col
, &col
, &bn
, FORWARD
))
3560 * Prepare for redo of a normal command.
3566 prep_redo(cap
->oap
->regname
, cap
->count0
,
3567 NUL
, cap
->cmdchar
, NUL
, NUL
, cap
->nchar
);
3571 * Prepare for redo of any command.
3572 * Note that only the last argument can be a multi-byte char.
3575 prep_redo(regname
, num
, cmd1
, cmd2
, cmd3
, cmd4
, cmd5
)
3585 if (regname
!= 0) /* yank from specified buffer */
3587 AppendCharToRedobuff('"');
3588 AppendCharToRedobuff(regname
);
3591 AppendNumberToRedobuff(num
);
3594 AppendCharToRedobuff(cmd1
);
3596 AppendCharToRedobuff(cmd2
);
3598 AppendCharToRedobuff(cmd3
);
3600 AppendCharToRedobuff(cmd4
);
3602 AppendCharToRedobuff(cmd5
);
3606 * check for operator active and clear it
3608 * return TRUE if operator was active
3614 if (oap
->op_type
== OP_NOP
)
3621 * Check for operator or Visual active. Clear active operator.
3623 * Return TRUE if operator or Visual was active.
3629 if (oap
->op_type
== OP_NOP
3643 oap
->op_type
= OP_NOP
;
3645 oap
->motion_force
= NUL
;
3646 oap
->use_reg_one
= FALSE
;
3659 * Remove the shift modifier from a special key.
3662 unshift_special(cap
)
3665 switch (cap
->cmdchar
)
3667 case K_S_RIGHT
: cap
->cmdchar
= K_RIGHT
; break;
3668 case K_S_LEFT
: cap
->cmdchar
= K_LEFT
; break;
3669 case K_S_UP
: cap
->cmdchar
= K_UP
; break;
3670 case K_S_DOWN
: cap
->cmdchar
= K_DOWN
; break;
3671 case K_S_HOME
: cap
->cmdchar
= K_HOME
; break;
3672 case K_S_END
: cap
->cmdchar
= K_END
; break;
3674 cap
->cmdchar
= simplify_key(cap
->cmdchar
, &mod_mask
);
3678 #if defined(FEAT_CMDL_INFO) || defined(PROTO)
3680 * Routines for displaying a partly typed command
3683 #ifdef FEAT_VISUAL /* need room for size of Visual area */
3684 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30
3686 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1
3688 static char_u showcmd_buf
[SHOWCMD_BUFLEN
];
3689 static char_u old_showcmd_buf
[SHOWCMD_BUFLEN
]; /* For push_showcmd() */
3690 static int showcmd_is_clear
= TRUE
;
3691 static int showcmd_visual
= FALSE
;
3693 static void display_showcmd
__ARGS((void));
3702 if (VIsual_active
&& !char_avail())
3704 int i
= lt(VIsual
, curwin
->w_cursor
);
3706 colnr_T leftcol
, rightcol
;
3709 /* Show the size of the Visual area. */
3713 bot
= curwin
->w_cursor
.lnum
;
3717 top
= curwin
->w_cursor
.lnum
;
3720 # ifdef FEAT_FOLDING
3721 /* Include closed folds as a whole. */
3722 hasFolding(top
, &top
, NULL
);
3723 hasFolding(bot
, NULL
, &bot
);
3725 lines
= bot
- top
+ 1;
3727 if (VIsual_mode
== Ctrl_V
)
3729 getvcols(curwin
, &curwin
->w_cursor
, &VIsual
, &leftcol
, &rightcol
);
3730 sprintf((char *)showcmd_buf
, "%ldx%ld", lines
,
3731 (long)(rightcol
- leftcol
+ 1));
3733 else if (VIsual_mode
== 'V' || VIsual
.lnum
!= curwin
->w_cursor
.lnum
)
3734 sprintf((char *)showcmd_buf
, "%ld", lines
);
3736 sprintf((char *)showcmd_buf
, "%ld", (long)(i
3737 ? curwin
->w_cursor
.col
- VIsual
.col
3738 : VIsual
.col
- curwin
->w_cursor
.col
) + (*p_sel
!= 'e'));
3739 showcmd_buf
[SHOWCMD_COLS
] = NUL
; /* truncate */
3740 showcmd_visual
= TRUE
;
3745 showcmd_buf
[0] = NUL
;
3746 showcmd_visual
= FALSE
;
3748 /* Don't actually display something if there is nothing to clear. */
3749 if (showcmd_is_clear
)
3757 * Add 'c' to string of shown command chars.
3758 * Return TRUE if output has been written (and setcursor() has been called).
3768 #if defined(FEAT_MOUSE)
3770 static int ignore
[] =
3773 K_VER_SCROLLBAR
, K_HOR_SCROLLBAR
,
3774 K_LEFTMOUSE_NM
, K_LEFTRELEASE_NM
,
3777 K_LEFTMOUSE
, K_LEFTDRAG
, K_LEFTRELEASE
,
3778 K_MIDDLEMOUSE
, K_MIDDLEDRAG
, K_MIDDLERELEASE
,
3779 K_RIGHTMOUSE
, K_RIGHTDRAG
, K_RIGHTRELEASE
,
3780 K_MOUSEDOWN
, K_MOUSEUP
,
3781 K_X1MOUSE
, K_X1DRAG
, K_X1RELEASE
, K_X2MOUSE
, K_X2DRAG
, K_X2RELEASE
,
3787 if (!p_sc
|| msg_silent
!= 0)
3792 showcmd_buf
[0] = NUL
;
3793 showcmd_visual
= FALSE
;
3796 #if defined(FEAT_MOUSE)
3797 /* Ignore keys that are scrollbar updates and mouse clicks */
3799 for (i
= 0; ignore
[i
] != 0; ++i
)
3805 old_len
= (int)STRLEN(showcmd_buf
);
3806 extra_len
= (int)STRLEN(p
);
3807 overflow
= old_len
+ extra_len
- SHOWCMD_COLS
;
3809 mch_memmove(showcmd_buf
, showcmd_buf
+ overflow
,
3810 old_len
- overflow
+ 1);
3811 STRCAT(showcmd_buf
, p
);
3825 if (!add_to_showcmd(c
))
3830 * Delete 'len' characters from the end of the shown command.
3833 del_from_showcmd(len
)
3841 old_len
= (int)STRLEN(showcmd_buf
);
3844 showcmd_buf
[old_len
- len
] = NUL
;
3851 * push_showcmd() and pop_showcmd() are used when waiting for the user to type
3852 * something and there is a partial mapping.
3858 STRCPY(old_showcmd_buf
, showcmd_buf
);
3867 STRCPY(showcmd_buf
, old_showcmd_buf
);
3879 len
= (int)STRLEN(showcmd_buf
);
3881 showcmd_is_clear
= TRUE
;
3884 screen_puts(showcmd_buf
, (int)Rows
- 1, sc_col
, 0);
3885 showcmd_is_clear
= FALSE
;
3889 * clear the rest of an old message by outputting up to SHOWCMD_COLS
3892 screen_puts((char_u
*)" " + len
, (int)Rows
- 1, sc_col
+ len
, 0);
3894 setcursor(); /* put cursor back where it belongs */
3898 #ifdef FEAT_SCROLLBIND
3900 * When "check" is FALSE, prepare for commands that scroll the window.
3901 * When "check" is TRUE, take care of scroll-binding after the window has
3902 * scrolled. Called from normal_cmd() and edit().
3905 do_check_scrollbind(check
)
3908 static win_T
*old_curwin
= NULL
;
3909 static linenr_T old_topline
= 0;
3911 static int old_topfill
= 0;
3913 static buf_T
*old_buf
= NULL
;
3914 static colnr_T old_leftcol
= 0;
3916 if (check
&& curwin
->w_p_scb
)
3918 /* If a ":syncbind" command was just used, don't scroll, only reset
3921 did_syncbind
= FALSE
;
3922 else if (curwin
== old_curwin
)
3925 * Synchronize other windows, as necessary according to
3926 * 'scrollbind'. Don't do this after an ":edit" command, except
3927 * when 'diff' is set.
3929 if ((curwin
->w_buffer
== old_buf
3934 && (curwin
->w_topline
!= old_topline
3936 || curwin
->w_topfill
!= old_topfill
3938 || curwin
->w_leftcol
!= old_leftcol
))
3940 check_scrollbind(curwin
->w_topline
- old_topline
,
3941 (long)(curwin
->w_leftcol
- old_leftcol
));
3944 else if (vim_strchr(p_sbo
, 'j')) /* jump flag set in 'scrollopt' */
3947 * When switching between windows, make sure that the relative
3948 * vertical offset is valid for the new window. The relative
3949 * offset is invalid whenever another 'scrollbind' window has
3950 * scrolled to a point that would force the current window to
3951 * scroll past the beginning or end of its buffer. When the
3952 * resync is performed, some of the other 'scrollbind' windows may
3953 * need to jump so that the current window's relative position is
3954 * visible on-screen.
3956 check_scrollbind(curwin
->w_topline
- curwin
->w_scbind_pos
, 0L);
3958 curwin
->w_scbind_pos
= curwin
->w_topline
;
3961 old_curwin
= curwin
;
3962 old_topline
= curwin
->w_topline
;
3964 old_topfill
= curwin
->w_topfill
;
3966 old_buf
= curwin
->w_buffer
;
3967 old_leftcol
= curwin
->w_leftcol
;
3971 * Synchronize any windows that have "scrollbind" set, based on the
3972 * number of rows by which the current window has changed
3973 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
3976 check_scrollbind(topline_diff
, leftcol_diff
)
3977 linenr_T topline_diff
;
3982 win_T
*old_curwin
= curwin
;
3983 buf_T
*old_curbuf
= curbuf
;
3985 int old_VIsual_select
= VIsual_select
;
3986 int old_VIsual_active
= VIsual_active
;
3988 colnr_T tgt_leftcol
= curwin
->w_leftcol
;
3993 * check 'scrollopt' string for vertical and horizontal scroll options
3995 want_ver
= (vim_strchr(p_sbo
, 'v') && topline_diff
!= 0);
3997 want_ver
|= old_curwin
->w_p_diff
;
3999 want_hor
= (vim_strchr(p_sbo
, 'h') && (leftcol_diff
|| topline_diff
!= 0));
4002 * loop through the scrollbound windows and scroll accordingly
4005 VIsual_select
= VIsual_active
= 0;
4007 for (curwin
= firstwin
; curwin
; curwin
= curwin
->w_next
)
4009 curbuf
= curwin
->w_buffer
;
4010 /* skip original window and windows with 'noscrollbind' */
4011 if (curwin
!= old_curwin
&& curwin
->w_p_scb
)
4014 * do the vertical scroll
4019 if (old_curwin
->w_p_diff
&& curwin
->w_p_diff
)
4021 diff_set_topline(old_curwin
, curwin
);
4026 curwin
->w_scbind_pos
+= topline_diff
;
4027 topline
= curwin
->w_scbind_pos
;
4028 if (topline
> curbuf
->b_ml
.ml_line_count
)
4029 topline
= curbuf
->b_ml
.ml_line_count
;
4033 y
= topline
- curwin
->w_topline
;
4037 scrolldown(-y
, FALSE
);
4040 redraw_later(VALID
);
4043 curwin
->w_redr_status
= TRUE
;
4048 * do the horizontal scroll
4050 if (want_hor
&& curwin
->w_leftcol
!= tgt_leftcol
)
4052 curwin
->w_leftcol
= tgt_leftcol
;
4059 * reset current-window
4062 VIsual_select
= old_VIsual_select
;
4063 VIsual_active
= old_VIsual_active
;
4065 curwin
= old_curwin
;
4066 curbuf
= old_curbuf
;
4068 #endif /* #ifdef FEAT_SCROLLBIND */
4071 * Command character that's ignored.
4072 * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use
4079 cap
->retval
|= CA_COMMAND_BUSY
; /* don't call edit() now */
4083 * Command character that doesn't do anything, but unlike nv_ignore() does
4084 * start edit(). Used for "startinsert" executed while starting up.
4094 * Command character doesn't exist.
4100 clearopbeep(cap
->oap
);
4104 * <Help> and <F1> commands.
4110 if (!checkclearopq(cap
->oap
))
4115 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor.
4121 if (!checkclearopq(cap
->oap
)
4122 && do_addsub((int)cap
->cmdchar
, cap
->count1
) == OK
)
4127 * CTRL-F, CTRL-B, etc: Scroll page up or down.
4133 if (!checkclearop(cap
->oap
))
4136 if (mod_mask
& MOD_MASK_CTRL
)
4138 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */
4139 if (cap
->arg
== BACKWARD
)
4140 goto_tabpage(-(int)cap
->count1
);
4142 goto_tabpage((int)cap
->count0
);
4146 (void)onepage(cap
->arg
, cap
->count1
);
4151 * Implementation of "gd" and "gD" command.
4154 nv_gd(oap
, nchar
, thisblock
)
4157 int thisblock
; /* 1 for "1gd" and "1gD" */
4162 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0
4163 || find_decl(ptr
, len
, nchar
== 'd', thisblock
, 0) == FAIL
)
4166 else if ((fdo_flags
& FDO_SEARCH
) && KeyTyped
&& oap
->op_type
== OP_NOP
)
4172 * Search for variable declaration of "ptr[len]".
4173 * When "locally" is TRUE in the current function ("gd"), otherwise in the
4174 * current file ("gD").
4175 * When "thisblock" is TRUE check the {} block scope.
4176 * Return FAIL when not found.
4179 find_decl(ptr
, len
, locally
, thisblock
, searchflags
)
4184 int searchflags
; /* flags passed to searchit() */
4196 if ((pat
= alloc(len
+ 7)) == NULL
)
4199 /* Put "\V" before the pattern to avoid that the special meaning of "."
4200 * and "~" causes trouble. */
4201 sprintf((char *)pat
, vim_iswordp(ptr
) ? "\\V\\<%.*s\\>" : "\\V%.*s",
4203 old_pos
= curwin
->w_cursor
;
4206 p_ws
= FALSE
; /* don't wrap around end of file now */
4207 p_scs
= FALSE
; /* don't switch ignorecase off now */
4210 * With "gD" go to line 1.
4211 * With "gd" Search back for the start of the current function, then go
4212 * back until a blank line. If this fails go to line 1.
4214 if (!locally
|| !findpar(&incll
, BACKWARD
, 1L, '{', FALSE
))
4216 setpcmark(); /* Set in findpar() otherwise */
4217 curwin
->w_cursor
.lnum
= 1;
4218 par_pos
= curwin
->w_cursor
;
4222 par_pos
= curwin
->w_cursor
;
4223 while (curwin
->w_cursor
.lnum
> 1 && *skipwhite(ml_get_curline()) != NUL
)
4224 --curwin
->w_cursor
.lnum
;
4226 curwin
->w_cursor
.col
= 0;
4228 /* Search forward for the identifier, ignore comment lines. */
4229 clearpos(&found_pos
);
4232 t
= searchit(curwin
, curbuf
, &curwin
->w_cursor
, FORWARD
,
4233 pat
, 1L, searchflags
, RE_LAST
, (linenr_T
)0, NULL
);
4234 if (curwin
->w_cursor
.lnum
>= old_pos
.lnum
)
4235 t
= FAIL
; /* match after start is failure too */
4237 if (thisblock
&& t
!= FAIL
)
4241 /* Check that the block the match is in doesn't end before the
4242 * position where we started the search from. */
4243 if ((pos
= findmatchlimit(NULL
, '}', FM_FORWARD
,
4244 (int)(old_pos
.lnum
- curwin
->w_cursor
.lnum
+ 1))) != NULL
4245 && pos
->lnum
< old_pos
.lnum
)
4251 /* If we previously found a valid position, use it. */
4252 if (found_pos
.lnum
!= 0)
4254 curwin
->w_cursor
= found_pos
;
4259 #ifdef FEAT_COMMENTS
4260 if (get_leader_len(ml_get_curline(), NULL
, FALSE
) > 0)
4262 /* Ignore this line, continue at start of next line. */
4263 ++curwin
->w_cursor
.lnum
;
4264 curwin
->w_cursor
.col
= 0;
4268 if (!locally
) /* global search: use first match found */
4270 if (curwin
->w_cursor
.lnum
>= par_pos
.lnum
)
4272 /* If we previously found a valid position, use it. */
4273 if (found_pos
.lnum
!= 0)
4274 curwin
->w_cursor
= found_pos
;
4278 /* For finding a local variable and the match is before the "{" search
4279 * to find a later match. For K&R style function declarations this
4280 * skips the function header without types. */
4281 found_pos
= curwin
->w_cursor
;
4287 curwin
->w_cursor
= old_pos
;
4291 curwin
->w_set_curswant
= TRUE
;
4292 /* "n" searches forward now */
4304 * Move 'dist' lines in direction 'dir', counting lines by *screen*
4305 * lines rather than lines in the file.
4306 * 'dist' must be positive.
4308 * Return OK if able to move cursor, FAIL otherwise.
4311 nv_screengo(oap
, dir
, dist
)
4316 int linelen
= linetabsize(ml_get_curline());
4320 int col_off1
; /* margin offset for first screen line */
4321 int col_off2
; /* margin offset for wrapped screen line */
4322 int width1
; /* text width for first screen line */
4323 int width2
; /* test width for wrapped screen line */
4325 oap
->motion_type
= MCHAR
;
4326 oap
->inclusive
= FALSE
;
4328 col_off1
= curwin_col_off();
4329 col_off2
= col_off1
- curwin_col_off2();
4330 width1
= W_WIDTH(curwin
) - col_off1
;
4331 width2
= W_WIDTH(curwin
) - col_off2
;
4333 #ifdef FEAT_VERTSPLIT
4334 if (curwin
->w_width
!= 0)
4338 * Instead of sticking at the last character of the buffer line we
4339 * try to stick in the last column of the screen.
4341 if (curwin
->w_curswant
== MAXCOL
)
4346 curwin
->w_curswant
= 0;
4349 curwin
->w_curswant
= width1
- 1;
4350 if (curwin
->w_virtcol
> curwin
->w_curswant
)
4351 curwin
->w_curswant
+= ((curwin
->w_virtcol
4352 - curwin
->w_curswant
- 1) / width2
+ 1) * width2
;
4357 if (linelen
> width1
)
4358 n
= ((linelen
- width1
- 1) / width2
+ 1) * width2
+ width1
;
4361 if (curwin
->w_curswant
> (colnr_T
)n
+ 1)
4362 curwin
->w_curswant
-= ((curwin
->w_curswant
- n
) / width2
+ 1)
4368 if (dir
== BACKWARD
)
4370 if ((long)curwin
->w_curswant
>= width2
)
4371 /* move back within line */
4372 curwin
->w_curswant
-= width2
;
4375 /* to previous line */
4376 if (curwin
->w_cursor
.lnum
== 1)
4381 --curwin
->w_cursor
.lnum
;
4383 /* Move to the start of a closed fold. Don't do that when
4384 * 'foldopen' contains "all": it will open in a moment. */
4385 if (!(fdo_flags
& FDO_ALL
))
4386 (void)hasFolding(curwin
->w_cursor
.lnum
,
4387 &curwin
->w_cursor
.lnum
, NULL
);
4389 linelen
= linetabsize(ml_get_curline());
4390 if (linelen
> width1
)
4391 curwin
->w_curswant
+= (((linelen
- width1
- 1) / width2
)
4395 else /* dir == FORWARD */
4397 if (linelen
> width1
)
4398 n
= ((linelen
- width1
- 1) / width2
+ 1) * width2
+ width1
;
4401 if (curwin
->w_curswant
+ width2
< (colnr_T
)n
)
4402 /* move forward within line */
4403 curwin
->w_curswant
+= width2
;
4408 /* Move to the end of a closed fold. */
4409 (void)hasFolding(curwin
->w_cursor
.lnum
, NULL
,
4410 &curwin
->w_cursor
.lnum
);
4412 if (curwin
->w_cursor
.lnum
== curbuf
->b_ml
.ml_line_count
)
4417 curwin
->w_cursor
.lnum
++;
4418 curwin
->w_curswant
%= width2
;
4422 #ifdef FEAT_VERTSPLIT
4426 coladvance(curwin
->w_curswant
);
4428 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
4429 if (curwin
->w_cursor
.col
> 0 && curwin
->w_p_wrap
)
4432 * Check for landing on a character that got split at the end of the
4433 * last line. We want to advance a screenline, not end up in the same
4434 * screenline or move two screenlines.
4437 if (curwin
->w_virtcol
> curwin
->w_curswant
4438 && (curwin
->w_curswant
< (colnr_T
)width1
4439 ? (curwin
->w_curswant
> (colnr_T
)width1
/ 2)
4440 : ((curwin
->w_curswant
- width1
) % width2
4441 > (colnr_T
)width2
/ 2)))
4442 --curwin
->w_cursor
.col
;
4447 curwin
->w_curswant
= MAXCOL
; /* stick in the last column */
4454 * Mouse scroll wheel: Default action is to scroll three lines, or one page
4455 * when Shift or Ctrl is used.
4456 * K_MOUSEUP (cap->arg == TRUE) or K_MOUSEDOWN (cap->arg == FALSE)
4462 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
4463 win_T
*old_curwin
= curwin
;
4465 /* Currently we only get the mouse coordinates in the GUI. */
4466 if (gui
.in_use
&& mouse_row
>= 0 && mouse_col
>= 0)
4473 /* find the window at the pointer coordinates */
4474 curwin
= mouse_find_win(&row
, &col
);
4475 curbuf
= curwin
->w_buffer
;
4479 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
4481 (void)onepage(cap
->arg
? FORWARD
: BACKWARD
, 1L);
4487 nv_scroll_line(cap
);
4490 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
4491 curwin
->w_redr_status
= TRUE
;
4493 curwin
= old_curwin
;
4494 curbuf
= curwin
->w_buffer
;
4499 * Mouse clicks and drags.
4505 (void)do_mouse(cap
->oap
, cap
->cmdchar
, BACKWARD
, cap
->count1
, 0);
4510 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down.
4511 * cap->arg must be TRUE for CTRL-E.
4517 if (!checkclearop(cap
->oap
))
4518 scroll_redraw(cap
->arg
, cap
->count1
);
4522 * Scroll "count" lines up or down, and redraw.
4525 scroll_redraw(up
, count
)
4529 linenr_T prev_topline
= curwin
->w_topline
;
4531 int prev_topfill
= curwin
->w_topfill
;
4533 linenr_T prev_lnum
= curwin
->w_cursor
.lnum
;
4536 scrollup(count
, TRUE
);
4538 scrolldown(count
, TRUE
);
4541 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as
4542 * valid, otherwise the screen jumps back at the end of the file. */
4544 check_cursor_moved(curwin
);
4545 curwin
->w_valid
|= VALID_TOPLINE
;
4547 /* If moved back to where we were, at least move the cursor, otherwise
4548 * we get stuck at one position. Don't move the cursor up if the
4549 * first line of the buffer is already on the screen */
4550 while (curwin
->w_topline
== prev_topline
4552 && curwin
->w_topfill
== prev_topfill
4558 if (curwin
->w_cursor
.lnum
> prev_lnum
4559 || cursor_down(1L, FALSE
) == FAIL
)
4564 if (curwin
->w_cursor
.lnum
< prev_lnum
4565 || prev_topline
== 1L
4566 || cursor_up(1L, FALSE
) == FAIL
)
4569 /* Mark w_topline as valid, otherwise the screen jumps back at the
4570 * end of the file. */
4571 check_cursor_moved(curwin
);
4572 curwin
->w_valid
|= VALID_TOPLINE
;
4575 if (curwin
->w_cursor
.lnum
!= prev_lnum
)
4576 coladvance(curwin
->w_curswant
);
4577 redraw_later(VALID
);
4581 * Commands that start with "z".
4589 int nchar
= cap
->nchar
;
4591 long old_fdl
= curwin
->w_p_fdl
;
4592 int old_fen
= curwin
->w_p_fen
;
4598 if (VIM_ISDIGIT(nchar
))
4601 * "z123{nchar}": edit the count before obtaining {nchar}
4603 if (checkclearop(cap
->oap
))
4608 #ifdef USE_ON_FLY_SCROLL
4609 dont_scroll
= TRUE
; /* disallow scrolling here */
4612 ++allow_keys
; /* no mapping for nchar, but allow key codes */
4613 nchar
= plain_vgetc();
4615 LANGMAP_ADJUST(nchar
, TRUE
);
4619 #ifdef FEAT_CMDL_INFO
4620 (void)add_to_showcmd(nchar
);
4622 if (nchar
== K_DEL
|| nchar
== K_KDEL
)
4624 else if (VIM_ISDIGIT(nchar
))
4625 n
= n
* 10 + (nchar
- '0');
4626 else if (nchar
== CAR
)
4629 need_mouse_correct
= TRUE
;
4631 win_setheight((int)n
);
4634 else if (nchar
== 'l'
4637 || nchar
== K_RIGHT
)
4639 cap
->count1
= n
? n
* cap
->count1
: cap
->count1
;
4644 clearopbeep(cap
->oap
);
4648 cap
->oap
->op_type
= OP_NOP
;
4655 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc"
4656 * and "zC" only in Visual mode. "zj" and "zk" are motion
4658 cap
->nchar
!= 'f' && cap
->nchar
!= 'F'
4659 && !(VIsual_active
&& vim_strchr((char_u
*)"dcCoO", cap
->nchar
))
4660 && cap
->nchar
!= 'j' && cap
->nchar
!= 'k'
4663 checkclearop(cap
->oap
))
4667 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb":
4668 * If line number given, set cursor.
4670 if ((vim_strchr((char_u
*)"+\r\nt.z^-b", nchar
) != NULL
)
4672 && cap
->count0
!= curwin
->w_cursor
.lnum
)
4675 if (cap
->count0
> curbuf
->b_ml
.ml_line_count
)
4676 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
4678 curwin
->w_cursor
.lnum
= cap
->count0
;
4684 /* "z+", "z<CR>" and "zt": put cursor at top of screen */
4686 if (cap
->count0
== 0)
4688 /* No count given: put cursor at the line below screen */
4689 validate_botline(); /* make sure w_botline is valid */
4690 if (curwin
->w_botline
> curbuf
->b_ml
.ml_line_count
)
4691 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
4693 curwin
->w_cursor
.lnum
= curwin
->w_botline
;
4699 beginline(BL_WHITE
| BL_FIX
);
4702 case 't': scroll_cursor_top(0, TRUE
);
4703 redraw_later(VALID
);
4706 /* "z." and "zz": put cursor in middle of screen */
4707 case '.': beginline(BL_WHITE
| BL_FIX
);
4710 case 'z': scroll_cursor_halfway(TRUE
);
4711 redraw_later(VALID
);
4714 /* "z^", "z-" and "zb": put cursor at bottom of screen */
4715 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window
4716 * when <count> is at bottom of window, and puts that one at
4717 * bottom of window. */
4718 if (cap
->count0
!= 0)
4720 scroll_cursor_bot(0, TRUE
);
4721 curwin
->w_cursor
.lnum
= curwin
->w_topline
;
4723 else if (curwin
->w_topline
== 1)
4724 curwin
->w_cursor
.lnum
= 1;
4726 curwin
->w_cursor
.lnum
= curwin
->w_topline
- 1;
4729 beginline(BL_WHITE
| BL_FIX
);
4732 case 'b': scroll_cursor_bot(0, TRUE
);
4733 redraw_later(VALID
);
4736 /* "zH" - scroll screen right half-page */
4738 cap
->count1
*= W_WIDTH(curwin
) / 2;
4741 /* "zh" - scroll screen to the right */
4744 if (!curwin
->w_p_wrap
)
4746 if ((colnr_T
)cap
->count1
> curwin
->w_leftcol
)
4747 curwin
->w_leftcol
= 0;
4749 curwin
->w_leftcol
-= (colnr_T
)cap
->count1
;
4754 /* "zL" - scroll screen left half-page */
4755 case 'L': cap
->count1
*= W_WIDTH(curwin
) / 2;
4758 /* "zl" - scroll screen to the left */
4761 if (!curwin
->w_p_wrap
)
4763 /* scroll the window left */
4764 curwin
->w_leftcol
+= (colnr_T
)cap
->count1
;
4769 /* "zs" - scroll screen, cursor at the start */
4770 case 's': if (!curwin
->w_p_wrap
)
4773 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4774 col
= 0; /* like the cursor is in col 0 */
4777 getvcol(curwin
, &curwin
->w_cursor
, &col
, NULL
, NULL
);
4778 if ((long)col
> p_siso
)
4782 if (curwin
->w_leftcol
!= col
)
4784 curwin
->w_leftcol
= col
;
4785 redraw_later(NOT_VALID
);
4790 /* "ze" - scroll screen, cursor at the end */
4791 case 'e': if (!curwin
->w_p_wrap
)
4794 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4795 col
= 0; /* like the cursor is in col 0 */
4798 getvcol(curwin
, &curwin
->w_cursor
, NULL
, NULL
, &col
);
4799 n
= W_WIDTH(curwin
) - curwin_col_off();
4800 if ((long)col
+ p_siso
< n
)
4803 col
= col
+ p_siso
- n
+ 1;
4804 if (curwin
->w_leftcol
!= col
)
4806 curwin
->w_leftcol
= col
;
4807 redraw_later(NOT_VALID
);
4813 /* "zF": create fold command */
4814 /* "zf": create fold operator */
4816 case 'f': if (foldManualAllowed(TRUE
))
4820 curwin
->w_p_fen
= TRUE
;
4822 /* "zF" is like "zfzf" */
4823 if (nchar
== 'F' && cap
->oap
->op_type
== OP_FOLD
)
4830 clearopbeep(cap
->oap
);
4833 /* "zd": delete fold at cursor */
4834 /* "zD": delete fold at cursor recursively */
4836 case 'D': if (foldManualAllowed(FALSE
))
4841 deleteFold(curwin
->w_cursor
.lnum
,
4842 curwin
->w_cursor
.lnum
, nchar
== 'D', FALSE
);
4846 /* "zE": erease all folds */
4847 case 'E': if (foldmethodIsManual(curwin
))
4849 clearFolding(curwin
);
4850 changed_window_setting();
4852 else if (foldmethodIsMarker(curwin
))
4853 deleteFold((linenr_T
)1, curbuf
->b_ml
.ml_line_count
,
4856 EMSG(_("E352: Cannot erase folds with current 'foldmethod'"));
4859 /* "zn": fold none: reset 'foldenable' */
4860 case 'n': curwin
->w_p_fen
= FALSE
;
4863 /* "zN": fold Normal: set 'foldenable' */
4864 case 'N': curwin
->w_p_fen
= TRUE
;
4867 /* "zi": invert folding: toggle 'foldenable' */
4868 case 'i': curwin
->w_p_fen
= !curwin
->w_p_fen
;
4871 /* "za": open closed fold or close open fold at cursor */
4872 case 'a': if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4873 openFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4876 closeFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4877 curwin
->w_p_fen
= TRUE
;
4881 /* "zA": open fold at cursor recursively */
4882 case 'A': if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4883 openFoldRecurse(curwin
->w_cursor
.lnum
);
4886 closeFoldRecurse(curwin
->w_cursor
.lnum
);
4887 curwin
->w_p_fen
= TRUE
;
4891 /* "zo": open fold at cursor or Visual area */
4892 case 'o': if (VIsual_active
)
4895 openFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4898 /* "zO": open fold recursively */
4899 case 'O': if (VIsual_active
)
4902 openFoldRecurse(curwin
->w_cursor
.lnum
);
4905 /* "zc": close fold at cursor or Visual area */
4906 case 'c': if (VIsual_active
)
4909 closeFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4910 curwin
->w_p_fen
= TRUE
;
4913 /* "zC": close fold recursively */
4914 case 'C': if (VIsual_active
)
4917 closeFoldRecurse(curwin
->w_cursor
.lnum
);
4918 curwin
->w_p_fen
= TRUE
;
4921 /* "zv": open folds at the cursor */
4922 case 'v': foldOpenCursor();
4925 /* "zx": re-apply 'foldlevel' and open folds at the cursor */
4926 case 'x': curwin
->w_p_fen
= TRUE
;
4927 newFoldLevel(); /* update right now */
4931 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */
4932 case 'X': curwin
->w_p_fen
= TRUE
;
4933 old_fdl
= -1; /* force an update */
4936 /* "zm": fold more */
4937 case 'm': if (curwin
->w_p_fdl
> 0)
4939 old_fdl
= -1; /* force an update */
4940 curwin
->w_p_fen
= TRUE
;
4943 /* "zM": close all folds */
4944 case 'M': curwin
->w_p_fdl
= 0;
4945 old_fdl
= -1; /* force an update */
4946 curwin
->w_p_fen
= TRUE
;
4949 /* "zr": reduce folding */
4950 case 'r': ++curwin
->w_p_fdl
;
4953 /* "zR": open all folds */
4954 case 'R': curwin
->w_p_fdl
= getDeepestNesting();
4955 old_fdl
= -1; /* force an update */
4958 case 'j': /* "zj" move to next fold downwards */
4959 case 'k': /* "zk" move to next fold upwards */
4960 if (foldMoveTo(TRUE
, nchar
== 'j' ? FORWARD
: BACKWARD
,
4961 cap
->count1
) == FAIL
)
4962 clearopbeep(cap
->oap
);
4965 #endif /* FEAT_FOLDING */
4968 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */
4970 ++allow_keys
; /* no mapping for nchar, but allow key codes */
4971 nchar
= plain_vgetc();
4973 LANGMAP_ADJUST(nchar
, TRUE
);
4977 #ifdef FEAT_CMDL_INFO
4978 (void)add_to_showcmd(nchar
);
4980 if (vim_strchr((char_u
*)"gGwW", nchar
) == NULL
)
4982 clearopbeep(cap
->oap
);
4988 case 'g': /* "zg": add good word to word list */
4989 case 'w': /* "zw": add wrong word to word list */
4990 case 'G': /* "zG": add good word to temp word list */
4991 case 'W': /* "zW": add wrong word to temp word list */
4996 if (checkclearop(cap
->oap
))
4999 if (VIsual_active
&& get_visual_text(cap
, &ptr
, &len
)
5005 pos_T pos
= curwin
->w_cursor
;
5007 /* Find bad word under the cursor. */
5008 len
= spell_move_to(curwin
, FORWARD
, TRUE
, TRUE
, NULL
);
5009 if (len
!= 0 && curwin
->w_cursor
.col
<= pos
.col
)
5010 ptr
= ml_get_pos(&curwin
->w_cursor
);
5011 curwin
->w_cursor
= pos
;
5014 if (ptr
== NULL
&& (len
= find_ident_under_cursor(&ptr
,
5017 spell_add_word(ptr
, len
, nchar
== 'w' || nchar
== 'W',
5018 (nchar
== 'G' || nchar
== 'W')
5019 ? 0 : (int)cap
->count1
,
5024 case '=': /* "z=": suggestions for a badly spelled word */
5025 if (!checkclearop(cap
->oap
))
5026 spell_suggest((int)cap
->count0
);
5030 default: clearopbeep(cap
->oap
);
5034 /* Redraw when 'foldenable' changed */
5035 if (old_fen
!= curwin
->w_p_fen
)
5040 if (foldmethodIsDiff(curwin
) && curwin
->w_p_scb
)
5042 /* Adjust 'foldenable' in diff-synced windows. */
5045 if (wp
!= curwin
&& foldmethodIsDiff(wp
) && wp
->w_p_scb
)
5047 wp
->w_p_fen
= curwin
->w_p_fen
;
5048 changed_window_setting_win(wp
);
5053 changed_window_setting();
5056 /* Redraw when 'foldlevel' changed. */
5057 if (old_fdl
!= curwin
->w_p_fdl
)
5064 * Vertical scrollbar movement.
5067 nv_ver_scrollbar(cap
)
5070 if (cap
->oap
->op_type
!= OP_NOP
)
5071 clearopbeep(cap
->oap
);
5073 /* Even if an operator was pending, we still want to scroll */
5078 * Horizontal scrollbar movement.
5081 nv_hor_scrollbar(cap
)
5084 if (cap
->oap
->op_type
!= OP_NOP
)
5085 clearopbeep(cap
->oap
);
5087 /* Even if an operator was pending, we still want to scroll */
5088 gui_do_horiz_scroll();
5092 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
5100 if (cap
->oap
->op_type
!= OP_NOP
)
5101 clearopbeep(cap
->oap
);
5103 /* Even if an operator was pending, we still want to jump tabs. */
5104 goto_tabpage(current_tab
);
5108 * Selected item in tab line menu.
5114 if (cap
->oap
->op_type
!= OP_NOP
)
5115 clearopbeep(cap
->oap
);
5117 /* Even if an operator was pending, we still want to jump tabs. */
5122 * Handle selecting an item of the GUI tab line menu.
5123 * Used in Normal and Insert mode.
5128 switch (current_tabmenu
)
5130 case TABLINE_MENU_CLOSE
:
5131 if (current_tab
== 0)
5132 do_cmdline_cmd((char_u
*)"tabclose");
5135 vim_snprintf((char *)IObuff
, IOSIZE
, "tabclose %d",
5137 do_cmdline_cmd(IObuff
);
5141 case TABLINE_MENU_NEW
:
5142 vim_snprintf((char *)IObuff
, IOSIZE
, "%dtabnew",
5143 current_tab
> 0 ? current_tab
- 1 : 999);
5144 do_cmdline_cmd(IObuff
);
5147 case TABLINE_MENU_OPEN
:
5148 vim_snprintf((char *)IObuff
, IOSIZE
, "browse %dtabnew",
5149 current_tab
> 0 ? current_tab
- 1 : 999);
5150 do_cmdline_cmd(IObuff
);
5164 * Ignore 'Q' in Visual mode, just give a beep.
5171 if (!checkclearop(cap
->oap
))
5176 * Handle a ":" command.
5190 if (cap
->oap
->op_type
!= OP_NOP
)
5192 /* Using ":" as a movement is characterwise exclusive. */
5193 cap
->oap
->motion_type
= MCHAR
;
5194 cap
->oap
->inclusive
= FALSE
;
5196 else if (cap
->count0
)
5198 /* translate "count:" into ":.,.+(count - 1)" */
5199 stuffcharReadbuff('.');
5200 if (cap
->count0
> 1)
5202 stuffReadbuff((char_u
*)",.+");
5203 stuffnumReadbuff((long)cap
->count0
- 1L);
5207 /* When typing, don't type below an old message */
5213 /* get a command line and execute it */
5214 do_cmdline(NULL
, getexline
, NULL
,
5215 cap
->oap
->op_type
!= OP_NOP
? DOCMD_KEEPLINE
: 0);
5217 /* If 'insertmode' changed, enter or exit Insert mode */
5218 if (p_im
!= old_p_im
)
5226 /* The start of the operator may have become invalid by the Ex
5228 if (cap
->oap
->op_type
!= OP_NOP
5229 && (cap
->oap
->start
.lnum
> curbuf
->b_ml
.ml_line_count
5230 || cap
->oap
->start
.col
>
5231 STRLEN(ml_get(cap
->oap
->start
.lnum
))))
5232 clearopbeep(cap
->oap
);
5237 * Handle CTRL-G command.
5244 if (VIsual_active
) /* toggle Selection/Visual mode */
5246 VIsual_select
= !VIsual_select
;
5251 if (!checkclearop(cap
->oap
))
5252 /* print full name if count given or :cd used */
5253 fileinfo((int)cap
->count0
, FALSE
, TRUE
);
5257 * Handle CTRL-H <Backspace> command.
5264 if (VIsual_active
&& VIsual_select
)
5266 cap
->cmdchar
= 'x'; /* BS key behaves like 'x' in Select mode */
5275 * CTRL-L: clear screen and redraw.
5281 if (!checkclearop(cap
->oap
))
5283 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT
5285 * Right now, the BeBox doesn't seem to have an easy way to detect
5286 * window resizing, so we cheat and make the user detect it
5287 * manually with CTRL-L instead
5292 /* Clear all syntax states to force resyncing. */
5293 syn_stack_free_all(curbuf
);
5295 redraw_later(CLEAR
);
5300 * CTRL-O: In Select mode: switch to Visual mode for one command.
5301 * Otherwise: Go to older pcmark.
5308 if (VIsual_active
&& VIsual_select
)
5310 VIsual_select
= FALSE
;
5312 restart_VIsual_select
= 2; /* restart Select mode later */
5317 cap
->count1
= -cap
->count1
;
5323 * CTRL-^ command, short for ":e #"
5329 if (!checkclearopq(cap
->oap
))
5330 (void)buflist_getfile((int)cap
->count0
, (linenr_T
)0,
5331 GETF_SETMARK
|GETF_ALT
, FALSE
);
5341 if (!checkclearopq(cap
->oap
))
5345 /* "ZZ": equivalent to ":x". */
5346 case 'Z': do_cmdline_cmd((char_u
*)"x");
5349 /* "ZQ": equivalent to ":q!" (Elvis compatible). */
5350 case 'Q': do_cmdline_cmd((char_u
*)"q!");
5353 default: clearopbeep(cap
->oap
);
5358 #if defined(FEAT_WINDOWS) || defined(PROTO)
5360 * Call nv_ident() as if "c1" was used, with "c2" as next character.
5371 vim_memset(&ca
, 0, sizeof(ca
));
5380 * Handle the commands that use the word under the cursor.
5381 * [g] CTRL-] :ta to current identifier
5382 * [g] 'K' run program for current identifier
5383 * [g] '*' / to current identifier or string
5384 * [g] '#' ? to current identifier or string
5385 * g ']' :tselect for current identifier
5394 char_u
*kp
; /* value of 'keywordprg' */
5395 int kp_help
; /* 'keywordprg' is ":help" */
5396 int n
= 0; /* init for GCC */
5398 int g_cmd
; /* "g" command */
5403 if (cap
->cmdchar
== 'g') /* "g*", "g#", "g]" and "gCTRL-]" */
5405 cmdchar
= cap
->nchar
;
5410 cmdchar
= cap
->cmdchar
;
5414 if (cmdchar
== POUND
) /* the pound sign, '#' for English keyboards */
5418 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode.
5420 if (cmdchar
== ']' || cmdchar
== Ctrl_RSB
|| cmdchar
== 'K')
5423 if (VIsual_active
&& get_visual_text(cap
, &ptr
, &n
) == FAIL
)
5426 if (checkclearopq(cap
->oap
))
5430 if (ptr
== NULL
&& (n
= find_ident_under_cursor(&ptr
,
5431 (cmdchar
== '*' || cmdchar
== '#')
5432 ? FIND_IDENT
|FIND_STRING
: FIND_IDENT
)) == 0)
5438 /* Allocate buffer to put the command in. Inserting backslashes can
5439 * double the length of the word. p_kp / curbuf->b_p_kp could be added
5440 * and some numbers. */
5441 kp
= (*curbuf
->b_p_kp
== NUL
? p_kp
: curbuf
->b_p_kp
);
5442 kp_help
= (*kp
== NUL
|| STRCMP(kp
, ":he") == 0
5443 || STRCMP(kp
, ":help") == 0);
5444 buf
= alloc((unsigned)(n
* 2 + 30 + STRLEN(kp
)));
5454 * Put cursor at start of word, makes search skip the word
5456 * Call setpcmark() first, so "*``" puts the cursor back where
5460 curwin
->w_cursor
.col
= (colnr_T
) (ptr
- ml_get_curline());
5462 if (!g_cmd
&& vim_iswordp(ptr
))
5464 no_smartcase
= TRUE
; /* don't use 'smartcase' now */
5469 STRCPY(buf
, "he! ");
5472 /* An external command will probably use an argument starting
5473 * with "-" as an option. To avoid trouble we skip the "-". */
5477 /* When a count is given, turn it into a range. Is this
5478 * really what we want? */
5479 isman
= (STRCMP(kp
, "man") == 0);
5480 isman_s
= (STRCMP(kp
, "man -s") == 0);
5481 if (cap
->count0
!= 0 && !(isman
|| isman_s
))
5482 sprintf((char *)buf
, ".,.+%ld", cap
->count0
- 1);
5485 if (cap
->count0
== 0 && isman_s
)
5490 if (cap
->count0
!= 0 && (isman
|| isman_s
))
5492 sprintf((char *)buf
+ STRLEN(buf
), "%ld", cap
->count0
);
5501 STRCPY(buf
, "cstag ");
5509 STRCPY(buf
, "he! ");
5513 sprintf((char *)buf
, "%ldta ", cap
->count0
);
5517 * Now grab the chars in the identifier
5519 if (cmdchar
== 'K' && !kp_help
)
5521 /* Escape the argument properly for a shell command */
5522 p
= vim_strsave_shellescape(ptr
, TRUE
);
5528 buf
= (char_u
*)vim_realloc(buf
, STRLEN(buf
) + STRLEN(p
) + 1);
5541 aux_ptr
= (char_u
*)(p_magic
? "/.*~[^$\\" : "/^$\\");
5542 else if (cmdchar
== '#')
5543 aux_ptr
= (char_u
*)(p_magic
? "/?.*~[^$\\" : "/?^$\\");
5545 /* Don't escape spaces and Tabs in a tag with a backslash */
5546 aux_ptr
= (char_u
*)"\\|\"\n*?[";
5548 p
= buf
+ STRLEN(buf
);
5551 /* put a backslash before \ and some others */
5552 if (vim_strchr(aux_ptr
, *ptr
) != NULL
)
5555 /* When current byte is a part of multibyte character, copy all
5556 * bytes of that character. */
5560 int len
= (*mb_ptr2len
)(ptr
) - 1;
5562 for (i
= 0; i
< len
&& n
>= 1; ++i
, --n
)
5572 * Execute the command.
5574 if (cmdchar
== '*' || cmdchar
== '#')
5578 has_mbyte
? vim_iswordp(mb_prevptr(ml_get_curline(), ptr
)) :
5580 vim_iswordc(ptr
[-1])))
5583 /* put pattern in search history */
5584 add_to_history(HIST_SEARCH
, buf
, TRUE
, NUL
);
5586 normal_search(cap
, cmdchar
== '*' ? '/' : '?', buf
, 0);
5589 do_cmdline_cmd(buf
);
5594 #if defined(FEAT_VISUAL) || defined(PROTO)
5596 * Get visually selected text, within one line only.
5597 * Returns FAIL if more than one line selected.
5600 get_visual_text(cap
, pp
, lenp
)
5602 char_u
**pp
; /* return: start of selected text */
5603 int *lenp
; /* return: length of selected text */
5605 if (VIsual_mode
!= 'V')
5607 if (VIsual
.lnum
!= curwin
->w_cursor
.lnum
)
5610 clearopbeep(cap
->oap
);
5613 if (VIsual_mode
== 'V')
5615 *pp
= ml_get_curline();
5616 *lenp
= (int)STRLEN(*pp
);
5620 if (lt(curwin
->w_cursor
, VIsual
))
5622 *pp
= ml_get_pos(&curwin
->w_cursor
);
5623 *lenp
= VIsual
.col
- curwin
->w_cursor
.col
+ 1;
5627 *pp
= ml_get_pos(&VIsual
);
5628 *lenp
= curwin
->w_cursor
.col
- VIsual
.col
+ 1;
5632 /* Correct the length to include the whole last character. */
5633 *lenp
+= (*mb_ptr2len
)(*pp
+ (*lenp
- 1)) - 1;
5636 reset_VIsual_and_resel();
5642 * CTRL-T: backwards in tag stack
5648 if (!checkclearopq(cap
->oap
))
5649 do_tag((char_u
*)"", DT_POP
, (int)cap
->count1
, FALSE
, TRUE
);
5653 * Handle scrolling command 'H', 'L' and 'M'.
5666 cap
->oap
->motion_type
= MLINE
;
5669 if (cap
->cmdchar
== 'L')
5671 validate_botline(); /* make sure curwin->w_botline is valid */
5672 curwin
->w_cursor
.lnum
= curwin
->w_botline
- 1;
5673 if (cap
->count1
- 1 >= curwin
->w_cursor
.lnum
)
5674 curwin
->w_cursor
.lnum
= 1;
5678 if (hasAnyFolding(curwin
))
5680 /* Count a fold for one screen line. */
5681 for (n
= cap
->count1
- 1; n
> 0
5682 && curwin
->w_cursor
.lnum
> curwin
->w_topline
; --n
)
5684 (void)hasFolding(curwin
->w_cursor
.lnum
,
5685 &curwin
->w_cursor
.lnum
, NULL
);
5686 --curwin
->w_cursor
.lnum
;
5691 curwin
->w_cursor
.lnum
-= cap
->count1
- 1;
5696 if (cap
->cmdchar
== 'M')
5699 /* Don't count filler lines above the window. */
5700 used
-= diff_check_fill(curwin
, curwin
->w_topline
)
5701 - curwin
->w_topfill
;
5703 validate_botline(); /* make sure w_empty_rows is valid */
5704 half
= (curwin
->w_height
- curwin
->w_empty_rows
+ 1) / 2;
5705 for (n
= 0; curwin
->w_topline
+ n
< curbuf
->b_ml
.ml_line_count
; ++n
)
5708 /* Count half he number of filler lines to be "below this
5709 * line" and half to be "above the next line". */
5710 if (n
> 0 && used
+ diff_check_fill(curwin
, curwin
->w_topline
5717 used
+= plines(curwin
->w_topline
+ n
);
5721 if (hasFolding(curwin
->w_topline
+ n
, NULL
, &lnum
))
5722 n
= lnum
- curwin
->w_topline
;
5725 if (n
> 0 && used
> curwin
->w_height
)
5728 else /* (cap->cmdchar == 'H') */
5730 n
= cap
->count1
- 1;
5732 if (hasAnyFolding(curwin
))
5734 /* Count a fold for one screen line. */
5735 lnum
= curwin
->w_topline
;
5736 while (n
-- > 0 && lnum
< curwin
->w_botline
- 1)
5738 hasFolding(lnum
, NULL
, &lnum
);
5741 n
= lnum
- curwin
->w_topline
;
5745 curwin
->w_cursor
.lnum
= curwin
->w_topline
+ n
;
5746 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
5747 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
5750 cursor_correct(); /* correct for 'so' */
5751 beginline(BL_SOL
| BL_FIX
);
5755 * Cursor right commands.
5765 # define PAST_LINE 0
5768 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
5770 /* <C-Right> and <S-Right> move a word or WORD right */
5771 if (mod_mask
& MOD_MASK_CTRL
)
5777 cap
->oap
->motion_type
= MCHAR
;
5778 cap
->oap
->inclusive
= FALSE
;
5780 PAST_LINE
= (VIsual_active
&& *p_sel
!= 'o');
5782 # ifdef FEAT_VIRTUALEDIT
5784 * In virtual mode, there's no such thing as "PAST_LINE", as lines are
5785 * (theoretically) infinitely long.
5787 if (virtual_active())
5792 for (n
= cap
->count1
; n
> 0; --n
)
5794 if ((!PAST_LINE
&& oneright() == FAIL
)
5795 || (PAST_LINE
&& *ml_get_cursor() == NUL
))
5798 * <Space> wraps to next line if 'whichwrap' has 's'.
5799 * 'l' wraps to next line if 'whichwrap' has 'l'.
5800 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'.
5802 if ( ((cap
->cmdchar
== ' '
5803 && vim_strchr(p_ww
, 's') != NULL
)
5804 || (cap
->cmdchar
== 'l'
5805 && vim_strchr(p_ww
, 'l') != NULL
)
5806 || (cap
->cmdchar
== K_RIGHT
5807 && vim_strchr(p_ww
, '>') != NULL
))
5808 && curwin
->w_cursor
.lnum
< curbuf
->b_ml
.ml_line_count
)
5810 /* When deleting we also count the NL as a character.
5811 * Set cap->oap->inclusive when last char in the line is
5812 * included, move to next line after that */
5813 if ( cap
->oap
->op_type
!= OP_NOP
5814 && !cap
->oap
->inclusive
5815 && !lineempty(curwin
->w_cursor
.lnum
))
5816 cap
->oap
->inclusive
= TRUE
;
5819 ++curwin
->w_cursor
.lnum
;
5820 curwin
->w_cursor
.col
= 0;
5821 #ifdef FEAT_VIRTUALEDIT
5822 curwin
->w_cursor
.coladd
= 0;
5824 curwin
->w_set_curswant
= TRUE
;
5825 cap
->oap
->inclusive
= FALSE
;
5829 if (cap
->oap
->op_type
== OP_NOP
)
5831 /* Only beep and flush if not moved at all */
5832 if (n
== cap
->count1
)
5837 if (!lineempty(curwin
->w_cursor
.lnum
))
5838 cap
->oap
->inclusive
= TRUE
;
5845 curwin
->w_set_curswant
= TRUE
;
5846 # ifdef FEAT_VIRTUALEDIT
5847 if (virtual_active())
5854 curwin
->w_cursor
.col
+=
5855 (*mb_ptr2len
)(ml_get_cursor());
5858 ++curwin
->w_cursor
.col
;
5864 if (n
!= cap
->count1
&& (fdo_flags
& FDO_HOR
) && KeyTyped
5865 && cap
->oap
->op_type
== OP_NOP
)
5871 * Cursor left commands.
5873 * Returns TRUE when operator end should not be adjusted.
5881 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
5883 /* <C-Left> and <S-Left> move a word or WORD left */
5884 if (mod_mask
& MOD_MASK_CTRL
)
5890 cap
->oap
->motion_type
= MCHAR
;
5891 cap
->oap
->inclusive
= FALSE
;
5892 for (n
= cap
->count1
; n
> 0; --n
)
5894 if (oneleft() == FAIL
)
5896 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'.
5897 * 'h' wraps to previous line if 'whichwrap' has 'h'.
5898 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'.
5900 if ( (((cap
->cmdchar
== K_BS
5901 || cap
->cmdchar
== Ctrl_H
)
5902 && vim_strchr(p_ww
, 'b') != NULL
)
5903 || (cap
->cmdchar
== 'h'
5904 && vim_strchr(p_ww
, 'h') != NULL
)
5905 || (cap
->cmdchar
== K_LEFT
5906 && vim_strchr(p_ww
, '<') != NULL
))
5907 && curwin
->w_cursor
.lnum
> 1)
5909 --(curwin
->w_cursor
.lnum
);
5910 coladvance((colnr_T
)MAXCOL
);
5911 curwin
->w_set_curswant
= TRUE
;
5913 /* When the NL before the first char has to be deleted we
5914 * put the cursor on the NUL after the previous line.
5915 * This is a very special case, be careful!
5916 * Don't adjust op_end now, otherwise it won't work. */
5917 if ( (cap
->oap
->op_type
== OP_DELETE
5918 || cap
->oap
->op_type
== OP_CHANGE
)
5919 && !lineempty(curwin
->w_cursor
.lnum
))
5921 if (*ml_get_cursor() != NUL
)
5922 ++curwin
->w_cursor
.col
;
5923 cap
->retval
|= CA_NO_ADJ_OP_END
;
5927 /* Only beep and flush if not moved at all */
5928 else if (cap
->oap
->op_type
== OP_NOP
&& n
== cap
->count1
)
5934 if (n
!= cap
->count1
&& (fdo_flags
& FDO_HOR
) && KeyTyped
5935 && cap
->oap
->op_type
== OP_NOP
)
5941 * Cursor up commands.
5942 * cap->arg is TRUE for "-": Move cursor to first non-blank.
5948 if (mod_mask
& MOD_MASK_SHIFT
)
5950 /* <S-Up> is page up */
5951 cap
->arg
= BACKWARD
;
5956 cap
->oap
->motion_type
= MLINE
;
5957 if (cursor_up(cap
->count1
, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
5958 clearopbeep(cap
->oap
);
5960 beginline(BL_WHITE
| BL_FIX
);
5965 * Cursor down commands.
5966 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank.
5972 if (mod_mask
& MOD_MASK_SHIFT
)
5974 /* <S-Down> is page down */
5979 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
5980 /* In a quickfix window a <CR> jumps to the error under the cursor. */
5981 if (bt_quickfix(curbuf
) && cap
->cmdchar
== CAR
)
5982 if (curwin
->w_llist_ref
== NULL
)
5983 do_cmdline_cmd((char_u
*)".cc"); /* quickfix window */
5985 do_cmdline_cmd((char_u
*)".ll"); /* location list window */
5990 /* In the cmdline window a <CR> executes the command. */
5991 if (cmdwin_type
!= 0 && cap
->cmdchar
== CAR
)
5992 cmdwin_result
= CAR
;
5996 cap
->oap
->motion_type
= MLINE
;
5997 if (cursor_down(cap
->count1
, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
5998 clearopbeep(cap
->oap
);
6000 beginline(BL_WHITE
| BL_FIX
);
6005 #ifdef FEAT_SEARCHPATH
6007 * Grab the file name under the cursor and edit it.
6018 clearopbeep(cap
->oap
);
6023 if (curbuf_locked())
6030 ptr
= grab_file_name(cap
->count1
, &lnum
);
6034 /* do autowrite if necessary */
6035 if (curbufIsChanged() && curbuf
->b_nwindows
<= 1 && !P_HID(curbuf
))
6036 autowrite(curbuf
, FALSE
);
6038 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LAST
,
6039 P_HID(curbuf
) ? ECMD_HIDE
: 0);
6040 if (cap
->nchar
== 'F' && lnum
>= 0)
6042 curwin
->w_cursor
.lnum
= lnum
;
6043 check_cursor_lnum();
6044 beginline(BL_SOL
| BL_FIX
);
6054 * <End> command: to end of current line or last line.
6060 if (cap
->arg
|| (mod_mask
& MOD_MASK_CTRL
)) /* CTRL-END = goto last line */
6064 cap
->count1
= 1; /* to end of current line */
6070 * Handle the "$" command.
6076 cap
->oap
->motion_type
= MCHAR
;
6077 cap
->oap
->inclusive
= TRUE
;
6078 #ifdef FEAT_VIRTUALEDIT
6079 /* In virtual mode when off the edge of a line and an operator
6080 * is pending (whew!) keep the cursor where it is.
6081 * Otherwise, send it to the end of the line. */
6082 if (!virtual_active() || gchar_cursor() != NUL
6083 || cap
->oap
->op_type
== OP_NOP
)
6085 curwin
->w_curswant
= MAXCOL
; /* so we stay at the end */
6086 if (cursor_down((long)(cap
->count1
- 1),
6087 cap
->oap
->op_type
== OP_NOP
) == FAIL
)
6088 clearopbeep(cap
->oap
);
6090 else if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6096 * Implementation of '?' and '/' commands.
6097 * If cap->arg is TRUE don't set PC mark.
6103 oparg_T
*oap
= cap
->oap
;
6105 if (cap
->cmdchar
== '?' && cap
->oap
->op_type
== OP_ROT13
)
6107 /* Translate "g??" to "g?g?" */
6114 cap
->searchbuf
= getcmdline(cap
->cmdchar
, cap
->count1
, 0);
6116 if (cap
->searchbuf
== NULL
)
6122 normal_search(cap
, cap
->cmdchar
, cap
->searchbuf
,
6123 (cap
->arg
? 0 : SEARCH_MARK
));
6127 * Handle "N" and "n" commands.
6128 * cap->arg is SEARCH_REV for "N", 0 for "n".
6134 normal_search(cap
, 0, NULL
, SEARCH_MARK
| cap
->arg
);
6138 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
6139 * Uses only cap->count1 and cap->oap from "cap".
6142 normal_search(cap
, dir
, pat
, opt
)
6146 int opt
; /* extra flags for do_search() */
6150 cap
->oap
->motion_type
= MCHAR
;
6151 cap
->oap
->inclusive
= FALSE
;
6152 cap
->oap
->use_reg_one
= TRUE
;
6153 curwin
->w_set_curswant
= TRUE
;
6155 i
= do_search(cap
->oap
, dir
, pat
, cap
->count1
,
6156 opt
| SEARCH_OPT
| SEARCH_ECHO
| SEARCH_MSG
, NULL
);
6162 cap
->oap
->motion_type
= MLINE
;
6163 #ifdef FEAT_VIRTUALEDIT
6164 curwin
->w_cursor
.coladd
= 0;
6167 if (cap
->oap
->op_type
== OP_NOP
&& (fdo_flags
& FDO_SEARCH
) && KeyTyped
)
6172 /* "/$" will put the cursor after the end of the line, may need to
6173 * correct that here */
6178 * Character search commands.
6179 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for
6180 * ',' and FALSE for ';'.
6181 * cap->nchar is NUL for ',' and ';' (repeat the search)
6189 if (cap
->cmdchar
== 't' || cap
->cmdchar
== 'T')
6194 cap
->oap
->motion_type
= MCHAR
;
6195 if (IS_SPECIAL(cap
->nchar
) || searchc(cap
, t_cmd
) == FAIL
)
6196 clearopbeep(cap
->oap
);
6199 curwin
->w_set_curswant
= TRUE
;
6200 #ifdef FEAT_VIRTUALEDIT
6201 /* Include a Tab for "tx" and for "dfx". */
6202 if (gchar_cursor() == TAB
&& virtual_active() && cap
->arg
== FORWARD
6203 && (t_cmd
|| cap
->oap
->op_type
!= OP_NOP
))
6207 getvcol(curwin
, &curwin
->w_cursor
, &scol
, NULL
, &ecol
);
6208 curwin
->w_cursor
.coladd
= ecol
- scol
;
6211 curwin
->w_cursor
.coladd
= 0;
6214 adjust_for_sel(cap
);
6217 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6224 * "[" and "]" commands.
6225 * cap->arg is BACKWARD for "[" and FORWARD for "]".
6233 pos_T
*pos
= NULL
; /* init for GCC */
6234 pos_T old_pos
; /* cursor position before command */
6240 cap
->oap
->motion_type
= MCHAR
;
6241 cap
->oap
->inclusive
= FALSE
;
6242 old_pos
= curwin
->w_cursor
;
6243 #ifdef FEAT_VIRTUALEDIT
6244 curwin
->w_cursor
.coladd
= 0; /* TODO: don't do this for an error. */
6247 #ifdef FEAT_SEARCHPATH
6249 * "[f" or "]f" : Edit file under the cursor (same as "gf")
6251 if (cap
->nchar
== 'f')
6258 * Find the occurrence(s) of the identifier or define under cursor
6259 * in current and included files or jump to the first occurrence.
6262 * fwd bwd fwd bwd fwd bwd
6263 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
6264 * define "]d" "[d" "]D" "[D" "]^D" "[^D"
6266 if (vim_strchr((char_u
*)
6272 cap
->nchar
) != NULL
)
6277 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
6281 find_pattern_in_path(ptr
, 0, len
, TRUE
,
6282 cap
->count0
== 0 ? !isupper(cap
->nchar
) : FALSE
,
6283 ((cap
->nchar
& 0xf) == ('d' & 0xf)) ? FIND_DEFINE
: FIND_ANY
,
6285 isupper(cap
->nchar
) ? ACTION_SHOW_ALL
:
6286 islower(cap
->nchar
) ? ACTION_SHOW
: ACTION_GOTO
,
6287 cap
->cmdchar
== ']' ? curwin
->w_cursor
.lnum
+ 1 : (linenr_T
)1,
6289 curwin
->w_set_curswant
= TRUE
;
6296 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')'
6297 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct.
6298 * "[/", "[*", "]/", "]*": go to Nth comment start/end.
6299 * "[m" or "]m" search for prev/next start of (Java) method.
6300 * "[M" or "]M" search for prev/next end of (Java) method.
6302 if ( (cap
->cmdchar
== '['
6303 && vim_strchr((char_u
*)"{(*/#mM", cap
->nchar
) != NULL
)
6304 || (cap
->cmdchar
== ']'
6305 && vim_strchr((char_u
*)"})*/#mM", cap
->nchar
) != NULL
))
6307 if (cap
->nchar
== '*')
6311 if (cap
->nchar
== 'm' || cap
->nchar
== 'M')
6313 if (cap
->cmdchar
== '[')
6326 if ((pos
= findmatchlimit(cap
->oap
, findc
,
6327 (cap
->cmdchar
== '[') ? FM_BACKWARD
: FM_FORWARD
, 0)) == NULL
)
6329 if (new_pos
.lnum
== 0) /* nothing found */
6331 if (cap
->nchar
!= 'm' && cap
->nchar
!= 'M')
6332 clearopbeep(cap
->oap
);
6335 pos
= &new_pos
; /* use last one found */
6339 curwin
->w_cursor
= *pos
;
6342 curwin
->w_cursor
= old_pos
;
6345 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only
6346 * brought us to the match for "[m" and "]M" when inside a method.
6347 * Try finding the '{' or '}' we want to be at.
6348 * Also repeat for the given count.
6350 if (cap
->nchar
== 'm' || cap
->nchar
== 'M')
6352 /* norm is TRUE for "]M" and "[m" */
6353 int norm
= ((findc
== '{') == (cap
->nchar
== 'm'));
6356 /* found a match: we were inside a method */
6357 if (prev_pos
.lnum
!= 0)
6360 curwin
->w_cursor
= prev_pos
;
6370 if ((findc
== '{' ? dec_cursor() : inc_cursor()) < 0)
6372 /* if not found anything, that's an error */
6374 clearopbeep(cap
->oap
);
6379 if (c
== '{' || c
== '}')
6381 /* Must have found end/start of class: use it.
6382 * Or found the place to be at. */
6383 if ((c
== findc
&& norm
) || (n
== 1 && !norm
))
6385 new_pos
= curwin
->w_cursor
;
6389 /* if no match found at all, we started outside of the
6390 * class and we're inside now. Just go on. */
6391 else if (new_pos
.lnum
== 0)
6393 new_pos
= curwin
->w_cursor
;
6396 /* found start/end of other method: go to match */
6397 else if ((pos
= findmatchlimit(cap
->oap
, findc
,
6398 (cap
->cmdchar
== '[') ? FM_BACKWARD
: FM_FORWARD
,
6402 curwin
->w_cursor
= *pos
;
6408 curwin
->w_cursor
= old_pos
;
6409 if (pos
== NULL
&& new_pos
.lnum
!= 0)
6410 clearopbeep(cap
->oap
);
6415 curwin
->w_cursor
= *pos
;
6416 curwin
->w_set_curswant
= TRUE
;
6418 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
6419 && cap
->oap
->op_type
== OP_NOP
)
6426 * "[[", "[]", "]]" and "][": move to start or end of function
6428 else if (cap
->nchar
== '[' || cap
->nchar
== ']')
6430 if (cap
->nchar
== cap
->cmdchar
) /* "]]" or "[[" */
6433 flag
= '}'; /* "][" or "[]" */
6435 curwin
->w_set_curswant
= TRUE
;
6437 * Imitate strange Vi behaviour: When using "]]" with an operator
6438 * we also stop at '}'.
6440 if (!findpar(&cap
->oap
->inclusive
, cap
->arg
, cap
->count1
, flag
,
6441 (cap
->oap
->op_type
!= OP_NOP
6442 && cap
->arg
== FORWARD
&& flag
== '{')))
6443 clearopbeep(cap
->oap
);
6446 if (cap
->oap
->op_type
== OP_NOP
)
6447 beginline(BL_WHITE
| BL_FIX
);
6449 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6456 * "[p", "[P", "]P" and "]p": put with indent adjustment
6458 else if (cap
->nchar
== 'p' || cap
->nchar
== 'P')
6460 if (!checkclearop(cap
->oap
))
6463 do_put(cap
->oap
->regname
,
6464 (cap
->cmdchar
== ']' && cap
->nchar
== 'p') ? FORWARD
: BACKWARD
,
6465 cap
->count1
, PUT_FIXINDENT
);
6470 * "['", "[`", "]'" and "]`": jump to next mark
6472 else if (cap
->nchar
== '\'' || cap
->nchar
== '`')
6474 pos
= &curwin
->w_cursor
;
6475 for (n
= cap
->count1
; n
> 0; --n
)
6478 pos
= getnextmark(pos
, cap
->cmdchar
== '[' ? BACKWARD
: FORWARD
,
6479 cap
->nchar
== '\'');
6485 nv_cursormark(cap
, cap
->nchar
== '\'', pos
);
6490 * [ or ] followed by a middle mouse click: put selected text with
6491 * indent adjustment. Any other button just does as usual.
6493 else if (cap
->nchar
>= K_LEFTMOUSE
&& cap
->nchar
<= K_RIGHTRELEASE
)
6495 (void)do_mouse(cap
->oap
, cap
->nchar
,
6496 (cap
->cmdchar
== ']') ? FORWARD
: BACKWARD
,
6497 cap
->count1
, PUT_FIXINDENT
);
6499 #endif /* FEAT_MOUSE */
6503 * "[z" and "]z": move to start or end of open fold.
6505 else if (cap
->nchar
== 'z')
6507 if (foldMoveTo(FALSE
, cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6508 cap
->count1
) == FAIL
)
6509 clearopbeep(cap
->oap
);
6515 * "[c" and "]c": move to next or previous diff-change.
6517 else if (cap
->nchar
== 'c')
6519 if (diff_move_to(cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6520 cap
->count1
) == FAIL
)
6521 clearopbeep(cap
->oap
);
6527 * "[s", "[S", "]s" and "]S": move to next spell error.
6529 else if (cap
->nchar
== 's' || cap
->nchar
== 'S')
6532 for (n
= 0; n
< cap
->count1
; ++n
)
6533 if (spell_move_to(curwin
, cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6534 cap
->nchar
== 's' ? TRUE
: FALSE
, FALSE
, NULL
) == 0)
6536 clearopbeep(cap
->oap
);
6539 # ifdef FEAT_FOLDING
6540 if (cap
->oap
->op_type
== OP_NOP
&& (fdo_flags
& FDO_SEARCH
) && KeyTyped
)
6546 /* Not a valid cap->nchar. */
6548 clearopbeep(cap
->oap
);
6552 * Handle Normal mode "%" command.
6560 linenr_T lnum
= curwin
->w_cursor
.lnum
;
6563 cap
->oap
->inclusive
= TRUE
;
6564 if (cap
->count0
) /* {cnt}% : goto {cnt} percentage in file */
6566 if (cap
->count0
> 100)
6567 clearopbeep(cap
->oap
);
6570 cap
->oap
->motion_type
= MLINE
;
6572 /* Round up, so CTRL-G will give same value. Watch out for a
6573 * large line count, the line number must not go negative! */
6574 if (curbuf
->b_ml
.ml_line_count
> 1000000)
6575 curwin
->w_cursor
.lnum
= (curbuf
->b_ml
.ml_line_count
+ 99L)
6576 / 100L * cap
->count0
;
6578 curwin
->w_cursor
.lnum
= (curbuf
->b_ml
.ml_line_count
*
6579 cap
->count0
+ 99L) / 100L;
6580 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6581 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6582 beginline(BL_SOL
| BL_FIX
);
6585 else /* "%" : go to matching paren */
6587 cap
->oap
->motion_type
= MCHAR
;
6588 cap
->oap
->use_reg_one
= TRUE
;
6589 if ((pos
= findmatch(cap
->oap
, NUL
)) == NULL
)
6590 clearopbeep(cap
->oap
);
6594 curwin
->w_cursor
= *pos
;
6595 curwin
->w_set_curswant
= TRUE
;
6596 #ifdef FEAT_VIRTUALEDIT
6597 curwin
->w_cursor
.coladd
= 0;
6600 adjust_for_sel(cap
);
6605 if (cap
->oap
->op_type
== OP_NOP
6606 && lnum
!= curwin
->w_cursor
.lnum
6607 && (fdo_flags
& FDO_PERCENT
)
6614 * Handle "(" and ")" commands.
6615 * cap->arg is BACKWARD for "(" and FORWARD for ")".
6621 cap
->oap
->motion_type
= MCHAR
;
6622 cap
->oap
->use_reg_one
= TRUE
;
6623 /* The motion used to be inclusive for "(", but that is not what Vi does. */
6624 cap
->oap
->inclusive
= FALSE
;
6625 curwin
->w_set_curswant
= TRUE
;
6627 if (findsent(cap
->arg
, cap
->count1
) == FAIL
)
6628 clearopbeep(cap
->oap
);
6631 /* Don't leave the cursor on the NUL past end of line. */
6632 adjust_cursor(cap
->oap
);
6633 #ifdef FEAT_VIRTUALEDIT
6634 curwin
->w_cursor
.coladd
= 0;
6637 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6644 * "m" command: Mark a position.
6650 if (!checkclearop(cap
->oap
))
6652 if (setmark(cap
->nchar
) == FAIL
)
6653 clearopbeep(cap
->oap
);
6658 * "{" and "}" commands.
6659 * cmd->arg is BACKWARD for "{" and FORWARD for "}".
6665 cap
->oap
->motion_type
= MCHAR
;
6666 cap
->oap
->inclusive
= FALSE
;
6667 cap
->oap
->use_reg_one
= TRUE
;
6668 curwin
->w_set_curswant
= TRUE
;
6669 if (!findpar(&cap
->oap
->inclusive
, cap
->arg
, cap
->count1
, NUL
, FALSE
))
6670 clearopbeep(cap
->oap
);
6673 #ifdef FEAT_VIRTUALEDIT
6674 curwin
->w_cursor
.coladd
= 0;
6677 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6684 * "u" command: Undo or make lower case.
6690 if (cap
->oap
->op_type
== OP_LOWER
6696 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */
6712 if (!checkclearopq(cap
->oap
))
6714 u_undo((int)cap
->count1
);
6715 curwin
->w_set_curswant
= TRUE
;
6720 * Handle the "r" command.
6730 if (checkclearop(cap
->oap
))
6733 /* get another character */
6734 if (cap
->nchar
== Ctrl_V
)
6736 had_ctrl_v
= Ctrl_V
;
6737 cap
->nchar
= get_literal();
6738 /* Don't redo a multibyte character with CTRL-V. */
6739 if (cap
->nchar
> DEL
)
6745 /* Abort if the character is a special key. */
6746 if (IS_SPECIAL(cap
->nchar
))
6748 clearopbeep(cap
->oap
);
6753 /* Visual mode "r" */
6761 #ifdef FEAT_VIRTUALEDIT
6762 /* Break tabs, etc. */
6763 if (virtual_active())
6765 if (u_save_cursor() == FAIL
)
6767 if (gchar_cursor() == NUL
)
6769 /* Add extra space and put the cursor on the first one. */
6770 coladvance_force((colnr_T
)(getviscol() + cap
->count1
));
6771 curwin
->w_cursor
.col
-= cap
->count1
;
6773 else if (gchar_cursor() == TAB
)
6774 coladvance_force(getviscol());
6778 /* Abort if not enough characters to replace. */
6779 ptr
= ml_get_cursor();
6780 if (STRLEN(ptr
) < (unsigned)cap
->count1
6782 || (has_mbyte
&& mb_charlen(ptr
) < cap
->count1
)
6786 clearopbeep(cap
->oap
);
6791 * Replacing with a TAB is done by edit() when it is complicated because
6792 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB.
6793 * Other characters are done below to avoid problems with things like
6794 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC).
6796 if (had_ctrl_v
!= Ctrl_V
&& cap
->nchar
== '\t' && (curbuf
->b_p_et
|| p_sta
))
6798 stuffnumReadbuff(cap
->count1
);
6799 stuffcharReadbuff('R');
6800 stuffcharReadbuff('\t');
6801 stuffcharReadbuff(ESC
);
6805 /* save line for undo */
6806 if (u_save_cursor() == FAIL
)
6809 if (had_ctrl_v
!= Ctrl_V
&& (cap
->nchar
== '\r' || cap
->nchar
== '\n'))
6812 * Replace character(s) by a single newline.
6813 * Strange vi behaviour: Only one newline is inserted.
6814 * Delete the characters here.
6815 * Insert the newline with an insert command, takes care of
6816 * autoindent. The insert command depends on being on the last
6817 * character of a line or not.
6820 (void)del_chars(cap
->count1
, FALSE
); /* delete the characters */
6822 (void)del_bytes(cap
->count1
, FALSE
, FALSE
); /* delete the characters */
6824 stuffcharReadbuff('\r');
6825 stuffcharReadbuff(ESC
);
6827 /* Give 'r' to edit(), to get the redo command right. */
6828 invoke_edit(cap
, TRUE
, 'r', FALSE
);
6832 prep_redo(cap
->oap
->regname
, cap
->count1
,
6833 NUL
, 'r', NUL
, had_ctrl_v
, cap
->nchar
);
6835 curbuf
->b_op_start
= curwin
->w_cursor
;
6839 int old_State
= State
;
6841 if (cap
->ncharC1
!= 0)
6842 AppendCharToRedobuff(cap
->ncharC1
);
6843 if (cap
->ncharC2
!= 0)
6844 AppendCharToRedobuff(cap
->ncharC2
);
6846 /* This is slow, but it handles replacing a single-byte with a
6847 * multi-byte and the other way around. Also handles adding
6848 * composing characters for utf-8. */
6849 for (n
= cap
->count1
; n
> 0; --n
)
6852 ins_char(cap
->nchar
);
6854 if (cap
->ncharC1
!= 0)
6855 ins_char(cap
->ncharC1
);
6856 if (cap
->ncharC2
!= 0)
6857 ins_char(cap
->ncharC2
);
6864 * Replace the characters within one line.
6866 for (n
= cap
->count1
; n
> 0; --n
)
6869 * Get ptr again, because u_save and/or showmatch() will have
6870 * released the line. At the same time we let know that the
6871 * line will be changed.
6873 ptr
= ml_get_buf(curbuf
, curwin
->w_cursor
.lnum
, TRUE
);
6874 ptr
[curwin
->w_cursor
.col
] = cap
->nchar
;
6875 if (p_sm
&& msg_silent
== 0)
6876 showmatch(cap
->nchar
);
6877 ++curwin
->w_cursor
.col
;
6879 #ifdef FEAT_NETBEANS_INTG
6882 colnr_T start
= (colnr_T
)(curwin
->w_cursor
.col
- cap
->count1
);
6884 netbeans_removed(curbuf
, curwin
->w_cursor
.lnum
, start
,
6886 netbeans_inserted(curbuf
, curwin
->w_cursor
.lnum
, start
,
6887 &ptr
[start
], (int)cap
->count1
);
6891 /* mark the buffer as changed and prepare for displaying */
6892 changed_bytes(curwin
->w_cursor
.lnum
,
6893 (colnr_T
)(curwin
->w_cursor
.col
- cap
->count1
));
6895 --curwin
->w_cursor
.col
; /* cursor on the last replaced char */
6897 /* if the character on the left of the current cursor is a multi-byte
6898 * character, move two characters left */
6902 curbuf
->b_op_end
= curwin
->w_cursor
;
6903 curwin
->w_set_curswant
= TRUE
;
6904 set_last_insert(cap
->nchar
);
6910 * 'o': Exchange start and end of Visual area.
6911 * 'O': same, but in block mode exchange left and right corners.
6914 v_swap_corners(cmdchar
)
6918 colnr_T left
, right
;
6920 if (cmdchar
== 'O' && VIsual_mode
== Ctrl_V
)
6922 old_cursor
= curwin
->w_cursor
;
6923 getvcols(curwin
, &old_cursor
, &VIsual
, &left
, &right
);
6924 curwin
->w_cursor
.lnum
= VIsual
.lnum
;
6926 VIsual
= curwin
->w_cursor
;
6928 curwin
->w_cursor
.lnum
= old_cursor
.lnum
;
6929 curwin
->w_curswant
= right
;
6930 /* 'selection "exclusive" and cursor at right-bottom corner: move it
6931 * right one column */
6932 if (old_cursor
.lnum
>= VIsual
.lnum
&& *p_sel
== 'e')
6933 ++curwin
->w_curswant
;
6934 coladvance(curwin
->w_curswant
);
6935 if (curwin
->w_cursor
.col
== old_cursor
.col
6936 #ifdef FEAT_VIRTUALEDIT
6937 && (!virtual_active()
6938 || curwin
->w_cursor
.coladd
== old_cursor
.coladd
)
6942 curwin
->w_cursor
.lnum
= VIsual
.lnum
;
6943 if (old_cursor
.lnum
<= VIsual
.lnum
&& *p_sel
== 'e')
6946 VIsual
= curwin
->w_cursor
;
6948 curwin
->w_cursor
.lnum
= old_cursor
.lnum
;
6950 curwin
->w_curswant
= left
;
6955 old_cursor
= curwin
->w_cursor
;
6956 curwin
->w_cursor
= VIsual
;
6957 VIsual
= old_cursor
;
6958 curwin
->w_set_curswant
= TRUE
;
6961 #endif /* FEAT_VISUAL */
6964 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE).
6971 if (VIsual_active
) /* "R" is replace lines */
6980 if (!checkclearopq(cap
->oap
))
6982 if (!curbuf
->b_p_ma
)
6983 EMSG(_(e_modifiable
));
6986 #ifdef FEAT_VIRTUALEDIT
6987 if (virtual_active())
6988 coladvance(getviscol());
6990 invoke_edit(cap
, FALSE
, cap
->arg
? 'V' : 'R', FALSE
);
6995 #ifdef FEAT_VREPLACE
7007 cap
->nchar
= cap
->extra_char
;
7008 nv_replace(cap
); /* Do same as "r" in Visual mode for now */
7012 if (!checkclearopq(cap
->oap
))
7014 if (!curbuf
->b_p_ma
)
7015 EMSG(_(e_modifiable
));
7018 if (cap
->extra_char
== Ctrl_V
) /* get another character */
7019 cap
->extra_char
= get_literal();
7020 stuffcharReadbuff(cap
->extra_char
);
7021 stuffcharReadbuff(ESC
);
7022 # ifdef FEAT_VIRTUALEDIT
7023 if (virtual_active())
7024 coladvance(getviscol());
7026 invoke_edit(cap
, TRUE
, 'v', FALSE
);
7033 * Swap case for "~" command, when it does not work like an operator.
7042 #ifdef FEAT_NETBEANS_INTG
7048 if (checkclearopq(cap
->oap
))
7051 if (lineempty(curwin
->w_cursor
.lnum
) && vim_strchr(p_ww
, '~') == NULL
)
7053 clearopbeep(cap
->oap
);
7059 if (u_save_cursor() == FAIL
)
7062 startpos
= curwin
->w_cursor
;
7063 #ifdef FEAT_NETBEANS_INTG
7066 for (n
= cap
->count1
; n
> 0; --n
)
7068 did_change
|= swapchar(cap
->oap
->op_type
, &curwin
->w_cursor
);
7070 if (gchar_cursor() == NUL
)
7072 if (vim_strchr(p_ww
, '~') != NULL
7073 && curwin
->w_cursor
.lnum
< curbuf
->b_ml
.ml_line_count
)
7075 #ifdef FEAT_NETBEANS_INTG
7080 ptr
= ml_get(pos
.lnum
);
7081 count
= (int)STRLEN(ptr
) - pos
.col
;
7082 netbeans_removed(curbuf
, pos
.lnum
, pos
.col
,
7084 netbeans_inserted(curbuf
, pos
.lnum
, pos
.col
,
7085 &ptr
[pos
.col
], count
);
7091 ++curwin
->w_cursor
.lnum
;
7092 curwin
->w_cursor
.col
= 0;
7095 if (u_savesub(curwin
->w_cursor
.lnum
) == FAIL
)
7104 #ifdef FEAT_NETBEANS_INTG
7105 if (did_change
&& usingNetbeans
)
7107 ptr
= ml_get(pos
.lnum
);
7108 count
= curwin
->w_cursor
.col
- pos
.col
;
7109 netbeans_removed(curbuf
, pos
.lnum
, pos
.col
, (long)count
);
7110 netbeans_inserted(curbuf
, pos
.lnum
, pos
.col
, &ptr
[pos
.col
], count
);
7116 curwin
->w_set_curswant
= TRUE
;
7119 changed_lines(startpos
.lnum
, startpos
.col
, curwin
->w_cursor
.lnum
+ 1,
7121 curbuf
->b_op_start
= startpos
;
7122 curbuf
->b_op_end
= curwin
->w_cursor
;
7123 if (curbuf
->b_op_end
.col
> 0)
7124 --curbuf
->b_op_end
.col
;
7129 * Move cursor to mark.
7132 nv_cursormark(cap
, flag
, pos
)
7137 if (check_mark(pos
) == FAIL
)
7141 if (cap
->cmdchar
== '\''
7142 || cap
->cmdchar
== '`'
7143 || cap
->cmdchar
== '['
7144 || cap
->cmdchar
== ']')
7146 curwin
->w_cursor
= *pos
;
7148 beginline(BL_WHITE
| BL_FIX
);
7152 cap
->oap
->motion_type
= flag
? MLINE
: MCHAR
;
7153 if (cap
->cmdchar
== '`')
7154 cap
->oap
->use_reg_one
= TRUE
;
7155 cap
->oap
->inclusive
= FALSE
; /* ignored if not MCHAR */
7156 curwin
->w_set_curswant
= TRUE
;
7161 * Handle commands that are operators in Visual mode.
7167 static char_u trans
[] = "YyDdCcxdXdAAIIrr";
7169 /* Uppercase means linewise, except in block mode, then "D" deletes till
7170 * the end of the line, and "C" replaces til EOL */
7171 if (isupper(cap
->cmdchar
))
7173 if (VIsual_mode
!= Ctrl_V
)
7175 else if (cap
->cmdchar
== 'C' || cap
->cmdchar
== 'D')
7176 curwin
->w_curswant
= MAXCOL
;
7178 cap
->cmdchar
= *(vim_strchr(trans
, cap
->cmdchar
) + 1);
7184 * "s" and "S" commands.
7191 if (VIsual_active
) /* "vs" and "vS" are the same as "vc" */
7193 if (cap
->cmdchar
== 'S')
7204 * Abbreviated commands.
7210 if (cap
->cmdchar
== K_DEL
|| cap
->cmdchar
== K_KDEL
)
7211 cap
->cmdchar
= 'x'; /* DEL key behaves like 'x' */
7214 /* in Visual mode these commands are operators */
7223 * Translate a command into another command.
7229 static char_u
*(ar
[8]) = {(char_u
*)"dl", (char_u
*)"dh",
7230 (char_u
*)"d$", (char_u
*)"c$",
7231 (char_u
*)"cl", (char_u
*)"cc",
7232 (char_u
*)"yy", (char_u
*)":s\r"};
7233 static char_u
*str
= (char_u
*)"xXDCsSY&";
7235 if (!checkclearopq(cap
->oap
))
7237 /* In Vi "2D" doesn't delete the next line. Can't translate it
7238 * either, because "2." should also not use the count. */
7239 if (cap
->cmdchar
== 'D' && vim_strchr(p_cpo
, CPO_HASH
) != NULL
)
7241 cap
->oap
->start
= curwin
->w_cursor
;
7242 cap
->oap
->op_type
= OP_DELETE
;
7244 set_op_var(OP_DELETE
);
7250 AppendCharToRedobuff('D');
7255 stuffnumReadbuff(cap
->count0
);
7256 stuffReadbuff(ar
[(int)(vim_strchr(str
, cap
->cmdchar
) - str
)]);
7263 * "'" and "`" commands. Also for "g'" and "g`".
7264 * cap->arg is TRUE for "'" and "g'".
7273 linenr_T lnum
= curwin
->w_cursor
.lnum
;
7274 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
7277 if (cap
->cmdchar
== 'g')
7278 c
= cap
->extra_char
;
7281 pos
= getmark(c
, (cap
->oap
->op_type
== OP_NOP
));
7282 if (pos
== (pos_T
*)-1) /* jumped to other file */
7286 check_cursor_lnum();
7287 beginline(BL_WHITE
| BL_FIX
);
7293 nv_cursormark(cap
, cap
->arg
, pos
);
7295 #ifdef FEAT_VIRTUALEDIT
7296 /* May need to clear the coladd that a mark includes. */
7297 if (!virtual_active())
7298 curwin
->w_cursor
.coladd
= 0;
7301 if (cap
->oap
->op_type
== OP_NOP
7302 && (pos
== (pos_T
*)-1 || lnum
!= curwin
->w_cursor
.lnum
)
7303 && (fdo_flags
& FDO_MARK
)
7310 * Handle CTRL-O, CTRL-I, "g;" and "g," commands.
7316 #ifdef FEAT_JUMPLIST
7318 # ifdef FEAT_FOLDING
7319 linenr_T lnum
= curwin
->w_cursor
.lnum
;
7320 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
7323 if (!checkclearopq(cap
->oap
))
7325 if (cap
->cmdchar
== 'g')
7326 pos
= movechangelist((int)cap
->count1
);
7328 pos
= movemark((int)cap
->count1
);
7329 if (pos
== (pos_T
*)-1) /* jump to other file */
7331 curwin
->w_set_curswant
= TRUE
;
7334 else if (pos
!= NULL
) /* can jump */
7335 nv_cursormark(cap
, FALSE
, pos
);
7336 else if (cap
->cmdchar
== 'g')
7338 if (curbuf
->b_changelistlen
== 0)
7339 EMSG(_("E664: changelist is empty"));
7340 else if (cap
->count1
< 0)
7341 EMSG(_("E662: At start of changelist"));
7343 EMSG(_("E663: At end of changelist"));
7346 clearopbeep(cap
->oap
);
7347 # ifdef FEAT_FOLDING
7348 if (cap
->oap
->op_type
== OP_NOP
7349 && (pos
== (pos_T
*)-1 || lnum
!= curwin
->w_cursor
.lnum
)
7350 && (fdo_flags
& FDO_MARK
)
7356 clearopbeep(cap
->oap
);
7361 * Handle '"' command.
7367 if (checkclearop(cap
->oap
))
7370 if (cap
->nchar
== '=')
7371 cap
->nchar
= get_expr_register();
7373 if (cap
->nchar
!= NUL
&& valid_yank_reg(cap
->nchar
, FALSE
))
7375 cap
->oap
->regname
= cap
->nchar
;
7376 cap
->opcount
= cap
->count0
; /* remember count before '"' */
7378 set_reg_var(cap
->oap
->regname
);
7382 clearopbeep(cap
->oap
);
7387 * Handle "v", "V" and "CTRL-V" commands.
7388 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg
7390 * Handle CTRL-Q just like CTRL-V.
7396 if (cap
->cmdchar
== Ctrl_Q
)
7397 cap
->cmdchar
= Ctrl_V
;
7399 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it
7400 * characterwise, linewise, or blockwise. */
7401 if (cap
->oap
->op_type
!= OP_NOP
)
7403 cap
->oap
->motion_force
= cap
->cmdchar
;
7404 finish_op
= FALSE
; /* operator doesn't finish now but later */
7408 VIsual_select
= cap
->arg
;
7409 if (VIsual_active
) /* change Visual mode */
7411 if (VIsual_mode
== cap
->cmdchar
) /* stop visual mode */
7413 else /* toggle char/block mode */
7414 { /* or char/line mode */
7415 VIsual_mode
= cap
->cmdchar
;
7418 redraw_curbuf_later(INVERTED
); /* update the inversion */
7420 else /* start Visual mode */
7422 check_visual_highlight();
7423 if (cap
->count0
) /* use previously selected part */
7425 if (resel_VIsual_mode
== NUL
) /* there is none */
7430 VIsual
= curwin
->w_cursor
;
7432 VIsual_active
= TRUE
;
7433 VIsual_reselect
= TRUE
;
7435 /* start Select mode when 'selectmode' contains "cmd" */
7436 may_start_select('c');
7440 if (p_smd
&& msg_silent
== 0)
7441 redraw_cmdline
= TRUE
; /* show visual mode later */
7443 * For V and ^V, we multiply the number of lines even if there
7444 * was only one -- webb
7446 if (resel_VIsual_mode
!= 'v' || resel_VIsual_line_count
> 1)
7448 curwin
->w_cursor
.lnum
+=
7449 resel_VIsual_line_count
* cap
->count0
- 1;
7450 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
7451 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
7453 VIsual_mode
= resel_VIsual_mode
;
7454 if (VIsual_mode
== 'v')
7456 if (resel_VIsual_line_count
<= 1)
7457 curwin
->w_cursor
.col
+= resel_VIsual_col
* cap
->count0
- 1;
7459 curwin
->w_cursor
.col
= resel_VIsual_col
;
7462 if (resel_VIsual_col
== MAXCOL
)
7464 curwin
->w_curswant
= MAXCOL
;
7465 coladvance((colnr_T
)MAXCOL
);
7467 else if (VIsual_mode
== Ctrl_V
)
7470 curwin
->w_curswant
= curwin
->w_virtcol
7471 + resel_VIsual_col
* cap
->count0
- 1;
7472 coladvance(curwin
->w_curswant
);
7475 curwin
->w_set_curswant
= TRUE
;
7476 redraw_curbuf_later(INVERTED
); /* show the inversion */
7481 /* start Select mode when 'selectmode' contains "cmd" */
7482 may_start_select('c');
7483 n_start_visual_mode(cap
->cmdchar
);
7489 * Start selection for Shift-movement keys.
7494 /* if 'selectmode' contains "key", start Select mode */
7495 may_start_select('k');
7496 n_start_visual_mode('v');
7500 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu.
7506 VIsual_select
= (stuff_empty() && typebuf_typed()
7507 && (vim_strchr(p_slm
, c
) != NULL
));
7511 * Start Visual mode "c".
7512 * Should set VIsual_select before calling this.
7515 n_start_visual_mode(c
)
7519 VIsual_active
= TRUE
;
7520 VIsual_reselect
= TRUE
;
7521 #ifdef FEAT_VIRTUALEDIT
7522 /* Corner case: the 0 position in a tab may change when going into
7523 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting.
7525 if (c
== Ctrl_V
&& (ve_flags
& VE_BLOCK
) && gchar_cursor() == TAB
)
7526 coladvance(curwin
->w_virtcol
);
7528 VIsual
= curwin
->w_cursor
;
7537 if (p_smd
&& msg_silent
== 0)
7538 redraw_cmdline
= TRUE
; /* show visual mode later */
7539 #ifdef FEAT_CLIPBOARD
7540 /* Make sure the clipboard gets updated. Needed because start and
7541 * end may still be the same, and the selection needs to be owned */
7542 clip_star
.vmode
= NUL
;
7545 /* Only need to redraw this line, unless still need to redraw an old
7546 * Visual area (when 'lazyredraw' is set). */
7547 if (curwin
->w_redr_type
< INVERTED
)
7549 curwin
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
7550 curwin
->w_old_visual_lnum
= curwin
->w_cursor
.lnum
;
7554 #endif /* FEAT_VISUAL */
7557 * CTRL-W: Window commands
7564 if (!checkclearop(cap
->oap
))
7565 do_window(cap
->nchar
, cap
->count0
, NUL
); /* everything is in window.c */
7567 (void)checkclearop(cap
->oap
);
7581 end_visual_mode(); /* stop Visual mode */
7583 do_cmdline_cmd((char_u
*)"st");
7587 * Commands starting with "g".
7593 oparg_T
*oap
= cap
->oap
;
7604 * "g^A": dump log of used memory.
7607 vim_mem_profile_dump();
7611 #ifdef FEAT_VREPLACE
7613 * "gR": Enter virtual replace mode.
7626 do_cmdline_cmd((char_u
*)"%s//~/&");
7631 * "gv": Reselect the previous Visual area. If Visual already active,
7632 * exchange previous and current Visual area.
7635 if (checkclearop(oap
))
7638 if ( curbuf
->b_visual
.vi_start
.lnum
== 0
7639 || curbuf
->b_visual
.vi_start
.lnum
> curbuf
->b_ml
.ml_line_count
7640 || curbuf
->b_visual
.vi_end
.lnum
== 0)
7644 /* set w_cursor to the start of the Visual area, tpos to the end */
7648 VIsual_mode
= curbuf
->b_visual
.vi_mode
;
7649 curbuf
->b_visual
.vi_mode
= i
;
7651 curbuf
->b_visual_mode_eval
= i
;
7653 i
= curwin
->w_curswant
;
7654 curwin
->w_curswant
= curbuf
->b_visual
.vi_curswant
;
7655 curbuf
->b_visual
.vi_curswant
= i
;
7657 tpos
= curbuf
->b_visual
.vi_end
;
7658 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
7659 curwin
->w_cursor
= curbuf
->b_visual
.vi_start
;
7660 curbuf
->b_visual
.vi_start
= VIsual
;
7664 VIsual_mode
= curbuf
->b_visual
.vi_mode
;
7665 curwin
->w_curswant
= curbuf
->b_visual
.vi_curswant
;
7666 tpos
= curbuf
->b_visual
.vi_end
;
7667 curwin
->w_cursor
= curbuf
->b_visual
.vi_start
;
7670 VIsual_active
= TRUE
;
7671 VIsual_reselect
= TRUE
;
7673 /* Set Visual to the start and w_cursor to the end of the Visual
7674 * area. Make sure they are on an existing character. */
7676 VIsual
= curwin
->w_cursor
;
7677 curwin
->w_cursor
= tpos
;
7681 * When called from normal "g" command: start Select mode when
7682 * 'selectmode' contains "cmd". When called for K_SELECT, always
7683 * start Select mode.
7686 VIsual_select
= TRUE
;
7688 may_start_select('c');
7692 #ifdef FEAT_CLIPBOARD
7693 /* Make sure the clipboard gets updated. Needed because start and
7694 * end are still the same, and the selection needs to be owned */
7695 clip_star
.vmode
= NUL
;
7697 redraw_curbuf_later(INVERTED
);
7702 * "gV": Don't reselect the previous Visual area after a Select mode
7706 VIsual_reselect
= FALSE
;
7710 * "gh": start Select mode.
7711 * "gH": start Select line mode.
7712 * "g^H": start Select block mode.
7715 cap
->nchar
= Ctrl_H
;
7721 /* EBCDIC: 'v'-'h' != '^v'-'^h' */
7722 if (cap
->nchar
== Ctrl_H
)
7723 cap
->cmdchar
= Ctrl_V
;
7726 cap
->cmdchar
= cap
->nchar
+ ('v' - 'h');
7730 #endif /* FEAT_VISUAL */
7733 * "gj" and "gk" two new funny movement keys -- up and down
7734 * movement based on *screen* line rather than *file* line.
7738 /* with 'nowrap' it works just like the normal "j" command; also when
7739 * in a closed fold */
7740 if (!curwin
->w_p_wrap
7742 || hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
)
7746 oap
->motion_type
= MLINE
;
7747 i
= cursor_down(cap
->count1
, oap
->op_type
== OP_NOP
);
7750 i
= nv_screengo(oap
, FORWARD
, cap
->count1
);
7757 /* with 'nowrap' it works just like the normal "k" command; also when
7758 * in a closed fold */
7759 if (!curwin
->w_p_wrap
7761 || hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
)
7765 oap
->motion_type
= MLINE
;
7766 i
= cursor_up(cap
->count1
, oap
->op_type
== OP_NOP
);
7769 i
= nv_screengo(oap
, BACKWARD
, cap
->count1
);
7775 * "gJ": join two lines without inserting a space.
7782 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines.
7783 * "gm": middle of "g0" and "g$".
7793 oap
->motion_type
= MCHAR
;
7794 oap
->inclusive
= FALSE
;
7795 if (curwin
->w_p_wrap
7796 #ifdef FEAT_VERTSPLIT
7797 && curwin
->w_width
!= 0
7801 int width1
= W_WIDTH(curwin
) - curwin_col_off();
7802 int width2
= width1
+ curwin_col_off2();
7806 if (curwin
->w_virtcol
>= (colnr_T
)width1
&& width2
> 0)
7807 i
= (curwin
->w_virtcol
- width1
) / width2
* width2
+ width1
;
7810 i
= curwin
->w_leftcol
;
7811 /* Go to the middle of the screen line. When 'number' is on and lines
7812 * are wrapping the middle can be more to the left.*/
7813 if (cap
->nchar
== 'm')
7814 i
+= (W_WIDTH(curwin
) - curwin_col_off()
7815 + ((curwin
->w_p_wrap
&& i
> 0)
7816 ? curwin_col_off2() : 0)) / 2;
7817 coladvance((colnr_T
)i
);
7822 while (vim_iswhite(i
) && oneright() == OK
);
7824 curwin
->w_set_curswant
= TRUE
;
7828 /* "g_": to the last non-blank character in the line or <count> lines
7830 cap
->oap
->motion_type
= MCHAR
;
7831 cap
->oap
->inclusive
= TRUE
;
7832 curwin
->w_curswant
= MAXCOL
;
7833 if (cursor_down((long)(cap
->count1
- 1),
7834 cap
->oap
->op_type
== OP_NOP
) == FAIL
)
7835 clearopbeep(cap
->oap
);
7838 char_u
*ptr
= ml_get_curline();
7840 /* In Visual mode we may end up after the line. */
7841 if (curwin
->w_cursor
.col
> 0 && ptr
[curwin
->w_cursor
.col
] == NUL
)
7842 --curwin
->w_cursor
.col
;
7844 /* Decrease the cursor column until it's on a non-blank. */
7845 while (curwin
->w_cursor
.col
> 0
7846 && vim_iswhite(ptr
[curwin
->w_cursor
.col
]))
7847 --curwin
->w_cursor
.col
;
7848 curwin
->w_set_curswant
= TRUE
;
7856 int col_off
= curwin_col_off();
7858 oap
->motion_type
= MCHAR
;
7859 oap
->inclusive
= TRUE
;
7860 if (curwin
->w_p_wrap
7861 #ifdef FEAT_VERTSPLIT
7862 && curwin
->w_width
!= 0
7866 curwin
->w_curswant
= MAXCOL
; /* so we stay at the end */
7867 if (cap
->count1
== 1)
7869 int width1
= W_WIDTH(curwin
) - col_off
;
7870 int width2
= width1
+ curwin_col_off2();
7874 if (curwin
->w_virtcol
>= (colnr_T
)width1
)
7875 i
+= ((curwin
->w_virtcol
- width1
) / width2
+ 1)
7877 coladvance((colnr_T
)i
);
7878 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
7879 if (curwin
->w_cursor
.col
> 0 && curwin
->w_p_wrap
)
7882 * Check for landing on a character that got split at
7883 * the end of the line. We do not want to advance to
7884 * the next screen line.
7887 if (curwin
->w_virtcol
> (colnr_T
)i
)
7888 --curwin
->w_cursor
.col
;
7892 else if (nv_screengo(oap
, FORWARD
, cap
->count1
- 1) == FAIL
)
7897 i
= curwin
->w_leftcol
+ W_WIDTH(curwin
) - col_off
- 1;
7898 coladvance((colnr_T
)i
);
7900 /* Make sure we stick in this column. */
7902 curwin
->w_curswant
= curwin
->w_virtcol
;
7903 curwin
->w_set_curswant
= FALSE
;
7909 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>"
7914 case POUND
: /* pound sign (sometimes equal to '#') */
7916 case Ctrl_RSB
: /* :tag or :tselect for current identifier */
7917 case ']': /* :tselect for current identifier */
7922 * ge and gE: go back to end of word
7926 oap
->motion_type
= MCHAR
;
7927 curwin
->w_set_curswant
= TRUE
;
7928 oap
->inclusive
= TRUE
;
7929 if (bckend_word(cap
->count1
, cap
->nchar
== 'E', FALSE
) == FAIL
)
7934 * "g CTRL-G": display info about cursor position
7941 * "gi": start Insert at the last position.
7944 if (curbuf
->b_last_insert
.lnum
!= 0)
7946 curwin
->w_cursor
= curbuf
->b_last_insert
;
7947 check_cursor_lnum();
7948 i
= (int)STRLEN(ml_get_curline());
7949 if (curwin
->w_cursor
.col
> (colnr_T
)i
)
7951 #ifdef FEAT_VIRTUALEDIT
7952 if (virtual_active())
7953 curwin
->w_cursor
.coladd
+= curwin
->w_cursor
.col
- i
;
7955 curwin
->w_cursor
.col
= i
;
7963 * "gI": Start insert in column 1.
7967 if (!checkclearopq(oap
))
7968 invoke_edit(cap
, FALSE
, 'g', FALSE
);
7971 #ifdef FEAT_SEARCHPATH
7973 * "gf": goto file, edit file under cursor
7974 * "]f" and "[f": can also be used.
7982 /* "g'm" and "g`m": jump to mark without setting pcmark */
7994 do_sleep(cap
->count1
* 1000L);
7998 * "ga": Display the ascii value of the character under the
7999 * cursor. It is displayed in decimal, hex, and octal. -- webb
8007 * "g8": Display the bytes used for the UTF-8 character under the
8008 * cursor. It is displayed in hex.
8009 * "8g8" finds illegal byte sequence.
8012 if (cap
->count0
== 8)
8024 * "gg": Goto the first line in file. With a count it goes to
8025 * that line number like for "G". -- webb
8033 * Two-character operators:
8035 * "gw" Format text and keep cursor position
8036 * "g~" Toggle the case of the text.
8037 * "gu" Change text to lower case.
8038 * "gU" Change text to upper case.
8039 * "g?" rot13 encoding
8040 * "g@" call 'operatorfunc'
8044 oap
->cursor_start
= curwin
->w_cursor
;
8055 * "gd": Find first occurrence of pattern under the cursor in the
8057 * "gD": idem, but in the current file.
8061 nv_gd(oap
, cap
->nchar
, (int)cap
->count0
);
8066 * g<*Mouse> : <C-*mouse>
8070 case K_MIDDLERELEASE
:
8076 case K_RIGHTRELEASE
:
8083 mod_mask
= MOD_MASK_CTRL
;
8084 (void)do_mouse(oap
, cap
->nchar
, BACKWARD
, cap
->count1
, 0);
8092 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text
8100 /* "go": goto byte count from start of buffer */
8102 goto_byte(cap
->count0
);
8106 /* "gQ": improved Ex mode */
8110 clearopbeep(cap
->oap
);
8115 if (!checkclearopq(oap
))
8119 #ifdef FEAT_JUMPLIST
8125 cap
->count1
= -cap
->count1
;
8132 goto_tabpage((int)cap
->count0
);
8135 goto_tabpage(-(int)cap
->count1
);
8140 case '-': /* "g+" and "g-": undo or redo along the timeline */
8141 if (!checkclearopq(oap
))
8142 undo_time(cap
->nchar
== '-' ? -cap
->count1
: cap
->count1
,
8153 * Handle "o" and "O" commands.
8159 if (!checkclearopq(cap
->oap
))
8162 if (cap
->cmdchar
== 'O')
8163 /* Open above the first line of a folded sequence of lines */
8164 (void)hasFolding(curwin
->w_cursor
.lnum
,
8165 &curwin
->w_cursor
.lnum
, NULL
);
8167 /* Open below the last line of a folded sequence of lines */
8168 (void)hasFolding(curwin
->w_cursor
.lnum
,
8169 NULL
, &curwin
->w_cursor
.lnum
);
8171 if (u_save((linenr_T
)(curwin
->w_cursor
.lnum
-
8172 (cap
->cmdchar
== 'O' ? 1 : 0)),
8173 (linenr_T
)(curwin
->w_cursor
.lnum
+
8174 (cap
->cmdchar
== 'o' ? 1 : 0))
8176 && open_line(cap
->cmdchar
== 'O' ? BACKWARD
: FORWARD
,
8177 #ifdef FEAT_COMMENTS
8178 has_format_option(FO_OPEN_COMS
) ? OPENLINE_DO_COM
:
8182 /* When '#' is in 'cpoptions' ignore the count. */
8183 if (vim_strchr(p_cpo
, CPO_HASH
) != NULL
)
8185 invoke_edit(cap
, FALSE
, cap
->cmdchar
, TRUE
);
8191 * "." command: redo last change.
8197 if (!checkclearopq(cap
->oap
))
8200 * If "restart_edit" is TRUE, the last but one command is repeated
8201 * instead of the last command (inserting text). This is used for
8202 * CTRL-O <.> in insert mode.
8204 if (start_redo(cap
->count0
, restart_edit
!= 0 && !arrow_used
) == FAIL
)
8205 clearopbeep(cap
->oap
);
8216 if (!checkclearopq(cap
->oap
))
8218 u_redo((int)cap
->count1
);
8219 curwin
->w_set_curswant
= TRUE
;
8224 * Handle "U" command.
8230 /* In Visual mode and typing "gUU" triggers an operator */
8231 if (cap
->oap
->op_type
== OP_UPPER
8237 /* translate "gUU" to "gUgU" */
8242 else if (!checkclearopq(cap
->oap
))
8245 curwin
->w_set_curswant
= TRUE
;
8250 * '~' command: If tilde is not an operator and Visual is off: swap case of a
8261 && cap
->oap
->op_type
!= OP_TILDE
)
8268 * Handle an operator command.
8269 * The actual work is done by do_pending_operator().
8277 op_type
= get_op_type(cap
->cmdchar
, cap
->nchar
);
8279 if (op_type
== cap
->oap
->op_type
) /* double operator works on lines */
8281 else if (!checkclearop(cap
->oap
))
8283 cap
->oap
->start
= curwin
->w_cursor
;
8284 cap
->oap
->op_type
= op_type
;
8286 set_op_var(op_type
);
8293 * Set v:operator to the characters for "optype".
8301 if (optype
== OP_NOP
)
8302 set_vim_var_string(VV_OP
, NULL
, 0);
8305 opchars
[0] = get_op_char(optype
);
8306 opchars
[1] = get_extra_op_char(optype
);
8308 set_vim_var_string(VV_OP
, opchars
, -1);
8314 * Handle linewise operator "dd", "yy", etc.
8316 * "_" is is a strange motion command that helps make operators more logical.
8317 * It is actually implemented, but not documented in the real Vi. This motion
8318 * command actually refers to "the current line". Commands like "dd" and "yy"
8319 * are really an alternate form of "d_" and "y_". It does accept a count, so
8320 * "d3_" works to delete 3 lines.
8326 cap
->oap
->motion_type
= MLINE
;
8327 if (cursor_down(cap
->count1
- 1L, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
8328 clearopbeep(cap
->oap
);
8329 else if ( cap
->oap
->op_type
== OP_DELETE
8330 || cap
->oap
->op_type
== OP_LSHIFT
8331 || cap
->oap
->op_type
== OP_RSHIFT
)
8332 beginline(BL_SOL
| BL_FIX
);
8333 else if (cap
->oap
->op_type
!= OP_YANK
) /* 'Y' does not move cursor */
8334 beginline(BL_WHITE
| BL_FIX
);
8344 /* CTRL-HOME is like "gg" */
8345 if (mod_mask
& MOD_MASK_CTRL
)
8352 ins_at_eol
= FALSE
; /* Don't move cursor past eol (only necessary in a
8353 one-character line). */
8363 cap
->oap
->motion_type
= MCHAR
;
8364 cap
->oap
->inclusive
= FALSE
;
8366 if (cap
->count0
> 0)
8368 coladvance((colnr_T
)(cap
->count0
- 1));
8369 curwin
->w_curswant
= (colnr_T
)(cap
->count0
- 1);
8372 curwin
->w_curswant
= 0;
8373 /* keep curswant at the column where we wanted to go, not where
8374 we ended; differs if line is too short */
8375 curwin
->w_set_curswant
= FALSE
;
8379 * Handle back-word command "b" and "B".
8380 * cap->arg is 1 for "B"
8386 cap
->oap
->motion_type
= MCHAR
;
8387 cap
->oap
->inclusive
= FALSE
;
8388 curwin
->w_set_curswant
= TRUE
;
8389 if (bck_word(cap
->count1
, cap
->arg
, FALSE
) == FAIL
)
8390 clearopbeep(cap
->oap
);
8392 else if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8398 * Handle word motion commands "e", "E", "w" and "W".
8399 * cap->arg is TRUE for "E" and "W".
8408 pos_T startpos
= curwin
->w_cursor
;
8411 * Set inclusive for the "E" and "e" command.
8413 if (cap
->cmdchar
== 'e' || cap
->cmdchar
== 'E')
8417 cap
->oap
->inclusive
= word_end
;
8420 * "cw" and "cW" are a special case.
8422 if (!word_end
&& cap
->oap
->op_type
== OP_CHANGE
)
8425 if (n
!= NUL
) /* not an empty line */
8430 * Reproduce a funny Vi behaviour: "cw" on a blank only
8431 * changes one character, not all blanks until the start of
8432 * the next word. Only do this when the 'w' flag is included
8435 if (cap
->count1
== 1 && vim_strchr(p_cpo
, CPO_CW
) != NULL
)
8437 cap
->oap
->inclusive
= TRUE
;
8438 cap
->oap
->motion_type
= MCHAR
;
8445 * This is a little strange. To match what the real Vi does,
8446 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided
8447 * that we are not on a space or a TAB. This seems impolite
8448 * at first, but it's really more what we mean when we say
8450 * Another strangeness: When standing on the end of a word
8451 * "ce" will change until the end of the next wordt, but "cw"
8452 * will change only one character! This is done by setting
8455 cap
->oap
->inclusive
= TRUE
;
8462 cap
->oap
->motion_type
= MCHAR
;
8463 curwin
->w_set_curswant
= TRUE
;
8465 n
= end_word(cap
->count1
, cap
->arg
, flag
, FALSE
);
8467 n
= fwd_word(cap
->count1
, cap
->arg
, cap
->oap
->op_type
!= OP_NOP
);
8469 /* Don't leave the cursor on the NUL past the end of line. Unless we
8470 * didn't move it forward. */
8471 if (lt(startpos
, curwin
->w_cursor
))
8472 adjust_cursor(cap
->oap
);
8474 if (n
== FAIL
&& cap
->oap
->op_type
== OP_NOP
)
8475 clearopbeep(cap
->oap
);
8479 adjust_for_sel(cap
);
8482 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8489 * Used after a movement command: If the cursor ends up on the NUL after the
8490 * end of the line, may move it back to the last character and make the motion
8497 /* The cursor cannot remain on the NUL when:
8498 * - the column is > 0
8499 * - not in Visual mode or 'selection' is "o"
8500 * - 'virtualedit' is not "all" and not "onemore".
8502 if (curwin
->w_cursor
.col
> 0 && gchar_cursor() == NUL
8504 && (!VIsual_active
|| *p_sel
== 'o')
8506 #ifdef FEAT_VIRTUALEDIT
8507 && !virtual_active() && (ve_flags
& VE_ONEMORE
) == 0
8511 --curwin
->w_cursor
.col
;
8513 /* prevent cursor from moving on the trail byte */
8517 oap
->inclusive
= TRUE
;
8522 * "0" and "^" commands.
8523 * cap->arg is the argument for beginline().
8529 cap
->oap
->motion_type
= MCHAR
;
8530 cap
->oap
->inclusive
= FALSE
;
8531 beginline(cap
->arg
);
8533 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8536 ins_at_eol
= FALSE
; /* Don't move cursor past eol (only necessary in a
8537 one-character line). */
8542 * In exclusive Visual mode, may include the last character.
8548 if (VIsual_active
&& cap
->oap
->inclusive
&& *p_sel
== 'e'
8549 && gchar_cursor() != NUL
&& lt(VIsual
, curwin
->w_cursor
))
8556 ++curwin
->w_cursor
.col
;
8557 cap
->oap
->inclusive
= FALSE
;
8562 * Exclude last character at end of Visual area for 'selection' == "exclusive".
8563 * Should check VIsual_mode before calling this.
8564 * Returns TRUE when backed up to the previous line.
8571 if (*p_sel
== 'e' && !equalpos(VIsual
, curwin
->w_cursor
))
8573 if (lt(VIsual
, curwin
->w_cursor
))
8574 pp
= &curwin
->w_cursor
;
8577 #ifdef FEAT_VIRTUALEDIT
8589 else if (pp
->lnum
> 1)
8592 pp
->col
= (colnr_T
)STRLEN(ml_get(pp
->lnum
));
8600 * SELECT key in Normal or Visual mode: end of Select mode mapping.
8607 VIsual_select
= TRUE
;
8608 else if (VIsual_reselect
)
8610 cap
->nchar
= 'v'; /* fake "gv" command */
8619 * "G", "gg", CTRL-END, CTRL-HOME.
8620 * cap->arg is TRUE for "G".
8629 lnum
= curbuf
->b_ml
.ml_line_count
;
8632 cap
->oap
->motion_type
= MLINE
;
8635 /* When a count is given, use it instead of the default lnum */
8636 if (cap
->count0
!= 0)
8640 else if (lnum
> curbuf
->b_ml
.ml_line_count
)
8641 lnum
= curbuf
->b_ml
.ml_line_count
;
8642 curwin
->w_cursor
.lnum
= lnum
;
8643 beginline(BL_SOL
| BL_FIX
);
8645 if ((fdo_flags
& FDO_JUMP
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8651 * CTRL-\ in Normal mode.
8657 if (cap
->nchar
== Ctrl_N
|| cap
->nchar
== Ctrl_G
)
8660 if (restart_edit
!= 0 && mode_displayed
)
8661 clear_cmdline
= TRUE
; /* unshow mode later */
8664 if (cmdwin_type
!= 0)
8665 cmdwin_result
= Ctrl_C
;
8670 end_visual_mode(); /* stop Visual */
8671 redraw_curbuf_later(INVERTED
);
8674 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */
8675 if (cap
->nchar
== Ctrl_G
&& p_im
)
8679 clearopbeep(cap
->oap
);
8683 * ESC in Normal mode: beep, but don't flush buffers.
8684 * Don't even beep if we are canceling a command.
8692 no_reason
= (cap
->oap
->op_type
== OP_NOP
8693 && cap
->opcount
== 0
8695 && cap
->oap
->regname
== 0
8698 if (cap
->arg
) /* TRUE for CTRL-C */
8700 if (restart_edit
== 0
8708 MSG(_("Type :quit<Enter> to exit Vim"));
8710 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be
8711 * set again below when halfway a mapping. */
8715 if (cmdwin_type
!= 0)
8717 cmdwin_result
= K_IGNORE
;
8718 got_int
= FALSE
; /* don't stop executing autocommands et al. */
8727 end_visual_mode(); /* stop Visual */
8728 check_cursor_col(); /* make sure cursor is not beyond EOL */
8729 curwin
->w_set_curswant
= TRUE
;
8730 redraw_curbuf_later(INVERTED
);
8738 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is
8739 * set return to Insert mode afterwards. */
8740 if (restart_edit
== 0 && goto_im()
8741 #ifdef FEAT_EX_EXTRA
8742 && ex_normal_busy
== 0
8749 * Handle "A", "a", "I", "i" and <Insert> commands.
8755 /* <Insert> is equal to "i" */
8756 if (cap
->cmdchar
== K_INS
|| cap
->cmdchar
== K_KINS
)
8760 /* in Visual mode "A" and "I" are an operator */
8761 if (VIsual_active
&& (cap
->cmdchar
== 'A' || cap
->cmdchar
== 'I'))
8764 /* in Visual mode and after an operator "a" and "i" are for text objects */
8767 if ((cap
->cmdchar
== 'a' || cap
->cmdchar
== 'i')
8768 && (cap
->oap
->op_type
!= OP_NOP
8777 clearopbeep(cap
->oap
);
8780 else if (!curbuf
->b_p_ma
&& !p_im
)
8782 /* Only give this error when 'insertmode' is off. */
8783 EMSG(_(e_modifiable
));
8786 else if (!checkclearopq(cap
->oap
))
8788 switch (cap
->cmdchar
)
8790 case 'A': /* "A"ppend after the line */
8791 curwin
->w_set_curswant
= TRUE
;
8792 #ifdef FEAT_VIRTUALEDIT
8793 if (ve_flags
== VE_ALL
)
8795 int save_State
= State
;
8797 /* Pretent Insert mode here to allow the cursor on the
8798 * character past the end of the line */
8800 coladvance((colnr_T
)MAXCOL
);
8805 curwin
->w_cursor
.col
+= (colnr_T
)STRLEN(ml_get_cursor());
8808 case 'I': /* "I"nsert before the first non-blank */
8809 if (vim_strchr(p_cpo
, CPO_INSEND
) == NULL
)
8810 beginline(BL_WHITE
);
8812 beginline(BL_WHITE
|BL_FIX
);
8815 case 'a': /* "a"ppend is like "i"nsert on the next character. */
8816 #ifdef FEAT_VIRTUALEDIT
8817 /* increment coladd when in virtual space, increment the
8818 * column otherwise, also to append after an unprintable char */
8819 if (virtual_active()
8820 && (curwin
->w_cursor
.coladd
> 0
8821 || *ml_get_cursor() == NUL
8822 || *ml_get_cursor() == TAB
))
8823 curwin
->w_cursor
.coladd
++;
8826 if (*ml_get_cursor() != NUL
)
8831 #ifdef FEAT_VIRTUALEDIT
8832 if (curwin
->w_cursor
.coladd
&& cap
->cmdchar
!= 'A')
8834 int save_State
= State
;
8836 /* Pretent Insert mode here to allow the cursor on the
8837 * character past the end of the line */
8839 coladvance(getviscol());
8844 invoke_edit(cap
, FALSE
, cap
->cmdchar
, FALSE
);
8849 * Invoke edit() and take care of "restart_edit" and the return value.
8852 invoke_edit(cap
, repl
, cmd
, startln
)
8854 int repl
; /* "r" or "gr" command */
8858 int restart_edit_save
= 0;
8860 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert
8861 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow
8863 if (repl
|| !stuff_empty())
8864 restart_edit_save
= restart_edit
;
8866 restart_edit_save
= 0;
8868 /* Always reset "restart_edit", this is not a restarted edit. */
8871 if (edit(cmd
, startln
, cap
->count1
))
8872 cap
->retval
|= CA_COMMAND_BUSY
;
8874 if (restart_edit
== 0)
8875 restart_edit
= restart_edit_save
;
8880 * "a" or "i" while an operator is pending or in Visual mode: object motion.
8890 if (cap
->cmdchar
== 'i')
8891 include
= FALSE
; /* "ix" = inner object: exclude white space */
8893 include
= TRUE
; /* "ax" = an object: include white space */
8895 /* Make sure (), [], {} and <> are in 'matchpairs' */
8896 mps_save
= curbuf
->b_p_mps
;
8897 curbuf
->b_p_mps
= (char_u
*)"(:),{:},[:],<:>";
8901 case 'w': /* "aw" = a word */
8902 flag
= current_word(cap
->oap
, cap
->count1
, include
, FALSE
);
8904 case 'W': /* "aW" = a WORD */
8905 flag
= current_word(cap
->oap
, cap
->count1
, include
, TRUE
);
8907 case 'b': /* "ab" = a braces block */
8910 flag
= current_block(cap
->oap
, cap
->count1
, include
, '(', ')');
8912 case 'B': /* "aB" = a Brackets block */
8915 flag
= current_block(cap
->oap
, cap
->count1
, include
, '{', '}');
8917 case '[': /* "a[" = a [] block */
8919 flag
= current_block(cap
->oap
, cap
->count1
, include
, '[', ']');
8921 case '<': /* "a<" = a <> block */
8923 flag
= current_block(cap
->oap
, cap
->count1
, include
, '<', '>');
8925 case 't': /* "at" = a tag block (xml and html) */
8926 flag
= current_tagblock(cap
->oap
, cap
->count1
, include
);
8928 case 'p': /* "ap" = a paragraph */
8929 flag
= current_par(cap
->oap
, cap
->count1
, include
, 'p');
8931 case 's': /* "as" = a sentence */
8932 flag
= current_sent(cap
->oap
, cap
->count1
, include
);
8934 case '"': /* "a"" = a double quoted string */
8935 case '\'': /* "a'" = a single quoted string */
8936 case '`': /* "a`" = a backtick quoted string */
8937 flag
= current_quote(cap
->oap
, cap
->count1
, include
,
8941 case 'S': /* "aS" = a section */
8942 case 'f': /* "af" = a filename */
8943 case 'u': /* "au" = a URL */
8950 curbuf
->b_p_mps
= mps_save
;
8952 clearopbeep(cap
->oap
);
8953 adjust_cursor_col();
8954 curwin
->w_set_curswant
= TRUE
;
8959 * "q" command: Start/stop recording.
8960 * "q:", "q/", "q?": edit command-line in command-line window.
8966 if (cap
->oap
->op_type
== OP_FORMAT
)
8968 /* "gqq" is the same as "gqgq": format line */
8973 else if (!checkclearop(cap
->oap
))
8976 if (cap
->nchar
== ':' || cap
->nchar
== '/' || cap
->nchar
== '?')
8978 stuffcharReadbuff(cap
->nchar
);
8979 stuffcharReadbuff(K_CMDWIN
);
8983 /* (stop) recording into a named register, unless executing a
8985 if (!Exec_reg
&& do_record(cap
->nchar
) == FAIL
)
8986 clearopbeep(cap
->oap
);
8991 * Handle the "@r" command.
8997 if (checkclearop(cap
->oap
))
9000 if (cap
->nchar
== '=')
9002 if (get_expr_register() == NUL
)
9006 while (cap
->count1
-- && !got_int
)
9008 if (do_execreg(cap
->nchar
, FALSE
, FALSE
, FALSE
) == FAIL
)
9010 clearopbeep(cap
->oap
);
9018 * Handle the CTRL-U and CTRL-D commands.
9024 if ((cap
->cmdchar
== Ctrl_U
&& curwin
->w_cursor
.lnum
== 1)
9025 || (cap
->cmdchar
== Ctrl_D
9026 && curwin
->w_cursor
.lnum
== curbuf
->b_ml
.ml_line_count
))
9027 clearopbeep(cap
->oap
);
9028 else if (!checkclearop(cap
->oap
))
9029 halfpage(cap
->cmdchar
== Ctrl_D
, cap
->count0
);
9033 * Handle "J" or "gJ" command.
9040 if (VIsual_active
) /* join the visual lines */
9044 if (!checkclearop(cap
->oap
))
9046 if (cap
->count0
<= 1)
9047 cap
->count0
= 2; /* default for join is two lines! */
9048 if (curwin
->w_cursor
.lnum
+ cap
->count0
- 1 >
9049 curbuf
->b_ml
.ml_line_count
)
9050 clearopbeep(cap
->oap
); /* beyond last line */
9053 prep_redo(cap
->oap
->regname
, cap
->count0
,
9054 NUL
, cap
->cmdchar
, NUL
, NUL
, cap
->nchar
);
9055 do_do_join(cap
->count0
, cap
->nchar
== NUL
);
9061 * "P", "gP", "p" and "gp" commands.
9069 void *reg1
= NULL
, *reg2
= NULL
;
9071 int was_visual
= FALSE
;
9076 if (cap
->oap
->op_type
!= OP_NOP
)
9079 /* "dp" is ":diffput" */
9080 if (cap
->oap
->op_type
== OP_DELETE
&& cap
->cmdchar
== 'p')
9083 nv_diffgetput(TRUE
);
9087 clearopbeep(cap
->oap
);
9091 dir
= (cap
->cmdchar
== 'P'
9092 || (cap
->cmdchar
== 'g' && cap
->nchar
== 'P'))
9093 ? BACKWARD
: FORWARD
;
9095 if (cap
->cmdchar
== 'g')
9096 flags
|= PUT_CURSEND
;
9101 /* Putting in Visual mode: The put text replaces the selected
9102 * text. First delete the selected text, then put the new text.
9103 * Need to save and restore the registers that the delete
9104 * overwrites if the old contents is being put.
9107 regname
= cap
->oap
->regname
;
9108 # ifdef FEAT_CLIPBOARD
9109 adjust_clip_reg(®name
);
9111 if (regname
== 0 || VIM_ISDIGIT(regname
)
9112 # ifdef FEAT_CLIPBOARD
9113 || (clip_unnamed
&& (regname
== '*' || regname
== '+'))
9118 /* the delete is going to overwrite the register we want to
9119 * put, save it first. */
9120 reg1
= get_register(regname
, TRUE
);
9123 /* Now delete the selected text. */
9126 cap
->oap
->regname
= NUL
;
9128 do_pending_operator(cap
, 0, FALSE
);
9129 empty
= (curbuf
->b_ml
.ml_flags
& ML_EMPTY
);
9131 /* delete PUT_LINE_BACKWARD; */
9132 cap
->oap
->regname
= regname
;
9136 /* Delete probably changed the register we want to put, save
9137 * it first. Then put back what was there before the delete. */
9138 reg2
= get_register(regname
, FALSE
);
9139 put_register(regname
, reg1
);
9142 /* When deleted a linewise Visual area, put the register as
9143 * lines to avoid it joined with the next line. When deletion was
9144 * characterwise, split a line when putting lines. */
9145 if (VIsual_mode
== 'V')
9147 else if (VIsual_mode
== 'v')
9148 flags
|= PUT_LINE_SPLIT
;
9149 if (VIsual_mode
== Ctrl_V
&& dir
== FORWARD
)
9150 flags
|= PUT_LINE_FORWARD
;
9152 if ((VIsual_mode
!= 'V'
9153 && curwin
->w_cursor
.col
< curbuf
->b_op_start
.col
)
9154 || (VIsual_mode
== 'V'
9155 && curwin
->w_cursor
.lnum
< curbuf
->b_op_start
.lnum
))
9156 /* cursor is at the end of the line or end of file, put
9161 do_put(cap
->oap
->regname
, dir
, cap
->count1
, flags
);
9164 /* If a register was saved, put it back now. */
9166 put_register(regname
, reg2
);
9168 /* What to reselect with "gv"? Selecting the just put text seems to
9169 * be the most useful, since the original text was removed. */
9172 curbuf
->b_visual
.vi_start
= curbuf
->b_op_start
;
9173 curbuf
->b_visual
.vi_end
= curbuf
->b_op_end
;
9176 /* When all lines were selected and deleted do_put() leaves an empty
9177 * line that needs to be deleted now. */
9178 if (empty
&& *ml_get(curbuf
->b_ml
.ml_line_count
) == NUL
)
9180 ml_delete(curbuf
->b_ml
.ml_line_count
, TRUE
);
9182 /* If the cursor was in that line, move it to the end of the last
9184 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
9186 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
9187 coladvance((colnr_T
)MAXCOL
);
9191 auto_format(FALSE
, TRUE
);
9196 * "o" and "O" commands.
9203 /* "do" is ":diffget" */
9204 if (cap
->oap
->op_type
== OP_DELETE
&& cap
->cmdchar
== 'o')
9207 nv_diffgetput(FALSE
);
9212 if (VIsual_active
) /* switch start and end of visual */
9213 v_swap_corners(cap
->cmdchar
);
9225 ProcessSniffRequests();
9229 #ifdef FEAT_NETBEANS_INTG
9234 netbeans_keycommand(cap
->nchar
);
9244 do_put('~', BACKWARD
, 1L, PUT_CURSEND
);
9250 * Trigger CursorHold event.
9251 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the
9252 * input buffer. "did_cursorhold" is set to avoid retriggering.
9259 apply_autocmds(EVENT_CURSORHOLD
, NULL
, NULL
, FALSE
, curbuf
);
9260 did_cursorhold
= TRUE
;
9261 cap
->retval
|= CA_COMMAND_BUSY
; /* don't call edit() now */