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
));
144 static void nv_lineop
__ARGS((cmdarg_T
*cap
));
145 static void nv_home
__ARGS((cmdarg_T
*cap
));
146 static void nv_pipe
__ARGS((cmdarg_T
*cap
));
147 static void nv_bck_word
__ARGS((cmdarg_T
*cap
));
148 static void nv_wordcmd
__ARGS((cmdarg_T
*cap
));
149 static void nv_beginline
__ARGS((cmdarg_T
*cap
));
151 static void adjust_for_sel
__ARGS((cmdarg_T
*cap
));
152 static int unadjust_for_sel
__ARGS((void));
153 static void nv_select
__ARGS((cmdarg_T
*cap
));
155 static void nv_goto
__ARGS((cmdarg_T
*cap
));
156 static void nv_normal
__ARGS((cmdarg_T
*cap
));
157 static void nv_esc
__ARGS((cmdarg_T
*oap
));
158 static void nv_edit
__ARGS((cmdarg_T
*cap
));
159 static void invoke_edit
__ARGS((cmdarg_T
*cap
, int repl
, int cmd
, int startln
));
161 static void nv_object
__ARGS((cmdarg_T
*cap
));
163 static void nv_record
__ARGS((cmdarg_T
*cap
));
164 static void nv_at
__ARGS((cmdarg_T
*cap
));
165 static void nv_halfpage
__ARGS((cmdarg_T
*cap
));
166 static void nv_join
__ARGS((cmdarg_T
*cap
));
167 static void nv_put
__ARGS((cmdarg_T
*cap
));
168 static void nv_open
__ARGS((cmdarg_T
*cap
));
170 static void nv_sniff
__ARGS((cmdarg_T
*cap
));
172 #ifdef FEAT_NETBEANS_INTG
173 static void nv_nbcmd
__ARGS((cmdarg_T
*cap
));
176 static void nv_drop
__ARGS((cmdarg_T
*cap
));
179 static void nv_cursorhold
__ARGS((cmdarg_T
*cap
));
183 * Function to be called for a Normal or Visual mode command.
184 * The argument is a cmdarg_T.
186 typedef void (*nv_func_T
) __ARGS((cmdarg_T
*cap
));
188 /* Values for cmd_flags. */
189 #define NV_NCH 0x01 /* may need to get a second char */
190 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */
191 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */
192 #define NV_LANG 0x08 /* second char needs language adjustment */
194 #define NV_SS 0x10 /* may start selection */
195 #define NV_SSS 0x20 /* may start selection with shift modifier */
196 #define NV_STS 0x40 /* may stop selection without shift modif. */
197 #define NV_RL 0x80 /* 'rightleft' modifies command */
198 #define NV_KEEPREG 0x100 /* don't clear regname */
199 #define NV_NCW 0x200 /* not allowed in command-line window */
202 * Generally speaking, every Normal mode command should either clear any
203 * pending operator (with *clearop*()), or set the motion type variable
206 * When a cursor motion command is made, it is marked as being a character or
207 * line oriented motion. Then, if an operator is in effect, the operation
208 * becomes character or line oriented accordingly.
212 * This table contains one entry for every Normal or Visual mode command.
213 * The order doesn't matter, init_normal_cmds() will create a sorted index.
214 * It is faster when all keys from zero to '~' are present.
216 static const struct nv_cmd
218 int cmd_char
; /* (first) command character */
219 nv_func_T cmd_func
; /* function for this command */
220 short_u cmd_flags
; /* NV_ flags */
221 short cmd_arg
; /* value for ca.arg */
224 {NUL
, nv_error
, 0, 0},
225 {Ctrl_A
, nv_addsub
, 0, 0},
226 {Ctrl_B
, nv_page
, NV_STS
, BACKWARD
},
227 {Ctrl_C
, nv_esc
, 0, TRUE
},
228 {Ctrl_D
, nv_halfpage
, 0, 0},
229 {Ctrl_E
, nv_scroll_line
, 0, TRUE
},
230 {Ctrl_F
, nv_page
, NV_STS
, FORWARD
},
231 {Ctrl_G
, nv_ctrlg
, 0, 0},
232 {Ctrl_H
, nv_ctrlh
, 0, 0},
233 {Ctrl_I
, nv_pcmark
, 0, 0},
234 {NL
, nv_down
, 0, FALSE
},
235 {Ctrl_K
, nv_error
, 0, 0},
236 {Ctrl_L
, nv_clear
, 0, 0},
237 {Ctrl_M
, nv_down
, 0, TRUE
},
238 {Ctrl_N
, nv_down
, NV_STS
, FALSE
},
239 {Ctrl_O
, nv_ctrlo
, 0, 0},
240 {Ctrl_P
, nv_up
, NV_STS
, FALSE
},
242 {Ctrl_Q
, nv_visual
, 0, FALSE
},
244 {Ctrl_Q
, nv_ignore
, 0, 0},
246 {Ctrl_R
, nv_redo
, 0, 0},
247 {Ctrl_S
, nv_ignore
, 0, 0},
248 {Ctrl_T
, nv_tagpop
, NV_NCW
, 0},
249 {Ctrl_U
, nv_halfpage
, 0, 0},
251 {Ctrl_V
, nv_visual
, 0, FALSE
},
252 {'V', nv_visual
, 0, FALSE
},
253 {'v', nv_visual
, 0, FALSE
},
255 {Ctrl_V
, nv_error
, 0, 0},
256 {'V', nv_error
, 0, 0},
257 {'v', nv_error
, 0, 0},
259 {Ctrl_W
, nv_window
, 0, 0},
260 {Ctrl_X
, nv_addsub
, 0, 0},
261 {Ctrl_Y
, nv_scroll_line
, 0, FALSE
},
262 {Ctrl_Z
, nv_suspend
, 0, 0},
263 {ESC
, nv_esc
, 0, FALSE
},
264 {Ctrl_BSL
, nv_normal
, NV_NCH_ALW
, 0},
265 {Ctrl_RSB
, nv_ident
, NV_NCW
, 0},
266 {Ctrl_HAT
, nv_hat
, NV_NCW
, 0},
267 {Ctrl__
, nv_error
, 0, 0},
268 {' ', nv_right
, 0, 0},
269 {'!', nv_operator
, 0, 0},
270 {'"', nv_regname
, NV_NCH_NOP
|NV_KEEPREG
, 0},
271 {'#', nv_ident
, 0, 0},
272 {'$', nv_dollar
, 0, 0},
273 {'%', nv_percent
, 0, 0},
274 {'&', nv_optrans
, 0, 0},
275 {'\'', nv_gomark
, NV_NCH_ALW
, TRUE
},
276 {'(', nv_brace
, 0, BACKWARD
},
277 {')', nv_brace
, 0, FORWARD
},
278 {'*', nv_ident
, 0, 0},
279 {'+', nv_down
, 0, TRUE
},
280 {',', nv_csearch
, 0, TRUE
},
281 {'-', nv_up
, 0, TRUE
},
282 {'.', nv_dot
, NV_KEEPREG
, 0},
283 {'/', nv_search
, 0, FALSE
},
284 {'0', nv_beginline
, 0, 0},
285 {'1', nv_ignore
, 0, 0},
286 {'2', nv_ignore
, 0, 0},
287 {'3', nv_ignore
, 0, 0},
288 {'4', nv_ignore
, 0, 0},
289 {'5', nv_ignore
, 0, 0},
290 {'6', nv_ignore
, 0, 0},
291 {'7', nv_ignore
, 0, 0},
292 {'8', nv_ignore
, 0, 0},
293 {'9', nv_ignore
, 0, 0},
294 {':', nv_colon
, 0, 0},
295 {';', nv_csearch
, 0, FALSE
},
296 {'<', nv_operator
, NV_RL
, 0},
297 {'=', nv_operator
, 0, 0},
298 {'>', nv_operator
, NV_RL
, 0},
299 {'?', nv_search
, 0, FALSE
},
300 {'@', nv_at
, NV_NCH_NOP
, FALSE
},
301 {'A', nv_edit
, 0, 0},
302 {'B', nv_bck_word
, 0, 1},
303 {'C', nv_abbrev
, NV_KEEPREG
, 0},
304 {'D', nv_abbrev
, NV_KEEPREG
, 0},
305 {'E', nv_wordcmd
, 0, TRUE
},
306 {'F', nv_csearch
, NV_NCH_ALW
|NV_LANG
, BACKWARD
},
307 {'G', nv_goto
, 0, TRUE
},
308 {'H', nv_scroll
, 0, 0},
309 {'I', nv_edit
, 0, 0},
310 {'J', nv_join
, 0, 0},
311 {'K', nv_ident
, 0, 0},
312 {'L', nv_scroll
, 0, 0},
313 {'M', nv_scroll
, 0, 0},
314 {'N', nv_next
, 0, SEARCH_REV
},
315 {'O', nv_open
, 0, 0},
317 {'Q', nv_exmode
, NV_NCW
, 0},
318 {'R', nv_Replace
, 0, FALSE
},
319 {'S', nv_subst
, NV_KEEPREG
, 0},
320 {'T', nv_csearch
, NV_NCH_ALW
|NV_LANG
, BACKWARD
},
321 {'U', nv_Undo
, 0, 0},
322 {'W', nv_wordcmd
, 0, TRUE
},
323 {'X', nv_abbrev
, NV_KEEPREG
, 0},
324 {'Y', nv_abbrev
, NV_KEEPREG
, 0},
325 {'Z', nv_Zet
, NV_NCH_NOP
|NV_NCW
, 0},
326 {'[', nv_brackets
, NV_NCH_ALW
, BACKWARD
},
327 {'\\', nv_error
, 0, 0},
328 {']', nv_brackets
, NV_NCH_ALW
, FORWARD
},
329 {'^', nv_beginline
, 0, BL_WHITE
| BL_FIX
},
330 {'_', nv_lineop
, 0, 0},
331 {'`', nv_gomark
, NV_NCH_ALW
, FALSE
},
332 {'a', nv_edit
, NV_NCH
, 0},
333 {'b', nv_bck_word
, 0, 0},
334 {'c', nv_operator
, 0, 0},
335 {'d', nv_operator
, 0, 0},
336 {'e', nv_wordcmd
, 0, FALSE
},
337 {'f', nv_csearch
, NV_NCH_ALW
|NV_LANG
, FORWARD
},
338 {'g', nv_g_cmd
, NV_NCH_ALW
, FALSE
},
339 {'h', nv_left
, NV_RL
, 0},
340 {'i', nv_edit
, NV_NCH
, 0},
341 {'j', nv_down
, 0, FALSE
},
342 {'k', nv_up
, 0, FALSE
},
343 {'l', nv_right
, NV_RL
, 0},
344 {'m', nv_mark
, NV_NCH_NOP
, 0},
345 {'n', nv_next
, 0, 0},
346 {'o', nv_open
, 0, 0},
348 {'q', nv_record
, NV_NCH
, 0},
349 {'r', nv_replace
, NV_NCH_NOP
|NV_LANG
, 0},
350 {'s', nv_subst
, NV_KEEPREG
, 0},
351 {'t', nv_csearch
, NV_NCH_ALW
|NV_LANG
, FORWARD
},
352 {'u', nv_undo
, 0, 0},
353 {'w', nv_wordcmd
, 0, FALSE
},
354 {'x', nv_abbrev
, NV_KEEPREG
, 0},
355 {'y', nv_operator
, 0, 0},
356 {'z', nv_zet
, NV_NCH_ALW
, 0},
357 {'{', nv_findpar
, 0, BACKWARD
},
358 {'|', nv_pipe
, 0, 0},
359 {'}', nv_findpar
, 0, FORWARD
},
360 {'~', nv_tilde
, 0, 0},
363 {POUND
, nv_ident
, 0, 0},
365 {K_MOUSEUP
, nv_mousescroll
, 0, TRUE
},
366 {K_MOUSEDOWN
, nv_mousescroll
, 0, FALSE
},
367 {K_LEFTMOUSE
, nv_mouse
, 0, 0},
368 {K_LEFTMOUSE_NM
, nv_mouse
, 0, 0},
369 {K_LEFTDRAG
, nv_mouse
, 0, 0},
370 {K_LEFTRELEASE
, nv_mouse
, 0, 0},
371 {K_LEFTRELEASE_NM
, nv_mouse
, 0, 0},
372 {K_MIDDLEMOUSE
, nv_mouse
, 0, 0},
373 {K_MIDDLEDRAG
, nv_mouse
, 0, 0},
374 {K_MIDDLERELEASE
, nv_mouse
, 0, 0},
375 {K_RIGHTMOUSE
, nv_mouse
, 0, 0},
376 {K_RIGHTDRAG
, nv_mouse
, 0, 0},
377 {K_RIGHTRELEASE
, nv_mouse
, 0, 0},
378 {K_X1MOUSE
, nv_mouse
, 0, 0},
379 {K_X1DRAG
, nv_mouse
, 0, 0},
380 {K_X1RELEASE
, nv_mouse
, 0, 0},
381 {K_X2MOUSE
, nv_mouse
, 0, 0},
382 {K_X2DRAG
, nv_mouse
, 0, 0},
383 {K_X2RELEASE
, nv_mouse
, 0, 0},
385 {K_IGNORE
, nv_ignore
, NV_KEEPREG
, 0},
386 {K_NOP
, nv_nop
, 0, 0},
387 {K_INS
, nv_edit
, 0, 0},
388 {K_KINS
, nv_edit
, 0, 0},
389 {K_BS
, nv_ctrlh
, 0, 0},
390 {K_UP
, nv_up
, NV_SSS
|NV_STS
, FALSE
},
391 {K_S_UP
, nv_page
, NV_SS
, BACKWARD
},
392 {K_DOWN
, nv_down
, NV_SSS
|NV_STS
, FALSE
},
393 {K_S_DOWN
, nv_page
, NV_SS
, FORWARD
},
394 {K_LEFT
, nv_left
, NV_SSS
|NV_STS
|NV_RL
, 0},
395 {K_S_LEFT
, nv_bck_word
, NV_SS
|NV_RL
, 0},
396 {K_C_LEFT
, nv_bck_word
, NV_SSS
|NV_RL
|NV_STS
, 1},
397 {K_RIGHT
, nv_right
, NV_SSS
|NV_STS
|NV_RL
, 0},
398 {K_S_RIGHT
, nv_wordcmd
, NV_SS
|NV_RL
, FALSE
},
399 {K_C_RIGHT
, nv_wordcmd
, NV_SSS
|NV_RL
|NV_STS
, TRUE
},
400 {K_PAGEUP
, nv_page
, NV_SSS
|NV_STS
, BACKWARD
},
401 {K_KPAGEUP
, nv_page
, NV_SSS
|NV_STS
, BACKWARD
},
402 {K_PAGEDOWN
, nv_page
, NV_SSS
|NV_STS
, FORWARD
},
403 {K_KPAGEDOWN
, nv_page
, NV_SSS
|NV_STS
, FORWARD
},
404 {K_END
, nv_end
, NV_SSS
|NV_STS
, FALSE
},
405 {K_KEND
, nv_end
, NV_SSS
|NV_STS
, FALSE
},
406 {K_S_END
, nv_end
, NV_SS
, FALSE
},
407 {K_C_END
, nv_end
, NV_SSS
|NV_STS
, TRUE
},
408 {K_HOME
, nv_home
, NV_SSS
|NV_STS
, 0},
409 {K_KHOME
, nv_home
, NV_SSS
|NV_STS
, 0},
410 {K_S_HOME
, nv_home
, NV_SS
, 0},
411 {K_C_HOME
, nv_goto
, NV_SSS
|NV_STS
, FALSE
},
412 {K_DEL
, nv_abbrev
, 0, 0},
413 {K_KDEL
, nv_abbrev
, 0, 0},
414 {K_UNDO
, nv_kundo
, 0, 0},
415 {K_HELP
, nv_help
, NV_NCW
, 0},
416 {K_F1
, nv_help
, NV_NCW
, 0},
417 {K_XF1
, nv_help
, NV_NCW
, 0},
419 {K_SELECT
, nv_select
, 0, 0},
422 {K_VER_SCROLLBAR
, nv_ver_scrollbar
, 0, 0},
423 {K_HOR_SCROLLBAR
, nv_hor_scrollbar
, 0, 0},
425 #ifdef FEAT_GUI_TABLINE
426 {K_TABLINE
, nv_tabline
, 0, 0},
427 {K_TABMENU
, nv_tabmenu
, 0, 0},
430 {K_F8
, farsi_fkey
, 0, 0},
431 {K_F9
, farsi_fkey
, 0, 0},
434 {K_SNIFF
, nv_sniff
, 0, 0},
436 #ifdef FEAT_NETBEANS_INTG
437 {K_F21
, nv_nbcmd
, NV_NCH_ALW
, 0},
440 {K_DROP
, nv_drop
, NV_STS
, 0},
443 {K_CURSORHOLD
, nv_cursorhold
, NV_KEEPREG
, 0},
447 /* Number of commands in nv_cmds[]. */
448 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd))
450 /* Sorted index of commands in nv_cmds[]. */
451 static short nv_cmd_idx
[NV_CMDS_SIZE
];
453 /* The highest index for which
454 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */
455 static int nv_max_linear
;
458 * Compare functions for qsort() below, that checks the command character
459 * through the index in nv_cmd_idx[].
471 /* The commands are sorted on absolute value. */
472 c1
= nv_cmds
[*(const short *)s1
].cmd_char
;
473 c2
= nv_cmds
[*(const short *)s2
].cmd_char
;
482 * Initialize the nv_cmd_idx[] table.
489 /* Fill the index table with a one to one relation. */
490 for (i
= 0; i
< NV_CMDS_SIZE
; ++i
)
493 /* Sort the commands by the command character. */
494 qsort((void *)&nv_cmd_idx
, (size_t)NV_CMDS_SIZE
, sizeof(short), nv_compare
);
496 /* Find the first entry that can't be indexed by the command character. */
497 for (i
= 0; i
< NV_CMDS_SIZE
; ++i
)
498 if (i
!= nv_cmds
[nv_cmd_idx
[i
]].cmd_char
)
500 nv_max_linear
= i
- 1;
504 * Search for a command in the commands table.
505 * Returns -1 for invalid command.
508 find_command(cmdchar
)
517 /* A multi-byte character is never a command. */
518 if (cmdchar
>= 0x100)
522 /* We use the absolute value of the character. Special keys have a
523 * negative value, but are sorted on their absolute value. */
527 /* If the character is in the first part: The character is the index into
529 if (cmdchar
<= nv_max_linear
)
530 return nv_cmd_idx
[cmdchar
];
532 /* Perform a binary search. */
533 bot
= nv_max_linear
+ 1;
534 top
= NV_CMDS_SIZE
- 1;
539 c
= nv_cmds
[nv_cmd_idx
[i
]].cmd_char
;
556 * Execute a command in Normal mode.
560 normal_cmd(oap
, toplevel
)
562 int toplevel
; /* TRUE when called from main() */
564 static long opcount
= 0; /* ca.opcount saved here */
565 cmdarg_T ca
; /* command arguments */
567 int ctrl_w
= FALSE
; /* got CTRL-W command */
568 int old_col
= curwin
->w_curswant
;
569 #ifdef FEAT_CMDL_INFO
570 int need_flushbuf
; /* need to call out_flush() */
573 pos_T old_pos
; /* cursor position before command */
575 static int old_mapped_len
= 0;
579 vim_memset(&ca
, 0, sizeof(ca
)); /* also resets ca.retval */
581 ca
.opcount
= opcount
;
584 want_sniff_request
= sniff_connected
;
588 * If there is an operator pending, then the command we take this time
589 * will terminate it. Finish_op tells us to finish the operation before
590 * returning this time (unless the operation was cancelled).
595 finish_op
= (oap
->op_type
!= OP_NOP
);
599 ui_cursor_shape(); /* may show different cursor shape */
600 # ifdef FEAT_MOUSESHAPE
601 update_mouseshape(-1);
606 if (!finish_op
&& !oap
->regname
)
610 mapped_len
= typebuf_maplen();
614 #ifdef USE_ON_FLY_SCROLL
615 dont_scroll
= FALSE
; /* allow scrolling here */
619 * Get the command character from the user.
624 LANGMAP_ADJUST(c
, TRUE
);
629 * If a mapping was started in Visual or Select mode, remember the length
630 * of the mapping. This is used below to not return to Insert mode for as
631 * long as the mapping is being executed.
633 if (restart_edit
== 0)
635 else if (old_mapped_len
636 || (VIsual_active
&& mapped_len
== 0 && typebuf_maplen() > 0))
637 old_mapped_len
= typebuf_maplen();
645 * In Select mode, typed text replaces the selection.
649 && (vim_isprintc(c
) || c
== NL
|| c
== CAR
|| c
== K_KENTER
))
651 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because
652 * 'insertmode' is set) fake a "d"elete command, Insert mode will
653 * restart automatically.
654 * Insert the typed character in the typeahead buffer, so that it can
655 * be mapped in Insert mode. Required for ":lmap" to work. */
657 if (restart_edit
!= 0)
661 msg_nowait
= TRUE
; /* don't delay going to insert mode */
665 #ifdef FEAT_CMDL_INFO
666 need_flushbuf
= add_to_showcmd(c
);
671 if (!(VIsual_active
&& VIsual_select
))
675 * Handle a count before a command and compute ca.count0.
676 * Note that '0' is a command and not the start of a count, but it's
677 * part of a count after other digits.
679 while ( (c
>= '1' && c
<= '9')
680 || (ca
.count0
!= 0 && (c
== K_DEL
|| c
== K_KDEL
|| c
== '0')))
682 if (c
== K_DEL
|| c
== K_KDEL
)
685 #ifdef FEAT_CMDL_INFO
686 del_from_showcmd(4); /* delete the digit and ~@% */
690 ca
.count0
= ca
.count0
* 10 + (c
- '0');
691 if (ca
.count0
< 0) /* got too large! */
692 ca
.count0
= 999999999L;
696 ++allow_keys
; /* no mapping for nchar, but keys */
698 ++no_zero_mapping
; /* don't map zero here */
701 LANGMAP_ADJUST(c
, TRUE
);
709 #ifdef FEAT_CMDL_INFO
710 need_flushbuf
|= add_to_showcmd(c
);
715 * If we got CTRL-W there may be a/another count
717 if (c
== Ctrl_W
&& !ctrl_w
&& oap
->op_type
== OP_NOP
)
720 ca
.opcount
= ca
.count0
; /* remember first count */
723 ++allow_keys
; /* no mapping for nchar, but keys */
724 c
= safe_vgetc(); /* get next character */
726 LANGMAP_ADJUST(c
, TRUE
);
730 #ifdef FEAT_CMDL_INFO
731 need_flushbuf
|= add_to_showcmd(c
);
733 goto getcount
; /* jump back */
738 * If we're in the middle of an operator (including after entering a yank
739 * buffer with '"') AND we had a count before the operator, then that
740 * count overrides the current value of ca.count0.
741 * What this means effectively, is that commands like "3dw" get turned
742 * into "d3w" which makes things fall into place pretty neatly.
743 * If you give a count before AND after the operator, they are multiplied.
748 ca
.count0
*= ca
.opcount
;
750 ca
.count0
= ca
.opcount
;
754 * Always remember the count. It will be set to zero (on the next call,
755 * above) when there is no pending operator.
756 * When called from main(), save the count for use by the "count" built-in
759 ca
.opcount
= ca
.count0
;
760 ca
.count1
= (ca
.count0
== 0 ? 1 : ca
.count0
);
764 * Only set v:count when called from main() and not a stuffed command.
766 if (toplevel
&& stuff_empty())
767 set_vcount(ca
.count0
, ca
.count1
);
771 * Find the command character in the table of commands.
772 * For CTRL-W we already got nchar when looking for a count.
781 idx
= find_command(ca
.cmdchar
);
784 /* Not a known command: beep. */
789 if (text_locked() && (nv_cmds
[idx
].cmd_flags
& NV_NCW
))
791 /* This command is not allowed wile editing a ccmdline: beep. */
797 if ((nv_cmds
[idx
].cmd_flags
& NV_NCW
) && curbuf_locked())
803 * In Visual/Select mode, a few keys are handled in a special way.
807 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */
809 && (nv_cmds
[idx
].cmd_flags
& NV_STS
)
810 && !(mod_mask
& MOD_MASK_SHIFT
))
813 redraw_curbuf_later(INVERTED
);
816 /* Keys that work different when 'keymodel' contains "startsel" */
819 if (nv_cmds
[idx
].cmd_flags
& NV_SS
)
821 unshift_special(&ca
);
822 idx
= find_command(ca
.cmdchar
);
830 else if ((nv_cmds
[idx
].cmd_flags
& NV_SSS
)
831 && (mod_mask
& MOD_MASK_SHIFT
))
833 mod_mask
&= ~MOD_MASK_SHIFT
;
839 #ifdef FEAT_RIGHTLEFT
840 if (curwin
->w_p_rl
&& KeyTyped
&& !KeyStuffed
841 && (nv_cmds
[idx
].cmd_flags
& NV_RL
))
843 /* Invert horizontal movements and operations. Only when typed by the
844 * user directly, not when the result of a mapping or "x" translated
848 case 'l': ca
.cmdchar
= 'h'; break;
849 case K_RIGHT
: ca
.cmdchar
= K_LEFT
; break;
850 case K_S_RIGHT
: ca
.cmdchar
= K_S_LEFT
; break;
851 case K_C_RIGHT
: ca
.cmdchar
= K_C_LEFT
; break;
852 case 'h': ca
.cmdchar
= 'l'; break;
853 case K_LEFT
: ca
.cmdchar
= K_RIGHT
; break;
854 case K_S_LEFT
: ca
.cmdchar
= K_S_RIGHT
; break;
855 case K_C_LEFT
: ca
.cmdchar
= K_C_RIGHT
; break;
856 case '>': ca
.cmdchar
= '<'; break;
857 case '<': ca
.cmdchar
= '>'; break;
859 idx
= find_command(ca
.cmdchar
);
864 * Get an additional character if we need one.
866 if ((nv_cmds
[idx
].cmd_flags
& NV_NCH
)
867 && (((nv_cmds
[idx
].cmd_flags
& NV_NCH_NOP
) == NV_NCH_NOP
868 && oap
->op_type
== OP_NOP
)
869 || (nv_cmds
[idx
].cmd_flags
& NV_NCH_ALW
) == NV_NCH_ALW
870 || (ca
.cmdchar
== 'q'
871 && oap
->op_type
== OP_NOP
874 || ((ca
.cmdchar
== 'a' || ca
.cmdchar
== 'i')
875 && (oap
->op_type
!= OP_NOP
882 int repl
= FALSE
; /* get character for replace mode */
883 int lit
= FALSE
; /* get extra character literally */
884 int langmap_active
= FALSE
; /* using :lmap mappings */
885 int lang
; /* getting a text character */
886 #ifdef USE_IM_CONTROL
887 int save_smd
; /* saved value of p_smd */
891 ++allow_keys
; /* no mapping for nchar, but allow key codes */
893 /* Don't generate a CursorHold event here, most commands can't handle
894 * it, e.g., nv_replace(), nv_csearch(). */
895 did_cursorhold
= TRUE
;
897 if (ca
.cmdchar
== 'g')
900 * For 'g' get the next character now, so that we can check for
901 * "gr", "g'" and "g`".
903 ca
.nchar
= safe_vgetc();
905 LANGMAP_ADJUST(ca
.nchar
, TRUE
);
907 #ifdef FEAT_CMDL_INFO
908 need_flushbuf
|= add_to_showcmd(ca
.nchar
);
910 if (ca
.nchar
== 'r' || ca
.nchar
== '\'' || ca
.nchar
== '`'
911 || ca
.nchar
== Ctrl_BSL
)
913 cp
= &ca
.extra_char
; /* need to get a third character */
915 lit
= TRUE
; /* get it literally */
917 repl
= TRUE
; /* get it in replace mode */
920 cp
= NULL
; /* no third character needed */
924 if (ca
.cmdchar
== 'r') /* get it in replace mode */
928 lang
= (repl
|| (nv_cmds
[idx
].cmd_flags
& NV_LANG
));
931 * Get a second or third character.
938 State
= REPLACE
; /* pretend Replace mode */
939 ui_cursor_shape(); /* show different cursor shape */
942 if (lang
&& curbuf
->b_p_iminsert
== B_IMODE_LMAP
)
944 /* Allow mappings defined with ":lmap". */
951 langmap_active
= TRUE
;
953 #ifdef USE_IM_CONTROL
955 p_smd
= FALSE
; /* Don't let the IM code show the mode here */
956 if (lang
&& curbuf
->b_p_iminsert
== B_IMODE_IM
)
964 /* Undo the decrement done above */
969 #ifdef USE_IM_CONTROL
972 if (curbuf
->b_p_iminsert
!= B_IMODE_LMAP
)
973 im_save_status(&curbuf
->b_p_iminsert
);
974 im_set_active(FALSE
);
981 #ifdef FEAT_CMDL_INFO
982 need_flushbuf
|= add_to_showcmd(*cp
);
988 /* Typing CTRL-K gets a digraph. */
990 && ((nv_cmds
[idx
].cmd_flags
& NV_LANG
)
991 || cp
== &ca
.extra_char
)
992 && vim_strchr(p_cpo
, CPO_DIGRAPH
) == NULL
)
994 c
= get_digraph(FALSE
);
998 # ifdef FEAT_CMDL_INFO
999 /* Guessing how to update showcmd here... */
1000 del_from_showcmd(3);
1001 need_flushbuf
|= add_to_showcmd(*cp
);
1008 /* adjust chars > 127, except after "tTfFr" commands */
1009 LANGMAP_ADJUST(*cp
, !lang
);
1011 #ifdef FEAT_RIGHTLEFT
1012 /* adjust Hebrew mapped char */
1013 if (p_hkmap
&& lang
&& KeyTyped
)
1016 /* adjust Farsi mapped char */
1017 if (p_fkmap
&& lang
&& KeyTyped
)
1024 * When the next character is CTRL-\ a following CTRL-N means the
1025 * command is aborted and we go to Normal mode.
1027 if (cp
== &ca
.extra_char
1028 && ca
.nchar
== Ctrl_BSL
1029 && (ca
.extra_char
== Ctrl_N
|| ca
.extra_char
== Ctrl_G
))
1031 ca
.cmdchar
= Ctrl_BSL
;
1032 ca
.nchar
= ca
.extra_char
;
1033 idx
= find_command(ca
.cmdchar
);
1035 else if (*cp
== Ctrl_BSL
)
1037 long towait
= (p_ttm
>= 0 ? p_ttm
: p_tm
);
1039 /* There is a busy wait here when typing "f<C-\>" and then
1040 * something different from CTRL-N. Can't be avoided. */
1041 while ((c
= vpeekc()) <= 0 && towait
> 0L)
1043 do_sleep(towait
> 50L ? 50L : towait
);
1049 if (c
!= Ctrl_N
&& c
!= Ctrl_G
)
1053 ca
.cmdchar
= Ctrl_BSL
;
1055 idx
= find_command(ca
.cmdchar
);
1061 /* When getting a text character and the next character is a
1062 * multi-byte character, it could be a composing character.
1063 * However, don't wait for it to arrive. */
1064 while (enc_utf8
&& lang
&& (c
= vpeekc()) > 0
1065 && (c
>= 0x100 || MB_BYTE2LEN(vpeekc()) > 1))
1068 if (!utf_iscomposing(c
))
1070 vungetc(c
); /* it wasn't, put it back */
1073 else if (ca
.ncharC1
== 0)
1084 #ifdef FEAT_CMDL_INFO
1086 * Flush the showcmd characters onto the screen so we can see them while
1087 * the command is being executed. Only do this when the shown command was
1088 * actually displayed, otherwise this will slow down a lot when executing
1095 did_cursorhold
= FALSE
;
1100 if (ca
.nchar
== ESC
)
1103 if (restart_edit
== 0 && goto_im())
1108 if (ca
.cmdchar
!= K_IGNORE
)
1110 msg_didout
= FALSE
; /* don't scroll screen up for normal command */
1115 old_pos
= curwin
->w_cursor
; /* remember where cursor was */
1117 /* When 'keymodel' contains "startsel" some keys start Select/Visual
1119 if (!VIsual_active
&& km_startsel
)
1121 if (nv_cmds
[idx
].cmd_flags
& NV_SS
)
1124 unshift_special(&ca
);
1125 idx
= find_command(ca
.cmdchar
);
1127 else if ((nv_cmds
[idx
].cmd_flags
& NV_SSS
)
1128 && (mod_mask
& MOD_MASK_SHIFT
))
1131 mod_mask
&= ~MOD_MASK_SHIFT
;
1137 * Execute the command!
1138 * Call the command function found in the commands table.
1140 ca
.arg
= nv_cmds
[idx
].cmd_arg
;
1141 (nv_cmds
[idx
].cmd_func
)(&ca
);
1144 * If we didn't start or finish an operator, reset oap->regname, unless we
1149 && (idx
< 0 || !(nv_cmds
[idx
].cmd_flags
& NV_KEEPREG
)))
1158 /* Get the length of mapped chars again after typing a count, second
1159 * character or "z333<cr>". */
1160 if (old_mapped_len
> 0)
1161 old_mapped_len
= typebuf_maplen();
1165 * If an operation is pending, handle it...
1167 do_pending_operator(&ca
, old_col
, FALSE
);
1170 * Wait for a moment when a message is displayed that will be overwritten
1171 * by the mode message.
1172 * In Visual mode and with "^O" in Insert mode, a short message will be
1173 * overwritten by the mode message. Wait a bit, until a key is hit.
1174 * In Visual mode, it's more important to keep the Visual area updated
1175 * than keeping a message (e.g. from a /pat search).
1176 * Only do this if the command was typed, not from a mapping.
1177 * Don't wait when emsg_silent is non-zero.
1178 * Also wait a bit after an error message, e.g. for "^O:".
1179 * Don't redraw the screen, it would remove the message.
1183 && (restart_edit
!= 0
1186 && old_pos
.lnum
== curwin
->w_cursor
.lnum
1187 && old_pos
.col
== curwin
->w_cursor
.col
)
1192 && (msg_didout
|| (msg_didany
&& msg_scroll
))
1195 || (restart_edit
!= 0
1200 || emsg_on_display
)))
1201 && oap
->regname
== 0
1202 && !(ca
.retval
& CA_COMMAND_BUSY
)
1207 && oap
->op_type
== OP_NOP
)
1209 int save_State
= State
;
1211 /* Draw the cursor with the right shape here */
1212 if (restart_edit
!= 0)
1215 /* If need to redraw, and there is a "keep_msg", redraw before the
1217 if (must_redraw
&& keep_msg
!= NULL
&& !emsg_on_display
)
1223 /* showmode() will clear keep_msg, but we want to use it anyway */
1225 /* now reset it, otherwise it's put in the history again */
1227 msg_attr(kmsg
, keep_msg_attr
);
1233 if (msg_scroll
|| emsg_on_display
)
1234 ui_delay(1000L, TRUE
); /* wait at least one second */
1235 ui_delay(3000L, FALSE
); /* wait up to three seconds */
1239 emsg_on_display
= FALSE
;
1243 * Finish up after executing a Normal mode command.
1249 /* Reset finish_op, in case it was set */
1255 /* Redraw the cursor with another shape, if we were in Operator-pending
1256 * mode or did a replace command. */
1257 if (c
|| ca
.cmdchar
== 'r')
1259 ui_cursor_shape(); /* may show different cursor shape */
1260 # ifdef FEAT_MOUSESHAPE
1261 update_mouseshape(-1);
1266 #ifdef FEAT_CMDL_INFO
1267 if (oap
->op_type
== OP_NOP
&& oap
->regname
== 0)
1271 checkpcmark(); /* check if we moved since setting pcmark */
1272 vim_free(ca
.searchbuf
);
1279 #ifdef FEAT_SCROLLBIND
1280 if (curwin
->w_p_scb
&& toplevel
)
1282 validate_cursor(); /* may need to update w_leftcol */
1283 do_check_scrollbind(TRUE
);
1288 * May restart edit(), if we got here with CTRL-O in Insert mode (but not
1289 * if still inside a mapping that started in Visual mode).
1290 * May switch from Visual to Select mode after CTRL-O command.
1292 if ( oap
->op_type
== OP_NOP
1294 && ((restart_edit
!= 0 && !VIsual_active
&& old_mapped_len
== 0)
1295 || restart_VIsual_select
== 1)
1297 && restart_edit
!= 0
1299 && !(ca
.retval
& CA_COMMAND_BUSY
)
1301 && oap
->regname
== 0)
1304 if (restart_VIsual_select
== 1)
1306 VIsual_select
= TRUE
;
1308 restart_VIsual_select
= 0;
1311 if (restart_edit
!= 0
1313 && !VIsual_active
&& old_mapped_len
== 0
1316 (void)edit(restart_edit
, FALSE
, 1L);
1320 if (restart_VIsual_select
== 2)
1321 restart_VIsual_select
= 1;
1324 /* Save count before an operator for next time. */
1325 opcount
= ca
.opcount
;
1329 * Handle an operator after visual mode or when the movement is finished
1332 do_pending_operator(cap
, old_col
, gui_yank
)
1337 oparg_T
*oap
= cap
->oap
;
1339 int empty_region_error
;
1340 int restart_edit_save
;
1343 /* The visual area is remembered for redo */
1344 static int redo_VIsual_mode
= NUL
; /* 'v', 'V', or Ctrl-V */
1345 static linenr_T redo_VIsual_line_count
; /* number of lines */
1346 static colnr_T redo_VIsual_col
; /* number of cols or end column */
1347 static long redo_VIsual_count
; /* count for Visual operator */
1348 # ifdef FEAT_VIRTUALEDIT
1349 int include_line_break
= FALSE
;
1353 #if defined(FEAT_CLIPBOARD)
1355 * Yank the visual area into the GUI selection register before we operate
1356 * on it and lose it forever.
1357 * Don't do it if a specific register was specified, so that ""x"*P works.
1358 * This could call do_pending_operator() recursively, but that's OK
1359 * because gui_yank will be TRUE for the nested call.
1361 if (clip_star
.available
1362 && oap
->op_type
!= OP_NOP
1366 && !redo_VIsual_busy
1368 && oap
->regname
== 0)
1371 old_cursor
= curwin
->w_cursor
;
1374 * If an operation is pending, handle it...
1380 ) && oap
->op_type
!= OP_NOP
)
1383 oap
->is_VIsual
= VIsual_active
;
1384 if (oap
->motion_force
== 'V')
1385 oap
->motion_type
= MLINE
;
1386 else if (oap
->motion_force
== 'v')
1388 /* If the motion was linewise, "inclusive" will not have been set.
1389 * Use "exclusive" to be consistent. Makes "dvj" work nice. */
1390 if (oap
->motion_type
== MLINE
)
1391 oap
->inclusive
= FALSE
;
1392 /* If the motion already was characterwise, toggle "inclusive" */
1393 else if (oap
->motion_type
== MCHAR
)
1394 oap
->inclusive
= !oap
->inclusive
;
1395 oap
->motion_type
= MCHAR
;
1397 else if (oap
->motion_force
== Ctrl_V
)
1399 /* Change line- or characterwise motion into Visual block mode. */
1400 VIsual_active
= TRUE
;
1401 VIsual
= oap
->start
;
1402 VIsual_mode
= Ctrl_V
;
1403 VIsual_select
= FALSE
;
1404 VIsual_reselect
= FALSE
;
1408 /* only redo yank when 'y' flag is in 'cpoptions' */
1409 /* never redo "zf" (define fold) */
1410 if ((vim_strchr(p_cpo
, CPO_YANK
) != NULL
|| oap
->op_type
!= OP_YANK
)
1412 && (!VIsual_active
|| oap
->motion_force
)
1414 && cap
->cmdchar
!= 'D'
1416 && oap
->op_type
!= OP_FOLD
1417 && oap
->op_type
!= OP_FOLDOPEN
1418 && oap
->op_type
!= OP_FOLDOPENREC
1419 && oap
->op_type
!= OP_FOLDCLOSE
1420 && oap
->op_type
!= OP_FOLDCLOSEREC
1421 && oap
->op_type
!= OP_FOLDDEL
1422 && oap
->op_type
!= OP_FOLDDELREC
1426 prep_redo(oap
->regname
, cap
->count0
,
1427 get_op_char(oap
->op_type
), get_extra_op_char(oap
->op_type
),
1428 oap
->motion_force
, cap
->cmdchar
, cap
->nchar
);
1429 if (cap
->cmdchar
== '/' || cap
->cmdchar
== '?') /* was a search */
1432 * If 'cpoptions' does not contain 'r', insert the search
1433 * pattern to really repeat the same command.
1435 if (vim_strchr(p_cpo
, CPO_REDO
) == NULL
)
1436 AppendToRedobuffLit(cap
->searchbuf
, -1);
1437 AppendToRedobuff(NL_STR
);
1439 else if (cap
->cmdchar
== ':')
1441 /* do_cmdline() has stored the first typed line in
1442 * "repeat_cmdline". When several lines are typed repeating
1443 * won't be possible. */
1444 if (repeat_cmdline
== NULL
)
1448 AppendToRedobuffLit(repeat_cmdline
, -1);
1449 AppendToRedobuff(NL_STR
);
1450 vim_free(repeat_cmdline
);
1451 repeat_cmdline
= NULL
;
1457 if (redo_VIsual_busy
)
1459 oap
->start
= curwin
->w_cursor
;
1460 curwin
->w_cursor
.lnum
+= redo_VIsual_line_count
- 1;
1461 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
1462 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
1463 VIsual_mode
= redo_VIsual_mode
;
1464 if (VIsual_mode
== 'v')
1466 if (redo_VIsual_line_count
<= 1)
1467 curwin
->w_cursor
.col
+= redo_VIsual_col
- 1;
1469 curwin
->w_cursor
.col
= redo_VIsual_col
;
1471 if (redo_VIsual_col
== MAXCOL
)
1473 curwin
->w_curswant
= MAXCOL
;
1474 coladvance((colnr_T
)MAXCOL
);
1476 cap
->count0
= redo_VIsual_count
;
1477 if (redo_VIsual_count
!= 0)
1478 cap
->count1
= redo_VIsual_count
;
1482 else if (VIsual_active
)
1486 /* Save the current VIsual area for '< and '> marks, and "gv" */
1487 curbuf
->b_visual
.vi_start
= VIsual
;
1488 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
1489 curbuf
->b_visual
.vi_mode
= VIsual_mode
;
1490 curbuf
->b_visual
.vi_curswant
= curwin
->w_curswant
;
1492 curbuf
->b_visual_mode_eval
= VIsual_mode
;
1496 /* In Select mode, a linewise selection is operated upon like a
1497 * characterwise selection. */
1498 if (VIsual_select
&& VIsual_mode
== 'V')
1500 if (lt(VIsual
, curwin
->w_cursor
))
1503 curwin
->w_cursor
.col
=
1504 (colnr_T
)STRLEN(ml_get(curwin
->w_cursor
.lnum
));
1508 curwin
->w_cursor
.col
= 0;
1509 VIsual
.col
= (colnr_T
)STRLEN(ml_get(VIsual
.lnum
));
1513 /* If 'selection' is "exclusive", backup one character for
1514 * charwise selections. */
1515 else if (VIsual_mode
== 'v')
1517 # ifdef FEAT_VIRTUALEDIT
1518 include_line_break
=
1523 oap
->start
= VIsual
;
1524 if (VIsual_mode
== 'V')
1527 #endif /* FEAT_VISUAL */
1530 * Set oap->start to the first position of the operated text, oap->end
1531 * to the end of the operated text. w_cursor is equal to oap->start.
1533 if (lt(oap
->start
, curwin
->w_cursor
))
1536 /* Include folded lines completely. */
1539 if (hasFolding(oap
->start
.lnum
, &oap
->start
.lnum
, NULL
))
1541 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
,
1542 &curwin
->w_cursor
.lnum
))
1543 curwin
->w_cursor
.col
= (colnr_T
)STRLEN(ml_get_curline());
1546 oap
->end
= curwin
->w_cursor
;
1547 curwin
->w_cursor
= oap
->start
;
1549 /* w_virtcol may have been updated; if the cursor goes back to its
1550 * previous position w_virtcol becomes invalid and isn't updated
1552 curwin
->w_valid
&= ~VALID_VIRTCOL
;
1557 /* Include folded lines completely. */
1558 if (!VIsual_active
&& oap
->motion_type
== MLINE
)
1560 if (hasFolding(curwin
->w_cursor
.lnum
, &curwin
->w_cursor
.lnum
,
1562 curwin
->w_cursor
.col
= 0;
1563 if (hasFolding(oap
->start
.lnum
, NULL
, &oap
->start
.lnum
))
1564 oap
->start
.col
= (colnr_T
)STRLEN(ml_get(oap
->start
.lnum
));
1567 oap
->end
= oap
->start
;
1568 oap
->start
= curwin
->w_cursor
;
1571 oap
->line_count
= oap
->end
.lnum
- oap
->start
.lnum
+ 1;
1573 #ifdef FEAT_VIRTUALEDIT
1574 /* Set "virtual_op" before resetting VIsual_active. */
1575 virtual_op
= virtual_active();
1579 if (VIsual_active
|| redo_VIsual_busy
)
1581 if (VIsual_mode
== Ctrl_V
) /* block mode */
1585 oap
->block_mode
= TRUE
;
1587 getvvcol(curwin
, &(oap
->start
),
1588 &oap
->start_vcol
, NULL
, &oap
->end_vcol
);
1589 if (!redo_VIsual_busy
)
1591 getvvcol(curwin
, &(oap
->end
), &start
, NULL
, &end
);
1593 if (start
< oap
->start_vcol
)
1594 oap
->start_vcol
= start
;
1595 if (end
> oap
->end_vcol
)
1597 if (*p_sel
== 'e' && start
>= 1
1598 && start
- 1 >= oap
->end_vcol
)
1599 oap
->end_vcol
= start
- 1;
1601 oap
->end_vcol
= end
;
1605 /* if '$' was used, get oap->end_vcol from longest line */
1606 if (curwin
->w_curswant
== MAXCOL
)
1608 curwin
->w_cursor
.col
= MAXCOL
;
1610 for (curwin
->w_cursor
.lnum
= oap
->start
.lnum
;
1611 curwin
->w_cursor
.lnum
<= oap
->end
.lnum
;
1612 ++curwin
->w_cursor
.lnum
)
1614 getvvcol(curwin
, &curwin
->w_cursor
, NULL
, NULL
, &end
);
1615 if (end
> oap
->end_vcol
)
1616 oap
->end_vcol
= end
;
1619 else if (redo_VIsual_busy
)
1620 oap
->end_vcol
= oap
->start_vcol
+ redo_VIsual_col
- 1;
1622 * Correct oap->end.col and oap->start.col to be the
1623 * upper-left and lower-right corner of the block area.
1625 * (Actually, this does convert column positions into character
1628 curwin
->w_cursor
.lnum
= oap
->end
.lnum
;
1629 coladvance(oap
->end_vcol
);
1630 oap
->end
= curwin
->w_cursor
;
1632 curwin
->w_cursor
= oap
->start
;
1633 coladvance(oap
->start_vcol
);
1634 oap
->start
= curwin
->w_cursor
;
1637 if (!redo_VIsual_busy
&& !gui_yank
)
1640 * Prepare to reselect and redo Visual: this is based on the
1641 * size of the Visual text
1643 resel_VIsual_mode
= VIsual_mode
;
1644 if (curwin
->w_curswant
== MAXCOL
)
1645 resel_VIsual_col
= MAXCOL
;
1646 else if (VIsual_mode
== Ctrl_V
)
1647 resel_VIsual_col
= oap
->end_vcol
- oap
->start_vcol
+ 1;
1648 else if (oap
->line_count
> 1)
1649 resel_VIsual_col
= oap
->end
.col
;
1651 resel_VIsual_col
= oap
->end
.col
- oap
->start
.col
+ 1;
1652 resel_VIsual_line_count
= oap
->line_count
;
1655 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */
1656 if ((vim_strchr(p_cpo
, CPO_YANK
) != NULL
|| oap
->op_type
!= OP_YANK
)
1657 && oap
->op_type
!= OP_COLON
1659 && oap
->op_type
!= OP_FOLD
1660 && oap
->op_type
!= OP_FOLDOPEN
1661 && oap
->op_type
!= OP_FOLDOPENREC
1662 && oap
->op_type
!= OP_FOLDCLOSE
1663 && oap
->op_type
!= OP_FOLDCLOSEREC
1664 && oap
->op_type
!= OP_FOLDDEL
1665 && oap
->op_type
!= OP_FOLDDELREC
1667 && oap
->motion_force
== NUL
1670 /* Prepare for redoing. Only use the nchar field for "r",
1671 * otherwise it might be the second char of the operator. */
1672 prep_redo(oap
->regname
, 0L, NUL
, 'v',
1673 get_op_char(oap
->op_type
),
1674 get_extra_op_char(oap
->op_type
),
1675 oap
->op_type
== OP_REPLACE
? cap
->nchar
: NUL
);
1676 if (!redo_VIsual_busy
)
1678 redo_VIsual_mode
= resel_VIsual_mode
;
1679 redo_VIsual_col
= resel_VIsual_col
;
1680 redo_VIsual_line_count
= resel_VIsual_line_count
;
1681 redo_VIsual_count
= cap
->count0
;
1686 * oap->inclusive defaults to TRUE.
1687 * If oap->end is on a NUL (empty line) oap->inclusive becomes
1688 * FALSE. This makes "d}P" and "v}dP" work the same.
1690 if (oap
->motion_force
== NUL
|| oap
->motion_type
== MLINE
)
1691 oap
->inclusive
= TRUE
;
1692 if (VIsual_mode
== 'V')
1693 oap
->motion_type
= MLINE
;
1696 oap
->motion_type
= MCHAR
;
1697 if (VIsual_mode
!= Ctrl_V
&& *ml_get_pos(&(oap
->end
)) == NUL
1698 # ifdef FEAT_VIRTUALEDIT
1699 && (include_line_break
|| !virtual_op
)
1703 oap
->inclusive
= FALSE
;
1704 /* Try to include the newline, unless it's an operator
1705 * that works on lines only */
1707 && !op_on_lines(oap
->op_type
)
1708 && oap
->end
.lnum
< curbuf
->b_ml
.ml_line_count
)
1712 # ifdef FEAT_VIRTUALEDIT
1713 oap
->end
.coladd
= 0;
1720 redo_VIsual_busy
= FALSE
;
1723 * Switch Visual off now, so screen updating does
1724 * not show inverted text when the screen is redrawn.
1725 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is
1726 * no screen redraw, so it is done here to remove the inverted
1731 VIsual_active
= FALSE
;
1737 clear_cmdline
= TRUE
; /* unshow visual mode later */
1738 #ifdef FEAT_CMDL_INFO
1742 if ((oap
->op_type
== OP_YANK
1743 || oap
->op_type
== OP_COLON
1744 || oap
->op_type
== OP_FUNCTION
1745 || oap
->op_type
== OP_FILTER
)
1746 && oap
->motion_force
== NUL
)
1747 redraw_curbuf_later(INVERTED
);
1753 /* Include the trailing byte of a multi-byte char. */
1754 if (has_mbyte
&& oap
->inclusive
)
1758 l
= (*mb_ptr2len
)(ml_get_pos(&oap
->end
));
1760 oap
->end
.col
+= l
- 1;
1763 curwin
->w_set_curswant
= TRUE
;
1766 * oap->empty is set when start and end are the same. The inclusive
1767 * flag affects this too, unless yanking and the end is on a NUL.
1769 oap
->empty
= (oap
->motion_type
== MCHAR
1771 || (oap
->op_type
== OP_YANK
1772 && gchar_pos(&oap
->end
) == NUL
))
1773 && equalpos(oap
->start
, oap
->end
)
1774 #ifdef FEAT_VIRTUALEDIT
1775 && !(virtual_op
&& oap
->start
.coladd
!= oap
->end
.coladd
)
1779 * For delete, change and yank, it's an error to operate on an
1780 * empty region, when 'E' included in 'cpoptions' (Vi compatible).
1782 empty_region_error
= (oap
->empty
1783 && vim_strchr(p_cpo
, CPO_EMPTYREGION
) != NULL
);
1786 /* Force a redraw when operating on an empty Visual region, when
1787 * 'modifiable is off or creating a fold. */
1788 if (oap
->is_VIsual
&& (oap
->empty
|| !curbuf
->b_p_ma
1789 # ifdef FEAT_FOLDING
1790 || oap
->op_type
== OP_FOLD
1793 redraw_curbuf_later(INVERTED
);
1797 * If the end of an operator is in column one while oap->motion_type
1798 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last
1799 * character in the previous line. If op_start is on or before the
1800 * first non-blank in the line, the operator becomes linewise
1801 * (strange, but that's the way vi does it).
1803 if ( oap
->motion_type
== MCHAR
1804 && oap
->inclusive
== FALSE
1805 && !(cap
->retval
& CA_NO_ADJ_OP_END
)
1806 && oap
->end
.col
== 0
1808 && (!oap
->is_VIsual
|| *p_sel
== 'o')
1811 && oap
->line_count
> 1)
1813 oap
->end_adjusted
= TRUE
; /* remember that we did this */
1817 oap
->motion_type
= MLINE
;
1820 oap
->end
.col
= (colnr_T
)STRLEN(ml_get(oap
->end
.lnum
));
1824 oap
->inclusive
= TRUE
;
1829 oap
->end_adjusted
= FALSE
;
1831 switch (oap
->op_type
)
1837 oap
->is_VIsual
? (int)cap
->count1
:
1840 auto_format(FALSE
, TRUE
);
1845 if (oap
->line_count
< 2)
1846 oap
->line_count
= 2;
1847 if (curwin
->w_cursor
.lnum
+ oap
->line_count
- 1 >
1848 curbuf
->b_ml
.ml_line_count
)
1852 do_do_join(oap
->line_count
, oap
->op_type
== OP_JOIN
);
1853 auto_format(FALSE
, TRUE
);
1859 VIsual_reselect
= FALSE
; /* don't reselect now */
1861 if (empty_region_error
)
1865 (void)op_delete(oap
);
1866 if (oap
->motion_type
== MLINE
&& has_format_option(FO_AUTO
))
1867 u_save_cursor(); /* cursor line wasn't saved yet */
1868 auto_format(FALSE
, TRUE
);
1873 if (empty_region_error
)
1879 (void)op_yank(oap
, FALSE
, !gui_yank
);
1885 VIsual_reselect
= FALSE
; /* don't reselect now */
1887 if (empty_region_error
)
1891 /* This is a new edit command, not a restart. Need to
1892 * remember it to make 'insertmode' work with mappings for
1893 * Visual mode. But do this only once and not when typed and
1894 * 'insertmode' isn't set. */
1895 if (p_im
|| !KeyTyped
)
1896 restart_edit_save
= restart_edit
;
1898 restart_edit_save
= 0;
1900 /* Reset finish_op now, don't want it set inside edit(). */
1902 if (op_change(oap
)) /* will call edit() */
1903 cap
->retval
|= CA_COMMAND_BUSY
;
1904 if (restart_edit
== 0)
1905 restart_edit
= restart_edit_save
;
1910 if (vim_strchr(p_cpo
, CPO_FILTER
) != NULL
)
1911 AppendToRedobuff((char_u
*)"!\r"); /* use any last used !cmd */
1913 bangredo
= TRUE
; /* do_bang() will put cmd in redo buffer */
1918 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
1920 * If 'equalprg' is empty, do the indenting internally.
1922 if (oap
->op_type
== OP_INDENT
&& *get_equalprg() == NUL
)
1925 if (curbuf
->b_p_lisp
)
1927 op_reindent(oap
, get_lisp_indent
);
1931 # ifdef FEAT_CINDENT
1934 *curbuf
->b_p_inde
!= NUL
? get_expr_indent
:
1949 if (empty_region_error
)
1957 #if defined(FEAT_EVAL)
1958 if (*curbuf
->b_p_fex
!= NUL
)
1959 op_formatexpr(oap
); /* use expression */
1963 op_colon(oap
); /* use external command */
1965 op_format(oap
, FALSE
); /* use internal function */
1969 op_format(oap
, TRUE
); /* use internal function */
1973 op_function(oap
); /* call 'operatorfunc' */
1979 VIsual_reselect
= FALSE
; /* don't reselect now */
1981 #ifdef FEAT_VISUALEXTRA
1982 if (empty_region_error
)
1986 /* This is a new edit command, not a restart. Need to
1987 * remember it to make 'insertmode' work with mappings for
1988 * Visual mode. But do this only once. */
1989 restart_edit_save
= restart_edit
;
1992 op_insert(oap
, cap
->count1
);
1994 /* TODO: when inserting in several lines, should format all
1996 auto_format(FALSE
, TRUE
);
1998 if (restart_edit
== 0)
1999 restart_edit
= restart_edit_save
;
2008 VIsual_reselect
= FALSE
; /* don't reselect now */
2010 #ifdef FEAT_VISUALEXTRA
2011 if (empty_region_error
)
2014 #ifdef FEAT_VISUALEXTRA
2016 op_replace(oap
, cap
->nchar
);
2022 VIsual_reselect
= FALSE
; /* don't reselect now */
2023 foldCreate(oap
->start
.lnum
, oap
->end
.lnum
);
2027 case OP_FOLDOPENREC
:
2029 case OP_FOLDCLOSEREC
:
2030 VIsual_reselect
= FALSE
; /* don't reselect now */
2031 opFoldRange(oap
->start
.lnum
, oap
->end
.lnum
,
2032 oap
->op_type
== OP_FOLDOPEN
2033 || oap
->op_type
== OP_FOLDOPENREC
,
2034 oap
->op_type
== OP_FOLDOPENREC
2035 || oap
->op_type
== OP_FOLDCLOSEREC
,
2041 VIsual_reselect
= FALSE
; /* don't reselect now */
2042 deleteFold(oap
->start
.lnum
, oap
->end
.lnum
,
2043 oap
->op_type
== OP_FOLDDELREC
, oap
->is_VIsual
);
2049 #ifdef FEAT_VIRTUALEDIT
2055 * if 'sol' not set, go back to old column for some commands
2057 if (!p_sol
&& oap
->motion_type
== MLINE
&& !oap
->end_adjusted
2058 && (oap
->op_type
== OP_LSHIFT
|| oap
->op_type
== OP_RSHIFT
2059 || oap
->op_type
== OP_DELETE
))
2060 coladvance(curwin
->w_curswant
= old_col
);
2064 curwin
->w_cursor
= old_cursor
;
2067 oap
->block_mode
= FALSE
;
2074 * Handle indent and format operators and visual mode ":".
2080 stuffcharReadbuff(':');
2083 stuffReadbuff((char_u
*)"'<,'>");
2088 * Make the range look nice, so it can be repeated.
2090 if (oap
->start
.lnum
== curwin
->w_cursor
.lnum
)
2091 stuffcharReadbuff('.');
2093 stuffnumReadbuff((long)oap
->start
.lnum
);
2094 if (oap
->end
.lnum
!= oap
->start
.lnum
)
2096 stuffcharReadbuff(',');
2097 if (oap
->end
.lnum
== curwin
->w_cursor
.lnum
)
2098 stuffcharReadbuff('.');
2099 else if (oap
->end
.lnum
== curbuf
->b_ml
.ml_line_count
)
2100 stuffcharReadbuff('$');
2101 else if (oap
->start
.lnum
== curwin
->w_cursor
.lnum
)
2103 stuffReadbuff((char_u
*)".+");
2104 stuffnumReadbuff((long)oap
->line_count
- 1);
2107 stuffnumReadbuff((long)oap
->end
.lnum
);
2110 if (oap
->op_type
!= OP_COLON
)
2111 stuffReadbuff((char_u
*)"!");
2112 if (oap
->op_type
== OP_INDENT
)
2114 #ifndef FEAT_CINDENT
2115 if (*get_equalprg() == NUL
)
2116 stuffReadbuff((char_u
*)"indent");
2119 stuffReadbuff(get_equalprg());
2120 stuffReadbuff((char_u
*)"\n");
2122 else if (oap
->op_type
== OP_FORMAT
)
2125 stuffReadbuff((char_u
*)"fmt");
2127 stuffReadbuff(p_fp
);
2128 stuffReadbuff((char_u
*)"\n']");
2132 * do_cmdline() does the rest
2137 * Handle the "g@" operator: call 'operatorfunc'.
2147 if (*p_opfunc
== NUL
)
2148 EMSG(_("E774: 'operatorfunc' is empty"));
2151 /* Set '[ and '] marks to text to be operated on. */
2152 curbuf
->b_op_start
= oap
->start
;
2153 curbuf
->b_op_end
= oap
->end
;
2154 if (oap
->motion_type
!= MLINE
&& !oap
->inclusive
)
2155 /* Exclude the end position. */
2156 decl(&curbuf
->b_op_end
);
2158 if (oap
->block_mode
)
2159 argv
[0] = (char_u
*)"block";
2160 else if (oap
->motion_type
== MLINE
)
2161 argv
[0] = (char_u
*)"line";
2163 argv
[0] = (char_u
*)"char";
2164 (void)call_func_retnr(p_opfunc
, 1, argv
, FALSE
);
2167 EMSG(_("E775: Eval feature not available"));
2171 #if defined(FEAT_MOUSE) || defined(PROTO)
2173 * Do the appropriate action for the current mouse click in the current mode.
2174 * Not used for Command-line mode.
2177 * event modi- position visual change action
2178 * fier cursor window
2179 * left press - yes end yes
2180 * left press C yes end yes "^]" (2)
2181 * left press S yes end yes "*" (2)
2182 * left drag - yes start if moved no
2183 * left relse - yes start if moved no
2184 * middle press - yes if not active no put register
2185 * middle press - yes if active no yank and put
2186 * right press - yes start or extend yes
2187 * right press S yes no change yes "#" (2)
2188 * right drag - yes extend no
2189 * right relse - yes extend no
2191 * Insert or Replace Mode:
2192 * event modi- position visual change action
2193 * fier cursor window
2194 * left press - yes (cannot be active) yes
2195 * left press C yes (cannot be active) yes "CTRL-O^]" (2)
2196 * left press S yes (cannot be active) yes "CTRL-O*" (2)
2197 * left drag - yes start or extend (1) no CTRL-O (1)
2198 * left relse - yes start or extend (1) no CTRL-O (1)
2199 * middle press - no (cannot be active) no put register
2200 * right press - yes start or extend yes CTRL-O
2201 * right press S yes (cannot be active) yes "CTRL-O#" (2)
2203 * (1) only if mouse pointer moved since press
2204 * (2) only if click is in same buffer
2206 * Return TRUE if start_arrow() should be called for edit mode.
2209 do_mouse(oap
, c
, dir
, count
, fixindent
)
2210 oparg_T
*oap
; /* operator argument, can be NULL */
2211 int c
; /* K_LEFTMOUSE, etc */
2212 int dir
; /* Direction to 'put' if necessary */
2214 int fixindent
; /* PUT_FIXINDENT if fixing indent necessary */
2216 static int do_always
= FALSE
; /* ignore 'mouse' setting next time */
2217 static int got_click
= FALSE
; /* got a click some time back */
2219 int which_button
; /* MOUSE_LEFT, _MIDDLE or _RIGHT */
2220 int is_click
; /* If FALSE it's a drag or release event */
2221 int is_drag
; /* If TRUE it's a drag event */
2222 int jump_flags
= 0; /* flags for jump_to_mouse() */
2224 int moved
; /* Has cursor moved? */
2225 int in_status_line
; /* mouse in status line */
2226 #ifdef FEAT_VERTSPLIT
2227 int in_sep_line
; /* mouse in vertical separator line */
2230 #if defined(FEAT_FOLDING)
2233 win_T
*old_curwin
= curwin
;
2235 static pos_T orig_cursor
;
2236 colnr_T leftcol
, rightcol
;
2239 int old_active
= VIsual_active
;
2240 int old_mode
= VIsual_mode
;
2244 #if defined(FEAT_FOLDING)
2245 save_cursor
= curwin
->w_cursor
;
2249 * When GUI is active, always recognize mouse events, otherwise:
2250 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
2251 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
2252 * - For command line and insert mode 'mouse' is checked before calling
2265 if (!mouse_has(MOUSE_VISUAL
))
2270 if (State
== NORMAL
&& !mouse_has(MOUSE_NORMAL
))
2274 which_button
= get_mouse_button(KEY2TERMCAP1(c
), &is_click
, &is_drag
);
2276 #ifdef FEAT_MOUSESHAPE
2277 /* May have stopped dragging the status or separator line. The pointer is
2278 * most likely still on the status or separator line. */
2279 if (!is_drag
&& drag_status_line
)
2281 drag_status_line
= FALSE
;
2282 update_mouseshape(SHAPE_IDX_STATUS
);
2284 # ifdef FEAT_VERTSPLIT
2285 if (!is_drag
&& drag_sep_line
)
2287 drag_sep_line
= FALSE
;
2288 update_mouseshape(SHAPE_IDX_VSEP
);
2294 * Ignore drag and release events if we didn't get a click.
2300 if (!got_click
) /* didn't get click, ignore */
2302 if (!is_drag
) /* release, reset got_click */
2308 * ALT is only used for starging/extending Visual mode.
2310 if ((mod_mask
& MOD_MASK_ALT
))
2315 * CTRL right mouse button does CTRL-T
2317 if (is_click
&& (mod_mask
& MOD_MASK_CTRL
) && which_button
== MOUSE_RIGHT
)
2320 stuffcharReadbuff(Ctrl_O
);
2322 stuffnumReadbuff(count
);
2323 stuffcharReadbuff(Ctrl_T
);
2324 got_click
= FALSE
; /* ignore drag&release now */
2329 * CTRL only works with left mouse button
2331 if ((mod_mask
& MOD_MASK_CTRL
) && which_button
!= MOUSE_LEFT
)
2335 * When a modifier is down, ignore drag and release events, as well as
2336 * multiple clicks and the middle mouse button.
2337 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
2339 if ((mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
| MOD_MASK_ALT
2342 || (mod_mask
& MOD_MASK_MULTI_CLICK
)
2343 || which_button
== MOUSE_MIDDLE
)
2344 && !((mod_mask
& (MOD_MASK_SHIFT
|MOD_MASK_ALT
))
2345 && mouse_model_popup()
2346 && which_button
== MOUSE_LEFT
)
2347 && !((mod_mask
& MOD_MASK_ALT
)
2348 && !mouse_model_popup()
2349 && which_button
== MOUSE_RIGHT
)
2354 * If the button press was used as the movement command for an operator
2355 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
2356 * drag/release events.
2358 if (!is_click
&& which_button
== MOUSE_MIDDLE
)
2362 regname
= oap
->regname
;
2367 * Middle mouse button does a 'put' of the selected text
2369 if (which_button
== MOUSE_MIDDLE
)
2371 if (State
== NORMAL
)
2374 * If an operator was pending, we don't know what the user wanted
2375 * to do. Go back to normal mode: Clear the operator and beep().
2377 if (oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2385 * If visual was active, yank the highlighted text and put it
2386 * before the mouse pointer position.
2387 * In Select mode replace the highlighted text with the clipboard.
2393 stuffcharReadbuff(Ctrl_G
);
2394 stuffReadbuff((char_u
*)"\"+p");
2398 stuffcharReadbuff('y');
2399 stuffcharReadbuff(K_MIDDLEMOUSE
);
2401 do_always
= TRUE
; /* ignore 'mouse' setting next time */
2406 * The rest is below jump_to_mouse()
2410 else if ((State
& INSERT
) == 0)
2414 * Middle click in insert mode doesn't move the mouse, just insert the
2415 * contents of a register. '.' register is special, can't insert that
2417 * Also paste at the cursor if the current mode isn't in 'mouse' (only
2418 * happens for the GUI).
2420 if ((State
& INSERT
) || !mouse_has(MOUSE_NORMAL
))
2423 insert_reg(regname
, TRUE
);
2426 #ifdef FEAT_CLIPBOARD
2427 if (clip_star
.available
&& regname
== 0)
2430 if ((State
& REPLACE_FLAG
) && !yank_register_mline(regname
))
2431 insert_reg(regname
, TRUE
);
2434 do_put(regname
, BACKWARD
, 1L, fixindent
| PUT_CURSEND
);
2436 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */
2437 AppendCharToRedobuff(Ctrl_R
);
2438 AppendCharToRedobuff(fixindent
? Ctrl_P
: Ctrl_O
);
2439 AppendCharToRedobuff(regname
== 0 ? '"' : regname
);
2446 /* When dragging or button-up stay in the same window. */
2448 jump_flags
|= MOUSE_FOCUS
| MOUSE_DID_MOVE
;
2450 start_visual
.lnum
= 0;
2453 /* Check for clicking in the tab page line. */
2454 if (mouse_row
== 0 && firstwin
->w_winrow
> 0)
2456 got_click
= FALSE
; /* ignore mouse-up and drag events */
2458 /* click in a tab selects that tab page */
2463 && mouse_col
< Columns
)
2465 c1
= TabPageIdxs
[mouse_col
];
2468 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2470 /* double click opens new page */
2473 tabpage_move(c1
== 0 ? 9999 : c1
- 1);
2477 /* Go to specified tab page, or next one if not clicking
2481 /* It's like clicking on the status line of a window. */
2482 if (curwin
!= old_curwin
)
2490 /* Close the current or specified tab page. */
2494 tp
= find_tabpage(-c1
);
2497 if (first_tabpage
->tp_next
!= NULL
)
2498 tabpage_close(FALSE
);
2500 else if (tp
!= NULL
)
2501 tabpage_close_other(tp
, FALSE
);
2509 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
2510 * right button up -> pop-up menu
2511 * shift-left button -> right button
2512 * alt-left button -> alt-right button
2514 if (mouse_model_popup())
2516 if (which_button
== MOUSE_RIGHT
2517 && !(mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
)))
2520 * NOTE: Ignore right button down and drag mouse events.
2521 * Windows only shows the popup menu on the button up event.
2523 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2524 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC)
2528 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN)
2529 if (is_click
|| is_drag
)
2532 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2533 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
2534 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON)
2538 if (STRCMP(p_mousem
, "popup_setpos") == 0)
2540 /* First set the cursor position before showing the popup
2548 * set MOUSE_MAY_STOP_VIS if we are outside the
2549 * selection or the current window (might have false
2552 if (mouse_row
< W_WINROW(curwin
)
2554 > (W_WINROW(curwin
) + curwin
->w_height
))
2555 jump_flags
= MOUSE_MAY_STOP_VIS
;
2556 else if (get_fpos_of_mouse(&m_pos
) != IN_BUFFER
)
2557 jump_flags
= MOUSE_MAY_STOP_VIS
;
2560 if ((lt(curwin
->w_cursor
, VIsual
)
2561 && (lt(m_pos
, curwin
->w_cursor
)
2562 || lt(VIsual
, m_pos
)))
2563 || (lt(VIsual
, curwin
->w_cursor
)
2564 && (lt(m_pos
, VIsual
)
2565 || lt(curwin
->w_cursor
, m_pos
))))
2567 jump_flags
= MOUSE_MAY_STOP_VIS
;
2569 else if (VIsual_mode
== Ctrl_V
)
2571 getvcols(curwin
, &curwin
->w_cursor
, &VIsual
,
2572 &leftcol
, &rightcol
);
2573 getvcol(curwin
, &m_pos
, NULL
, &m_pos
.col
, NULL
);
2574 if (m_pos
.col
< leftcol
|| m_pos
.col
> rightcol
)
2575 jump_flags
= MOUSE_MAY_STOP_VIS
;
2580 jump_flags
= MOUSE_MAY_STOP_VIS
;
2585 jump_flags
= jump_to_mouse(jump_flags
, NULL
, which_button
);
2588 VIsual_active
? INVERTED
:
2592 out_flush(); /* Update before showing popup menu */
2595 gui_show_popupmenu();
2597 return (jump_flags
& CURSOR_MOVED
) != 0;
2605 if (which_button
== MOUSE_LEFT
2606 && (mod_mask
& (MOD_MASK_SHIFT
|MOD_MASK_ALT
)))
2608 which_button
= MOUSE_RIGHT
;
2609 mod_mask
&= ~MOD_MASK_SHIFT
;
2614 if ((State
& (NORMAL
| INSERT
))
2615 && !(mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
)))
2617 if (which_button
== MOUSE_LEFT
)
2621 /* stop Visual mode for a left click in a window, but not when
2622 * on a status line */
2624 jump_flags
|= MOUSE_MAY_STOP_VIS
;
2626 else if (mouse_has(MOUSE_VISUAL
))
2627 jump_flags
|= MOUSE_MAY_VIS
;
2629 else if (which_button
== MOUSE_RIGHT
)
2631 if (is_click
&& VIsual_active
)
2634 * Remember the start and end of visual before moving the
2637 if (lt(curwin
->w_cursor
, VIsual
))
2639 start_visual
= curwin
->w_cursor
;
2640 end_visual
= VIsual
;
2644 start_visual
= VIsual
;
2645 end_visual
= curwin
->w_cursor
;
2648 jump_flags
|= MOUSE_FOCUS
;
2649 if (mouse_has(MOUSE_VISUAL
))
2650 jump_flags
|= MOUSE_MAY_VIS
;
2656 * If an operator is pending, ignore all drags and releases until the
2659 if (!is_drag
&& oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2662 oap
->motion_type
= MCHAR
;
2665 /* When releasing the button let jump_to_mouse() know. */
2666 if (!is_click
&& !is_drag
)
2667 jump_flags
|= MOUSE_RELEASED
;
2672 jump_flags
= jump_to_mouse(jump_flags
,
2673 oap
== NULL
? NULL
: &(oap
->inclusive
), which_button
);
2674 moved
= (jump_flags
& CURSOR_MOVED
);
2675 in_status_line
= (jump_flags
& IN_STATUS_LINE
);
2676 #ifdef FEAT_VERTSPLIT
2677 in_sep_line
= (jump_flags
& IN_SEP_LINE
);
2680 #ifdef FEAT_NETBEANS_INTG
2681 if (usingNetbeans
&& isNetbeansBuffer(curbuf
)
2682 && !(jump_flags
& (IN_STATUS_LINE
| IN_SEP_LINE
)))
2684 int key
= KEY2TERMCAP1(c
);
2686 if (key
== (int)KE_LEFTRELEASE
|| key
== (int)KE_MIDDLERELEASE
2687 || key
== (int)KE_RIGHTRELEASE
)
2688 netbeans_button_release(which_button
);
2692 /* When jumping to another window, clear a pending operator. That's a bit
2693 * friendlier than beeping and not jumping to that window. */
2694 if (curwin
!= old_curwin
&& oap
!= NULL
&& oap
->op_type
!= OP_NOP
)
2700 && (jump_flags
& (MOUSE_FOLD_CLOSE
| MOUSE_FOLD_OPEN
))
2701 && which_button
== MOUSE_LEFT
)
2703 /* open or close a fold at this line */
2704 if (jump_flags
& MOUSE_FOLD_OPEN
)
2705 openFold(curwin
->w_cursor
.lnum
, 1L);
2707 closeFold(curwin
->w_cursor
.lnum
, 1L);
2708 /* don't move the cursor if still in the same window */
2709 if (curwin
== old_curwin
)
2710 curwin
->w_cursor
= save_cursor
;
2714 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
2715 if ((jump_flags
& IN_OTHER_WIN
) && !VIsual_active
&& clip_star
.available
)
2717 clip_modeless(which_button
, is_click
, is_drag
);
2723 /* Set global flag that we are extending the Visual area with mouse
2724 * dragging; temporarily minimize 'scrolloff'. */
2725 if (VIsual_active
&& is_drag
&& p_so
)
2727 /* In the very first line, allow scrolling one line */
2734 /* When dragging the mouse above the window, scroll down. */
2735 if (is_drag
&& mouse_row
< 0 && !in_status_line
)
2737 scroll_redraw(FALSE
, 1L);
2741 if (start_visual
.lnum
) /* right click in visual mode */
2743 /* When ALT is pressed make Visual mode blockwise. */
2744 if (mod_mask
& MOD_MASK_ALT
)
2745 VIsual_mode
= Ctrl_V
;
2748 * In Visual-block mode, divide the area in four, pick up the corner
2749 * that is in the quarter that the cursor is in.
2751 if (VIsual_mode
== Ctrl_V
)
2753 getvcols(curwin
, &start_visual
, &end_visual
, &leftcol
, &rightcol
);
2754 if (curwin
->w_curswant
> (leftcol
+ rightcol
) / 2)
2755 end_visual
.col
= leftcol
;
2757 end_visual
.col
= rightcol
;
2758 if (curwin
->w_cursor
.lnum
<
2759 (start_visual
.lnum
+ end_visual
.lnum
) / 2)
2760 end_visual
.lnum
= end_visual
.lnum
;
2762 end_visual
.lnum
= start_visual
.lnum
;
2764 /* move VIsual to the right column */
2765 start_visual
= curwin
->w_cursor
; /* save the cursor pos */
2766 curwin
->w_cursor
= end_visual
;
2767 coladvance(end_visual
.col
);
2768 VIsual
= curwin
->w_cursor
;
2769 curwin
->w_cursor
= start_visual
; /* restore the cursor */
2774 * If the click is before the start of visual, change the start.
2775 * If the click is after the end of visual, change the end. If
2776 * the click is inside the visual, change the closest side.
2778 if (lt(curwin
->w_cursor
, start_visual
))
2779 VIsual
= end_visual
;
2780 else if (lt(end_visual
, curwin
->w_cursor
))
2781 VIsual
= start_visual
;
2784 /* In the same line, compare column number */
2785 if (end_visual
.lnum
== start_visual
.lnum
)
2787 if (curwin
->w_cursor
.col
- start_visual
.col
>
2788 end_visual
.col
- curwin
->w_cursor
.col
)
2789 VIsual
= start_visual
;
2791 VIsual
= end_visual
;
2794 /* In different lines, compare line number */
2797 diff
= (curwin
->w_cursor
.lnum
- start_visual
.lnum
) -
2798 (end_visual
.lnum
- curwin
->w_cursor
.lnum
);
2800 if (diff
> 0) /* closest to end */
2801 VIsual
= start_visual
;
2802 else if (diff
< 0) /* closest to start */
2803 VIsual
= end_visual
;
2804 else /* in the middle line */
2806 if (curwin
->w_cursor
.col
<
2807 (start_visual
.col
+ end_visual
.col
) / 2)
2808 VIsual
= end_visual
;
2810 VIsual
= start_visual
;
2817 * If Visual mode started in insert mode, execute "CTRL-O"
2819 else if ((State
& INSERT
) && VIsual_active
)
2820 stuffcharReadbuff(Ctrl_O
);
2824 * Middle mouse click: Put text before cursor.
2826 if (which_button
== MOUSE_MIDDLE
)
2828 #ifdef FEAT_CLIPBOARD
2829 if (clip_star
.available
&& regname
== 0)
2832 if (yank_register_mline(regname
))
2834 if (mouse_past_bottom
)
2837 else if (mouse_past_eol
)
2842 c1
= (dir
== BACKWARD
) ? '[' : ']';
2847 c1
= (dir
== FORWARD
) ? 'p' : 'P';
2850 prep_redo(regname
, count
, NUL
, c1
, NUL
, c2
, NUL
);
2853 * Remember where the paste started, so in edit() Insstart can be set
2856 if (restart_edit
!= 0)
2857 where_paste_started
= curwin
->w_cursor
;
2858 do_put(regname
, dir
, count
, fixindent
| PUT_CURSEND
);
2861 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2863 * Ctrl-Mouse click or double click in a quickfix window jumps to the
2864 * error under the mouse pointer.
2866 else if (((mod_mask
& MOD_MASK_CTRL
)
2867 || (mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2868 && bt_quickfix(curbuf
))
2871 stuffcharReadbuff(Ctrl_O
);
2872 if (curwin
->w_llist_ref
== NULL
) /* quickfix window */
2873 stuffReadbuff((char_u
*)":.cc\n");
2874 else /* location list window */
2875 stuffReadbuff((char_u
*)":.ll\n");
2876 got_click
= FALSE
; /* ignore drag&release now */
2881 * Ctrl-Mouse click (or double click in a help window) jumps to the tag
2882 * under the mouse pointer.
2884 else if ((mod_mask
& MOD_MASK_CTRL
) || (curbuf
->b_help
2885 && (mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
))
2888 stuffcharReadbuff(Ctrl_O
);
2889 stuffcharReadbuff(Ctrl_RSB
);
2890 got_click
= FALSE
; /* ignore drag&release now */
2894 * Shift-Mouse click searches for the next occurrence of the word under
2897 else if ((mod_mask
& MOD_MASK_SHIFT
))
2901 || (VIsual_active
&& VIsual_select
)
2904 stuffcharReadbuff(Ctrl_O
);
2905 if (which_button
== MOUSE_LEFT
)
2906 stuffcharReadbuff('*');
2907 else /* MOUSE_RIGHT */
2908 stuffcharReadbuff('#');
2911 /* Handle double clicks, unless on status line */
2912 else if (in_status_line
)
2914 #ifdef FEAT_MOUSESHAPE
2915 if ((is_drag
|| is_click
) && !drag_status_line
)
2917 drag_status_line
= TRUE
;
2918 update_mouseshape(-1);
2922 #ifdef FEAT_VERTSPLIT
2923 else if (in_sep_line
)
2925 # ifdef FEAT_MOUSESHAPE
2926 if ((is_drag
|| is_click
) && !drag_sep_line
)
2928 drag_sep_line
= TRUE
;
2929 update_mouseshape(-1);
2935 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) && (State
& (NORMAL
| INSERT
))
2936 && mouse_has(MOUSE_VISUAL
))
2938 if (is_click
|| !VIsual_active
)
2941 orig_cursor
= VIsual
;
2944 check_visual_highlight();
2945 VIsual
= curwin
->w_cursor
;
2946 orig_cursor
= VIsual
;
2947 VIsual_active
= TRUE
;
2948 VIsual_reselect
= TRUE
;
2949 /* start Select mode if 'selectmode' contains "mouse" */
2950 may_start_select('o');
2953 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2955 /* Double click with ALT pressed makes it blockwise. */
2956 if (mod_mask
& MOD_MASK_ALT
)
2957 VIsual_mode
= Ctrl_V
;
2961 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_3CLICK
)
2963 else if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_4CLICK
)
2964 VIsual_mode
= Ctrl_V
;
2965 #ifdef FEAT_CLIPBOARD
2966 /* Make sure the clipboard gets updated. Needed because start and
2967 * end may still be the same, and the selection needs to be owned */
2968 clip_star
.vmode
= NUL
;
2972 * A double click selects a word or a block.
2974 if ((mod_mask
& MOD_MASK_MULTI_CLICK
) == MOD_MASK_2CLICK
)
2981 /* If the character under the cursor (skipping white space) is
2982 * not a word character, try finding a match and select a (),
2983 * {}, [], #if/#endif, etc. block. */
2984 end_visual
= curwin
->w_cursor
;
2985 while (gc
= gchar_pos(&end_visual
), vim_iswhite(gc
))
2988 oap
->motion_type
= MCHAR
;
2990 && VIsual_mode
== 'v'
2991 && !vim_iswordc(gchar_pos(&end_visual
))
2992 && equalpos(curwin
->w_cursor
, VIsual
)
2993 && (pos
= findmatch(oap
, NUL
)) != NULL
)
2995 curwin
->w_cursor
= *pos
;
2996 if (oap
->motion_type
== MLINE
)
2998 else if (*p_sel
== 'e')
3000 if (lt(curwin
->w_cursor
, VIsual
))
3003 ++curwin
->w_cursor
.col
;
3008 if (pos
== NULL
&& (is_click
|| is_drag
))
3010 /* When not found a match or when dragging: extend to include
3012 if (lt(curwin
->w_cursor
, orig_cursor
))
3014 find_start_of_word(&curwin
->w_cursor
);
3015 find_end_of_word(&VIsual
);
3019 find_start_of_word(&VIsual
);
3020 if (*p_sel
== 'e' && *ml_get_cursor() != NUL
)
3022 curwin
->w_cursor
.col
+=
3023 (*mb_ptr2len
)(ml_get_cursor());
3025 ++curwin
->w_cursor
.col
;
3027 find_end_of_word(&curwin
->w_cursor
);
3030 curwin
->w_set_curswant
= TRUE
;
3033 redraw_curbuf_later(INVERTED
); /* update the inversion */
3035 else if (VIsual_active
&& !old_active
)
3037 if (mod_mask
& MOD_MASK_ALT
)
3038 VIsual_mode
= Ctrl_V
;
3043 /* If Visual mode changed show it later. */
3044 if ((!VIsual_active
&& old_active
&& mode_displayed
)
3045 || (VIsual_active
&& p_smd
&& msg_silent
== 0
3046 && (!old_active
|| VIsual_mode
!= old_mode
)))
3047 redraw_cmdline
= TRUE
;
3055 * Move "pos" back to the start of the word it's in.
3058 find_start_of_word(pos
)
3065 line
= ml_get(pos
->lnum
);
3066 cclass
= get_mouse_class(line
+ pos
->col
);
3068 while (pos
->col
> 0)
3072 col
-= (*mb_head_off
)(line
, line
+ col
);
3074 if (get_mouse_class(line
+ col
) != cclass
)
3081 * Move "pos" forward to the end of the word it's in.
3082 * When 'selection' is "exclusive", the position is just after the word.
3085 find_end_of_word(pos
)
3092 line
= ml_get(pos
->lnum
);
3093 if (*p_sel
== 'e' && pos
->col
> 0)
3097 pos
->col
-= (*mb_head_off
)(line
, line
+ pos
->col
);
3100 cclass
= get_mouse_class(line
+ pos
->col
);
3101 while (line
[pos
->col
] != NUL
)
3104 col
= pos
->col
+ (*mb_ptr2len
)(line
+ pos
->col
);
3108 if (get_mouse_class(line
+ col
) != cclass
)
3119 * Get class of a character for selection: same class means same word.
3121 * 1: punctuation groups
3122 * 2: normal word character
3123 * >2: multi-byte word character.
3132 if (has_mbyte
&& MB_BYTE2LEN(p
[0]) > 1)
3133 return mb_get_class(p
);
3137 if (c
== ' ' || c
== '\t')
3144 * There are a few special cases where we want certain combinations of
3145 * characters to be considered as a single word. These are things like
3146 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
3147 * character is in it's own class.
3149 if (c
!= NUL
&& vim_strchr((char_u
*)"-+*/%<>&|^!=", c
) != NULL
)
3153 #endif /* FEAT_VISUAL */
3154 #endif /* FEAT_MOUSE */
3156 #if defined(FEAT_VISUAL) || defined(PROTO)
3158 * Check if highlighting for visual mode is possible, give a warning message
3162 check_visual_highlight()
3164 static int did_check
= FALSE
;
3168 if (!did_check
&& hl_attr(HLF_V
) == 0)
3169 MSG(_("Warning: terminal cannot highlight"));
3176 * This function should ALWAYS be called to end Visual mode, except from
3177 * do_pending_operator().
3182 #ifdef FEAT_CLIPBOARD
3184 * If we are using the clipboard, then remember what was selected in case
3185 * we need to paste it somewhere while we still own the selection.
3186 * Only do this when the clipboard is already owned. Don't want to grab
3187 * the selection when hitting ESC.
3189 if (clip_star
.available
&& clip_star
.owned
)
3193 VIsual_active
= FALSE
;
3199 /* Save the current VIsual area for '< and '> marks, and "gv" */
3200 curbuf
->b_visual
.vi_mode
= VIsual_mode
;
3201 curbuf
->b_visual
.vi_start
= VIsual
;
3202 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
3203 curbuf
->b_visual
.vi_curswant
= curwin
->w_curswant
;
3205 curbuf
->b_visual_mode_eval
= VIsual_mode
;
3207 #ifdef FEAT_VIRTUALEDIT
3208 if (!virtual_active())
3209 curwin
->w_cursor
.coladd
= 0;
3213 clear_cmdline
= TRUE
; /* unshow visual mode later */
3214 #ifdef FEAT_CMDL_INFO
3219 adjust_cursor_eol();
3223 * Reset VIsual_active and VIsual_reselect.
3226 reset_VIsual_and_resel()
3231 redraw_curbuf_later(INVERTED
); /* delete the inversion later */
3233 VIsual_reselect
= FALSE
;
3237 * Reset VIsual_active and VIsual_reselect if it's set.
3245 redraw_curbuf_later(INVERTED
); /* delete the inversion later */
3246 VIsual_reselect
= FALSE
;
3249 #endif /* FEAT_VISUAL */
3251 #if defined(FEAT_BEVAL)
3252 static int find_is_eval_item
__ARGS((char_u
*ptr
, int *colp
, int *nbp
, int dir
));
3255 * Check for a balloon-eval special item to include when searching for an
3256 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid!
3257 * Returns TRUE if the character at "*ptr" should be included.
3258 * "dir" is FORWARD or BACKWARD, the direction of searching.
3259 * "*colp" is in/decremented if "ptr[-dir]" should also be included.
3260 * "bnp" points to a counter for square brackets.
3263 find_is_eval_item(ptr
, colp
, bnp
, dir
)
3269 /* Accept everything inside []. */
3270 if ((*ptr
== ']' && dir
== BACKWARD
) || (*ptr
== '[' && dir
== FORWARD
))
3274 if ((*ptr
== '[' && dir
== BACKWARD
) || (*ptr
== ']' && dir
== FORWARD
))
3279 /* skip over "s.var" */
3283 /* two-character item: s->var */
3284 if (ptr
[dir
== BACKWARD
? 0 : 1] == '>'
3285 && ptr
[dir
== BACKWARD
? -1 : 0] == '-')
3295 * Find the identifier under or to the right of the cursor.
3296 * "find_type" can have one of three values:
3297 * FIND_IDENT: find an identifier (keyword)
3298 * FIND_STRING: find any non-white string
3299 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred.
3300 * FIND_EVAL: find text useful for C program debugging
3302 * There are three steps:
3303 * 1. Search forward for the start of an identifier/string. Doesn't move if
3305 * 2. Search backward for the start of this identifier/string.
3306 * This doesn't match the real Vi but I like it a little better and it
3307 * shouldn't bother anyone.
3308 * 3. Search forward to the end of this identifier/string.
3309 * When FIND_IDENT isn't defined, we backup until a blank.
3311 * Returns the length of the string, or zero if no string is found.
3312 * If a string is found, a pointer to the string is put in "*string". This
3313 * string is not always NUL terminated.
3316 find_ident_under_cursor(string
, find_type
)
3320 return find_ident_at_pos(curwin
, curwin
->w_cursor
.lnum
,
3321 curwin
->w_cursor
.col
, string
, find_type
);
3325 * Like find_ident_under_cursor(), but for any window and any position.
3326 * However: Uses 'iskeyword' from the current window!.
3329 find_ident_at_pos(wp
, lnum
, startcol
, string
, find_type
)
3337 int col
= 0; /* init to shut up GCC */
3344 #if defined(FEAT_BEVAL)
3345 int bn
= 0; /* bracket nesting */
3349 * if i == 0: try to find an identifier
3350 * if i == 1: try to find any non-white string
3352 ptr
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3353 for (i
= (find_type
& FIND_IDENT
) ? 0 : 1; i
< 2; ++i
)
3356 * 1. skip to start of identifier/string
3362 while (ptr
[col
] != NUL
)
3364 # if defined(FEAT_BEVAL)
3365 /* Stop at a ']' to evaluate "a[x]". */
3366 if ((find_type
& FIND_EVAL
) && ptr
[col
] == ']')
3369 this_class
= mb_get_class(ptr
+ col
);
3370 if (this_class
!= 0 && (i
== 1 || this_class
!= 1))
3372 col
+= (*mb_ptr2len
)(ptr
+ col
);
3377 while (ptr
[col
] != NUL
3378 && (i
== 0 ? !vim_iswordc(ptr
[col
]) : vim_iswhite(ptr
[col
]))
3379 # if defined(FEAT_BEVAL)
3380 && (!(find_type
& FIND_EVAL
) || ptr
[col
] != ']')
3385 #if defined(FEAT_BEVAL)
3386 /* When starting on a ']' count it, so that we include the '['. */
3387 bn
= ptr
[col
] == ']';
3391 * 2. Back up to start of identifier/string.
3396 /* Remember class of character under cursor. */
3397 # if defined(FEAT_BEVAL)
3398 if ((find_type
& FIND_EVAL
) && ptr
[col
] == ']')
3399 this_class
= mb_get_class((char_u
*)"a");
3402 this_class
= mb_get_class(ptr
+ col
);
3403 while (col
> 0 && this_class
!= 0)
3405 prevcol
= col
- 1 - (*mb_head_off
)(ptr
, ptr
+ col
- 1);
3406 prev_class
= mb_get_class(ptr
+ prevcol
);
3407 if (this_class
!= prev_class
3410 || (find_type
& FIND_IDENT
))
3411 # if defined(FEAT_BEVAL)
3412 && (!(find_type
& FIND_EVAL
)
3414 || !find_is_eval_item(ptr
+ prevcol
, &prevcol
,
3422 /* If we don't want just any old string, or we've found an
3423 * identifier, stop searching. */
3426 if (!(find_type
& FIND_STRING
) || this_class
== 2)
3434 ? vim_iswordc(ptr
[col
- 1])
3435 : (!vim_iswhite(ptr
[col
- 1])
3436 && (!(find_type
& FIND_IDENT
)
3437 || !vim_iswordc(ptr
[col
- 1]))))
3438 #if defined(FEAT_BEVAL)
3439 || ((find_type
& FIND_EVAL
)
3441 && find_is_eval_item(ptr
+ col
- 1, &col
,
3447 /* If we don't want just any old string, or we've found an
3448 * identifier, stop searching. */
3449 if (!(find_type
& FIND_STRING
) || vim_iswordc(ptr
[col
]))
3454 if (ptr
[col
] == NUL
|| (i
== 0 && (
3456 has_mbyte
? this_class
!= 2 :
3458 !vim_iswordc(ptr
[col
]))))
3461 * didn't find an identifier or string
3463 if (find_type
& FIND_STRING
)
3464 EMSG(_("E348: No string under cursor"));
3466 EMSG(_("E349: No identifier under cursor"));
3473 * 3. Find the end if the identifier/string.
3475 #if defined(FEAT_BEVAL)
3483 /* Search for point of changing multibyte character class. */
3484 this_class
= mb_get_class(ptr
);
3485 while (ptr
[col
] != NUL
3486 && ((i
== 0 ? mb_get_class(ptr
+ col
) == this_class
3487 : mb_get_class(ptr
+ col
) != 0)
3488 # if defined(FEAT_BEVAL)
3489 || ((find_type
& FIND_EVAL
)
3490 && col
<= (int)startcol
3491 && find_is_eval_item(ptr
+ col
, &col
, &bn
, FORWARD
))
3494 col
+= (*mb_ptr2len
)(ptr
+ col
);
3498 while ((i
== 0 ? vim_iswordc(ptr
[col
])
3499 : (ptr
[col
] != NUL
&& !vim_iswhite(ptr
[col
])))
3500 # if defined(FEAT_BEVAL)
3501 || ((find_type
& FIND_EVAL
)
3502 && col
<= (int)startcol
3503 && find_is_eval_item(ptr
+ col
, &col
, &bn
, FORWARD
))
3514 * Prepare for redo of a normal command.
3520 prep_redo(cap
->oap
->regname
, cap
->count0
,
3521 NUL
, cap
->cmdchar
, NUL
, NUL
, cap
->nchar
);
3525 * Prepare for redo of any command.
3526 * Note that only the last argument can be a multi-byte char.
3529 prep_redo(regname
, num
, cmd1
, cmd2
, cmd3
, cmd4
, cmd5
)
3539 if (regname
!= 0) /* yank from specified buffer */
3541 AppendCharToRedobuff('"');
3542 AppendCharToRedobuff(regname
);
3545 AppendNumberToRedobuff(num
);
3548 AppendCharToRedobuff(cmd1
);
3550 AppendCharToRedobuff(cmd2
);
3552 AppendCharToRedobuff(cmd3
);
3554 AppendCharToRedobuff(cmd4
);
3556 AppendCharToRedobuff(cmd5
);
3560 * check for operator active and clear it
3562 * return TRUE if operator was active
3568 if (oap
->op_type
== OP_NOP
)
3575 * Check for operator or Visual active. Clear active operator.
3577 * Return TRUE if operator or Visual was active.
3583 if (oap
->op_type
== OP_NOP
3597 oap
->op_type
= OP_NOP
;
3599 oap
->motion_force
= NUL
;
3600 oap
->use_reg_one
= FALSE
;
3613 * Remove the shift modifier from a special key.
3616 unshift_special(cap
)
3619 switch (cap
->cmdchar
)
3621 case K_S_RIGHT
: cap
->cmdchar
= K_RIGHT
; break;
3622 case K_S_LEFT
: cap
->cmdchar
= K_LEFT
; break;
3623 case K_S_UP
: cap
->cmdchar
= K_UP
; break;
3624 case K_S_DOWN
: cap
->cmdchar
= K_DOWN
; break;
3625 case K_S_HOME
: cap
->cmdchar
= K_HOME
; break;
3626 case K_S_END
: cap
->cmdchar
= K_END
; break;
3628 cap
->cmdchar
= simplify_key(cap
->cmdchar
, &mod_mask
);
3632 #if defined(FEAT_CMDL_INFO) || defined(PROTO)
3634 * Routines for displaying a partly typed command
3637 #ifdef FEAT_VISUAL /* need room for size of Visual area */
3638 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30
3640 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1
3642 static char_u showcmd_buf
[SHOWCMD_BUFLEN
];
3643 static char_u old_showcmd_buf
[SHOWCMD_BUFLEN
]; /* For push_showcmd() */
3644 static int showcmd_is_clear
= TRUE
;
3645 static int showcmd_visual
= FALSE
;
3647 static void display_showcmd
__ARGS((void));
3656 if (VIsual_active
&& !char_avail())
3658 int i
= lt(VIsual
, curwin
->w_cursor
);
3660 colnr_T leftcol
, rightcol
;
3663 /* Show the size of the Visual area. */
3667 bot
= curwin
->w_cursor
.lnum
;
3671 top
= curwin
->w_cursor
.lnum
;
3674 # ifdef FEAT_FOLDING
3675 /* Include closed folds as a whole. */
3676 hasFolding(top
, &top
, NULL
);
3677 hasFolding(bot
, NULL
, &bot
);
3679 lines
= bot
- top
+ 1;
3681 if (VIsual_mode
== Ctrl_V
)
3683 getvcols(curwin
, &curwin
->w_cursor
, &VIsual
, &leftcol
, &rightcol
);
3684 sprintf((char *)showcmd_buf
, "%ldx%ld", lines
,
3685 (long)(rightcol
- leftcol
+ 1));
3687 else if (VIsual_mode
== 'V' || VIsual
.lnum
!= curwin
->w_cursor
.lnum
)
3688 sprintf((char *)showcmd_buf
, "%ld", lines
);
3690 sprintf((char *)showcmd_buf
, "%ld", (long)(i
3691 ? curwin
->w_cursor
.col
- VIsual
.col
3692 : VIsual
.col
- curwin
->w_cursor
.col
) + (*p_sel
!= 'e'));
3693 showcmd_buf
[SHOWCMD_COLS
] = NUL
; /* truncate */
3694 showcmd_visual
= TRUE
;
3699 showcmd_buf
[0] = NUL
;
3700 showcmd_visual
= FALSE
;
3702 /* Don't actually display something if there is nothing to clear. */
3703 if (showcmd_is_clear
)
3711 * Add 'c' to string of shown command chars.
3712 * Return TRUE if output has been written (and setcursor() has been called).
3722 #if defined(FEAT_MOUSE)
3724 static int ignore
[] =
3727 K_VER_SCROLLBAR
, K_HOR_SCROLLBAR
,
3728 K_LEFTMOUSE_NM
, K_LEFTRELEASE_NM
,
3731 K_LEFTMOUSE
, K_LEFTDRAG
, K_LEFTRELEASE
,
3732 K_MIDDLEMOUSE
, K_MIDDLEDRAG
, K_MIDDLERELEASE
,
3733 K_RIGHTMOUSE
, K_RIGHTDRAG
, K_RIGHTRELEASE
,
3734 K_MOUSEDOWN
, K_MOUSEUP
,
3735 K_X1MOUSE
, K_X1DRAG
, K_X1RELEASE
, K_X2MOUSE
, K_X2DRAG
, K_X2RELEASE
,
3741 if (!p_sc
|| msg_silent
!= 0)
3746 showcmd_buf
[0] = NUL
;
3747 showcmd_visual
= FALSE
;
3750 #if defined(FEAT_MOUSE)
3751 /* Ignore keys that are scrollbar updates and mouse clicks */
3753 for (i
= 0; ignore
[i
] != 0; ++i
)
3759 old_len
= (int)STRLEN(showcmd_buf
);
3760 extra_len
= (int)STRLEN(p
);
3761 overflow
= old_len
+ extra_len
- SHOWCMD_COLS
;
3763 STRCPY(showcmd_buf
, showcmd_buf
+ overflow
);
3764 STRCAT(showcmd_buf
, p
);
3778 if (!add_to_showcmd(c
))
3783 * Delete 'len' characters from the end of the shown command.
3786 del_from_showcmd(len
)
3794 old_len
= (int)STRLEN(showcmd_buf
);
3797 showcmd_buf
[old_len
- len
] = NUL
;
3804 * push_showcmd() and pop_showcmd() are used when waiting for the user to type
3805 * something and there is a partial mapping.
3811 STRCPY(old_showcmd_buf
, showcmd_buf
);
3820 STRCPY(showcmd_buf
, old_showcmd_buf
);
3832 len
= (int)STRLEN(showcmd_buf
);
3834 showcmd_is_clear
= TRUE
;
3837 screen_puts(showcmd_buf
, (int)Rows
- 1, sc_col
, 0);
3838 showcmd_is_clear
= FALSE
;
3842 * clear the rest of an old message by outputting up to SHOWCMD_COLS
3845 screen_puts((char_u
*)" " + len
, (int)Rows
- 1, sc_col
+ len
, 0);
3847 setcursor(); /* put cursor back where it belongs */
3851 #ifdef FEAT_SCROLLBIND
3853 * When "check" is FALSE, prepare for commands that scroll the window.
3854 * When "check" is TRUE, take care of scroll-binding after the window has
3855 * scrolled. Called from normal_cmd() and edit().
3858 do_check_scrollbind(check
)
3861 static win_T
*old_curwin
= NULL
;
3862 static linenr_T old_topline
= 0;
3864 static int old_topfill
= 0;
3866 static buf_T
*old_buf
= NULL
;
3867 static colnr_T old_leftcol
= 0;
3869 if (check
&& curwin
->w_p_scb
)
3871 /* If a ":syncbind" command was just used, don't scroll, only reset
3874 did_syncbind
= FALSE
;
3875 else if (curwin
== old_curwin
)
3878 * Synchronize other windows, as necessary according to
3879 * 'scrollbind'. Don't do this after an ":edit" command, except
3880 * when 'diff' is set.
3882 if ((curwin
->w_buffer
== old_buf
3887 && (curwin
->w_topline
!= old_topline
3889 || curwin
->w_topfill
!= old_topfill
3891 || curwin
->w_leftcol
!= old_leftcol
))
3893 check_scrollbind(curwin
->w_topline
- old_topline
,
3894 (long)(curwin
->w_leftcol
- old_leftcol
));
3897 else if (vim_strchr(p_sbo
, 'j')) /* jump flag set in 'scrollopt' */
3900 * When switching between windows, make sure that the relative
3901 * vertical offset is valid for the new window. The relative
3902 * offset is invalid whenever another 'scrollbind' window has
3903 * scrolled to a point that would force the current window to
3904 * scroll past the beginning or end of its buffer. When the
3905 * resync is performed, some of the other 'scrollbind' windows may
3906 * need to jump so that the current window's relative position is
3907 * visible on-screen.
3909 check_scrollbind(curwin
->w_topline
- curwin
->w_scbind_pos
, 0L);
3911 curwin
->w_scbind_pos
= curwin
->w_topline
;
3914 old_curwin
= curwin
;
3915 old_topline
= curwin
->w_topline
;
3917 old_topfill
= curwin
->w_topfill
;
3919 old_buf
= curwin
->w_buffer
;
3920 old_leftcol
= curwin
->w_leftcol
;
3924 * Synchronize any windows that have "scrollbind" set, based on the
3925 * number of rows by which the current window has changed
3926 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
3929 check_scrollbind(topline_diff
, leftcol_diff
)
3930 linenr_T topline_diff
;
3935 win_T
*old_curwin
= curwin
;
3936 buf_T
*old_curbuf
= curbuf
;
3938 int old_VIsual_select
= VIsual_select
;
3939 int old_VIsual_active
= VIsual_active
;
3941 colnr_T tgt_leftcol
= curwin
->w_leftcol
;
3946 * check 'scrollopt' string for vertical and horizontal scroll options
3948 want_ver
= (vim_strchr(p_sbo
, 'v') && topline_diff
!= 0);
3950 want_ver
|= old_curwin
->w_p_diff
;
3952 want_hor
= (vim_strchr(p_sbo
, 'h') && (leftcol_diff
|| topline_diff
!= 0));
3955 * loop through the scrollbound windows and scroll accordingly
3958 VIsual_select
= VIsual_active
= 0;
3960 for (curwin
= firstwin
; curwin
; curwin
= curwin
->w_next
)
3962 curbuf
= curwin
->w_buffer
;
3963 /* skip original window and windows with 'noscrollbind' */
3964 if (curwin
!= old_curwin
&& curwin
->w_p_scb
)
3967 * do the vertical scroll
3972 if (old_curwin
->w_p_diff
&& curwin
->w_p_diff
)
3974 diff_set_topline(old_curwin
, curwin
);
3979 curwin
->w_scbind_pos
+= topline_diff
;
3980 topline
= curwin
->w_scbind_pos
;
3981 if (topline
> curbuf
->b_ml
.ml_line_count
)
3982 topline
= curbuf
->b_ml
.ml_line_count
;
3986 y
= topline
- curwin
->w_topline
;
3990 scrolldown(-y
, FALSE
);
3993 redraw_later(VALID
);
3996 curwin
->w_redr_status
= TRUE
;
4001 * do the horizontal scroll
4003 if (want_hor
&& curwin
->w_leftcol
!= tgt_leftcol
)
4005 curwin
->w_leftcol
= tgt_leftcol
;
4012 * reset current-window
4015 VIsual_select
= old_VIsual_select
;
4016 VIsual_active
= old_VIsual_active
;
4018 curwin
= old_curwin
;
4019 curbuf
= old_curbuf
;
4021 #endif /* #ifdef FEAT_SCROLLBIND */
4024 * Command character that's ignored.
4025 * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use
4032 cap
->retval
|= CA_COMMAND_BUSY
; /* don't call edit() now */
4036 * Command character that doesn't do anything, but unlike nv_ignore() does
4037 * start edit(). Used for "startinsert" executed while starting up.
4047 * Command character doesn't exist.
4053 clearopbeep(cap
->oap
);
4057 * <Help> and <F1> commands.
4063 if (!checkclearopq(cap
->oap
))
4068 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor.
4074 if (!checkclearopq(cap
->oap
)
4075 && do_addsub((int)cap
->cmdchar
, cap
->count1
) == OK
)
4080 * CTRL-F, CTRL-B, etc: Scroll page up or down.
4086 if (!checkclearop(cap
->oap
))
4089 if (mod_mask
& MOD_MASK_CTRL
)
4091 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */
4092 if (cap
->arg
== BACKWARD
)
4093 goto_tabpage(-(int)cap
->count1
);
4095 goto_tabpage((int)cap
->count0
);
4099 (void)onepage(cap
->arg
, cap
->count1
);
4104 * Implementation of "gd" and "gD" command.
4107 nv_gd(oap
, nchar
, thisblock
)
4110 int thisblock
; /* 1 for "1gd" and "1gD" */
4115 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0
4116 || find_decl(ptr
, len
, nchar
== 'd', thisblock
, 0) == FAIL
)
4119 else if ((fdo_flags
& FDO_SEARCH
) && KeyTyped
&& oap
->op_type
== OP_NOP
)
4125 * Search for variable declaration of "ptr[len]".
4126 * When "locally" is TRUE in the current function ("gd"), otherwise in the
4127 * current file ("gD").
4128 * When "thisblock" is TRUE check the {} block scope.
4129 * Return FAIL when not found.
4132 find_decl(ptr
, len
, locally
, thisblock
, searchflags
)
4137 int searchflags
; /* flags passed to searchit() */
4149 if ((pat
= alloc(len
+ 7)) == NULL
)
4152 /* Put "\V" before the pattern to avoid that the special meaning of "."
4153 * and "~" causes trouble. */
4154 sprintf((char *)pat
, vim_iswordp(ptr
) ? "\\V\\<%.*s\\>" : "\\V%.*s",
4156 old_pos
= curwin
->w_cursor
;
4159 p_ws
= FALSE
; /* don't wrap around end of file now */
4160 p_scs
= FALSE
; /* don't switch ignorecase off now */
4163 * With "gD" go to line 1.
4164 * With "gd" Search back for the start of the current function, then go
4165 * back until a blank line. If this fails go to line 1.
4167 if (!locally
|| !findpar(&incll
, BACKWARD
, 1L, '{', FALSE
))
4169 setpcmark(); /* Set in findpar() otherwise */
4170 curwin
->w_cursor
.lnum
= 1;
4171 par_pos
= curwin
->w_cursor
;
4175 par_pos
= curwin
->w_cursor
;
4176 while (curwin
->w_cursor
.lnum
> 1 && *skipwhite(ml_get_curline()) != NUL
)
4177 --curwin
->w_cursor
.lnum
;
4179 curwin
->w_cursor
.col
= 0;
4181 /* Search forward for the identifier, ignore comment lines. */
4182 clearpos(&found_pos
);
4185 t
= searchit(curwin
, curbuf
, &curwin
->w_cursor
, FORWARD
,
4186 pat
, 1L, searchflags
, RE_LAST
, (linenr_T
)0);
4187 if (curwin
->w_cursor
.lnum
>= old_pos
.lnum
)
4188 t
= FAIL
; /* match after start is failure too */
4190 if (thisblock
&& t
!= FAIL
)
4194 /* Check that the block the match is in doesn't end before the
4195 * position where we started the search from. */
4196 if ((pos
= findmatchlimit(NULL
, '}', FM_FORWARD
,
4197 (int)(old_pos
.lnum
- curwin
->w_cursor
.lnum
+ 1))) != NULL
4198 && pos
->lnum
< old_pos
.lnum
)
4204 /* If we previously found a valid position, use it. */
4205 if (found_pos
.lnum
!= 0)
4207 curwin
->w_cursor
= found_pos
;
4212 #ifdef FEAT_COMMENTS
4213 if (get_leader_len(ml_get_curline(), NULL
, FALSE
) > 0)
4215 /* Ignore this line, continue at start of next line. */
4216 ++curwin
->w_cursor
.lnum
;
4217 curwin
->w_cursor
.col
= 0;
4221 if (!locally
) /* global search: use first match found */
4223 if (curwin
->w_cursor
.lnum
>= par_pos
.lnum
)
4225 /* If we previously found a valid position, use it. */
4226 if (found_pos
.lnum
!= 0)
4227 curwin
->w_cursor
= found_pos
;
4231 /* For finding a local variable and the match is before the "{" search
4232 * to find a later match. For K&R style function declarations this
4233 * skips the function header without types. */
4234 found_pos
= curwin
->w_cursor
;
4240 curwin
->w_cursor
= old_pos
;
4244 curwin
->w_set_curswant
= TRUE
;
4245 /* "n" searches forward now */
4257 * Move 'dist' lines in direction 'dir', counting lines by *screen*
4258 * lines rather than lines in the file.
4259 * 'dist' must be positive.
4261 * Return OK if able to move cursor, FAIL otherwise.
4264 nv_screengo(oap
, dir
, dist
)
4269 int linelen
= linetabsize(ml_get_curline());
4273 int col_off1
; /* margin offset for first screen line */
4274 int col_off2
; /* margin offset for wrapped screen line */
4275 int width1
; /* text width for first screen line */
4276 int width2
; /* test width for wrapped screen line */
4278 oap
->motion_type
= MCHAR
;
4279 oap
->inclusive
= FALSE
;
4281 col_off1
= curwin_col_off();
4282 col_off2
= col_off1
- curwin_col_off2();
4283 width1
= W_WIDTH(curwin
) - col_off1
;
4284 width2
= W_WIDTH(curwin
) - col_off2
;
4286 #ifdef FEAT_VERTSPLIT
4287 if (curwin
->w_width
!= 0)
4291 * Instead of sticking at the last character of the buffer line we
4292 * try to stick in the last column of the screen.
4294 if (curwin
->w_curswant
== MAXCOL
)
4299 curwin
->w_curswant
= 0;
4302 curwin
->w_curswant
= width1
- 1;
4303 if (curwin
->w_virtcol
> curwin
->w_curswant
)
4304 curwin
->w_curswant
+= ((curwin
->w_virtcol
4305 - curwin
->w_curswant
- 1) / width2
+ 1) * width2
;
4310 if (linelen
> width1
)
4311 n
= ((linelen
- width1
- 1) / width2
+ 1) * width2
+ width1
;
4314 if (curwin
->w_curswant
> (colnr_T
)n
+ 1)
4315 curwin
->w_curswant
-= ((curwin
->w_curswant
- n
) / width2
+ 1)
4321 if (dir
== BACKWARD
)
4323 if ((long)curwin
->w_curswant
>= width2
)
4324 /* move back within line */
4325 curwin
->w_curswant
-= width2
;
4328 /* to previous line */
4329 if (curwin
->w_cursor
.lnum
== 1)
4334 --curwin
->w_cursor
.lnum
;
4336 /* Move to the start of a closed fold. Don't do that when
4337 * 'foldopen' contains "all": it will open in a moment. */
4338 if (!(fdo_flags
& FDO_ALL
))
4339 (void)hasFolding(curwin
->w_cursor
.lnum
,
4340 &curwin
->w_cursor
.lnum
, NULL
);
4342 linelen
= linetabsize(ml_get_curline());
4343 if (linelen
> width1
)
4344 curwin
->w_curswant
+= (((linelen
- width1
- 1) / width2
)
4348 else /* dir == FORWARD */
4350 if (linelen
> width1
)
4351 n
= ((linelen
- width1
- 1) / width2
+ 1) * width2
+ width1
;
4354 if (curwin
->w_curswant
+ width2
< (colnr_T
)n
)
4355 /* move forward within line */
4356 curwin
->w_curswant
+= width2
;
4361 /* Move to the end of a closed fold. */
4362 (void)hasFolding(curwin
->w_cursor
.lnum
, NULL
,
4363 &curwin
->w_cursor
.lnum
);
4365 if (curwin
->w_cursor
.lnum
== curbuf
->b_ml
.ml_line_count
)
4370 curwin
->w_cursor
.lnum
++;
4371 curwin
->w_curswant
%= width2
;
4375 #ifdef FEAT_VERTSPLIT
4379 coladvance(curwin
->w_curswant
);
4381 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
4382 if (curwin
->w_cursor
.col
> 0 && curwin
->w_p_wrap
)
4385 * Check for landing on a character that got split at the end of the
4386 * last line. We want to advance a screenline, not end up in the same
4387 * screenline or move two screenlines.
4390 if (curwin
->w_virtcol
> curwin
->w_curswant
4391 && (curwin
->w_curswant
< (colnr_T
)width1
4392 ? (curwin
->w_curswant
> (colnr_T
)width1
/ 2)
4393 : ((curwin
->w_curswant
- width1
) % width2
4394 > (colnr_T
)width2
/ 2)))
4395 --curwin
->w_cursor
.col
;
4400 curwin
->w_curswant
= MAXCOL
; /* stick in the last column */
4407 * Mouse scroll wheel: Default action is to scroll three lines, or one page
4408 * when Shift or Ctrl is used.
4409 * K_MOUSEUP (cap->arg == TRUE) or K_MOUSEDOWN (cap->arg == FALSE)
4415 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
4416 win_T
*old_curwin
= curwin
;
4418 /* Currently we only get the mouse coordinates in the GUI. */
4419 if (gui
.in_use
&& mouse_row
>= 0 && mouse_col
>= 0)
4426 /* find the window at the pointer coordinates */
4427 curwin
= mouse_find_win(&row
, &col
);
4428 curbuf
= curwin
->w_buffer
;
4432 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
4434 (void)onepage(cap
->arg
? FORWARD
: BACKWARD
, 1L);
4440 nv_scroll_line(cap
);
4443 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
4444 curwin
->w_redr_status
= TRUE
;
4446 curwin
= old_curwin
;
4447 curbuf
= curwin
->w_buffer
;
4452 * Mouse clicks and drags.
4458 (void)do_mouse(cap
->oap
, cap
->cmdchar
, BACKWARD
, cap
->count1
, 0);
4463 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down.
4464 * cap->arg must be TRUE for CTRL-E.
4470 if (!checkclearop(cap
->oap
))
4471 scroll_redraw(cap
->arg
, cap
->count1
);
4475 * Scroll "count" lines up or down, and redraw.
4478 scroll_redraw(up
, count
)
4482 linenr_T prev_topline
= curwin
->w_topline
;
4484 int prev_topfill
= curwin
->w_topfill
;
4486 linenr_T prev_lnum
= curwin
->w_cursor
.lnum
;
4489 scrollup(count
, TRUE
);
4491 scrolldown(count
, TRUE
);
4494 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as
4495 * valid, otherwise the screen jumps back at the end of the file. */
4497 check_cursor_moved(curwin
);
4498 curwin
->w_valid
|= VALID_TOPLINE
;
4500 /* If moved back to where we were, at least move the cursor, otherwise
4501 * we get stuck at one position. Don't move the cursor up if the
4502 * first line of the buffer is already on the screen */
4503 while (curwin
->w_topline
== prev_topline
4505 && curwin
->w_topfill
== prev_topfill
4511 if (curwin
->w_cursor
.lnum
> prev_lnum
4512 || cursor_down(1L, FALSE
) == FAIL
)
4517 if (curwin
->w_cursor
.lnum
< prev_lnum
4518 || prev_topline
== 1L
4519 || cursor_up(1L, FALSE
) == FAIL
)
4522 /* Mark w_topline as valid, otherwise the screen jumps back at the
4523 * end of the file. */
4524 check_cursor_moved(curwin
);
4525 curwin
->w_valid
|= VALID_TOPLINE
;
4528 if (curwin
->w_cursor
.lnum
!= prev_lnum
)
4529 coladvance(curwin
->w_curswant
);
4530 redraw_later(VALID
);
4534 * Commands that start with "z".
4542 int nchar
= cap
->nchar
;
4544 long old_fdl
= curwin
->w_p_fdl
;
4545 int old_fen
= curwin
->w_p_fen
;
4551 if (VIM_ISDIGIT(nchar
))
4554 * "z123{nchar}": edit the count before obtaining {nchar}
4556 if (checkclearop(cap
->oap
))
4561 #ifdef USE_ON_FLY_SCROLL
4562 dont_scroll
= TRUE
; /* disallow scrolling here */
4565 ++allow_keys
; /* no mapping for nchar, but allow key codes */
4566 nchar
= safe_vgetc();
4568 LANGMAP_ADJUST(nchar
, TRUE
);
4572 #ifdef FEAT_CMDL_INFO
4573 (void)add_to_showcmd(nchar
);
4575 if (nchar
== K_DEL
|| nchar
== K_KDEL
)
4577 else if (VIM_ISDIGIT(nchar
))
4578 n
= n
* 10 + (nchar
- '0');
4579 else if (nchar
== CAR
)
4582 need_mouse_correct
= TRUE
;
4584 win_setheight((int)n
);
4587 else if (nchar
== 'l'
4590 || nchar
== K_RIGHT
)
4592 cap
->count1
= n
? n
* cap
->count1
: cap
->count1
;
4597 clearopbeep(cap
->oap
);
4601 cap
->oap
->op_type
= OP_NOP
;
4608 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc"
4609 * and "zC" only in Visual mode. "zj" and "zk" are motion
4611 cap
->nchar
!= 'f' && cap
->nchar
!= 'F'
4612 && !(VIsual_active
&& vim_strchr((char_u
*)"dcCoO", cap
->nchar
))
4613 && cap
->nchar
!= 'j' && cap
->nchar
!= 'k'
4616 checkclearop(cap
->oap
))
4620 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb":
4621 * If line number given, set cursor.
4623 if ((vim_strchr((char_u
*)"+\r\nt.z^-b", nchar
) != NULL
)
4625 && cap
->count0
!= curwin
->w_cursor
.lnum
)
4628 if (cap
->count0
> curbuf
->b_ml
.ml_line_count
)
4629 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
4631 curwin
->w_cursor
.lnum
= cap
->count0
;
4637 /* "z+", "z<CR>" and "zt": put cursor at top of screen */
4639 if (cap
->count0
== 0)
4641 /* No count given: put cursor at the line below screen */
4642 validate_botline(); /* make sure w_botline is valid */
4643 if (curwin
->w_botline
> curbuf
->b_ml
.ml_line_count
)
4644 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
4646 curwin
->w_cursor
.lnum
= curwin
->w_botline
;
4652 beginline(BL_WHITE
| BL_FIX
);
4655 case 't': scroll_cursor_top(0, TRUE
);
4656 redraw_later(VALID
);
4659 /* "z." and "zz": put cursor in middle of screen */
4660 case '.': beginline(BL_WHITE
| BL_FIX
);
4663 case 'z': scroll_cursor_halfway(TRUE
);
4664 redraw_later(VALID
);
4667 /* "z^", "z-" and "zb": put cursor at bottom of screen */
4668 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window
4669 * when <count> is at bottom of window, and puts that one at
4670 * bottom of window. */
4671 if (cap
->count0
!= 0)
4673 scroll_cursor_bot(0, TRUE
);
4674 curwin
->w_cursor
.lnum
= curwin
->w_topline
;
4676 else if (curwin
->w_topline
== 1)
4677 curwin
->w_cursor
.lnum
= 1;
4679 curwin
->w_cursor
.lnum
= curwin
->w_topline
- 1;
4682 beginline(BL_WHITE
| BL_FIX
);
4685 case 'b': scroll_cursor_bot(0, TRUE
);
4686 redraw_later(VALID
);
4689 /* "zH" - scroll screen right half-page */
4691 cap
->count1
*= W_WIDTH(curwin
) / 2;
4694 /* "zh" - scroll screen to the right */
4697 if (!curwin
->w_p_wrap
)
4699 if ((colnr_T
)cap
->count1
> curwin
->w_leftcol
)
4700 curwin
->w_leftcol
= 0;
4702 curwin
->w_leftcol
-= (colnr_T
)cap
->count1
;
4707 /* "zL" - scroll screen left half-page */
4708 case 'L': cap
->count1
*= W_WIDTH(curwin
) / 2;
4711 /* "zl" - scroll screen to the left */
4714 if (!curwin
->w_p_wrap
)
4716 /* scroll the window left */
4717 curwin
->w_leftcol
+= (colnr_T
)cap
->count1
;
4722 /* "zs" - scroll screen, cursor at the start */
4723 case 's': if (!curwin
->w_p_wrap
)
4726 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4727 col
= 0; /* like the cursor is in col 0 */
4730 getvcol(curwin
, &curwin
->w_cursor
, &col
, NULL
, NULL
);
4731 if ((long)col
> p_siso
)
4735 if (curwin
->w_leftcol
!= col
)
4737 curwin
->w_leftcol
= col
;
4738 redraw_later(NOT_VALID
);
4743 /* "ze" - scroll screen, cursor at the end */
4744 case 'e': if (!curwin
->w_p_wrap
)
4747 if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4748 col
= 0; /* like the cursor is in col 0 */
4751 getvcol(curwin
, &curwin
->w_cursor
, NULL
, NULL
, &col
);
4752 n
= W_WIDTH(curwin
) - curwin_col_off();
4753 if ((long)col
+ p_siso
< n
)
4756 col
= col
+ p_siso
- n
+ 1;
4757 if (curwin
->w_leftcol
!= col
)
4759 curwin
->w_leftcol
= col
;
4760 redraw_later(NOT_VALID
);
4766 /* "zF": create fold command */
4767 /* "zf": create fold operator */
4769 case 'f': if (foldManualAllowed(TRUE
))
4773 curwin
->w_p_fen
= TRUE
;
4775 /* "zF" is like "zfzf" */
4776 if (nchar
== 'F' && cap
->oap
->op_type
== OP_FOLD
)
4783 clearopbeep(cap
->oap
);
4786 /* "zd": delete fold at cursor */
4787 /* "zD": delete fold at cursor recursively */
4789 case 'D': if (foldManualAllowed(FALSE
))
4794 deleteFold(curwin
->w_cursor
.lnum
,
4795 curwin
->w_cursor
.lnum
, nchar
== 'D', FALSE
);
4799 /* "zE": erease all folds */
4800 case 'E': if (foldmethodIsManual(curwin
))
4802 clearFolding(curwin
);
4803 changed_window_setting();
4805 else if (foldmethodIsMarker(curwin
))
4806 deleteFold((linenr_T
)1, curbuf
->b_ml
.ml_line_count
,
4809 EMSG(_("E352: Cannot erase folds with current 'foldmethod'"));
4812 /* "zn": fold none: reset 'foldenable' */
4813 case 'n': curwin
->w_p_fen
= FALSE
;
4816 /* "zN": fold Normal: set 'foldenable' */
4817 case 'N': curwin
->w_p_fen
= TRUE
;
4820 /* "zi": invert folding: toggle 'foldenable' */
4821 case 'i': curwin
->w_p_fen
= !curwin
->w_p_fen
;
4824 /* "za": open closed fold or close open fold at cursor */
4825 case 'a': if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4826 openFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4829 closeFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4830 curwin
->w_p_fen
= TRUE
;
4834 /* "zA": open fold at cursor recursively */
4835 case 'A': if (hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
))
4836 openFoldRecurse(curwin
->w_cursor
.lnum
);
4839 closeFoldRecurse(curwin
->w_cursor
.lnum
);
4840 curwin
->w_p_fen
= TRUE
;
4844 /* "zo": open fold at cursor or Visual area */
4845 case 'o': if (VIsual_active
)
4848 openFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4851 /* "zO": open fold recursively */
4852 case 'O': if (VIsual_active
)
4855 openFoldRecurse(curwin
->w_cursor
.lnum
);
4858 /* "zc": close fold at cursor or Visual area */
4859 case 'c': if (VIsual_active
)
4862 closeFold(curwin
->w_cursor
.lnum
, cap
->count1
);
4863 curwin
->w_p_fen
= TRUE
;
4866 /* "zC": close fold recursively */
4867 case 'C': if (VIsual_active
)
4870 closeFoldRecurse(curwin
->w_cursor
.lnum
);
4871 curwin
->w_p_fen
= TRUE
;
4874 /* "zv": open folds at the cursor */
4875 case 'v': foldOpenCursor();
4878 /* "zx": re-apply 'foldlevel' and open folds at the cursor */
4879 case 'x': curwin
->w_p_fen
= TRUE
;
4880 newFoldLevel(); /* update right now */
4884 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */
4885 case 'X': curwin
->w_p_fen
= TRUE
;
4886 old_fdl
= -1; /* force an update */
4889 /* "zm": fold more */
4890 case 'm': if (curwin
->w_p_fdl
> 0)
4892 old_fdl
= -1; /* force an update */
4893 curwin
->w_p_fen
= TRUE
;
4896 /* "zM": close all folds */
4897 case 'M': curwin
->w_p_fdl
= 0;
4898 old_fdl
= -1; /* force an update */
4899 curwin
->w_p_fen
= TRUE
;
4902 /* "zr": reduce folding */
4903 case 'r': ++curwin
->w_p_fdl
;
4906 /* "zR": open all folds */
4907 case 'R': curwin
->w_p_fdl
= getDeepestNesting();
4908 old_fdl
= -1; /* force an update */
4911 case 'j': /* "zj" move to next fold downwards */
4912 case 'k': /* "zk" move to next fold upwards */
4913 if (foldMoveTo(TRUE
, nchar
== 'j' ? FORWARD
: BACKWARD
,
4914 cap
->count1
) == FAIL
)
4915 clearopbeep(cap
->oap
);
4918 #endif /* FEAT_FOLDING */
4921 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */
4923 ++allow_keys
; /* no mapping for nchar, but allow key codes */
4924 nchar
= safe_vgetc();
4926 LANGMAP_ADJUST(nchar
, TRUE
);
4930 #ifdef FEAT_CMDL_INFO
4931 (void)add_to_showcmd(nchar
);
4933 if (vim_strchr((char_u
*)"gGwW", nchar
) == NULL
)
4935 clearopbeep(cap
->oap
);
4941 case 'g': /* "zg": add good word to word list */
4942 case 'w': /* "zw": add wrong word to word list */
4943 case 'G': /* "zG": add good word to temp word list */
4944 case 'W': /* "zW": add wrong word to temp word list */
4949 if (checkclearop(cap
->oap
))
4952 if (VIsual_active
&& get_visual_text(cap
, &ptr
, &len
)
4958 pos_T pos
= curwin
->w_cursor
;
4960 /* Find bad word under the cursor. */
4961 len
= spell_move_to(curwin
, FORWARD
, TRUE
, TRUE
, NULL
);
4962 if (len
!= 0 && curwin
->w_cursor
.col
<= pos
.col
)
4963 ptr
= ml_get_pos(&curwin
->w_cursor
);
4964 curwin
->w_cursor
= pos
;
4967 if (ptr
== NULL
&& (len
= find_ident_under_cursor(&ptr
,
4970 spell_add_word(ptr
, len
, nchar
== 'w' || nchar
== 'W',
4971 (nchar
== 'G' || nchar
== 'W')
4972 ? 0 : (int)cap
->count1
,
4977 case '=': /* "z=": suggestions for a badly spelled word */
4978 if (!checkclearop(cap
->oap
))
4979 spell_suggest((int)cap
->count0
);
4983 default: clearopbeep(cap
->oap
);
4987 /* Redraw when 'foldenable' changed */
4988 if (old_fen
!= curwin
->w_p_fen
)
4993 if (foldmethodIsDiff(curwin
) && curwin
->w_p_scb
)
4995 /* Adjust 'foldenable' in diff-synced windows. */
4998 if (wp
!= curwin
&& foldmethodIsDiff(wp
) && wp
->w_p_scb
)
5000 wp
->w_p_fen
= curwin
->w_p_fen
;
5001 changed_window_setting_win(wp
);
5006 changed_window_setting();
5009 /* Redraw when 'foldlevel' changed. */
5010 if (old_fdl
!= curwin
->w_p_fdl
)
5017 * Vertical scrollbar movement.
5020 nv_ver_scrollbar(cap
)
5023 if (cap
->oap
->op_type
!= OP_NOP
)
5024 clearopbeep(cap
->oap
);
5026 /* Even if an operator was pending, we still want to scroll */
5031 * Horizontal scrollbar movement.
5034 nv_hor_scrollbar(cap
)
5037 if (cap
->oap
->op_type
!= OP_NOP
)
5038 clearopbeep(cap
->oap
);
5040 /* Even if an operator was pending, we still want to scroll */
5041 gui_do_horiz_scroll();
5045 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
5053 if (cap
->oap
->op_type
!= OP_NOP
)
5054 clearopbeep(cap
->oap
);
5056 /* Even if an operator was pending, we still want to jump tabs. */
5057 goto_tabpage(current_tab
);
5061 * Selected item in tab line menu.
5067 if (cap
->oap
->op_type
!= OP_NOP
)
5068 clearopbeep(cap
->oap
);
5070 /* Even if an operator was pending, we still want to jump tabs. */
5075 * Handle selecting an item of the GUI tab line menu.
5076 * Used in Normal and Insert mode.
5081 switch (current_tabmenu
)
5083 case TABLINE_MENU_CLOSE
:
5084 if (current_tab
== 0)
5085 do_cmdline_cmd((char_u
*)"tabclose");
5088 vim_snprintf((char *)IObuff
, IOSIZE
, "tabclose %d",
5090 do_cmdline_cmd(IObuff
);
5094 case TABLINE_MENU_NEW
:
5095 vim_snprintf((char *)IObuff
, IOSIZE
, "%dtabnew",
5096 current_tab
> 0 ? current_tab
- 1 : 999);
5097 do_cmdline_cmd(IObuff
);
5100 case TABLINE_MENU_OPEN
:
5101 vim_snprintf((char *)IObuff
, IOSIZE
, "browse %dtabnew",
5102 current_tab
> 0 ? current_tab
- 1 : 999);
5103 do_cmdline_cmd(IObuff
);
5117 * Ignore 'Q' in Visual mode, just give a beep.
5124 if (!checkclearop(cap
->oap
))
5129 * Handle a ":" command.
5143 if (cap
->oap
->op_type
!= OP_NOP
)
5145 /* Using ":" as a movement is characterwise exclusive. */
5146 cap
->oap
->motion_type
= MCHAR
;
5147 cap
->oap
->inclusive
= FALSE
;
5149 else if (cap
->count0
)
5151 /* translate "count:" into ":.,.+(count - 1)" */
5152 stuffcharReadbuff('.');
5153 if (cap
->count0
> 1)
5155 stuffReadbuff((char_u
*)",.+");
5156 stuffnumReadbuff((long)cap
->count0
- 1L);
5160 /* When typing, don't type below an old message */
5166 /* get a command line and execute it */
5167 do_cmdline(NULL
, getexline
, NULL
,
5168 cap
->oap
->op_type
!= OP_NOP
? DOCMD_KEEPLINE
: 0);
5170 /* If 'insertmode' changed, enter or exit Insert mode */
5171 if (p_im
!= old_p_im
)
5179 /* The start of the operator may have become invalid by the Ex
5181 if (cap
->oap
->op_type
!= OP_NOP
5182 && (cap
->oap
->start
.lnum
> curbuf
->b_ml
.ml_line_count
5183 || cap
->oap
->start
.col
>
5184 STRLEN(ml_get(cap
->oap
->start
.lnum
))))
5185 clearopbeep(cap
->oap
);
5190 * Handle CTRL-G command.
5197 if (VIsual_active
) /* toggle Selection/Visual mode */
5199 VIsual_select
= !VIsual_select
;
5204 if (!checkclearop(cap
->oap
))
5205 /* print full name if count given or :cd used */
5206 fileinfo((int)cap
->count0
, FALSE
, TRUE
);
5210 * Handle CTRL-H <Backspace> command.
5217 if (VIsual_active
&& VIsual_select
)
5219 cap
->cmdchar
= 'x'; /* BS key behaves like 'x' in Select mode */
5228 * CTRL-L: clear screen and redraw.
5234 if (!checkclearop(cap
->oap
))
5236 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT
5238 * Right now, the BeBox doesn't seem to have an easy way to detect
5239 * window resizing, so we cheat and make the user detect it
5240 * manually with CTRL-L instead
5245 /* Clear all syntax states to force resyncing. */
5246 syn_stack_free_all(curbuf
);
5248 redraw_later(CLEAR
);
5253 * CTRL-O: In Select mode: switch to Visual mode for one command.
5254 * Otherwise: Go to older pcmark.
5261 if (VIsual_active
&& VIsual_select
)
5263 VIsual_select
= FALSE
;
5265 restart_VIsual_select
= 2; /* restart Select mode later */
5270 cap
->count1
= -cap
->count1
;
5276 * CTRL-^ command, short for ":e #"
5282 if (!checkclearopq(cap
->oap
))
5283 (void)buflist_getfile((int)cap
->count0
, (linenr_T
)0,
5284 GETF_SETMARK
|GETF_ALT
, FALSE
);
5294 if (!checkclearopq(cap
->oap
))
5298 /* "ZZ": equivalent to ":x". */
5299 case 'Z': do_cmdline_cmd((char_u
*)"x");
5302 /* "ZQ": equivalent to ":q!" (Elvis compatible). */
5303 case 'Q': do_cmdline_cmd((char_u
*)"q!");
5306 default: clearopbeep(cap
->oap
);
5311 #if defined(FEAT_WINDOWS) || defined(PROTO)
5313 * Call nv_ident() as if "c1" was used, with "c2" as next character.
5324 vim_memset(&ca
, 0, sizeof(ca
));
5333 * Handle the commands that use the word under the cursor.
5334 * [g] CTRL-] :ta to current identifier
5335 * [g] 'K' run program for current identifier
5336 * [g] '*' / to current identifier or string
5337 * [g] '#' ? to current identifier or string
5338 * g ']' :tselect for current identifier
5347 char_u
*kp
; /* value of 'keywordprg' */
5348 int kp_help
; /* 'keywordprg' is ":help" */
5349 int n
= 0; /* init for GCC */
5351 int g_cmd
; /* "g" command */
5356 if (cap
->cmdchar
== 'g') /* "g*", "g#", "g]" and "gCTRL-]" */
5358 cmdchar
= cap
->nchar
;
5363 cmdchar
= cap
->cmdchar
;
5367 if (cmdchar
== POUND
) /* the pound sign, '#' for English keyboards */
5371 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode.
5373 if (cmdchar
== ']' || cmdchar
== Ctrl_RSB
|| cmdchar
== 'K')
5376 if (VIsual_active
&& get_visual_text(cap
, &ptr
, &n
) == FAIL
)
5379 if (checkclearopq(cap
->oap
))
5383 if (ptr
== NULL
&& (n
= find_ident_under_cursor(&ptr
,
5384 (cmdchar
== '*' || cmdchar
== '#')
5385 ? FIND_IDENT
|FIND_STRING
: FIND_IDENT
)) == 0)
5391 /* Allocate buffer to put the command in. Inserting backslashes can
5392 * double the length of the word. p_kp / curbuf->b_p_kp could be added
5393 * and some numbers. */
5394 kp
= (*curbuf
->b_p_kp
== NUL
? p_kp
: curbuf
->b_p_kp
);
5395 kp_help
= (*kp
== NUL
|| STRCMP(kp
, ":he") == 0
5396 || STRCMP(kp
, ":help") == 0);
5397 buf
= alloc((unsigned)(n
* 2 + 30 + STRLEN(kp
)));
5407 * Put cursor at start of word, makes search skip the word
5409 * Call setpcmark() first, so "*``" puts the cursor back where
5413 curwin
->w_cursor
.col
= (colnr_T
) (ptr
- ml_get_curline());
5415 if (!g_cmd
&& vim_iswordp(ptr
))
5417 no_smartcase
= TRUE
; /* don't use 'smartcase' now */
5422 STRCPY(buf
, "he! ");
5425 /* When a count is given, turn it into a range. Is this
5426 * really what we want? */
5427 isman
= (STRCMP(kp
, "man") == 0);
5428 isman_s
= (STRCMP(kp
, "man -s") == 0);
5429 if (cap
->count0
!= 0 && !(isman
|| isman_s
))
5430 sprintf((char *)buf
, ".,.+%ld", cap
->count0
- 1);
5433 if (cap
->count0
== 0 && isman_s
)
5438 if (cap
->count0
!= 0 && (isman
|| isman_s
))
5440 sprintf((char *)buf
+ STRLEN(buf
), "%ld", cap
->count0
);
5449 STRCPY(buf
, "cstag ");
5457 STRCPY(buf
, "he! ");
5461 sprintf((char *)buf
, "%ldta ", cap
->count0
);
5465 * Now grab the chars in the identifier
5468 aux_ptr
= (char_u
*)(p_magic
? "/.*~[^$\\" : "/^$\\");
5469 else if (cmdchar
== '#')
5470 aux_ptr
= (char_u
*)(p_magic
? "/?.*~[^$\\" : "/?^$\\");
5471 else if (cmdchar
== 'K' && !kp_help
)
5472 aux_ptr
= (char_u
*)" \t\\\"|!";
5474 /* Don't escape spaces and Tabs in a tag with a backslash */
5475 aux_ptr
= (char_u
*)"\\|\"";
5477 p
= buf
+ STRLEN(buf
);
5480 /* put a backslash before \ and some others */
5481 if (vim_strchr(aux_ptr
, *ptr
) != NULL
)
5484 /* When current byte is a part of multibyte character, copy all bytes
5485 * of that character. */
5489 int len
= (*mb_ptr2len
)(ptr
) - 1;
5491 for (i
= 0; i
< len
&& n
>= 1; ++i
, --n
)
5500 * Execute the command.
5502 if (cmdchar
== '*' || cmdchar
== '#')
5506 has_mbyte
? vim_iswordp(mb_prevptr(ml_get_curline(), ptr
)) :
5508 vim_iswordc(ptr
[-1])))
5511 /* put pattern in search history */
5512 add_to_history(HIST_SEARCH
, buf
, TRUE
, NUL
);
5514 normal_search(cap
, cmdchar
== '*' ? '/' : '?', buf
, 0);
5517 do_cmdline_cmd(buf
);
5522 #if defined(FEAT_VISUAL) || defined(PROTO)
5524 * Get visually selected text, within one line only.
5525 * Returns FAIL if more than one line selected.
5528 get_visual_text(cap
, pp
, lenp
)
5530 char_u
**pp
; /* return: start of selected text */
5531 int *lenp
; /* return: length of selected text */
5533 if (VIsual_mode
!= 'V')
5535 if (VIsual
.lnum
!= curwin
->w_cursor
.lnum
)
5538 clearopbeep(cap
->oap
);
5541 if (VIsual_mode
== 'V')
5543 *pp
= ml_get_curline();
5544 *lenp
= (int)STRLEN(*pp
);
5548 if (lt(curwin
->w_cursor
, VIsual
))
5550 *pp
= ml_get_pos(&curwin
->w_cursor
);
5551 *lenp
= VIsual
.col
- curwin
->w_cursor
.col
+ 1;
5555 *pp
= ml_get_pos(&VIsual
);
5556 *lenp
= curwin
->w_cursor
.col
- VIsual
.col
+ 1;
5560 /* Correct the length to include the whole last character. */
5561 *lenp
+= (*mb_ptr2len
)(*pp
+ (*lenp
- 1)) - 1;
5564 reset_VIsual_and_resel();
5570 * CTRL-T: backwards in tag stack
5576 if (!checkclearopq(cap
->oap
))
5577 do_tag((char_u
*)"", DT_POP
, (int)cap
->count1
, FALSE
, TRUE
);
5581 * Handle scrolling command 'H', 'L' and 'M'.
5594 cap
->oap
->motion_type
= MLINE
;
5597 if (cap
->cmdchar
== 'L')
5599 validate_botline(); /* make sure curwin->w_botline is valid */
5600 curwin
->w_cursor
.lnum
= curwin
->w_botline
- 1;
5601 if (cap
->count1
- 1 >= curwin
->w_cursor
.lnum
)
5602 curwin
->w_cursor
.lnum
= 1;
5606 if (hasAnyFolding(curwin
))
5608 /* Count a fold for one screen line. */
5609 for (n
= cap
->count1
- 1; n
> 0
5610 && curwin
->w_cursor
.lnum
> curwin
->w_topline
; --n
)
5612 (void)hasFolding(curwin
->w_cursor
.lnum
,
5613 &curwin
->w_cursor
.lnum
, NULL
);
5614 --curwin
->w_cursor
.lnum
;
5619 curwin
->w_cursor
.lnum
-= cap
->count1
- 1;
5624 if (cap
->cmdchar
== 'M')
5627 /* Don't count filler lines above the window. */
5628 used
-= diff_check_fill(curwin
, curwin
->w_topline
)
5629 - curwin
->w_topfill
;
5631 validate_botline(); /* make sure w_empty_rows is valid */
5632 half
= (curwin
->w_height
- curwin
->w_empty_rows
+ 1) / 2;
5633 for (n
= 0; curwin
->w_topline
+ n
< curbuf
->b_ml
.ml_line_count
; ++n
)
5636 /* Count half he number of filler lines to be "below this
5637 * line" and half to be "above the next line". */
5638 if (n
> 0 && used
+ diff_check_fill(curwin
, curwin
->w_topline
5645 used
+= plines(curwin
->w_topline
+ n
);
5649 if (hasFolding(curwin
->w_topline
+ n
, NULL
, &lnum
))
5650 n
= lnum
- curwin
->w_topline
;
5653 if (n
> 0 && used
> curwin
->w_height
)
5656 else /* (cap->cmdchar == 'H') */
5658 n
= cap
->count1
- 1;
5660 if (hasAnyFolding(curwin
))
5662 /* Count a fold for one screen line. */
5663 lnum
= curwin
->w_topline
;
5664 while (n
-- > 0 && lnum
< curwin
->w_botline
- 1)
5666 hasFolding(lnum
, NULL
, &lnum
);
5669 n
= lnum
- curwin
->w_topline
;
5673 curwin
->w_cursor
.lnum
= curwin
->w_topline
+ n
;
5674 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
5675 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
5678 cursor_correct(); /* correct for 'so' */
5679 beginline(BL_SOL
| BL_FIX
);
5683 * Cursor right commands.
5693 # define PAST_LINE 0
5696 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
5698 /* <C-Right> and <S-Right> move a word or WORD right */
5699 if (mod_mask
& MOD_MASK_CTRL
)
5705 cap
->oap
->motion_type
= MCHAR
;
5706 cap
->oap
->inclusive
= FALSE
;
5708 PAST_LINE
= (VIsual_active
&& *p_sel
!= 'o');
5710 # ifdef FEAT_VIRTUALEDIT
5712 * In virtual mode, there's no such thing as "PAST_LINE", as lines are
5713 * (theoretically) infinitely long.
5715 if (virtual_active())
5720 for (n
= cap
->count1
; n
> 0; --n
)
5722 if ((!PAST_LINE
&& oneright() == FAIL
)
5723 || (PAST_LINE
&& *ml_get_cursor() == NUL
))
5726 * <Space> wraps to next line if 'whichwrap' has 's'.
5727 * 'l' wraps to next line if 'whichwrap' has 'l'.
5728 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'.
5730 if ( ((cap
->cmdchar
== ' '
5731 && vim_strchr(p_ww
, 's') != NULL
)
5732 || (cap
->cmdchar
== 'l'
5733 && vim_strchr(p_ww
, 'l') != NULL
)
5734 || (cap
->cmdchar
== K_RIGHT
5735 && vim_strchr(p_ww
, '>') != NULL
))
5736 && curwin
->w_cursor
.lnum
< curbuf
->b_ml
.ml_line_count
)
5738 /* When deleting we also count the NL as a character.
5739 * Set cap->oap->inclusive when last char in the line is
5740 * included, move to next line after that */
5741 if ( cap
->oap
->op_type
!= OP_NOP
5742 && !cap
->oap
->inclusive
5743 && !lineempty(curwin
->w_cursor
.lnum
))
5744 cap
->oap
->inclusive
= TRUE
;
5747 ++curwin
->w_cursor
.lnum
;
5748 curwin
->w_cursor
.col
= 0;
5749 #ifdef FEAT_VIRTUALEDIT
5750 curwin
->w_cursor
.coladd
= 0;
5752 curwin
->w_set_curswant
= TRUE
;
5753 cap
->oap
->inclusive
= FALSE
;
5757 if (cap
->oap
->op_type
== OP_NOP
)
5759 /* Only beep and flush if not moved at all */
5760 if (n
== cap
->count1
)
5765 if (!lineempty(curwin
->w_cursor
.lnum
))
5766 cap
->oap
->inclusive
= TRUE
;
5773 curwin
->w_set_curswant
= TRUE
;
5774 # ifdef FEAT_VIRTUALEDIT
5775 if (virtual_active())
5782 curwin
->w_cursor
.col
+=
5783 (*mb_ptr2len
)(ml_get_cursor());
5786 ++curwin
->w_cursor
.col
;
5792 if (n
!= cap
->count1
&& (fdo_flags
& FDO_HOR
) && KeyTyped
5793 && cap
->oap
->op_type
== OP_NOP
)
5799 * Cursor left commands.
5801 * Returns TRUE when operator end should not be adjusted.
5809 if (mod_mask
& (MOD_MASK_SHIFT
| MOD_MASK_CTRL
))
5811 /* <C-Left> and <S-Left> move a word or WORD left */
5812 if (mod_mask
& MOD_MASK_CTRL
)
5818 cap
->oap
->motion_type
= MCHAR
;
5819 cap
->oap
->inclusive
= FALSE
;
5820 for (n
= cap
->count1
; n
> 0; --n
)
5822 if (oneleft() == FAIL
)
5824 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'.
5825 * 'h' wraps to previous line if 'whichwrap' has 'h'.
5826 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'.
5828 if ( (((cap
->cmdchar
== K_BS
5829 || cap
->cmdchar
== Ctrl_H
)
5830 && vim_strchr(p_ww
, 'b') != NULL
)
5831 || (cap
->cmdchar
== 'h'
5832 && vim_strchr(p_ww
, 'h') != NULL
)
5833 || (cap
->cmdchar
== K_LEFT
5834 && vim_strchr(p_ww
, '<') != NULL
))
5835 && curwin
->w_cursor
.lnum
> 1)
5837 --(curwin
->w_cursor
.lnum
);
5838 coladvance((colnr_T
)MAXCOL
);
5839 curwin
->w_set_curswant
= TRUE
;
5841 /* When the NL before the first char has to be deleted we
5842 * put the cursor on the NUL after the previous line.
5843 * This is a very special case, be careful!
5844 * don't adjust op_end now, otherwise it won't work */
5845 if ( (cap
->oap
->op_type
== OP_DELETE
5846 || cap
->oap
->op_type
== OP_CHANGE
)
5847 && !lineempty(curwin
->w_cursor
.lnum
))
5849 ++curwin
->w_cursor
.col
;
5850 cap
->retval
|= CA_NO_ADJ_OP_END
;
5854 /* Only beep and flush if not moved at all */
5855 else if (cap
->oap
->op_type
== OP_NOP
&& n
== cap
->count1
)
5861 if (n
!= cap
->count1
&& (fdo_flags
& FDO_HOR
) && KeyTyped
5862 && cap
->oap
->op_type
== OP_NOP
)
5868 * Cursor up commands.
5869 * cap->arg is TRUE for "-": Move cursor to first non-blank.
5875 if (mod_mask
& MOD_MASK_SHIFT
)
5877 /* <S-Up> is page up */
5878 cap
->arg
= BACKWARD
;
5883 cap
->oap
->motion_type
= MLINE
;
5884 if (cursor_up(cap
->count1
, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
5885 clearopbeep(cap
->oap
);
5887 beginline(BL_WHITE
| BL_FIX
);
5892 * Cursor down commands.
5893 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank.
5899 if (mod_mask
& MOD_MASK_SHIFT
)
5901 /* <S-Down> is page down */
5906 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
5907 /* In a quickfix window a <CR> jumps to the error under the cursor. */
5908 if (bt_quickfix(curbuf
) && cap
->cmdchar
== CAR
)
5909 if (curwin
->w_llist_ref
== NULL
)
5910 do_cmdline_cmd((char_u
*)".cc"); /* quickfix window */
5912 do_cmdline_cmd((char_u
*)".ll"); /* location list window */
5917 /* In the cmdline window a <CR> executes the command. */
5918 if (cmdwin_type
!= 0 && cap
->cmdchar
== CAR
)
5919 cmdwin_result
= CAR
;
5923 cap
->oap
->motion_type
= MLINE
;
5924 if (cursor_down(cap
->count1
, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
5925 clearopbeep(cap
->oap
);
5927 beginline(BL_WHITE
| BL_FIX
);
5932 #ifdef FEAT_SEARCHPATH
5934 * Grab the file name under the cursor and edit it.
5945 clearopbeep(cap
->oap
);
5950 if (curbuf_locked())
5957 ptr
= grab_file_name(cap
->count1
, &lnum
);
5961 /* do autowrite if necessary */
5962 if (curbufIsChanged() && curbuf
->b_nwindows
<= 1 && !P_HID(curbuf
))
5963 autowrite(curbuf
, FALSE
);
5965 (void)do_ecmd(0, ptr
, NULL
, NULL
, ECMD_LAST
,
5966 P_HID(curbuf
) ? ECMD_HIDE
: 0);
5967 if (cap
->nchar
== 'F' && lnum
>= 0)
5969 curwin
->w_cursor
.lnum
= lnum
;
5970 check_cursor_lnum();
5971 beginline(BL_SOL
| BL_FIX
);
5981 * <End> command: to end of current line or last line.
5987 if (cap
->arg
|| (mod_mask
& MOD_MASK_CTRL
)) /* CTRL-END = goto last line */
5991 cap
->count1
= 1; /* to end of current line */
5997 * Handle the "$" command.
6003 cap
->oap
->motion_type
= MCHAR
;
6004 cap
->oap
->inclusive
= TRUE
;
6005 #ifdef FEAT_VIRTUALEDIT
6006 /* In virtual mode when off the edge of a line and an operator
6007 * is pending (whew!) keep the cursor where it is.
6008 * Otherwise, send it to the end of the line. */
6009 if (!virtual_active() || gchar_cursor() != NUL
6010 || cap
->oap
->op_type
== OP_NOP
)
6012 curwin
->w_curswant
= MAXCOL
; /* so we stay at the end */
6013 if (cursor_down((long)(cap
->count1
- 1),
6014 cap
->oap
->op_type
== OP_NOP
) == FAIL
)
6015 clearopbeep(cap
->oap
);
6017 else if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6023 * Implementation of '?' and '/' commands.
6024 * If cap->arg is TRUE don't set PC mark.
6030 oparg_T
*oap
= cap
->oap
;
6032 if (cap
->cmdchar
== '?' && cap
->oap
->op_type
== OP_ROT13
)
6034 /* Translate "g??" to "g?g?" */
6041 cap
->searchbuf
= getcmdline(cap
->cmdchar
, cap
->count1
, 0);
6043 if (cap
->searchbuf
== NULL
)
6049 normal_search(cap
, cap
->cmdchar
, cap
->searchbuf
,
6050 (cap
->arg
? 0 : SEARCH_MARK
));
6054 * Handle "N" and "n" commands.
6055 * cap->arg is SEARCH_REV for "N", 0 for "n".
6061 normal_search(cap
, 0, NULL
, SEARCH_MARK
| cap
->arg
);
6065 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
6066 * Uses only cap->count1 and cap->oap from "cap".
6069 normal_search(cap
, dir
, pat
, opt
)
6073 int opt
; /* extra flags for do_search() */
6077 cap
->oap
->motion_type
= MCHAR
;
6078 cap
->oap
->inclusive
= FALSE
;
6079 cap
->oap
->use_reg_one
= TRUE
;
6080 curwin
->w_set_curswant
= TRUE
;
6082 i
= do_search(cap
->oap
, dir
, pat
, cap
->count1
,
6083 opt
| SEARCH_OPT
| SEARCH_ECHO
| SEARCH_MSG
);
6089 cap
->oap
->motion_type
= MLINE
;
6090 #ifdef FEAT_VIRTUALEDIT
6091 curwin
->w_cursor
.coladd
= 0;
6094 if (cap
->oap
->op_type
== OP_NOP
&& (fdo_flags
& FDO_SEARCH
) && KeyTyped
)
6099 /* "/$" will put the cursor after the end of the line, may need to
6100 * correct that here */
6105 * Character search commands.
6106 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for
6107 * ',' and FALSE for ';'.
6108 * cap->nchar is NUL for ',' and ';' (repeat the search)
6116 if (cap
->cmdchar
== 't' || cap
->cmdchar
== 'T')
6121 cap
->oap
->motion_type
= MCHAR
;
6122 if (IS_SPECIAL(cap
->nchar
) || searchc(cap
, t_cmd
) == FAIL
)
6123 clearopbeep(cap
->oap
);
6126 curwin
->w_set_curswant
= TRUE
;
6127 #ifdef FEAT_VIRTUALEDIT
6128 /* Include a Tab for "tx" and for "dfx". */
6129 if (gchar_cursor() == TAB
&& virtual_active() && cap
->arg
== FORWARD
6130 && (t_cmd
|| cap
->oap
->op_type
!= OP_NOP
))
6134 getvcol(curwin
, &curwin
->w_cursor
, &scol
, NULL
, &ecol
);
6135 curwin
->w_cursor
.coladd
= ecol
- scol
;
6138 curwin
->w_cursor
.coladd
= 0;
6141 adjust_for_sel(cap
);
6144 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6151 * "[" and "]" commands.
6152 * cap->arg is BACKWARD for "[" and FORWARD for "]".
6160 pos_T
*pos
= NULL
; /* init for GCC */
6161 pos_T old_pos
; /* cursor position before command */
6167 cap
->oap
->motion_type
= MCHAR
;
6168 cap
->oap
->inclusive
= FALSE
;
6169 old_pos
= curwin
->w_cursor
;
6170 #ifdef FEAT_VIRTUALEDIT
6171 curwin
->w_cursor
.coladd
= 0; /* TODO: don't do this for an error. */
6174 #ifdef FEAT_SEARCHPATH
6176 * "[f" or "]f" : Edit file under the cursor (same as "gf")
6178 if (cap
->nchar
== 'f')
6185 * Find the occurrence(s) of the identifier or define under cursor
6186 * in current and included files or jump to the first occurrence.
6189 * fwd bwd fwd bwd fwd bwd
6190 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
6191 * define "]d" "[d" "]D" "[D" "]^D" "[^D"
6193 if (vim_strchr((char_u
*)
6199 cap
->nchar
) != NULL
)
6204 if ((len
= find_ident_under_cursor(&ptr
, FIND_IDENT
)) == 0)
6208 find_pattern_in_path(ptr
, 0, len
, TRUE
,
6209 cap
->count0
== 0 ? !isupper(cap
->nchar
) : FALSE
,
6210 ((cap
->nchar
& 0xf) == ('d' & 0xf)) ? FIND_DEFINE
: FIND_ANY
,
6212 isupper(cap
->nchar
) ? ACTION_SHOW_ALL
:
6213 islower(cap
->nchar
) ? ACTION_SHOW
: ACTION_GOTO
,
6214 cap
->cmdchar
== ']' ? curwin
->w_cursor
.lnum
+ 1 : (linenr_T
)1,
6216 curwin
->w_set_curswant
= TRUE
;
6223 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')'
6224 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct.
6225 * "[/", "[*", "]/", "]*": go to Nth comment start/end.
6226 * "[m" or "]m" search for prev/next start of (Java) method.
6227 * "[M" or "]M" search for prev/next end of (Java) method.
6229 if ( (cap
->cmdchar
== '['
6230 && vim_strchr((char_u
*)"{(*/#mM", cap
->nchar
) != NULL
)
6231 || (cap
->cmdchar
== ']'
6232 && vim_strchr((char_u
*)"})*/#mM", cap
->nchar
) != NULL
))
6234 if (cap
->nchar
== '*')
6238 if (cap
->nchar
== 'm' || cap
->nchar
== 'M')
6240 if (cap
->cmdchar
== '[')
6253 if ((pos
= findmatchlimit(cap
->oap
, findc
,
6254 (cap
->cmdchar
== '[') ? FM_BACKWARD
: FM_FORWARD
, 0)) == NULL
)
6256 if (new_pos
.lnum
== 0) /* nothing found */
6258 if (cap
->nchar
!= 'm' && cap
->nchar
!= 'M')
6259 clearopbeep(cap
->oap
);
6262 pos
= &new_pos
; /* use last one found */
6266 curwin
->w_cursor
= *pos
;
6269 curwin
->w_cursor
= old_pos
;
6272 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only
6273 * brought us to the match for "[m" and "]M" when inside a method.
6274 * Try finding the '{' or '}' we want to be at.
6275 * Also repeat for the given count.
6277 if (cap
->nchar
== 'm' || cap
->nchar
== 'M')
6279 /* norm is TRUE for "]M" and "[m" */
6280 int norm
= ((findc
== '{') == (cap
->nchar
== 'm'));
6283 /* found a match: we were inside a method */
6284 if (prev_pos
.lnum
!= 0)
6287 curwin
->w_cursor
= prev_pos
;
6297 if ((findc
== '{' ? dec_cursor() : inc_cursor()) < 0)
6299 /* if not found anything, that's an error */
6301 clearopbeep(cap
->oap
);
6306 if (c
== '{' || c
== '}')
6308 /* Must have found end/start of class: use it.
6309 * Or found the place to be at. */
6310 if ((c
== findc
&& norm
) || (n
== 1 && !norm
))
6312 new_pos
= curwin
->w_cursor
;
6316 /* if no match found at all, we started outside of the
6317 * class and we're inside now. Just go on. */
6318 else if (new_pos
.lnum
== 0)
6320 new_pos
= curwin
->w_cursor
;
6323 /* found start/end of other method: go to match */
6324 else if ((pos
= findmatchlimit(cap
->oap
, findc
,
6325 (cap
->cmdchar
== '[') ? FM_BACKWARD
: FM_FORWARD
,
6329 curwin
->w_cursor
= *pos
;
6335 curwin
->w_cursor
= old_pos
;
6336 if (pos
== NULL
&& new_pos
.lnum
!= 0)
6337 clearopbeep(cap
->oap
);
6342 curwin
->w_cursor
= *pos
;
6343 curwin
->w_set_curswant
= TRUE
;
6345 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
6346 && cap
->oap
->op_type
== OP_NOP
)
6353 * "[[", "[]", "]]" and "][": move to start or end of function
6355 else if (cap
->nchar
== '[' || cap
->nchar
== ']')
6357 if (cap
->nchar
== cap
->cmdchar
) /* "]]" or "[[" */
6360 flag
= '}'; /* "][" or "[]" */
6362 curwin
->w_set_curswant
= TRUE
;
6364 * Imitate strange Vi behaviour: When using "]]" with an operator
6365 * we also stop at '}'.
6367 if (!findpar(&cap
->oap
->inclusive
, cap
->arg
, cap
->count1
, flag
,
6368 (cap
->oap
->op_type
!= OP_NOP
6369 && cap
->arg
== FORWARD
&& flag
== '{')))
6370 clearopbeep(cap
->oap
);
6373 if (cap
->oap
->op_type
== OP_NOP
)
6374 beginline(BL_WHITE
| BL_FIX
);
6376 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6383 * "[p", "[P", "]P" and "]p": put with indent adjustment
6385 else if (cap
->nchar
== 'p' || cap
->nchar
== 'P')
6387 if (!checkclearop(cap
->oap
))
6390 do_put(cap
->oap
->regname
,
6391 (cap
->cmdchar
== ']' && cap
->nchar
== 'p') ? FORWARD
: BACKWARD
,
6392 cap
->count1
, PUT_FIXINDENT
);
6397 * "['", "[`", "]'" and "]`": jump to next mark
6399 else if (cap
->nchar
== '\'' || cap
->nchar
== '`')
6401 pos
= &curwin
->w_cursor
;
6402 for (n
= cap
->count1
; n
> 0; --n
)
6405 pos
= getnextmark(pos
, cap
->cmdchar
== '[' ? BACKWARD
: FORWARD
,
6406 cap
->nchar
== '\'');
6412 nv_cursormark(cap
, cap
->nchar
== '\'', pos
);
6417 * [ or ] followed by a middle mouse click: put selected text with
6418 * indent adjustment. Any other button just does as usual.
6420 else if (cap
->nchar
>= K_LEFTMOUSE
&& cap
->nchar
<= K_RIGHTRELEASE
)
6422 (void)do_mouse(cap
->oap
, cap
->nchar
,
6423 (cap
->cmdchar
== ']') ? FORWARD
: BACKWARD
,
6424 cap
->count1
, PUT_FIXINDENT
);
6426 #endif /* FEAT_MOUSE */
6430 * "[z" and "]z": move to start or end of open fold.
6432 else if (cap
->nchar
== 'z')
6434 if (foldMoveTo(FALSE
, cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6435 cap
->count1
) == FAIL
)
6436 clearopbeep(cap
->oap
);
6442 * "[c" and "]c": move to next or previous diff-change.
6444 else if (cap
->nchar
== 'c')
6446 if (diff_move_to(cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6447 cap
->count1
) == FAIL
)
6448 clearopbeep(cap
->oap
);
6454 * "[s", "[S", "]s" and "]S": move to next spell error.
6456 else if (cap
->nchar
== 's' || cap
->nchar
== 'S')
6459 for (n
= 0; n
< cap
->count1
; ++n
)
6460 if (spell_move_to(curwin
, cap
->cmdchar
== ']' ? FORWARD
: BACKWARD
,
6461 cap
->nchar
== 's' ? TRUE
: FALSE
, FALSE
, NULL
) == 0)
6463 clearopbeep(cap
->oap
);
6466 # ifdef FEAT_FOLDING
6467 if (cap
->oap
->op_type
== OP_NOP
&& (fdo_flags
& FDO_SEARCH
) && KeyTyped
)
6473 /* Not a valid cap->nchar. */
6475 clearopbeep(cap
->oap
);
6479 * Handle Normal mode "%" command.
6487 linenr_T lnum
= curwin
->w_cursor
.lnum
;
6490 cap
->oap
->inclusive
= TRUE
;
6491 if (cap
->count0
) /* {cnt}% : goto {cnt} percentage in file */
6493 if (cap
->count0
> 100)
6494 clearopbeep(cap
->oap
);
6497 cap
->oap
->motion_type
= MLINE
;
6499 /* Round up, so CTRL-G will give same value. Watch out for a
6500 * large line count, the line number must not go negative! */
6501 if (curbuf
->b_ml
.ml_line_count
> 1000000)
6502 curwin
->w_cursor
.lnum
= (curbuf
->b_ml
.ml_line_count
+ 99L)
6503 / 100L * cap
->count0
;
6505 curwin
->w_cursor
.lnum
= (curbuf
->b_ml
.ml_line_count
*
6506 cap
->count0
+ 99L) / 100L;
6507 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
6508 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
6509 beginline(BL_SOL
| BL_FIX
);
6512 else /* "%" : go to matching paren */
6514 cap
->oap
->motion_type
= MCHAR
;
6515 cap
->oap
->use_reg_one
= TRUE
;
6516 if ((pos
= findmatch(cap
->oap
, NUL
)) == NULL
)
6517 clearopbeep(cap
->oap
);
6521 curwin
->w_cursor
= *pos
;
6522 curwin
->w_set_curswant
= TRUE
;
6523 #ifdef FEAT_VIRTUALEDIT
6524 curwin
->w_cursor
.coladd
= 0;
6527 adjust_for_sel(cap
);
6532 if (cap
->oap
->op_type
== OP_NOP
6533 && lnum
!= curwin
->w_cursor
.lnum
6534 && (fdo_flags
& FDO_PERCENT
)
6541 * Handle "(" and ")" commands.
6542 * cap->arg is BACKWARD for "(" and FORWARD for ")".
6548 cap
->oap
->motion_type
= MCHAR
;
6549 cap
->oap
->use_reg_one
= TRUE
;
6550 /* The motion used to be inclusive for "(", but that is not what Vi does. */
6551 cap
->oap
->inclusive
= FALSE
;
6552 curwin
->w_set_curswant
= TRUE
;
6554 if (findsent(cap
->arg
, cap
->count1
) == FAIL
)
6555 clearopbeep(cap
->oap
);
6558 #ifdef FEAT_VIRTUALEDIT
6559 curwin
->w_cursor
.coladd
= 0;
6562 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6569 * "m" command: Mark a position.
6575 if (!checkclearop(cap
->oap
))
6577 if (setmark(cap
->nchar
) == FAIL
)
6578 clearopbeep(cap
->oap
);
6583 * "{" and "}" commands.
6584 * cmd->arg is BACKWARD for "{" and FORWARD for "}".
6590 cap
->oap
->motion_type
= MCHAR
;
6591 cap
->oap
->inclusive
= FALSE
;
6592 cap
->oap
->use_reg_one
= TRUE
;
6593 curwin
->w_set_curswant
= TRUE
;
6594 if (!findpar(&cap
->oap
->inclusive
, cap
->arg
, cap
->count1
, NUL
, FALSE
))
6595 clearopbeep(cap
->oap
);
6598 #ifdef FEAT_VIRTUALEDIT
6599 curwin
->w_cursor
.coladd
= 0;
6602 if ((fdo_flags
& FDO_BLOCK
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
6609 * "u" command: Undo or make lower case.
6615 if (cap
->oap
->op_type
== OP_LOWER
6621 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */
6637 if (!checkclearopq(cap
->oap
))
6639 u_undo((int)cap
->count1
);
6640 curwin
->w_set_curswant
= TRUE
;
6645 * Handle the "r" command.
6655 if (checkclearop(cap
->oap
))
6658 /* get another character */
6659 if (cap
->nchar
== Ctrl_V
)
6661 had_ctrl_v
= Ctrl_V
;
6662 cap
->nchar
= get_literal();
6663 /* Don't redo a multibyte character with CTRL-V. */
6664 if (cap
->nchar
> DEL
)
6670 /* Abort if the character is a special key. */
6671 if (IS_SPECIAL(cap
->nchar
))
6673 clearopbeep(cap
->oap
);
6678 /* Visual mode "r" */
6686 #ifdef FEAT_VIRTUALEDIT
6687 /* Break tabs, etc. */
6688 if (virtual_active())
6690 if (u_save_cursor() == FAIL
)
6692 if (gchar_cursor() == NUL
)
6694 /* Add extra space and put the cursor on the first one. */
6695 coladvance_force((colnr_T
)(getviscol() + cap
->count1
));
6696 curwin
->w_cursor
.col
-= cap
->count1
;
6698 else if (gchar_cursor() == TAB
)
6699 coladvance_force(getviscol());
6703 /* Abort if not enough characters to replace. */
6704 ptr
= ml_get_cursor();
6705 if (STRLEN(ptr
) < (unsigned)cap
->count1
6707 || (has_mbyte
&& mb_charlen(ptr
) < cap
->count1
)
6711 clearopbeep(cap
->oap
);
6716 * Replacing with a TAB is done by edit() when it is complicated because
6717 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB.
6718 * Other characters are done below to avoid problems with things like
6719 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC).
6721 if (had_ctrl_v
!= Ctrl_V
&& cap
->nchar
== '\t' && (curbuf
->b_p_et
|| p_sta
))
6723 stuffnumReadbuff(cap
->count1
);
6724 stuffcharReadbuff('R');
6725 stuffcharReadbuff('\t');
6726 stuffcharReadbuff(ESC
);
6730 /* save line for undo */
6731 if (u_save_cursor() == FAIL
)
6734 if (had_ctrl_v
!= Ctrl_V
&& (cap
->nchar
== '\r' || cap
->nchar
== '\n'))
6737 * Replace character(s) by a single newline.
6738 * Strange vi behaviour: Only one newline is inserted.
6739 * Delete the characters here.
6740 * Insert the newline with an insert command, takes care of
6741 * autoindent. The insert command depends on being on the last
6742 * character of a line or not.
6745 (void)del_chars(cap
->count1
, FALSE
); /* delete the characters */
6747 (void)del_bytes(cap
->count1
, FALSE
, FALSE
); /* delete the characters */
6749 stuffcharReadbuff('\r');
6750 stuffcharReadbuff(ESC
);
6752 /* Give 'r' to edit(), to get the redo command right. */
6753 invoke_edit(cap
, TRUE
, 'r', FALSE
);
6757 prep_redo(cap
->oap
->regname
, cap
->count1
,
6758 NUL
, 'r', NUL
, had_ctrl_v
, cap
->nchar
);
6760 curbuf
->b_op_start
= curwin
->w_cursor
;
6764 int old_State
= State
;
6766 if (cap
->ncharC1
!= 0)
6767 AppendCharToRedobuff(cap
->ncharC1
);
6768 if (cap
->ncharC2
!= 0)
6769 AppendCharToRedobuff(cap
->ncharC2
);
6771 /* This is slow, but it handles replacing a single-byte with a
6772 * multi-byte and the other way around. Also handles adding
6773 * composing characters for utf-8. */
6774 for (n
= cap
->count1
; n
> 0; --n
)
6777 ins_char(cap
->nchar
);
6779 if (cap
->ncharC1
!= 0)
6780 ins_char(cap
->ncharC1
);
6781 if (cap
->ncharC2
!= 0)
6782 ins_char(cap
->ncharC2
);
6789 * Replace the characters within one line.
6791 for (n
= cap
->count1
; n
> 0; --n
)
6794 * Get ptr again, because u_save and/or showmatch() will have
6795 * released the line. At the same time we let know that the
6796 * line will be changed.
6798 ptr
= ml_get_buf(curbuf
, curwin
->w_cursor
.lnum
, TRUE
);
6799 ptr
[curwin
->w_cursor
.col
] = cap
->nchar
;
6800 if (p_sm
&& msg_silent
== 0)
6801 showmatch(cap
->nchar
);
6802 ++curwin
->w_cursor
.col
;
6804 #ifdef FEAT_NETBEANS_INTG
6807 colnr_T start
= (colnr_T
)(curwin
->w_cursor
.col
- cap
->count1
);
6809 netbeans_removed(curbuf
, curwin
->w_cursor
.lnum
, start
,
6811 netbeans_inserted(curbuf
, curwin
->w_cursor
.lnum
, start
,
6812 &ptr
[start
], (int)cap
->count1
);
6816 /* mark the buffer as changed and prepare for displaying */
6817 changed_bytes(curwin
->w_cursor
.lnum
,
6818 (colnr_T
)(curwin
->w_cursor
.col
- cap
->count1
));
6820 --curwin
->w_cursor
.col
; /* cursor on the last replaced char */
6822 /* if the character on the left of the current cursor is a multi-byte
6823 * character, move two characters left */
6827 curbuf
->b_op_end
= curwin
->w_cursor
;
6828 curwin
->w_set_curswant
= TRUE
;
6829 set_last_insert(cap
->nchar
);
6835 * 'o': Exchange start and end of Visual area.
6836 * 'O': same, but in block mode exchange left and right corners.
6839 v_swap_corners(cmdchar
)
6843 colnr_T left
, right
;
6845 if (cmdchar
== 'O' && VIsual_mode
== Ctrl_V
)
6847 old_cursor
= curwin
->w_cursor
;
6848 getvcols(curwin
, &old_cursor
, &VIsual
, &left
, &right
);
6849 curwin
->w_cursor
.lnum
= VIsual
.lnum
;
6851 VIsual
= curwin
->w_cursor
;
6853 curwin
->w_cursor
.lnum
= old_cursor
.lnum
;
6854 curwin
->w_curswant
= right
;
6855 /* 'selection "exclusive" and cursor at right-bottom corner: move it
6856 * right one column */
6857 if (old_cursor
.lnum
>= VIsual
.lnum
&& *p_sel
== 'e')
6858 ++curwin
->w_curswant
;
6859 coladvance(curwin
->w_curswant
);
6860 if (curwin
->w_cursor
.col
== old_cursor
.col
6861 #ifdef FEAT_VIRTUALEDIT
6862 && (!virtual_active()
6863 || curwin
->w_cursor
.coladd
== old_cursor
.coladd
)
6867 curwin
->w_cursor
.lnum
= VIsual
.lnum
;
6868 if (old_cursor
.lnum
<= VIsual
.lnum
&& *p_sel
== 'e')
6871 VIsual
= curwin
->w_cursor
;
6873 curwin
->w_cursor
.lnum
= old_cursor
.lnum
;
6875 curwin
->w_curswant
= left
;
6880 old_cursor
= curwin
->w_cursor
;
6881 curwin
->w_cursor
= VIsual
;
6882 VIsual
= old_cursor
;
6883 curwin
->w_set_curswant
= TRUE
;
6886 #endif /* FEAT_VISUAL */
6889 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE).
6896 if (VIsual_active
) /* "R" is replace lines */
6905 if (!checkclearopq(cap
->oap
))
6907 if (!curbuf
->b_p_ma
)
6908 EMSG(_(e_modifiable
));
6911 #ifdef FEAT_VIRTUALEDIT
6912 if (virtual_active())
6913 coladvance(getviscol());
6915 invoke_edit(cap
, FALSE
, cap
->arg
? 'V' : 'R', FALSE
);
6920 #ifdef FEAT_VREPLACE
6932 cap
->nchar
= cap
->extra_char
;
6933 nv_replace(cap
); /* Do same as "r" in Visual mode for now */
6937 if (!checkclearopq(cap
->oap
))
6939 if (!curbuf
->b_p_ma
)
6940 EMSG(_(e_modifiable
));
6943 if (cap
->extra_char
== Ctrl_V
) /* get another character */
6944 cap
->extra_char
= get_literal();
6945 stuffcharReadbuff(cap
->extra_char
);
6946 stuffcharReadbuff(ESC
);
6947 # ifdef FEAT_VIRTUALEDIT
6948 if (virtual_active())
6949 coladvance(getviscol());
6951 invoke_edit(cap
, TRUE
, 'v', FALSE
);
6958 * Swap case for "~" command, when it does not work like an operator.
6967 #ifdef FEAT_NETBEANS_INTG
6973 if (checkclearopq(cap
->oap
))
6976 if (lineempty(curwin
->w_cursor
.lnum
) && vim_strchr(p_ww
, '~') == NULL
)
6978 clearopbeep(cap
->oap
);
6984 if (u_save_cursor() == FAIL
)
6987 startpos
= curwin
->w_cursor
;
6988 #ifdef FEAT_NETBEANS_INTG
6991 for (n
= cap
->count1
; n
> 0; --n
)
6993 did_change
|= swapchar(cap
->oap
->op_type
, &curwin
->w_cursor
);
6995 if (gchar_cursor() == NUL
)
6997 if (vim_strchr(p_ww
, '~') != NULL
6998 && curwin
->w_cursor
.lnum
< curbuf
->b_ml
.ml_line_count
)
7000 #ifdef FEAT_NETBEANS_INTG
7005 ptr
= ml_get(pos
.lnum
);
7006 count
= (int)STRLEN(ptr
) - pos
.col
;
7007 netbeans_removed(curbuf
, pos
.lnum
, pos
.col
,
7009 netbeans_inserted(curbuf
, pos
.lnum
, pos
.col
,
7010 &ptr
[pos
.col
], count
);
7016 ++curwin
->w_cursor
.lnum
;
7017 curwin
->w_cursor
.col
= 0;
7020 if (u_savesub(curwin
->w_cursor
.lnum
) == FAIL
)
7029 #ifdef FEAT_NETBEANS_INTG
7030 if (did_change
&& usingNetbeans
)
7032 ptr
= ml_get(pos
.lnum
);
7033 count
= curwin
->w_cursor
.col
- pos
.col
;
7034 netbeans_removed(curbuf
, pos
.lnum
, pos
.col
, (long)count
);
7035 netbeans_inserted(curbuf
, pos
.lnum
, pos
.col
, &ptr
[pos
.col
], count
);
7041 curwin
->w_set_curswant
= TRUE
;
7044 changed_lines(startpos
.lnum
, startpos
.col
, curwin
->w_cursor
.lnum
+ 1,
7046 curbuf
->b_op_start
= startpos
;
7047 curbuf
->b_op_end
= curwin
->w_cursor
;
7048 if (curbuf
->b_op_end
.col
> 0)
7049 --curbuf
->b_op_end
.col
;
7054 * Move cursor to mark.
7057 nv_cursormark(cap
, flag
, pos
)
7062 if (check_mark(pos
) == FAIL
)
7066 if (cap
->cmdchar
== '\''
7067 || cap
->cmdchar
== '`'
7068 || cap
->cmdchar
== '['
7069 || cap
->cmdchar
== ']')
7071 curwin
->w_cursor
= *pos
;
7073 beginline(BL_WHITE
| BL_FIX
);
7077 cap
->oap
->motion_type
= flag
? MLINE
: MCHAR
;
7078 if (cap
->cmdchar
== '`')
7079 cap
->oap
->use_reg_one
= TRUE
;
7080 cap
->oap
->inclusive
= FALSE
; /* ignored if not MCHAR */
7081 curwin
->w_set_curswant
= TRUE
;
7086 * Handle commands that are operators in Visual mode.
7092 static char_u trans
[] = "YyDdCcxdXdAAIIrr";
7094 /* Uppercase means linewise, except in block mode, then "D" deletes till
7095 * the end of the line, and "C" replaces til EOL */
7096 if (isupper(cap
->cmdchar
))
7098 if (VIsual_mode
!= Ctrl_V
)
7100 else if (cap
->cmdchar
== 'C' || cap
->cmdchar
== 'D')
7101 curwin
->w_curswant
= MAXCOL
;
7103 cap
->cmdchar
= *(vim_strchr(trans
, cap
->cmdchar
) + 1);
7109 * "s" and "S" commands.
7116 if (VIsual_active
) /* "vs" and "vS" are the same as "vc" */
7118 if (cap
->cmdchar
== 'S')
7129 * Abbreviated commands.
7135 if (cap
->cmdchar
== K_DEL
|| cap
->cmdchar
== K_KDEL
)
7136 cap
->cmdchar
= 'x'; /* DEL key behaves like 'x' */
7139 /* in Visual mode these commands are operators */
7148 * Translate a command into another command.
7154 static char_u
*(ar
[8]) = {(char_u
*)"dl", (char_u
*)"dh",
7155 (char_u
*)"d$", (char_u
*)"c$",
7156 (char_u
*)"cl", (char_u
*)"cc",
7157 (char_u
*)"yy", (char_u
*)":s\r"};
7158 static char_u
*str
= (char_u
*)"xXDCsSY&";
7160 if (!checkclearopq(cap
->oap
))
7162 /* In Vi "2D" doesn't delete the next line. Can't translate it
7163 * either, because "2." should also not use the count. */
7164 if (cap
->cmdchar
== 'D' && vim_strchr(p_cpo
, CPO_HASH
) != NULL
)
7166 cap
->oap
->start
= curwin
->w_cursor
;
7167 cap
->oap
->op_type
= OP_DELETE
;
7172 AppendCharToRedobuff('D');
7177 stuffnumReadbuff(cap
->count0
);
7178 stuffReadbuff(ar
[(int)(vim_strchr(str
, cap
->cmdchar
) - str
)]);
7185 * "'" and "`" commands. Also for "g'" and "g`".
7186 * cap->arg is TRUE for "'" and "g'".
7195 linenr_T lnum
= curwin
->w_cursor
.lnum
;
7196 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
7199 if (cap
->cmdchar
== 'g')
7200 c
= cap
->extra_char
;
7203 pos
= getmark(c
, (cap
->oap
->op_type
== OP_NOP
));
7204 if (pos
== (pos_T
*)-1) /* jumped to other file */
7208 check_cursor_lnum();
7209 beginline(BL_WHITE
| BL_FIX
);
7215 nv_cursormark(cap
, cap
->arg
, pos
);
7217 #ifdef FEAT_VIRTUALEDIT
7218 /* May need to clear the coladd that a mark includes. */
7219 if (!virtual_active())
7220 curwin
->w_cursor
.coladd
= 0;
7223 if (cap
->oap
->op_type
== OP_NOP
7224 && (pos
== (pos_T
*)-1 || lnum
!= curwin
->w_cursor
.lnum
)
7225 && (fdo_flags
& FDO_MARK
)
7232 * Handle CTRL-O, CTRL-I, "g;" and "g," commands.
7238 #ifdef FEAT_JUMPLIST
7240 # ifdef FEAT_FOLDING
7241 linenr_T lnum
= curwin
->w_cursor
.lnum
;
7242 int old_KeyTyped
= KeyTyped
; /* getting file may reset it */
7245 if (!checkclearopq(cap
->oap
))
7247 if (cap
->cmdchar
== 'g')
7248 pos
= movechangelist((int)cap
->count1
);
7250 pos
= movemark((int)cap
->count1
);
7251 if (pos
== (pos_T
*)-1) /* jump to other file */
7253 curwin
->w_set_curswant
= TRUE
;
7256 else if (pos
!= NULL
) /* can jump */
7257 nv_cursormark(cap
, FALSE
, pos
);
7258 else if (cap
->cmdchar
== 'g')
7260 if (curbuf
->b_changelistlen
== 0)
7261 EMSG(_("E664: changelist is empty"));
7262 else if (cap
->count1
< 0)
7263 EMSG(_("E662: At start of changelist"));
7265 EMSG(_("E663: At end of changelist"));
7268 clearopbeep(cap
->oap
);
7269 # ifdef FEAT_FOLDING
7270 if (cap
->oap
->op_type
== OP_NOP
7271 && (pos
== (pos_T
*)-1 || lnum
!= curwin
->w_cursor
.lnum
)
7272 && (fdo_flags
& FDO_MARK
)
7278 clearopbeep(cap
->oap
);
7283 * Handle '"' command.
7289 if (checkclearop(cap
->oap
))
7292 if (cap
->nchar
== '=')
7293 cap
->nchar
= get_expr_register();
7295 if (cap
->nchar
!= NUL
&& valid_yank_reg(cap
->nchar
, FALSE
))
7297 cap
->oap
->regname
= cap
->nchar
;
7298 cap
->opcount
= cap
->count0
; /* remember count before '"' */
7300 set_reg_var(cap
->oap
->regname
);
7304 clearopbeep(cap
->oap
);
7309 * Handle "v", "V" and "CTRL-V" commands.
7310 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg
7312 * Handle CTRL-Q just like CTRL-V.
7318 if (cap
->cmdchar
== Ctrl_Q
)
7319 cap
->cmdchar
= Ctrl_V
;
7321 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it
7322 * characterwise, linewise, or blockwise. */
7323 if (cap
->oap
->op_type
!= OP_NOP
)
7325 cap
->oap
->motion_force
= cap
->cmdchar
;
7326 finish_op
= FALSE
; /* operator doesn't finish now but later */
7330 VIsual_select
= cap
->arg
;
7331 if (VIsual_active
) /* change Visual mode */
7333 if (VIsual_mode
== cap
->cmdchar
) /* stop visual mode */
7335 else /* toggle char/block mode */
7336 { /* or char/line mode */
7337 VIsual_mode
= cap
->cmdchar
;
7340 redraw_curbuf_later(INVERTED
); /* update the inversion */
7342 else /* start Visual mode */
7344 check_visual_highlight();
7345 if (cap
->count0
) /* use previously selected part */
7347 if (resel_VIsual_mode
== NUL
) /* there is none */
7352 VIsual
= curwin
->w_cursor
;
7354 VIsual_active
= TRUE
;
7355 VIsual_reselect
= TRUE
;
7357 /* start Select mode when 'selectmode' contains "cmd" */
7358 may_start_select('c');
7362 if (p_smd
&& msg_silent
== 0)
7363 redraw_cmdline
= TRUE
; /* show visual mode later */
7365 * For V and ^V, we multiply the number of lines even if there
7366 * was only one -- webb
7368 if (resel_VIsual_mode
!= 'v' || resel_VIsual_line_count
> 1)
7370 curwin
->w_cursor
.lnum
+=
7371 resel_VIsual_line_count
* cap
->count0
- 1;
7372 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
7373 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
7375 VIsual_mode
= resel_VIsual_mode
;
7376 if (VIsual_mode
== 'v')
7378 if (resel_VIsual_line_count
<= 1)
7379 curwin
->w_cursor
.col
+= resel_VIsual_col
* cap
->count0
- 1;
7381 curwin
->w_cursor
.col
= resel_VIsual_col
;
7384 if (resel_VIsual_col
== MAXCOL
)
7386 curwin
->w_curswant
= MAXCOL
;
7387 coladvance((colnr_T
)MAXCOL
);
7389 else if (VIsual_mode
== Ctrl_V
)
7392 curwin
->w_curswant
= curwin
->w_virtcol
7393 + resel_VIsual_col
* cap
->count0
- 1;
7394 coladvance(curwin
->w_curswant
);
7397 curwin
->w_set_curswant
= TRUE
;
7398 redraw_curbuf_later(INVERTED
); /* show the inversion */
7403 /* start Select mode when 'selectmode' contains "cmd" */
7404 may_start_select('c');
7405 n_start_visual_mode(cap
->cmdchar
);
7411 * Start selection for Shift-movement keys.
7416 /* if 'selectmode' contains "key", start Select mode */
7417 may_start_select('k');
7418 n_start_visual_mode('v');
7422 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu.
7428 VIsual_select
= (stuff_empty() && typebuf_typed()
7429 && (vim_strchr(p_slm
, c
) != NULL
));
7433 * Start Visual mode "c".
7434 * Should set VIsual_select before calling this.
7437 n_start_visual_mode(c
)
7441 VIsual_active
= TRUE
;
7442 VIsual_reselect
= TRUE
;
7443 #ifdef FEAT_VIRTUALEDIT
7444 /* Corner case: the 0 position in a tab may change when going into
7445 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting.
7447 if (c
== Ctrl_V
&& (ve_flags
& VE_BLOCK
) && gchar_cursor() == TAB
)
7448 coladvance(curwin
->w_virtcol
);
7450 VIsual
= curwin
->w_cursor
;
7459 if (p_smd
&& msg_silent
== 0)
7460 redraw_cmdline
= TRUE
; /* show visual mode later */
7461 #ifdef FEAT_CLIPBOARD
7462 /* Make sure the clipboard gets updated. Needed because start and
7463 * end may still be the same, and the selection needs to be owned */
7464 clip_star
.vmode
= NUL
;
7467 /* Only need to redraw this line, unless still need to redraw an old
7468 * Visual area (when 'lazyredraw' is set). */
7469 if (curwin
->w_redr_type
< INVERTED
)
7471 curwin
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
7472 curwin
->w_old_visual_lnum
= curwin
->w_cursor
.lnum
;
7476 #endif /* FEAT_VISUAL */
7479 * CTRL-W: Window commands
7486 if (!checkclearop(cap
->oap
))
7487 do_window(cap
->nchar
, cap
->count0
, NUL
); /* everything is in window.c */
7489 (void)checkclearop(cap
->oap
);
7503 end_visual_mode(); /* stop Visual mode */
7505 do_cmdline_cmd((char_u
*)"st");
7509 * Commands starting with "g".
7515 oparg_T
*oap
= cap
->oap
;
7526 * "g^A": dump log of used memory.
7529 vim_mem_profile_dump();
7533 #ifdef FEAT_VREPLACE
7535 * "gR": Enter virtual replace mode.
7548 do_cmdline_cmd((char_u
*)"%s//~/&");
7553 * "gv": Reselect the previous Visual area. If Visual already active,
7554 * exchange previous and current Visual area.
7557 if (checkclearop(oap
))
7560 if ( curbuf
->b_visual
.vi_start
.lnum
== 0
7561 || curbuf
->b_visual
.vi_start
.lnum
> curbuf
->b_ml
.ml_line_count
7562 || curbuf
->b_visual
.vi_end
.lnum
== 0)
7566 /* set w_cursor to the start of the Visual area, tpos to the end */
7570 VIsual_mode
= curbuf
->b_visual
.vi_mode
;
7571 curbuf
->b_visual
.vi_mode
= i
;
7573 curbuf
->b_visual_mode_eval
= i
;
7575 i
= curwin
->w_curswant
;
7576 curwin
->w_curswant
= curbuf
->b_visual
.vi_curswant
;
7577 curbuf
->b_visual
.vi_curswant
= i
;
7579 tpos
= curbuf
->b_visual
.vi_end
;
7580 curbuf
->b_visual
.vi_end
= curwin
->w_cursor
;
7581 curwin
->w_cursor
= curbuf
->b_visual
.vi_start
;
7582 curbuf
->b_visual
.vi_start
= VIsual
;
7586 VIsual_mode
= curbuf
->b_visual
.vi_mode
;
7587 curwin
->w_curswant
= curbuf
->b_visual
.vi_curswant
;
7588 tpos
= curbuf
->b_visual
.vi_end
;
7589 curwin
->w_cursor
= curbuf
->b_visual
.vi_start
;
7592 VIsual_active
= TRUE
;
7593 VIsual_reselect
= TRUE
;
7595 /* Set Visual to the start and w_cursor to the end of the Visual
7596 * area. Make sure they are on an existing character. */
7598 VIsual
= curwin
->w_cursor
;
7599 curwin
->w_cursor
= tpos
;
7603 * When called from normal "g" command: start Select mode when
7604 * 'selectmode' contains "cmd". When called for K_SELECT, always
7605 * start Select mode.
7608 VIsual_select
= TRUE
;
7610 may_start_select('c');
7614 #ifdef FEAT_CLIPBOARD
7615 /* Make sure the clipboard gets updated. Needed because start and
7616 * end are still the same, and the selection needs to be owned */
7617 clip_star
.vmode
= NUL
;
7619 redraw_curbuf_later(INVERTED
);
7624 * "gV": Don't reselect the previous Visual area after a Select mode
7628 VIsual_reselect
= FALSE
;
7632 * "gh": start Select mode.
7633 * "gH": start Select line mode.
7634 * "g^H": start Select block mode.
7637 cap
->nchar
= Ctrl_H
;
7643 /* EBCDIC: 'v'-'h' != '^v'-'^h' */
7644 if (cap
->nchar
== Ctrl_H
)
7645 cap
->cmdchar
= Ctrl_V
;
7648 cap
->cmdchar
= cap
->nchar
+ ('v' - 'h');
7652 #endif /* FEAT_VISUAL */
7655 * "gj" and "gk" two new funny movement keys -- up and down
7656 * movement based on *screen* line rather than *file* line.
7660 /* with 'nowrap' it works just like the normal "j" command; also when
7661 * in a closed fold */
7662 if (!curwin
->w_p_wrap
7664 || hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
)
7668 oap
->motion_type
= MLINE
;
7669 i
= cursor_down(cap
->count1
, oap
->op_type
== OP_NOP
);
7672 i
= nv_screengo(oap
, FORWARD
, cap
->count1
);
7679 /* with 'nowrap' it works just like the normal "k" command; also when
7680 * in a closed fold */
7681 if (!curwin
->w_p_wrap
7683 || hasFolding(curwin
->w_cursor
.lnum
, NULL
, NULL
)
7687 oap
->motion_type
= MLINE
;
7688 i
= cursor_up(cap
->count1
, oap
->op_type
== OP_NOP
);
7691 i
= nv_screengo(oap
, BACKWARD
, cap
->count1
);
7697 * "gJ": join two lines without inserting a space.
7704 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines.
7705 * "gm": middle of "g0" and "g$".
7715 oap
->motion_type
= MCHAR
;
7716 oap
->inclusive
= FALSE
;
7717 if (curwin
->w_p_wrap
7718 #ifdef FEAT_VERTSPLIT
7719 && curwin
->w_width
!= 0
7723 int width1
= W_WIDTH(curwin
) - curwin_col_off();
7724 int width2
= width1
+ curwin_col_off2();
7728 if (curwin
->w_virtcol
>= (colnr_T
)width1
&& width2
> 0)
7729 i
= (curwin
->w_virtcol
- width1
) / width2
* width2
+ width1
;
7732 i
= curwin
->w_leftcol
;
7733 /* Go to the middle of the screen line. When 'number' is on and lines
7734 * are wrapping the middle can be more to the left.*/
7735 if (cap
->nchar
== 'm')
7736 i
+= (W_WIDTH(curwin
) - curwin_col_off()
7737 + ((curwin
->w_p_wrap
&& i
> 0)
7738 ? curwin_col_off2() : 0)) / 2;
7739 coladvance((colnr_T
)i
);
7744 while (vim_iswhite(i
) && oneright() == OK
);
7746 curwin
->w_set_curswant
= TRUE
;
7750 /* "g_": to the last non-blank character in the line or <count> lines
7752 cap
->oap
->motion_type
= MCHAR
;
7753 cap
->oap
->inclusive
= TRUE
;
7754 curwin
->w_curswant
= MAXCOL
;
7755 if (cursor_down((long)(cap
->count1
- 1),
7756 cap
->oap
->op_type
== OP_NOP
) == FAIL
)
7757 clearopbeep(cap
->oap
);
7760 char_u
*ptr
= ml_get_curline();
7762 /* In Visual mode we may end up after the line. */
7763 if (curwin
->w_cursor
.col
> 0 && ptr
[curwin
->w_cursor
.col
] == NUL
)
7764 --curwin
->w_cursor
.col
;
7766 /* Decrease the cursor column until it's on a non-blank. */
7767 while (curwin
->w_cursor
.col
> 0
7768 && vim_iswhite(ptr
[curwin
->w_cursor
.col
]))
7769 --curwin
->w_cursor
.col
;
7770 curwin
->w_set_curswant
= TRUE
;
7778 int col_off
= curwin_col_off();
7780 oap
->motion_type
= MCHAR
;
7781 oap
->inclusive
= TRUE
;
7782 if (curwin
->w_p_wrap
7783 #ifdef FEAT_VERTSPLIT
7784 && curwin
->w_width
!= 0
7788 curwin
->w_curswant
= MAXCOL
; /* so we stay at the end */
7789 if (cap
->count1
== 1)
7791 int width1
= W_WIDTH(curwin
) - col_off
;
7792 int width2
= width1
+ curwin_col_off2();
7796 if (curwin
->w_virtcol
>= (colnr_T
)width1
)
7797 i
+= ((curwin
->w_virtcol
- width1
) / width2
+ 1)
7799 coladvance((colnr_T
)i
);
7800 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
7801 if (curwin
->w_cursor
.col
> 0 && curwin
->w_p_wrap
)
7804 * Check for landing on a character that got split at
7805 * the end of the line. We do not want to advance to
7806 * the next screen line.
7809 if (curwin
->w_virtcol
> (colnr_T
)i
)
7810 --curwin
->w_cursor
.col
;
7814 else if (nv_screengo(oap
, FORWARD
, cap
->count1
- 1) == FAIL
)
7819 i
= curwin
->w_leftcol
+ W_WIDTH(curwin
) - col_off
- 1;
7820 coladvance((colnr_T
)i
);
7822 /* Make sure we stick in this column. */
7824 curwin
->w_curswant
= curwin
->w_virtcol
;
7825 curwin
->w_set_curswant
= FALSE
;
7831 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>"
7836 case POUND
: /* pound sign (sometimes equal to '#') */
7838 case Ctrl_RSB
: /* :tag or :tselect for current identifier */
7839 case ']': /* :tselect for current identifier */
7844 * ge and gE: go back to end of word
7848 oap
->motion_type
= MCHAR
;
7849 curwin
->w_set_curswant
= TRUE
;
7850 oap
->inclusive
= TRUE
;
7851 if (bckend_word(cap
->count1
, cap
->nchar
== 'E', FALSE
) == FAIL
)
7856 * "g CTRL-G": display info about cursor position
7863 * "gi": start Insert at the last position.
7866 if (curbuf
->b_last_insert
.lnum
!= 0)
7868 curwin
->w_cursor
= curbuf
->b_last_insert
;
7869 check_cursor_lnum();
7870 i
= (int)STRLEN(ml_get_curline());
7871 if (curwin
->w_cursor
.col
> (colnr_T
)i
)
7873 #ifdef FEAT_VIRTUALEDIT
7874 if (virtual_active())
7875 curwin
->w_cursor
.coladd
+= curwin
->w_cursor
.col
- i
;
7877 curwin
->w_cursor
.col
= i
;
7885 * "gI": Start insert in column 1.
7889 if (!checkclearopq(oap
))
7890 invoke_edit(cap
, FALSE
, 'g', FALSE
);
7893 #ifdef FEAT_SEARCHPATH
7895 * "gf": goto file, edit file under cursor
7896 * "]f" and "[f": can also be used.
7904 /* "g'm" and "g`m": jump to mark without setting pcmark */
7916 do_sleep(cap
->count1
* 1000L);
7920 * "ga": Display the ascii value of the character under the
7921 * cursor. It is displayed in decimal, hex, and octal. -- webb
7929 * "g8": Display the bytes used for the UTF-8 character under the
7930 * cursor. It is displayed in hex.
7931 * "8g8" finds illegal byte sequence.
7934 if (cap
->count0
== 8)
7946 * "gg": Goto the first line in file. With a count it goes to
7947 * that line number like for "G". -- webb
7955 * Two-character operators:
7957 * "gw" Format text and keep cursor position
7958 * "g~" Toggle the case of the text.
7959 * "gu" Change text to lower case.
7960 * "gU" Change text to upper case.
7961 * "g?" rot13 encoding
7962 * "g@" call 'operatorfunc'
7966 oap
->cursor_start
= curwin
->w_cursor
;
7977 * "gd": Find first occurrence of pattern under the cursor in the
7979 * "gD": idem, but in the current file.
7983 nv_gd(oap
, cap
->nchar
, (int)cap
->count0
);
7988 * g<*Mouse> : <C-*mouse>
7992 case K_MIDDLERELEASE
:
7998 case K_RIGHTRELEASE
:
8005 mod_mask
= MOD_MASK_CTRL
;
8006 (void)do_mouse(oap
, cap
->nchar
, BACKWARD
, cap
->count1
, 0);
8014 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text
8022 /* "go": goto byte count from start of buffer */
8024 goto_byte(cap
->count0
);
8028 /* "gQ": improved Ex mode */
8032 clearopbeep(cap
->oap
);
8037 if (!checkclearopq(oap
))
8041 #ifdef FEAT_JUMPLIST
8047 cap
->count1
= -cap
->count1
;
8054 goto_tabpage((int)cap
->count0
);
8057 goto_tabpage(-(int)cap
->count1
);
8062 case '-': /* "g+" and "g-": undo or redo along the timeline */
8063 if (!checkclearopq(oap
))
8064 undo_time(cap
->nchar
== '-' ? -cap
->count1
: cap
->count1
,
8075 * Handle "o" and "O" commands.
8081 if (!checkclearopq(cap
->oap
))
8084 if (cap
->cmdchar
== 'O')
8085 /* Open above the first line of a folded sequence of lines */
8086 (void)hasFolding(curwin
->w_cursor
.lnum
,
8087 &curwin
->w_cursor
.lnum
, NULL
);
8089 /* Open below the last line of a folded sequence of lines */
8090 (void)hasFolding(curwin
->w_cursor
.lnum
,
8091 NULL
, &curwin
->w_cursor
.lnum
);
8093 if (u_save((linenr_T
)(curwin
->w_cursor
.lnum
-
8094 (cap
->cmdchar
== 'O' ? 1 : 0)),
8095 (linenr_T
)(curwin
->w_cursor
.lnum
+
8096 (cap
->cmdchar
== 'o' ? 1 : 0))
8098 && open_line(cap
->cmdchar
== 'O' ? BACKWARD
: FORWARD
,
8099 #ifdef FEAT_COMMENTS
8100 has_format_option(FO_OPEN_COMS
) ? OPENLINE_DO_COM
:
8104 /* When '#' is in 'cpoptions' ignore the count. */
8105 if (vim_strchr(p_cpo
, CPO_HASH
) != NULL
)
8107 invoke_edit(cap
, FALSE
, cap
->cmdchar
, TRUE
);
8113 * "." command: redo last change.
8119 if (!checkclearopq(cap
->oap
))
8122 * If "restart_edit" is TRUE, the last but one command is repeated
8123 * instead of the last command (inserting text). This is used for
8124 * CTRL-O <.> in insert mode.
8126 if (start_redo(cap
->count0
, restart_edit
!= 0 && !arrow_used
) == FAIL
)
8127 clearopbeep(cap
->oap
);
8138 if (!checkclearopq(cap
->oap
))
8140 u_redo((int)cap
->count1
);
8141 curwin
->w_set_curswant
= TRUE
;
8146 * Handle "U" command.
8152 /* In Visual mode and typing "gUU" triggers an operator */
8153 if (cap
->oap
->op_type
== OP_UPPER
8159 /* translate "gUU" to "gUgU" */
8164 else if (!checkclearopq(cap
->oap
))
8167 curwin
->w_set_curswant
= TRUE
;
8172 * '~' command: If tilde is not an operator and Visual is off: swap case of a
8183 && cap
->oap
->op_type
!= OP_TILDE
)
8190 * Handle an operator command.
8191 * The actual work is done by do_pending_operator().
8199 op_type
= get_op_type(cap
->cmdchar
, cap
->nchar
);
8201 if (op_type
== cap
->oap
->op_type
) /* double operator works on lines */
8203 else if (!checkclearop(cap
->oap
))
8205 cap
->oap
->start
= curwin
->w_cursor
;
8206 cap
->oap
->op_type
= op_type
;
8211 * Handle linewise operator "dd", "yy", etc.
8213 * "_" is is a strange motion command that helps make operators more logical.
8214 * It is actually implemented, but not documented in the real Vi. This motion
8215 * command actually refers to "the current line". Commands like "dd" and "yy"
8216 * are really an alternate form of "d_" and "y_". It does accept a count, so
8217 * "d3_" works to delete 3 lines.
8223 cap
->oap
->motion_type
= MLINE
;
8224 if (cursor_down(cap
->count1
- 1L, cap
->oap
->op_type
== OP_NOP
) == FAIL
)
8225 clearopbeep(cap
->oap
);
8226 else if ( cap
->oap
->op_type
== OP_DELETE
8227 || cap
->oap
->op_type
== OP_LSHIFT
8228 || cap
->oap
->op_type
== OP_RSHIFT
)
8229 beginline(BL_SOL
| BL_FIX
);
8230 else if (cap
->oap
->op_type
!= OP_YANK
) /* 'Y' does not move cursor */
8231 beginline(BL_WHITE
| BL_FIX
);
8241 /* CTRL-HOME is like "gg" */
8242 if (mod_mask
& MOD_MASK_CTRL
)
8249 ins_at_eol
= FALSE
; /* Don't move cursor past eol (only necessary in a
8250 one-character line). */
8260 cap
->oap
->motion_type
= MCHAR
;
8261 cap
->oap
->inclusive
= FALSE
;
8263 if (cap
->count0
> 0)
8265 coladvance((colnr_T
)(cap
->count0
- 1));
8266 curwin
->w_curswant
= (colnr_T
)(cap
->count0
- 1);
8269 curwin
->w_curswant
= 0;
8270 /* keep curswant at the column where we wanted to go, not where
8271 we ended; differs if line is too short */
8272 curwin
->w_set_curswant
= FALSE
;
8276 * Handle back-word command "b" and "B".
8277 * cap->arg is 1 for "B"
8283 cap
->oap
->motion_type
= MCHAR
;
8284 cap
->oap
->inclusive
= FALSE
;
8285 curwin
->w_set_curswant
= TRUE
;
8286 if (bck_word(cap
->count1
, cap
->arg
, FALSE
) == FAIL
)
8287 clearopbeep(cap
->oap
);
8289 else if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8295 * Handle word motion commands "e", "E", "w" and "W".
8296 * cap->arg is TRUE for "E" and "W".
8307 * Set inclusive for the "E" and "e" command.
8309 if (cap
->cmdchar
== 'e' || cap
->cmdchar
== 'E')
8313 cap
->oap
->inclusive
= word_end
;
8316 * "cw" and "cW" are a special case.
8318 if (!word_end
&& cap
->oap
->op_type
== OP_CHANGE
)
8321 if (n
!= NUL
) /* not an empty line */
8326 * Reproduce a funny Vi behaviour: "cw" on a blank only
8327 * changes one character, not all blanks until the start of
8328 * the next word. Only do this when the 'w' flag is included
8331 if (cap
->count1
== 1 && vim_strchr(p_cpo
, CPO_CW
) != NULL
)
8333 cap
->oap
->inclusive
= TRUE
;
8334 cap
->oap
->motion_type
= MCHAR
;
8341 * This is a little strange. To match what the real Vi does,
8342 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided
8343 * that we are not on a space or a TAB. This seems impolite
8344 * at first, but it's really more what we mean when we say
8346 * Another strangeness: When standing on the end of a word
8347 * "ce" will change until the end of the next wordt, but "cw"
8348 * will change only one character! This is done by setting
8351 cap
->oap
->inclusive
= TRUE
;
8358 cap
->oap
->motion_type
= MCHAR
;
8359 curwin
->w_set_curswant
= TRUE
;
8361 n
= end_word(cap
->count1
, cap
->arg
, flag
, FALSE
);
8363 n
= fwd_word(cap
->count1
, cap
->arg
, cap
->oap
->op_type
!= OP_NOP
);
8365 /* Don't leave the cursor on the NUL past a line */
8366 if (curwin
->w_cursor
.col
&& gchar_cursor() == NUL
)
8368 --curwin
->w_cursor
.col
;
8369 cap
->oap
->inclusive
= TRUE
;
8372 if (n
== FAIL
&& cap
->oap
->op_type
== OP_NOP
)
8373 clearopbeep(cap
->oap
);
8377 adjust_for_sel(cap
);
8380 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8387 * "0" and "^" commands.
8388 * cap->arg is the argument for beginline().
8394 cap
->oap
->motion_type
= MCHAR
;
8395 cap
->oap
->inclusive
= FALSE
;
8396 beginline(cap
->arg
);
8398 if ((fdo_flags
& FDO_HOR
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8401 ins_at_eol
= FALSE
; /* Don't move cursor past eol (only necessary in a
8402 one-character line). */
8407 * In exclusive Visual mode, may include the last character.
8413 if (VIsual_active
&& cap
->oap
->inclusive
&& *p_sel
== 'e'
8414 && gchar_cursor() != NUL
&& lt(VIsual
, curwin
->w_cursor
))
8421 ++curwin
->w_cursor
.col
;
8422 cap
->oap
->inclusive
= FALSE
;
8427 * Exclude last character at end of Visual area for 'selection' == "exclusive".
8428 * Should check VIsual_mode before calling this.
8429 * Returns TRUE when backed up to the previous line.
8436 if (*p_sel
== 'e' && !equalpos(VIsual
, curwin
->w_cursor
))
8438 if (lt(VIsual
, curwin
->w_cursor
))
8439 pp
= &curwin
->w_cursor
;
8442 #ifdef FEAT_VIRTUALEDIT
8454 else if (pp
->lnum
> 1)
8457 pp
->col
= (colnr_T
)STRLEN(ml_get(pp
->lnum
));
8465 * SELECT key in Normal or Visual mode: end of Select mode mapping.
8472 VIsual_select
= TRUE
;
8473 else if (VIsual_reselect
)
8475 cap
->nchar
= 'v'; /* fake "gv" command */
8484 * "G", "gg", CTRL-END, CTRL-HOME.
8485 * cap->arg is TRUE for "G".
8494 lnum
= curbuf
->b_ml
.ml_line_count
;
8497 cap
->oap
->motion_type
= MLINE
;
8500 /* When a count is given, use it instead of the default lnum */
8501 if (cap
->count0
!= 0)
8505 else if (lnum
> curbuf
->b_ml
.ml_line_count
)
8506 lnum
= curbuf
->b_ml
.ml_line_count
;
8507 curwin
->w_cursor
.lnum
= lnum
;
8508 beginline(BL_SOL
| BL_FIX
);
8510 if ((fdo_flags
& FDO_JUMP
) && KeyTyped
&& cap
->oap
->op_type
== OP_NOP
)
8516 * CTRL-\ in Normal mode.
8522 if (cap
->nchar
== Ctrl_N
|| cap
->nchar
== Ctrl_G
)
8525 if (restart_edit
!= 0 && mode_displayed
)
8526 clear_cmdline
= TRUE
; /* unshow mode later */
8529 if (cmdwin_type
!= 0)
8530 cmdwin_result
= Ctrl_C
;
8535 end_visual_mode(); /* stop Visual */
8536 redraw_curbuf_later(INVERTED
);
8539 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */
8540 if (cap
->nchar
== Ctrl_G
&& p_im
)
8544 clearopbeep(cap
->oap
);
8548 * ESC in Normal mode: beep, but don't flush buffers.
8549 * Don't even beep if we are canceling a command.
8557 no_reason
= (cap
->oap
->op_type
== OP_NOP
8558 && cap
->opcount
== 0
8560 && cap
->oap
->regname
== 0
8563 if (cap
->arg
) /* TRUE for CTRL-C */
8565 if (restart_edit
== 0
8573 MSG(_("Type :quit<Enter> to exit Vim"));
8575 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be
8576 * set again below when halfway a mapping. */
8580 if (cmdwin_type
!= 0)
8582 cmdwin_result
= K_IGNORE
;
8583 got_int
= FALSE
; /* don't stop executing autocommands et al. */
8592 end_visual_mode(); /* stop Visual */
8593 check_cursor_col(); /* make sure cursor is not beyond EOL */
8594 curwin
->w_set_curswant
= TRUE
;
8595 redraw_curbuf_later(INVERTED
);
8603 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is
8604 * set return to Insert mode afterwards. */
8605 if (restart_edit
== 0 && goto_im()
8606 #ifdef FEAT_EX_EXTRA
8607 && ex_normal_busy
== 0
8614 * Handle "A", "a", "I", "i" and <Insert> commands.
8620 /* <Insert> is equal to "i" */
8621 if (cap
->cmdchar
== K_INS
|| cap
->cmdchar
== K_KINS
)
8625 /* in Visual mode "A" and "I" are an operator */
8626 if (VIsual_active
&& (cap
->cmdchar
== 'A' || cap
->cmdchar
== 'I'))
8629 /* in Visual mode and after an operator "a" and "i" are for text objects */
8632 if ((cap
->cmdchar
== 'a' || cap
->cmdchar
== 'i')
8633 && (cap
->oap
->op_type
!= OP_NOP
8642 clearopbeep(cap
->oap
);
8645 else if (!curbuf
->b_p_ma
&& !p_im
)
8647 /* Only give this error when 'insertmode' is off. */
8648 EMSG(_(e_modifiable
));
8651 else if (!checkclearopq(cap
->oap
))
8653 switch (cap
->cmdchar
)
8655 case 'A': /* "A"ppend after the line */
8656 curwin
->w_set_curswant
= TRUE
;
8657 #ifdef FEAT_VIRTUALEDIT
8658 if (ve_flags
== VE_ALL
)
8660 int save_State
= State
;
8662 /* Pretent Insert mode here to allow the cursor on the
8663 * character past the end of the line */
8665 coladvance((colnr_T
)MAXCOL
);
8670 curwin
->w_cursor
.col
+= (colnr_T
)STRLEN(ml_get_cursor());
8673 case 'I': /* "I"nsert before the first non-blank */
8674 if (vim_strchr(p_cpo
, CPO_INSEND
) == NULL
)
8675 beginline(BL_WHITE
);
8677 beginline(BL_WHITE
|BL_FIX
);
8680 case 'a': /* "a"ppend is like "i"nsert on the next character. */
8681 #ifdef FEAT_VIRTUALEDIT
8682 /* increment coladd when in virtual space, increment the
8683 * column otherwise, also to append after an unprintable char */
8684 if (virtual_active()
8685 && (curwin
->w_cursor
.coladd
> 0
8686 || *ml_get_cursor() == NUL
8687 || *ml_get_cursor() == TAB
))
8688 curwin
->w_cursor
.coladd
++;
8691 if (*ml_get_cursor() != NUL
)
8696 #ifdef FEAT_VIRTUALEDIT
8697 if (curwin
->w_cursor
.coladd
&& cap
->cmdchar
!= 'A')
8699 int save_State
= State
;
8701 /* Pretent Insert mode here to allow the cursor on the
8702 * character past the end of the line */
8704 coladvance(getviscol());
8709 invoke_edit(cap
, FALSE
, cap
->cmdchar
, FALSE
);
8714 * Invoke edit() and take care of "restart_edit" and the return value.
8717 invoke_edit(cap
, repl
, cmd
, startln
)
8719 int repl
; /* "r" or "gr" command */
8723 int restart_edit_save
= 0;
8725 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert
8726 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow
8728 if (repl
|| !stuff_empty())
8729 restart_edit_save
= restart_edit
;
8731 restart_edit_save
= 0;
8733 /* Always reset "restart_edit", this is not a restarted edit. */
8736 if (edit(cmd
, startln
, cap
->count1
))
8737 cap
->retval
|= CA_COMMAND_BUSY
;
8739 if (restart_edit
== 0)
8740 restart_edit
= restart_edit_save
;
8745 * "a" or "i" while an operator is pending or in Visual mode: object motion.
8755 if (cap
->cmdchar
== 'i')
8756 include
= FALSE
; /* "ix" = inner object: exclude white space */
8758 include
= TRUE
; /* "ax" = an object: include white space */
8760 /* Make sure (), [], {} and <> are in 'matchpairs' */
8761 mps_save
= curbuf
->b_p_mps
;
8762 curbuf
->b_p_mps
= (char_u
*)"(:),{:},[:],<:>";
8766 case 'w': /* "aw" = a word */
8767 flag
= current_word(cap
->oap
, cap
->count1
, include
, FALSE
);
8769 case 'W': /* "aW" = a WORD */
8770 flag
= current_word(cap
->oap
, cap
->count1
, include
, TRUE
);
8772 case 'b': /* "ab" = a braces block */
8775 flag
= current_block(cap
->oap
, cap
->count1
, include
, '(', ')');
8777 case 'B': /* "aB" = a Brackets block */
8780 flag
= current_block(cap
->oap
, cap
->count1
, include
, '{', '}');
8782 case '[': /* "a[" = a [] block */
8784 flag
= current_block(cap
->oap
, cap
->count1
, include
, '[', ']');
8786 case '<': /* "a<" = a <> block */
8788 flag
= current_block(cap
->oap
, cap
->count1
, include
, '<', '>');
8790 case 't': /* "at" = a tag block (xml and html) */
8791 flag
= current_tagblock(cap
->oap
, cap
->count1
, include
);
8793 case 'p': /* "ap" = a paragraph */
8794 flag
= current_par(cap
->oap
, cap
->count1
, include
, 'p');
8796 case 's': /* "as" = a sentence */
8797 flag
= current_sent(cap
->oap
, cap
->count1
, include
);
8799 case '"': /* "a"" = a double quoted string */
8800 case '\'': /* "a'" = a single quoted string */
8801 case '`': /* "a`" = a backtick quoted string */
8802 flag
= current_quote(cap
->oap
, cap
->count1
, include
,
8806 case 'S': /* "aS" = a section */
8807 case 'f': /* "af" = a filename */
8808 case 'u': /* "au" = a URL */
8815 curbuf
->b_p_mps
= mps_save
;
8817 clearopbeep(cap
->oap
);
8818 adjust_cursor_col();
8819 curwin
->w_set_curswant
= TRUE
;
8824 * "q" command: Start/stop recording.
8825 * "q:", "q/", "q?": edit command-line in command-line window.
8831 if (cap
->oap
->op_type
== OP_FORMAT
)
8833 /* "gqq" is the same as "gqgq": format line */
8838 else if (!checkclearop(cap
->oap
))
8841 if (cap
->nchar
== ':' || cap
->nchar
== '/' || cap
->nchar
== '?')
8843 stuffcharReadbuff(cap
->nchar
);
8844 stuffcharReadbuff(K_CMDWIN
);
8848 /* (stop) recording into a named register, unless executing a
8850 if (!Exec_reg
&& do_record(cap
->nchar
) == FAIL
)
8851 clearopbeep(cap
->oap
);
8856 * Handle the "@r" command.
8862 if (checkclearop(cap
->oap
))
8865 if (cap
->nchar
== '=')
8867 if (get_expr_register() == NUL
)
8871 while (cap
->count1
-- && !got_int
)
8873 if (do_execreg(cap
->nchar
, FALSE
, FALSE
, FALSE
) == FAIL
)
8875 clearopbeep(cap
->oap
);
8883 * Handle the CTRL-U and CTRL-D commands.
8889 if ((cap
->cmdchar
== Ctrl_U
&& curwin
->w_cursor
.lnum
== 1)
8890 || (cap
->cmdchar
== Ctrl_D
8891 && curwin
->w_cursor
.lnum
== curbuf
->b_ml
.ml_line_count
))
8892 clearopbeep(cap
->oap
);
8893 else if (!checkclearop(cap
->oap
))
8894 halfpage(cap
->cmdchar
== Ctrl_D
, cap
->count0
);
8898 * Handle "J" or "gJ" command.
8905 if (VIsual_active
) /* join the visual lines */
8909 if (!checkclearop(cap
->oap
))
8911 if (cap
->count0
<= 1)
8912 cap
->count0
= 2; /* default for join is two lines! */
8913 if (curwin
->w_cursor
.lnum
+ cap
->count0
- 1 >
8914 curbuf
->b_ml
.ml_line_count
)
8915 clearopbeep(cap
->oap
); /* beyond last line */
8918 prep_redo(cap
->oap
->regname
, cap
->count0
,
8919 NUL
, cap
->cmdchar
, NUL
, NUL
, cap
->nchar
);
8920 do_do_join(cap
->count0
, cap
->nchar
== NUL
);
8926 * "P", "gP", "p" and "gp" commands.
8934 void *reg1
= NULL
, *reg2
= NULL
;
8936 int was_visual
= FALSE
;
8941 if (cap
->oap
->op_type
!= OP_NOP
)
8944 /* "dp" is ":diffput" */
8945 if (cap
->oap
->op_type
== OP_DELETE
&& cap
->cmdchar
== 'p')
8948 nv_diffgetput(TRUE
);
8952 clearopbeep(cap
->oap
);
8956 dir
= (cap
->cmdchar
== 'P'
8957 || (cap
->cmdchar
== 'g' && cap
->nchar
== 'P'))
8958 ? BACKWARD
: FORWARD
;
8960 if (cap
->cmdchar
== 'g')
8961 flags
|= PUT_CURSEND
;
8966 /* Putting in Visual mode: The put text replaces the selected
8967 * text. First delete the selected text, then put the new text.
8968 * Need to save and restore the registers that the delete
8969 * overwrites if the old contents is being put.
8972 regname
= cap
->oap
->regname
;
8973 # ifdef FEAT_CLIPBOARD
8974 adjust_clip_reg(®name
);
8976 if (regname
== 0 || VIM_ISDIGIT(regname
)
8977 # ifdef FEAT_CLIPBOARD
8978 || (clip_unnamed
&& (regname
== '*' || regname
== '+'))
8983 /* the delete is going to overwrite the register we want to
8984 * put, save it first. */
8985 reg1
= get_register(regname
, TRUE
);
8988 /* Now delete the selected text. */
8991 cap
->oap
->regname
= NUL
;
8993 do_pending_operator(cap
, 0, FALSE
);
8994 empty
= (curbuf
->b_ml
.ml_flags
& ML_EMPTY
);
8996 /* delete PUT_LINE_BACKWARD; */
8997 cap
->oap
->regname
= regname
;
9001 /* Delete probably changed the register we want to put, save
9002 * it first. Then put back what was there before the delete. */
9003 reg2
= get_register(regname
, FALSE
);
9004 put_register(regname
, reg1
);
9007 /* When deleted a linewise Visual area, put the register as
9008 * lines to avoid it joined with the next line. When deletion was
9009 * characterwise, split a line when putting lines. */
9010 if (VIsual_mode
== 'V')
9012 else if (VIsual_mode
== 'v')
9013 flags
|= PUT_LINE_SPLIT
;
9014 if (VIsual_mode
== Ctrl_V
&& dir
== FORWARD
)
9015 flags
|= PUT_LINE_FORWARD
;
9017 if ((VIsual_mode
!= 'V'
9018 && curwin
->w_cursor
.col
< curbuf
->b_op_start
.col
)
9019 || (VIsual_mode
== 'V'
9020 && curwin
->w_cursor
.lnum
< curbuf
->b_op_start
.lnum
))
9021 /* cursor is at the end of the line or end of file, put
9026 do_put(cap
->oap
->regname
, dir
, cap
->count1
, flags
);
9029 /* If a register was saved, put it back now. */
9031 put_register(regname
, reg2
);
9033 /* What to reselect with "gv"? Selecting the just put text seems to
9034 * be the most useful, since the original text was removed. */
9037 curbuf
->b_visual
.vi_start
= curbuf
->b_op_start
;
9038 curbuf
->b_visual
.vi_end
= curbuf
->b_op_end
;
9041 /* When all lines were selected and deleted do_put() leaves an empty
9042 * line that needs to be deleted now. */
9043 if (empty
&& *ml_get(curbuf
->b_ml
.ml_line_count
) == NUL
)
9045 ml_delete(curbuf
->b_ml
.ml_line_count
, TRUE
);
9047 /* If the cursor was in that line, move it to the end of the last
9049 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
9051 curwin
->w_cursor
.lnum
= curbuf
->b_ml
.ml_line_count
;
9052 coladvance((colnr_T
)MAXCOL
);
9056 auto_format(FALSE
, TRUE
);
9061 * "o" and "O" commands.
9068 /* "do" is ":diffget" */
9069 if (cap
->oap
->op_type
== OP_DELETE
&& cap
->cmdchar
== 'o')
9072 nv_diffgetput(FALSE
);
9077 if (VIsual_active
) /* switch start and end of visual */
9078 v_swap_corners(cap
->cmdchar
);
9090 ProcessSniffRequests();
9094 #ifdef FEAT_NETBEANS_INTG
9099 netbeans_keycommand(cap
->nchar
);
9109 do_put('~', BACKWARD
, 1L, PUT_CURSEND
);
9115 * Trigger CursorHold event.
9116 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the
9117 * input buffer. "did_cursorhold" is set to avoid retriggering.
9124 apply_autocmds(EVENT_CURSORHOLD
, NULL
, NULL
, FALSE
, curbuf
);
9125 did_cursorhold
= TRUE
;
9126 cap
->retval
|= CA_COMMAND_BUSY
; /* don't call edit() now */