Mercurial > vim
annotate src/normal.c @ 18219:5d67f207f7c3 v8.1.2104
patch 8.1.2104: the normal.c file is too big
Commit: https://github.com/vim/vim/commit/792cf5e1bec04c6d6d70cfbb9ef24c798b469731
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 30 23:12:16 2019 +0200
patch 8.1.2104: the normal.c file is too big
Problem: The normal.c file is too big.
Solution: Move do_pending_operator() to ops.c. (Yegappan Lakshmanan,
closes #4999).
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 30 Sep 2019 23:15:03 +0200 |
parents | e0ec4cd7a865 |
children | 11f68eb58fda |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * normal.c: Contains the main routine for processing characters in command | |
11 * mode. Communicates closely with the code in ops.c to handle | |
12 * the operators. | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
17 static int VIsual_mode_orig = NUL; // saved Visual mode |
7 | 18 static int restart_VIsual_select = 0; |
19 | |
2667 | 20 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
21 static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
2667 | 22 #endif |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16598
diff
changeset
|
23 static int nv_compare(const void *s1, const void *s2); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
24 static void unshift_special(cmdarg_T *cap); |
7 | 25 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
26 static void del_from_showcmd(int); |
7 | 27 #endif |
28 | |
29 /* | |
30 * nv_*(): functions called to handle Normal and Visual mode commands. | |
31 * n_*(): functions called to handle Normal mode commands. | |
32 * v_*(): functions called to handle Visual mode commands. | |
33 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
34 static void nv_ignore(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
35 static void nv_nop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
36 static void nv_error(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
37 static void nv_help(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
38 static void nv_addsub(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
39 static void nv_page(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
40 static void nv_zet(cmdarg_T *cap); |
7 | 41 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
42 static void nv_ver_scrollbar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
43 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 44 #endif |
685 | 45 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
46 static void nv_tabline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
47 static void nv_tabmenu(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
48 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
49 static void nv_exmode(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
50 static void nv_colon(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
51 static void nv_ctrlg(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
52 static void nv_ctrlh(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
53 static void nv_clear(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
54 static void nv_ctrlo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
55 static void nv_hat(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
56 static void nv_Zet(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
57 static void nv_ident(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
58 static void nv_tagpop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
59 static void nv_scroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
60 static void nv_right(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
61 static void nv_left(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
62 static void nv_up(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
63 static void nv_down(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
64 static void nv_end(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
65 static void nv_dollar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
66 static void nv_search(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
67 static void nv_next(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
68 static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
69 static void nv_csearch(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
70 static void nv_brackets(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
71 static void nv_percent(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
72 static void nv_brace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
73 static void nv_mark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
74 static void nv_findpar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
75 static void nv_undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
76 static void nv_kundo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
77 static void nv_Replace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
78 static void nv_replace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
79 static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
80 static void v_visop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
81 static void nv_subst(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
82 static void nv_abbrev(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
83 static void nv_optrans(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
84 static void nv_gomark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
85 static void nv_pcmark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
86 static void nv_regname(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
87 static void nv_visual(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
88 static void n_start_visual_mode(int c); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
89 static void nv_window(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
90 static void nv_suspend(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
91 static void nv_g_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
92 static void nv_dot(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
93 static void nv_redo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
94 static void nv_Undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
95 static void nv_tilde(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
96 static void nv_operator(cmdarg_T *cap); |
1490 | 97 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
98 static void set_op_var(int optype); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
99 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
100 static void nv_lineop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
101 static void nv_home(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
102 static void nv_pipe(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
103 static void nv_bck_word(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
104 static void nv_wordcmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
105 static void nv_beginline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
106 static void adjust_cursor(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
107 static void adjust_for_sel(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
108 static void nv_select(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
109 static void nv_goto(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
110 static void nv_normal(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
111 static void nv_esc(cmdarg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
112 static void nv_edit(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
113 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 114 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
115 static void nv_object(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
116 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
117 static void nv_record(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
118 static void nv_at(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
119 static void nv_halfpage(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
120 static void nv_join(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
121 static void nv_put(cmdarg_T *cap); |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
122 static void nv_put_opt(cmdarg_T *cap, int fix_indent); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
123 static void nv_open(cmdarg_T *cap); |
7 | 124 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
125 static void nv_nbcmd(cmdarg_T *cap); |
7 | 126 #endif |
127 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
128 static void nv_drop(cmdarg_T *cap); |
7 | 129 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
130 static void nv_cursorhold(cmdarg_T *cap); |
7 | 131 |
1728 | 132 static char *e_noident = N_("E349: No identifier under cursor"); |
133 | |
7 | 134 /* |
135 * Function to be called for a Normal or Visual mode command. | |
136 * The argument is a cmdarg_T. | |
137 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
138 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 139 |
140 /* Values for cmd_flags. */ | |
141 #define NV_NCH 0x01 /* may need to get a second char */ | |
142 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
143 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
144 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
145 | |
146 #define NV_SS 0x10 /* may start selection */ | |
147 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
148 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
149 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
150 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
151 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
152 | |
153 /* | |
154 * Generally speaking, every Normal mode command should either clear any | |
155 * pending operator (with *clearop*()), or set the motion type variable | |
156 * oap->motion_type. | |
157 * | |
158 * When a cursor motion command is made, it is marked as being a character or | |
159 * line oriented motion. Then, if an operator is in effect, the operation | |
160 * becomes character or line oriented accordingly. | |
161 */ | |
162 | |
163 /* | |
164 * This table contains one entry for every Normal or Visual mode command. | |
165 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
166 * It is faster when all keys from zero to '~' are present. | |
167 */ | |
168 static const struct nv_cmd | |
169 { | |
170 int cmd_char; /* (first) command character */ | |
171 nv_func_T cmd_func; /* function for this command */ | |
172 short_u cmd_flags; /* NV_ flags */ | |
173 short cmd_arg; /* value for ca.arg */ | |
174 } nv_cmds[] = | |
175 { | |
176 {NUL, nv_error, 0, 0}, | |
177 {Ctrl_A, nv_addsub, 0, 0}, | |
178 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
179 {Ctrl_C, nv_esc, 0, TRUE}, | |
180 {Ctrl_D, nv_halfpage, 0, 0}, | |
181 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
182 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
183 {Ctrl_G, nv_ctrlg, 0, 0}, | |
184 {Ctrl_H, nv_ctrlh, 0, 0}, | |
185 {Ctrl_I, nv_pcmark, 0, 0}, | |
186 {NL, nv_down, 0, FALSE}, | |
187 {Ctrl_K, nv_error, 0, 0}, | |
188 {Ctrl_L, nv_clear, 0, 0}, | |
16054
78faa25f9698
patch 8.1.1032: warnings from clang static analyzer
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
189 {CAR, nv_down, 0, TRUE}, |
7 | 190 {Ctrl_N, nv_down, NV_STS, FALSE}, |
191 {Ctrl_O, nv_ctrlo, 0, 0}, | |
192 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 193 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 194 {Ctrl_R, nv_redo, 0, 0}, |
195 {Ctrl_S, nv_ignore, 0, 0}, | |
196 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
197 {Ctrl_U, nv_halfpage, 0, 0}, | |
198 {Ctrl_V, nv_visual, 0, FALSE}, | |
199 {'V', nv_visual, 0, FALSE}, | |
200 {'v', nv_visual, 0, FALSE}, | |
201 {Ctrl_W, nv_window, 0, 0}, | |
202 {Ctrl_X, nv_addsub, 0, 0}, | |
203 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
204 {Ctrl_Z, nv_suspend, 0, 0}, | |
205 {ESC, nv_esc, 0, FALSE}, | |
206 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
207 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
208 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
209 {Ctrl__, nv_error, 0, 0}, | |
210 {' ', nv_right, 0, 0}, | |
211 {'!', nv_operator, 0, 0}, | |
212 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
213 {'#', nv_ident, 0, 0}, | |
214 {'$', nv_dollar, 0, 0}, | |
215 {'%', nv_percent, 0, 0}, | |
216 {'&', nv_optrans, 0, 0}, | |
217 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
218 {'(', nv_brace, 0, BACKWARD}, | |
219 {')', nv_brace, 0, FORWARD}, | |
220 {'*', nv_ident, 0, 0}, | |
221 {'+', nv_down, 0, TRUE}, | |
222 {',', nv_csearch, 0, TRUE}, | |
223 {'-', nv_up, 0, TRUE}, | |
224 {'.', nv_dot, NV_KEEPREG, 0}, | |
225 {'/', nv_search, 0, FALSE}, | |
226 {'0', nv_beginline, 0, 0}, | |
227 {'1', nv_ignore, 0, 0}, | |
228 {'2', nv_ignore, 0, 0}, | |
229 {'3', nv_ignore, 0, 0}, | |
230 {'4', nv_ignore, 0, 0}, | |
231 {'5', nv_ignore, 0, 0}, | |
232 {'6', nv_ignore, 0, 0}, | |
233 {'7', nv_ignore, 0, 0}, | |
234 {'8', nv_ignore, 0, 0}, | |
235 {'9', nv_ignore, 0, 0}, | |
236 {':', nv_colon, 0, 0}, | |
237 {';', nv_csearch, 0, FALSE}, | |
238 {'<', nv_operator, NV_RL, 0}, | |
239 {'=', nv_operator, 0, 0}, | |
240 {'>', nv_operator, NV_RL, 0}, | |
241 {'?', nv_search, 0, FALSE}, | |
242 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
243 {'A', nv_edit, 0, 0}, | |
244 {'B', nv_bck_word, 0, 1}, | |
245 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
246 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
247 {'E', nv_wordcmd, 0, TRUE}, | |
248 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
249 {'G', nv_goto, 0, TRUE}, | |
250 {'H', nv_scroll, 0, 0}, | |
251 {'I', nv_edit, 0, 0}, | |
252 {'J', nv_join, 0, 0}, | |
253 {'K', nv_ident, 0, 0}, | |
254 {'L', nv_scroll, 0, 0}, | |
255 {'M', nv_scroll, 0, 0}, | |
256 {'N', nv_next, 0, SEARCH_REV}, | |
257 {'O', nv_open, 0, 0}, | |
258 {'P', nv_put, 0, 0}, | |
259 {'Q', nv_exmode, NV_NCW, 0}, | |
260 {'R', nv_Replace, 0, FALSE}, | |
261 {'S', nv_subst, NV_KEEPREG, 0}, | |
262 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
263 {'U', nv_Undo, 0, 0}, | |
264 {'W', nv_wordcmd, 0, TRUE}, | |
265 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
266 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
267 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
268 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
269 {'\\', nv_error, 0, 0}, | |
270 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
271 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
272 {'_', nv_lineop, 0, 0}, | |
273 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
274 {'a', nv_edit, NV_NCH, 0}, | |
275 {'b', nv_bck_word, 0, 0}, | |
276 {'c', nv_operator, 0, 0}, | |
277 {'d', nv_operator, 0, 0}, | |
278 {'e', nv_wordcmd, 0, FALSE}, | |
279 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
280 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
281 {'h', nv_left, NV_RL, 0}, | |
282 {'i', nv_edit, NV_NCH, 0}, | |
283 {'j', nv_down, 0, FALSE}, | |
284 {'k', nv_up, 0, FALSE}, | |
285 {'l', nv_right, NV_RL, 0}, | |
286 {'m', nv_mark, NV_NCH_NOP, 0}, | |
287 {'n', nv_next, 0, 0}, | |
288 {'o', nv_open, 0, 0}, | |
289 {'p', nv_put, 0, 0}, | |
290 {'q', nv_record, NV_NCH, 0}, | |
291 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
292 {'s', nv_subst, NV_KEEPREG, 0}, | |
293 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
294 {'u', nv_undo, 0, 0}, | |
295 {'w', nv_wordcmd, 0, FALSE}, | |
296 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
297 {'y', nv_operator, 0, 0}, | |
298 {'z', nv_zet, NV_NCH_ALW, 0}, | |
299 {'{', nv_findpar, 0, BACKWARD}, | |
300 {'|', nv_pipe, 0, 0}, | |
301 {'}', nv_findpar, 0, FORWARD}, | |
302 {'~', nv_tilde, 0, 0}, | |
303 | |
304 /* pound sign */ | |
305 {POUND, nv_ident, 0, 0}, | |
306 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
307 {K_MOUSEUP, nv_mousescroll, 0, MSCR_UP}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
308 {K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
309 {K_MOUSELEFT, nv_mousescroll, 0, MSCR_LEFT}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
310 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 311 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
312 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
313 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
314 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
315 {K_LEFTRELEASE_NM, nv_mouse, 0, 0}, | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
316 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 317 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
318 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
319 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
320 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
321 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
322 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
323 {K_X1MOUSE, nv_mouse, 0, 0}, | |
324 {K_X1DRAG, nv_mouse, 0, 0}, | |
325 {K_X1RELEASE, nv_mouse, 0, 0}, | |
326 {K_X2MOUSE, nv_mouse, 0, 0}, | |
327 {K_X2DRAG, nv_mouse, 0, 0}, | |
328 {K_X2RELEASE, nv_mouse, 0, 0}, | |
329 #endif | |
819 | 330 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 331 {K_NOP, nv_nop, 0, 0}, |
7 | 332 {K_INS, nv_edit, 0, 0}, |
333 {K_KINS, nv_edit, 0, 0}, | |
334 {K_BS, nv_ctrlh, 0, 0}, | |
335 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
336 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
337 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
338 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
339 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
340 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
341 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
342 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
343 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
344 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
345 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
346 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
347 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
348 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
349 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
350 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
351 {K_S_END, nv_end, NV_SS, FALSE}, | |
352 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
353 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
354 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
355 {K_S_HOME, nv_home, NV_SS, 0}, | |
356 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
357 {K_DEL, nv_abbrev, 0, 0}, | |
358 {K_KDEL, nv_abbrev, 0, 0}, | |
359 {K_UNDO, nv_kundo, 0, 0}, | |
360 {K_HELP, nv_help, NV_NCW, 0}, | |
361 {K_F1, nv_help, NV_NCW, 0}, | |
362 {K_XF1, nv_help, NV_NCW, 0}, | |
363 {K_SELECT, nv_select, 0, 0}, | |
364 #ifdef FEAT_GUI | |
365 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
366 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
367 #endif | |
685 | 368 #ifdef FEAT_GUI_TABLINE |
369 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 370 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 371 #endif |
7 | 372 #ifdef FEAT_NETBEANS_INTG |
373 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
374 #endif | |
375 #ifdef FEAT_DND | |
376 {K_DROP, nv_drop, NV_STS, 0}, | |
377 #endif | |
819 | 378 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
379 {K_PS, nv_edit, 0, 0}, |
7 | 380 }; |
381 | |
382 /* Number of commands in nv_cmds[]. */ | |
383 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
384 | |
385 /* Sorted index of commands in nv_cmds[]. */ | |
386 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
387 | |
388 /* The highest index for which | |
389 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
390 static int nv_max_linear; | |
391 | |
392 /* | |
393 * Compare functions for qsort() below, that checks the command character | |
394 * through the index in nv_cmd_idx[]. | |
395 */ | |
396 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
397 nv_compare(const void *s1, const void *s2) |
7 | 398 { |
399 int c1, c2; | |
400 | |
401 /* The commands are sorted on absolute value. */ | |
402 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
403 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
404 if (c1 < 0) | |
405 c1 = -c1; | |
406 if (c2 < 0) | |
407 c2 = -c2; | |
408 return c1 - c2; | |
409 } | |
410 | |
411 /* | |
412 * Initialize the nv_cmd_idx[] table. | |
413 */ | |
414 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
415 init_normal_cmds(void) |
7 | 416 { |
417 int i; | |
418 | |
419 /* Fill the index table with a one to one relation. */ | |
1877 | 420 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 421 nv_cmd_idx[i] = i; |
422 | |
423 /* Sort the commands by the command character. */ | |
424 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
425 | |
426 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 427 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 428 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
429 break; | |
430 nv_max_linear = i - 1; | |
431 } | |
432 | |
433 /* | |
434 * Search for a command in the commands table. | |
435 * Returns -1 for invalid command. | |
436 */ | |
437 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
438 find_command(int cmdchar) |
7 | 439 { |
440 int i; | |
441 int idx; | |
442 int top, bot; | |
443 int c; | |
444 | |
445 /* A multi-byte character is never a command. */ | |
446 if (cmdchar >= 0x100) | |
447 return -1; | |
448 | |
449 /* We use the absolute value of the character. Special keys have a | |
450 * negative value, but are sorted on their absolute value. */ | |
451 if (cmdchar < 0) | |
452 cmdchar = -cmdchar; | |
453 | |
454 /* If the character is in the first part: The character is the index into | |
455 * nv_cmd_idx[]. */ | |
456 if (cmdchar <= nv_max_linear) | |
457 return nv_cmd_idx[cmdchar]; | |
458 | |
459 /* Perform a binary search. */ | |
460 bot = nv_max_linear + 1; | |
461 top = NV_CMDS_SIZE - 1; | |
462 idx = -1; | |
463 while (bot <= top) | |
464 { | |
465 i = (top + bot) / 2; | |
466 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
467 if (c < 0) | |
468 c = -c; | |
469 if (cmdchar == c) | |
470 { | |
471 idx = nv_cmd_idx[i]; | |
472 break; | |
473 } | |
474 if (cmdchar > c) | |
475 bot = i + 1; | |
476 else | |
477 top = i - 1; | |
478 } | |
479 return idx; | |
480 } | |
481 | |
482 /* | |
483 * Execute a command in Normal mode. | |
484 */ | |
485 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
486 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
487 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
488 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 489 { |
490 cmdarg_T ca; /* command arguments */ | |
491 int c; | |
492 int ctrl_w = FALSE; /* got CTRL-W command */ | |
493 int old_col = curwin->w_curswant; | |
494 #ifdef FEAT_CMDL_INFO | |
495 int need_flushbuf; /* need to call out_flush() */ | |
496 #endif | |
497 pos_T old_pos; /* cursor position before command */ | |
498 int mapped_len; | |
499 static int old_mapped_len = 0; | |
500 int idx; | |
1751 | 501 #ifdef FEAT_EVAL |
502 int set_prevcount = FALSE; | |
503 #endif | |
7 | 504 |
505 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
506 ca.oap = oap; | |
1692 | 507 |
508 /* Use a count remembered from before entering an operator. After typing | |
509 * "3d" we return from normal_cmd() and come back here, the "3" is | |
510 * remembered in "opcount". */ | |
7 | 511 ca.opcount = opcount; |
512 | |
513 /* | |
514 * If there is an operator pending, then the command we take this time | |
515 * will terminate it. Finish_op tells us to finish the operation before | |
516 * returning this time (unless the operation was cancelled). | |
517 */ | |
518 #ifdef CURSOR_SHAPE | |
519 c = finish_op; | |
520 #endif | |
521 finish_op = (oap->op_type != OP_NOP); | |
522 #ifdef CURSOR_SHAPE | |
523 if (finish_op != c) | |
524 { | |
525 ui_cursor_shape(); /* may show different cursor shape */ | |
526 # ifdef FEAT_MOUSESHAPE | |
527 update_mouseshape(-1); | |
528 # endif | |
529 } | |
530 #endif | |
531 | |
1692 | 532 /* When not finishing an operator and no register name typed, reset the |
533 * count. */ | |
7 | 534 if (!finish_op && !oap->regname) |
1751 | 535 { |
7 | 536 ca.opcount = 0; |
1751 | 537 #ifdef FEAT_EVAL |
538 set_prevcount = TRUE; | |
539 #endif | |
540 } | |
7 | 541 |
1692 | 542 /* Restore counts from before receiving K_CURSORHOLD. This means after |
543 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
544 * "3 * 2". */ | |
545 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
546 { | |
547 ca.opcount = oap->prev_opcount; | |
548 ca.count0 = oap->prev_count0; | |
549 oap->prev_opcount = 0; | |
550 oap->prev_count0 = 0; | |
551 } | |
552 | |
7 | 553 mapped_len = typebuf_maplen(); |
554 | |
555 State = NORMAL_BUSY; | |
556 #ifdef USE_ON_FLY_SCROLL | |
557 dont_scroll = FALSE; /* allow scrolling here */ | |
558 #endif | |
559 | |
2667 | 560 #ifdef FEAT_EVAL |
561 /* Set v:count here, when called from main() and not a stuffed | |
562 * command, so that v:count can be used in an expression mapping | |
5649 | 563 * when there is no count. Do set it for redo. */ |
564 if (toplevel && readbuf1_empty()) | |
2667 | 565 set_vcount_ca(&ca, &set_prevcount); |
566 #endif | |
567 | |
7 | 568 /* |
569 * Get the command character from the user. | |
570 */ | |
571 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
572 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 573 |
574 /* | |
575 * If a mapping was started in Visual or Select mode, remember the length | |
576 * of the mapping. This is used below to not return to Insert mode for as | |
577 * long as the mapping is being executed. | |
578 */ | |
579 if (restart_edit == 0) | |
580 old_mapped_len = 0; | |
581 else if (old_mapped_len | |
819 | 582 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 583 old_mapped_len = typebuf_maplen(); |
584 | |
585 if (c == NUL) | |
586 c = K_ZERO; | |
587 | |
588 /* | |
589 * In Select mode, typed text replaces the selection. | |
590 */ | |
591 if (VIsual_active | |
592 && VIsual_select | |
593 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
594 { | |
275 | 595 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
596 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
597 * restart automatically. | |
1051 | 598 * Insert the typed character in the typeahead buffer, so that it can |
599 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 600 ins_char_typebuf(c); |
275 | 601 if (restart_edit != 0) |
602 c = 'd'; | |
603 else | |
604 c = 'c'; | |
695 | 605 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 606 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 607 } |
608 | |
609 #ifdef FEAT_CMDL_INFO | |
610 need_flushbuf = add_to_showcmd(c); | |
611 #endif | |
612 | |
613 getcount: | |
614 if (!(VIsual_active && VIsual_select)) | |
615 { | |
616 /* | |
617 * Handle a count before a command and compute ca.count0. | |
618 * Note that '0' is a command and not the start of a count, but it's | |
619 * part of a count after other digits. | |
620 */ | |
621 while ( (c >= '1' && c <= '9') | |
622 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
623 { | |
624 if (c == K_DEL || c == K_KDEL) | |
625 { | |
626 ca.count0 /= 10; | |
627 #ifdef FEAT_CMDL_INFO | |
628 del_from_showcmd(4); /* delete the digit and ~@% */ | |
629 #endif | |
630 } | |
631 else | |
632 ca.count0 = ca.count0 * 10 + (c - '0'); | |
633 if (ca.count0 < 0) /* got too large! */ | |
634 ca.count0 = 999999999L; | |
1425 | 635 #ifdef FEAT_EVAL |
636 /* Set v:count here, when called from main() and not a stuffed | |
637 * command, so that v:count can be used in an expression mapping | |
5649 | 638 * right after the count. Do set it for redo. */ |
639 if (toplevel && readbuf1_empty()) | |
2667 | 640 set_vcount_ca(&ca, &set_prevcount); |
1425 | 641 #endif |
7 | 642 if (ctrl_w) |
643 { | |
644 ++no_mapping; | |
645 ++allow_keys; /* no mapping for nchar, but keys */ | |
646 } | |
647 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 648 c = plain_vgetc(); |
7 | 649 LANGMAP_ADJUST(c, TRUE); |
650 --no_zero_mapping; | |
651 if (ctrl_w) | |
652 { | |
653 --no_mapping; | |
654 --allow_keys; | |
655 } | |
656 #ifdef FEAT_CMDL_INFO | |
657 need_flushbuf |= add_to_showcmd(c); | |
658 #endif | |
659 } | |
660 | |
661 /* | |
662 * If we got CTRL-W there may be a/another count | |
663 */ | |
664 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
665 { | |
666 ctrl_w = TRUE; | |
667 ca.opcount = ca.count0; /* remember first count */ | |
668 ca.count0 = 0; | |
669 ++no_mapping; | |
670 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 671 c = plain_vgetc(); /* get next character */ |
7 | 672 LANGMAP_ADJUST(c, TRUE); |
673 --no_mapping; | |
674 --allow_keys; | |
675 #ifdef FEAT_CMDL_INFO | |
676 need_flushbuf |= add_to_showcmd(c); | |
677 #endif | |
678 goto getcount; /* jump back */ | |
679 } | |
680 } | |
681 | |
1692 | 682 if (c == K_CURSORHOLD) |
683 { | |
684 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
685 * the same when coming back here after handling K_CURSORHOLD. */ | |
686 oap->prev_opcount = ca.opcount; | |
687 oap->prev_count0 = ca.count0; | |
688 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
689 else if (ca.opcount != 0) |
1692 | 690 { |
691 /* | |
692 * If we're in the middle of an operator (including after entering a | |
693 * yank buffer with '"') AND we had a count before the operator, then | |
694 * that count overrides the current value of ca.count0. | |
695 * What this means effectively, is that commands like "3dw" get turned | |
696 * into "d3w" which makes things fall into place pretty neatly. | |
697 * If you give a count before AND after the operator, they are | |
698 * multiplied. | |
699 */ | |
7 | 700 if (ca.count0) |
701 ca.count0 *= ca.opcount; | |
702 else | |
703 ca.count0 = ca.opcount; | |
704 } | |
705 | |
706 /* | |
707 * Always remember the count. It will be set to zero (on the next call, | |
708 * above) when there is no pending operator. | |
709 * When called from main(), save the count for use by the "count" built-in | |
710 * variable. | |
711 */ | |
712 ca.opcount = ca.count0; | |
713 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
714 | |
715 #ifdef FEAT_EVAL | |
716 /* | |
717 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 718 * Do set it for redo. |
7 | 719 */ |
5649 | 720 if (toplevel && readbuf1_empty()) |
1751 | 721 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 722 #endif |
723 | |
724 /* | |
725 * Find the command character in the table of commands. | |
726 * For CTRL-W we already got nchar when looking for a count. | |
727 */ | |
728 if (ctrl_w) | |
729 { | |
730 ca.nchar = c; | |
731 ca.cmdchar = Ctrl_W; | |
732 } | |
733 else | |
734 ca.cmdchar = c; | |
735 idx = find_command(ca.cmdchar); | |
736 if (idx < 0) | |
737 { | |
738 /* Not a known command: beep. */ | |
739 clearopbeep(oap); | |
740 goto normal_end; | |
741 } | |
631 | 742 |
633 | 743 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 744 { |
5848 | 745 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 746 clearopbeep(oap); |
633 | 747 text_locked_msg(); |
7 | 748 goto normal_end; |
749 } | |
819 | 750 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
751 goto normal_end; | |
7 | 752 |
753 /* | |
754 * In Visual/Select mode, a few keys are handled in a special way. | |
755 */ | |
756 if (VIsual_active) | |
757 { | |
758 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
759 if (km_stopsel | |
760 && (nv_cmds[idx].cmd_flags & NV_STS) | |
761 && !(mod_mask & MOD_MASK_SHIFT)) | |
762 { | |
763 end_visual_mode(); | |
764 redraw_curbuf_later(INVERTED); | |
765 } | |
766 | |
767 /* Keys that work different when 'keymodel' contains "startsel" */ | |
768 if (km_startsel) | |
769 { | |
770 if (nv_cmds[idx].cmd_flags & NV_SS) | |
771 { | |
772 unshift_special(&ca); | |
773 idx = find_command(ca.cmdchar); | |
840 | 774 if (idx < 0) |
775 { | |
776 /* Just in case */ | |
777 clearopbeep(oap); | |
778 goto normal_end; | |
779 } | |
7 | 780 } |
781 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
782 && (mod_mask & MOD_MASK_SHIFT)) | |
783 mod_mask &= ~MOD_MASK_SHIFT; | |
784 } | |
785 } | |
786 | |
787 #ifdef FEAT_RIGHTLEFT | |
788 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
789 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
790 { | |
791 /* Invert horizontal movements and operations. Only when typed by the | |
792 * user directly, not when the result of a mapping or "x" translated | |
793 * to "dl". */ | |
794 switch (ca.cmdchar) | |
795 { | |
796 case 'l': ca.cmdchar = 'h'; break; | |
797 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
798 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
799 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
800 case 'h': ca.cmdchar = 'l'; break; | |
801 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
802 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
803 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
804 case '>': ca.cmdchar = '<'; break; | |
805 case '<': ca.cmdchar = '>'; break; | |
806 } | |
807 idx = find_command(ca.cmdchar); | |
808 } | |
809 #endif | |
810 | |
811 /* | |
812 * Get an additional character if we need one. | |
813 */ | |
814 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
815 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
816 && oap->op_type == OP_NOP) | |
817 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
818 || (ca.cmdchar == 'q' | |
819 && oap->op_type == OP_NOP | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
820 && reg_recording == 0 |
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
821 && reg_executing == 0) |
7 | 822 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 823 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 824 { |
825 int *cp; | |
826 int repl = FALSE; /* get character for replace mode */ | |
827 int lit = FALSE; /* get extra character literally */ | |
828 int langmap_active = FALSE; /* using :lmap mappings */ | |
829 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
830 #ifdef HAVE_INPUT_METHOD |
7 | 831 int save_smd; /* saved value of p_smd */ |
832 #endif | |
833 | |
834 ++no_mapping; | |
835 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 836 /* Don't generate a CursorHold event here, most commands can't handle |
837 * it, e.g., nv_replace(), nv_csearch(). */ | |
838 did_cursorhold = TRUE; | |
7 | 839 if (ca.cmdchar == 'g') |
840 { | |
841 /* | |
842 * For 'g' get the next character now, so that we can check for | |
843 * "gr", "g'" and "g`". | |
844 */ | |
1389 | 845 ca.nchar = plain_vgetc(); |
7 | 846 LANGMAP_ADJUST(ca.nchar, TRUE); |
847 #ifdef FEAT_CMDL_INFO | |
848 need_flushbuf |= add_to_showcmd(ca.nchar); | |
849 #endif | |
850 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 851 || ca.nchar == Ctrl_BSL) |
7 | 852 { |
853 cp = &ca.extra_char; /* need to get a third character */ | |
854 if (ca.nchar != 'r') | |
855 lit = TRUE; /* get it literally */ | |
856 else | |
857 repl = TRUE; /* get it in replace mode */ | |
858 } | |
859 else | |
860 cp = NULL; /* no third character needed */ | |
861 } | |
862 else | |
863 { | |
864 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
865 repl = TRUE; | |
866 cp = &ca.nchar; | |
867 } | |
868 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
869 | |
870 /* | |
871 * Get a second or third character. | |
872 */ | |
873 if (cp != NULL) | |
874 { | |
875 #ifdef CURSOR_SHAPE | |
876 if (repl) | |
877 { | |
878 State = REPLACE; /* pretend Replace mode */ | |
879 ui_cursor_shape(); /* show different cursor shape */ | |
880 } | |
881 #endif | |
882 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
883 { | |
884 /* Allow mappings defined with ":lmap". */ | |
885 --no_mapping; | |
886 --allow_keys; | |
887 if (repl) | |
888 State = LREPLACE; | |
889 else | |
890 State = LANGMAP; | |
891 langmap_active = TRUE; | |
892 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
893 #ifdef HAVE_INPUT_METHOD |
7 | 894 save_smd = p_smd; |
895 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
896 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
897 im_set_active(TRUE); | |
898 #endif | |
899 | |
1389 | 900 *cp = plain_vgetc(); |
7 | 901 |
902 if (langmap_active) | |
903 { | |
904 /* Undo the decrement done above */ | |
905 ++no_mapping; | |
906 ++allow_keys; | |
907 State = NORMAL_BUSY; | |
908 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
909 #ifdef HAVE_INPUT_METHOD |
7 | 910 if (lang) |
911 { | |
912 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
913 im_save_status(&curbuf->b_p_iminsert); | |
914 im_set_active(FALSE); | |
915 } | |
916 p_smd = save_smd; | |
917 #endif | |
918 #ifdef CURSOR_SHAPE | |
919 State = NORMAL_BUSY; | |
920 #endif | |
921 #ifdef FEAT_CMDL_INFO | |
922 need_flushbuf |= add_to_showcmd(*cp); | |
923 #endif | |
924 | |
925 if (!lit) | |
926 { | |
927 #ifdef FEAT_DIGRAPHS | |
928 /* Typing CTRL-K gets a digraph. */ | |
929 if (*cp == Ctrl_K | |
930 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
931 || cp == &ca.extra_char) | |
932 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
933 { | |
934 c = get_digraph(FALSE); | |
935 if (c > 0) | |
936 { | |
937 *cp = c; | |
938 # ifdef FEAT_CMDL_INFO | |
939 /* Guessing how to update showcmd here... */ | |
940 del_from_showcmd(3); | |
941 need_flushbuf |= add_to_showcmd(*cp); | |
942 # endif | |
943 } | |
944 } | |
945 #endif | |
946 | |
947 /* adjust chars > 127, except after "tTfFr" commands */ | |
948 LANGMAP_ADJUST(*cp, !lang); | |
949 #ifdef FEAT_RIGHTLEFT | |
950 /* adjust Hebrew mapped char */ | |
951 if (p_hkmap && lang && KeyTyped) | |
952 *cp = hkmap(*cp); | |
953 #endif | |
954 } | |
955 | |
956 /* | |
957 * When the next character is CTRL-\ a following CTRL-N means the | |
958 * command is aborted and we go to Normal mode. | |
959 */ | |
960 if (cp == &ca.extra_char | |
961 && ca.nchar == Ctrl_BSL | |
962 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
963 { | |
964 ca.cmdchar = Ctrl_BSL; | |
965 ca.nchar = ca.extra_char; | |
966 idx = find_command(ca.cmdchar); | |
967 } | |
3908 | 968 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 969 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 970 else if (*cp == Ctrl_BSL) |
971 { | |
972 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
973 | |
974 /* There is a busy wait here when typing "f<C-\>" and then | |
975 * something different from CTRL-N. Can't be avoided. */ | |
976 while ((c = vpeekc()) <= 0 && towait > 0L) | |
977 { | |
978 do_sleep(towait > 50L ? 50L : towait); | |
979 towait -= 50L; | |
980 } | |
981 if (c > 0) | |
982 { | |
1389 | 983 c = plain_vgetc(); |
7 | 984 if (c != Ctrl_N && c != Ctrl_G) |
985 vungetc(c); | |
986 else | |
987 { | |
988 ca.cmdchar = Ctrl_BSL; | |
989 ca.nchar = c; | |
990 idx = find_command(ca.cmdchar); | |
991 } | |
992 } | |
993 } | |
994 | |
995 /* When getting a text character and the next character is a | |
996 * multi-byte character, it could be a composing character. | |
6071 | 997 * However, don't wait for it to arrive. Also, do enable mapping, |
998 * because if it's put back with vungetc() it's too late to apply | |
999 * mapping. */ | |
1000 --no_mapping; | |
7 | 1001 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1002 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1003 { | |
1389 | 1004 c = plain_vgetc(); |
7 | 1005 if (!utf_iscomposing(c)) |
1006 { | |
1007 vungetc(c); /* it wasn't, put it back */ | |
1008 break; | |
1009 } | |
1010 else if (ca.ncharC1 == 0) | |
1011 ca.ncharC1 = c; | |
1012 else | |
1013 ca.ncharC2 = c; | |
1014 } | |
6071 | 1015 ++no_mapping; |
7 | 1016 } |
1017 --no_mapping; | |
1018 --allow_keys; | |
1019 } | |
1020 | |
1021 #ifdef FEAT_CMDL_INFO | |
1022 /* | |
1023 * Flush the showcmd characters onto the screen so we can see them while | |
1024 * the command is being executed. Only do this when the shown command was | |
1025 * actually displayed, otherwise this will slow down a lot when executing | |
1026 * mappings. | |
1027 */ | |
1028 if (need_flushbuf) | |
1029 out_flush(); | |
1030 #endif | |
1727 | 1031 if (ca.cmdchar != K_IGNORE) |
1032 did_cursorhold = FALSE; | |
7 | 1033 |
1034 State = NORMAL; | |
1035 | |
1036 if (ca.nchar == ESC) | |
1037 { | |
1038 clearop(oap); | |
1039 if (restart_edit == 0 && goto_im()) | |
1040 restart_edit = 'a'; | |
1041 goto normal_end; | |
1042 } | |
1043 | |
24 | 1044 if (ca.cmdchar != K_IGNORE) |
1045 { | |
1046 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1047 msg_col = 0; | |
1048 } | |
7 | 1049 |
1050 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1051 | |
1052 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1053 * mode. */ | |
1054 if (!VIsual_active && km_startsel) | |
1055 { | |
1056 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1057 { | |
1058 start_selection(); | |
1059 unshift_special(&ca); | |
1060 idx = find_command(ca.cmdchar); | |
1061 } | |
1062 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1063 && (mod_mask & MOD_MASK_SHIFT)) | |
1064 { | |
1065 start_selection(); | |
1066 mod_mask &= ~MOD_MASK_SHIFT; | |
1067 } | |
1068 } | |
1069 | |
1070 /* | |
1071 * Execute the command! | |
1072 * Call the command function found in the commands table. | |
1073 */ | |
1074 ca.arg = nv_cmds[idx].cmd_arg; | |
1075 (nv_cmds[idx].cmd_func)(&ca); | |
1076 | |
1077 /* | |
1078 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1079 * need it later. | |
1080 */ | |
1081 if (!finish_op | |
1082 && !oap->op_type | |
1083 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1084 { | |
1085 clearop(oap); | |
1086 #ifdef FEAT_EVAL | |
2821 | 1087 { |
1088 int regname = 0; | |
2829 | 1089 |
2821 | 1090 /* Adjust the register according to 'clipboard', so that when |
1091 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1092 # ifdef FEAT_CLIPBOARD |
2821 | 1093 adjust_clip_reg(®name); |
2829 | 1094 # endif |
2821 | 1095 set_reg_var(regname); |
1096 } | |
7 | 1097 #endif |
1098 } | |
1099 | |
570 | 1100 /* Get the length of mapped chars again after typing a count, second |
36 | 1101 * character or "z333<cr>". */ |
1102 if (old_mapped_len > 0) | |
1103 old_mapped_len = typebuf_maplen(); | |
1104 | |
7 | 1105 /* |
1106 * If an operation is pending, handle it... | |
1107 */ | |
1108 do_pending_operator(&ca, old_col, FALSE); | |
1109 | |
1110 /* | |
1111 * Wait for a moment when a message is displayed that will be overwritten | |
1112 * by the mode message. | |
1113 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1114 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1115 * In Visual mode, it's more important to keep the Visual area updated | |
1116 * than keeping a message (e.g. from a /pat search). | |
1117 * Only do this if the command was typed, not from a mapping. | |
1118 * Don't wait when emsg_silent is non-zero. | |
1119 * Also wait a bit after an error message, e.g. for "^O:". | |
1120 * Don't redraw the screen, it would remove the message. | |
1121 */ | |
1122 if ( ((p_smd | |
641 | 1123 && msg_silent == 0 |
7 | 1124 && (restart_edit != 0 |
1125 || (VIsual_active | |
1126 && old_pos.lnum == curwin->w_cursor.lnum | |
1127 && old_pos.col == curwin->w_cursor.col) | |
1128 ) | |
1129 && (clear_cmdline | |
1130 || redraw_cmdline) | |
1131 && (msg_didout || (msg_didany && msg_scroll)) | |
1132 && !msg_nowait | |
1133 && KeyTyped) | |
1134 || (restart_edit != 0 | |
1135 && !VIsual_active | |
1136 && (msg_scroll | |
1137 || emsg_on_display))) | |
1138 && oap->regname == 0 | |
1139 && !(ca.retval & CA_COMMAND_BUSY) | |
1140 && stuff_empty() | |
1141 && typebuf_typed() | |
1142 && emsg_silent == 0 | |
1143 && !did_wait_return | |
1144 && oap->op_type == OP_NOP) | |
1145 { | |
1146 int save_State = State; | |
1147 | |
1148 /* Draw the cursor with the right shape here */ | |
1149 if (restart_edit != 0) | |
1150 State = INSERT; | |
1151 | |
1152 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1153 * delay */ | |
1154 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1155 { | |
1156 char_u *kmsg; | |
1157 | |
1158 kmsg = keep_msg; | |
1159 keep_msg = NULL; | |
18045
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1160 // showmode() will clear keep_msg, but we want to use it anyway |
7 | 1161 update_screen(0); |
18045
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1162 // now reset it, otherwise it's put in the history again |
7 | 1163 keep_msg = kmsg; |
18045
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1164 |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1165 kmsg = vim_strsave(keep_msg); |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1166 if (kmsg != NULL) |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1167 { |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1168 msg_attr((char *)kmsg, keep_msg_attr); |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1169 vim_free(kmsg); |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1170 } |
7 | 1171 } |
1172 setcursor(); | |
1173 cursor_on(); | |
1174 out_flush(); | |
1175 if (msg_scroll || emsg_on_display) | |
1176 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1177 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1178 State = save_State; | |
1179 | |
1180 msg_scroll = FALSE; | |
1181 emsg_on_display = FALSE; | |
1182 } | |
1183 | |
1184 /* | |
1185 * Finish up after executing a Normal mode command. | |
1186 */ | |
1187 normal_end: | |
1188 | |
1189 msg_nowait = FALSE; | |
1190 | |
1191 /* Reset finish_op, in case it was set */ | |
1192 #ifdef CURSOR_SHAPE | |
1193 c = finish_op; | |
1194 #endif | |
1195 finish_op = FALSE; | |
1196 #ifdef CURSOR_SHAPE | |
1197 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1198 * mode or did a replace command. */ | |
1199 if (c || ca.cmdchar == 'r') | |
1200 { | |
1201 ui_cursor_shape(); /* may show different cursor shape */ | |
1202 # ifdef FEAT_MOUSESHAPE | |
1203 update_mouseshape(-1); | |
1204 # endif | |
1205 } | |
1206 #endif | |
1207 | |
1208 #ifdef FEAT_CMDL_INFO | |
1692 | 1209 if (oap->op_type == OP_NOP && oap->regname == 0 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1210 && ca.cmdchar != K_CURSORHOLD) |
7 | 1211 clear_showcmd(); |
1212 #endif | |
1213 | |
1214 checkpcmark(); /* check if we moved since setting pcmark */ | |
1215 vim_free(ca.searchbuf); | |
1216 | |
1217 if (has_mbyte) | |
1218 mb_adjust_cursor(); | |
1219 | |
1220 if (curwin->w_p_scb && toplevel) | |
1221 { | |
1222 validate_cursor(); /* may need to update w_leftcol */ | |
1223 do_check_scrollbind(TRUE); | |
1224 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1225 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1226 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1227 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1228 validate_cursor(); /* may need to update w_leftcol */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1229 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1230 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1231 |
12134
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1232 #ifdef FEAT_TERMINAL |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
1233 /* don't go to Insert mode if a terminal has a running job */ |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
1234 if (term_job_running(curbuf->b_term)) |
12134
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1235 restart_edit = 0; |
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1236 #endif |
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1237 |
7 | 1238 /* |
1239 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1240 * if still inside a mapping that started in Visual mode). | |
1241 * May switch from Visual to Select mode after CTRL-O command. | |
1242 */ | |
1243 if ( oap->op_type == OP_NOP | |
1244 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1245 || restart_VIsual_select == 1) | |
1246 && !(ca.retval & CA_COMMAND_BUSY) | |
1247 && stuff_empty() | |
1248 && oap->regname == 0) | |
1249 { | |
1250 if (restart_VIsual_select == 1) | |
1251 { | |
1252 VIsual_select = TRUE; | |
1253 showmode(); | |
1254 restart_VIsual_select = 0; | |
1255 } | |
5735 | 1256 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1257 (void)edit(restart_edit, FALSE, 1L); |
1258 } | |
1259 | |
1260 if (restart_VIsual_select == 2) | |
1261 restart_VIsual_select = 1; | |
1262 | |
1263 /* Save count before an operator for next time. */ | |
1264 opcount = ca.opcount; | |
1265 } | |
1266 | |
2667 | 1267 #ifdef FEAT_EVAL |
1268 /* | |
1269 * Set v:count and v:count1 according to "cap". | |
1270 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1271 */ | |
1272 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1273 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1274 { |
1275 long count = cap->count0; | |
1276 | |
1277 /* multiply with cap->opcount the same way as above */ | |
1278 if (cap->opcount != 0) | |
1279 count = cap->opcount * (count == 0 ? 1 : count); | |
1280 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1281 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1282 } | |
1283 #endif | |
1284 | |
7 | 1285 /* |
1286 * Check if highlighting for visual mode is possible, give a warning message | |
1287 * if not. | |
1288 */ | |
1289 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1290 check_visual_highlight(void) |
7 | 1291 { |
1292 static int did_check = FALSE; | |
1293 | |
1294 if (full_screen) | |
1295 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1296 if (!did_check && HL_ATTR(HLF_V) == 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1297 msg(_("Warning: terminal cannot highlight")); |
7 | 1298 did_check = TRUE; |
1299 } | |
1300 } | |
1301 | |
1302 /* | |
638 | 1303 * End Visual mode. |
7 | 1304 * This function should ALWAYS be called to end Visual mode, except from |
1305 * do_pending_operator(). | |
1306 */ | |
1307 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1308 end_visual_mode(void) |
7 | 1309 { |
1310 #ifdef FEAT_CLIPBOARD | |
1311 /* | |
1312 * If we are using the clipboard, then remember what was selected in case | |
1313 * we need to paste it somewhere while we still own the selection. | |
1314 * Only do this when the clipboard is already owned. Don't want to grab | |
1315 * the selection when hitting ESC. | |
1316 */ | |
1317 if (clip_star.available && clip_star.owned) | |
1318 clip_auto_select(); | |
1319 #endif | |
1320 | |
1321 VIsual_active = FALSE; | |
1322 #ifdef FEAT_MOUSE | |
1323 setmouse(); | |
1324 mouse_dragging = 0; | |
1325 #endif | |
1326 | |
1327 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 1328 curbuf->b_visual.vi_mode = VIsual_mode; |
1329 curbuf->b_visual.vi_start = VIsual; | |
1330 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1331 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 1332 #ifdef FEAT_EVAL |
1333 curbuf->b_visual_mode_eval = VIsual_mode; | |
1334 #endif | |
1335 if (!virtual_active()) | |
1336 curwin->w_cursor.coladd = 0; | |
6979 | 1337 may_clear_cmdline(); |
7 | 1338 |
844 | 1339 adjust_cursor_eol(); |
7 | 1340 } |
1341 | |
1342 /* | |
1343 * Reset VIsual_active and VIsual_reselect. | |
1344 */ | |
1345 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1346 reset_VIsual_and_resel(void) |
7 | 1347 { |
1348 if (VIsual_active) | |
1349 { | |
1350 end_visual_mode(); | |
1351 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
1352 } | |
1353 VIsual_reselect = FALSE; | |
1354 } | |
1355 | |
1356 /* | |
1357 * Reset VIsual_active and VIsual_reselect if it's set. | |
1358 */ | |
1359 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1360 reset_VIsual(void) |
7 | 1361 { |
1362 if (VIsual_active) | |
1363 { | |
1364 end_visual_mode(); | |
1365 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
1366 VIsual_reselect = FALSE; | |
1367 } | |
1368 } | |
1369 | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1370 void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1371 restore_visual_mode(void) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1372 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1373 if (VIsual_mode_orig != NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1374 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1375 curbuf->b_visual.vi_mode = VIsual_mode_orig; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1376 VIsual_mode_orig = NUL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1377 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1378 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1379 |
7 | 1380 /* |
1381 * Check for a balloon-eval special item to include when searching for an | |
1382 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
1383 * Returns TRUE if the character at "*ptr" should be included. | |
1384 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
1385 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
1386 * "bnp" points to a counter for square brackets. | |
1387 */ | |
1388 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1389 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1390 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1391 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1392 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1393 int dir) |
7 | 1394 { |
1395 /* Accept everything inside []. */ | |
1396 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
1397 ++*bnp; | |
1398 if (*bnp > 0) | |
1399 { | |
1400 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
1401 --*bnp; | |
1402 return TRUE; | |
1403 } | |
1404 | |
1405 /* skip over "s.var" */ | |
1406 if (*ptr == '.') | |
1407 return TRUE; | |
1408 | |
1409 /* two-character item: s->var */ | |
1410 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
1411 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
1412 { | |
1413 *colp += dir; | |
1414 return TRUE; | |
1415 } | |
1416 return FALSE; | |
1417 } | |
1418 | |
1419 /* | |
1420 * Find the identifier under or to the right of the cursor. | |
1421 * "find_type" can have one of three values: | |
1422 * FIND_IDENT: find an identifier (keyword) | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1423 * FIND_STRING: find any non-white text |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1424 * FIND_IDENT + FIND_STRING: find any non-white text, identifier preferred. |
184 | 1425 * FIND_EVAL: find text useful for C program debugging |
7 | 1426 * |
1427 * There are three steps: | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1428 * 1. Search forward for the start of an identifier/text. Doesn't move if |
7 | 1429 * already on one. |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1430 * 2. Search backward for the start of this identifier/text. |
7 | 1431 * This doesn't match the real Vi but I like it a little better and it |
1432 * shouldn't bother anyone. | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1433 * 3. Search forward to the end of this identifier/text. |
7 | 1434 * When FIND_IDENT isn't defined, we backup until a blank. |
1435 * | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1436 * Returns the length of the text, or zero if no text is found. |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1437 * If text is found, a pointer to the text is put in "*text". This |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1438 * points into the current buffer line and is not always NUL terminated. |
7 | 1439 */ |
1440 int | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1441 find_ident_under_cursor(char_u **text, int find_type) |
7 | 1442 { |
1443 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1444 curwin->w_cursor.col, text, NULL, find_type); |
7 | 1445 } |
1446 | |
1447 /* | |
1448 * Like find_ident_under_cursor(), but for any window and any position. | |
1449 * However: Uses 'iskeyword' from the current window!. | |
1450 */ | |
1451 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1452 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1453 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1454 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1455 colnr_T startcol, |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1456 char_u **text, |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1457 int *textcol, // column where "text" starts, can be NULL |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1458 int find_type) |
7 | 1459 { |
1460 char_u *ptr; | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1461 int col = 0; // init to shut up GCC |
7 | 1462 int i; |
1463 int this_class = 0; | |
1464 int prev_class; | |
1465 int prevcol; | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1466 int bn = 0; // bracket nesting |
7 | 1467 |
1468 /* | |
1469 * if i == 0: try to find an identifier | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1470 * if i == 1: try to find any non-white text |
7 | 1471 */ |
1472 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
1473 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
1474 { | |
1475 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1476 * 1. skip to start of identifier/text |
7 | 1477 */ |
1478 col = startcol; | |
1479 if (has_mbyte) | |
1480 { | |
1481 while (ptr[col] != NUL) | |
1482 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1483 // Stop at a ']' to evaluate "a[x]". |
7 | 1484 if ((find_type & FIND_EVAL) && ptr[col] == ']') |
1485 break; | |
1486 this_class = mb_get_class(ptr + col); | |
1487 if (this_class != 0 && (i == 1 || this_class != 1)) | |
1488 break; | |
474 | 1489 col += (*mb_ptr2len)(ptr + col); |
7 | 1490 } |
1491 } | |
1492 else | |
1493 while (ptr[col] != NUL | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1494 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 1495 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
1496 ) | |
1497 ++col; | |
1498 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1499 // When starting on a ']' count it, so that we include the '['. |
7 | 1500 bn = ptr[col] == ']'; |
1501 | |
1502 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1503 * 2. Back up to start of identifier/text. |
7 | 1504 */ |
1505 if (has_mbyte) | |
1506 { | |
1507 /* Remember class of character under cursor. */ | |
1508 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
1509 this_class = mb_get_class((char_u *)"a"); | |
1510 else | |
1511 this_class = mb_get_class(ptr + col); | |
835 | 1512 while (col > 0 && this_class != 0) |
7 | 1513 { |
1514 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
1515 prev_class = mb_get_class(ptr + prevcol); | |
1516 if (this_class != prev_class | |
1517 && (i == 0 | |
1518 || prev_class == 0 | |
1519 || (find_type & FIND_IDENT)) | |
1520 && (!(find_type & FIND_EVAL) | |
1521 || prevcol == 0 | |
1522 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
1523 &bn, BACKWARD)) | |
1524 ) | |
1525 break; | |
1526 col = prevcol; | |
1527 } | |
1528 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1529 // If we don't want just any old text, or we've found an |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1530 // identifier, stop searching. |
7 | 1531 if (this_class > 2) |
1532 this_class = 2; | |
1533 if (!(find_type & FIND_STRING) || this_class == 2) | |
1534 break; | |
1535 } | |
1536 else | |
1537 { | |
1538 while (col > 0 | |
1539 && ((i == 0 | |
1540 ? vim_iswordc(ptr[col - 1]) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1541 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 1542 && (!(find_type & FIND_IDENT) |
1543 || !vim_iswordc(ptr[col - 1])))) | |
1544 || ((find_type & FIND_EVAL) | |
1545 && col > 1 | |
1546 && find_is_eval_item(ptr + col - 1, &col, | |
1547 &bn, BACKWARD)) | |
1548 )) | |
1549 --col; | |
1550 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1551 // If we don't want just any old text, or we've found an |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1552 // identifier, stop searching. |
7 | 1553 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) |
1554 break; | |
1555 } | |
1556 } | |
1557 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1558 if (ptr[col] == NUL || (i == 0 |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1559 && (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col])))) |
7 | 1560 { |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1561 // didn't find an identifier or text |
16908
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1562 if ((find_type & FIND_NOERROR) == 0) |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1563 { |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1564 if (find_type & FIND_STRING) |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1565 emsg(_("E348: No string under cursor")); |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1566 else |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1567 emsg(_(e_noident)); |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1568 } |
7 | 1569 return 0; |
1570 } | |
1571 ptr += col; | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1572 *text = ptr; |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1573 if (textcol != NULL) |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1574 *textcol = col; |
7 | 1575 |
1576 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1577 * 3. Find the end if the identifier/text. |
7 | 1578 */ |
1579 bn = 0; | |
1580 startcol -= col; | |
1581 col = 0; | |
1582 if (has_mbyte) | |
1583 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1584 // Search for point of changing multibyte character class. |
7 | 1585 this_class = mb_get_class(ptr); |
1586 while (ptr[col] != NUL | |
1587 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
1588 : mb_get_class(ptr + col) != 0) | |
1589 || ((find_type & FIND_EVAL) | |
1590 && col <= (int)startcol | |
1591 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
1592 )) | |
474 | 1593 col += (*mb_ptr2len)(ptr + col); |
7 | 1594 } |
1595 else | |
1596 while ((i == 0 ? vim_iswordc(ptr[col]) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1597 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 1598 || ((find_type & FIND_EVAL) |
1599 && col <= (int)startcol | |
1600 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
1601 ) | |
1602 ++col; | |
1603 | |
1604 return col; | |
1605 } | |
1606 | |
1607 /* | |
1608 * Prepare for redo of a normal command. | |
1609 */ | |
1610 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1611 prep_redo_cmd(cmdarg_T *cap) |
7 | 1612 { |
1613 prep_redo(cap->oap->regname, cap->count0, | |
1614 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
1615 } | |
1616 | |
1617 /* | |
1618 * Prepare for redo of any command. | |
1619 * Note that only the last argument can be a multi-byte char. | |
1620 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
1621 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1622 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1623 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1624 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1625 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1626 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1627 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1628 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1629 int cmd5) |
7 | 1630 { |
1631 ResetRedobuff(); | |
1632 if (regname != 0) /* yank from specified buffer */ | |
1633 { | |
1634 AppendCharToRedobuff('"'); | |
1635 AppendCharToRedobuff(regname); | |
1636 } | |
1637 if (num) | |
1638 AppendNumberToRedobuff(num); | |
1639 | |
1640 if (cmd1 != NUL) | |
1641 AppendCharToRedobuff(cmd1); | |
1642 if (cmd2 != NUL) | |
1643 AppendCharToRedobuff(cmd2); | |
1644 if (cmd3 != NUL) | |
1645 AppendCharToRedobuff(cmd3); | |
1646 if (cmd4 != NUL) | |
1647 AppendCharToRedobuff(cmd4); | |
1648 if (cmd5 != NUL) | |
1649 AppendCharToRedobuff(cmd5); | |
1650 } | |
1651 | |
1652 /* | |
1653 * check for operator active and clear it | |
1654 * | |
1655 * return TRUE if operator was active | |
1656 */ | |
1657 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1658 checkclearop(oparg_T *oap) |
7 | 1659 { |
1660 if (oap->op_type == OP_NOP) | |
1661 return FALSE; | |
1662 clearopbeep(oap); | |
1663 return TRUE; | |
1664 } | |
1665 | |
1666 /* | |
1131 | 1667 * Check for operator or Visual active. Clear active operator. |
7 | 1668 * |
1131 | 1669 * Return TRUE if operator or Visual was active. |
7 | 1670 */ |
1671 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1672 checkclearopq(oparg_T *oap) |
7 | 1673 { |
5735 | 1674 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 1675 return FALSE; |
1676 clearopbeep(oap); | |
1677 return TRUE; | |
1678 } | |
1679 | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
1680 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1681 clearop(oparg_T *oap) |
7 | 1682 { |
1683 oap->op_type = OP_NOP; | |
1684 oap->regname = 0; | |
1685 oap->motion_force = NUL; | |
1686 oap->use_reg_one = FALSE; | |
1687 } | |
1688 | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
1689 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1690 clearopbeep(oparg_T *oap) |
7 | 1691 { |
1692 clearop(oap); | |
1693 beep_flush(); | |
1694 } | |
1695 | |
1696 /* | |
1697 * Remove the shift modifier from a special key. | |
1698 */ | |
1699 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1700 unshift_special(cmdarg_T *cap) |
7 | 1701 { |
1702 switch (cap->cmdchar) | |
1703 { | |
1704 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
1705 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
1706 case K_S_UP: cap->cmdchar = K_UP; break; | |
1707 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
1708 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
1709 case K_S_END: cap->cmdchar = K_END; break; | |
1710 } | |
1711 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
1712 } | |
1713 | |
6979 | 1714 /* |
1715 * If the mode is currently displayed clear the command line or update the | |
1716 * command displayed. | |
1717 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1718 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1719 may_clear_cmdline(void) |
6979 | 1720 { |
1721 if (mode_displayed) | |
1722 clear_cmdline = TRUE; /* unshow visual mode later */ | |
1723 #ifdef FEAT_CMDL_INFO | |
1724 else | |
1725 clear_showcmd(); | |
1726 #endif | |
1727 } | |
1728 | |
7 | 1729 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
1730 /* | |
1731 * Routines for displaying a partly typed command | |
1732 */ | |
1733 | |
5735 | 1734 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 1735 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
1736 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
1737 static int showcmd_is_clear = TRUE; | |
1738 static int showcmd_visual = FALSE; | |
1739 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
1740 static void display_showcmd(void); |
7 | 1741 |
1742 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1743 clear_showcmd(void) |
7 | 1744 { |
1745 if (!p_sc) | |
1746 return; | |
1747 | |
1748 if (VIsual_active && !char_avail()) | |
1749 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1750 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 1751 long lines; |
1752 colnr_T leftcol, rightcol; | |
1753 linenr_T top, bot; | |
1754 | |
1755 /* Show the size of the Visual area. */ | |
1866 | 1756 if (cursor_bot) |
7 | 1757 { |
1758 top = VIsual.lnum; | |
1759 bot = curwin->w_cursor.lnum; | |
1760 } | |
1761 else | |
1762 { | |
1763 top = curwin->w_cursor.lnum; | |
1764 bot = VIsual.lnum; | |
1765 } | |
1766 # ifdef FEAT_FOLDING | |
1767 /* Include closed folds as a whole. */ | |
7009 | 1768 (void)hasFolding(top, &top, NULL); |
1769 (void)hasFolding(bot, NULL, &bot); | |
7 | 1770 # endif |
1771 lines = bot - top + 1; | |
1772 | |
1773 if (VIsual_mode == Ctrl_V) | |
1774 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1775 # ifdef FEAT_LINEBREAK |
1866 | 1776 char_u *saved_sbr = p_sbr; |
1777 | |
1778 /* Make 'sbr' empty for a moment to get the correct size. */ | |
1779 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1780 # endif |
7 | 1781 getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1782 # ifdef FEAT_LINEBREAK |
1866 | 1783 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1784 # endif |
7 | 1785 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
1786 (long)(rightcol - leftcol + 1)); | |
1787 } | |
1788 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
1789 sprintf((char *)showcmd_buf, "%ld", lines); | |
1790 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1791 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1792 char_u *s, *e; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1793 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1794 int bytes = 0; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1795 int chars = 0; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1796 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1797 if (cursor_bot) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1798 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1799 s = ml_get_pos(&VIsual); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1800 e = ml_get_cursor(); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1801 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1802 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1803 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1804 s = ml_get_cursor(); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1805 e = ml_get_pos(&VIsual); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1806 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1807 while ((*p_sel != 'e') ? s <= e : s < e) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1808 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1809 l = (*mb_ptr2len)(s); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1810 if (l == 0) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1811 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1812 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1813 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1814 break; /* end of line */ |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1815 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1816 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1817 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1818 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1819 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1820 if (bytes == chars) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1821 sprintf((char *)showcmd_buf, "%d", chars); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1822 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1823 sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1824 } |
7 | 1825 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
1826 showcmd_visual = TRUE; | |
1827 } | |
1828 else | |
1829 { | |
1830 showcmd_buf[0] = NUL; | |
1831 showcmd_visual = FALSE; | |
1832 | |
1833 /* Don't actually display something if there is nothing to clear. */ | |
1834 if (showcmd_is_clear) | |
1835 return; | |
1836 } | |
1837 | |
1838 display_showcmd(); | |
1839 } | |
1840 | |
1841 /* | |
1842 * Add 'c' to string of shown command chars. | |
1843 * Return TRUE if output has been written (and setcursor() has been called). | |
1844 */ | |
1845 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1846 add_to_showcmd(int c) |
7 | 1847 { |
1848 char_u *p; | |
1849 int old_len; | |
1850 int extra_len; | |
1851 int overflow; | |
1852 #if defined(FEAT_MOUSE) | |
1853 int i; | |
1854 static int ignore[] = | |
1855 { | |
660 | 1856 # ifdef FEAT_GUI |
7 | 1857 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
1858 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 1859 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1860 K_IGNORE, K_PS, |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1861 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 1862 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
1863 K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE, | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1864 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 1865 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 1866 K_CURSORHOLD, |
7 | 1867 0 |
1868 }; | |
1869 #endif | |
1870 | |
641 | 1871 if (!p_sc || msg_silent != 0) |
7 | 1872 return FALSE; |
1873 | |
1874 if (showcmd_visual) | |
1875 { | |
1876 showcmd_buf[0] = NUL; | |
1877 showcmd_visual = FALSE; | |
1878 } | |
1879 | |
1880 #if defined(FEAT_MOUSE) | |
1881 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
1882 if (IS_SPECIAL(c)) | |
1883 for (i = 0; ignore[i] != 0; ++i) | |
1884 if (ignore[i] == c) | |
1885 return FALSE; | |
1886 #endif | |
1887 | |
1888 p = transchar(c); | |
5535 | 1889 if (*p == ' ') |
1890 STRCPY(p, "<20>"); | |
7 | 1891 old_len = (int)STRLEN(showcmd_buf); |
1892 extra_len = (int)STRLEN(p); | |
1893 overflow = old_len + extra_len - SHOWCMD_COLS; | |
1894 if (overflow > 0) | |
1362 | 1895 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
1896 old_len - overflow + 1); | |
7 | 1897 STRCAT(showcmd_buf, p); |
1898 | |
1899 if (char_avail()) | |
1900 return FALSE; | |
1901 | |
1902 display_showcmd(); | |
1903 | |
1904 return TRUE; | |
1905 } | |
1906 | |
1907 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1908 add_to_showcmd_c(int c) |
7 | 1909 { |
1910 if (!add_to_showcmd(c)) | |
1911 setcursor(); | |
1912 } | |
1913 | |
1914 /* | |
1915 * Delete 'len' characters from the end of the shown command. | |
1916 */ | |
1917 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1918 del_from_showcmd(int len) |
7 | 1919 { |
1920 int old_len; | |
1921 | |
1922 if (!p_sc) | |
1923 return; | |
1924 | |
1925 old_len = (int)STRLEN(showcmd_buf); | |
1926 if (len > old_len) | |
1927 len = old_len; | |
1928 showcmd_buf[old_len - len] = NUL; | |
1929 | |
1930 if (!char_avail()) | |
1931 display_showcmd(); | |
1932 } | |
1933 | |
1934 /* | |
1935 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
1936 * something and there is a partial mapping. | |
1937 */ | |
1938 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1939 push_showcmd(void) |
7 | 1940 { |
1941 if (p_sc) | |
1942 STRCPY(old_showcmd_buf, showcmd_buf); | |
1943 } | |
1944 | |
1945 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1946 pop_showcmd(void) |
7 | 1947 { |
1948 if (!p_sc) | |
1949 return; | |
1950 | |
1951 STRCPY(showcmd_buf, old_showcmd_buf); | |
1952 | |
1953 display_showcmd(); | |
1954 } | |
1955 | |
1956 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1957 display_showcmd(void) |
7 | 1958 { |
1959 int len; | |
1960 | |
1961 cursor_off(); | |
1962 | |
1963 len = (int)STRLEN(showcmd_buf); | |
1964 if (len == 0) | |
1965 showcmd_is_clear = TRUE; | |
1966 else | |
1967 { | |
1968 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
1969 showcmd_is_clear = FALSE; | |
1970 } | |
1971 | |
1972 /* | |
1188 | 1973 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
1974 * spaces | |
7 | 1975 */ |
1976 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
1977 | |
1978 setcursor(); /* put cursor back where it belongs */ | |
1979 } | |
1980 #endif | |
1981 | |
1982 /* | |
1983 * When "check" is FALSE, prepare for commands that scroll the window. | |
1984 * When "check" is TRUE, take care of scroll-binding after the window has | |
1985 * scrolled. Called from normal_cmd() and edit(). | |
1986 */ | |
1987 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1988 do_check_scrollbind(int check) |
7 | 1989 { |
1990 static win_T *old_curwin = NULL; | |
1991 static linenr_T old_topline = 0; | |
1992 #ifdef FEAT_DIFF | |
1993 static int old_topfill = 0; | |
1994 #endif | |
1995 static buf_T *old_buf = NULL; | |
1996 static colnr_T old_leftcol = 0; | |
1997 | |
1998 if (check && curwin->w_p_scb) | |
1999 { | |
2000 /* If a ":syncbind" command was just used, don't scroll, only reset | |
2001 * the values. */ | |
2002 if (did_syncbind) | |
2003 did_syncbind = FALSE; | |
2004 else if (curwin == old_curwin) | |
2005 { | |
2006 /* | |
2007 * Synchronize other windows, as necessary according to | |
2008 * 'scrollbind'. Don't do this after an ":edit" command, except | |
2009 * when 'diff' is set. | |
2010 */ | |
2011 if ((curwin->w_buffer == old_buf | |
2012 #ifdef FEAT_DIFF | |
2013 || curwin->w_p_diff | |
2014 #endif | |
2015 ) | |
2016 && (curwin->w_topline != old_topline | |
2017 #ifdef FEAT_DIFF | |
2018 || curwin->w_topfill != old_topfill | |
2019 #endif | |
2020 || curwin->w_leftcol != old_leftcol)) | |
2021 { | |
2022 check_scrollbind(curwin->w_topline - old_topline, | |
2023 (long)(curwin->w_leftcol - old_leftcol)); | |
2024 } | |
2025 } | |
2026 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
2027 { | |
2028 /* | |
2029 * When switching between windows, make sure that the relative | |
2030 * vertical offset is valid for the new window. The relative | |
2031 * offset is invalid whenever another 'scrollbind' window has | |
2032 * scrolled to a point that would force the current window to | |
2033 * scroll past the beginning or end of its buffer. When the | |
2034 * resync is performed, some of the other 'scrollbind' windows may | |
2035 * need to jump so that the current window's relative position is | |
2036 * visible on-screen. | |
2037 */ | |
2038 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
2039 } | |
2040 curwin->w_scbind_pos = curwin->w_topline; | |
2041 } | |
2042 | |
2043 old_curwin = curwin; | |
2044 old_topline = curwin->w_topline; | |
2045 #ifdef FEAT_DIFF | |
2046 old_topfill = curwin->w_topfill; | |
2047 #endif | |
2048 old_buf = curwin->w_buffer; | |
2049 old_leftcol = curwin->w_leftcol; | |
2050 } | |
2051 | |
2052 /* | |
2053 * Synchronize any windows that have "scrollbind" set, based on the | |
2054 * number of rows by which the current window has changed | |
2055 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
2056 */ | |
2057 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2058 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 2059 { |
2060 int want_ver; | |
2061 int want_hor; | |
2062 win_T *old_curwin = curwin; | |
2063 buf_T *old_curbuf = curbuf; | |
2064 int old_VIsual_select = VIsual_select; | |
2065 int old_VIsual_active = VIsual_active; | |
2066 colnr_T tgt_leftcol = curwin->w_leftcol; | |
2067 long topline; | |
2068 long y; | |
2069 | |
2070 /* | |
2071 * check 'scrollopt' string for vertical and horizontal scroll options | |
2072 */ | |
2073 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
2074 #ifdef FEAT_DIFF | |
2075 want_ver |= old_curwin->w_p_diff; | |
2076 #endif | |
2077 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
2078 | |
2079 /* | |
2080 * loop through the scrollbound windows and scroll accordingly | |
2081 */ | |
2082 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
2083 FOR_ALL_WINDOWS(curwin) |
7 | 2084 { |
2085 curbuf = curwin->w_buffer; | |
2086 /* skip original window and windows with 'noscrollbind' */ | |
2087 if (curwin != old_curwin && curwin->w_p_scb) | |
2088 { | |
2089 /* | |
2090 * do the vertical scroll | |
2091 */ | |
2092 if (want_ver) | |
2093 { | |
2094 #ifdef FEAT_DIFF | |
2095 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
2096 { | |
2097 diff_set_topline(old_curwin, curwin); | |
2098 } | |
2099 else | |
2100 #endif | |
2101 { | |
2102 curwin->w_scbind_pos += topline_diff; | |
2103 topline = curwin->w_scbind_pos; | |
2104 if (topline > curbuf->b_ml.ml_line_count) | |
2105 topline = curbuf->b_ml.ml_line_count; | |
2106 if (topline < 1) | |
2107 topline = 1; | |
2108 | |
2109 y = topline - curwin->w_topline; | |
2110 if (y > 0) | |
2111 scrollup(y, FALSE); | |
2112 else | |
2113 scrolldown(-y, FALSE); | |
2114 } | |
2115 | |
2116 redraw_later(VALID); | |
2117 cursor_correct(); | |
2118 curwin->w_redr_status = TRUE; | |
2119 } | |
2120 | |
2121 /* | |
2122 * do the horizontal scroll | |
2123 */ | |
2124 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
2125 { | |
2126 curwin->w_leftcol = tgt_leftcol; | |
2127 leftcol_changed(); | |
2128 } | |
2129 } | |
2130 } | |
2131 | |
2132 /* | |
2133 * reset current-window | |
2134 */ | |
2135 VIsual_select = old_VIsual_select; | |
2136 VIsual_active = old_VIsual_active; | |
2137 curwin = old_curwin; | |
2138 curbuf = old_curbuf; | |
2139 } | |
2140 | |
2141 /* | |
2142 * Command character that's ignored. | |
2143 * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
2144 * xon/xoff. |
7 | 2145 */ |
2146 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2147 nv_ignore(cmdarg_T *cap) |
7 | 2148 { |
226 | 2149 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 2150 } |
2151 | |
2152 /* | |
620 | 2153 * Command character that doesn't do anything, but unlike nv_ignore() does |
2154 * start edit(). Used for "startinsert" executed while starting up. | |
2155 */ | |
2156 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2157 nv_nop(cmdarg_T *cap UNUSED) |
620 | 2158 { |
2159 } | |
2160 | |
2161 /* | |
7 | 2162 * Command character doesn't exist. |
2163 */ | |
2164 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2165 nv_error(cmdarg_T *cap) |
7 | 2166 { |
2167 clearopbeep(cap->oap); | |
2168 } | |
2169 | |
2170 /* | |
2171 * <Help> and <F1> commands. | |
2172 */ | |
2173 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2174 nv_help(cmdarg_T *cap) |
7 | 2175 { |
2176 if (!checkclearopq(cap->oap)) | |
2177 ex_help(NULL); | |
2178 } | |
2179 | |
2180 /* | |
2181 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
2182 */ | |
2183 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2184 nv_addsub(cmdarg_T *cap) |
7 | 2185 { |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2186 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2187 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2188 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2189 else |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2190 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2191 if (!VIsual_active && cap->oap->op_type == OP_NOP) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2192 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2193 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2194 cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2195 op_addsub(cap->oap, cap->count1, cap->arg); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2196 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2197 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2198 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2199 nv_operator(cap); |
6868 | 2200 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2201 clearop(cap->oap); |
7 | 2202 } |
2203 | |
2204 /* | |
2205 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
2206 */ | |
2207 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2208 nv_page(cmdarg_T *cap) |
7 | 2209 { |
2210 if (!checkclearop(cap->oap)) | |
819 | 2211 { |
2212 if (mod_mask & MOD_MASK_CTRL) | |
2213 { | |
2214 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
2215 if (cap->arg == BACKWARD) | |
2216 goto_tabpage(-(int)cap->count1); | |
2217 else | |
2218 goto_tabpage((int)cap->count0); | |
2219 } | |
2220 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2221 (void)onepage(cap->arg, cap->count1); |
819 | 2222 } |
7 | 2223 } |
2224 | |
2225 /* | |
2226 * Implementation of "gd" and "gD" command. | |
2227 */ | |
2228 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2229 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2230 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2231 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2232 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 2233 { |
2234 int len; | |
503 | 2235 char_u *ptr; |
2236 | |
2237 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0 | |
8923
face93b02af4
commit https://github.com/vim/vim/commit/1538fc34fae3fae39773ca43f6ff52401fce61d8
Christian Brabandt <cb@256bit.org>
parents:
8651
diff
changeset
|
2238 || find_decl(ptr, len, nchar == 'd', thisblock, SEARCH_START) |
face93b02af4
commit https://github.com/vim/vim/commit/1538fc34fae3fae39773ca43f6ff52401fce61d8
Christian Brabandt <cb@256bit.org>
parents:
8651
diff
changeset
|
2239 == FAIL) |
503 | 2240 clearopbeep(oap); |
2241 #ifdef FEAT_FOLDING | |
2242 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
2243 foldOpenCursor(); | |
2244 #endif | |
2245 } | |
2246 | |
2247 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2248 * Return TRUE if line[offset] is not inside a C-style comment or string, FALSE |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2249 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2250 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2251 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2252 is_ident(char_u *line, int offset) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2253 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2254 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2255 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2256 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2257 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2258 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2259 for (i = 0; i < offset && line[i] != NUL; i++) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2260 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2261 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2262 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2263 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2264 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2265 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2266 else if ((line[i] == '"' || line[i] == '\'') && !incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2267 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2268 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2269 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2270 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2271 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2272 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2273 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2274 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2275 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2276 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2277 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2278 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2279 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2280 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2281 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2282 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2283 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2284 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2285 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2286 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2287 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2288 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2289 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2290 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2291 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2292 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2293 /* |
523 | 2294 * Search for variable declaration of "ptr[len]". |
2295 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
2296 * current file ("gD"). | |
2297 * When "thisblock" is TRUE check the {} block scope. | |
503 | 2298 * Return FAIL when not found. |
2299 */ | |
2300 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2301 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2302 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2303 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2304 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2305 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
2306 int flags_arg) /* flags passed to searchit() */ |
503 | 2307 { |
7 | 2308 char_u *pat; |
2309 pos_T old_pos; | |
503 | 2310 pos_T par_pos; |
2311 pos_T found_pos; | |
7 | 2312 int t; |
2313 int save_p_ws; | |
2314 int save_p_scs; | |
503 | 2315 int retval = OK; |
944 | 2316 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
2317 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2318 int valid; |
503 | 2319 |
2320 if ((pat = alloc(len + 7)) == NULL) | |
2321 return FAIL; | |
268 | 2322 |
2323 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
2324 * and "~" causes trouble. */ | |
2325 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
2326 len, ptr); | |
7 | 2327 old_pos = curwin->w_cursor; |
2328 save_p_ws = p_ws; | |
2329 save_p_scs = p_scs; | |
2330 p_ws = FALSE; /* don't wrap around end of file now */ | |
2331 p_scs = FALSE; /* don't switch ignorecase off now */ | |
2332 | |
2333 /* | |
2334 * With "gD" go to line 1. | |
2335 * With "gd" Search back for the start of the current function, then go | |
2336 * back until a blank line. If this fails go to line 1. | |
2337 */ | |
944 | 2338 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 2339 { |
2340 setpcmark(); /* Set in findpar() otherwise */ | |
2341 curwin->w_cursor.lnum = 1; | |
539 | 2342 par_pos = curwin->w_cursor; |
7 | 2343 } |
2344 else | |
2345 { | |
539 | 2346 par_pos = curwin->w_cursor; |
7 | 2347 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
2348 --curwin->w_cursor.lnum; | |
2349 } | |
2350 curwin->w_cursor.col = 0; | |
2351 | |
2352 /* Search forward for the identifier, ignore comment lines. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2353 CLEAR_POS(&found_pos); |
503 | 2354 for (;;) |
2355 { | |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2356 t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, FORWARD, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11451
diff
changeset
|
2357 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 2358 if (curwin->w_cursor.lnum >= old_pos.lnum) |
2359 t = FAIL; /* match after start is failure too */ | |
523 | 2360 |
718 | 2361 if (thisblock && t != FAIL) |
523 | 2362 { |
2363 pos_T *pos; | |
2364 | |
2365 /* Check that the block the match is in doesn't end before the | |
2366 * position where we started the search from. */ | |
2367 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
2368 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
2369 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2370 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2371 /* There can't be a useful match before the end of this block. |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2372 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2373 curwin->w_cursor = *pos; |
523 | 2374 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2375 } |
523 | 2376 } |
2377 | |
503 | 2378 if (t == FAIL) |
2379 { | |
2380 /* If we previously found a valid position, use it. */ | |
2381 if (found_pos.lnum != 0) | |
2382 { | |
2383 curwin->w_cursor = found_pos; | |
2384 t = OK; | |
2385 } | |
2386 break; | |
2387 } | |
3562 | 2388 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 2389 { |
2390 /* Ignore this line, continue at start of next line. */ | |
2391 ++curwin->w_cursor.lnum; | |
2392 curwin->w_cursor.col = 0; | |
2393 continue; | |
2394 } | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2395 valid = is_ident(ml_get_curline(), curwin->w_cursor.col); |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2396 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2397 /* If the current position is not a valid identifier and a previous |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2398 * match is present, favor that one instead. */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2399 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2400 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2401 curwin->w_cursor = found_pos; |
503 | 2402 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2403 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2404 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2405 /* Global search: use first valid match found */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2406 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2407 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2408 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 2409 { |
2410 /* If we previously found a valid position, use it. */ | |
2411 if (found_pos.lnum != 0) | |
2412 curwin->w_cursor = found_pos; | |
2413 break; | |
2414 } | |
2415 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2416 /* For finding a local variable and the match is before the "{" or |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2417 * inside a comment, continue searching. For K&R style function |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2418 * declarations this skips the function header without types. */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2419 if (!valid) |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2420 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2421 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2422 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2423 /* Remove SEARCH_START from flags to avoid getting stuck at one |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2424 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
2425 searchflags &= ~SEARCH_START; |
503 | 2426 } |
2427 | |
2428 if (t == FAIL) | |
2429 { | |
2430 retval = FAIL; | |
7 | 2431 curwin->w_cursor = old_pos; |
2432 } | |
2433 else | |
2434 { | |
2435 curwin->w_set_curswant = TRUE; | |
2436 /* "n" searches forward now */ | |
2437 reset_search_dir(); | |
2438 } | |
2439 | |
2440 vim_free(pat); | |
2441 p_ws = save_p_ws; | |
2442 p_scs = save_p_scs; | |
503 | 2443 |
2444 return retval; | |
7 | 2445 } |
2446 | |
2447 /* | |
2448 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
2449 * lines rather than lines in the file. | |
2450 * 'dist' must be positive. | |
2451 * | |
2452 * Return OK if able to move cursor, FAIL otherwise. | |
2453 */ | |
2454 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2455 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 2456 { |
2457 int linelen = linetabsize(ml_get_curline()); | |
2458 int retval = OK; | |
2459 int atend = FALSE; | |
2460 int n; | |
2461 int col_off1; /* margin offset for first screen line */ | |
2462 int col_off2; /* margin offset for wrapped screen line */ | |
2463 int width1; /* text width for first screen line */ | |
2464 int width2; /* test width for wrapped screen line */ | |
2465 | |
2466 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
2467 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 2468 |
2469 col_off1 = curwin_col_off(); | |
2470 col_off2 = col_off1 - curwin_col_off2(); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2471 width1 = curwin->w_width - col_off1; |
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2472 width2 = curwin->w_width - col_off2; |
6559 | 2473 if (width2 == 0) |
2474 width2 = 1; /* avoid divide by zero */ | |
7 | 2475 |
2476 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
2477 { |
7 | 2478 /* |
2479 * Instead of sticking at the last character of the buffer line we | |
2480 * try to stick in the last column of the screen. | |
2481 */ | |
2482 if (curwin->w_curswant == MAXCOL) | |
2483 { | |
2484 atend = TRUE; | |
2485 validate_virtcol(); | |
2486 if (width1 <= 0) | |
2487 curwin->w_curswant = 0; | |
2488 else | |
2489 { | |
2490 curwin->w_curswant = width1 - 1; | |
2491 if (curwin->w_virtcol > curwin->w_curswant) | |
2492 curwin->w_curswant += ((curwin->w_virtcol | |
2493 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
2494 } | |
2495 } | |
2496 else | |
2497 { | |
2498 if (linelen > width1) | |
2499 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
2500 else | |
2501 n = width1; | |
2502 if (curwin->w_curswant > (colnr_T)n + 1) | |
2503 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
2504 * width2; | |
2505 } | |
2506 | |
2507 while (dist--) | |
2508 { | |
2509 if (dir == BACKWARD) | |
2510 { | |
18154
5e10ee16f4b4
patch 8.1.2072: "gk" moves to start of line instead of upwards
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2511 if ((long)curwin->w_curswant > width2) |
5e10ee16f4b4
patch 8.1.2072: "gk" moves to start of line instead of upwards
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2512 // move back within line |
7 | 2513 curwin->w_curswant -= width2; |
2514 else | |
2515 { | |
2516 /* to previous line */ | |
2517 if (curwin->w_cursor.lnum == 1) | |
2518 { | |
2519 retval = FAIL; | |
2520 break; | |
2521 } | |
2522 --curwin->w_cursor.lnum; | |
2523 #ifdef FEAT_FOLDING | |
2524 /* Move to the start of a closed fold. Don't do that when | |
2525 * 'foldopen' contains "all": it will open in a moment. */ | |
2526 if (!(fdo_flags & FDO_ALL)) | |
2527 (void)hasFolding(curwin->w_cursor.lnum, | |
2528 &curwin->w_cursor.lnum, NULL); | |
2529 #endif | |
2530 linelen = linetabsize(ml_get_curline()); | |
2531 if (linelen > width1) | |
2532 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
2533 + 1) * width2; | |
2534 } | |
2535 } | |
2536 else /* dir == FORWARD */ | |
2537 { | |
2538 if (linelen > width1) | |
2539 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
2540 else | |
2541 n = width1; | |
2542 if (curwin->w_curswant + width2 < (colnr_T)n) | |
2543 /* move forward within line */ | |
2544 curwin->w_curswant += width2; | |
2545 else | |
2546 { | |
2547 /* to next line */ | |
2548 #ifdef FEAT_FOLDING | |
2549 /* Move to the end of a closed fold. */ | |
2550 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
2551 &curwin->w_cursor.lnum); | |
2552 #endif | |
2553 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
2554 { | |
2555 retval = FAIL; | |
2556 break; | |
2557 } | |
2558 curwin->w_cursor.lnum++; | |
2559 curwin->w_curswant %= width2; | |
2911 | 2560 linelen = linetabsize(ml_get_curline()); |
7 | 2561 } |
2562 } | |
2563 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
2564 } |
7 | 2565 |
5600 | 2566 if (virtual_active() && atend) |
2567 coladvance(MAXCOL); | |
2568 else | |
2569 coladvance(curwin->w_curswant); | |
7 | 2570 |
2571 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
2572 { | |
6178 | 2573 colnr_T virtcol; |
2574 | |
7 | 2575 /* |
2576 * Check for landing on a character that got split at the end of the | |
2577 * last line. We want to advance a screenline, not end up in the same | |
2578 * screenline or move two screenlines. | |
2579 */ | |
2580 validate_virtcol(); | |
6178 | 2581 virtcol = curwin->w_virtcol; |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2582 #if defined(FEAT_LINEBREAK) |
6178 | 2583 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
2584 virtcol -= vim_strsize(p_sbr); | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2585 #endif |
6178 | 2586 |
2587 if (virtcol > curwin->w_curswant | |
7 | 2588 && (curwin->w_curswant < (colnr_T)width1 |
2589 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
2590 : ((curwin->w_curswant - width1) % width2 | |
2591 > (colnr_T)width2 / 2))) | |
2592 --curwin->w_cursor.col; | |
2593 } | |
2594 | |
2595 if (atend) | |
2596 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
2597 | |
2598 return retval; | |
2599 } | |
2600 | |
2601 /* | |
2602 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
2603 * cap->arg must be TRUE for CTRL-E. | |
2604 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
2605 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2606 nv_scroll_line(cmdarg_T *cap) |
7 | 2607 { |
2608 if (!checkclearop(cap->oap)) | |
2609 scroll_redraw(cap->arg, cap->count1); | |
2610 } | |
2611 | |
2612 /* | |
2613 * Scroll "count" lines up or down, and redraw. | |
2614 */ | |
2615 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2616 scroll_redraw(int up, long count) |
7 | 2617 { |
2618 linenr_T prev_topline = curwin->w_topline; | |
2619 #ifdef FEAT_DIFF | |
2620 int prev_topfill = curwin->w_topfill; | |
2621 #endif | |
2622 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
2623 | |
2624 if (up) | |
2625 scrollup(count, TRUE); | |
2626 else | |
2627 scrolldown(count, TRUE); | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2628 if (get_scrolloff_value()) |
7 | 2629 { |
2630 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
2631 * valid, otherwise the screen jumps back at the end of the file. */ | |
2632 cursor_correct(); | |
2633 check_cursor_moved(curwin); | |
2634 curwin->w_valid |= VALID_TOPLINE; | |
2635 | |
2636 /* If moved back to where we were, at least move the cursor, otherwise | |
2637 * we get stuck at one position. Don't move the cursor up if the | |
2638 * first line of the buffer is already on the screen */ | |
2639 while (curwin->w_topline == prev_topline | |
2640 #ifdef FEAT_DIFF | |
2641 && curwin->w_topfill == prev_topfill | |
2642 #endif | |
2643 ) | |
2644 { | |
2645 if (up) | |
2646 { | |
2647 if (curwin->w_cursor.lnum > prev_lnum | |
2648 || cursor_down(1L, FALSE) == FAIL) | |
2649 break; | |
2650 } | |
2651 else | |
2652 { | |
2653 if (curwin->w_cursor.lnum < prev_lnum | |
2654 || prev_topline == 1L | |
2655 || cursor_up(1L, FALSE) == FAIL) | |
2656 break; | |
2657 } | |
2658 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
2659 * end of the file. */ | |
2660 check_cursor_moved(curwin); | |
2661 curwin->w_valid |= VALID_TOPLINE; | |
2662 } | |
2663 } | |
2664 if (curwin->w_cursor.lnum != prev_lnum) | |
2665 coladvance(curwin->w_curswant); | |
2666 redraw_later(VALID); | |
2667 } | |
2668 | |
2669 /* | |
2670 * Commands that start with "z". | |
2671 */ | |
2672 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2673 nv_zet(cmdarg_T *cap) |
7 | 2674 { |
2675 long n; | |
2676 colnr_T col; | |
2677 int nchar = cap->nchar; | |
2678 #ifdef FEAT_FOLDING | |
2679 long old_fdl = curwin->w_p_fdl; | |
2680 int old_fen = curwin->w_p_fen; | |
2681 #endif | |
737 | 2682 #ifdef FEAT_SPELL |
710 | 2683 int undo = FALSE; |
2684 #endif | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2685 long siso = get_sidescrolloff_value(); |
7 | 2686 |
2687 if (VIM_ISDIGIT(nchar)) | |
2688 { | |
2689 /* | |
2690 * "z123{nchar}": edit the count before obtaining {nchar} | |
2691 */ | |
2692 if (checkclearop(cap->oap)) | |
2693 return; | |
2694 n = nchar - '0'; | |
2695 for (;;) | |
2696 { | |
2697 #ifdef USE_ON_FLY_SCROLL | |
2698 dont_scroll = TRUE; /* disallow scrolling here */ | |
2699 #endif | |
2700 ++no_mapping; | |
2701 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 2702 nchar = plain_vgetc(); |
7 | 2703 LANGMAP_ADJUST(nchar, TRUE); |
2704 --no_mapping; | |
2705 --allow_keys; | |
2706 #ifdef FEAT_CMDL_INFO | |
2707 (void)add_to_showcmd(nchar); | |
2708 #endif | |
2709 if (nchar == K_DEL || nchar == K_KDEL) | |
2710 n /= 10; | |
2711 else if (VIM_ISDIGIT(nchar)) | |
2712 n = n * 10 + (nchar - '0'); | |
2713 else if (nchar == CAR) | |
2714 { | |
2715 #ifdef FEAT_GUI | |
2716 need_mouse_correct = TRUE; | |
2717 #endif | |
2718 win_setheight((int)n); | |
2719 break; | |
2720 } | |
2721 else if (nchar == 'l' | |
2722 || nchar == 'h' | |
2723 || nchar == K_LEFT | |
229 | 2724 || nchar == K_RIGHT) |
7 | 2725 { |
2726 cap->count1 = n ? n * cap->count1 : cap->count1; | |
2727 goto dozet; | |
2728 } | |
2729 else | |
2730 { | |
2731 clearopbeep(cap->oap); | |
2732 break; | |
2733 } | |
2734 } | |
2735 cap->oap->op_type = OP_NOP; | |
2736 return; | |
2737 } | |
2738 | |
2739 dozet: | |
2740 if ( | |
2741 #ifdef FEAT_FOLDING | |
2742 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
2743 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
2744 * commands. */ | |
2745 cap->nchar != 'f' && cap->nchar != 'F' | |
2746 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
2747 && cap->nchar != 'j' && cap->nchar != 'k' | |
2748 && | |
2749 #endif | |
2750 checkclearop(cap->oap)) | |
2751 return; | |
2752 | |
2753 /* | |
2754 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
2755 * If line number given, set cursor. | |
2756 */ | |
2757 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
2758 && cap->count0 | |
2759 && cap->count0 != curwin->w_cursor.lnum) | |
2760 { | |
2761 setpcmark(); | |
2762 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
2763 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2764 else | |
2765 curwin->w_cursor.lnum = cap->count0; | |
22 | 2766 check_cursor_col(); |
7 | 2767 } |
2768 | |
2769 switch (nchar) | |
2770 { | |
2771 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
2772 case '+': | |
2773 if (cap->count0 == 0) | |
2774 { | |
2775 /* No count given: put cursor at the line below screen */ | |
2776 validate_botline(); /* make sure w_botline is valid */ | |
2777 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
2778 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2779 else | |
2780 curwin->w_cursor.lnum = curwin->w_botline; | |
2781 } | |
2782 /* FALLTHROUGH */ | |
2783 case NL: | |
2784 case CAR: | |
2785 case K_KENTER: | |
2786 beginline(BL_WHITE | BL_FIX); | |
2787 /* FALLTHROUGH */ | |
2788 | |
2789 case 't': scroll_cursor_top(0, TRUE); | |
2790 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
2791 set_fraction(curwin); |
7 | 2792 break; |
2793 | |
2794 /* "z." and "zz": put cursor in middle of screen */ | |
2795 case '.': beginline(BL_WHITE | BL_FIX); | |
2796 /* FALLTHROUGH */ | |
2797 | |
2798 case 'z': scroll_cursor_halfway(TRUE); | |
2799 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
2800 set_fraction(curwin); |
7 | 2801 break; |
2802 | |
2803 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
2804 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
2805 * when <count> is at bottom of window, and puts that one at | |
2806 * bottom of window. */ | |
2807 if (cap->count0 != 0) | |
2808 { | |
2809 scroll_cursor_bot(0, TRUE); | |
2810 curwin->w_cursor.lnum = curwin->w_topline; | |
2811 } | |
2812 else if (curwin->w_topline == 1) | |
2813 curwin->w_cursor.lnum = 1; | |
2814 else | |
2815 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
2816 /* FALLTHROUGH */ | |
2817 case '-': | |
2818 beginline(BL_WHITE | BL_FIX); | |
2819 /* FALLTHROUGH */ | |
2820 | |
2821 case 'b': scroll_cursor_bot(0, TRUE); | |
2822 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
2823 set_fraction(curwin); |
7 | 2824 break; |
2825 | |
2826 /* "zH" - scroll screen right half-page */ | |
2827 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2828 cap->count1 *= curwin->w_width / 2; |
7 | 2829 /* FALLTHROUGH */ |
2830 | |
2831 /* "zh" - scroll screen to the right */ | |
2832 case 'h': | |
2833 case K_LEFT: | |
2834 if (!curwin->w_p_wrap) | |
2835 { | |
2836 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
2837 curwin->w_leftcol = 0; | |
2838 else | |
2839 curwin->w_leftcol -= (colnr_T)cap->count1; | |
2840 leftcol_changed(); | |
2841 } | |
2842 break; | |
2843 | |
2844 /* "zL" - scroll screen left half-page */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2845 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 2846 /* FALLTHROUGH */ |
2847 | |
2848 /* "zl" - scroll screen to the left */ | |
2849 case 'l': | |
2850 case K_RIGHT: | |
2851 if (!curwin->w_p_wrap) | |
2852 { | |
2853 /* scroll the window left */ | |
2854 curwin->w_leftcol += (colnr_T)cap->count1; | |
2855 leftcol_changed(); | |
2856 } | |
2857 break; | |
2858 | |
2859 /* "zs" - scroll screen, cursor at the start */ | |
2860 case 's': if (!curwin->w_p_wrap) | |
2861 { | |
2862 #ifdef FEAT_FOLDING | |
2863 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
2864 col = 0; /* like the cursor is in col 0 */ | |
2865 else | |
2866 #endif | |
2867 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2868 if ((long)col > siso) |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2869 col -= siso; |
7 | 2870 else |
2871 col = 0; | |
2872 if (curwin->w_leftcol != col) | |
2873 { | |
2874 curwin->w_leftcol = col; | |
2875 redraw_later(NOT_VALID); | |
2876 } | |
2877 } | |
2878 break; | |
2879 | |
2880 /* "ze" - scroll screen, cursor at the end */ | |
2881 case 'e': if (!curwin->w_p_wrap) | |
2882 { | |
2883 #ifdef FEAT_FOLDING | |
2884 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
2885 col = 0; /* like the cursor is in col 0 */ | |
2886 else | |
2887 #endif | |
2888 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2889 n = curwin->w_width - curwin_col_off(); |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2890 if ((long)col + siso < n) |
7 | 2891 col = 0; |
2892 else | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2893 col = col + siso - n + 1; |
7 | 2894 if (curwin->w_leftcol != col) |
2895 { | |
2896 curwin->w_leftcol = col; | |
2897 redraw_later(NOT_VALID); | |
2898 } | |
2899 } | |
2900 break; | |
2901 | |
2902 #ifdef FEAT_FOLDING | |
2903 /* "zF": create fold command */ | |
2904 /* "zf": create fold operator */ | |
2905 case 'F': | |
2906 case 'f': if (foldManualAllowed(TRUE)) | |
2907 { | |
2908 cap->nchar = 'f'; | |
2909 nv_operator(cap); | |
2910 curwin->w_p_fen = TRUE; | |
2911 | |
2912 /* "zF" is like "zfzf" */ | |
2913 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
2914 { | |
2915 nv_operator(cap); | |
2916 finish_op = TRUE; | |
2917 } | |
2918 } | |
2919 else | |
2920 clearopbeep(cap->oap); | |
2921 break; | |
2922 | |
2923 /* "zd": delete fold at cursor */ | |
2924 /* "zD": delete fold at cursor recursively */ | |
2925 case 'd': | |
2926 case 'D': if (foldManualAllowed(FALSE)) | |
2927 { | |
2928 if (VIsual_active) | |
2929 nv_operator(cap); | |
2930 else | |
2931 deleteFold(curwin->w_cursor.lnum, | |
2932 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
2933 } | |
2934 break; | |
2935 | |
4352 | 2936 /* "zE": erase all folds */ |
7 | 2937 case 'E': if (foldmethodIsManual(curwin)) |
2938 { | |
2939 clearFolding(curwin); | |
2940 changed_window_setting(); | |
2941 } | |
2942 else if (foldmethodIsMarker(curwin)) | |
2943 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
2944 TRUE, FALSE); | |
2945 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2946 emsg(_("E352: Cannot erase folds with current 'foldmethod'")); |
7 | 2947 break; |
2948 | |
2949 /* "zn": fold none: reset 'foldenable' */ | |
2950 case 'n': curwin->w_p_fen = FALSE; | |
2951 break; | |
2952 | |
2953 /* "zN": fold Normal: set 'foldenable' */ | |
2954 case 'N': curwin->w_p_fen = TRUE; | |
2955 break; | |
2956 | |
2957 /* "zi": invert folding: toggle 'foldenable' */ | |
2958 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
2959 break; | |
2960 | |
2961 /* "za": open closed fold or close open fold at cursor */ | |
2962 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
2963 openFold(curwin->w_cursor.lnum, cap->count1); | |
2964 else | |
2965 { | |
2966 closeFold(curwin->w_cursor.lnum, cap->count1); | |
2967 curwin->w_p_fen = TRUE; | |
2968 } | |
2969 break; | |
2970 | |
2971 /* "zA": open fold at cursor recursively */ | |
2972 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
2973 openFoldRecurse(curwin->w_cursor.lnum); | |
2974 else | |
2975 { | |
2976 closeFoldRecurse(curwin->w_cursor.lnum); | |
2977 curwin->w_p_fen = TRUE; | |
2978 } | |
2979 break; | |
2980 | |
2981 /* "zo": open fold at cursor or Visual area */ | |
2982 case 'o': if (VIsual_active) | |
2983 nv_operator(cap); | |
2984 else | |
2985 openFold(curwin->w_cursor.lnum, cap->count1); | |
2986 break; | |
2987 | |
2988 /* "zO": open fold recursively */ | |
2989 case 'O': if (VIsual_active) | |
2990 nv_operator(cap); | |
2991 else | |
2992 openFoldRecurse(curwin->w_cursor.lnum); | |
2993 break; | |
2994 | |
2995 /* "zc": close fold at cursor or Visual area */ | |
2996 case 'c': if (VIsual_active) | |
2997 nv_operator(cap); | |
2998 else | |
2999 closeFold(curwin->w_cursor.lnum, cap->count1); | |
3000 curwin->w_p_fen = TRUE; | |
3001 break; | |
3002 | |
3003 /* "zC": close fold recursively */ | |
3004 case 'C': if (VIsual_active) | |
3005 nv_operator(cap); | |
3006 else | |
3007 closeFoldRecurse(curwin->w_cursor.lnum); | |
3008 curwin->w_p_fen = TRUE; | |
3009 break; | |
3010 | |
3011 /* "zv": open folds at the cursor */ | |
3012 case 'v': foldOpenCursor(); | |
3013 break; | |
3014 | |
3015 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
3016 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3017 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3018 newFoldLevel(); /* update right now */ |
7 | 3019 foldOpenCursor(); |
3020 break; | |
3021 | |
3022 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
3023 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3024 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3025 old_fdl = -1; /* force an update */ |
7 | 3026 break; |
3027 | |
3028 /* "zm": fold more */ | |
3029 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 3030 { |
3031 curwin->w_p_fdl -= cap->count1; | |
3032 if (curwin->w_p_fdl < 0) | |
3033 curwin->w_p_fdl = 0; | |
3034 } | |
7 | 3035 old_fdl = -1; /* force an update */ |
3036 curwin->w_p_fen = TRUE; | |
3037 break; | |
3038 | |
3039 /* "zM": close all folds */ | |
3040 case 'M': curwin->w_p_fdl = 0; | |
3041 old_fdl = -1; /* force an update */ | |
3042 curwin->w_p_fen = TRUE; | |
3043 break; | |
3044 | |
3045 /* "zr": reduce folding */ | |
6725 | 3046 case 'r': curwin->w_p_fdl += cap->count1; |
3047 { | |
3048 int d = getDeepestNesting(); | |
3049 | |
3050 if (curwin->w_p_fdl >= d) | |
3051 curwin->w_p_fdl = d; | |
3052 } | |
7 | 3053 break; |
3054 | |
3055 /* "zR": open all folds */ | |
3056 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
3057 old_fdl = -1; /* force an update */ | |
3058 break; | |
3059 | |
3060 case 'j': /* "zj" move to next fold downwards */ | |
3061 case 'k': /* "zk" move to next fold upwards */ | |
3062 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
3063 cap->count1) == FAIL) | |
3064 clearopbeep(cap->oap); | |
3065 break; | |
3066 | |
3067 #endif /* FEAT_FOLDING */ | |
3068 | |
737 | 3069 #ifdef FEAT_SPELL |
710 | 3070 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
3071 ++no_mapping; | |
3072 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 3073 nchar = plain_vgetc(); |
710 | 3074 LANGMAP_ADJUST(nchar, TRUE); |
3075 --no_mapping; | |
3076 --allow_keys; | |
3077 #ifdef FEAT_CMDL_INFO | |
3078 (void)add_to_showcmd(nchar); | |
3079 #endif | |
3080 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
3081 { | |
3082 clearopbeep(cap->oap); | |
3083 break; | |
3084 } | |
3085 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
3086 /* FALLTHROUGH */ |
710 | 3087 |
310 | 3088 case 'g': /* "zg": add good word to word list */ |
3089 case 'w': /* "zw": add wrong word to word list */ | |
381 | 3090 case 'G': /* "zG": add good word to temp word list */ |
3091 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 3092 { |
3093 char_u *ptr = NULL; | |
3094 int len; | |
3095 | |
3096 if (checkclearop(cap->oap)) | |
3097 break; | |
3098 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
3099 == FAIL) | |
3100 return; | |
501 | 3101 if (ptr == NULL) |
3102 { | |
3103 pos_T pos = curwin->w_cursor; | |
3104 | |
5374 | 3105 /* Find bad word under the cursor. When 'spell' is |
3106 * off this fails and find_ident_under_cursor() is | |
3107 * used below. */ | |
3108 emsg_off++; | |
534 | 3109 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 3110 emsg_off--; |
501 | 3111 if (len != 0 && curwin->w_cursor.col <= pos.col) |
3112 ptr = ml_get_pos(&curwin->w_cursor); | |
3113 curwin->w_cursor = pos; | |
3114 } | |
3115 | |
310 | 3116 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
3117 FIND_IDENT)) == 0) | |
3118 return; | |
17682
3dbff5d37520
patch 8.1.1838: there is :spellwrong and :spellgood but not :spellrare
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3119 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W' |
3dbff5d37520
patch 8.1.1838: there is :spellwrong and :spellgood but not :spellrare
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3120 ? SPELL_ADD_BAD : SPELL_ADD_GOOD, |
710 | 3121 (nchar == 'G' || nchar == 'W') |
3122 ? 0 : (int)cap->count1, | |
3123 undo); | |
310 | 3124 } |
316 | 3125 break; |
323 | 3126 |
584 | 3127 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 3128 if (!checkclearop(cap->oap)) |
485 | 3129 spell_suggest((int)cap->count0); |
323 | 3130 break; |
310 | 3131 #endif |
3132 | |
7 | 3133 default: clearopbeep(cap->oap); |
3134 } | |
3135 | |
3136 #ifdef FEAT_FOLDING | |
3137 /* Redraw when 'foldenable' changed */ | |
3138 if (old_fen != curwin->w_p_fen) | |
3139 { | |
3140 # ifdef FEAT_DIFF | |
3141 win_T *wp; | |
3142 | |
3143 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
3144 { | |
3145 /* Adjust 'foldenable' in diff-synced windows. */ | |
3146 FOR_ALL_WINDOWS(wp) | |
3147 { | |
3148 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
3149 { | |
3150 wp->w_p_fen = curwin->w_p_fen; | |
3151 changed_window_setting_win(wp); | |
3152 } | |
3153 } | |
3154 } | |
3155 # endif | |
3156 changed_window_setting(); | |
3157 } | |
3158 | |
3159 /* Redraw when 'foldlevel' changed. */ | |
3160 if (old_fdl != curwin->w_p_fdl) | |
3161 newFoldLevel(); | |
3162 #endif | |
3163 } | |
3164 | |
3165 #ifdef FEAT_GUI | |
3166 /* | |
3167 * Vertical scrollbar movement. | |
3168 */ | |
3169 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3170 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 3171 { |
3172 if (cap->oap->op_type != OP_NOP) | |
3173 clearopbeep(cap->oap); | |
3174 | |
3175 /* Even if an operator was pending, we still want to scroll */ | |
3176 gui_do_scroll(); | |
3177 } | |
3178 | |
3179 /* | |
3180 * Horizontal scrollbar movement. | |
3181 */ | |
3182 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3183 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 3184 { |
3185 if (cap->oap->op_type != OP_NOP) | |
3186 clearopbeep(cap->oap); | |
3187 | |
3188 /* Even if an operator was pending, we still want to scroll */ | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3189 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 3190 } |
3191 #endif | |
3192 | |
690 | 3193 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 3194 /* |
3195 * Click in GUI tab. | |
3196 */ | |
3197 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3198 nv_tabline(cmdarg_T *cap) |
685 | 3199 { |
3200 if (cap->oap->op_type != OP_NOP) | |
3201 clearopbeep(cap->oap); | |
3202 | |
3203 /* Even if an operator was pending, we still want to jump tabs. */ | |
3204 goto_tabpage(current_tab); | |
3205 } | |
686 | 3206 |
3207 /* | |
3208 * Selected item in tab line menu. | |
3209 */ | |
3210 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3211 nv_tabmenu(cmdarg_T *cap) |
686 | 3212 { |
3213 if (cap->oap->op_type != OP_NOP) | |
3214 clearopbeep(cap->oap); | |
3215 | |
3216 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 3217 handle_tabmenu(); |
3218 } | |
3219 | |
3220 /* | |
3221 * Handle selecting an item of the GUI tab line menu. | |
3222 * Used in Normal and Insert mode. | |
3223 */ | |
3224 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3225 handle_tabmenu(void) |
690 | 3226 { |
686 | 3227 switch (current_tabmenu) |
3228 { | |
3229 case TABLINE_MENU_CLOSE: | |
3230 if (current_tab == 0) | |
3231 do_cmdline_cmd((char_u *)"tabclose"); | |
3232 else | |
3233 { | |
3234 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
3235 current_tab); | |
3236 do_cmdline_cmd(IObuff); | |
3237 } | |
3238 break; | |
3239 | |
3240 case TABLINE_MENU_NEW: | |
6631 | 3241 if (current_tab == 0) |
3242 do_cmdline_cmd((char_u *)"$tabnew"); | |
3243 else | |
3244 { | |
3245 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
3246 current_tab - 1); | |
3247 do_cmdline_cmd(IObuff); | |
3248 } | |
686 | 3249 break; |
3250 | |
3251 case TABLINE_MENU_OPEN: | |
6631 | 3252 if (current_tab == 0) |
3253 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
3254 else | |
3255 { | |
3256 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
3257 current_tab - 1); | |
3258 do_cmdline_cmd(IObuff); | |
3259 } | |
686 | 3260 break; |
3261 } | |
3262 } | |
685 | 3263 #endif |
3264 | |
7 | 3265 /* |
3266 * "Q" command. | |
3267 */ | |
3268 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3269 nv_exmode(cmdarg_T *cap) |
7 | 3270 { |
3271 /* | |
3272 * Ignore 'Q' in Visual mode, just give a beep. | |
3273 */ | |
3274 if (VIsual_active) | |
6949 | 3275 vim_beep(BO_EX); |
5735 | 3276 else if (!checkclearop(cap->oap)) |
7 | 3277 do_exmode(FALSE); |
3278 } | |
3279 | |
3280 /* | |
3281 * Handle a ":" command. | |
3282 */ | |
3283 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3284 nv_colon(cmdarg_T *cap) |
7 | 3285 { |
3286 int old_p_im; | |
4256 | 3287 int cmd_result; |
7 | 3288 |
3289 if (VIsual_active) | |
3290 nv_operator(cap); | |
3291 else | |
3292 { | |
3293 if (cap->oap->op_type != OP_NOP) | |
3294 { | |
3295 /* Using ":" as a movement is characterwise exclusive. */ | |
3296 cap->oap->motion_type = MCHAR; | |
3297 cap->oap->inclusive = FALSE; | |
3298 } | |
3299 else if (cap->count0) | |
3300 { | |
3301 /* translate "count:" into ":.,.+(count - 1)" */ | |
3302 stuffcharReadbuff('.'); | |
3303 if (cap->count0 > 1) | |
3304 { | |
3305 stuffReadbuff((char_u *)",.+"); | |
3306 stuffnumReadbuff((long)cap->count0 - 1L); | |
3307 } | |
3308 } | |
3309 | |
3310 /* When typing, don't type below an old message */ | |
3311 if (KeyTyped) | |
3312 compute_cmdrow(); | |
3313 | |
3314 old_p_im = p_im; | |
3315 | |
3316 /* get a command line and execute it */ | |
4256 | 3317 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 3318 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
3319 | |
3320 /* If 'insertmode' changed, enter or exit Insert mode */ | |
3321 if (p_im != old_p_im) | |
3322 { | |
3323 if (p_im) | |
3324 restart_edit = 'i'; | |
3325 else | |
3326 restart_edit = 0; | |
3327 } | |
3328 | |
4256 | 3329 if (cmd_result == FAIL) |
3330 /* The Ex command failed, do not execute the operator. */ | |
3331 clearop(cap->oap); | |
3332 else if (cap->oap->op_type != OP_NOP | |
7 | 3333 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
3334 || cap->oap->start.col > | |
4256 | 3335 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
3336 || did_emsg | |
3337 )) | |
3338 /* The start of the operator has become invalid by the Ex command. | |
3339 */ | |
7 | 3340 clearopbeep(cap->oap); |
3341 } | |
3342 } | |
3343 | |
3344 /* | |
3345 * Handle CTRL-G command. | |
3346 */ | |
3347 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3348 nv_ctrlg(cmdarg_T *cap) |
7 | 3349 { |
3350 if (VIsual_active) /* toggle Selection/Visual mode */ | |
3351 { | |
3352 VIsual_select = !VIsual_select; | |
3353 showmode(); | |
3354 } | |
5735 | 3355 else if (!checkclearop(cap->oap)) |
7 | 3356 /* print full name if count given or :cd used */ |
3357 fileinfo((int)cap->count0, FALSE, TRUE); | |
3358 } | |
3359 | |
3360 /* | |
3361 * Handle CTRL-H <Backspace> command. | |
3362 */ | |
3363 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3364 nv_ctrlh(cmdarg_T *cap) |
7 | 3365 { |
3366 if (VIsual_active && VIsual_select) | |
3367 { | |
3368 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
3369 v_visop(cap); | |
3370 } | |
3371 else | |
3372 nv_left(cap); | |
3373 } | |
3374 | |
3375 /* | |
3376 * CTRL-L: clear screen and redraw. | |
3377 */ | |
3378 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3379 nv_clear(cmdarg_T *cap) |
7 | 3380 { |
3381 if (!checkclearop(cap->oap)) | |
3382 { | |
3383 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
3384 /* | |
3385 * Right now, the BeBox doesn't seem to have an easy way to detect | |
3386 * window resizing, so we cheat and make the user detect it | |
3387 * manually with CTRL-L instead | |
3388 */ | |
3389 ui_get_shellsize(); | |
3390 #endif | |
3391 #ifdef FEAT_SYN_HL | |
3392 /* Clear all syntax states to force resyncing. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3393 syn_stack_free_all(curwin->w_s); |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3394 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3395 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3396 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3397 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3398 FOR_ALL_WINDOWS(wp) |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3399 wp->w_s->b_syn_slow = FALSE; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3400 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3401 # endif |
7 | 3402 #endif |
3403 redraw_later(CLEAR); | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
3404 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
3405 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
3406 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
3407 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
3408 resize_console_buf(); |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
3409 #endif |
7 | 3410 } |
3411 } | |
3412 | |
3413 /* | |
3414 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
3415 * Otherwise: Go to older pcmark. | |
3416 */ | |
3417 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3418 nv_ctrlo(cmdarg_T *cap) |
7 | 3419 { |
3420 if (VIsual_active && VIsual_select) | |
3421 { | |
3422 VIsual_select = FALSE; | |
3423 showmode(); | |
3424 restart_VIsual_select = 2; /* restart Select mode later */ | |
3425 } | |
3426 else | |
3427 { | |
3428 cap->count1 = -cap->count1; | |
3429 nv_pcmark(cap); | |
3430 } | |
3431 } | |
3432 | |
3433 /* | |
15006
1fd8e32532f7
patch 8.1.0514: CTRL-W ^ does not work when alternate buffer has no name
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3434 * CTRL-^ command, short for ":e #". Works even when the alternate buffer is |
1fd8e32532f7
patch 8.1.0514: CTRL-W ^ does not work when alternate buffer has no name
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3435 * not named. |
7 | 3436 */ |
3437 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3438 nv_hat(cmdarg_T *cap) |
7 | 3439 { |
3440 if (!checkclearopq(cap->oap)) | |
3441 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
3442 GETF_SETMARK|GETF_ALT, FALSE); | |
3443 } | |
3444 | |
3445 /* | |
3446 * "Z" commands. | |
3447 */ | |
3448 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3449 nv_Zet(cmdarg_T *cap) |
7 | 3450 { |
3451 if (!checkclearopq(cap->oap)) | |
3452 { | |
3453 switch (cap->nchar) | |
3454 { | |
3455 /* "ZZ": equivalent to ":x". */ | |
3456 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
3457 break; | |
3458 | |
3459 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
3460 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
3461 break; | |
3462 | |
3463 default: clearopbeep(cap->oap); | |
3464 } | |
3465 } | |
3466 } | |
3467 | |
3468 /* | |
3469 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
3470 */ | |
3471 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3472 do_nv_ident(int c1, int c2) |
7 | 3473 { |
3474 oparg_T oa; | |
3475 cmdarg_T ca; | |
3476 | |
3477 clear_oparg(&oa); | |
3478 vim_memset(&ca, 0, sizeof(ca)); | |
3479 ca.oap = &oa; | |
3480 ca.cmdchar = c1; | |
3481 ca.nchar = c2; | |
3482 nv_ident(&ca); | |
3483 } | |
3484 | |
3485 /* | |
3486 * Handle the commands that use the word under the cursor. | |
3487 * [g] CTRL-] :ta to current identifier | |
3488 * [g] 'K' run program for current identifier | |
3489 * [g] '*' / to current identifier or string | |
3490 * [g] '#' ? to current identifier or string | |
3491 * g ']' :tselect for current identifier | |
3492 */ | |
3493 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3494 nv_ident(cmdarg_T *cap) |
7 | 3495 { |
3496 char_u *ptr = NULL; | |
3497 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3498 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
3499 char_u *newbuf; |
7 | 3500 char_u *p; |
3501 char_u *kp; /* value of 'keywordprg' */ | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3502 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3503 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 3504 int n = 0; /* init for GCC */ |
3505 int cmdchar; | |
3506 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3507 int tag_cmd = FALSE; |
7 | 3508 char_u *aux_ptr; |
3509 int isman; | |
3510 int isman_s; | |
3511 | |
3512 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
3513 { | |
3514 cmdchar = cap->nchar; | |
3515 g_cmd = TRUE; | |
3516 } | |
3517 else | |
3518 { | |
3519 cmdchar = cap->cmdchar; | |
3520 g_cmd = FALSE; | |
3521 } | |
3522 | |
3523 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
3524 cmdchar = '#'; | |
3525 | |
3526 /* | |
3527 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
3528 */ | |
3529 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
3530 { | |
3531 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
3532 return; | |
3533 if (checkclearopq(cap->oap)) | |
3534 return; | |
3535 } | |
3536 | |
3537 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
3538 (cmdchar == '*' || cmdchar == '#') | |
3539 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
3540 { | |
3541 clearop(cap->oap); | |
3542 return; | |
3543 } | |
3544 | |
3545 /* Allocate buffer to put the command in. Inserting backslashes can | |
3546 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
3547 * and some numbers. */ | |
3548 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
3549 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
3550 || STRCMP(kp, ":help") == 0); | |
12236
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
3551 if (kp_help && *skipwhite(ptr) == NUL) |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
3552 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3553 emsg(_(e_noident)); /* found white space only */ |
12236
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
3554 return; |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
3555 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3556 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3557 buflen = (unsigned)(n * 2 + 30 + STRLEN(kp)); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3558 buf = alloc(buflen); |
7 | 3559 if (buf == NULL) |
3560 return; | |
3561 buf[0] = NUL; | |
3562 | |
3563 switch (cmdchar) | |
3564 { | |
3565 case '*': | |
3566 case '#': | |
3567 /* | |
3568 * Put cursor at start of word, makes search skip the word | |
3569 * under the cursor. | |
3570 * Call setpcmark() first, so "*``" puts the cursor back where | |
3571 * it was. | |
3572 */ | |
3573 setpcmark(); | |
3574 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
3575 | |
3576 if (!g_cmd && vim_iswordp(ptr)) | |
3577 STRCPY(buf, "\\<"); | |
3578 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
3579 break; | |
3580 | |
3581 case 'K': | |
3582 if (kp_help) | |
3583 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3584 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3585 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3586 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3587 vim_snprintf((char *)buf, buflen, "%s %ld", |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3588 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3589 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3590 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3591 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3592 } |
7 | 3593 else |
3594 { | |
1712 | 3595 /* An external command will probably use an argument starting |
3596 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 3597 while (*ptr == '-' && n > 0) |
3598 { | |
1712 | 3599 ++ptr; |
1728 | 3600 --n; |
3601 } | |
3602 if (n == 0) | |
3603 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3604 emsg(_(e_noident)); /* found dashes only */ |
1728 | 3605 vim_free(buf); |
3606 return; | |
3607 } | |
1712 | 3608 |
7 | 3609 /* When a count is given, turn it into a range. Is this |
3610 * really what we want? */ | |
3611 isman = (STRCMP(kp, "man") == 0); | |
3612 isman_s = (STRCMP(kp, "man -s") == 0); | |
3613 if (cap->count0 != 0 && !(isman || isman_s)) | |
3614 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
3615 | |
3616 STRCAT(buf, "! "); | |
3617 if (cap->count0 == 0 && isman_s) | |
3618 STRCAT(buf, "man"); | |
3619 else | |
3620 STRCAT(buf, kp); | |
3621 STRCAT(buf, " "); | |
3622 if (cap->count0 != 0 && (isman || isman_s)) | |
3623 { | |
3624 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
3625 STRCAT(buf, " "); | |
3626 } | |
3627 } | |
3628 break; | |
3629 | |
3630 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3631 tag_cmd = TRUE; |
7 | 3632 #ifdef FEAT_CSCOPE |
3633 if (p_cst) | |
3634 STRCPY(buf, "cstag "); | |
3635 else | |
3636 #endif | |
3637 STRCPY(buf, "ts "); | |
3638 break; | |
3639 | |
3640 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
3641 tag_cmd = TRUE; |
7 | 3642 if (curbuf->b_help) |
3643 STRCPY(buf, "he! "); | |
3644 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3645 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3646 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3647 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3648 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3649 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3650 } |
7 | 3651 } |
3652 | |
3653 /* | |
3654 * Now grab the chars in the identifier | |
3655 */ | |
1712 | 3656 if (cmdchar == 'K' && !kp_help) |
3657 { | |
1728 | 3658 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3659 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3660 /* Escape the argument properly for an Ex command */ |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3661 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3662 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3663 /* Escape the argument properly for a shell command */ |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3664 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 3665 vim_free(ptr); |
1712 | 3666 if (p == NULL) |
3667 { | |
3668 vim_free(buf); | |
3669 return; | |
3670 } | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16742
diff
changeset
|
3671 newbuf = vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1); |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
3672 if (newbuf == NULL) |
1712 | 3673 { |
3674 vim_free(buf); | |
3675 vim_free(p); | |
3676 return; | |
3677 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
3678 buf = newbuf; |
1712 | 3679 STRCAT(buf, p); |
3680 vim_free(p); | |
3681 } | |
7 | 3682 else |
1712 | 3683 { |
3684 if (cmdchar == '*') | |
3685 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
3686 else if (cmdchar == '#') | |
3687 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3688 else if (tag_cmd) |
2603 | 3689 { |
3690 if (curbuf->b_help) | |
3691 /* ":help" handles unescaped argument */ | |
3692 aux_ptr = (char_u *)""; | |
3693 else | |
3694 aux_ptr = (char_u *)"\\|\"\n["; | |
3695 } | |
1712 | 3696 else |
3697 aux_ptr = (char_u *)"\\|\"\n*?["; | |
3698 | |
3699 p = buf + STRLEN(buf); | |
3700 while (n-- > 0) | |
3701 { | |
3702 /* put a backslash before \ and some others */ | |
3703 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
3704 *p++ = '\\'; | |
3705 /* When current byte is a part of multibyte character, copy all | |
3706 * bytes of that character. */ | |
3707 if (has_mbyte) | |
3708 { | |
3709 int i; | |
3710 int len = (*mb_ptr2len)(ptr) - 1; | |
3711 | |
3712 for (i = 0; i < len && n >= 1; ++i, --n) | |
3713 *p++ = *ptr++; | |
3714 } | |
3715 *p++ = *ptr++; | |
3716 } | |
3717 *p = NUL; | |
3718 } | |
7 | 3719 |
3720 /* | |
3721 * Execute the command. | |
3722 */ | |
3723 if (cmdchar == '*' || cmdchar == '#') | |
3724 { | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3725 if (!g_cmd && (has_mbyte |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3726 ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3727 : vim_iswordc(ptr[-1]))) |
7 | 3728 STRCAT(buf, "\\>"); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
3729 |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
3730 // put pattern in search history |
2024 | 3731 init_history(); |
7 | 3732 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
3733 |
6620 | 3734 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 3735 } |
3736 else | |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3737 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3738 g_tag_at_cursor = TRUE; |
7 | 3739 do_cmdline_cmd(buf); |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3740 g_tag_at_cursor = FALSE; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3741 } |
7 | 3742 |
3743 vim_free(buf); | |
3744 } | |
3745 | |
3746 /* | |
3747 * Get visually selected text, within one line only. | |
3748 * Returns FAIL if more than one line selected. | |
3749 */ | |
344 | 3750 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3751 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3752 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3753 char_u **pp, /* return: start of selected text */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3754 int *lenp) /* return: length of selected text */ |
7 | 3755 { |
3756 if (VIsual_mode != 'V') | |
3757 unadjust_for_sel(); | |
3758 if (VIsual.lnum != curwin->w_cursor.lnum) | |
3759 { | |
344 | 3760 if (cap != NULL) |
3761 clearopbeep(cap->oap); | |
7 | 3762 return FAIL; |
3763 } | |
3764 if (VIsual_mode == 'V') | |
3765 { | |
3766 *pp = ml_get_curline(); | |
3767 *lenp = (int)STRLEN(*pp); | |
3768 } | |
3769 else | |
3770 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3771 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3772 { |
3773 *pp = ml_get_pos(&curwin->w_cursor); | |
3774 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
3775 } | |
3776 else | |
3777 { | |
3778 *pp = ml_get_pos(&VIsual); | |
3779 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
3780 } | |
3781 if (has_mbyte) | |
3782 /* Correct the length to include the whole last character. */ | |
474 | 3783 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 3784 } |
3785 reset_VIsual_and_resel(); | |
3786 return OK; | |
3787 } | |
3788 | |
3789 /* | |
3790 * CTRL-T: backwards in tag stack | |
3791 */ | |
3792 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3793 nv_tagpop(cmdarg_T *cap) |
7 | 3794 { |
3795 if (!checkclearopq(cap->oap)) | |
3796 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
3797 } | |
3798 | |
3799 /* | |
3800 * Handle scrolling command 'H', 'L' and 'M'. | |
3801 */ | |
3802 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3803 nv_scroll(cmdarg_T *cap) |
7 | 3804 { |
3805 int used = 0; | |
3806 long n; | |
3807 #ifdef FEAT_FOLDING | |
3808 linenr_T lnum; | |
3809 #endif | |
3810 int half; | |
3811 | |
3812 cap->oap->motion_type = MLINE; | |
3813 setpcmark(); | |
3814 | |
3815 if (cap->cmdchar == 'L') | |
3816 { | |
3817 validate_botline(); /* make sure curwin->w_botline is valid */ | |
3818 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
3819 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
3820 curwin->w_cursor.lnum = 1; | |
3821 else | |
9 | 3822 { |
3823 #ifdef FEAT_FOLDING | |
3824 if (hasAnyFolding(curwin)) | |
3825 { | |
3826 /* Count a fold for one screen line. */ | |
3827 for (n = cap->count1 - 1; n > 0 | |
3828 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
3829 { | |
3830 (void)hasFolding(curwin->w_cursor.lnum, | |
3831 &curwin->w_cursor.lnum, NULL); | |
3832 --curwin->w_cursor.lnum; | |
3833 } | |
3834 } | |
3835 else | |
3836 #endif | |
3837 curwin->w_cursor.lnum -= cap->count1 - 1; | |
3838 } | |
7 | 3839 } |
3840 else | |
3841 { | |
3842 if (cap->cmdchar == 'M') | |
3843 { | |
3844 #ifdef FEAT_DIFF | |
3845 /* Don't count filler lines above the window. */ | |
3846 used -= diff_check_fill(curwin, curwin->w_topline) | |
3847 - curwin->w_topfill; | |
3848 #endif | |
3849 validate_botline(); /* make sure w_empty_rows is valid */ | |
3850 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
3851 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
3852 { | |
3853 #ifdef FEAT_DIFF | |
3854 /* Count half he number of filler lines to be "below this | |
3855 * line" and half to be "above the next line". */ | |
3856 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
3857 + n) / 2 >= half) | |
3858 { | |
3859 --n; | |
3860 break; | |
3861 } | |
3862 #endif | |
3863 used += plines(curwin->w_topline + n); | |
3864 if (used >= half) | |
3865 break; | |
3866 #ifdef FEAT_FOLDING | |
3867 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
3868 n = lnum - curwin->w_topline; | |
3869 #endif | |
3870 } | |
3871 if (n > 0 && used > curwin->w_height) | |
3872 --n; | |
3873 } | |
9 | 3874 else /* (cap->cmdchar == 'H') */ |
3875 { | |
7 | 3876 n = cap->count1 - 1; |
9 | 3877 #ifdef FEAT_FOLDING |
3878 if (hasAnyFolding(curwin)) | |
3879 { | |
3880 /* Count a fold for one screen line. */ | |
3881 lnum = curwin->w_topline; | |
3882 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
3883 { | |
7009 | 3884 (void)hasFolding(lnum, NULL, &lnum); |
9 | 3885 ++lnum; |
3886 } | |
3887 n = lnum - curwin->w_topline; | |
3888 } | |
3889 #endif | |
3890 } | |
7 | 3891 curwin->w_cursor.lnum = curwin->w_topline + n; |
3892 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3893 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3894 } | |
3895 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
3896 /* Correct for 'so', except when an operator is pending. */ |
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
3897 if (cap->oap->op_type == OP_NOP) |
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
3898 cursor_correct(); |
7 | 3899 beginline(BL_SOL | BL_FIX); |
3900 } | |
3901 | |
3902 /* | |
3903 * Cursor right commands. | |
3904 */ | |
3905 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3906 nv_right(cmdarg_T *cap) |
7 | 3907 { |
3908 long n; | |
5735 | 3909 int past_line; |
7 | 3910 |
180 | 3911 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
3912 { | |
3913 /* <C-Right> and <S-Right> move a word or WORD right */ | |
3914 if (mod_mask & MOD_MASK_CTRL) | |
3915 cap->arg = TRUE; | |
3916 nv_wordcmd(cap); | |
3917 return; | |
3918 } | |
3919 | |
7 | 3920 cap->oap->motion_type = MCHAR; |
3921 cap->oap->inclusive = FALSE; | |
5735 | 3922 past_line = (VIsual_active && *p_sel != 'o'); |
3923 | |
7 | 3924 /* |
5735 | 3925 * In virtual edit mode, there's no such thing as "past_line", as lines |
3926 * are (theoretically) infinitely long. | |
7 | 3927 */ |
3928 if (virtual_active()) | |
5735 | 3929 past_line = 0; |
7 | 3930 |
3931 for (n = cap->count1; n > 0; --n) | |
3932 { | |
5735 | 3933 if ((!past_line && oneright() == FAIL) |
3934 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 3935 ) |
7 | 3936 { |
3937 /* | |
714 | 3938 * <Space> wraps to next line if 'whichwrap' has 's'. |
3939 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
3940 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 3941 */ |
3942 if ( ((cap->cmdchar == ' ' | |
3943 && vim_strchr(p_ww, 's') != NULL) | |
3944 || (cap->cmdchar == 'l' | |
3945 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 3946 || (cap->cmdchar == K_RIGHT |
7 | 3947 && vim_strchr(p_ww, '>') != NULL)) |
3948 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
3949 { | |
3950 /* When deleting we also count the NL as a character. | |
3951 * Set cap->oap->inclusive when last char in the line is | |
3952 * included, move to next line after that */ | |
714 | 3953 if ( cap->oap->op_type != OP_NOP |
7 | 3954 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3955 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 3956 cap->oap->inclusive = TRUE; |
3957 else | |
3958 { | |
3959 ++curwin->w_cursor.lnum; | |
3960 curwin->w_cursor.col = 0; | |
3961 curwin->w_cursor.coladd = 0; | |
3962 curwin->w_set_curswant = TRUE; | |
3963 cap->oap->inclusive = FALSE; | |
3964 } | |
3965 continue; | |
3966 } | |
3967 if (cap->oap->op_type == OP_NOP) | |
3968 { | |
3969 /* Only beep and flush if not moved at all */ | |
3970 if (n == cap->count1) | |
3971 beep_flush(); | |
3972 } | |
3973 else | |
3974 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3975 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 3976 cap->oap->inclusive = TRUE; |
3977 } | |
3978 break; | |
3979 } | |
5735 | 3980 else if (past_line) |
7 | 3981 { |
3982 curwin->w_set_curswant = TRUE; | |
3983 if (virtual_active()) | |
3984 oneright(); | |
3985 else | |
5735 | 3986 { |
7 | 3987 if (has_mbyte) |
18128
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
3988 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3989 else |
3990 ++curwin->w_cursor.col; | |
3991 } | |
3992 } | |
3993 } | |
3994 #ifdef FEAT_FOLDING | |
3995 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
3996 && cap->oap->op_type == OP_NOP) | |
3997 foldOpenCursor(); | |
3998 #endif | |
3999 } | |
4000 | |
4001 /* | |
4002 * Cursor left commands. | |
4003 * | |
4004 * Returns TRUE when operator end should not be adjusted. | |
4005 */ | |
4006 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4007 nv_left(cmdarg_T *cap) |
7 | 4008 { |
4009 long n; | |
4010 | |
180 | 4011 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
4012 { | |
4013 /* <C-Left> and <S-Left> move a word or WORD left */ | |
4014 if (mod_mask & MOD_MASK_CTRL) | |
4015 cap->arg = 1; | |
4016 nv_bck_word(cap); | |
4017 return; | |
4018 } | |
4019 | |
7 | 4020 cap->oap->motion_type = MCHAR; |
4021 cap->oap->inclusive = FALSE; | |
4022 for (n = cap->count1; n > 0; --n) | |
4023 { | |
4024 if (oneleft() == FAIL) | |
4025 { | |
4026 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
4027 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
4028 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
4029 */ | |
4030 if ( (((cap->cmdchar == K_BS | |
4031 || cap->cmdchar == Ctrl_H) | |
4032 && vim_strchr(p_ww, 'b') != NULL) | |
4033 || (cap->cmdchar == 'h' | |
4034 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 4035 || (cap->cmdchar == K_LEFT |
7 | 4036 && vim_strchr(p_ww, '<') != NULL)) |
4037 && curwin->w_cursor.lnum > 1) | |
4038 { | |
4039 --(curwin->w_cursor.lnum); | |
4040 coladvance((colnr_T)MAXCOL); | |
4041 curwin->w_set_curswant = TRUE; | |
4042 | |
4043 /* When the NL before the first char has to be deleted we | |
4044 * put the cursor on the NUL after the previous line. | |
4045 * This is a very special case, be careful! | |
1469 | 4046 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 4047 if ( (cap->oap->op_type == OP_DELETE |
4048 || cap->oap->op_type == OP_CHANGE) | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4049 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4050 { |
5682 | 4051 char_u *cp = ml_get_cursor(); |
4052 | |
4053 if (*cp != NUL) | |
4054 { | |
4055 if (has_mbyte) | |
4056 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
4057 else | |
4058 ++curwin->w_cursor.col; | |
4059 } | |
7 | 4060 cap->retval |= CA_NO_ADJ_OP_END; |
4061 } | |
4062 continue; | |
4063 } | |
4064 /* Only beep and flush if not moved at all */ | |
4065 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
4066 beep_flush(); | |
4067 break; | |
4068 } | |
4069 } | |
4070 #ifdef FEAT_FOLDING | |
4071 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
4072 && cap->oap->op_type == OP_NOP) | |
4073 foldOpenCursor(); | |
4074 #endif | |
4075 } | |
4076 | |
4077 /* | |
4078 * Cursor up commands. | |
4079 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
4080 */ | |
4081 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4082 nv_up(cmdarg_T *cap) |
7 | 4083 { |
180 | 4084 if (mod_mask & MOD_MASK_SHIFT) |
4085 { | |
4086 /* <S-Up> is page up */ | |
4087 cap->arg = BACKWARD; | |
4088 nv_page(cap); | |
4089 } | |
4090 else | |
4091 { | |
4092 cap->oap->motion_type = MLINE; | |
4093 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
4094 clearopbeep(cap->oap); | |
4095 else if (cap->arg) | |
4096 beginline(BL_WHITE | BL_FIX); | |
4097 } | |
7 | 4098 } |
4099 | |
4100 /* | |
4101 * Cursor down commands. | |
4102 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
4103 */ | |
4104 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
4105 nv_down(cmdarg_T *cap) |
7 | 4106 { |
180 | 4107 if (mod_mask & MOD_MASK_SHIFT) |
4108 { | |
4109 /* <S-Down> is page down */ | |
4110 cap->arg = FORWARD; | |
4111 nv_page(cap); | |
4112 } | |
14397
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
4113 #if defined(FEAT_QUICKFIX) |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
4114 /* Quickfix window only: view the result under the cursor. */ |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
4115 else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
4116 qf_view_result(FALSE); |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
4117 #endif |
180 | 4118 else |
7 | 4119 { |
4120 #ifdef FEAT_CMDWIN | |
4121 /* In the cmdline window a <CR> executes the command. */ | |
170 | 4122 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 4123 cmdwin_result = CAR; |
4124 else | |
4125 #endif | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4126 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4127 /* In a prompt buffer a <CR> in the last line invokes the callback. */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4128 if (bt_prompt(curbuf) && cap->cmdchar == CAR |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4129 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4130 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4131 invoke_prompt_callback(); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4132 if (restart_edit == 0) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4133 restart_edit = 'a'; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4134 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4135 else |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4136 #endif |
7 | 4137 { |
4138 cap->oap->motion_type = MLINE; | |
4139 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
4140 clearopbeep(cap->oap); | |
4141 else if (cap->arg) | |
4142 beginline(BL_WHITE | BL_FIX); | |
4143 } | |
4144 } | |
4145 } | |
4146 | |
4147 #ifdef FEAT_SEARCHPATH | |
4148 /* | |
4149 * Grab the file name under the cursor and edit it. | |
4150 */ | |
4151 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4152 nv_gotofile(cmdarg_T *cap) |
7 | 4153 { |
4154 char_u *ptr; | |
681 | 4155 linenr_T lnum = -1; |
7 | 4156 |
633 | 4157 if (text_locked()) |
7 | 4158 { |
4159 clearopbeep(cap->oap); | |
633 | 4160 text_locked_msg(); |
7 | 4161 return; |
4162 } | |
819 | 4163 if (curbuf_locked()) |
4164 { | |
4165 clearop(cap->oap); | |
4166 return; | |
4167 } | |
7 | 4168 |
681 | 4169 ptr = grab_file_name(cap->count1, &lnum); |
7 | 4170 |
4171 if (ptr != NULL) | |
4172 { | |
4173 /* do autowrite if necessary */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11892
diff
changeset
|
4174 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 4175 (void)autowrite(curbuf, FALSE); |
7 | 4176 setpcmark(); |
11436
69b52a770b29
patch 8.0.0602: when gF fails to edit the file the cursor still moves
Christian Brabandt <cb@256bit.org>
parents:
11366
diff
changeset
|
4177 if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST, |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11892
diff
changeset
|
4178 buf_hide(curbuf) ? ECMD_HIDE : 0, curwin) == OK |
11436
69b52a770b29
patch 8.0.0602: when gF fails to edit the file the cursor still moves
Christian Brabandt <cb@256bit.org>
parents:
11366
diff
changeset
|
4179 && cap->nchar == 'F' && lnum >= 0) |
681 | 4180 { |
4181 curwin->w_cursor.lnum = lnum; | |
4182 check_cursor_lnum(); | |
4183 beginline(BL_SOL | BL_FIX); | |
4184 } | |
7 | 4185 vim_free(ptr); |
4186 } | |
4187 else | |
4188 clearop(cap->oap); | |
4189 } | |
4190 #endif | |
4191 | |
4192 /* | |
4193 * <End> command: to end of current line or last line. | |
4194 */ | |
4195 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4196 nv_end(cmdarg_T *cap) |
7 | 4197 { |
180 | 4198 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
4199 { | |
4200 cap->arg = TRUE; | |
7 | 4201 nv_goto(cap); |
4202 cap->count1 = 1; /* to end of current line */ | |
4203 } | |
4204 nv_dollar(cap); | |
4205 } | |
4206 | |
4207 /* | |
4208 * Handle the "$" command. | |
4209 */ | |
4210 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4211 nv_dollar(cmdarg_T *cap) |
7 | 4212 { |
4213 cap->oap->motion_type = MCHAR; | |
4214 cap->oap->inclusive = TRUE; | |
4215 /* In virtual mode when off the edge of a line and an operator | |
4216 * is pending (whew!) keep the cursor where it is. | |
4217 * Otherwise, send it to the end of the line. */ | |
4218 if (!virtual_active() || gchar_cursor() != NUL | |
4219 || cap->oap->op_type == OP_NOP) | |
4220 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
4221 if (cursor_down((long)(cap->count1 - 1), | |
4222 cap->oap->op_type == OP_NOP) == FAIL) | |
4223 clearopbeep(cap->oap); | |
4224 #ifdef FEAT_FOLDING | |
4225 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4226 foldOpenCursor(); | |
4227 #endif | |
4228 } | |
4229 | |
4230 /* | |
4231 * Implementation of '?' and '/' commands. | |
4232 * If cap->arg is TRUE don't set PC mark. | |
4233 */ | |
4234 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4235 nv_search(cmdarg_T *cap) |
7 | 4236 { |
4237 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4238 pos_T save_cursor = curwin->w_cursor; |
7 | 4239 |
4240 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
4241 { | |
4242 /* Translate "g??" to "g?g?" */ | |
4243 cap->cmdchar = 'g'; | |
4244 cap->nchar = '?'; | |
4245 nv_operator(cap); | |
4246 return; | |
4247 } | |
4248 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4249 /* When using 'incsearch' the cursor may be moved to set a different search |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4250 * start position. */ |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17041
diff
changeset
|
4251 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, TRUE); |
7 | 4252 |
4253 if (cap->searchbuf == NULL) | |
4254 { | |
4255 clearop(oap); | |
4256 return; | |
4257 } | |
4258 | |
6620 | 4259 (void)normal_search(cap, cap->cmdchar, cap->searchbuf, |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4260 (cap->arg || !EQUAL_POS(save_cursor, curwin->w_cursor)) |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4261 ? 0 : SEARCH_MARK); |
7 | 4262 } |
4263 | |
4264 /* | |
4265 * Handle "N" and "n" commands. | |
4266 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
4267 */ | |
4268 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4269 nv_next(cmdarg_T *cap) |
7 | 4270 { |
6620 | 4271 pos_T old = curwin->w_cursor; |
4272 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
4273 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4274 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 4275 { |
4276 /* Avoid getting stuck on the current cursor position, which can | |
4277 * happen when an offset is given and the cursor is on the last char | |
4278 * in the buffer: Repeat with count + 1. */ | |
4279 cap->count1 += 1; | |
4280 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
4281 cap->count1 -= 1; | |
4282 } | |
7 | 4283 } |
4284 | |
4285 /* | |
4286 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
4287 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 4288 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
4289 */ | |
4290 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4291 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4292 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4293 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4294 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4295 int opt) /* extra flags for do_search() */ |
7 | 4296 { |
4297 int i; | |
4298 | |
4299 cap->oap->motion_type = MCHAR; | |
4300 cap->oap->inclusive = FALSE; | |
4301 cap->oap->use_reg_one = TRUE; | |
4302 curwin->w_set_curswant = TRUE; | |
4303 | |
4304 i = do_search(cap->oap, dir, pat, cap->count1, | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11451
diff
changeset
|
4305 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 4306 if (i == 0) |
4307 clearop(cap->oap); | |
4308 else | |
4309 { | |
4310 if (i == 2) | |
4311 cap->oap->motion_type = MLINE; | |
4312 curwin->w_cursor.coladd = 0; | |
4313 #ifdef FEAT_FOLDING | |
4314 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
4315 foldOpenCursor(); | |
4316 #endif | |
4317 } | |
4318 | |
4319 /* "/$" will put the cursor after the end of the line, may need to | |
4320 * correct that here */ | |
4321 check_cursor(); | |
6620 | 4322 return i; |
7 | 4323 } |
4324 | |
4325 /* | |
4326 * Character search commands. | |
4327 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
4328 * ',' and FALSE for ';'. | |
4329 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
4330 */ | |
4331 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4332 nv_csearch(cmdarg_T *cap) |
7 | 4333 { |
4334 int t_cmd; | |
4335 | |
4336 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
4337 t_cmd = TRUE; | |
4338 else | |
4339 t_cmd = FALSE; | |
4340 | |
4341 cap->oap->motion_type = MCHAR; | |
4342 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
4343 clearopbeep(cap->oap); | |
4344 else | |
4345 { | |
4346 curwin->w_set_curswant = TRUE; | |
4347 /* Include a Tab for "tx" and for "dfx". */ | |
4348 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
4349 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
4350 { | |
4351 colnr_T scol, ecol; | |
4352 | |
4353 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4354 curwin->w_cursor.coladd = ecol - scol; | |
4355 } | |
4356 else | |
4357 curwin->w_cursor.coladd = 0; | |
4358 adjust_for_sel(cap); | |
4359 #ifdef FEAT_FOLDING | |
4360 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4361 foldOpenCursor(); | |
4362 #endif | |
4363 } | |
4364 } | |
4365 | |
4366 /* | |
4367 * "[" and "]" commands. | |
4368 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
4369 */ | |
4370 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4371 nv_brackets(cmdarg_T *cap) |
7 | 4372 { |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
4373 pos_T new_pos = {0, 0, 0}; |
7 | 4374 pos_T prev_pos; |
4375 pos_T *pos = NULL; /* init for GCC */ | |
4376 pos_T old_pos; /* cursor position before command */ | |
4377 int flag; | |
4378 long n; | |
4379 int findc; | |
4380 int c; | |
4381 | |
4382 cap->oap->motion_type = MCHAR; | |
4383 cap->oap->inclusive = FALSE; | |
4384 old_pos = curwin->w_cursor; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4385 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error. |
7 | 4386 |
4387 #ifdef FEAT_SEARCHPATH | |
4388 /* | |
4389 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
4390 */ | |
4391 if (cap->nchar == 'f') | |
4392 nv_gotofile(cap); | |
4393 else | |
4394 #endif | |
4395 | |
4396 #ifdef FEAT_FIND_ID | |
4397 /* | |
1188 | 4398 * Find the occurrence(s) of the identifier or define under cursor |
4399 * in current and included files or jump to the first occurrence. | |
7 | 4400 * |
4401 * search list jump | |
4402 * fwd bwd fwd bwd fwd bwd | |
4403 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
4404 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
4405 */ | |
4406 if (vim_strchr((char_u *) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4407 # ifdef EBCDIC |
7 | 4408 "iI\005dD\067", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4409 # else |
7 | 4410 "iI\011dD\004", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4411 # endif |
7 | 4412 cap->nchar) != NULL) |
4413 { | |
4414 char_u *ptr; | |
4415 int len; | |
4416 | |
4417 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
4418 clearop(cap->oap); | |
4419 else | |
4420 { | |
4421 find_pattern_in_path(ptr, 0, len, TRUE, | |
4422 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
4423 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
4424 cap->count1, | |
4425 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
4426 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
4427 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
4428 (linenr_T)MAXLNUM); | |
4429 curwin->w_set_curswant = TRUE; | |
4430 } | |
4431 } | |
4432 else | |
4433 #endif | |
4434 | |
4435 /* | |
4436 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
4437 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
4438 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
4439 * "[m" or "]m" search for prev/next start of (Java) method. | |
4440 * "[M" or "]M" search for prev/next end of (Java) method. | |
4441 */ | |
4442 if ( (cap->cmdchar == '[' | |
4443 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
4444 || (cap->cmdchar == ']' | |
4445 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
4446 { | |
4447 if (cap->nchar == '*') | |
4448 cap->nchar = '/'; | |
4449 prev_pos.lnum = 0; | |
4450 if (cap->nchar == 'm' || cap->nchar == 'M') | |
4451 { | |
4452 if (cap->cmdchar == '[') | |
4453 findc = '{'; | |
4454 else | |
4455 findc = '}'; | |
4456 n = 9999; | |
4457 } | |
4458 else | |
4459 { | |
4460 findc = cap->nchar; | |
4461 n = cap->count1; | |
4462 } | |
4463 for ( ; n > 0; --n) | |
4464 { | |
4465 if ((pos = findmatchlimit(cap->oap, findc, | |
4466 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
4467 { | |
4468 if (new_pos.lnum == 0) /* nothing found */ | |
4469 { | |
4470 if (cap->nchar != 'm' && cap->nchar != 'M') | |
4471 clearopbeep(cap->oap); | |
4472 } | |
4473 else | |
4474 pos = &new_pos; /* use last one found */ | |
4475 break; | |
4476 } | |
4477 prev_pos = new_pos; | |
4478 curwin->w_cursor = *pos; | |
4479 new_pos = *pos; | |
4480 } | |
4481 curwin->w_cursor = old_pos; | |
4482 | |
4483 /* | |
4484 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
4485 * brought us to the match for "[m" and "]M" when inside a method. | |
4486 * Try finding the '{' or '}' we want to be at. | |
4487 * Also repeat for the given count. | |
4488 */ | |
4489 if (cap->nchar == 'm' || cap->nchar == 'M') | |
4490 { | |
4491 /* norm is TRUE for "]M" and "[m" */ | |
4492 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
4493 | |
4494 n = cap->count1; | |
4495 /* found a match: we were inside a method */ | |
4496 if (prev_pos.lnum != 0) | |
4497 { | |
4498 pos = &prev_pos; | |
4499 curwin->w_cursor = prev_pos; | |
4500 if (norm) | |
4501 --n; | |
4502 } | |
4503 else | |
4504 pos = NULL; | |
4505 while (n > 0) | |
4506 { | |
4507 for (;;) | |
4508 { | |
4509 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
4510 { | |
4511 /* if not found anything, that's an error */ | |
4512 if (pos == NULL) | |
4513 clearopbeep(cap->oap); | |
4514 n = 0; | |
4515 break; | |
4516 } | |
4517 c = gchar_cursor(); | |
4518 if (c == '{' || c == '}') | |
4519 { | |
4520 /* Must have found end/start of class: use it. | |
4521 * Or found the place to be at. */ | |
4522 if ((c == findc && norm) || (n == 1 && !norm)) | |
4523 { | |
4524 new_pos = curwin->w_cursor; | |
4525 pos = &new_pos; | |
4526 n = 0; | |
4527 } | |
4528 /* if no match found at all, we started outside of the | |
4529 * class and we're inside now. Just go on. */ | |
4530 else if (new_pos.lnum == 0) | |
4531 { | |
4532 new_pos = curwin->w_cursor; | |
4533 pos = &new_pos; | |
4534 } | |
4535 /* found start/end of other method: go to match */ | |
4536 else if ((pos = findmatchlimit(cap->oap, findc, | |
4537 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
4538 0)) == NULL) | |
4539 n = 0; | |
4540 else | |
4541 curwin->w_cursor = *pos; | |
4542 break; | |
4543 } | |
4544 } | |
4545 --n; | |
4546 } | |
4547 curwin->w_cursor = old_pos; | |
4548 if (pos == NULL && new_pos.lnum != 0) | |
4549 clearopbeep(cap->oap); | |
4550 } | |
4551 if (pos != NULL) | |
4552 { | |
4553 setpcmark(); | |
4554 curwin->w_cursor = *pos; | |
4555 curwin->w_set_curswant = TRUE; | |
4556 #ifdef FEAT_FOLDING | |
4557 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
4558 && cap->oap->op_type == OP_NOP) | |
4559 foldOpenCursor(); | |
4560 #endif | |
4561 } | |
4562 } | |
4563 | |
4564 /* | |
4565 * "[[", "[]", "]]" and "][": move to start or end of function | |
4566 */ | |
4567 else if (cap->nchar == '[' || cap->nchar == ']') | |
4568 { | |
4569 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
4570 flag = '{'; | |
4571 else | |
4572 flag = '}'; /* "][" or "[]" */ | |
4573 | |
4574 curwin->w_set_curswant = TRUE; | |
4575 /* | |
4576 * Imitate strange Vi behaviour: When using "]]" with an operator | |
4577 * we also stop at '}'. | |
4578 */ | |
503 | 4579 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 4580 (cap->oap->op_type != OP_NOP |
4581 && cap->arg == FORWARD && flag == '{'))) | |
4582 clearopbeep(cap->oap); | |
4583 else | |
4584 { | |
4585 if (cap->oap->op_type == OP_NOP) | |
4586 beginline(BL_WHITE | BL_FIX); | |
4587 #ifdef FEAT_FOLDING | |
4588 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4589 foldOpenCursor(); | |
4590 #endif | |
4591 } | |
4592 } | |
4593 | |
4594 /* | |
4595 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
4596 */ | |
4597 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
4598 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4599 nv_put_opt(cap, TRUE); |
7 | 4600 } |
4601 | |
4602 /* | |
4603 * "['", "[`", "]'" and "]`": jump to next mark | |
4604 */ | |
4605 else if (cap->nchar == '\'' || cap->nchar == '`') | |
4606 { | |
4607 pos = &curwin->w_cursor; | |
4608 for (n = cap->count1; n > 0; --n) | |
4609 { | |
4610 prev_pos = *pos; | |
4611 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
4612 cap->nchar == '\''); | |
4613 if (pos == NULL) | |
4614 break; | |
4615 } | |
4616 if (pos == NULL) | |
4617 pos = &prev_pos; | |
4618 nv_cursormark(cap, cap->nchar == '\'', pos); | |
4619 } | |
4620 | |
4621 #ifdef FEAT_MOUSE | |
4622 /* | |
4623 * [ or ] followed by a middle mouse click: put selected text with | |
4624 * indent adjustment. Any other button just does as usual. | |
4625 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
4626 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 4627 { |
4628 (void)do_mouse(cap->oap, cap->nchar, | |
4629 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
4630 cap->count1, PUT_FIXINDENT); | |
4631 } | |
4632 #endif /* FEAT_MOUSE */ | |
4633 | |
4634 #ifdef FEAT_FOLDING | |
4635 /* | |
4636 * "[z" and "]z": move to start or end of open fold. | |
4637 */ | |
4638 else if (cap->nchar == 'z') | |
4639 { | |
4640 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
4641 cap->count1) == FAIL) | |
4642 clearopbeep(cap->oap); | |
4643 } | |
4644 #endif | |
4645 | |
4646 #ifdef FEAT_DIFF | |
4647 /* | |
4648 * "[c" and "]c": move to next or previous diff-change. | |
4649 */ | |
4650 else if (cap->nchar == 'c') | |
4651 { | |
4652 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
4653 cap->count1) == FAIL) | |
4654 clearopbeep(cap->oap); | |
4655 } | |
4656 #endif | |
4657 | |
737 | 4658 #ifdef FEAT_SPELL |
236 | 4659 /* |
4660 * "[s", "[S", "]s" and "]S": move to next spell error. | |
4661 */ | |
4662 else if (cap->nchar == 's' || cap->nchar == 'S') | |
4663 { | |
249 | 4664 setpcmark(); |
4665 for (n = 0; n < cap->count1; ++n) | |
498 | 4666 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
4667 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 4668 { |
4669 clearopbeep(cap->oap); | |
4670 break; | |
4671 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
4672 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
4673 curwin->w_set_curswant = TRUE; |
819 | 4674 # ifdef FEAT_FOLDING |
4675 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
4676 foldOpenCursor(); | |
4677 # endif | |
236 | 4678 } |
4679 #endif | |
4680 | |
7 | 4681 /* Not a valid cap->nchar. */ |
4682 else | |
4683 clearopbeep(cap->oap); | |
4684 } | |
4685 | |
4686 /* | |
4687 * Handle Normal mode "%" command. | |
4688 */ | |
4689 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4690 nv_percent(cmdarg_T *cap) |
7 | 4691 { |
4692 pos_T *pos; | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
4693 #if defined(FEAT_FOLDING) |
7 | 4694 linenr_T lnum = curwin->w_cursor.lnum; |
4695 #endif | |
4696 | |
4697 cap->oap->inclusive = TRUE; | |
4698 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
4699 { | |
4700 if (cap->count0 > 100) | |
4701 clearopbeep(cap->oap); | |
4702 else | |
4703 { | |
4704 cap->oap->motion_type = MLINE; | |
4705 setpcmark(); | |
4706 /* Round up, so CTRL-G will give same value. Watch out for a | |
4707 * large line count, the line number must not go negative! */ | |
4708 if (curbuf->b_ml.ml_line_count > 1000000) | |
4709 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
4710 / 100L * cap->count0; | |
4711 else | |
4712 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
4713 cap->count0 + 99L) / 100L; | |
4714 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
4715 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4716 beginline(BL_SOL | BL_FIX); | |
4717 } | |
4718 } | |
4719 else /* "%" : go to matching paren */ | |
4720 { | |
4721 cap->oap->motion_type = MCHAR; | |
4722 cap->oap->use_reg_one = TRUE; | |
4723 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
4724 clearopbeep(cap->oap); | |
4725 else | |
4726 { | |
4727 setpcmark(); | |
4728 curwin->w_cursor = *pos; | |
4729 curwin->w_set_curswant = TRUE; | |
4730 curwin->w_cursor.coladd = 0; | |
4731 adjust_for_sel(cap); | |
4732 } | |
4733 } | |
4734 #ifdef FEAT_FOLDING | |
4735 if (cap->oap->op_type == OP_NOP | |
4736 && lnum != curwin->w_cursor.lnum | |
4737 && (fdo_flags & FDO_PERCENT) | |
4738 && KeyTyped) | |
4739 foldOpenCursor(); | |
4740 #endif | |
4741 } | |
4742 | |
4743 /* | |
4744 * Handle "(" and ")" commands. | |
4745 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
4746 */ | |
4747 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4748 nv_brace(cmdarg_T *cap) |
7 | 4749 { |
4750 cap->oap->motion_type = MCHAR; | |
4751 cap->oap->use_reg_one = TRUE; | |
620 | 4752 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
4753 cap->oap->inclusive = FALSE; | |
7 | 4754 curwin->w_set_curswant = TRUE; |
4755 | |
4756 if (findsent(cap->arg, cap->count1) == FAIL) | |
4757 clearopbeep(cap->oap); | |
4758 else | |
4759 { | |
1505 | 4760 /* Don't leave the cursor on the NUL past end of line. */ |
4761 adjust_cursor(cap->oap); | |
7 | 4762 curwin->w_cursor.coladd = 0; |
4763 #ifdef FEAT_FOLDING | |
4764 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4765 foldOpenCursor(); | |
4766 #endif | |
4767 } | |
4768 } | |
4769 | |
4770 /* | |
4771 * "m" command: Mark a position. | |
4772 */ | |
4773 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4774 nv_mark(cmdarg_T *cap) |
7 | 4775 { |
4776 if (!checkclearop(cap->oap)) | |
4777 { | |
4778 if (setmark(cap->nchar) == FAIL) | |
4779 clearopbeep(cap->oap); | |
4780 } | |
4781 } | |
4782 | |
4783 /* | |
4784 * "{" and "}" commands. | |
4785 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
4786 */ | |
4787 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4788 nv_findpar(cmdarg_T *cap) |
7 | 4789 { |
4790 cap->oap->motion_type = MCHAR; | |
4791 cap->oap->inclusive = FALSE; | |
4792 cap->oap->use_reg_one = TRUE; | |
4793 curwin->w_set_curswant = TRUE; | |
503 | 4794 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 4795 clearopbeep(cap->oap); |
4796 else | |
4797 { | |
4798 curwin->w_cursor.coladd = 0; | |
4799 #ifdef FEAT_FOLDING | |
4800 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4801 foldOpenCursor(); | |
4802 #endif | |
4803 } | |
4804 } | |
4805 | |
4806 /* | |
4807 * "u" command: Undo or make lower case. | |
4808 */ | |
4809 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4810 nv_undo(cmdarg_T *cap) |
7 | 4811 { |
5735 | 4812 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 4813 { |
4814 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
4815 cap->cmdchar = 'g'; | |
4816 cap->nchar = 'u'; | |
4817 nv_operator(cap); | |
4818 } | |
4819 else | |
4820 nv_kundo(cap); | |
4821 } | |
4822 | |
4823 /* | |
4824 * <Undo> command. | |
4825 */ | |
4826 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4827 nv_kundo(cmdarg_T *cap) |
7 | 4828 { |
4829 if (!checkclearopq(cap->oap)) | |
4830 { | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4831 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4832 if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4833 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4834 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4835 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4836 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4837 #endif |
7 | 4838 u_undo((int)cap->count1); |
4839 curwin->w_set_curswant = TRUE; | |
4840 } | |
4841 } | |
4842 | |
4843 /* | |
4844 * Handle the "r" command. | |
4845 */ | |
4846 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4847 nv_replace(cmdarg_T *cap) |
7 | 4848 { |
4849 char_u *ptr; | |
4850 int had_ctrl_v; | |
4851 long n; | |
4852 | |
4853 if (checkclearop(cap->oap)) | |
4854 return; | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4855 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4856 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4857 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4858 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4859 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4860 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4861 #endif |
7 | 4862 |
4863 /* get another character */ | |
4864 if (cap->nchar == Ctrl_V) | |
4865 { | |
4866 had_ctrl_v = Ctrl_V; | |
4867 cap->nchar = get_literal(); | |
4868 /* Don't redo a multibyte character with CTRL-V. */ | |
4869 if (cap->nchar > DEL) | |
4870 had_ctrl_v = NUL; | |
4871 } | |
4872 else | |
4873 had_ctrl_v = NUL; | |
4874 | |
1343 | 4875 /* Abort if the character is a special key. */ |
4876 if (IS_SPECIAL(cap->nchar)) | |
4877 { | |
4878 clearopbeep(cap->oap); | |
4879 return; | |
4880 } | |
4881 | |
7 | 4882 /* Visual mode "r" */ |
4883 if (VIsual_active) | |
4884 { | |
1797 | 4885 if (got_int) |
4886 reset_VIsual(); | |
5428 | 4887 if (had_ctrl_v) |
4888 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4889 /* Use a special (negative) number to make a difference between a |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4890 * literal CR or NL and a line break. */ |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4891 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4892 cap->nchar = REPLACE_CR_NCHAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4893 else if (cap->nchar == NL) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4894 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 4895 } |
7 | 4896 nv_operator(cap); |
4897 return; | |
4898 } | |
4899 | |
4900 /* Break tabs, etc. */ | |
4901 if (virtual_active()) | |
4902 { | |
4903 if (u_save_cursor() == FAIL) | |
4904 return; | |
4905 if (gchar_cursor() == NUL) | |
4906 { | |
4907 /* Add extra space and put the cursor on the first one. */ | |
4908 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
4909 curwin->w_cursor.col -= cap->count1; | |
4910 } | |
4911 else if (gchar_cursor() == TAB) | |
4912 coladvance_force(getviscol()); | |
4913 } | |
4914 | |
1343 | 4915 /* Abort if not enough characters to replace. */ |
7 | 4916 ptr = ml_get_cursor(); |
1343 | 4917 if (STRLEN(ptr) < (unsigned)cap->count1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4918 || (has_mbyte && mb_charlen(ptr) < cap->count1)) |
7 | 4919 { |
4920 clearopbeep(cap->oap); | |
4921 return; | |
4922 } | |
4923 | |
4924 /* | |
4925 * Replacing with a TAB is done by edit() when it is complicated because | |
4926 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
4927 * Other characters are done below to avoid problems with things like | |
4928 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
4929 */ | |
4930 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
4931 { | |
4932 stuffnumReadbuff(cap->count1); | |
4933 stuffcharReadbuff('R'); | |
4934 stuffcharReadbuff('\t'); | |
4935 stuffcharReadbuff(ESC); | |
4936 return; | |
4937 } | |
4938 | |
4939 /* save line for undo */ | |
4940 if (u_save_cursor() == FAIL) | |
4941 return; | |
4942 | |
4943 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
4944 { | |
4945 /* | |
4946 * Replace character(s) by a single newline. | |
4947 * Strange vi behaviour: Only one newline is inserted. | |
4948 * Delete the characters here. | |
4949 * Insert the newline with an insert command, takes care of | |
4950 * autoindent. The insert command depends on being on the last | |
4951 * character of a line or not. | |
4952 */ | |
4953 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
4954 stuffcharReadbuff('\r'); | |
4955 stuffcharReadbuff(ESC); | |
4956 | |
4957 /* Give 'r' to edit(), to get the redo command right. */ | |
4958 invoke_edit(cap, TRUE, 'r', FALSE); | |
4959 } | |
4960 else | |
4961 { | |
4962 prep_redo(cap->oap->regname, cap->count1, | |
4963 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
4964 | |
4965 curbuf->b_op_start = curwin->w_cursor; | |
4966 if (has_mbyte) | |
4967 { | |
4968 int old_State = State; | |
4969 | |
4970 if (cap->ncharC1 != 0) | |
4971 AppendCharToRedobuff(cap->ncharC1); | |
4972 if (cap->ncharC2 != 0) | |
4973 AppendCharToRedobuff(cap->ncharC2); | |
4974 | |
4975 /* This is slow, but it handles replacing a single-byte with a | |
4976 * multi-byte and the other way around. Also handles adding | |
4977 * composing characters for utf-8. */ | |
4978 for (n = cap->count1; n > 0; --n) | |
4979 { | |
4980 State = REPLACE; | |
3501 | 4981 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
4982 { | |
4983 int c = ins_copychar(curwin->w_cursor.lnum | |
4984 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
4985 if (c != NUL) | |
4986 ins_char(c); | |
4987 else | |
4988 /* will be decremented further down */ | |
4989 ++curwin->w_cursor.col; | |
4990 } | |
4991 else | |
4992 ins_char(cap->nchar); | |
7 | 4993 State = old_State; |
4994 if (cap->ncharC1 != 0) | |
4995 ins_char(cap->ncharC1); | |
4996 if (cap->ncharC2 != 0) | |
4997 ins_char(cap->ncharC2); | |
4998 } | |
4999 } | |
5000 else | |
5001 { | |
5002 /* | |
5003 * Replace the characters within one line. | |
5004 */ | |
5005 for (n = cap->count1; n > 0; --n) | |
5006 { | |
5007 /* | |
5008 * Get ptr again, because u_save and/or showmatch() will have | |
5009 * released the line. At the same time we let know that the | |
5010 * line will be changed. | |
5011 */ | |
5012 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 5013 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
5014 { | |
5015 int c = ins_copychar(curwin->w_cursor.lnum | |
5016 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
5017 if (c != NUL) | |
5018 ptr[curwin->w_cursor.col] = c; | |
5019 } | |
5020 else | |
5021 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 5022 if (p_sm && msg_silent == 0) |
5023 showmatch(cap->nchar); | |
5024 ++curwin->w_cursor.col; | |
5025 } | |
5026 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5027 if (netbeans_active()) |
7 | 5028 { |
2210 | 5029 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 5030 |
33 | 5031 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 5032 (long)cap->count1); |
7 | 5033 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 5034 &ptr[start], (int)cap->count1); |
7 | 5035 } |
5036 #endif | |
5037 | |
5038 /* mark the buffer as changed and prepare for displaying */ | |
5039 changed_bytes(curwin->w_cursor.lnum, | |
5040 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
5041 } | |
5042 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
5043 /* if the character on the left of the current cursor is a multi-byte | |
5044 * character, move two characters left */ | |
5045 if (has_mbyte) | |
5046 mb_adjust_cursor(); | |
5047 curbuf->b_op_end = curwin->w_cursor; | |
5048 curwin->w_set_curswant = TRUE; | |
5049 set_last_insert(cap->nchar); | |
5050 } | |
5051 } | |
5052 | |
5053 /* | |
5054 * 'o': Exchange start and end of Visual area. | |
5055 * 'O': same, but in block mode exchange left and right corners. | |
5056 */ | |
5057 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5058 v_swap_corners(int cmdchar) |
7 | 5059 { |
5060 pos_T old_cursor; | |
5061 colnr_T left, right; | |
5062 | |
5063 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
5064 { | |
5065 old_cursor = curwin->w_cursor; | |
5066 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
5067 curwin->w_cursor.lnum = VIsual.lnum; | |
5068 coladvance(left); | |
5069 VIsual = curwin->w_cursor; | |
5070 | |
5071 curwin->w_cursor.lnum = old_cursor.lnum; | |
5072 curwin->w_curswant = right; | |
5073 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
5074 * right one column */ | |
5075 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
5076 ++curwin->w_curswant; | |
5077 coladvance(curwin->w_curswant); | |
5078 if (curwin->w_cursor.col == old_cursor.col | |
5079 && (!virtual_active() | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5080 || curwin->w_cursor.coladd == old_cursor.coladd)) |
7 | 5081 { |
5082 curwin->w_cursor.lnum = VIsual.lnum; | |
5083 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
5084 ++right; | |
5085 coladvance(right); | |
5086 VIsual = curwin->w_cursor; | |
5087 | |
5088 curwin->w_cursor.lnum = old_cursor.lnum; | |
5089 coladvance(left); | |
5090 curwin->w_curswant = left; | |
5091 } | |
5092 } | |
5093 else | |
5094 { | |
5095 old_cursor = curwin->w_cursor; | |
5096 curwin->w_cursor = VIsual; | |
5097 VIsual = old_cursor; | |
5098 curwin->w_set_curswant = TRUE; | |
5099 } | |
5100 } | |
5101 | |
5102 /* | |
5103 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
5104 */ | |
5105 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5106 nv_Replace(cmdarg_T *cap) |
7 | 5107 { |
5108 if (VIsual_active) /* "R" is replace lines */ | |
5109 { | |
5110 cap->cmdchar = 'c'; | |
5111 cap->nchar = NUL; | |
4213 | 5112 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 5113 VIsual_mode = 'V'; |
5114 nv_operator(cap); | |
5115 } | |
5735 | 5116 else if (!checkclearopq(cap->oap)) |
7 | 5117 { |
5118 if (!curbuf->b_p_ma) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5119 emsg(_(e_modifiable)); |
7 | 5120 else |
5121 { | |
5122 if (virtual_active()) | |
5123 coladvance(getviscol()); | |
5124 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
5125 } | |
5126 } | |
5127 } | |
5128 | |
5129 /* | |
5130 * "gr". | |
5131 */ | |
5132 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5133 nv_vreplace(cmdarg_T *cap) |
7 | 5134 { |
5135 if (VIsual_active) | |
5136 { | |
5137 cap->cmdchar = 'r'; | |
5138 cap->nchar = cap->extra_char; | |
5139 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
5140 } | |
5735 | 5141 else if (!checkclearopq(cap->oap)) |
7 | 5142 { |
5143 if (!curbuf->b_p_ma) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5144 emsg(_(e_modifiable)); |
7 | 5145 else |
5146 { | |
5147 if (cap->extra_char == Ctrl_V) /* get another character */ | |
5148 cap->extra_char = get_literal(); | |
5149 stuffcharReadbuff(cap->extra_char); | |
5150 stuffcharReadbuff(ESC); | |
5151 if (virtual_active()) | |
5152 coladvance(getviscol()); | |
5153 invoke_edit(cap, TRUE, 'v', FALSE); | |
5154 } | |
5155 } | |
5156 } | |
5157 | |
5158 /* | |
5159 * Swap case for "~" command, when it does not work like an operator. | |
5160 */ | |
5161 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5162 n_swapchar(cmdarg_T *cap) |
7 | 5163 { |
5164 long n; | |
5165 pos_T startpos; | |
5166 int did_change = 0; | |
5167 #ifdef FEAT_NETBEANS_INTG | |
5168 pos_T pos; | |
5169 char_u *ptr; | |
5170 int count; | |
5171 #endif | |
5172 | |
5173 if (checkclearopq(cap->oap)) | |
5174 return; | |
5175 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5176 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 5177 { |
5178 clearopbeep(cap->oap); | |
5179 return; | |
5180 } | |
5181 | |
5182 prep_redo_cmd(cap); | |
5183 | |
5184 if (u_save_cursor() == FAIL) | |
5185 return; | |
5186 | |
5187 startpos = curwin->w_cursor; | |
5188 #ifdef FEAT_NETBEANS_INTG | |
5189 pos = startpos; | |
5190 #endif | |
5191 for (n = cap->count1; n > 0; --n) | |
5192 { | |
5193 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
5194 inc_cursor(); | |
5195 if (gchar_cursor() == NUL) | |
5196 { | |
5197 if (vim_strchr(p_ww, '~') != NULL | |
5198 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
5199 { | |
5200 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5201 if (netbeans_active()) |
7 | 5202 { |
5203 if (did_change) | |
5204 { | |
5205 ptr = ml_get(pos.lnum); | |
835 | 5206 count = (int)STRLEN(ptr) - pos.col; |
33 | 5207 netbeans_removed(curbuf, pos.lnum, pos.col, |
5208 (long)count); | |
7 | 5209 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 5210 &ptr[pos.col], count); |
7 | 5211 } |
5212 pos.col = 0; | |
5213 pos.lnum++; | |
5214 } | |
5215 #endif | |
5216 ++curwin->w_cursor.lnum; | |
5217 curwin->w_cursor.col = 0; | |
5218 if (n > 1) | |
5219 { | |
5220 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
5221 break; | |
5222 u_clearline(); | |
5223 } | |
5224 } | |
5225 else | |
5226 break; | |
5227 } | |
5228 } | |
5229 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5230 if (did_change && netbeans_active()) |
7 | 5231 { |
5232 ptr = ml_get(pos.lnum); | |
5233 count = curwin->w_cursor.col - pos.col; | |
33 | 5234 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
5235 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 5236 } |
5237 #endif | |
5238 | |
5239 | |
5240 check_cursor(); | |
5241 curwin->w_set_curswant = TRUE; | |
5242 if (did_change) | |
5243 { | |
5244 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
5245 0L); | |
5246 curbuf->b_op_start = startpos; | |
5247 curbuf->b_op_end = curwin->w_cursor; | |
5248 if (curbuf->b_op_end.col > 0) | |
5249 --curbuf->b_op_end.col; | |
5250 } | |
5251 } | |
5252 | |
5253 /* | |
5254 * Move cursor to mark. | |
5255 */ | |
5256 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5257 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 5258 { |
5259 if (check_mark(pos) == FAIL) | |
5260 clearop(cap->oap); | |
5261 else | |
5262 { | |
5263 if (cap->cmdchar == '\'' | |
5264 || cap->cmdchar == '`' | |
5265 || cap->cmdchar == '[' | |
5266 || cap->cmdchar == ']') | |
5267 setpcmark(); | |
5268 curwin->w_cursor = *pos; | |
5269 if (flag) | |
5270 beginline(BL_WHITE | BL_FIX); | |
5271 else | |
5272 check_cursor(); | |
5273 } | |
5274 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
5275 if (cap->cmdchar == '`') | |
5276 cap->oap->use_reg_one = TRUE; | |
5277 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
5278 curwin->w_set_curswant = TRUE; | |
5279 } | |
5280 | |
5281 /* | |
5282 * Handle commands that are operators in Visual mode. | |
5283 */ | |
5284 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5285 v_visop(cmdarg_T *cap) |
7 | 5286 { |
5287 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
5288 | |
5289 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 5290 * the end of the line, and "C" replaces till EOL */ |
7 | 5291 if (isupper(cap->cmdchar)) |
5292 { | |
5293 if (VIsual_mode != Ctrl_V) | |
4213 | 5294 { |
5295 VIsual_mode_orig = VIsual_mode; | |
7 | 5296 VIsual_mode = 'V'; |
4213 | 5297 } |
7 | 5298 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
5299 curwin->w_curswant = MAXCOL; | |
5300 } | |
5301 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
5302 nv_operator(cap); | |
5303 } | |
5304 | |
5305 /* | |
5306 * "s" and "S" commands. | |
5307 */ | |
5308 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5309 nv_subst(cmdarg_T *cap) |
7 | 5310 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5311 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5312 /* When showing output of term_dumpdiff() swap the top and botom. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5313 if (term_swap_diff() == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5314 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5315 #endif |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5316 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5317 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5318 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5319 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5320 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5321 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
5322 #endif |
7 | 5323 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
5324 { | |
5325 if (cap->cmdchar == 'S') | |
4213 | 5326 { |
5327 VIsual_mode_orig = VIsual_mode; | |
7 | 5328 VIsual_mode = 'V'; |
4213 | 5329 } |
7 | 5330 cap->cmdchar = 'c'; |
5331 nv_operator(cap); | |
5332 } | |
5333 else | |
5334 nv_optrans(cap); | |
5335 } | |
5336 | |
5337 /* | |
5338 * Abbreviated commands. | |
5339 */ | |
5340 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5341 nv_abbrev(cmdarg_T *cap) |
7 | 5342 { |
5343 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
5344 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
5345 | |
5346 /* in Visual mode these commands are operators */ | |
5347 if (VIsual_active) | |
5348 v_visop(cap); | |
5349 else | |
5350 nv_optrans(cap); | |
5351 } | |
5352 | |
5353 /* | |
5354 * Translate a command into another command. | |
5355 */ | |
5356 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5357 nv_optrans(cmdarg_T *cap) |
7 | 5358 { |
5359 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
5360 (char_u *)"d$", (char_u *)"c$", | |
5361 (char_u *)"cl", (char_u *)"cc", | |
5362 (char_u *)"yy", (char_u *)":s\r"}; | |
5363 static char_u *str = (char_u *)"xXDCsSY&"; | |
5364 | |
5365 if (!checkclearopq(cap->oap)) | |
5366 { | |
18114
90b0af9ba4ff
patch 8.1.2052: using "x" before a closed fold may delete that fold
Bram Moolenaar <Bram@vim.org>
parents:
18045
diff
changeset
|
5367 // In Vi "2D" doesn't delete the next line. Can't translate it |
90b0af9ba4ff
patch 8.1.2052: using "x" before a closed fold may delete that fold
Bram Moolenaar <Bram@vim.org>
parents:
18045
diff
changeset
|
5368 // either, because "2." should also not use the count. |
164 | 5369 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) |
5370 { | |
5371 cap->oap->start = curwin->w_cursor; | |
5372 cap->oap->op_type = OP_DELETE; | |
1490 | 5373 #ifdef FEAT_EVAL |
5374 set_op_var(OP_DELETE); | |
5375 #endif | |
164 | 5376 cap->count1 = 1; |
5377 nv_dollar(cap); | |
5378 finish_op = TRUE; | |
5379 ResetRedobuff(); | |
5380 AppendCharToRedobuff('D'); | |
5381 } | |
5382 else | |
5383 { | |
5384 if (cap->count0) | |
5385 stuffnumReadbuff(cap->count0); | |
18128
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
5386 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); |
164 | 5387 } |
7 | 5388 } |
5389 cap->opcount = 0; | |
5390 } | |
5391 | |
5392 /* | |
5393 * "'" and "`" commands. Also for "g'" and "g`". | |
5394 * cap->arg is TRUE for "'" and "g'". | |
5395 */ | |
5396 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5397 nv_gomark(cmdarg_T *cap) |
7 | 5398 { |
5399 pos_T *pos; | |
5400 int c; | |
5401 #ifdef FEAT_FOLDING | |
4017 | 5402 pos_T old_cursor = curwin->w_cursor; |
7 | 5403 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
5404 #endif | |
5405 | |
5406 if (cap->cmdchar == 'g') | |
5407 c = cap->extra_char; | |
5408 else | |
5409 c = cap->nchar; | |
5410 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
5411 if (pos == (pos_T *)-1) /* jumped to other file */ | |
5412 { | |
5413 if (cap->arg) | |
5414 { | |
5415 check_cursor_lnum(); | |
5416 beginline(BL_WHITE | BL_FIX); | |
5417 } | |
5418 else | |
5419 check_cursor(); | |
5420 } | |
5421 else | |
5422 nv_cursormark(cap, cap->arg, pos); | |
5423 | |
5424 /* May need to clear the coladd that a mark includes. */ | |
5425 if (!virtual_active()) | |
5426 curwin->w_cursor.coladd = 0; | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
5427 check_cursor_col(); |
7 | 5428 #ifdef FEAT_FOLDING |
5429 if (cap->oap->op_type == OP_NOP | |
4057 | 5430 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5431 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 5432 && (fdo_flags & FDO_MARK) |
5433 && old_KeyTyped) | |
5434 foldOpenCursor(); | |
5435 #endif | |
5436 } | |
5437 | |
5438 /* | |
5439 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
5440 */ | |
5441 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5442 nv_pcmark(cmdarg_T *cap) |
7 | 5443 { |
5444 #ifdef FEAT_JUMPLIST | |
5445 pos_T *pos; | |
5446 # ifdef FEAT_FOLDING | |
5447 linenr_T lnum = curwin->w_cursor.lnum; | |
5448 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
5449 # endif | |
5450 | |
5451 if (!checkclearopq(cap->oap)) | |
5452 { | |
5453 if (cap->cmdchar == 'g') | |
5454 pos = movechangelist((int)cap->count1); | |
5455 else | |
5456 pos = movemark((int)cap->count1); | |
5457 if (pos == (pos_T *)-1) /* jump to other file */ | |
5458 { | |
5459 curwin->w_set_curswant = TRUE; | |
5460 check_cursor(); | |
5461 } | |
5462 else if (pos != NULL) /* can jump */ | |
5463 nv_cursormark(cap, FALSE, pos); | |
5464 else if (cap->cmdchar == 'g') | |
5465 { | |
5466 if (curbuf->b_changelistlen == 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5467 emsg(_("E664: changelist is empty")); |
7 | 5468 else if (cap->count1 < 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5469 emsg(_("E662: At start of changelist")); |
7 | 5470 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5471 emsg(_("E663: At end of changelist")); |
7 | 5472 } |
5473 else | |
5474 clearopbeep(cap->oap); | |
5475 # ifdef FEAT_FOLDING | |
5476 if (cap->oap->op_type == OP_NOP | |
5477 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
5478 && (fdo_flags & FDO_MARK) | |
5479 && old_KeyTyped) | |
5480 foldOpenCursor(); | |
5481 # endif | |
5482 } | |
5483 #else | |
5484 clearopbeep(cap->oap); | |
5485 #endif | |
5486 } | |
5487 | |
5488 /* | |
5489 * Handle '"' command. | |
5490 */ | |
5491 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5492 nv_regname(cmdarg_T *cap) |
7 | 5493 { |
5494 if (checkclearop(cap->oap)) | |
5495 return; | |
5496 #ifdef FEAT_EVAL | |
5497 if (cap->nchar == '=') | |
5498 cap->nchar = get_expr_register(); | |
5499 #endif | |
5500 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
5501 { | |
5502 cap->oap->regname = cap->nchar; | |
5503 cap->opcount = cap->count0; /* remember count before '"' */ | |
5504 #ifdef FEAT_EVAL | |
5505 set_reg_var(cap->oap->regname); | |
5506 #endif | |
5507 } | |
5508 else | |
5509 clearopbeep(cap->oap); | |
5510 } | |
5511 | |
5512 /* | |
5513 * Handle "v", "V" and "CTRL-V" commands. | |
5514 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
5515 * is TRUE. | |
167 | 5516 * Handle CTRL-Q just like CTRL-V. |
7 | 5517 */ |
5518 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5519 nv_visual(cmdarg_T *cap) |
7 | 5520 { |
167 | 5521 if (cap->cmdchar == Ctrl_Q) |
5522 cap->cmdchar = Ctrl_V; | |
5523 | |
7 | 5524 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
5525 * characterwise, linewise, or blockwise. */ | |
5526 if (cap->oap->op_type != OP_NOP) | |
5527 { | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5528 motion_force = cap->oap->motion_force = cap->cmdchar; |
7 | 5529 finish_op = FALSE; /* operator doesn't finish now but later */ |
5530 return; | |
5531 } | |
5532 | |
5533 VIsual_select = cap->arg; | |
5534 if (VIsual_active) /* change Visual mode */ | |
5535 { | |
5536 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
5537 end_visual_mode(); | |
5538 else /* toggle char/block mode */ | |
5539 { /* or char/line mode */ | |
5540 VIsual_mode = cap->cmdchar; | |
5541 showmode(); | |
5542 } | |
5543 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
5544 } | |
5545 else /* start Visual mode */ | |
5546 { | |
5547 check_visual_highlight(); | |
3537 | 5548 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
5549 { | |
5550 /* use previously selected part */ | |
7 | 5551 VIsual = curwin->w_cursor; |
5552 | |
5553 VIsual_active = TRUE; | |
5554 VIsual_reselect = TRUE; | |
5555 if (!cap->arg) | |
5556 /* start Select mode when 'selectmode' contains "cmd" */ | |
5557 may_start_select('c'); | |
5558 setmouse(); | |
641 | 5559 if (p_smd && msg_silent == 0) |
7 | 5560 redraw_cmdline = TRUE; /* show visual mode later */ |
5561 /* | |
5562 * For V and ^V, we multiply the number of lines even if there | |
5563 * was only one -- webb | |
5564 */ | |
5565 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
5566 { | |
5567 curwin->w_cursor.lnum += | |
5568 resel_VIsual_line_count * cap->count0 - 1; | |
5569 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5570 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5571 } | |
5572 VIsual_mode = resel_VIsual_mode; | |
5573 if (VIsual_mode == 'v') | |
5574 { | |
5575 if (resel_VIsual_line_count <= 1) | |
3125 | 5576 { |
5577 validate_virtcol(); | |
5578 curwin->w_curswant = curwin->w_virtcol | |
5579 + resel_VIsual_vcol * cap->count0 - 1; | |
5580 } | |
7 | 5581 else |
3125 | 5582 curwin->w_curswant = resel_VIsual_vcol; |
5583 coladvance(curwin->w_curswant); | |
7 | 5584 } |
3125 | 5585 if (resel_VIsual_vcol == MAXCOL) |
7 | 5586 { |
5587 curwin->w_curswant = MAXCOL; | |
5588 coladvance((colnr_T)MAXCOL); | |
5589 } | |
5590 else if (VIsual_mode == Ctrl_V) | |
5591 { | |
5592 validate_virtcol(); | |
5593 curwin->w_curswant = curwin->w_virtcol | |
3125 | 5594 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 5595 coladvance(curwin->w_curswant); |
5596 } | |
5597 else | |
5598 curwin->w_set_curswant = TRUE; | |
5599 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
5600 } | |
5601 else | |
5602 { | |
5603 if (!cap->arg) | |
5604 /* start Select mode when 'selectmode' contains "cmd" */ | |
5605 may_start_select('c'); | |
5606 n_start_visual_mode(cap->cmdchar); | |
3537 | 5607 if (VIsual_mode != 'V' && *p_sel == 'e') |
5608 ++cap->count1; /* include one more char */ | |
5609 if (cap->count0 > 0 && --cap->count1 > 0) | |
5610 { | |
5611 /* With a count select that many characters or lines. */ | |
5612 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
5613 nv_right(cap); | |
5614 else if (VIsual_mode == 'V') | |
5615 nv_down(cap); | |
5616 } | |
7 | 5617 } |
5618 } | |
5619 } | |
5620 | |
5621 /* | |
5622 * Start selection for Shift-movement keys. | |
5623 */ | |
5624 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5625 start_selection(void) |
7 | 5626 { |
5627 /* if 'selectmode' contains "key", start Select mode */ | |
5628 may_start_select('k'); | |
5629 n_start_visual_mode('v'); | |
5630 } | |
5631 | |
5632 /* | |
5633 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
5634 */ | |
5635 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5636 may_start_select(int c) |
7 | 5637 { |
5638 VIsual_select = (stuff_empty() && typebuf_typed() | |
5639 && (vim_strchr(p_slm, c) != NULL)); | |
5640 } | |
5641 | |
5642 /* | |
5643 * Start Visual mode "c". | |
5644 * Should set VIsual_select before calling this. | |
5645 */ | |
5646 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5647 n_start_visual_mode(int c) |
7 | 5648 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5649 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5650 /* Check for redraw before changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
5651 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5652 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5653 |
7 | 5654 VIsual_mode = c; |
5655 VIsual_active = TRUE; | |
5656 VIsual_reselect = TRUE; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5657 |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5658 // Corner case: the 0 position in a tab may change when going into |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5659 // virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. |
7 | 5660 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) |
3742 | 5661 { |
5662 validate_virtcol(); | |
7 | 5663 coladvance(curwin->w_virtcol); |
3742 | 5664 } |
7 | 5665 VIsual = curwin->w_cursor; |
5666 | |
5667 #ifdef FEAT_FOLDING | |
5668 foldAdjustVisual(); | |
5669 #endif | |
5670 | |
5671 setmouse(); | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5672 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5673 /* Check for redraw after changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
5674 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5675 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5676 |
641 | 5677 if (p_smd && msg_silent == 0) |
7 | 5678 redraw_cmdline = TRUE; /* show visual mode later */ |
5679 #ifdef FEAT_CLIPBOARD | |
5680 /* Make sure the clipboard gets updated. Needed because start and | |
5681 * end may still be the same, and the selection needs to be owned */ | |
5682 clip_star.vmode = NUL; | |
5683 #endif | |
5684 | |
5685 /* Only need to redraw this line, unless still need to redraw an old | |
5686 * Visual area (when 'lazyredraw' is set). */ | |
5687 if (curwin->w_redr_type < INVERTED) | |
5688 { | |
5689 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
5690 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
5691 } | |
5692 } | |
5693 | |
5694 | |
5695 /* | |
5696 * CTRL-W: Window commands | |
5697 */ | |
5698 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5699 nv_window(cmdarg_T *cap) |
7 | 5700 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
5701 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5702 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
5703 /* "CTRL-W :" is the same as typing ":"; useful in a terminal window */ |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5704 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5705 cap->nchar = NUL; |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
5706 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5707 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
5708 else if (!checkclearop(cap->oap)) |
7 | 5709 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
5710 } | |
5711 | |
5712 /* | |
5713 * CTRL-Z: Suspend | |
5714 */ | |
5715 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5716 nv_suspend(cmdarg_T *cap) |
7 | 5717 { |
5718 clearop(cap->oap); | |
5719 if (VIsual_active) | |
5720 end_visual_mode(); /* stop Visual mode */ | |
5721 do_cmdline_cmd((char_u *)"st"); | |
5722 } | |
5723 | |
5724 /* | |
5725 * Commands starting with "g". | |
5726 */ | |
5727 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5728 nv_g_cmd(cmdarg_T *cap) |
7 | 5729 { |
5730 oparg_T *oap = cap->oap; | |
5731 pos_T tpos; | |
5732 int i; | |
5733 int flag = FALSE; | |
5734 | |
5735 switch (cap->nchar) | |
5736 { | |
6868 | 5737 case Ctrl_A: |
5738 case Ctrl_X: | |
7 | 5739 #ifdef MEM_PROFILE |
5740 /* | |
5741 * "g^A": dump log of used memory. | |
5742 */ | |
6868 | 5743 if (!VIsual_active && cap->nchar == Ctrl_A) |
5744 vim_mem_profile_dump(); | |
5745 else | |
5746 #endif | |
5747 /* | |
5748 * "g^A/g^X": sequentially increment visually selected region | |
5749 */ | |
5750 if (VIsual_active) | |
5751 { | |
5752 cap->arg = TRUE; | |
5753 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
5754 cap->nchar = NUL; |
6868 | 5755 nv_addsub(cap); |
5756 } | |
5757 else | |
5758 clearopbeep(oap); | |
7 | 5759 break; |
5760 | |
5761 /* | |
5762 * "gR": Enter virtual replace mode. | |
5763 */ | |
5764 case 'R': | |
5765 cap->arg = TRUE; | |
5766 nv_Replace(cap); | |
5767 break; | |
5768 | |
5769 case 'r': | |
5770 nv_vreplace(cap); | |
5771 break; | |
5772 | |
5773 case '&': | |
5774 do_cmdline_cmd((char_u *)"%s//~/&"); | |
5775 break; | |
5776 | |
5777 /* | |
5778 * "gv": Reselect the previous Visual area. If Visual already active, | |
5779 * exchange previous and current Visual area. | |
5780 */ | |
5781 case 'v': | |
5782 if (checkclearop(oap)) | |
5783 break; | |
5784 | |
690 | 5785 if ( curbuf->b_visual.vi_start.lnum == 0 |
5786 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
5787 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 5788 beep_flush(); |
5789 else | |
5790 { | |
5791 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
5792 if (VIsual_active) | |
5793 { | |
5794 i = VIsual_mode; | |
690 | 5795 VIsual_mode = curbuf->b_visual.vi_mode; |
5796 curbuf->b_visual.vi_mode = i; | |
7 | 5797 # ifdef FEAT_EVAL |
5798 curbuf->b_visual_mode_eval = i; | |
5799 # endif | |
5800 i = curwin->w_curswant; | |
690 | 5801 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
5802 curbuf->b_visual.vi_curswant = i; | |
5803 | |
5804 tpos = curbuf->b_visual.vi_end; | |
5805 curbuf->b_visual.vi_end = curwin->w_cursor; | |
5806 curwin->w_cursor = curbuf->b_visual.vi_start; | |
5807 curbuf->b_visual.vi_start = VIsual; | |
7 | 5808 } |
5809 else | |
5810 { | |
690 | 5811 VIsual_mode = curbuf->b_visual.vi_mode; |
5812 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
5813 tpos = curbuf->b_visual.vi_end; | |
5814 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 5815 } |
5816 | |
5817 VIsual_active = TRUE; | |
5818 VIsual_reselect = TRUE; | |
5819 | |
5820 /* Set Visual to the start and w_cursor to the end of the Visual | |
5821 * area. Make sure they are on an existing character. */ | |
5822 check_cursor(); | |
5823 VIsual = curwin->w_cursor; | |
5824 curwin->w_cursor = tpos; | |
5825 check_cursor(); | |
5826 update_topline(); | |
5827 /* | |
5828 * When called from normal "g" command: start Select mode when | |
5829 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
5830 * start Select mode. | |
5831 */ | |
5832 if (cap->arg) | |
5833 VIsual_select = TRUE; | |
5834 else | |
5835 may_start_select('c'); | |
5836 setmouse(); | |
5837 #ifdef FEAT_CLIPBOARD | |
5838 /* Make sure the clipboard gets updated. Needed because start and | |
5839 * end are still the same, and the selection needs to be owned */ | |
5840 clip_star.vmode = NUL; | |
5841 #endif | |
5842 redraw_curbuf_later(INVERTED); | |
5843 showmode(); | |
5844 } | |
5845 break; | |
5846 /* | |
5847 * "gV": Don't reselect the previous Visual area after a Select mode | |
5848 * mapping of menu. | |
5849 */ | |
5850 case 'V': | |
5851 VIsual_reselect = FALSE; | |
5852 break; | |
5853 | |
5854 /* | |
5855 * "gh": start Select mode. | |
5856 * "gH": start Select line mode. | |
5857 * "g^H": start Select block mode. | |
5858 */ | |
5859 case K_BS: | |
5860 cap->nchar = Ctrl_H; | |
5861 /* FALLTHROUGH */ | |
5862 case 'h': | |
5863 case 'H': | |
5864 case Ctrl_H: | |
5865 # ifdef EBCDIC | |
5866 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
5867 if (cap->nchar == Ctrl_H) | |
5868 cap->cmdchar = Ctrl_V; | |
5869 else | |
5870 # endif | |
5871 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
5872 cap->arg = TRUE; | |
5873 nv_visual(cap); | |
5874 break; | |
3701 | 5875 |
5876 /* "gn", "gN" visually select next/previous search match | |
5877 * "gn" selects next match | |
5878 * "gN" selects previous match | |
5879 */ | |
5880 case 'N': | |
5881 case 'n': | |
5882 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 5883 clearopbeep(oap); |
3701 | 5884 break; |
7 | 5885 |
5886 /* | |
5887 * "gj" and "gk" two new funny movement keys -- up and down | |
5888 * movement based on *screen* line rather than *file* line. | |
5889 */ | |
5890 case 'j': | |
5891 case K_DOWN: | |
5892 /* with 'nowrap' it works just like the normal "j" command; also when | |
5893 * in a closed fold */ | |
5894 if (!curwin->w_p_wrap | |
5895 #ifdef FEAT_FOLDING | |
5896 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
5897 #endif | |
5898 ) | |
5899 { | |
5900 oap->motion_type = MLINE; | |
5901 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
5902 } | |
5903 else | |
5904 i = nv_screengo(oap, FORWARD, cap->count1); | |
5905 if (i == FAIL) | |
5906 clearopbeep(oap); | |
5907 break; | |
5908 | |
5909 case 'k': | |
5910 case K_UP: | |
5911 /* with 'nowrap' it works just like the normal "k" command; also when | |
5912 * in a closed fold */ | |
5913 if (!curwin->w_p_wrap | |
5914 #ifdef FEAT_FOLDING | |
5915 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
5916 #endif | |
5917 ) | |
5918 { | |
5919 oap->motion_type = MLINE; | |
5920 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
5921 } | |
5922 else | |
5923 i = nv_screengo(oap, BACKWARD, cap->count1); | |
5924 if (i == FAIL) | |
5925 clearopbeep(oap); | |
5926 break; | |
5927 | |
5928 /* | |
5929 * "gJ": join two lines without inserting a space. | |
5930 */ | |
5931 case 'J': | |
5932 nv_join(cap); | |
5933 break; | |
5934 | |
5935 /* | |
5936 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
5937 * "gm": middle of "g0" and "g$". | |
5938 */ | |
5939 case '^': | |
5940 flag = TRUE; | |
5941 /* FALLTHROUGH */ | |
5942 | |
5943 case '0': | |
5944 case 'm': | |
5945 case K_HOME: | |
5946 case K_KHOME: | |
5947 oap->motion_type = MCHAR; | |
5948 oap->inclusive = FALSE; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
5949 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 5950 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
5951 int width1 = curwin->w_width - curwin_col_off(); |
7 | 5952 int width2 = width1 + curwin_col_off2(); |
5953 | |
5954 validate_virtcol(); | |
5955 i = 0; | |
5956 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
5957 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
5958 } | |
5959 else | |
5960 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
5961 /* Go to the middle of the screen line. When 'number' or |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
5962 * 'relativenumber' is on and lines are wrapping the middle can be more |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
5963 * to the left. */ |
7 | 5964 if (cap->nchar == 'm') |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
5965 i += (curwin->w_width - curwin_col_off() |
7 | 5966 + ((curwin->w_p_wrap && i > 0) |
5967 ? curwin_col_off2() : 0)) / 2; | |
5968 coladvance((colnr_T)i); | |
5969 if (flag) | |
5970 { | |
5971 do | |
5972 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5973 while (VIM_ISWHITE(i) && oneright() == OK); |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
15006
diff
changeset
|
5974 curwin->w_valid &= ~VALID_WCOL; |
7 | 5975 } |
5976 curwin->w_set_curswant = TRUE; | |
5977 break; | |
5978 | |
5979 case '_': | |
5980 /* "g_": to the last non-blank character in the line or <count> lines | |
5981 * downward. */ | |
5982 cap->oap->motion_type = MCHAR; | |
5983 cap->oap->inclusive = TRUE; | |
5984 curwin->w_curswant = MAXCOL; | |
5985 if (cursor_down((long)(cap->count1 - 1), | |
5986 cap->oap->op_type == OP_NOP) == FAIL) | |
5987 clearopbeep(cap->oap); | |
5988 else | |
5989 { | |
5990 char_u *ptr = ml_get_curline(); | |
5991 | |
5992 /* In Visual mode we may end up after the line. */ | |
5993 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
5994 --curwin->w_cursor.col; | |
5995 | |
5996 /* Decrease the cursor column until it's on a non-blank. */ | |
5997 while (curwin->w_cursor.col > 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5998 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 5999 --curwin->w_cursor.col; |
6000 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
6001 adjust_for_sel(cap); |
7 | 6002 } |
6003 break; | |
6004 | |
6005 case '$': | |
6006 case K_END: | |
6007 case K_KEND: | |
6008 { | |
6009 int col_off = curwin_col_off(); | |
6010 | |
6011 oap->motion_type = MCHAR; | |
6012 oap->inclusive = TRUE; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
6013 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 6014 { |
6015 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6016 if (cap->count1 == 1) | |
6017 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6018 int width1 = curwin->w_width - col_off; |
7 | 6019 int width2 = width1 + curwin_col_off2(); |
6020 | |
6021 validate_virtcol(); | |
6022 i = width1 - 1; | |
6023 if (curwin->w_virtcol >= (colnr_T)width1) | |
6024 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
6025 * width2; | |
6026 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6027 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6028 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6029 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6030 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6031 curwin->w_set_curswant = FALSE; |
7 | 6032 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
6033 { | |
6034 /* | |
6035 * Check for landing on a character that got split at | |
6036 * the end of the line. We do not want to advance to | |
6037 * the next screen line. | |
6038 */ | |
6039 if (curwin->w_virtcol > (colnr_T)i) | |
6040 --curwin->w_cursor.col; | |
6041 } | |
6042 } | |
6043 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
6044 clearopbeep(oap); | |
6045 } | |
6046 else | |
6047 { | |
17520
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
6048 if (cap->count1 > 1) |
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
6049 // if it fails, let the cursor still move to the last char |
17730
2fe133c7e972
patch 8.1.1862: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents:
17682
diff
changeset
|
6050 (void)cursor_down(cap->count1 - 1, FALSE); |
17520
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
6051 |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6052 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 6053 coladvance((colnr_T)i); |
40 | 6054 |
17520
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
6055 // Make sure we stick in this column. |
40 | 6056 validate_virtcol(); |
6057 curwin->w_curswant = curwin->w_virtcol; | |
6058 curwin->w_set_curswant = FALSE; | |
7 | 6059 } |
6060 } | |
6061 break; | |
6062 | |
6063 /* | |
6064 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
6065 */ | |
6066 case '*': | |
6067 case '#': | |
6068 #if POUND != '#' | |
6069 case POUND: /* pound sign (sometimes equal to '#') */ | |
6070 #endif | |
6071 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
6072 case ']': /* :tselect for current identifier */ | |
6073 nv_ident(cap); | |
6074 break; | |
6075 | |
6076 /* | |
6077 * ge and gE: go back to end of word | |
6078 */ | |
6079 case 'e': | |
6080 case 'E': | |
6081 oap->motion_type = MCHAR; | |
6082 curwin->w_set_curswant = TRUE; | |
6083 oap->inclusive = TRUE; | |
6084 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
6085 clearopbeep(oap); | |
6086 break; | |
6087 | |
6088 /* | |
6089 * "g CTRL-G": display info about cursor position | |
6090 */ | |
6091 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
6092 cursor_pos_info(NULL); |
7 | 6093 break; |
6094 | |
6095 /* | |
6096 * "gi": start Insert at the last position. | |
6097 */ | |
6098 case 'i': | |
6099 if (curbuf->b_last_insert.lnum != 0) | |
6100 { | |
6101 curwin->w_cursor = curbuf->b_last_insert; | |
6102 check_cursor_lnum(); | |
6103 i = (int)STRLEN(ml_get_curline()); | |
6104 if (curwin->w_cursor.col > (colnr_T)i) | |
6105 { | |
6106 if (virtual_active()) | |
6107 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
6108 curwin->w_cursor.col = i; | |
6109 } | |
6110 } | |
6111 cap->cmdchar = 'i'; | |
6112 nv_edit(cap); | |
6113 break; | |
6114 | |
6115 /* | |
6116 * "gI": Start insert in column 1. | |
6117 */ | |
6118 case 'I': | |
6119 beginline(0); | |
6120 if (!checkclearopq(oap)) | |
6121 invoke_edit(cap, FALSE, 'g', FALSE); | |
6122 break; | |
6123 | |
6124 #ifdef FEAT_SEARCHPATH | |
6125 /* | |
6126 * "gf": goto file, edit file under cursor | |
6127 * "]f" and "[f": can also be used. | |
6128 */ | |
6129 case 'f': | |
681 | 6130 case 'F': |
7 | 6131 nv_gotofile(cap); |
6132 break; | |
6133 #endif | |
6134 | |
6135 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
6136 case '\'': | |
6137 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
6138 /* FALLTHROUGH */ |
7 | 6139 case '`': |
6140 nv_gomark(cap); | |
6141 break; | |
6142 | |
6143 /* | |
6144 * "gs": Goto sleep. | |
6145 */ | |
6146 case 's': | |
6147 do_sleep(cap->count1 * 1000L); | |
6148 break; | |
6149 | |
6150 /* | |
6151 * "ga": Display the ascii value of the character under the | |
6152 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
6153 */ | |
6154 case 'a': | |
6155 do_ascii(NULL); | |
6156 break; | |
6157 | |
6158 /* | |
6159 * "g8": Display the bytes used for the UTF-8 character under the | |
6160 * cursor. It is displayed in hex. | |
775 | 6161 * "8g8" finds illegal byte sequence. |
7 | 6162 */ |
6163 case '8': | |
775 | 6164 if (cap->count0 == 8) |
6165 utf_find_illegal(); | |
6166 else | |
6167 show_utf8(); | |
7 | 6168 break; |
6169 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6170 /* "g<": show scrollback text */ |
447 | 6171 case '<': |
6172 show_sb_text(); | |
6173 break; | |
6174 | |
7 | 6175 /* |
6176 * "gg": Goto the first line in file. With a count it goes to | |
6177 * that line number like for "G". -- webb | |
6178 */ | |
6179 case 'g': | |
6180 cap->arg = FALSE; | |
6181 nv_goto(cap); | |
6182 break; | |
6183 | |
6184 /* | |
6185 * Two-character operators: | |
6186 * "gq" Format text | |
6187 * "gw" Format text and keep cursor position | |
6188 * "g~" Toggle the case of the text. | |
6189 * "gu" Change text to lower case. | |
6190 * "gU" Change text to upper case. | |
6191 * "g?" rot13 encoding | |
602 | 6192 * "g@" call 'operatorfunc' |
7 | 6193 */ |
6194 case 'q': | |
6195 case 'w': | |
6196 oap->cursor_start = curwin->w_cursor; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
6197 /* FALLTHROUGH */ |
7 | 6198 case '~': |
6199 case 'u': | |
6200 case 'U': | |
6201 case '?': | |
602 | 6202 case '@': |
7 | 6203 nv_operator(cap); |
6204 break; | |
6205 | |
6206 /* | |
1188 | 6207 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 6208 * current function |
6209 * "gD": idem, but in the current file. | |
6210 */ | |
6211 case 'd': | |
6212 case 'D': | |
523 | 6213 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 6214 break; |
6215 | |
6216 #ifdef FEAT_MOUSE | |
6217 /* | |
6218 * g<*Mouse> : <C-*mouse> | |
6219 */ | |
6220 case K_MIDDLEMOUSE: | |
6221 case K_MIDDLEDRAG: | |
6222 case K_MIDDLERELEASE: | |
6223 case K_LEFTMOUSE: | |
6224 case K_LEFTDRAG: | |
6225 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
6226 case K_MOUSEMOVE: |
7 | 6227 case K_RIGHTMOUSE: |
6228 case K_RIGHTDRAG: | |
6229 case K_RIGHTRELEASE: | |
6230 case K_X1MOUSE: | |
6231 case K_X1DRAG: | |
6232 case K_X1RELEASE: | |
6233 case K_X2MOUSE: | |
6234 case K_X2DRAG: | |
6235 case K_X2RELEASE: | |
6236 mod_mask = MOD_MASK_CTRL; | |
6237 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
6238 break; | |
6239 #endif | |
6240 | |
6241 case K_IGNORE: | |
6242 break; | |
6243 | |
6244 /* | |
6245 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
6246 */ | |
6247 case 'p': | |
6248 case 'P': | |
6249 nv_put(cap); | |
6250 break; | |
6251 | |
6252 #ifdef FEAT_BYTEOFF | |
6253 /* "go": goto byte count from start of buffer */ | |
6254 case 'o': | |
6255 goto_byte(cap->count0); | |
6256 break; | |
6257 #endif | |
6258 | |
6259 /* "gQ": improved Ex mode */ | |
6260 case 'Q': | |
633 | 6261 if (text_locked()) |
7 | 6262 { |
6263 clearopbeep(cap->oap); | |
633 | 6264 text_locked_msg(); |
7 | 6265 break; |
6266 } | |
631 | 6267 |
7 | 6268 if (!checkclearopq(oap)) |
6269 do_exmode(TRUE); | |
6270 break; | |
6271 | |
6272 #ifdef FEAT_JUMPLIST | |
6273 case ',': | |
6274 nv_pcmark(cap); | |
6275 break; | |
6276 | |
6277 case ';': | |
6278 cap->count1 = -cap->count1; | |
6279 nv_pcmark(cap); | |
6280 break; | |
6281 #endif | |
6282 | |
667 | 6283 case 't': |
3630 | 6284 if (!checkclearop(oap)) |
6285 goto_tabpage((int)cap->count0); | |
667 | 6286 break; |
682 | 6287 case 'T': |
3630 | 6288 if (!checkclearop(oap)) |
6289 goto_tabpage(-(int)cap->count1); | |
682 | 6290 break; |
667 | 6291 |
750 | 6292 case '+': |
6293 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
6294 if (!checkclearopq(oap)) | |
771 | 6295 undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1, |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2259
diff
changeset
|
6296 FALSE, FALSE, FALSE); |
750 | 6297 break; |
6298 | |
7 | 6299 default: |
6300 clearopbeep(oap); | |
6301 break; | |
6302 } | |
6303 } | |
6304 | |
6305 /* | |
6306 * Handle "o" and "O" commands. | |
6307 */ | |
6308 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6309 n_opencmd(cmdarg_T *cap) |
7 | 6310 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6311 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6312 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6313 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6314 |
7 | 6315 if (!checkclearopq(cap->oap)) |
6316 { | |
6317 #ifdef FEAT_FOLDING | |
6318 if (cap->cmdchar == 'O') | |
6319 /* Open above the first line of a folded sequence of lines */ | |
6320 (void)hasFolding(curwin->w_cursor.lnum, | |
6321 &curwin->w_cursor.lnum, NULL); | |
6322 else | |
6323 /* Open below the last line of a folded sequence of lines */ | |
6324 (void)hasFolding(curwin->w_cursor.lnum, | |
6325 NULL, &curwin->w_cursor.lnum); | |
6326 #endif | |
6327 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
6328 (cap->cmdchar == 'O' ? 1 : 0)), | |
6329 (linenr_T)(curwin->w_cursor.lnum + | |
6330 (cap->cmdchar == 'o' ? 1 : 0)) | |
6331 ) == OK | |
6332 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18154
diff
changeset
|
6333 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : 0, |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18154
diff
changeset
|
6334 0) == OK) |
7 | 6335 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6336 #ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
6337 if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum) |
15436
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
6338 redrawWinline(curwin, oldline); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6339 #endif |
6834 | 6340 #ifdef FEAT_SYN_HL |
6821 | 6341 if (curwin->w_p_cul) |
6342 /* force redraw of cursorline */ | |
6343 curwin->w_valid &= ~VALID_CROW; | |
6834 | 6344 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
6345 /* When '#' is in 'cpoptions' ignore the count. */ |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
6346 if (vim_strchr(p_cpo, CPO_HASH) != NULL) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
6347 cap->count1 = 1; |
7 | 6348 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
6349 } | |
6350 } | |
6351 } | |
6352 | |
6353 /* | |
6354 * "." command: redo last change. | |
6355 */ | |
6356 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6357 nv_dot(cmdarg_T *cap) |
7 | 6358 { |
6359 if (!checkclearopq(cap->oap)) | |
6360 { | |
6361 /* | |
6362 * If "restart_edit" is TRUE, the last but one command is repeated | |
6363 * instead of the last command (inserting text). This is used for | |
6364 * CTRL-O <.> in insert mode. | |
6365 */ | |
6366 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
6367 clearopbeep(cap->oap); | |
6368 } | |
6369 } | |
6370 | |
6371 /* | |
6372 * CTRL-R: undo undo | |
6373 */ | |
6374 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6375 nv_redo(cmdarg_T *cap) |
7 | 6376 { |
6377 if (!checkclearopq(cap->oap)) | |
6378 { | |
6379 u_redo((int)cap->count1); | |
6380 curwin->w_set_curswant = TRUE; | |
6381 } | |
6382 } | |
6383 | |
6384 /* | |
6385 * Handle "U" command. | |
6386 */ | |
6387 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6388 nv_Undo(cmdarg_T *cap) |
7 | 6389 { |
6390 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 6391 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 6392 { |
6393 /* translate "gUU" to "gUgU" */ | |
6394 cap->cmdchar = 'g'; | |
6395 cap->nchar = 'U'; | |
6396 nv_operator(cap); | |
6397 } | |
6398 else if (!checkclearopq(cap->oap)) | |
6399 { | |
6400 u_undoline(); | |
6401 curwin->w_set_curswant = TRUE; | |
6402 } | |
6403 } | |
6404 | |
6405 /* | |
6406 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
6407 * single character. | |
6408 */ | |
6409 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6410 nv_tilde(cmdarg_T *cap) |
7 | 6411 { |
5735 | 6412 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6413 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6414 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6415 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6416 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6417 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6418 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6419 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6420 #endif |
7 | 6421 n_swapchar(cap); |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6422 } |
7 | 6423 else |
6424 nv_operator(cap); | |
6425 } | |
6426 | |
6427 /* | |
6428 * Handle an operator command. | |
6429 * The actual work is done by do_pending_operator(). | |
6430 */ | |
6431 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6432 nv_operator(cmdarg_T *cap) |
7 | 6433 { |
6434 int op_type; | |
6435 | |
6436 op_type = get_op_type(cap->cmdchar, cap->nchar); | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6437 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6438 if (bt_prompt(curbuf) && op_is_change(op_type) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6439 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6440 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6441 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6442 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6443 #endif |
7 | 6444 |
6445 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
6446 nv_lineop(cap); | |
6447 else if (!checkclearop(cap->oap)) | |
6448 { | |
6449 cap->oap->start = curwin->w_cursor; | |
6450 cap->oap->op_type = op_type; | |
1490 | 6451 #ifdef FEAT_EVAL |
6452 set_op_var(op_type); | |
6453 #endif | |
6454 } | |
6455 } | |
6456 | |
6457 #ifdef FEAT_EVAL | |
6458 /* | |
6459 * Set v:operator to the characters for "optype". | |
6460 */ | |
6461 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6462 set_op_var(int optype) |
1490 | 6463 { |
6464 char_u opchars[3]; | |
6465 | |
6466 if (optype == OP_NOP) | |
6467 set_vim_var_string(VV_OP, NULL, 0); | |
6468 else | |
6469 { | |
6470 opchars[0] = get_op_char(optype); | |
6471 opchars[1] = get_extra_op_char(optype); | |
6472 opchars[2] = NUL; | |
6473 set_vim_var_string(VV_OP, opchars, -1); | |
6474 } | |
6475 } | |
6476 #endif | |
7 | 6477 |
6478 /* | |
6479 * Handle linewise operator "dd", "yy", etc. | |
6480 * | |
6481 * "_" is is a strange motion command that helps make operators more logical. | |
6482 * It is actually implemented, but not documented in the real Vi. This motion | |
6483 * command actually refers to "the current line". Commands like "dd" and "yy" | |
6484 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
6485 * "d3_" works to delete 3 lines. | |
6486 */ | |
6487 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6488 nv_lineop(cmdarg_T *cap) |
7 | 6489 { |
6490 cap->oap->motion_type = MLINE; | |
6491 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
6492 clearopbeep(cap->oap); | |
4011 | 6493 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
6494 && cap->oap->motion_force != 'v' | |
6495 && cap->oap->motion_force != Ctrl_V) | |
7 | 6496 || cap->oap->op_type == OP_LSHIFT |
6497 || cap->oap->op_type == OP_RSHIFT) | |
6498 beginline(BL_SOL | BL_FIX); | |
6499 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
6500 beginline(BL_WHITE | BL_FIX); | |
6501 } | |
6502 | |
6503 /* | |
6504 * <Home> command. | |
6505 */ | |
6506 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6507 nv_home(cmdarg_T *cap) |
7 | 6508 { |
180 | 6509 /* CTRL-HOME is like "gg" */ |
6510 if (mod_mask & MOD_MASK_CTRL) | |
6511 nv_goto(cap); | |
6512 else | |
6513 { | |
6514 cap->count0 = 1; | |
6515 nv_pipe(cap); | |
6516 } | |
229 | 6517 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
6518 one-character line). */ | |
7 | 6519 } |
6520 | |
6521 /* | |
6522 * "|" command. | |
6523 */ | |
6524 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6525 nv_pipe(cmdarg_T *cap) |
7 | 6526 { |
6527 cap->oap->motion_type = MCHAR; | |
6528 cap->oap->inclusive = FALSE; | |
6529 beginline(0); | |
6530 if (cap->count0 > 0) | |
6531 { | |
6532 coladvance((colnr_T)(cap->count0 - 1)); | |
6533 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
6534 } | |
6535 else | |
6536 curwin->w_curswant = 0; | |
6537 /* keep curswant at the column where we wanted to go, not where | |
2667 | 6538 * we ended; differs if line is too short */ |
7 | 6539 curwin->w_set_curswant = FALSE; |
6540 } | |
6541 | |
6542 /* | |
6543 * Handle back-word command "b" and "B". | |
6544 * cap->arg is 1 for "B" | |
6545 */ | |
6546 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6547 nv_bck_word(cmdarg_T *cap) |
7 | 6548 { |
6549 cap->oap->motion_type = MCHAR; | |
6550 cap->oap->inclusive = FALSE; | |
6551 curwin->w_set_curswant = TRUE; | |
6552 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
6553 clearopbeep(cap->oap); | |
6554 #ifdef FEAT_FOLDING | |
6555 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6556 foldOpenCursor(); | |
6557 #endif | |
6558 } | |
6559 | |
6560 /* | |
6561 * Handle word motion commands "e", "E", "w" and "W". | |
6562 * cap->arg is TRUE for "E" and "W". | |
6563 */ | |
6564 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6565 nv_wordcmd(cmdarg_T *cap) |
7 | 6566 { |
6567 int n; | |
6568 int word_end; | |
6569 int flag = FALSE; | |
1573 | 6570 pos_T startpos = curwin->w_cursor; |
7 | 6571 |
6572 /* | |
6573 * Set inclusive for the "E" and "e" command. | |
6574 */ | |
6575 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
6576 word_end = TRUE; | |
6577 else | |
6578 word_end = FALSE; | |
6579 cap->oap->inclusive = word_end; | |
6580 | |
6581 /* | |
6582 * "cw" and "cW" are a special case. | |
6583 */ | |
6584 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
6585 { | |
6586 n = gchar_cursor(); | |
6587 if (n != NUL) /* not an empty line */ | |
6588 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
6589 if (VIM_ISWHITE(n)) |
7 | 6590 { |
6591 /* | |
6592 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
6593 * changes one character, not all blanks until the start of | |
6594 * the next word. Only do this when the 'w' flag is included | |
6595 * in 'cpoptions'. | |
6596 */ | |
6597 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
6598 { | |
6599 cap->oap->inclusive = TRUE; | |
6600 cap->oap->motion_type = MCHAR; | |
6601 return; | |
6602 } | |
6603 } | |
6604 else | |
6605 { | |
6606 /* | |
6607 * This is a little strange. To match what the real Vi does, | |
6608 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
6609 * that we are not on a space or a TAB. This seems impolite | |
6610 * at first, but it's really more what we mean when we say | |
6611 * 'cw'. | |
6612 * Another strangeness: When standing on the end of a word | |
4352 | 6613 * "ce" will change until the end of the next word, but "cw" |
7 | 6614 * will change only one character! This is done by setting |
6615 * flag. | |
6616 */ | |
6617 cap->oap->inclusive = TRUE; | |
6618 word_end = TRUE; | |
6619 flag = TRUE; | |
6620 } | |
6621 } | |
6622 } | |
6623 | |
6624 cap->oap->motion_type = MCHAR; | |
6625 curwin->w_set_curswant = TRUE; | |
6626 if (word_end) | |
6627 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
6628 else | |
6629 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
6630 | |
1573 | 6631 /* Don't leave the cursor on the NUL past the end of line. Unless we |
6632 * didn't move it forward. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6633 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 6634 adjust_cursor(cap->oap); |
7 | 6635 |
6636 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
6637 clearopbeep(cap->oap); | |
6638 else | |
6639 { | |
6640 adjust_for_sel(cap); | |
6641 #ifdef FEAT_FOLDING | |
6642 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6643 foldOpenCursor(); | |
6644 #endif | |
6645 } | |
6646 } | |
6647 | |
6648 /* | |
1505 | 6649 * Used after a movement command: If the cursor ends up on the NUL after the |
6650 * end of the line, may move it back to the last character and make the motion | |
6651 * inclusive. | |
6652 */ | |
6653 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6654 adjust_cursor(oparg_T *oap) |
1505 | 6655 { |
6656 /* The cursor cannot remain on the NUL when: | |
6657 * - the column is > 0 | |
6658 * - not in Visual mode or 'selection' is "o" | |
6659 * - 'virtualedit' is not "all" and not "onemore". | |
6660 */ | |
6661 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
6662 && (!VIsual_active || *p_sel == 'o') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
6663 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0) |
1505 | 6664 { |
6665 --curwin->w_cursor.col; | |
6666 /* prevent cursor from moving on the trail byte */ | |
6667 if (has_mbyte) | |
6668 mb_adjust_cursor(); | |
6669 oap->inclusive = TRUE; | |
6670 } | |
6671 } | |
6672 | |
6673 /* | |
7 | 6674 * "0" and "^" commands. |
6675 * cap->arg is the argument for beginline(). | |
6676 */ | |
6677 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6678 nv_beginline(cmdarg_T *cap) |
7 | 6679 { |
6680 cap->oap->motion_type = MCHAR; | |
6681 cap->oap->inclusive = FALSE; | |
6682 beginline(cap->arg); | |
6683 #ifdef FEAT_FOLDING | |
6684 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6685 foldOpenCursor(); | |
6686 #endif | |
557 | 6687 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
6688 one-character line). */ | |
7 | 6689 } |
6690 | |
6691 /* | |
6692 * In exclusive Visual mode, may include the last character. | |
6693 */ | |
6694 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6695 adjust_for_sel(cmdarg_T *cap) |
7 | 6696 { |
6697 if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6698 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 6699 { |
6700 if (has_mbyte) | |
6701 inc_cursor(); | |
6702 else | |
6703 ++curwin->w_cursor.col; | |
6704 cap->oap->inclusive = FALSE; | |
6705 } | |
6706 } | |
6707 | |
6708 /* | |
6709 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
6710 * Should check VIsual_mode before calling this. | |
6711 * Returns TRUE when backed up to the previous line. | |
6712 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
6713 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6714 unadjust_for_sel(void) |
7 | 6715 { |
6716 pos_T *pp; | |
6717 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6718 if (*p_sel == 'e' && !EQUAL_POS(VIsual, curwin->w_cursor)) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6719 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6720 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 6721 pp = &curwin->w_cursor; |
6722 else | |
6723 pp = &VIsual; | |
6724 if (pp->coladd > 0) | |
6725 --pp->coladd; | |
6726 else | |
6727 if (pp->col > 0) | |
6728 { | |
6729 --pp->col; | |
2933 | 6730 mb_adjustpos(curbuf, pp); |
7 | 6731 } |
6732 else if (pp->lnum > 1) | |
6733 { | |
6734 --pp->lnum; | |
6735 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
6736 return TRUE; | |
6737 } | |
6738 } | |
6739 return FALSE; | |
6740 } | |
6741 | |
6742 /* | |
6743 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
6744 */ | |
6745 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6746 nv_select(cmdarg_T *cap) |
7 | 6747 { |
6748 if (VIsual_active) | |
6749 VIsual_select = TRUE; | |
6750 else if (VIsual_reselect) | |
6751 { | |
6752 cap->nchar = 'v'; /* fake "gv" command */ | |
6753 cap->arg = TRUE; | |
6754 nv_g_cmd(cap); | |
6755 } | |
6756 } | |
6757 | |
6758 | |
6759 /* | |
6760 * "G", "gg", CTRL-END, CTRL-HOME. | |
6761 * cap->arg is TRUE for "G". | |
6762 */ | |
6763 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6764 nv_goto(cmdarg_T *cap) |
7 | 6765 { |
6766 linenr_T lnum; | |
6767 | |
6768 if (cap->arg) | |
6769 lnum = curbuf->b_ml.ml_line_count; | |
6770 else | |
6771 lnum = 1L; | |
6772 cap->oap->motion_type = MLINE; | |
6773 setpcmark(); | |
6774 | |
6775 /* When a count is given, use it instead of the default lnum */ | |
6776 if (cap->count0 != 0) | |
6777 lnum = cap->count0; | |
6778 if (lnum < 1L) | |
6779 lnum = 1L; | |
6780 else if (lnum > curbuf->b_ml.ml_line_count) | |
6781 lnum = curbuf->b_ml.ml_line_count; | |
6782 curwin->w_cursor.lnum = lnum; | |
6783 beginline(BL_SOL | BL_FIX); | |
6784 #ifdef FEAT_FOLDING | |
6785 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6786 foldOpenCursor(); | |
6787 #endif | |
6788 } | |
6789 | |
6790 /* | |
6791 * CTRL-\ in Normal mode. | |
6792 */ | |
6793 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6794 nv_normal(cmdarg_T *cap) |
7 | 6795 { |
6796 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
6797 { | |
6798 clearop(cap->oap); | |
643 | 6799 if (restart_edit != 0 && mode_displayed) |
7 | 6800 clear_cmdline = TRUE; /* unshow mode later */ |
6801 restart_edit = 0; | |
6802 #ifdef FEAT_CMDWIN | |
6803 if (cmdwin_type != 0) | |
6804 cmdwin_result = Ctrl_C; | |
6805 #endif | |
6806 if (VIsual_active) | |
6807 { | |
6808 end_visual_mode(); /* stop Visual */ | |
6809 redraw_curbuf_later(INVERTED); | |
6810 } | |
6811 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
6812 if (cap->nchar == Ctrl_G && p_im) | |
6813 restart_edit = 'a'; | |
6814 } | |
6815 else | |
6816 clearopbeep(cap->oap); | |
6817 } | |
6818 | |
6819 /* | |
6820 * ESC in Normal mode: beep, but don't flush buffers. | |
6821 * Don't even beep if we are canceling a command. | |
6822 */ | |
6823 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6824 nv_esc(cmdarg_T *cap) |
7 | 6825 { |
6826 int no_reason; | |
6827 | |
6828 no_reason = (cap->oap->op_type == OP_NOP | |
6829 && cap->opcount == 0 | |
6830 && cap->count0 == 0 | |
6831 && cap->oap->regname == 0 | |
6832 && !p_im); | |
6833 | |
6834 if (cap->arg) /* TRUE for CTRL-C */ | |
6835 { | |
6836 if (restart_edit == 0 | |
6837 #ifdef FEAT_CMDWIN | |
6838 && cmdwin_type == 0 | |
6839 #endif | |
6840 && !VIsual_active | |
6841 && no_reason) | |
16089
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6842 { |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6843 if (anyBufIsChanged()) |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6844 msg(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6845 else |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6846 msg(_("Type :qa and press <Enter> to exit Vim")); |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6847 } |
7 | 6848 |
6849 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
6850 * set again below when halfway a mapping. */ | |
6851 if (!p_im) | |
6852 restart_edit = 0; | |
6853 #ifdef FEAT_CMDWIN | |
6854 if (cmdwin_type != 0) | |
6855 { | |
6856 cmdwin_result = K_IGNORE; | |
6857 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
6858 return; | |
6859 } | |
6860 #endif | |
6861 } | |
6862 | |
6863 if (VIsual_active) | |
6864 { | |
6865 end_visual_mode(); /* stop Visual */ | |
6866 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
6867 curwin->w_set_curswant = TRUE; | |
6868 redraw_curbuf_later(INVERTED); | |
6869 } | |
5735 | 6870 else if (no_reason) |
6949 | 6871 vim_beep(BO_ESC); |
7 | 6872 clearop(cap->oap); |
6873 | |
6874 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
6875 * set return to Insert mode afterwards. */ | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
6876 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 6877 restart_edit = 'a'; |
6878 } | |
6879 | |
6880 /* | |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6881 * Move the cursor for the "A" command. |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6882 */ |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6883 void |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6884 set_cursor_for_append_to_line(void) |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6885 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6886 curwin->w_set_curswant = TRUE; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6887 if (ve_flags == VE_ALL) |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6888 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6889 int save_State = State; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6890 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6891 /* Pretend Insert mode here to allow the cursor on the |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6892 * character past the end of the line */ |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6893 State = INSERT; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6894 coladvance((colnr_T)MAXCOL); |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6895 State = save_State; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6896 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6897 else |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6898 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6899 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6900 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6901 /* |
7 | 6902 * Handle "A", "a", "I", "i" and <Insert> commands. |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
6903 * Also handle K_PS, start bracketed paste. |
7 | 6904 */ |
6905 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6906 nv_edit(cmdarg_T *cap) |
7 | 6907 { |
6908 /* <Insert> is equal to "i" */ | |
6909 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
6910 cap->cmdchar = 'i'; | |
6911 | |
6912 /* in Visual mode "A" and "I" are an operator */ | |
6913 if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) | |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6914 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6915 #ifdef FEAT_TERMINAL |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6916 if (term_in_normal_mode()) |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6917 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6918 end_visual_mode(); |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6919 clearop(cap->oap); |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6920 term_enter_job_mode(); |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6921 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6922 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6923 #endif |
7 | 6924 v_visop(cap); |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
6925 } |
7 | 6926 |
6927 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 6928 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
6929 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 6930 { |
6931 #ifdef FEAT_TEXTOBJ | |
6932 nv_object(cap); | |
6933 #else | |
6934 clearopbeep(cap->oap); | |
6935 #endif | |
6936 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
6937 #ifdef FEAT_TERMINAL |
11993
92a86fe8adc0
patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
11987
diff
changeset
|
6938 else if (term_in_normal_mode()) |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
6939 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
6940 clearop(cap->oap); |
11993
92a86fe8adc0
patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
11987
diff
changeset
|
6941 term_enter_job_mode(); |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
6942 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
6943 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
6944 #endif |
7 | 6945 else if (!curbuf->b_p_ma && !p_im) |
6946 { | |
6947 /* Only give this error when 'insertmode' is off. */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
6948 emsg(_(e_modifiable)); |
7 | 6949 clearop(cap->oap); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
6950 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
6951 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
6952 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 6953 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6954 else if (cap->cmdchar == K_PS && VIsual_active) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6955 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6956 pos_T old_pos = curwin->w_cursor; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6957 pos_T old_visual = VIsual; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6958 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6959 /* In Visual mode the selected text is deleted. */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6960 if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6961 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6962 shift_delete_registers(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6963 cap->oap->regname = '1'; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6964 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6965 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6966 cap->oap->regname = '-'; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6967 cap->cmdchar = 'd'; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6968 cap->nchar = NUL; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6969 nv_operator(cap); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6970 do_pending_operator(cap, 0, FALSE); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6971 cap->cmdchar = K_PS; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6972 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6973 /* When the last char in the line was deleted then append. Detect this |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6974 * by checking if the cursor moved to before the Visual area. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6975 if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6976 && LT_POS(curwin->w_cursor, old_visual)) |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6977 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6978 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6979 /* Insert to replace the deleted text with the pasted text. */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6980 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6981 } |
7 | 6982 else if (!checkclearopq(cap->oap)) |
6983 { | |
6984 switch (cap->cmdchar) | |
6985 { | |
6986 case 'A': /* "A"ppend after the line */ | |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
6987 set_cursor_for_append_to_line(); |
7 | 6988 break; |
6989 | |
6990 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 6991 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
6992 beginline(BL_WHITE); | |
6993 else | |
6994 beginline(BL_WHITE|BL_FIX); | |
7 | 6995 break; |
6996 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6997 case K_PS: |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6998 /* Bracketed paste works like "a"ppend, unless the cursor is in |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
6999 * the first column, then it inserts. */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
7000 if (curwin->w_cursor.col == 0) |
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
7001 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
7002 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
7003 |
7 | 7004 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
7005 /* increment coladd when in virtual space, increment the | |
7006 * column otherwise, also to append after an unprintable char */ | |
7007 if (virtual_active() | |
7008 && (curwin->w_cursor.coladd > 0 | |
7009 || *ml_get_cursor() == NUL | |
7010 || *ml_get_cursor() == TAB)) | |
7011 curwin->w_cursor.coladd++; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7012 else if (*ml_get_cursor() != NUL) |
7 | 7013 inc_cursor(); |
7014 break; | |
7015 } | |
7016 | |
7017 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
7018 { | |
7019 int save_State = State; | |
7020 | |
4352 | 7021 /* Pretend Insert mode here to allow the cursor on the |
7 | 7022 * character past the end of the line */ |
7023 State = INSERT; | |
7024 coladvance(getviscol()); | |
7025 State = save_State; | |
7026 } | |
7027 | |
7028 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
7029 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7030 else if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7031 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7032 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 7033 } |
7034 | |
7035 /* | |
7036 * Invoke edit() and take care of "restart_edit" and the return value. | |
7037 */ | |
7038 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7039 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7040 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7041 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7042 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7043 int startln) |
7 | 7044 { |
7045 int restart_edit_save = 0; | |
7046 | |
7047 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
7048 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
7049 * it. */ | |
7050 if (repl || !stuff_empty()) | |
7051 restart_edit_save = restart_edit; | |
7052 else | |
7053 restart_edit_save = 0; | |
7054 | |
7055 /* Always reset "restart_edit", this is not a restarted edit. */ | |
7056 restart_edit = 0; | |
7057 | |
7058 if (edit(cmd, startln, cap->count1)) | |
7059 cap->retval |= CA_COMMAND_BUSY; | |
7060 | |
7061 if (restart_edit == 0) | |
7062 restart_edit = restart_edit_save; | |
7063 } | |
7064 | |
7065 #ifdef FEAT_TEXTOBJ | |
7066 /* | |
7067 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
7068 */ | |
7069 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7070 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7071 cmdarg_T *cap) |
7 | 7072 { |
7073 int flag; | |
7074 int include; | |
7075 char_u *mps_save; | |
7076 | |
7077 if (cap->cmdchar == 'i') | |
7078 include = FALSE; /* "ix" = inner object: exclude white space */ | |
7079 else | |
7080 include = TRUE; /* "ax" = an object: include white space */ | |
7081 | |
7082 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
7083 mps_save = curbuf->b_p_mps; | |
7084 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
7085 | |
7086 switch (cap->nchar) | |
7087 { | |
7088 case 'w': /* "aw" = a word */ | |
7089 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
7090 break; | |
7091 case 'W': /* "aW" = a WORD */ | |
7092 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
7093 break; | |
7094 case 'b': /* "ab" = a braces block */ | |
7095 case '(': | |
7096 case ')': | |
7097 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
7098 break; | |
7099 case 'B': /* "aB" = a Brackets block */ | |
7100 case '{': | |
7101 case '}': | |
7102 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
7103 break; | |
7104 case '[': /* "a[" = a [] block */ | |
7105 case ']': | |
7106 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
7107 break; | |
7108 case '<': /* "a<" = a <> block */ | |
7109 case '>': | |
7110 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
7111 break; | |
420 | 7112 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 7113 /* Do not adjust oap->end in do_pending_operator() |
7114 * otherwise there are different results for 'dit' | |
7115 * (note leading whitespace in last line): | |
7116 * 1) <b> 2) <b> | |
7117 * foobar foobar | |
7118 * </b> </b> | |
7119 */ | |
7120 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 7121 flag = current_tagblock(cap->oap, cap->count1, include); |
7122 break; | |
7 | 7123 case 'p': /* "ap" = a paragraph */ |
7124 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
7125 break; | |
7126 case 's': /* "as" = a sentence */ | |
7127 flag = current_sent(cap->oap, cap->count1, include); | |
7128 break; | |
12 | 7129 case '"': /* "a"" = a double quoted string */ |
7130 case '\'': /* "a'" = a single quoted string */ | |
7131 case '`': /* "a`" = a backtick quoted string */ | |
7132 flag = current_quote(cap->oap, cap->count1, include, | |
7133 cap->nchar); | |
7134 break; | |
7 | 7135 #if 0 /* TODO */ |
7136 case 'S': /* "aS" = a section */ | |
7137 case 'f': /* "af" = a filename */ | |
7138 case 'u': /* "au" = a URL */ | |
7139 #endif | |
7140 default: | |
7141 flag = FAIL; | |
7142 break; | |
7143 } | |
7144 | |
7145 curbuf->b_p_mps = mps_save; | |
7146 if (flag == FAIL) | |
7147 clearopbeep(cap->oap); | |
7148 adjust_cursor_col(); | |
7149 curwin->w_set_curswant = TRUE; | |
7150 } | |
7151 #endif | |
7152 | |
7153 /* | |
7154 * "q" command: Start/stop recording. | |
7155 * "q:", "q/", "q?": edit command-line in command-line window. | |
7156 */ | |
7157 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7158 nv_record(cmdarg_T *cap) |
7 | 7159 { |
7160 if (cap->oap->op_type == OP_FORMAT) | |
7161 { | |
7162 /* "gqq" is the same as "gqgq": format line */ | |
7163 cap->cmdchar = 'g'; | |
7164 cap->nchar = 'q'; | |
7165 nv_operator(cap); | |
7166 } | |
7167 else if (!checkclearop(cap->oap)) | |
7168 { | |
7169 #ifdef FEAT_CMDWIN | |
7170 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
7171 { | |
7172 stuffcharReadbuff(cap->nchar); | |
7173 stuffcharReadbuff(K_CMDWIN); | |
7174 } | |
7175 else | |
7176 #endif | |
7177 /* (stop) recording into a named register, unless executing a | |
7178 * register */ | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
7179 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 7180 clearopbeep(cap->oap); |
7181 } | |
7182 } | |
7183 | |
7184 /* | |
7185 * Handle the "@r" command. | |
7186 */ | |
7187 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7188 nv_at(cmdarg_T *cap) |
7 | 7189 { |
7190 if (checkclearop(cap->oap)) | |
7191 return; | |
7192 #ifdef FEAT_EVAL | |
7193 if (cap->nchar == '=') | |
7194 { | |
7195 if (get_expr_register() == NUL) | |
7196 return; | |
7197 } | |
7198 #endif | |
7199 while (cap->count1-- && !got_int) | |
7200 { | |
1034 | 7201 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 7202 { |
7203 clearopbeep(cap->oap); | |
7204 break; | |
7205 } | |
7206 line_breakcheck(); | |
7207 } | |
7208 } | |
7209 | |
7210 /* | |
7211 * Handle the CTRL-U and CTRL-D commands. | |
7212 */ | |
7213 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7214 nv_halfpage(cmdarg_T *cap) |
7 | 7215 { |
7216 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
7217 || (cap->cmdchar == Ctrl_D | |
7218 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
7219 clearopbeep(cap->oap); | |
7220 else if (!checkclearop(cap->oap)) | |
7221 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
7222 } | |
7223 | |
7224 /* | |
7225 * Handle "J" or "gJ" command. | |
7226 */ | |
7227 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7228 nv_join(cmdarg_T *cap) |
7 | 7229 { |
7230 if (VIsual_active) /* join the visual lines */ | |
7231 nv_operator(cap); | |
5735 | 7232 else if (!checkclearop(cap->oap)) |
7 | 7233 { |
7234 if (cap->count0 <= 1) | |
7235 cap->count0 = 2; /* default for join is two lines! */ | |
7236 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
7237 curbuf->b_ml.ml_line_count) | |
8445
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7238 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7239 /* can't join when on the last line */ |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7240 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7241 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7242 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7243 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7244 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7245 cap->count0 = curbuf->b_ml.ml_line_count |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7246 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7247 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7248 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7249 prep_redo(cap->oap->regname, cap->count0, |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7250 NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7251 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 7252 } |
7253 } | |
7254 | |
7255 /* | |
7256 * "P", "gP", "p" and "gp" commands. | |
7257 */ | |
7258 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7259 nv_put(cmdarg_T *cap) |
7 | 7260 { |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7261 nv_put_opt(cap, FALSE); |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7262 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7263 |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7264 /* |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7265 * "P", "gP", "p" and "gp" commands. |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7266 * "fix_indent" is TRUE for "[p", "[P", "]p" and "]P". |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7267 */ |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7268 static void |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7269 nv_put_opt(cmdarg_T *cap, int fix_indent) |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7270 { |
7 | 7271 int regname = 0; |
7272 void *reg1 = NULL, *reg2 = NULL; | |
84 | 7273 int empty = FALSE; |
236 | 7274 int was_visual = FALSE; |
7 | 7275 int dir; |
7276 int flags = 0; | |
7277 | |
7278 if (cap->oap->op_type != OP_NOP) | |
7279 { | |
7280 #ifdef FEAT_DIFF | |
7281 /* "dp" is ":diffput" */ | |
7282 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
7283 { | |
7284 clearop(cap->oap); | |
6314 | 7285 nv_diffgetput(TRUE, cap->opcount); |
7 | 7286 } |
7287 else | |
7288 #endif | |
7289 clearopbeep(cap->oap); | |
7290 } | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7291 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7292 else if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7293 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7294 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7295 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7296 #endif |
7 | 7297 else |
7298 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7299 if (fix_indent) |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7300 { |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7301 dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7302 ? FORWARD : BACKWARD; |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7303 flags |= PUT_FIXINDENT; |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7304 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7305 else |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7306 dir = (cap->cmdchar == 'P' |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7307 || (cap->cmdchar == 'g' && cap->nchar == 'P')) |
7 | 7308 ? BACKWARD : FORWARD; |
7309 prep_redo_cmd(cap); | |
7310 if (cap->cmdchar == 'g') | |
7311 flags |= PUT_CURSEND; | |
7312 | |
7313 if (VIsual_active) | |
7314 { | |
7315 /* Putting in Visual mode: The put text replaces the selected | |
7316 * text. First delete the selected text, then put the new text. | |
7317 * Need to save and restore the registers that the delete | |
7318 * overwrites if the old contents is being put. | |
7319 */ | |
236 | 7320 was_visual = TRUE; |
7 | 7321 regname = cap->oap->regname; |
5735 | 7322 #ifdef FEAT_CLIPBOARD |
7 | 7323 adjust_clip_reg(®name); |
5735 | 7324 #endif |
5682 | 7325 if (regname == 0 || regname == '"' |
4013 | 7326 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 7327 #ifdef FEAT_CLIPBOARD |
7 | 7328 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 7329 #endif |
7 | 7330 |
7331 ) | |
7332 { | |
4013 | 7333 /* The delete is going to overwrite the register we want to |
7 | 7334 * put, save it first. */ |
7335 reg1 = get_register(regname, TRUE); | |
7336 } | |
7337 | |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
7338 // Now delete the selected text. Avoid messages here. |
7 | 7339 cap->cmdchar = 'd'; |
7340 cap->nchar = NUL; | |
7341 cap->oap->regname = NUL; | |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
7342 ++msg_silent; |
7 | 7343 nv_operator(cap); |
7344 do_pending_operator(cap, 0, FALSE); | |
84 | 7345 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
7346 --msg_silent; |
7 | 7347 |
7348 /* delete PUT_LINE_BACKWARD; */ | |
7349 cap->oap->regname = regname; | |
7350 | |
7351 if (reg1 != NULL) | |
7352 { | |
7353 /* Delete probably changed the register we want to put, save | |
7354 * it first. Then put back what was there before the delete. */ | |
7355 reg2 = get_register(regname, FALSE); | |
7356 put_register(regname, reg1); | |
7357 } | |
7358 | |
7359 /* When deleted a linewise Visual area, put the register as | |
7360 * lines to avoid it joined with the next line. When deletion was | |
7361 * characterwise, split a line when putting lines. */ | |
7362 if (VIsual_mode == 'V') | |
7363 flags |= PUT_LINE; | |
7364 else if (VIsual_mode == 'v') | |
7365 flags |= PUT_LINE_SPLIT; | |
7366 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
7367 flags |= PUT_LINE_FORWARD; | |
7368 dir = BACKWARD; | |
7369 if ((VIsual_mode != 'V' | |
7370 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
7371 || (VIsual_mode == 'V' | |
7372 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
7373 /* cursor is at the end of the line or end of file, put | |
7374 * forward. */ | |
7375 dir = FORWARD; | |
5365 | 7376 /* May have been reset in do_put(). */ |
7377 VIsual_active = TRUE; | |
7 | 7378 } |
7379 do_put(cap->oap->regname, dir, cap->count1, flags); | |
7380 | |
7381 /* If a register was saved, put it back now. */ | |
7382 if (reg2 != NULL) | |
7383 put_register(regname, reg2); | |
236 | 7384 |
7385 /* What to reselect with "gv"? Selecting the just put text seems to | |
7386 * be the most useful, since the original text was removed. */ | |
7387 if (was_visual) | |
7388 { | |
690 | 7389 curbuf->b_visual.vi_start = curbuf->b_op_start; |
7390 curbuf->b_visual.vi_end = curbuf->b_op_end; | |
7241
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
7391 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
7392 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
7393 inc(&curbuf->b_visual.vi_end); |
236 | 7394 } |
7395 | |
84 | 7396 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 7397 * line that needs to be deleted now. */ |
84 | 7398 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 7399 { |
84 | 7400 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
7401 deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); |
817 | 7402 |
7403 /* If the cursor was in that line, move it to the end of the last | |
7404 * line. */ | |
7405 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7406 { | |
7407 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7408 coladvance((colnr_T)MAXCOL); | |
7409 } | |
7410 } | |
7 | 7411 auto_format(FALSE, TRUE); |
7412 } | |
7413 } | |
7414 | |
7415 /* | |
7416 * "o" and "O" commands. | |
7417 */ | |
7418 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7419 nv_open(cmdarg_T *cap) |
7 | 7420 { |
7421 #ifdef FEAT_DIFF | |
7422 /* "do" is ":diffget" */ | |
7423 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
7424 { | |
7425 clearop(cap->oap); | |
6314 | 7426 nv_diffgetput(FALSE, cap->opcount); |
7 | 7427 } |
7428 else | |
7429 #endif | |
7430 if (VIsual_active) /* switch start and end of visual */ | |
7431 v_swap_corners(cap->cmdchar); | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7432 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7433 else if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7434 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7435 #endif |
7 | 7436 else |
7437 n_opencmd(cap); | |
7438 } | |
7439 | |
7440 #ifdef FEAT_NETBEANS_INTG | |
7441 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7442 nv_nbcmd(cmdarg_T *cap) |
7 | 7443 { |
7444 netbeans_keycommand(cap->nchar); | |
7445 } | |
7446 #endif | |
7447 | |
7448 #ifdef FEAT_DND | |
7449 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7450 nv_drop(cmdarg_T *cap UNUSED) |
7 | 7451 { |
7452 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
7453 } | |
7454 #endif | |
203 | 7455 |
7456 /* | |
7457 * Trigger CursorHold event. | |
7458 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
7459 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
7460 */ | |
7461 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7462 nv_cursorhold(cmdarg_T *cap) |
203 | 7463 { |
7464 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
7465 did_cursorhold = TRUE; | |
226 | 7466 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7467 } |