Mercurial > vim
annotate src/normal.c @ 18203:e0ec4cd7a865 v8.1.2096
patch 8.1.2096: too many #ifdefs
Commit: https://github.com/vim/vim/commit/8c96af9c05bfcac2d5ae081e098d4863db561511
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 28 19:05:57 2019 +0200
patch 8.1.2096: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_COMMENTS.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Sep 2019 19:15:03 +0200 |
parents | 5e10ee16f4b4 |
children | 5d67f207f7c3 |
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 | |
17 /* | |
18 * The Visual area is remembered for reselection. | |
19 */ | |
20 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
21 static linenr_T resel_VIsual_line_count; /* number of lines */ | |
3125 | 22 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
5682 | 23 static int VIsual_mode_orig = NUL; /* saved Visual mode */ |
7 | 24 |
25 static int restart_VIsual_select = 0; | |
26 | |
2667 | 27 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
28 static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
2667 | 29 #endif |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16598
diff
changeset
|
30 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
|
31 static void op_colon(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
32 static void op_function(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
33 static void unshift_special(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
34 static void may_clear_cmdline(void); |
7 | 35 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
36 static void del_from_showcmd(int); |
7 | 37 #endif |
38 | |
39 /* | |
40 * nv_*(): functions called to handle Normal and Visual mode commands. | |
41 * n_*(): functions called to handle Normal mode commands. | |
42 * v_*(): functions called to handle Visual mode commands. | |
43 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 static void nv_zet(cmdarg_T *cap); |
7 | 51 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
52 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
|
53 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 54 #endif |
685 | 55 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
56 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
|
57 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
|
58 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 static void nv_operator(cmdarg_T *cap); |
1490 | 107 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
108 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
|
109 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 static int unadjust_for_sel(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 125 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
126 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
|
127 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 static void nv_open(cmdarg_T *cap); |
7 | 135 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
136 static void nv_nbcmd(cmdarg_T *cap); |
7 | 137 #endif |
138 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
139 static void nv_drop(cmdarg_T *cap); |
7 | 140 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
141 static void nv_cursorhold(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
142 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 143 |
1728 | 144 static char *e_noident = N_("E349: No identifier under cursor"); |
145 | |
7 | 146 /* |
147 * Function to be called for a Normal or Visual mode command. | |
148 * The argument is a cmdarg_T. | |
149 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
150 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 151 |
152 /* Values for cmd_flags. */ | |
153 #define NV_NCH 0x01 /* may need to get a second char */ | |
154 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
155 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
156 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
157 | |
158 #define NV_SS 0x10 /* may start selection */ | |
159 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
160 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
161 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
162 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
163 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
164 | |
165 /* | |
166 * Generally speaking, every Normal mode command should either clear any | |
167 * pending operator (with *clearop*()), or set the motion type variable | |
168 * oap->motion_type. | |
169 * | |
170 * When a cursor motion command is made, it is marked as being a character or | |
171 * line oriented motion. Then, if an operator is in effect, the operation | |
172 * becomes character or line oriented accordingly. | |
173 */ | |
174 | |
175 /* | |
176 * This table contains one entry for every Normal or Visual mode command. | |
177 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
178 * It is faster when all keys from zero to '~' are present. | |
179 */ | |
180 static const struct nv_cmd | |
181 { | |
182 int cmd_char; /* (first) command character */ | |
183 nv_func_T cmd_func; /* function for this command */ | |
184 short_u cmd_flags; /* NV_ flags */ | |
185 short cmd_arg; /* value for ca.arg */ | |
186 } nv_cmds[] = | |
187 { | |
188 {NUL, nv_error, 0, 0}, | |
189 {Ctrl_A, nv_addsub, 0, 0}, | |
190 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
191 {Ctrl_C, nv_esc, 0, TRUE}, | |
192 {Ctrl_D, nv_halfpage, 0, 0}, | |
193 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
194 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
195 {Ctrl_G, nv_ctrlg, 0, 0}, | |
196 {Ctrl_H, nv_ctrlh, 0, 0}, | |
197 {Ctrl_I, nv_pcmark, 0, 0}, | |
198 {NL, nv_down, 0, FALSE}, | |
199 {Ctrl_K, nv_error, 0, 0}, | |
200 {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
|
201 {CAR, nv_down, 0, TRUE}, |
7 | 202 {Ctrl_N, nv_down, NV_STS, FALSE}, |
203 {Ctrl_O, nv_ctrlo, 0, 0}, | |
204 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 205 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 206 {Ctrl_R, nv_redo, 0, 0}, |
207 {Ctrl_S, nv_ignore, 0, 0}, | |
208 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
209 {Ctrl_U, nv_halfpage, 0, 0}, | |
210 {Ctrl_V, nv_visual, 0, FALSE}, | |
211 {'V', nv_visual, 0, FALSE}, | |
212 {'v', nv_visual, 0, FALSE}, | |
213 {Ctrl_W, nv_window, 0, 0}, | |
214 {Ctrl_X, nv_addsub, 0, 0}, | |
215 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
216 {Ctrl_Z, nv_suspend, 0, 0}, | |
217 {ESC, nv_esc, 0, FALSE}, | |
218 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
219 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
220 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
221 {Ctrl__, nv_error, 0, 0}, | |
222 {' ', nv_right, 0, 0}, | |
223 {'!', nv_operator, 0, 0}, | |
224 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
225 {'#', nv_ident, 0, 0}, | |
226 {'$', nv_dollar, 0, 0}, | |
227 {'%', nv_percent, 0, 0}, | |
228 {'&', nv_optrans, 0, 0}, | |
229 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
230 {'(', nv_brace, 0, BACKWARD}, | |
231 {')', nv_brace, 0, FORWARD}, | |
232 {'*', nv_ident, 0, 0}, | |
233 {'+', nv_down, 0, TRUE}, | |
234 {',', nv_csearch, 0, TRUE}, | |
235 {'-', nv_up, 0, TRUE}, | |
236 {'.', nv_dot, NV_KEEPREG, 0}, | |
237 {'/', nv_search, 0, FALSE}, | |
238 {'0', nv_beginline, 0, 0}, | |
239 {'1', nv_ignore, 0, 0}, | |
240 {'2', nv_ignore, 0, 0}, | |
241 {'3', nv_ignore, 0, 0}, | |
242 {'4', nv_ignore, 0, 0}, | |
243 {'5', nv_ignore, 0, 0}, | |
244 {'6', nv_ignore, 0, 0}, | |
245 {'7', nv_ignore, 0, 0}, | |
246 {'8', nv_ignore, 0, 0}, | |
247 {'9', nv_ignore, 0, 0}, | |
248 {':', nv_colon, 0, 0}, | |
249 {';', nv_csearch, 0, FALSE}, | |
250 {'<', nv_operator, NV_RL, 0}, | |
251 {'=', nv_operator, 0, 0}, | |
252 {'>', nv_operator, NV_RL, 0}, | |
253 {'?', nv_search, 0, FALSE}, | |
254 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
255 {'A', nv_edit, 0, 0}, | |
256 {'B', nv_bck_word, 0, 1}, | |
257 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
258 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
259 {'E', nv_wordcmd, 0, TRUE}, | |
260 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
261 {'G', nv_goto, 0, TRUE}, | |
262 {'H', nv_scroll, 0, 0}, | |
263 {'I', nv_edit, 0, 0}, | |
264 {'J', nv_join, 0, 0}, | |
265 {'K', nv_ident, 0, 0}, | |
266 {'L', nv_scroll, 0, 0}, | |
267 {'M', nv_scroll, 0, 0}, | |
268 {'N', nv_next, 0, SEARCH_REV}, | |
269 {'O', nv_open, 0, 0}, | |
270 {'P', nv_put, 0, 0}, | |
271 {'Q', nv_exmode, NV_NCW, 0}, | |
272 {'R', nv_Replace, 0, FALSE}, | |
273 {'S', nv_subst, NV_KEEPREG, 0}, | |
274 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
275 {'U', nv_Undo, 0, 0}, | |
276 {'W', nv_wordcmd, 0, TRUE}, | |
277 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
278 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
279 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
280 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
281 {'\\', nv_error, 0, 0}, | |
282 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
283 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
284 {'_', nv_lineop, 0, 0}, | |
285 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
286 {'a', nv_edit, NV_NCH, 0}, | |
287 {'b', nv_bck_word, 0, 0}, | |
288 {'c', nv_operator, 0, 0}, | |
289 {'d', nv_operator, 0, 0}, | |
290 {'e', nv_wordcmd, 0, FALSE}, | |
291 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
292 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
293 {'h', nv_left, NV_RL, 0}, | |
294 {'i', nv_edit, NV_NCH, 0}, | |
295 {'j', nv_down, 0, FALSE}, | |
296 {'k', nv_up, 0, FALSE}, | |
297 {'l', nv_right, NV_RL, 0}, | |
298 {'m', nv_mark, NV_NCH_NOP, 0}, | |
299 {'n', nv_next, 0, 0}, | |
300 {'o', nv_open, 0, 0}, | |
301 {'p', nv_put, 0, 0}, | |
302 {'q', nv_record, NV_NCH, 0}, | |
303 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
304 {'s', nv_subst, NV_KEEPREG, 0}, | |
305 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
306 {'u', nv_undo, 0, 0}, | |
307 {'w', nv_wordcmd, 0, FALSE}, | |
308 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
309 {'y', nv_operator, 0, 0}, | |
310 {'z', nv_zet, NV_NCH_ALW, 0}, | |
311 {'{', nv_findpar, 0, BACKWARD}, | |
312 {'|', nv_pipe, 0, 0}, | |
313 {'}', nv_findpar, 0, FORWARD}, | |
314 {'~', nv_tilde, 0, 0}, | |
315 | |
316 /* pound sign */ | |
317 {POUND, nv_ident, 0, 0}, | |
318 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
319 {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
|
320 {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
|
321 {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
|
322 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 323 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
324 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
325 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
326 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
327 {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
|
328 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 329 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
330 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
331 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
332 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
333 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
334 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
335 {K_X1MOUSE, nv_mouse, 0, 0}, | |
336 {K_X1DRAG, nv_mouse, 0, 0}, | |
337 {K_X1RELEASE, nv_mouse, 0, 0}, | |
338 {K_X2MOUSE, nv_mouse, 0, 0}, | |
339 {K_X2DRAG, nv_mouse, 0, 0}, | |
340 {K_X2RELEASE, nv_mouse, 0, 0}, | |
341 #endif | |
819 | 342 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 343 {K_NOP, nv_nop, 0, 0}, |
7 | 344 {K_INS, nv_edit, 0, 0}, |
345 {K_KINS, nv_edit, 0, 0}, | |
346 {K_BS, nv_ctrlh, 0, 0}, | |
347 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
348 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
349 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
350 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
351 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
352 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
353 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
354 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
355 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
356 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
357 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
358 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
359 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
360 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
361 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
362 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
363 {K_S_END, nv_end, NV_SS, FALSE}, | |
364 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
365 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
366 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
367 {K_S_HOME, nv_home, NV_SS, 0}, | |
368 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
369 {K_DEL, nv_abbrev, 0, 0}, | |
370 {K_KDEL, nv_abbrev, 0, 0}, | |
371 {K_UNDO, nv_kundo, 0, 0}, | |
372 {K_HELP, nv_help, NV_NCW, 0}, | |
373 {K_F1, nv_help, NV_NCW, 0}, | |
374 {K_XF1, nv_help, NV_NCW, 0}, | |
375 {K_SELECT, nv_select, 0, 0}, | |
376 #ifdef FEAT_GUI | |
377 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
378 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
379 #endif | |
685 | 380 #ifdef FEAT_GUI_TABLINE |
381 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 382 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 383 #endif |
7 | 384 #ifdef FEAT_NETBEANS_INTG |
385 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
386 #endif | |
387 #ifdef FEAT_DND | |
388 {K_DROP, nv_drop, NV_STS, 0}, | |
389 #endif | |
819 | 390 {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
|
391 {K_PS, nv_edit, 0, 0}, |
7 | 392 }; |
393 | |
394 /* Number of commands in nv_cmds[]. */ | |
395 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
396 | |
397 /* Sorted index of commands in nv_cmds[]. */ | |
398 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
399 | |
400 /* The highest index for which | |
401 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
402 static int nv_max_linear; | |
403 | |
404 /* | |
405 * Compare functions for qsort() below, that checks the command character | |
406 * through the index in nv_cmd_idx[]. | |
407 */ | |
408 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
409 nv_compare(const void *s1, const void *s2) |
7 | 410 { |
411 int c1, c2; | |
412 | |
413 /* The commands are sorted on absolute value. */ | |
414 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
415 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
416 if (c1 < 0) | |
417 c1 = -c1; | |
418 if (c2 < 0) | |
419 c2 = -c2; | |
420 return c1 - c2; | |
421 } | |
422 | |
423 /* | |
424 * Initialize the nv_cmd_idx[] table. | |
425 */ | |
426 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
427 init_normal_cmds(void) |
7 | 428 { |
429 int i; | |
430 | |
431 /* Fill the index table with a one to one relation. */ | |
1877 | 432 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 433 nv_cmd_idx[i] = i; |
434 | |
435 /* Sort the commands by the command character. */ | |
436 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
437 | |
438 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 439 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 440 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
441 break; | |
442 nv_max_linear = i - 1; | |
443 } | |
444 | |
445 /* | |
446 * Search for a command in the commands table. | |
447 * Returns -1 for invalid command. | |
448 */ | |
449 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
450 find_command(int cmdchar) |
7 | 451 { |
452 int i; | |
453 int idx; | |
454 int top, bot; | |
455 int c; | |
456 | |
457 /* A multi-byte character is never a command. */ | |
458 if (cmdchar >= 0x100) | |
459 return -1; | |
460 | |
461 /* We use the absolute value of the character. Special keys have a | |
462 * negative value, but are sorted on their absolute value. */ | |
463 if (cmdchar < 0) | |
464 cmdchar = -cmdchar; | |
465 | |
466 /* If the character is in the first part: The character is the index into | |
467 * nv_cmd_idx[]. */ | |
468 if (cmdchar <= nv_max_linear) | |
469 return nv_cmd_idx[cmdchar]; | |
470 | |
471 /* Perform a binary search. */ | |
472 bot = nv_max_linear + 1; | |
473 top = NV_CMDS_SIZE - 1; | |
474 idx = -1; | |
475 while (bot <= top) | |
476 { | |
477 i = (top + bot) / 2; | |
478 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
479 if (c < 0) | |
480 c = -c; | |
481 if (cmdchar == c) | |
482 { | |
483 idx = nv_cmd_idx[i]; | |
484 break; | |
485 } | |
486 if (cmdchar > c) | |
487 bot = i + 1; | |
488 else | |
489 top = i - 1; | |
490 } | |
491 return idx; | |
492 } | |
493 | |
494 /* | |
495 * Execute a command in Normal mode. | |
496 */ | |
497 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
498 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
499 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
500 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 501 { |
502 cmdarg_T ca; /* command arguments */ | |
503 int c; | |
504 int ctrl_w = FALSE; /* got CTRL-W command */ | |
505 int old_col = curwin->w_curswant; | |
506 #ifdef FEAT_CMDL_INFO | |
507 int need_flushbuf; /* need to call out_flush() */ | |
508 #endif | |
509 pos_T old_pos; /* cursor position before command */ | |
510 int mapped_len; | |
511 static int old_mapped_len = 0; | |
512 int idx; | |
1751 | 513 #ifdef FEAT_EVAL |
514 int set_prevcount = FALSE; | |
515 #endif | |
7 | 516 |
517 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
518 ca.oap = oap; | |
1692 | 519 |
520 /* Use a count remembered from before entering an operator. After typing | |
521 * "3d" we return from normal_cmd() and come back here, the "3" is | |
522 * remembered in "opcount". */ | |
7 | 523 ca.opcount = opcount; |
524 | |
525 /* | |
526 * If there is an operator pending, then the command we take this time | |
527 * will terminate it. Finish_op tells us to finish the operation before | |
528 * returning this time (unless the operation was cancelled). | |
529 */ | |
530 #ifdef CURSOR_SHAPE | |
531 c = finish_op; | |
532 #endif | |
533 finish_op = (oap->op_type != OP_NOP); | |
534 #ifdef CURSOR_SHAPE | |
535 if (finish_op != c) | |
536 { | |
537 ui_cursor_shape(); /* may show different cursor shape */ | |
538 # ifdef FEAT_MOUSESHAPE | |
539 update_mouseshape(-1); | |
540 # endif | |
541 } | |
542 #endif | |
543 | |
1692 | 544 /* When not finishing an operator and no register name typed, reset the |
545 * count. */ | |
7 | 546 if (!finish_op && !oap->regname) |
1751 | 547 { |
7 | 548 ca.opcount = 0; |
1751 | 549 #ifdef FEAT_EVAL |
550 set_prevcount = TRUE; | |
551 #endif | |
552 } | |
7 | 553 |
1692 | 554 /* Restore counts from before receiving K_CURSORHOLD. This means after |
555 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
556 * "3 * 2". */ | |
557 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
558 { | |
559 ca.opcount = oap->prev_opcount; | |
560 ca.count0 = oap->prev_count0; | |
561 oap->prev_opcount = 0; | |
562 oap->prev_count0 = 0; | |
563 } | |
564 | |
7 | 565 mapped_len = typebuf_maplen(); |
566 | |
567 State = NORMAL_BUSY; | |
568 #ifdef USE_ON_FLY_SCROLL | |
569 dont_scroll = FALSE; /* allow scrolling here */ | |
570 #endif | |
571 | |
2667 | 572 #ifdef FEAT_EVAL |
573 /* Set v:count here, when called from main() and not a stuffed | |
574 * command, so that v:count can be used in an expression mapping | |
5649 | 575 * when there is no count. Do set it for redo. */ |
576 if (toplevel && readbuf1_empty()) | |
2667 | 577 set_vcount_ca(&ca, &set_prevcount); |
578 #endif | |
579 | |
7 | 580 /* |
581 * Get the command character from the user. | |
582 */ | |
583 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
584 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 585 |
586 /* | |
587 * If a mapping was started in Visual or Select mode, remember the length | |
588 * of the mapping. This is used below to not return to Insert mode for as | |
589 * long as the mapping is being executed. | |
590 */ | |
591 if (restart_edit == 0) | |
592 old_mapped_len = 0; | |
593 else if (old_mapped_len | |
819 | 594 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 595 old_mapped_len = typebuf_maplen(); |
596 | |
597 if (c == NUL) | |
598 c = K_ZERO; | |
599 | |
600 /* | |
601 * In Select mode, typed text replaces the selection. | |
602 */ | |
603 if (VIsual_active | |
604 && VIsual_select | |
605 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
606 { | |
275 | 607 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
608 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
609 * restart automatically. | |
1051 | 610 * Insert the typed character in the typeahead buffer, so that it can |
611 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 612 ins_char_typebuf(c); |
275 | 613 if (restart_edit != 0) |
614 c = 'd'; | |
615 else | |
616 c = 'c'; | |
695 | 617 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 618 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 619 } |
620 | |
621 #ifdef FEAT_CMDL_INFO | |
622 need_flushbuf = add_to_showcmd(c); | |
623 #endif | |
624 | |
625 getcount: | |
626 if (!(VIsual_active && VIsual_select)) | |
627 { | |
628 /* | |
629 * Handle a count before a command and compute ca.count0. | |
630 * Note that '0' is a command and not the start of a count, but it's | |
631 * part of a count after other digits. | |
632 */ | |
633 while ( (c >= '1' && c <= '9') | |
634 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
635 { | |
636 if (c == K_DEL || c == K_KDEL) | |
637 { | |
638 ca.count0 /= 10; | |
639 #ifdef FEAT_CMDL_INFO | |
640 del_from_showcmd(4); /* delete the digit and ~@% */ | |
641 #endif | |
642 } | |
643 else | |
644 ca.count0 = ca.count0 * 10 + (c - '0'); | |
645 if (ca.count0 < 0) /* got too large! */ | |
646 ca.count0 = 999999999L; | |
1425 | 647 #ifdef FEAT_EVAL |
648 /* Set v:count here, when called from main() and not a stuffed | |
649 * command, so that v:count can be used in an expression mapping | |
5649 | 650 * right after the count. Do set it for redo. */ |
651 if (toplevel && readbuf1_empty()) | |
2667 | 652 set_vcount_ca(&ca, &set_prevcount); |
1425 | 653 #endif |
7 | 654 if (ctrl_w) |
655 { | |
656 ++no_mapping; | |
657 ++allow_keys; /* no mapping for nchar, but keys */ | |
658 } | |
659 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 660 c = plain_vgetc(); |
7 | 661 LANGMAP_ADJUST(c, TRUE); |
662 --no_zero_mapping; | |
663 if (ctrl_w) | |
664 { | |
665 --no_mapping; | |
666 --allow_keys; | |
667 } | |
668 #ifdef FEAT_CMDL_INFO | |
669 need_flushbuf |= add_to_showcmd(c); | |
670 #endif | |
671 } | |
672 | |
673 /* | |
674 * If we got CTRL-W there may be a/another count | |
675 */ | |
676 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
677 { | |
678 ctrl_w = TRUE; | |
679 ca.opcount = ca.count0; /* remember first count */ | |
680 ca.count0 = 0; | |
681 ++no_mapping; | |
682 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 683 c = plain_vgetc(); /* get next character */ |
7 | 684 LANGMAP_ADJUST(c, TRUE); |
685 --no_mapping; | |
686 --allow_keys; | |
687 #ifdef FEAT_CMDL_INFO | |
688 need_flushbuf |= add_to_showcmd(c); | |
689 #endif | |
690 goto getcount; /* jump back */ | |
691 } | |
692 } | |
693 | |
1692 | 694 if (c == K_CURSORHOLD) |
695 { | |
696 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
697 * the same when coming back here after handling K_CURSORHOLD. */ | |
698 oap->prev_opcount = ca.opcount; | |
699 oap->prev_count0 = ca.count0; | |
700 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
701 else if (ca.opcount != 0) |
1692 | 702 { |
703 /* | |
704 * If we're in the middle of an operator (including after entering a | |
705 * yank buffer with '"') AND we had a count before the operator, then | |
706 * that count overrides the current value of ca.count0. | |
707 * What this means effectively, is that commands like "3dw" get turned | |
708 * into "d3w" which makes things fall into place pretty neatly. | |
709 * If you give a count before AND after the operator, they are | |
710 * multiplied. | |
711 */ | |
7 | 712 if (ca.count0) |
713 ca.count0 *= ca.opcount; | |
714 else | |
715 ca.count0 = ca.opcount; | |
716 } | |
717 | |
718 /* | |
719 * Always remember the count. It will be set to zero (on the next call, | |
720 * above) when there is no pending operator. | |
721 * When called from main(), save the count for use by the "count" built-in | |
722 * variable. | |
723 */ | |
724 ca.opcount = ca.count0; | |
725 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
726 | |
727 #ifdef FEAT_EVAL | |
728 /* | |
729 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 730 * Do set it for redo. |
7 | 731 */ |
5649 | 732 if (toplevel && readbuf1_empty()) |
1751 | 733 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 734 #endif |
735 | |
736 /* | |
737 * Find the command character in the table of commands. | |
738 * For CTRL-W we already got nchar when looking for a count. | |
739 */ | |
740 if (ctrl_w) | |
741 { | |
742 ca.nchar = c; | |
743 ca.cmdchar = Ctrl_W; | |
744 } | |
745 else | |
746 ca.cmdchar = c; | |
747 idx = find_command(ca.cmdchar); | |
748 if (idx < 0) | |
749 { | |
750 /* Not a known command: beep. */ | |
751 clearopbeep(oap); | |
752 goto normal_end; | |
753 } | |
631 | 754 |
633 | 755 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 756 { |
5848 | 757 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 758 clearopbeep(oap); |
633 | 759 text_locked_msg(); |
7 | 760 goto normal_end; |
761 } | |
819 | 762 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
763 goto normal_end; | |
7 | 764 |
765 /* | |
766 * In Visual/Select mode, a few keys are handled in a special way. | |
767 */ | |
768 if (VIsual_active) | |
769 { | |
770 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
771 if (km_stopsel | |
772 && (nv_cmds[idx].cmd_flags & NV_STS) | |
773 && !(mod_mask & MOD_MASK_SHIFT)) | |
774 { | |
775 end_visual_mode(); | |
776 redraw_curbuf_later(INVERTED); | |
777 } | |
778 | |
779 /* Keys that work different when 'keymodel' contains "startsel" */ | |
780 if (km_startsel) | |
781 { | |
782 if (nv_cmds[idx].cmd_flags & NV_SS) | |
783 { | |
784 unshift_special(&ca); | |
785 idx = find_command(ca.cmdchar); | |
840 | 786 if (idx < 0) |
787 { | |
788 /* Just in case */ | |
789 clearopbeep(oap); | |
790 goto normal_end; | |
791 } | |
7 | 792 } |
793 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
794 && (mod_mask & MOD_MASK_SHIFT)) | |
795 mod_mask &= ~MOD_MASK_SHIFT; | |
796 } | |
797 } | |
798 | |
799 #ifdef FEAT_RIGHTLEFT | |
800 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
801 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
802 { | |
803 /* Invert horizontal movements and operations. Only when typed by the | |
804 * user directly, not when the result of a mapping or "x" translated | |
805 * to "dl". */ | |
806 switch (ca.cmdchar) | |
807 { | |
808 case 'l': ca.cmdchar = 'h'; break; | |
809 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
810 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
811 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
812 case 'h': ca.cmdchar = 'l'; break; | |
813 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
814 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
815 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
816 case '>': ca.cmdchar = '<'; break; | |
817 case '<': ca.cmdchar = '>'; break; | |
818 } | |
819 idx = find_command(ca.cmdchar); | |
820 } | |
821 #endif | |
822 | |
823 /* | |
824 * Get an additional character if we need one. | |
825 */ | |
826 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
827 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
828 && oap->op_type == OP_NOP) | |
829 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
830 || (ca.cmdchar == 'q' | |
831 && 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
|
832 && 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
|
833 && reg_executing == 0) |
7 | 834 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 835 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 836 { |
837 int *cp; | |
838 int repl = FALSE; /* get character for replace mode */ | |
839 int lit = FALSE; /* get extra character literally */ | |
840 int langmap_active = FALSE; /* using :lmap mappings */ | |
841 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
842 #ifdef HAVE_INPUT_METHOD |
7 | 843 int save_smd; /* saved value of p_smd */ |
844 #endif | |
845 | |
846 ++no_mapping; | |
847 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 848 /* Don't generate a CursorHold event here, most commands can't handle |
849 * it, e.g., nv_replace(), nv_csearch(). */ | |
850 did_cursorhold = TRUE; | |
7 | 851 if (ca.cmdchar == 'g') |
852 { | |
853 /* | |
854 * For 'g' get the next character now, so that we can check for | |
855 * "gr", "g'" and "g`". | |
856 */ | |
1389 | 857 ca.nchar = plain_vgetc(); |
7 | 858 LANGMAP_ADJUST(ca.nchar, TRUE); |
859 #ifdef FEAT_CMDL_INFO | |
860 need_flushbuf |= add_to_showcmd(ca.nchar); | |
861 #endif | |
862 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 863 || ca.nchar == Ctrl_BSL) |
7 | 864 { |
865 cp = &ca.extra_char; /* need to get a third character */ | |
866 if (ca.nchar != 'r') | |
867 lit = TRUE; /* get it literally */ | |
868 else | |
869 repl = TRUE; /* get it in replace mode */ | |
870 } | |
871 else | |
872 cp = NULL; /* no third character needed */ | |
873 } | |
874 else | |
875 { | |
876 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
877 repl = TRUE; | |
878 cp = &ca.nchar; | |
879 } | |
880 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
881 | |
882 /* | |
883 * Get a second or third character. | |
884 */ | |
885 if (cp != NULL) | |
886 { | |
887 #ifdef CURSOR_SHAPE | |
888 if (repl) | |
889 { | |
890 State = REPLACE; /* pretend Replace mode */ | |
891 ui_cursor_shape(); /* show different cursor shape */ | |
892 } | |
893 #endif | |
894 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
895 { | |
896 /* Allow mappings defined with ":lmap". */ | |
897 --no_mapping; | |
898 --allow_keys; | |
899 if (repl) | |
900 State = LREPLACE; | |
901 else | |
902 State = LANGMAP; | |
903 langmap_active = TRUE; | |
904 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
905 #ifdef HAVE_INPUT_METHOD |
7 | 906 save_smd = p_smd; |
907 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
908 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
909 im_set_active(TRUE); | |
910 #endif | |
911 | |
1389 | 912 *cp = plain_vgetc(); |
7 | 913 |
914 if (langmap_active) | |
915 { | |
916 /* Undo the decrement done above */ | |
917 ++no_mapping; | |
918 ++allow_keys; | |
919 State = NORMAL_BUSY; | |
920 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
921 #ifdef HAVE_INPUT_METHOD |
7 | 922 if (lang) |
923 { | |
924 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
925 im_save_status(&curbuf->b_p_iminsert); | |
926 im_set_active(FALSE); | |
927 } | |
928 p_smd = save_smd; | |
929 #endif | |
930 #ifdef CURSOR_SHAPE | |
931 State = NORMAL_BUSY; | |
932 #endif | |
933 #ifdef FEAT_CMDL_INFO | |
934 need_flushbuf |= add_to_showcmd(*cp); | |
935 #endif | |
936 | |
937 if (!lit) | |
938 { | |
939 #ifdef FEAT_DIGRAPHS | |
940 /* Typing CTRL-K gets a digraph. */ | |
941 if (*cp == Ctrl_K | |
942 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
943 || cp == &ca.extra_char) | |
944 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
945 { | |
946 c = get_digraph(FALSE); | |
947 if (c > 0) | |
948 { | |
949 *cp = c; | |
950 # ifdef FEAT_CMDL_INFO | |
951 /* Guessing how to update showcmd here... */ | |
952 del_from_showcmd(3); | |
953 need_flushbuf |= add_to_showcmd(*cp); | |
954 # endif | |
955 } | |
956 } | |
957 #endif | |
958 | |
959 /* adjust chars > 127, except after "tTfFr" commands */ | |
960 LANGMAP_ADJUST(*cp, !lang); | |
961 #ifdef FEAT_RIGHTLEFT | |
962 /* adjust Hebrew mapped char */ | |
963 if (p_hkmap && lang && KeyTyped) | |
964 *cp = hkmap(*cp); | |
965 #endif | |
966 } | |
967 | |
968 /* | |
969 * When the next character is CTRL-\ a following CTRL-N means the | |
970 * command is aborted and we go to Normal mode. | |
971 */ | |
972 if (cp == &ca.extra_char | |
973 && ca.nchar == Ctrl_BSL | |
974 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
975 { | |
976 ca.cmdchar = Ctrl_BSL; | |
977 ca.nchar = ca.extra_char; | |
978 idx = find_command(ca.cmdchar); | |
979 } | |
3908 | 980 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 981 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 982 else if (*cp == Ctrl_BSL) |
983 { | |
984 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
985 | |
986 /* There is a busy wait here when typing "f<C-\>" and then | |
987 * something different from CTRL-N. Can't be avoided. */ | |
988 while ((c = vpeekc()) <= 0 && towait > 0L) | |
989 { | |
990 do_sleep(towait > 50L ? 50L : towait); | |
991 towait -= 50L; | |
992 } | |
993 if (c > 0) | |
994 { | |
1389 | 995 c = plain_vgetc(); |
7 | 996 if (c != Ctrl_N && c != Ctrl_G) |
997 vungetc(c); | |
998 else | |
999 { | |
1000 ca.cmdchar = Ctrl_BSL; | |
1001 ca.nchar = c; | |
1002 idx = find_command(ca.cmdchar); | |
1003 } | |
1004 } | |
1005 } | |
1006 | |
1007 /* When getting a text character and the next character is a | |
1008 * multi-byte character, it could be a composing character. | |
6071 | 1009 * However, don't wait for it to arrive. Also, do enable mapping, |
1010 * because if it's put back with vungetc() it's too late to apply | |
1011 * mapping. */ | |
1012 --no_mapping; | |
7 | 1013 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1014 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1015 { | |
1389 | 1016 c = plain_vgetc(); |
7 | 1017 if (!utf_iscomposing(c)) |
1018 { | |
1019 vungetc(c); /* it wasn't, put it back */ | |
1020 break; | |
1021 } | |
1022 else if (ca.ncharC1 == 0) | |
1023 ca.ncharC1 = c; | |
1024 else | |
1025 ca.ncharC2 = c; | |
1026 } | |
6071 | 1027 ++no_mapping; |
7 | 1028 } |
1029 --no_mapping; | |
1030 --allow_keys; | |
1031 } | |
1032 | |
1033 #ifdef FEAT_CMDL_INFO | |
1034 /* | |
1035 * Flush the showcmd characters onto the screen so we can see them while | |
1036 * the command is being executed. Only do this when the shown command was | |
1037 * actually displayed, otherwise this will slow down a lot when executing | |
1038 * mappings. | |
1039 */ | |
1040 if (need_flushbuf) | |
1041 out_flush(); | |
1042 #endif | |
1727 | 1043 if (ca.cmdchar != K_IGNORE) |
1044 did_cursorhold = FALSE; | |
7 | 1045 |
1046 State = NORMAL; | |
1047 | |
1048 if (ca.nchar == ESC) | |
1049 { | |
1050 clearop(oap); | |
1051 if (restart_edit == 0 && goto_im()) | |
1052 restart_edit = 'a'; | |
1053 goto normal_end; | |
1054 } | |
1055 | |
24 | 1056 if (ca.cmdchar != K_IGNORE) |
1057 { | |
1058 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1059 msg_col = 0; | |
1060 } | |
7 | 1061 |
1062 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1063 | |
1064 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1065 * mode. */ | |
1066 if (!VIsual_active && km_startsel) | |
1067 { | |
1068 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1069 { | |
1070 start_selection(); | |
1071 unshift_special(&ca); | |
1072 idx = find_command(ca.cmdchar); | |
1073 } | |
1074 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1075 && (mod_mask & MOD_MASK_SHIFT)) | |
1076 { | |
1077 start_selection(); | |
1078 mod_mask &= ~MOD_MASK_SHIFT; | |
1079 } | |
1080 } | |
1081 | |
1082 /* | |
1083 * Execute the command! | |
1084 * Call the command function found in the commands table. | |
1085 */ | |
1086 ca.arg = nv_cmds[idx].cmd_arg; | |
1087 (nv_cmds[idx].cmd_func)(&ca); | |
1088 | |
1089 /* | |
1090 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1091 * need it later. | |
1092 */ | |
1093 if (!finish_op | |
1094 && !oap->op_type | |
1095 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1096 { | |
1097 clearop(oap); | |
1098 #ifdef FEAT_EVAL | |
2821 | 1099 { |
1100 int regname = 0; | |
2829 | 1101 |
2821 | 1102 /* Adjust the register according to 'clipboard', so that when |
1103 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1104 # ifdef FEAT_CLIPBOARD |
2821 | 1105 adjust_clip_reg(®name); |
2829 | 1106 # endif |
2821 | 1107 set_reg_var(regname); |
1108 } | |
7 | 1109 #endif |
1110 } | |
1111 | |
570 | 1112 /* Get the length of mapped chars again after typing a count, second |
36 | 1113 * character or "z333<cr>". */ |
1114 if (old_mapped_len > 0) | |
1115 old_mapped_len = typebuf_maplen(); | |
1116 | |
7 | 1117 /* |
1118 * If an operation is pending, handle it... | |
1119 */ | |
1120 do_pending_operator(&ca, old_col, FALSE); | |
1121 | |
1122 /* | |
1123 * Wait for a moment when a message is displayed that will be overwritten | |
1124 * by the mode message. | |
1125 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1126 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1127 * In Visual mode, it's more important to keep the Visual area updated | |
1128 * than keeping a message (e.g. from a /pat search). | |
1129 * Only do this if the command was typed, not from a mapping. | |
1130 * Don't wait when emsg_silent is non-zero. | |
1131 * Also wait a bit after an error message, e.g. for "^O:". | |
1132 * Don't redraw the screen, it would remove the message. | |
1133 */ | |
1134 if ( ((p_smd | |
641 | 1135 && msg_silent == 0 |
7 | 1136 && (restart_edit != 0 |
1137 || (VIsual_active | |
1138 && old_pos.lnum == curwin->w_cursor.lnum | |
1139 && old_pos.col == curwin->w_cursor.col) | |
1140 ) | |
1141 && (clear_cmdline | |
1142 || redraw_cmdline) | |
1143 && (msg_didout || (msg_didany && msg_scroll)) | |
1144 && !msg_nowait | |
1145 && KeyTyped) | |
1146 || (restart_edit != 0 | |
1147 && !VIsual_active | |
1148 && (msg_scroll | |
1149 || emsg_on_display))) | |
1150 && oap->regname == 0 | |
1151 && !(ca.retval & CA_COMMAND_BUSY) | |
1152 && stuff_empty() | |
1153 && typebuf_typed() | |
1154 && emsg_silent == 0 | |
1155 && !did_wait_return | |
1156 && oap->op_type == OP_NOP) | |
1157 { | |
1158 int save_State = State; | |
1159 | |
1160 /* Draw the cursor with the right shape here */ | |
1161 if (restart_edit != 0) | |
1162 State = INSERT; | |
1163 | |
1164 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1165 * delay */ | |
1166 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1167 { | |
1168 char_u *kmsg; | |
1169 | |
1170 kmsg = keep_msg; | |
1171 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
|
1172 // showmode() will clear keep_msg, but we want to use it anyway |
7 | 1173 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
|
1174 // now reset it, otherwise it's put in the history again |
7 | 1175 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
|
1176 |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1177 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
|
1178 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
|
1179 { |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1180 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
|
1181 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
|
1182 } |
7 | 1183 } |
1184 setcursor(); | |
1185 cursor_on(); | |
1186 out_flush(); | |
1187 if (msg_scroll || emsg_on_display) | |
1188 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1189 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1190 State = save_State; | |
1191 | |
1192 msg_scroll = FALSE; | |
1193 emsg_on_display = FALSE; | |
1194 } | |
1195 | |
1196 /* | |
1197 * Finish up after executing a Normal mode command. | |
1198 */ | |
1199 normal_end: | |
1200 | |
1201 msg_nowait = FALSE; | |
1202 | |
1203 /* Reset finish_op, in case it was set */ | |
1204 #ifdef CURSOR_SHAPE | |
1205 c = finish_op; | |
1206 #endif | |
1207 finish_op = FALSE; | |
1208 #ifdef CURSOR_SHAPE | |
1209 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1210 * mode or did a replace command. */ | |
1211 if (c || ca.cmdchar == 'r') | |
1212 { | |
1213 ui_cursor_shape(); /* may show different cursor shape */ | |
1214 # ifdef FEAT_MOUSESHAPE | |
1215 update_mouseshape(-1); | |
1216 # endif | |
1217 } | |
1218 #endif | |
1219 | |
1220 #ifdef FEAT_CMDL_INFO | |
1692 | 1221 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
|
1222 && ca.cmdchar != K_CURSORHOLD) |
7 | 1223 clear_showcmd(); |
1224 #endif | |
1225 | |
1226 checkpcmark(); /* check if we moved since setting pcmark */ | |
1227 vim_free(ca.searchbuf); | |
1228 | |
1229 if (has_mbyte) | |
1230 mb_adjust_cursor(); | |
1231 | |
1232 if (curwin->w_p_scb && toplevel) | |
1233 { | |
1234 validate_cursor(); /* may need to update w_leftcol */ | |
1235 do_check_scrollbind(TRUE); | |
1236 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1237 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1238 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1239 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1240 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
|
1241 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1242 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1243 |
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
|
1244 #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
|
1245 /* 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
|
1246 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
|
1247 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
|
1248 #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
|
1249 |
7 | 1250 /* |
1251 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1252 * if still inside a mapping that started in Visual mode). | |
1253 * May switch from Visual to Select mode after CTRL-O command. | |
1254 */ | |
1255 if ( oap->op_type == OP_NOP | |
1256 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1257 || restart_VIsual_select == 1) | |
1258 && !(ca.retval & CA_COMMAND_BUSY) | |
1259 && stuff_empty() | |
1260 && oap->regname == 0) | |
1261 { | |
1262 if (restart_VIsual_select == 1) | |
1263 { | |
1264 VIsual_select = TRUE; | |
1265 showmode(); | |
1266 restart_VIsual_select = 0; | |
1267 } | |
5735 | 1268 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1269 (void)edit(restart_edit, FALSE, 1L); |
1270 } | |
1271 | |
1272 if (restart_VIsual_select == 2) | |
1273 restart_VIsual_select = 1; | |
1274 | |
1275 /* Save count before an operator for next time. */ | |
1276 opcount = ca.opcount; | |
1277 } | |
1278 | |
2667 | 1279 #ifdef FEAT_EVAL |
1280 /* | |
1281 * Set v:count and v:count1 according to "cap". | |
1282 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1283 */ | |
1284 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1285 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1286 { |
1287 long count = cap->count0; | |
1288 | |
1289 /* multiply with cap->opcount the same way as above */ | |
1290 if (cap->opcount != 0) | |
1291 count = cap->opcount * (count == 0 ? 1 : count); | |
1292 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1293 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1294 } | |
1295 #endif | |
1296 | |
7 | 1297 /* |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1298 * Handle an operator after Visual mode or when the movement is finished. |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1299 * "gui_yank" is true when yanking text for the clipboard. |
7 | 1300 */ |
1301 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1302 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1303 { |
1304 oparg_T *oap = cap->oap; | |
1305 pos_T old_cursor; | |
1306 int empty_region_error; | |
1307 int restart_edit_save; | |
6266 | 1308 #ifdef FEAT_LINEBREAK |
1309 int lbr_saved = curwin->w_p_lbr; | |
1310 #endif | |
7 | 1311 |
1312 /* The visual area is remembered for redo */ | |
1313 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1314 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1315 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1316 static long redo_VIsual_count; /* count for Visual operator */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1317 static int redo_VIsual_arg; /* extra argument */ |
7 | 1318 int include_line_break = FALSE; |
1319 | |
1320 #if defined(FEAT_CLIPBOARD) | |
1321 /* | |
1322 * Yank the visual area into the GUI selection register before we operate | |
1323 * on it and lose it forever. | |
1324 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1325 * This could call do_pending_operator() recursively, but that's OK | |
1326 * because gui_yank will be TRUE for the nested call. | |
1327 */ | |
3674 | 1328 if ((clip_star.available || clip_plus.available) |
7 | 1329 && oap->op_type != OP_NOP |
1330 && !gui_yank | |
1331 && VIsual_active | |
1332 && !redo_VIsual_busy | |
1333 && oap->regname == 0) | |
1334 clip_auto_select(); | |
1335 #endif | |
1336 old_cursor = curwin->w_cursor; | |
1337 | |
1338 /* | |
1339 * If an operation is pending, handle it... | |
1340 */ | |
5735 | 1341 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1342 { | |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1343 // Yank can be redone when 'y' is in 'cpoptions', but not when yanking |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1344 // for the clipboard. |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1345 int redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank; |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1346 |
6497 | 1347 #ifdef FEAT_LINEBREAK |
1348 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1349 if (curwin->w_p_lbr) |
1350 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1351 curwin->w_p_lbr = FALSE; |
1352 #endif | |
7 | 1353 oap->is_VIsual = VIsual_active; |
1354 if (oap->motion_force == 'V') | |
1355 oap->motion_type = MLINE; | |
1356 else if (oap->motion_force == 'v') | |
1357 { | |
1358 /* If the motion was linewise, "inclusive" will not have been set. | |
1359 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1360 if (oap->motion_type == MLINE) | |
1361 oap->inclusive = FALSE; | |
1362 /* If the motion already was characterwise, toggle "inclusive" */ | |
1363 else if (oap->motion_type == MCHAR) | |
1364 oap->inclusive = !oap->inclusive; | |
1365 oap->motion_type = MCHAR; | |
1366 } | |
1367 else if (oap->motion_force == Ctrl_V) | |
1368 { | |
1369 /* Change line- or characterwise motion into Visual block mode. */ | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1370 if (!VIsual_active) |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1371 { |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1372 VIsual_active = TRUE; |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1373 VIsual = oap->start; |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1374 } |
7 | 1375 VIsual_mode = Ctrl_V; |
1376 VIsual_select = FALSE; | |
1377 VIsual_reselect = FALSE; | |
1378 } | |
1379 | |
4337 | 1380 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1381 /* Never redo "zf" (define fold). */ | |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1382 if ((redo_yank || oap->op_type != OP_YANK) |
4337 | 1383 && ((!VIsual_active || oap->motion_force) |
1384 /* Also redo Operator-pending Visual mode mappings */ | |
1385 || (VIsual_active && cap->cmdchar == ':' | |
1386 && oap->op_type != OP_COLON)) | |
164 | 1387 && cap->cmdchar != 'D' |
7 | 1388 #ifdef FEAT_FOLDING |
1389 && oap->op_type != OP_FOLD | |
1390 && oap->op_type != OP_FOLDOPEN | |
1391 && oap->op_type != OP_FOLDOPENREC | |
1392 && oap->op_type != OP_FOLDCLOSE | |
1393 && oap->op_type != OP_FOLDCLOSEREC | |
1394 && oap->op_type != OP_FOLDDEL | |
1395 && oap->op_type != OP_FOLDDELREC | |
1396 #endif | |
1397 ) | |
1398 { | |
1399 prep_redo(oap->regname, cap->count0, | |
1400 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1401 oap->motion_force, cap->cmdchar, cap->nchar); | |
1402 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1403 { | |
1404 /* | |
1405 * If 'cpoptions' does not contain 'r', insert the search | |
1406 * pattern to really repeat the same command. | |
1407 */ | |
1408 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1409 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1410 AppendToRedobuff(NL_STR); |
1411 } | |
1412 else if (cap->cmdchar == ':') | |
1413 { | |
1414 /* do_cmdline() has stored the first typed line in | |
1415 * "repeat_cmdline". When several lines are typed repeating | |
1416 * won't be possible. */ | |
1417 if (repeat_cmdline == NULL) | |
1418 ResetRedobuff(); | |
1419 else | |
1420 { | |
620 | 1421 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1422 AppendToRedobuff(NL_STR); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1423 VIM_CLEAR(repeat_cmdline); |
7 | 1424 } |
1425 } | |
1426 } | |
1427 | |
1428 if (redo_VIsual_busy) | |
1429 { | |
3125 | 1430 /* Redo of an operation on a Visual area. Use the same size from |
1431 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1432 oap->start = curwin->w_cursor; |
1433 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1434 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1435 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1436 VIsual_mode = redo_VIsual_mode; | |
3125 | 1437 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1438 { |
3125 | 1439 if (VIsual_mode == 'v') |
1440 { | |
1441 if (redo_VIsual_line_count <= 1) | |
1442 { | |
1443 validate_virtcol(); | |
1444 curwin->w_curswant = | |
1445 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1446 } | |
1447 else | |
1448 curwin->w_curswant = redo_VIsual_vcol; | |
1449 } | |
7 | 1450 else |
3125 | 1451 { |
1452 curwin->w_curswant = MAXCOL; | |
1453 } | |
1454 coladvance(curwin->w_curswant); | |
7 | 1455 } |
1456 cap->count0 = redo_VIsual_count; | |
1457 if (redo_VIsual_count != 0) | |
1458 cap->count1 = redo_VIsual_count; | |
1459 else | |
1460 cap->count1 = 1; | |
1461 } | |
1462 else if (VIsual_active) | |
1463 { | |
999 | 1464 if (!gui_yank) |
1465 { | |
1466 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1467 curbuf->b_visual.vi_start = VIsual; | |
1468 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1469 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1470 if (VIsual_mode_orig != NUL) |
1471 { | |
1472 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1473 VIsual_mode_orig = NUL; | |
1474 } | |
999 | 1475 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1476 # ifdef FEAT_EVAL |
999 | 1477 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1478 # endif |
999 | 1479 } |
7 | 1480 |
1481 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1482 * characterwise selection. |
1483 * Special case: gH<Del> deletes the last line. */ | |
1484 if (VIsual_select && VIsual_mode == 'V' | |
1485 && cap->oap->op_type != OP_DELETE) | |
7 | 1486 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1487 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1488 { |
1489 VIsual.col = 0; | |
1490 curwin->w_cursor.col = | |
1491 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1492 } | |
1493 else | |
1494 { | |
1495 curwin->w_cursor.col = 0; | |
1496 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1497 } | |
1498 VIsual_mode = 'v'; | |
1499 } | |
1500 /* If 'selection' is "exclusive", backup one character for | |
1501 * charwise selections. */ | |
1502 else if (VIsual_mode == 'v') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1503 include_line_break = unadjust_for_sel(); |
7 | 1504 |
1505 oap->start = VIsual; | |
1506 if (VIsual_mode == 'V') | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1507 { |
7 | 1508 oap->start.col = 0; |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1509 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1510 } |
7 | 1511 } |
1512 | |
1513 /* | |
1514 * Set oap->start to the first position of the operated text, oap->end | |
1515 * to the end of the operated text. w_cursor is equal to oap->start. | |
1516 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1517 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1518 { |
1519 #ifdef FEAT_FOLDING | |
1520 /* Include folded lines completely. */ | |
1521 if (!VIsual_active) | |
1522 { | |
1523 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1524 oap->start.col = 0; | |
18128
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
1525 if ((curwin->w_cursor.col > 0 || oap->inclusive) |
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
1526 && hasFolding(curwin->w_cursor.lnum, NULL, |
7 | 1527 &curwin->w_cursor.lnum)) |
1528 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1529 } | |
1530 #endif | |
1531 oap->end = curwin->w_cursor; | |
1532 curwin->w_cursor = oap->start; | |
1533 | |
1534 /* w_virtcol may have been updated; if the cursor goes back to its | |
1535 * previous position w_virtcol becomes invalid and isn't updated | |
1536 * automatically. */ | |
1537 curwin->w_valid &= ~VALID_VIRTCOL; | |
1538 } | |
1539 else | |
1540 { | |
1541 #ifdef FEAT_FOLDING | |
1542 /* Include folded lines completely. */ | |
1543 if (!VIsual_active && oap->motion_type == MLINE) | |
1544 { | |
1545 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1546 NULL)) | |
1547 curwin->w_cursor.col = 0; | |
1548 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1549 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1550 } | |
1551 #endif | |
1552 oap->end = oap->start; | |
1553 oap->start = curwin->w_cursor; | |
1554 } | |
1555 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1556 /* Just in case lines were deleted that make the position invalid. */ |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1557 check_pos(curwin->w_buffer, &oap->end); |
7 | 1558 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1559 | |
1560 /* Set "virtual_op" before resetting VIsual_active. */ | |
1561 virtual_op = virtual_active(); | |
1562 | |
1563 if (VIsual_active || redo_VIsual_busy) | |
1564 { | |
6866 | 1565 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1566 |
1567 if (!redo_VIsual_busy && !gui_yank) | |
1568 { | |
1569 /* | |
1570 * Prepare to reselect and redo Visual: this is based on the | |
1571 * size of the Visual text | |
1572 */ | |
1573 resel_VIsual_mode = VIsual_mode; | |
1574 if (curwin->w_curswant == MAXCOL) | |
3125 | 1575 resel_VIsual_vcol = MAXCOL; |
7 | 1576 else |
3125 | 1577 { |
1578 if (VIsual_mode != Ctrl_V) | |
1579 getvvcol(curwin, &(oap->end), | |
1580 NULL, NULL, &oap->end_vcol); | |
1581 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1582 { | |
1583 if (VIsual_mode != Ctrl_V) | |
1584 getvvcol(curwin, &(oap->start), | |
1585 &oap->start_vcol, NULL, NULL); | |
1586 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1587 } | |
1588 else | |
1589 resel_VIsual_vcol = oap->end_vcol; | |
1590 } | |
7 | 1591 resel_VIsual_line_count = oap->line_count; |
1592 } | |
1593 | |
1594 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1595 if ((redo_yank || oap->op_type != OP_YANK) |
7 | 1596 && oap->op_type != OP_COLON |
1597 #ifdef FEAT_FOLDING | |
1598 && oap->op_type != OP_FOLD | |
1599 && oap->op_type != OP_FOLDOPEN | |
1600 && oap->op_type != OP_FOLDOPENREC | |
1601 && oap->op_type != OP_FOLDCLOSE | |
1602 && oap->op_type != OP_FOLDCLOSEREC | |
1603 && oap->op_type != OP_FOLDDEL | |
1604 && oap->op_type != OP_FOLDDELREC | |
1605 #endif | |
1606 && oap->motion_force == NUL | |
1607 ) | |
1608 { | |
1609 /* Prepare for redoing. Only use the nchar field for "r", | |
1610 * otherwise it might be the second char of the operator. */ | |
3701 | 1611 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1612 || cap->nchar == 'N')) | |
5523 | 1613 prep_redo(oap->regname, cap->count0, |
1614 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1615 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1616 else if (cap->cmdchar != ':') |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1617 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1618 int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1619 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1620 /* reverse what nv_replace() did */ |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1621 if (nchar == REPLACE_CR_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1622 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1623 else if (nchar == REPLACE_NL_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1624 nchar = NL; |
3701 | 1625 prep_redo(oap->regname, 0L, NUL, 'v', |
1626 get_op_char(oap->op_type), | |
1627 get_extra_op_char(oap->op_type), | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1628 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1629 } |
7 | 1630 if (!redo_VIsual_busy) |
1631 { | |
1632 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1633 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1634 redo_VIsual_line_count = resel_VIsual_line_count; |
1635 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1636 redo_VIsual_arg = cap->arg; |
7 | 1637 } |
1638 } | |
1639 | |
1640 /* | |
1641 * oap->inclusive defaults to TRUE. | |
1642 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1643 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1644 */ | |
1645 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1646 oap->inclusive = TRUE; | |
1647 if (VIsual_mode == 'V') | |
1648 oap->motion_type = MLINE; | |
1649 else | |
1650 { | |
1651 oap->motion_type = MCHAR; | |
1652 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1653 && (include_line_break || !virtual_op)) |
7 | 1654 { |
1655 oap->inclusive = FALSE; | |
1656 /* Try to include the newline, unless it's an operator | |
2957 | 1657 * that works on lines only. */ |
6826 | 1658 if (*p_sel != 'o' |
1659 && !op_on_lines(oap->op_type) | |
1660 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1661 { |
6826 | 1662 ++oap->end.lnum; |
1663 oap->end.col = 0; | |
1664 oap->end.coladd = 0; | |
1665 ++oap->line_count; | |
7 | 1666 } |
1667 } | |
1668 } | |
1669 | |
1670 redo_VIsual_busy = FALSE; | |
592 | 1671 |
7 | 1672 /* |
1673 * Switch Visual off now, so screen updating does | |
1674 * not show inverted text when the screen is redrawn. | |
1675 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1676 * no screen redraw, so it is done here to remove the inverted | |
1677 * part. | |
1678 */ | |
1679 if (!gui_yank) | |
1680 { | |
1681 VIsual_active = FALSE; | |
5735 | 1682 #ifdef FEAT_MOUSE |
7 | 1683 setmouse(); |
1684 mouse_dragging = 0; | |
5735 | 1685 #endif |
6979 | 1686 may_clear_cmdline(); |
7 | 1687 if ((oap->op_type == OP_YANK |
1688 || oap->op_type == OP_COLON | |
592 | 1689 || oap->op_type == OP_FUNCTION |
7 | 1690 || oap->op_type == OP_FILTER) |
1691 && oap->motion_force == NUL) | |
6497 | 1692 { |
1693 #ifdef FEAT_LINEBREAK | |
1694 /* make sure redrawing is correct */ | |
1695 curwin->w_p_lbr = lbr_saved; | |
1696 #endif | |
7 | 1697 redraw_curbuf_later(INVERTED); |
6497 | 1698 } |
7 | 1699 } |
1700 } | |
1701 | |
1702 /* Include the trailing byte of a multi-byte char. */ | |
1703 if (has_mbyte && oap->inclusive) | |
1704 { | |
1705 int l; | |
1706 | |
474 | 1707 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1708 if (l > 1) |
1709 oap->end.col += l - 1; | |
1710 } | |
1711 curwin->w_set_curswant = TRUE; | |
1712 | |
1713 /* | |
1714 * oap->empty is set when start and end are the same. The inclusive | |
1715 * flag affects this too, unless yanking and the end is on a NUL. | |
1716 */ | |
1717 oap->empty = (oap->motion_type == MCHAR | |
1718 && (!oap->inclusive | |
1719 || (oap->op_type == OP_YANK | |
1720 && gchar_pos(&oap->end) == NUL)) | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1721 && EQUAL_POS(oap->start, oap->end) |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1722 && !(virtual_op && oap->start.coladd != oap->end.coladd)); |
7 | 1723 /* |
1724 * For delete, change and yank, it's an error to operate on an | |
1725 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1726 */ | |
1727 empty_region_error = (oap->empty | |
1728 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1729 | |
1730 /* Force a redraw when operating on an empty Visual region, when | |
1731 * 'modifiable is off or creating a fold. */ | |
1732 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1733 #ifdef FEAT_FOLDING |
7 | 1734 || oap->op_type == OP_FOLD |
5735 | 1735 #endif |
7 | 1736 )) |
6497 | 1737 { |
1738 #ifdef FEAT_LINEBREAK | |
1739 curwin->w_p_lbr = lbr_saved; | |
1740 #endif | |
7 | 1741 redraw_curbuf_later(INVERTED); |
6497 | 1742 } |
7 | 1743 |
1744 /* | |
1745 * If the end of an operator is in column one while oap->motion_type | |
1746 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1747 * character in the previous line. If op_start is on or before the | |
1748 * first non-blank in the line, the operator becomes linewise | |
1749 * (strange, but that's the way vi does it). | |
1750 */ | |
1751 if ( oap->motion_type == MCHAR | |
1752 && oap->inclusive == FALSE | |
1753 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1754 && oap->end.col == 0 | |
1755 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1756 && !oap->block_mode |
7 | 1757 && oap->line_count > 1) |
1758 { | |
1759 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1760 --oap->line_count; | |
1761 --oap->end.lnum; | |
1762 if (inindent(0)) | |
1763 oap->motion_type = MLINE; | |
1764 else | |
1765 { | |
1766 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1767 if (oap->end.col) | |
1768 { | |
1769 --oap->end.col; | |
1770 oap->inclusive = TRUE; | |
1771 } | |
1772 } | |
1773 } | |
1774 else | |
1775 oap->end_adjusted = FALSE; | |
1776 | |
1777 switch (oap->op_type) | |
1778 { | |
1779 case OP_LSHIFT: | |
1780 case OP_RSHIFT: | |
5735 | 1781 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1782 auto_format(FALSE, TRUE); |
1783 break; | |
1784 | |
1785 case OP_JOIN_NS: | |
1786 case OP_JOIN: | |
1787 if (oap->line_count < 2) | |
1788 oap->line_count = 2; | |
1789 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1790 curbuf->b_ml.ml_line_count) | |
1791 beep_flush(); | |
1792 else | |
1793 { | |
5735 | 1794 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1795 TRUE, TRUE, TRUE); |
7 | 1796 auto_format(FALSE, TRUE); |
1797 } | |
1798 break; | |
1799 | |
1800 case OP_DELETE: | |
1801 VIsual_reselect = FALSE; /* don't reselect now */ | |
1802 if (empty_region_error) | |
3324 | 1803 { |
6949 | 1804 vim_beep(BO_OPER); |
3324 | 1805 CancelRedo(); |
1806 } | |
7 | 1807 else |
1808 { | |
1809 (void)op_delete(oap); | |
1810 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1811 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1812 auto_format(FALSE, TRUE); | |
1813 } | |
1814 break; | |
1815 | |
1816 case OP_YANK: | |
1817 if (empty_region_error) | |
1818 { | |
1819 if (!gui_yank) | |
3324 | 1820 { |
6949 | 1821 vim_beep(BO_OPER); |
3324 | 1822 CancelRedo(); |
1823 } | |
7 | 1824 } |
1825 else | |
6497 | 1826 { |
1827 #ifdef FEAT_LINEBREAK | |
1828 curwin->w_p_lbr = lbr_saved; | |
1829 #endif | |
7 | 1830 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1831 } |
7 | 1832 check_cursor_col(); |
1833 break; | |
1834 | |
1835 case OP_CHANGE: | |
1836 VIsual_reselect = FALSE; /* don't reselect now */ | |
1837 if (empty_region_error) | |
3324 | 1838 { |
6949 | 1839 vim_beep(BO_OPER); |
3324 | 1840 CancelRedo(); |
1841 } | |
7 | 1842 else |
1843 { | |
1844 /* This is a new edit command, not a restart. Need to | |
1845 * remember it to make 'insertmode' work with mappings for | |
1846 * Visual mode. But do this only once and not when typed and | |
1847 * 'insertmode' isn't set. */ | |
1848 if (p_im || !KeyTyped) | |
1849 restart_edit_save = restart_edit; | |
1850 else | |
1851 restart_edit_save = 0; | |
1852 restart_edit = 0; | |
6497 | 1853 #ifdef FEAT_LINEBREAK |
1854 /* Restore linebreak, so that when the user edits it looks as | |
1855 * before. */ | |
6866 | 1856 if (curwin->w_p_lbr != lbr_saved) |
1857 { | |
1858 curwin->w_p_lbr = lbr_saved; | |
1859 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1860 } | |
6497 | 1861 #endif |
7 | 1862 /* Reset finish_op now, don't want it set inside edit(). */ |
1863 finish_op = FALSE; | |
1864 if (op_change(oap)) /* will call edit() */ | |
1865 cap->retval |= CA_COMMAND_BUSY; | |
1866 if (restart_edit == 0) | |
1867 restart_edit = restart_edit_save; | |
1868 } | |
1869 break; | |
1870 | |
1871 case OP_FILTER: | |
1872 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1873 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1874 else | |
1875 bangredo = TRUE; /* do_bang() will put cmd in redo buffer */ | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
1876 /* FALLTHROUGH */ |
7 | 1877 |
1878 case OP_INDENT: | |
1879 case OP_COLON: | |
1880 | |
1881 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1882 /* | |
1883 * If 'equalprg' is empty, do the indenting internally. | |
1884 */ | |
1885 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1886 { | |
1887 # ifdef FEAT_LISP | |
1888 if (curbuf->b_p_lisp) | |
1889 { | |
1890 op_reindent(oap, get_lisp_indent); | |
1891 break; | |
1892 } | |
1893 # endif | |
1894 # ifdef FEAT_CINDENT | |
1895 op_reindent(oap, | |
1896 # ifdef FEAT_EVAL | |
1897 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1898 # endif | |
1899 get_c_indent); | |
1900 break; | |
1901 # endif | |
1902 } | |
1903 #endif | |
1904 | |
1905 op_colon(oap); | |
1906 break; | |
1907 | |
1908 case OP_TILDE: | |
1909 case OP_UPPER: | |
1910 case OP_LOWER: | |
1911 case OP_ROT13: | |
1912 if (empty_region_error) | |
3324 | 1913 { |
6949 | 1914 vim_beep(BO_OPER); |
3324 | 1915 CancelRedo(); |
1916 } | |
7 | 1917 else |
1918 op_tilde(oap); | |
1919 check_cursor_col(); | |
1920 break; | |
1921 | |
1922 case OP_FORMAT: | |
667 | 1923 #if defined(FEAT_EVAL) |
1924 if (*curbuf->b_p_fex != NUL) | |
1925 op_formatexpr(oap); /* use expression */ | |
1926 else | |
1927 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1928 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1929 op_colon(oap); /* use external command */ |
1930 else | |
1931 op_format(oap, FALSE); /* use internal function */ | |
1932 break; | |
1933 | |
1934 case OP_FORMAT2: | |
1935 op_format(oap, TRUE); /* use internal function */ | |
1936 break; | |
1937 | |
592 | 1938 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1939 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1940 /* Restore linebreak, so that when the user edits it looks as |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1941 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1942 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1943 #endif |
592 | 1944 op_function(oap); /* call 'operatorfunc' */ |
1945 break; | |
1946 | |
7 | 1947 case OP_INSERT: |
1948 case OP_APPEND: | |
1949 VIsual_reselect = FALSE; /* don't reselect now */ | |
1950 if (empty_region_error) | |
3324 | 1951 { |
6949 | 1952 vim_beep(BO_OPER); |
3324 | 1953 CancelRedo(); |
1954 } | |
7 | 1955 else |
1956 { | |
1957 /* This is a new edit command, not a restart. Need to | |
1958 * remember it to make 'insertmode' work with mappings for | |
1959 * Visual mode. But do this only once. */ | |
1960 restart_edit_save = restart_edit; | |
1961 restart_edit = 0; | |
6497 | 1962 #ifdef FEAT_LINEBREAK |
1963 /* Restore linebreak, so that when the user edits it looks as | |
1964 * before. */ | |
6866 | 1965 if (curwin->w_p_lbr != lbr_saved) |
1966 { | |
1967 curwin->w_p_lbr = lbr_saved; | |
1968 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1969 } | |
6497 | 1970 #endif |
7 | 1971 op_insert(oap, cap->count1); |
6497 | 1972 #ifdef FEAT_LINEBREAK |
1973 /* Reset linebreak, so that formatting works correctly. */ | |
1974 curwin->w_p_lbr = FALSE; | |
1975 #endif | |
7 | 1976 |
1977 /* TODO: when inserting in several lines, should format all | |
1978 * the lines. */ | |
1979 auto_format(FALSE, TRUE); | |
1980 | |
1981 if (restart_edit == 0) | |
1982 restart_edit = restart_edit_save; | |
10785
9938c90d1e6c
patch 8.0.0282: need to use CTRL-O twice when in Visual-Insert mode
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
1983 else |
9938c90d1e6c
patch 8.0.0282: need to use CTRL-O twice when in Visual-Insert mode
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
1984 cap->retval |= CA_COMMAND_BUSY; |
7 | 1985 } |
1986 break; | |
1987 | |
1988 case OP_REPLACE: | |
1989 VIsual_reselect = FALSE; /* don't reselect now */ | |
1990 if (empty_region_error) | |
3324 | 1991 { |
6949 | 1992 vim_beep(BO_OPER); |
3324 | 1993 CancelRedo(); |
1994 } | |
7 | 1995 else |
6497 | 1996 { |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
1997 #ifdef FEAT_LINEBREAK |
6497 | 1998 /* Restore linebreak, so that when the user edits it looks as |
1999 * before. */ | |
6866 | 2000 if (curwin->w_p_lbr != lbr_saved) |
2001 { | |
2002 curwin->w_p_lbr = lbr_saved; | |
2003 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2004 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2005 #endif |
7 | 2006 op_replace(oap, cap->nchar); |
6497 | 2007 } |
7 | 2008 break; |
2009 | |
2010 #ifdef FEAT_FOLDING | |
2011 case OP_FOLD: | |
2012 VIsual_reselect = FALSE; /* don't reselect now */ | |
2013 foldCreate(oap->start.lnum, oap->end.lnum); | |
2014 break; | |
2015 | |
2016 case OP_FOLDOPEN: | |
2017 case OP_FOLDOPENREC: | |
2018 case OP_FOLDCLOSE: | |
2019 case OP_FOLDCLOSEREC: | |
2020 VIsual_reselect = FALSE; /* don't reselect now */ | |
2021 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2022 oap->op_type == OP_FOLDOPEN | |
2023 || oap->op_type == OP_FOLDOPENREC, | |
2024 oap->op_type == OP_FOLDOPENREC | |
2025 || oap->op_type == OP_FOLDCLOSEREC, | |
2026 oap->is_VIsual); | |
2027 break; | |
2028 | |
2029 case OP_FOLDDEL: | |
2030 case OP_FOLDDELREC: | |
2031 VIsual_reselect = FALSE; /* don't reselect now */ | |
2032 deleteFold(oap->start.lnum, oap->end.lnum, | |
2033 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2034 break; | |
2035 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2036 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2037 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2038 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2039 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2040 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2041 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2042 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2043 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2044 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2045 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2046 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2047 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2048 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2049 op_addsub(oap, cap->count1, redo_VIsual_arg); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2050 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2051 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2052 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2053 break; |
7 | 2054 default: |
2055 clearopbeep(oap); | |
2056 } | |
2057 virtual_op = MAYBE; | |
2058 if (!gui_yank) | |
2059 { | |
2060 /* | |
2061 * if 'sol' not set, go back to old column for some commands | |
2062 */ | |
2063 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2064 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2065 || oap->op_type == OP_DELETE)) | |
6497 | 2066 { |
2067 #ifdef FEAT_LINEBREAK | |
2068 curwin->w_p_lbr = FALSE; | |
2069 #endif | |
7 | 2070 coladvance(curwin->w_curswant = old_col); |
6497 | 2071 } |
7 | 2072 } |
2073 else | |
2074 { | |
2075 curwin->w_cursor = old_cursor; | |
2076 } | |
2077 oap->block_mode = FALSE; | |
2078 clearop(oap); | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2079 motion_force = NUL; |
7 | 2080 } |
6266 | 2081 #ifdef FEAT_LINEBREAK |
2082 curwin->w_p_lbr = lbr_saved; | |
2083 #endif | |
7 | 2084 } |
2085 | |
2086 /* | |
2087 * Handle indent and format operators and visual mode ":". | |
2088 */ | |
2089 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2090 op_colon(oparg_T *oap) |
7 | 2091 { |
2092 stuffcharReadbuff(':'); | |
2093 if (oap->is_VIsual) | |
2094 stuffReadbuff((char_u *)"'<,'>"); | |
2095 else | |
2096 { | |
2097 /* | |
2098 * Make the range look nice, so it can be repeated. | |
2099 */ | |
2100 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2101 stuffcharReadbuff('.'); | |
2102 else | |
2103 stuffnumReadbuff((long)oap->start.lnum); | |
2104 if (oap->end.lnum != oap->start.lnum) | |
2105 { | |
2106 stuffcharReadbuff(','); | |
2107 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2108 stuffcharReadbuff('.'); | |
2109 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2110 stuffcharReadbuff('$'); | |
2111 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2112 { | |
2113 stuffReadbuff((char_u *)".+"); | |
2114 stuffnumReadbuff((long)oap->line_count - 1); | |
2115 } | |
2116 else | |
2117 stuffnumReadbuff((long)oap->end.lnum); | |
2118 } | |
2119 } | |
2120 if (oap->op_type != OP_COLON) | |
2121 stuffReadbuff((char_u *)"!"); | |
2122 if (oap->op_type == OP_INDENT) | |
2123 { | |
2124 #ifndef FEAT_CINDENT | |
2125 if (*get_equalprg() == NUL) | |
2126 stuffReadbuff((char_u *)"indent"); | |
2127 else | |
2128 #endif | |
2129 stuffReadbuff(get_equalprg()); | |
2130 stuffReadbuff((char_u *)"\n"); | |
2131 } | |
2132 else if (oap->op_type == OP_FORMAT) | |
2133 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2134 if (*curbuf->b_p_fp != NUL) |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2135 stuffReadbuff(curbuf->b_p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2136 else if (*p_fp != NUL) |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2137 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2138 else |
7 | 2139 stuffReadbuff((char_u *)"fmt"); |
216 | 2140 stuffReadbuff((char_u *)"\n']"); |
7 | 2141 } |
2142 | |
2143 /* | |
2144 * do_cmdline() does the rest | |
2145 */ | |
2146 } | |
2147 | |
592 | 2148 /* |
602 | 2149 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2150 */ |
690 | 2151 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2152 op_function(oparg_T *oap UNUSED) |
592 | 2153 { |
2154 #ifdef FEAT_EVAL | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2155 typval_T argv[2]; |
3431 | 2156 int save_virtual_op = virtual_op; |
592 | 2157 |
2158 if (*p_opfunc == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2159 emsg(_("E774: 'operatorfunc' is empty")); |
592 | 2160 else |
2161 { | |
2162 /* Set '[ and '] marks to text to be operated on. */ | |
2163 curbuf->b_op_start = oap->start; | |
2164 curbuf->b_op_end = oap->end; | |
2165 if (oap->motion_type != MLINE && !oap->inclusive) | |
2166 /* Exclude the end position. */ | |
2167 decl(&curbuf->b_op_end); | |
2168 | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2169 argv[0].v_type = VAR_STRING; |
592 | 2170 if (oap->block_mode) |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2171 argv[0].vval.v_string = (char_u *)"block"; |
592 | 2172 else if (oap->motion_type == MLINE) |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2173 argv[0].vval.v_string = (char_u *)"line"; |
592 | 2174 else |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2175 argv[0].vval.v_string = (char_u *)"char"; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2176 argv[1].v_type = VAR_UNKNOWN; |
3431 | 2177 |
2178 /* Reset virtual_op so that 'virtualedit' can be changed in the | |
2179 * function. */ | |
2180 virtual_op = MAYBE; | |
2181 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2182 (void)call_func_retnr(p_opfunc, 1, argv); |
3431 | 2183 |
2184 virtual_op = save_virtual_op; | |
592 | 2185 } |
2186 #else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2187 emsg(_("E775: Eval feature not available")); |
592 | 2188 #endif |
2189 } | |
2190 | |
7 | 2191 /* |
2192 * Check if highlighting for visual mode is possible, give a warning message | |
2193 * if not. | |
2194 */ | |
2195 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2196 check_visual_highlight(void) |
7 | 2197 { |
2198 static int did_check = FALSE; | |
2199 | |
2200 if (full_screen) | |
2201 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2202 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
|
2203 msg(_("Warning: terminal cannot highlight")); |
7 | 2204 did_check = TRUE; |
2205 } | |
2206 } | |
2207 | |
2208 /* | |
638 | 2209 * End Visual mode. |
7 | 2210 * This function should ALWAYS be called to end Visual mode, except from |
2211 * do_pending_operator(). | |
2212 */ | |
2213 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2214 end_visual_mode(void) |
7 | 2215 { |
2216 #ifdef FEAT_CLIPBOARD | |
2217 /* | |
2218 * If we are using the clipboard, then remember what was selected in case | |
2219 * we need to paste it somewhere while we still own the selection. | |
2220 * Only do this when the clipboard is already owned. Don't want to grab | |
2221 * the selection when hitting ESC. | |
2222 */ | |
2223 if (clip_star.available && clip_star.owned) | |
2224 clip_auto_select(); | |
2225 #endif | |
2226 | |
2227 VIsual_active = FALSE; | |
2228 #ifdef FEAT_MOUSE | |
2229 setmouse(); | |
2230 mouse_dragging = 0; | |
2231 #endif | |
2232 | |
2233 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 2234 curbuf->b_visual.vi_mode = VIsual_mode; |
2235 curbuf->b_visual.vi_start = VIsual; | |
2236 curbuf->b_visual.vi_end = curwin->w_cursor; | |
2237 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 2238 #ifdef FEAT_EVAL |
2239 curbuf->b_visual_mode_eval = VIsual_mode; | |
2240 #endif | |
2241 if (!virtual_active()) | |
2242 curwin->w_cursor.coladd = 0; | |
6979 | 2243 may_clear_cmdline(); |
7 | 2244 |
844 | 2245 adjust_cursor_eol(); |
7 | 2246 } |
2247 | |
2248 /* | |
2249 * Reset VIsual_active and VIsual_reselect. | |
2250 */ | |
2251 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2252 reset_VIsual_and_resel(void) |
7 | 2253 { |
2254 if (VIsual_active) | |
2255 { | |
2256 end_visual_mode(); | |
2257 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
2258 } | |
2259 VIsual_reselect = FALSE; | |
2260 } | |
2261 | |
2262 /* | |
2263 * Reset VIsual_active and VIsual_reselect if it's set. | |
2264 */ | |
2265 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2266 reset_VIsual(void) |
7 | 2267 { |
2268 if (VIsual_active) | |
2269 { | |
2270 end_visual_mode(); | |
2271 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
2272 VIsual_reselect = FALSE; | |
2273 } | |
2274 } | |
2275 | |
2276 /* | |
2277 * Check for a balloon-eval special item to include when searching for an | |
2278 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
2279 * Returns TRUE if the character at "*ptr" should be included. | |
2280 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
2281 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
2282 * "bnp" points to a counter for square brackets. | |
2283 */ | |
2284 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2285 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2286 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2287 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2288 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2289 int dir) |
7 | 2290 { |
2291 /* Accept everything inside []. */ | |
2292 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
2293 ++*bnp; | |
2294 if (*bnp > 0) | |
2295 { | |
2296 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
2297 --*bnp; | |
2298 return TRUE; | |
2299 } | |
2300 | |
2301 /* skip over "s.var" */ | |
2302 if (*ptr == '.') | |
2303 return TRUE; | |
2304 | |
2305 /* two-character item: s->var */ | |
2306 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
2307 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
2308 { | |
2309 *colp += dir; | |
2310 return TRUE; | |
2311 } | |
2312 return FALSE; | |
2313 } | |
2314 | |
2315 /* | |
2316 * Find the identifier under or to the right of the cursor. | |
2317 * "find_type" can have one of three values: | |
2318 * 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
|
2319 * 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
|
2320 * FIND_IDENT + FIND_STRING: find any non-white text, identifier preferred. |
184 | 2321 * FIND_EVAL: find text useful for C program debugging |
7 | 2322 * |
2323 * 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
|
2324 * 1. Search forward for the start of an identifier/text. Doesn't move if |
7 | 2325 * 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
|
2326 * 2. Search backward for the start of this identifier/text. |
7 | 2327 * This doesn't match the real Vi but I like it a little better and it |
2328 * 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
|
2329 * 3. Search forward to the end of this identifier/text. |
7 | 2330 * When FIND_IDENT isn't defined, we backup until a blank. |
2331 * | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2332 * 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
|
2333 * 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
|
2334 * points into the current buffer line and is not always NUL terminated. |
7 | 2335 */ |
2336 int | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2337 find_ident_under_cursor(char_u **text, int find_type) |
7 | 2338 { |
2339 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
|
2340 curwin->w_cursor.col, text, NULL, find_type); |
7 | 2341 } |
2342 | |
2343 /* | |
2344 * Like find_ident_under_cursor(), but for any window and any position. | |
2345 * However: Uses 'iskeyword' from the current window!. | |
2346 */ | |
2347 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2348 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2349 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2350 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2351 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
|
2352 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
|
2353 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
|
2354 int find_type) |
7 | 2355 { |
2356 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
|
2357 int col = 0; // init to shut up GCC |
7 | 2358 int i; |
2359 int this_class = 0; | |
2360 int prev_class; | |
2361 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
|
2362 int bn = 0; // bracket nesting |
7 | 2363 |
2364 /* | |
2365 * 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
|
2366 * if i == 1: try to find any non-white text |
7 | 2367 */ |
2368 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
2369 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
2370 { | |
2371 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2372 * 1. skip to start of identifier/text |
7 | 2373 */ |
2374 col = startcol; | |
2375 if (has_mbyte) | |
2376 { | |
2377 while (ptr[col] != NUL) | |
2378 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2379 // Stop at a ']' to evaluate "a[x]". |
7 | 2380 if ((find_type & FIND_EVAL) && ptr[col] == ']') |
2381 break; | |
2382 this_class = mb_get_class(ptr + col); | |
2383 if (this_class != 0 && (i == 1 || this_class != 1)) | |
2384 break; | |
474 | 2385 col += (*mb_ptr2len)(ptr + col); |
7 | 2386 } |
2387 } | |
2388 else | |
2389 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
|
2390 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 2391 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
2392 ) | |
2393 ++col; | |
2394 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2395 // When starting on a ']' count it, so that we include the '['. |
7 | 2396 bn = ptr[col] == ']'; |
2397 | |
2398 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2399 * 2. Back up to start of identifier/text. |
7 | 2400 */ |
2401 if (has_mbyte) | |
2402 { | |
2403 /* Remember class of character under cursor. */ | |
2404 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
2405 this_class = mb_get_class((char_u *)"a"); | |
2406 else | |
2407 this_class = mb_get_class(ptr + col); | |
835 | 2408 while (col > 0 && this_class != 0) |
7 | 2409 { |
2410 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
2411 prev_class = mb_get_class(ptr + prevcol); | |
2412 if (this_class != prev_class | |
2413 && (i == 0 | |
2414 || prev_class == 0 | |
2415 || (find_type & FIND_IDENT)) | |
2416 && (!(find_type & FIND_EVAL) | |
2417 || prevcol == 0 | |
2418 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
2419 &bn, BACKWARD)) | |
2420 ) | |
2421 break; | |
2422 col = prevcol; | |
2423 } | |
2424 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2425 // 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
|
2426 // identifier, stop searching. |
7 | 2427 if (this_class > 2) |
2428 this_class = 2; | |
2429 if (!(find_type & FIND_STRING) || this_class == 2) | |
2430 break; | |
2431 } | |
2432 else | |
2433 { | |
2434 while (col > 0 | |
2435 && ((i == 0 | |
2436 ? 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
|
2437 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 2438 && (!(find_type & FIND_IDENT) |
2439 || !vim_iswordc(ptr[col - 1])))) | |
2440 || ((find_type & FIND_EVAL) | |
2441 && col > 1 | |
2442 && find_is_eval_item(ptr + col - 1, &col, | |
2443 &bn, BACKWARD)) | |
2444 )) | |
2445 --col; | |
2446 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2447 // 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
|
2448 // identifier, stop searching. |
7 | 2449 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) |
2450 break; | |
2451 } | |
2452 } | |
2453 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2454 if (ptr[col] == NUL || (i == 0 |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2455 && (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col])))) |
7 | 2456 { |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2457 // 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
|
2458 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
|
2459 { |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2460 if (find_type & FIND_STRING) |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2461 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
|
2462 else |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2463 emsg(_(e_noident)); |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2464 } |
7 | 2465 return 0; |
2466 } | |
2467 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
|
2468 *text = ptr; |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2469 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
|
2470 *textcol = col; |
7 | 2471 |
2472 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2473 * 3. Find the end if the identifier/text. |
7 | 2474 */ |
2475 bn = 0; | |
2476 startcol -= col; | |
2477 col = 0; | |
2478 if (has_mbyte) | |
2479 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
2480 // Search for point of changing multibyte character class. |
7 | 2481 this_class = mb_get_class(ptr); |
2482 while (ptr[col] != NUL | |
2483 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
2484 : mb_get_class(ptr + col) != 0) | |
2485 || ((find_type & FIND_EVAL) | |
2486 && col <= (int)startcol | |
2487 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
2488 )) | |
474 | 2489 col += (*mb_ptr2len)(ptr + col); |
7 | 2490 } |
2491 else | |
2492 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
|
2493 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 2494 || ((find_type & FIND_EVAL) |
2495 && col <= (int)startcol | |
2496 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
2497 ) | |
2498 ++col; | |
2499 | |
2500 return col; | |
2501 } | |
2502 | |
2503 /* | |
2504 * Prepare for redo of a normal command. | |
2505 */ | |
2506 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2507 prep_redo_cmd(cmdarg_T *cap) |
7 | 2508 { |
2509 prep_redo(cap->oap->regname, cap->count0, | |
2510 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
2511 } | |
2512 | |
2513 /* | |
2514 * Prepare for redo of any command. | |
2515 * Note that only the last argument can be a multi-byte char. | |
2516 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
2517 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2518 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2519 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2520 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2521 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2522 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2523 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2524 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2525 int cmd5) |
7 | 2526 { |
2527 ResetRedobuff(); | |
2528 if (regname != 0) /* yank from specified buffer */ | |
2529 { | |
2530 AppendCharToRedobuff('"'); | |
2531 AppendCharToRedobuff(regname); | |
2532 } | |
2533 if (num) | |
2534 AppendNumberToRedobuff(num); | |
2535 | |
2536 if (cmd1 != NUL) | |
2537 AppendCharToRedobuff(cmd1); | |
2538 if (cmd2 != NUL) | |
2539 AppendCharToRedobuff(cmd2); | |
2540 if (cmd3 != NUL) | |
2541 AppendCharToRedobuff(cmd3); | |
2542 if (cmd4 != NUL) | |
2543 AppendCharToRedobuff(cmd4); | |
2544 if (cmd5 != NUL) | |
2545 AppendCharToRedobuff(cmd5); | |
2546 } | |
2547 | |
2548 /* | |
2549 * check for operator active and clear it | |
2550 * | |
2551 * return TRUE if operator was active | |
2552 */ | |
2553 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2554 checkclearop(oparg_T *oap) |
7 | 2555 { |
2556 if (oap->op_type == OP_NOP) | |
2557 return FALSE; | |
2558 clearopbeep(oap); | |
2559 return TRUE; | |
2560 } | |
2561 | |
2562 /* | |
1131 | 2563 * Check for operator or Visual active. Clear active operator. |
7 | 2564 * |
1131 | 2565 * Return TRUE if operator or Visual was active. |
7 | 2566 */ |
2567 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2568 checkclearopq(oparg_T *oap) |
7 | 2569 { |
5735 | 2570 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 2571 return FALSE; |
2572 clearopbeep(oap); | |
2573 return TRUE; | |
2574 } | |
2575 | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
2576 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2577 clearop(oparg_T *oap) |
7 | 2578 { |
2579 oap->op_type = OP_NOP; | |
2580 oap->regname = 0; | |
2581 oap->motion_force = NUL; | |
2582 oap->use_reg_one = FALSE; | |
2583 } | |
2584 | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
2585 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2586 clearopbeep(oparg_T *oap) |
7 | 2587 { |
2588 clearop(oap); | |
2589 beep_flush(); | |
2590 } | |
2591 | |
2592 /* | |
2593 * Remove the shift modifier from a special key. | |
2594 */ | |
2595 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2596 unshift_special(cmdarg_T *cap) |
7 | 2597 { |
2598 switch (cap->cmdchar) | |
2599 { | |
2600 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
2601 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
2602 case K_S_UP: cap->cmdchar = K_UP; break; | |
2603 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
2604 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
2605 case K_S_END: cap->cmdchar = K_END; break; | |
2606 } | |
2607 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
2608 } | |
2609 | |
6979 | 2610 /* |
2611 * If the mode is currently displayed clear the command line or update the | |
2612 * command displayed. | |
2613 */ | |
2614 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2615 may_clear_cmdline(void) |
6979 | 2616 { |
2617 if (mode_displayed) | |
2618 clear_cmdline = TRUE; /* unshow visual mode later */ | |
2619 #ifdef FEAT_CMDL_INFO | |
2620 else | |
2621 clear_showcmd(); | |
2622 #endif | |
2623 } | |
2624 | |
7 | 2625 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
2626 /* | |
2627 * Routines for displaying a partly typed command | |
2628 */ | |
2629 | |
5735 | 2630 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 2631 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
2632 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
2633 static int showcmd_is_clear = TRUE; | |
2634 static int showcmd_visual = FALSE; | |
2635 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
2636 static void display_showcmd(void); |
7 | 2637 |
2638 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2639 clear_showcmd(void) |
7 | 2640 { |
2641 if (!p_sc) | |
2642 return; | |
2643 | |
2644 if (VIsual_active && !char_avail()) | |
2645 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2646 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 2647 long lines; |
2648 colnr_T leftcol, rightcol; | |
2649 linenr_T top, bot; | |
2650 | |
2651 /* Show the size of the Visual area. */ | |
1866 | 2652 if (cursor_bot) |
7 | 2653 { |
2654 top = VIsual.lnum; | |
2655 bot = curwin->w_cursor.lnum; | |
2656 } | |
2657 else | |
2658 { | |
2659 top = curwin->w_cursor.lnum; | |
2660 bot = VIsual.lnum; | |
2661 } | |
2662 # ifdef FEAT_FOLDING | |
2663 /* Include closed folds as a whole. */ | |
7009 | 2664 (void)hasFolding(top, &top, NULL); |
2665 (void)hasFolding(bot, NULL, &bot); | |
7 | 2666 # endif |
2667 lines = bot - top + 1; | |
2668 | |
2669 if (VIsual_mode == Ctrl_V) | |
2670 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
2671 # ifdef FEAT_LINEBREAK |
1866 | 2672 char_u *saved_sbr = p_sbr; |
2673 | |
2674 /* Make 'sbr' empty for a moment to get the correct size. */ | |
2675 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
2676 # endif |
7 | 2677 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
|
2678 # ifdef FEAT_LINEBREAK |
1866 | 2679 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
2680 # endif |
7 | 2681 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
2682 (long)(rightcol - leftcol + 1)); | |
2683 } | |
2684 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
2685 sprintf((char *)showcmd_buf, "%ld", lines); | |
2686 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2687 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2688 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
|
2689 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2690 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
|
2691 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
|
2692 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2693 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
|
2694 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2695 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
|
2696 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
|
2697 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2698 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2699 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2700 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
|
2701 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
|
2702 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2703 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
|
2704 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2705 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
|
2706 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
|
2707 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2708 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2709 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2710 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
|
2711 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2712 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2713 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2714 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2715 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2716 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
|
2717 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
|
2718 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2719 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
|
2720 } |
7 | 2721 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
2722 showcmd_visual = TRUE; | |
2723 } | |
2724 else | |
2725 { | |
2726 showcmd_buf[0] = NUL; | |
2727 showcmd_visual = FALSE; | |
2728 | |
2729 /* Don't actually display something if there is nothing to clear. */ | |
2730 if (showcmd_is_clear) | |
2731 return; | |
2732 } | |
2733 | |
2734 display_showcmd(); | |
2735 } | |
2736 | |
2737 /* | |
2738 * Add 'c' to string of shown command chars. | |
2739 * Return TRUE if output has been written (and setcursor() has been called). | |
2740 */ | |
2741 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2742 add_to_showcmd(int c) |
7 | 2743 { |
2744 char_u *p; | |
2745 int old_len; | |
2746 int extra_len; | |
2747 int overflow; | |
2748 #if defined(FEAT_MOUSE) | |
2749 int i; | |
2750 static int ignore[] = | |
2751 { | |
660 | 2752 # ifdef FEAT_GUI |
7 | 2753 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
2754 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 2755 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
2756 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
|
2757 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 2758 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
2759 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
|
2760 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 2761 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 2762 K_CURSORHOLD, |
7 | 2763 0 |
2764 }; | |
2765 #endif | |
2766 | |
641 | 2767 if (!p_sc || msg_silent != 0) |
7 | 2768 return FALSE; |
2769 | |
2770 if (showcmd_visual) | |
2771 { | |
2772 showcmd_buf[0] = NUL; | |
2773 showcmd_visual = FALSE; | |
2774 } | |
2775 | |
2776 #if defined(FEAT_MOUSE) | |
2777 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
2778 if (IS_SPECIAL(c)) | |
2779 for (i = 0; ignore[i] != 0; ++i) | |
2780 if (ignore[i] == c) | |
2781 return FALSE; | |
2782 #endif | |
2783 | |
2784 p = transchar(c); | |
5535 | 2785 if (*p == ' ') |
2786 STRCPY(p, "<20>"); | |
7 | 2787 old_len = (int)STRLEN(showcmd_buf); |
2788 extra_len = (int)STRLEN(p); | |
2789 overflow = old_len + extra_len - SHOWCMD_COLS; | |
2790 if (overflow > 0) | |
1362 | 2791 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
2792 old_len - overflow + 1); | |
7 | 2793 STRCAT(showcmd_buf, p); |
2794 | |
2795 if (char_avail()) | |
2796 return FALSE; | |
2797 | |
2798 display_showcmd(); | |
2799 | |
2800 return TRUE; | |
2801 } | |
2802 | |
2803 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2804 add_to_showcmd_c(int c) |
7 | 2805 { |
2806 if (!add_to_showcmd(c)) | |
2807 setcursor(); | |
2808 } | |
2809 | |
2810 /* | |
2811 * Delete 'len' characters from the end of the shown command. | |
2812 */ | |
2813 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2814 del_from_showcmd(int len) |
7 | 2815 { |
2816 int old_len; | |
2817 | |
2818 if (!p_sc) | |
2819 return; | |
2820 | |
2821 old_len = (int)STRLEN(showcmd_buf); | |
2822 if (len > old_len) | |
2823 len = old_len; | |
2824 showcmd_buf[old_len - len] = NUL; | |
2825 | |
2826 if (!char_avail()) | |
2827 display_showcmd(); | |
2828 } | |
2829 | |
2830 /* | |
2831 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
2832 * something and there is a partial mapping. | |
2833 */ | |
2834 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2835 push_showcmd(void) |
7 | 2836 { |
2837 if (p_sc) | |
2838 STRCPY(old_showcmd_buf, showcmd_buf); | |
2839 } | |
2840 | |
2841 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2842 pop_showcmd(void) |
7 | 2843 { |
2844 if (!p_sc) | |
2845 return; | |
2846 | |
2847 STRCPY(showcmd_buf, old_showcmd_buf); | |
2848 | |
2849 display_showcmd(); | |
2850 } | |
2851 | |
2852 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2853 display_showcmd(void) |
7 | 2854 { |
2855 int len; | |
2856 | |
2857 cursor_off(); | |
2858 | |
2859 len = (int)STRLEN(showcmd_buf); | |
2860 if (len == 0) | |
2861 showcmd_is_clear = TRUE; | |
2862 else | |
2863 { | |
2864 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
2865 showcmd_is_clear = FALSE; | |
2866 } | |
2867 | |
2868 /* | |
1188 | 2869 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
2870 * spaces | |
7 | 2871 */ |
2872 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
2873 | |
2874 setcursor(); /* put cursor back where it belongs */ | |
2875 } | |
2876 #endif | |
2877 | |
2878 /* | |
2879 * When "check" is FALSE, prepare for commands that scroll the window. | |
2880 * When "check" is TRUE, take care of scroll-binding after the window has | |
2881 * scrolled. Called from normal_cmd() and edit(). | |
2882 */ | |
2883 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2884 do_check_scrollbind(int check) |
7 | 2885 { |
2886 static win_T *old_curwin = NULL; | |
2887 static linenr_T old_topline = 0; | |
2888 #ifdef FEAT_DIFF | |
2889 static int old_topfill = 0; | |
2890 #endif | |
2891 static buf_T *old_buf = NULL; | |
2892 static colnr_T old_leftcol = 0; | |
2893 | |
2894 if (check && curwin->w_p_scb) | |
2895 { | |
2896 /* If a ":syncbind" command was just used, don't scroll, only reset | |
2897 * the values. */ | |
2898 if (did_syncbind) | |
2899 did_syncbind = FALSE; | |
2900 else if (curwin == old_curwin) | |
2901 { | |
2902 /* | |
2903 * Synchronize other windows, as necessary according to | |
2904 * 'scrollbind'. Don't do this after an ":edit" command, except | |
2905 * when 'diff' is set. | |
2906 */ | |
2907 if ((curwin->w_buffer == old_buf | |
2908 #ifdef FEAT_DIFF | |
2909 || curwin->w_p_diff | |
2910 #endif | |
2911 ) | |
2912 && (curwin->w_topline != old_topline | |
2913 #ifdef FEAT_DIFF | |
2914 || curwin->w_topfill != old_topfill | |
2915 #endif | |
2916 || curwin->w_leftcol != old_leftcol)) | |
2917 { | |
2918 check_scrollbind(curwin->w_topline - old_topline, | |
2919 (long)(curwin->w_leftcol - old_leftcol)); | |
2920 } | |
2921 } | |
2922 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
2923 { | |
2924 /* | |
2925 * When switching between windows, make sure that the relative | |
2926 * vertical offset is valid for the new window. The relative | |
2927 * offset is invalid whenever another 'scrollbind' window has | |
2928 * scrolled to a point that would force the current window to | |
2929 * scroll past the beginning or end of its buffer. When the | |
2930 * resync is performed, some of the other 'scrollbind' windows may | |
2931 * need to jump so that the current window's relative position is | |
2932 * visible on-screen. | |
2933 */ | |
2934 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
2935 } | |
2936 curwin->w_scbind_pos = curwin->w_topline; | |
2937 } | |
2938 | |
2939 old_curwin = curwin; | |
2940 old_topline = curwin->w_topline; | |
2941 #ifdef FEAT_DIFF | |
2942 old_topfill = curwin->w_topfill; | |
2943 #endif | |
2944 old_buf = curwin->w_buffer; | |
2945 old_leftcol = curwin->w_leftcol; | |
2946 } | |
2947 | |
2948 /* | |
2949 * Synchronize any windows that have "scrollbind" set, based on the | |
2950 * number of rows by which the current window has changed | |
2951 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
2952 */ | |
2953 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2954 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 2955 { |
2956 int want_ver; | |
2957 int want_hor; | |
2958 win_T *old_curwin = curwin; | |
2959 buf_T *old_curbuf = curbuf; | |
2960 int old_VIsual_select = VIsual_select; | |
2961 int old_VIsual_active = VIsual_active; | |
2962 colnr_T tgt_leftcol = curwin->w_leftcol; | |
2963 long topline; | |
2964 long y; | |
2965 | |
2966 /* | |
2967 * check 'scrollopt' string for vertical and horizontal scroll options | |
2968 */ | |
2969 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
2970 #ifdef FEAT_DIFF | |
2971 want_ver |= old_curwin->w_p_diff; | |
2972 #endif | |
2973 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
2974 | |
2975 /* | |
2976 * loop through the scrollbound windows and scroll accordingly | |
2977 */ | |
2978 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
2979 FOR_ALL_WINDOWS(curwin) |
7 | 2980 { |
2981 curbuf = curwin->w_buffer; | |
2982 /* skip original window and windows with 'noscrollbind' */ | |
2983 if (curwin != old_curwin && curwin->w_p_scb) | |
2984 { | |
2985 /* | |
2986 * do the vertical scroll | |
2987 */ | |
2988 if (want_ver) | |
2989 { | |
2990 #ifdef FEAT_DIFF | |
2991 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
2992 { | |
2993 diff_set_topline(old_curwin, curwin); | |
2994 } | |
2995 else | |
2996 #endif | |
2997 { | |
2998 curwin->w_scbind_pos += topline_diff; | |
2999 topline = curwin->w_scbind_pos; | |
3000 if (topline > curbuf->b_ml.ml_line_count) | |
3001 topline = curbuf->b_ml.ml_line_count; | |
3002 if (topline < 1) | |
3003 topline = 1; | |
3004 | |
3005 y = topline - curwin->w_topline; | |
3006 if (y > 0) | |
3007 scrollup(y, FALSE); | |
3008 else | |
3009 scrolldown(-y, FALSE); | |
3010 } | |
3011 | |
3012 redraw_later(VALID); | |
3013 cursor_correct(); | |
3014 curwin->w_redr_status = TRUE; | |
3015 } | |
3016 | |
3017 /* | |
3018 * do the horizontal scroll | |
3019 */ | |
3020 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
3021 { | |
3022 curwin->w_leftcol = tgt_leftcol; | |
3023 leftcol_changed(); | |
3024 } | |
3025 } | |
3026 } | |
3027 | |
3028 /* | |
3029 * reset current-window | |
3030 */ | |
3031 VIsual_select = old_VIsual_select; | |
3032 VIsual_active = old_VIsual_active; | |
3033 curwin = old_curwin; | |
3034 curbuf = old_curbuf; | |
3035 } | |
3036 | |
3037 /* | |
3038 * Command character that's ignored. | |
3039 * 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
|
3040 * xon/xoff. |
7 | 3041 */ |
3042 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3043 nv_ignore(cmdarg_T *cap) |
7 | 3044 { |
226 | 3045 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 3046 } |
3047 | |
3048 /* | |
620 | 3049 * Command character that doesn't do anything, but unlike nv_ignore() does |
3050 * start edit(). Used for "startinsert" executed while starting up. | |
3051 */ | |
3052 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3053 nv_nop(cmdarg_T *cap UNUSED) |
620 | 3054 { |
3055 } | |
3056 | |
3057 /* | |
7 | 3058 * Command character doesn't exist. |
3059 */ | |
3060 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3061 nv_error(cmdarg_T *cap) |
7 | 3062 { |
3063 clearopbeep(cap->oap); | |
3064 } | |
3065 | |
3066 /* | |
3067 * <Help> and <F1> commands. | |
3068 */ | |
3069 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3070 nv_help(cmdarg_T *cap) |
7 | 3071 { |
3072 if (!checkclearopq(cap->oap)) | |
3073 ex_help(NULL); | |
3074 } | |
3075 | |
3076 /* | |
3077 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
3078 */ | |
3079 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3080 nv_addsub(cmdarg_T *cap) |
7 | 3081 { |
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
|
3082 #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
|
3083 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
|
3084 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
|
3085 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
|
3086 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
3087 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
|
3088 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
3089 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
3090 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
|
3091 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
|
3092 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
3093 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
3094 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
3095 nv_operator(cap); |
6868 | 3096 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
3097 clearop(cap->oap); |
7 | 3098 } |
3099 | |
3100 /* | |
3101 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
3102 */ | |
3103 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3104 nv_page(cmdarg_T *cap) |
7 | 3105 { |
3106 if (!checkclearop(cap->oap)) | |
819 | 3107 { |
3108 if (mod_mask & MOD_MASK_CTRL) | |
3109 { | |
3110 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
3111 if (cap->arg == BACKWARD) | |
3112 goto_tabpage(-(int)cap->count1); | |
3113 else | |
3114 goto_tabpage((int)cap->count0); | |
3115 } | |
3116 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3117 (void)onepage(cap->arg, cap->count1); |
819 | 3118 } |
7 | 3119 } |
3120 | |
3121 /* | |
3122 * Implementation of "gd" and "gD" command. | |
3123 */ | |
3124 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3125 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3126 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3127 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3128 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 3129 { |
3130 int len; | |
503 | 3131 char_u *ptr; |
3132 | |
3133 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
|
3134 || 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
|
3135 == FAIL) |
503 | 3136 clearopbeep(oap); |
3137 #ifdef FEAT_FOLDING | |
3138 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
3139 foldOpenCursor(); | |
3140 #endif | |
3141 } | |
3142 | |
3143 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3144 * 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
|
3145 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3146 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3147 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3148 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
|
3149 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3150 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3151 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3152 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3153 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3154 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3155 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
|
3156 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3157 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3158 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3159 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3160 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3161 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3162 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
|
3163 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3164 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3165 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3166 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3167 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3168 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3169 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3170 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3171 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3172 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3173 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3174 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3175 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3176 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3177 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3178 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3179 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3180 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3181 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3182 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3183 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3184 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3185 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3186 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3187 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3188 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3189 /* |
523 | 3190 * Search for variable declaration of "ptr[len]". |
3191 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
3192 * current file ("gD"). | |
3193 * When "thisblock" is TRUE check the {} block scope. | |
503 | 3194 * Return FAIL when not found. |
3195 */ | |
3196 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3197 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3198 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3199 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3200 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3201 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
3202 int flags_arg) /* flags passed to searchit() */ |
503 | 3203 { |
7 | 3204 char_u *pat; |
3205 pos_T old_pos; | |
503 | 3206 pos_T par_pos; |
3207 pos_T found_pos; | |
7 | 3208 int t; |
3209 int save_p_ws; | |
3210 int save_p_scs; | |
503 | 3211 int retval = OK; |
944 | 3212 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
3213 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3214 int valid; |
503 | 3215 |
3216 if ((pat = alloc(len + 7)) == NULL) | |
3217 return FAIL; | |
268 | 3218 |
3219 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
3220 * and "~" causes trouble. */ | |
3221 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
3222 len, ptr); | |
7 | 3223 old_pos = curwin->w_cursor; |
3224 save_p_ws = p_ws; | |
3225 save_p_scs = p_scs; | |
3226 p_ws = FALSE; /* don't wrap around end of file now */ | |
3227 p_scs = FALSE; /* don't switch ignorecase off now */ | |
3228 | |
3229 /* | |
3230 * With "gD" go to line 1. | |
3231 * With "gd" Search back for the start of the current function, then go | |
3232 * back until a blank line. If this fails go to line 1. | |
3233 */ | |
944 | 3234 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 3235 { |
3236 setpcmark(); /* Set in findpar() otherwise */ | |
3237 curwin->w_cursor.lnum = 1; | |
539 | 3238 par_pos = curwin->w_cursor; |
7 | 3239 } |
3240 else | |
3241 { | |
539 | 3242 par_pos = curwin->w_cursor; |
7 | 3243 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
3244 --curwin->w_cursor.lnum; | |
3245 } | |
3246 curwin->w_cursor.col = 0; | |
3247 | |
3248 /* 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
|
3249 CLEAR_POS(&found_pos); |
503 | 3250 for (;;) |
3251 { | |
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
|
3252 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
|
3253 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 3254 if (curwin->w_cursor.lnum >= old_pos.lnum) |
3255 t = FAIL; /* match after start is failure too */ | |
523 | 3256 |
718 | 3257 if (thisblock && t != FAIL) |
523 | 3258 { |
3259 pos_T *pos; | |
3260 | |
3261 /* Check that the block the match is in doesn't end before the | |
3262 * position where we started the search from. */ | |
3263 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
3264 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
3265 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3266 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3267 /* 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
|
3268 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3269 curwin->w_cursor = *pos; |
523 | 3270 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3271 } |
523 | 3272 } |
3273 | |
503 | 3274 if (t == FAIL) |
3275 { | |
3276 /* If we previously found a valid position, use it. */ | |
3277 if (found_pos.lnum != 0) | |
3278 { | |
3279 curwin->w_cursor = found_pos; | |
3280 t = OK; | |
3281 } | |
3282 break; | |
3283 } | |
3562 | 3284 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 3285 { |
3286 /* Ignore this line, continue at start of next line. */ | |
3287 ++curwin->w_cursor.lnum; | |
3288 curwin->w_cursor.col = 0; | |
3289 continue; | |
3290 } | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3291 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
|
3292 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3293 /* 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
|
3294 * 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
|
3295 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3296 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3297 curwin->w_cursor = found_pos; |
503 | 3298 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3299 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3300 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3301 /* 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
|
3302 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3303 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3304 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 3305 { |
3306 /* If we previously found a valid position, use it. */ | |
3307 if (found_pos.lnum != 0) | |
3308 curwin->w_cursor = found_pos; | |
3309 break; | |
3310 } | |
3311 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3312 /* 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
|
3313 * 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
|
3314 * 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
|
3315 if (!valid) |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3316 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3317 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3318 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
3319 /* 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
|
3320 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
3321 searchflags &= ~SEARCH_START; |
503 | 3322 } |
3323 | |
3324 if (t == FAIL) | |
3325 { | |
3326 retval = FAIL; | |
7 | 3327 curwin->w_cursor = old_pos; |
3328 } | |
3329 else | |
3330 { | |
3331 curwin->w_set_curswant = TRUE; | |
3332 /* "n" searches forward now */ | |
3333 reset_search_dir(); | |
3334 } | |
3335 | |
3336 vim_free(pat); | |
3337 p_ws = save_p_ws; | |
3338 p_scs = save_p_scs; | |
503 | 3339 |
3340 return retval; | |
7 | 3341 } |
3342 | |
3343 /* | |
3344 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
3345 * lines rather than lines in the file. | |
3346 * 'dist' must be positive. | |
3347 * | |
3348 * Return OK if able to move cursor, FAIL otherwise. | |
3349 */ | |
3350 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3351 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 3352 { |
3353 int linelen = linetabsize(ml_get_curline()); | |
3354 int retval = OK; | |
3355 int atend = FALSE; | |
3356 int n; | |
3357 int col_off1; /* margin offset for first screen line */ | |
3358 int col_off2; /* margin offset for wrapped screen line */ | |
3359 int width1; /* text width for first screen line */ | |
3360 int width2; /* test width for wrapped screen line */ | |
3361 | |
3362 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
3363 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 3364 |
3365 col_off1 = curwin_col_off(); | |
3366 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
|
3367 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
|
3368 width2 = curwin->w_width - col_off2; |
6559 | 3369 if (width2 == 0) |
3370 width2 = 1; /* avoid divide by zero */ | |
7 | 3371 |
3372 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
3373 { |
7 | 3374 /* |
3375 * Instead of sticking at the last character of the buffer line we | |
3376 * try to stick in the last column of the screen. | |
3377 */ | |
3378 if (curwin->w_curswant == MAXCOL) | |
3379 { | |
3380 atend = TRUE; | |
3381 validate_virtcol(); | |
3382 if (width1 <= 0) | |
3383 curwin->w_curswant = 0; | |
3384 else | |
3385 { | |
3386 curwin->w_curswant = width1 - 1; | |
3387 if (curwin->w_virtcol > curwin->w_curswant) | |
3388 curwin->w_curswant += ((curwin->w_virtcol | |
3389 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
3390 } | |
3391 } | |
3392 else | |
3393 { | |
3394 if (linelen > width1) | |
3395 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
3396 else | |
3397 n = width1; | |
3398 if (curwin->w_curswant > (colnr_T)n + 1) | |
3399 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
3400 * width2; | |
3401 } | |
3402 | |
3403 while (dist--) | |
3404 { | |
3405 if (dir == BACKWARD) | |
3406 { | |
18154
5e10ee16f4b4
patch 8.1.2072: "gk" moves to start of line instead of upwards
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
3407 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
|
3408 // move back within line |
7 | 3409 curwin->w_curswant -= width2; |
3410 else | |
3411 { | |
3412 /* to previous line */ | |
3413 if (curwin->w_cursor.lnum == 1) | |
3414 { | |
3415 retval = FAIL; | |
3416 break; | |
3417 } | |
3418 --curwin->w_cursor.lnum; | |
3419 #ifdef FEAT_FOLDING | |
3420 /* Move to the start of a closed fold. Don't do that when | |
3421 * 'foldopen' contains "all": it will open in a moment. */ | |
3422 if (!(fdo_flags & FDO_ALL)) | |
3423 (void)hasFolding(curwin->w_cursor.lnum, | |
3424 &curwin->w_cursor.lnum, NULL); | |
3425 #endif | |
3426 linelen = linetabsize(ml_get_curline()); | |
3427 if (linelen > width1) | |
3428 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
3429 + 1) * width2; | |
3430 } | |
3431 } | |
3432 else /* dir == FORWARD */ | |
3433 { | |
3434 if (linelen > width1) | |
3435 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
3436 else | |
3437 n = width1; | |
3438 if (curwin->w_curswant + width2 < (colnr_T)n) | |
3439 /* move forward within line */ | |
3440 curwin->w_curswant += width2; | |
3441 else | |
3442 { | |
3443 /* to next line */ | |
3444 #ifdef FEAT_FOLDING | |
3445 /* Move to the end of a closed fold. */ | |
3446 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
3447 &curwin->w_cursor.lnum); | |
3448 #endif | |
3449 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
3450 { | |
3451 retval = FAIL; | |
3452 break; | |
3453 } | |
3454 curwin->w_cursor.lnum++; | |
3455 curwin->w_curswant %= width2; | |
2911 | 3456 linelen = linetabsize(ml_get_curline()); |
7 | 3457 } |
3458 } | |
3459 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
3460 } |
7 | 3461 |
5600 | 3462 if (virtual_active() && atend) |
3463 coladvance(MAXCOL); | |
3464 else | |
3465 coladvance(curwin->w_curswant); | |
7 | 3466 |
3467 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
3468 { | |
6178 | 3469 colnr_T virtcol; |
3470 | |
7 | 3471 /* |
3472 * Check for landing on a character that got split at the end of the | |
3473 * last line. We want to advance a screenline, not end up in the same | |
3474 * screenline or move two screenlines. | |
3475 */ | |
3476 validate_virtcol(); | |
6178 | 3477 virtcol = curwin->w_virtcol; |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3478 #if defined(FEAT_LINEBREAK) |
6178 | 3479 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
3480 virtcol -= vim_strsize(p_sbr); | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3481 #endif |
6178 | 3482 |
3483 if (virtcol > curwin->w_curswant | |
7 | 3484 && (curwin->w_curswant < (colnr_T)width1 |
3485 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
3486 : ((curwin->w_curswant - width1) % width2 | |
3487 > (colnr_T)width2 / 2))) | |
3488 --curwin->w_cursor.col; | |
3489 } | |
3490 | |
3491 if (atend) | |
3492 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
3493 | |
3494 return retval; | |
3495 } | |
3496 | |
3497 /* | |
3498 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
3499 * cap->arg must be TRUE for CTRL-E. | |
3500 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
3501 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3502 nv_scroll_line(cmdarg_T *cap) |
7 | 3503 { |
3504 if (!checkclearop(cap->oap)) | |
3505 scroll_redraw(cap->arg, cap->count1); | |
3506 } | |
3507 | |
3508 /* | |
3509 * Scroll "count" lines up or down, and redraw. | |
3510 */ | |
3511 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3512 scroll_redraw(int up, long count) |
7 | 3513 { |
3514 linenr_T prev_topline = curwin->w_topline; | |
3515 #ifdef FEAT_DIFF | |
3516 int prev_topfill = curwin->w_topfill; | |
3517 #endif | |
3518 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
3519 | |
3520 if (up) | |
3521 scrollup(count, TRUE); | |
3522 else | |
3523 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
|
3524 if (get_scrolloff_value()) |
7 | 3525 { |
3526 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
3527 * valid, otherwise the screen jumps back at the end of the file. */ | |
3528 cursor_correct(); | |
3529 check_cursor_moved(curwin); | |
3530 curwin->w_valid |= VALID_TOPLINE; | |
3531 | |
3532 /* If moved back to where we were, at least move the cursor, otherwise | |
3533 * we get stuck at one position. Don't move the cursor up if the | |
3534 * first line of the buffer is already on the screen */ | |
3535 while (curwin->w_topline == prev_topline | |
3536 #ifdef FEAT_DIFF | |
3537 && curwin->w_topfill == prev_topfill | |
3538 #endif | |
3539 ) | |
3540 { | |
3541 if (up) | |
3542 { | |
3543 if (curwin->w_cursor.lnum > prev_lnum | |
3544 || cursor_down(1L, FALSE) == FAIL) | |
3545 break; | |
3546 } | |
3547 else | |
3548 { | |
3549 if (curwin->w_cursor.lnum < prev_lnum | |
3550 || prev_topline == 1L | |
3551 || cursor_up(1L, FALSE) == FAIL) | |
3552 break; | |
3553 } | |
3554 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
3555 * end of the file. */ | |
3556 check_cursor_moved(curwin); | |
3557 curwin->w_valid |= VALID_TOPLINE; | |
3558 } | |
3559 } | |
3560 if (curwin->w_cursor.lnum != prev_lnum) | |
3561 coladvance(curwin->w_curswant); | |
3562 redraw_later(VALID); | |
3563 } | |
3564 | |
3565 /* | |
3566 * Commands that start with "z". | |
3567 */ | |
3568 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3569 nv_zet(cmdarg_T *cap) |
7 | 3570 { |
3571 long n; | |
3572 colnr_T col; | |
3573 int nchar = cap->nchar; | |
3574 #ifdef FEAT_FOLDING | |
3575 long old_fdl = curwin->w_p_fdl; | |
3576 int old_fen = curwin->w_p_fen; | |
3577 #endif | |
737 | 3578 #ifdef FEAT_SPELL |
710 | 3579 int undo = FALSE; |
3580 #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
|
3581 long siso = get_sidescrolloff_value(); |
7 | 3582 |
3583 if (VIM_ISDIGIT(nchar)) | |
3584 { | |
3585 /* | |
3586 * "z123{nchar}": edit the count before obtaining {nchar} | |
3587 */ | |
3588 if (checkclearop(cap->oap)) | |
3589 return; | |
3590 n = nchar - '0'; | |
3591 for (;;) | |
3592 { | |
3593 #ifdef USE_ON_FLY_SCROLL | |
3594 dont_scroll = TRUE; /* disallow scrolling here */ | |
3595 #endif | |
3596 ++no_mapping; | |
3597 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 3598 nchar = plain_vgetc(); |
7 | 3599 LANGMAP_ADJUST(nchar, TRUE); |
3600 --no_mapping; | |
3601 --allow_keys; | |
3602 #ifdef FEAT_CMDL_INFO | |
3603 (void)add_to_showcmd(nchar); | |
3604 #endif | |
3605 if (nchar == K_DEL || nchar == K_KDEL) | |
3606 n /= 10; | |
3607 else if (VIM_ISDIGIT(nchar)) | |
3608 n = n * 10 + (nchar - '0'); | |
3609 else if (nchar == CAR) | |
3610 { | |
3611 #ifdef FEAT_GUI | |
3612 need_mouse_correct = TRUE; | |
3613 #endif | |
3614 win_setheight((int)n); | |
3615 break; | |
3616 } | |
3617 else if (nchar == 'l' | |
3618 || nchar == 'h' | |
3619 || nchar == K_LEFT | |
229 | 3620 || nchar == K_RIGHT) |
7 | 3621 { |
3622 cap->count1 = n ? n * cap->count1 : cap->count1; | |
3623 goto dozet; | |
3624 } | |
3625 else | |
3626 { | |
3627 clearopbeep(cap->oap); | |
3628 break; | |
3629 } | |
3630 } | |
3631 cap->oap->op_type = OP_NOP; | |
3632 return; | |
3633 } | |
3634 | |
3635 dozet: | |
3636 if ( | |
3637 #ifdef FEAT_FOLDING | |
3638 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
3639 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
3640 * commands. */ | |
3641 cap->nchar != 'f' && cap->nchar != 'F' | |
3642 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
3643 && cap->nchar != 'j' && cap->nchar != 'k' | |
3644 && | |
3645 #endif | |
3646 checkclearop(cap->oap)) | |
3647 return; | |
3648 | |
3649 /* | |
3650 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
3651 * If line number given, set cursor. | |
3652 */ | |
3653 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
3654 && cap->count0 | |
3655 && cap->count0 != curwin->w_cursor.lnum) | |
3656 { | |
3657 setpcmark(); | |
3658 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
3659 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3660 else | |
3661 curwin->w_cursor.lnum = cap->count0; | |
22 | 3662 check_cursor_col(); |
7 | 3663 } |
3664 | |
3665 switch (nchar) | |
3666 { | |
3667 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
3668 case '+': | |
3669 if (cap->count0 == 0) | |
3670 { | |
3671 /* No count given: put cursor at the line below screen */ | |
3672 validate_botline(); /* make sure w_botline is valid */ | |
3673 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
3674 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3675 else | |
3676 curwin->w_cursor.lnum = curwin->w_botline; | |
3677 } | |
3678 /* FALLTHROUGH */ | |
3679 case NL: | |
3680 case CAR: | |
3681 case K_KENTER: | |
3682 beginline(BL_WHITE | BL_FIX); | |
3683 /* FALLTHROUGH */ | |
3684 | |
3685 case 't': scroll_cursor_top(0, TRUE); | |
3686 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
3687 set_fraction(curwin); |
7 | 3688 break; |
3689 | |
3690 /* "z." and "zz": put cursor in middle of screen */ | |
3691 case '.': beginline(BL_WHITE | BL_FIX); | |
3692 /* FALLTHROUGH */ | |
3693 | |
3694 case 'z': scroll_cursor_halfway(TRUE); | |
3695 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
3696 set_fraction(curwin); |
7 | 3697 break; |
3698 | |
3699 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
3700 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
3701 * when <count> is at bottom of window, and puts that one at | |
3702 * bottom of window. */ | |
3703 if (cap->count0 != 0) | |
3704 { | |
3705 scroll_cursor_bot(0, TRUE); | |
3706 curwin->w_cursor.lnum = curwin->w_topline; | |
3707 } | |
3708 else if (curwin->w_topline == 1) | |
3709 curwin->w_cursor.lnum = 1; | |
3710 else | |
3711 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
3712 /* FALLTHROUGH */ | |
3713 case '-': | |
3714 beginline(BL_WHITE | BL_FIX); | |
3715 /* FALLTHROUGH */ | |
3716 | |
3717 case 'b': scroll_cursor_bot(0, TRUE); | |
3718 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
3719 set_fraction(curwin); |
7 | 3720 break; |
3721 | |
3722 /* "zH" - scroll screen right half-page */ | |
3723 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
3724 cap->count1 *= curwin->w_width / 2; |
7 | 3725 /* FALLTHROUGH */ |
3726 | |
3727 /* "zh" - scroll screen to the right */ | |
3728 case 'h': | |
3729 case K_LEFT: | |
3730 if (!curwin->w_p_wrap) | |
3731 { | |
3732 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
3733 curwin->w_leftcol = 0; | |
3734 else | |
3735 curwin->w_leftcol -= (colnr_T)cap->count1; | |
3736 leftcol_changed(); | |
3737 } | |
3738 break; | |
3739 | |
3740 /* "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
|
3741 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 3742 /* FALLTHROUGH */ |
3743 | |
3744 /* "zl" - scroll screen to the left */ | |
3745 case 'l': | |
3746 case K_RIGHT: | |
3747 if (!curwin->w_p_wrap) | |
3748 { | |
3749 /* scroll the window left */ | |
3750 curwin->w_leftcol += (colnr_T)cap->count1; | |
3751 leftcol_changed(); | |
3752 } | |
3753 break; | |
3754 | |
3755 /* "zs" - scroll screen, cursor at the start */ | |
3756 case 's': if (!curwin->w_p_wrap) | |
3757 { | |
3758 #ifdef FEAT_FOLDING | |
3759 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
3760 col = 0; /* like the cursor is in col 0 */ | |
3761 else | |
3762 #endif | |
3763 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
|
3764 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
|
3765 col -= siso; |
7 | 3766 else |
3767 col = 0; | |
3768 if (curwin->w_leftcol != col) | |
3769 { | |
3770 curwin->w_leftcol = col; | |
3771 redraw_later(NOT_VALID); | |
3772 } | |
3773 } | |
3774 break; | |
3775 | |
3776 /* "ze" - scroll screen, cursor at the end */ | |
3777 case 'e': if (!curwin->w_p_wrap) | |
3778 { | |
3779 #ifdef FEAT_FOLDING | |
3780 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
3781 col = 0; /* like the cursor is in col 0 */ | |
3782 else | |
3783 #endif | |
3784 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
|
3785 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
|
3786 if ((long)col + siso < n) |
7 | 3787 col = 0; |
3788 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
|
3789 col = col + siso - n + 1; |
7 | 3790 if (curwin->w_leftcol != col) |
3791 { | |
3792 curwin->w_leftcol = col; | |
3793 redraw_later(NOT_VALID); | |
3794 } | |
3795 } | |
3796 break; | |
3797 | |
3798 #ifdef FEAT_FOLDING | |
3799 /* "zF": create fold command */ | |
3800 /* "zf": create fold operator */ | |
3801 case 'F': | |
3802 case 'f': if (foldManualAllowed(TRUE)) | |
3803 { | |
3804 cap->nchar = 'f'; | |
3805 nv_operator(cap); | |
3806 curwin->w_p_fen = TRUE; | |
3807 | |
3808 /* "zF" is like "zfzf" */ | |
3809 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
3810 { | |
3811 nv_operator(cap); | |
3812 finish_op = TRUE; | |
3813 } | |
3814 } | |
3815 else | |
3816 clearopbeep(cap->oap); | |
3817 break; | |
3818 | |
3819 /* "zd": delete fold at cursor */ | |
3820 /* "zD": delete fold at cursor recursively */ | |
3821 case 'd': | |
3822 case 'D': if (foldManualAllowed(FALSE)) | |
3823 { | |
3824 if (VIsual_active) | |
3825 nv_operator(cap); | |
3826 else | |
3827 deleteFold(curwin->w_cursor.lnum, | |
3828 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
3829 } | |
3830 break; | |
3831 | |
4352 | 3832 /* "zE": erase all folds */ |
7 | 3833 case 'E': if (foldmethodIsManual(curwin)) |
3834 { | |
3835 clearFolding(curwin); | |
3836 changed_window_setting(); | |
3837 } | |
3838 else if (foldmethodIsMarker(curwin)) | |
3839 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
3840 TRUE, FALSE); | |
3841 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3842 emsg(_("E352: Cannot erase folds with current 'foldmethod'")); |
7 | 3843 break; |
3844 | |
3845 /* "zn": fold none: reset 'foldenable' */ | |
3846 case 'n': curwin->w_p_fen = FALSE; | |
3847 break; | |
3848 | |
3849 /* "zN": fold Normal: set 'foldenable' */ | |
3850 case 'N': curwin->w_p_fen = TRUE; | |
3851 break; | |
3852 | |
3853 /* "zi": invert folding: toggle 'foldenable' */ | |
3854 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
3855 break; | |
3856 | |
3857 /* "za": open closed fold or close open fold at cursor */ | |
3858 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
3859 openFold(curwin->w_cursor.lnum, cap->count1); | |
3860 else | |
3861 { | |
3862 closeFold(curwin->w_cursor.lnum, cap->count1); | |
3863 curwin->w_p_fen = TRUE; | |
3864 } | |
3865 break; | |
3866 | |
3867 /* "zA": open fold at cursor recursively */ | |
3868 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
3869 openFoldRecurse(curwin->w_cursor.lnum); | |
3870 else | |
3871 { | |
3872 closeFoldRecurse(curwin->w_cursor.lnum); | |
3873 curwin->w_p_fen = TRUE; | |
3874 } | |
3875 break; | |
3876 | |
3877 /* "zo": open fold at cursor or Visual area */ | |
3878 case 'o': if (VIsual_active) | |
3879 nv_operator(cap); | |
3880 else | |
3881 openFold(curwin->w_cursor.lnum, cap->count1); | |
3882 break; | |
3883 | |
3884 /* "zO": open fold recursively */ | |
3885 case 'O': if (VIsual_active) | |
3886 nv_operator(cap); | |
3887 else | |
3888 openFoldRecurse(curwin->w_cursor.lnum); | |
3889 break; | |
3890 | |
3891 /* "zc": close fold at cursor or Visual area */ | |
3892 case 'c': if (VIsual_active) | |
3893 nv_operator(cap); | |
3894 else | |
3895 closeFold(curwin->w_cursor.lnum, cap->count1); | |
3896 curwin->w_p_fen = TRUE; | |
3897 break; | |
3898 | |
3899 /* "zC": close fold recursively */ | |
3900 case 'C': if (VIsual_active) | |
3901 nv_operator(cap); | |
3902 else | |
3903 closeFoldRecurse(curwin->w_cursor.lnum); | |
3904 curwin->w_p_fen = TRUE; | |
3905 break; | |
3906 | |
3907 /* "zv": open folds at the cursor */ | |
3908 case 'v': foldOpenCursor(); | |
3909 break; | |
3910 | |
3911 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
3912 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3913 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3914 newFoldLevel(); /* update right now */ |
7 | 3915 foldOpenCursor(); |
3916 break; | |
3917 | |
3918 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
3919 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3920 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
3921 old_fdl = -1; /* force an update */ |
7 | 3922 break; |
3923 | |
3924 /* "zm": fold more */ | |
3925 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 3926 { |
3927 curwin->w_p_fdl -= cap->count1; | |
3928 if (curwin->w_p_fdl < 0) | |
3929 curwin->w_p_fdl = 0; | |
3930 } | |
7 | 3931 old_fdl = -1; /* force an update */ |
3932 curwin->w_p_fen = TRUE; | |
3933 break; | |
3934 | |
3935 /* "zM": close all folds */ | |
3936 case 'M': curwin->w_p_fdl = 0; | |
3937 old_fdl = -1; /* force an update */ | |
3938 curwin->w_p_fen = TRUE; | |
3939 break; | |
3940 | |
3941 /* "zr": reduce folding */ | |
6725 | 3942 case 'r': curwin->w_p_fdl += cap->count1; |
3943 { | |
3944 int d = getDeepestNesting(); | |
3945 | |
3946 if (curwin->w_p_fdl >= d) | |
3947 curwin->w_p_fdl = d; | |
3948 } | |
7 | 3949 break; |
3950 | |
3951 /* "zR": open all folds */ | |
3952 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
3953 old_fdl = -1; /* force an update */ | |
3954 break; | |
3955 | |
3956 case 'j': /* "zj" move to next fold downwards */ | |
3957 case 'k': /* "zk" move to next fold upwards */ | |
3958 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
3959 cap->count1) == FAIL) | |
3960 clearopbeep(cap->oap); | |
3961 break; | |
3962 | |
3963 #endif /* FEAT_FOLDING */ | |
3964 | |
737 | 3965 #ifdef FEAT_SPELL |
710 | 3966 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
3967 ++no_mapping; | |
3968 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 3969 nchar = plain_vgetc(); |
710 | 3970 LANGMAP_ADJUST(nchar, TRUE); |
3971 --no_mapping; | |
3972 --allow_keys; | |
3973 #ifdef FEAT_CMDL_INFO | |
3974 (void)add_to_showcmd(nchar); | |
3975 #endif | |
3976 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
3977 { | |
3978 clearopbeep(cap->oap); | |
3979 break; | |
3980 } | |
3981 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
3982 /* FALLTHROUGH */ |
710 | 3983 |
310 | 3984 case 'g': /* "zg": add good word to word list */ |
3985 case 'w': /* "zw": add wrong word to word list */ | |
381 | 3986 case 'G': /* "zG": add good word to temp word list */ |
3987 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 3988 { |
3989 char_u *ptr = NULL; | |
3990 int len; | |
3991 | |
3992 if (checkclearop(cap->oap)) | |
3993 break; | |
3994 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
3995 == FAIL) | |
3996 return; | |
501 | 3997 if (ptr == NULL) |
3998 { | |
3999 pos_T pos = curwin->w_cursor; | |
4000 | |
5374 | 4001 /* Find bad word under the cursor. When 'spell' is |
4002 * off this fails and find_ident_under_cursor() is | |
4003 * used below. */ | |
4004 emsg_off++; | |
534 | 4005 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 4006 emsg_off--; |
501 | 4007 if (len != 0 && curwin->w_cursor.col <= pos.col) |
4008 ptr = ml_get_pos(&curwin->w_cursor); | |
4009 curwin->w_cursor = pos; | |
4010 } | |
4011 | |
310 | 4012 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
4013 FIND_IDENT)) == 0) | |
4014 return; | |
17682
3dbff5d37520
patch 8.1.1838: there is :spellwrong and :spellgood but not :spellrare
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
4015 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
|
4016 ? SPELL_ADD_BAD : SPELL_ADD_GOOD, |
710 | 4017 (nchar == 'G' || nchar == 'W') |
4018 ? 0 : (int)cap->count1, | |
4019 undo); | |
310 | 4020 } |
316 | 4021 break; |
323 | 4022 |
584 | 4023 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 4024 if (!checkclearop(cap->oap)) |
485 | 4025 spell_suggest((int)cap->count0); |
323 | 4026 break; |
310 | 4027 #endif |
4028 | |
7 | 4029 default: clearopbeep(cap->oap); |
4030 } | |
4031 | |
4032 #ifdef FEAT_FOLDING | |
4033 /* Redraw when 'foldenable' changed */ | |
4034 if (old_fen != curwin->w_p_fen) | |
4035 { | |
4036 # ifdef FEAT_DIFF | |
4037 win_T *wp; | |
4038 | |
4039 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
4040 { | |
4041 /* Adjust 'foldenable' in diff-synced windows. */ | |
4042 FOR_ALL_WINDOWS(wp) | |
4043 { | |
4044 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
4045 { | |
4046 wp->w_p_fen = curwin->w_p_fen; | |
4047 changed_window_setting_win(wp); | |
4048 } | |
4049 } | |
4050 } | |
4051 # endif | |
4052 changed_window_setting(); | |
4053 } | |
4054 | |
4055 /* Redraw when 'foldlevel' changed. */ | |
4056 if (old_fdl != curwin->w_p_fdl) | |
4057 newFoldLevel(); | |
4058 #endif | |
4059 } | |
4060 | |
4061 #ifdef FEAT_GUI | |
4062 /* | |
4063 * Vertical scrollbar movement. | |
4064 */ | |
4065 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4066 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 4067 { |
4068 if (cap->oap->op_type != OP_NOP) | |
4069 clearopbeep(cap->oap); | |
4070 | |
4071 /* Even if an operator was pending, we still want to scroll */ | |
4072 gui_do_scroll(); | |
4073 } | |
4074 | |
4075 /* | |
4076 * Horizontal scrollbar movement. | |
4077 */ | |
4078 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4079 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 4080 { |
4081 if (cap->oap->op_type != OP_NOP) | |
4082 clearopbeep(cap->oap); | |
4083 | |
4084 /* 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
|
4085 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 4086 } |
4087 #endif | |
4088 | |
690 | 4089 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 4090 /* |
4091 * Click in GUI tab. | |
4092 */ | |
4093 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4094 nv_tabline(cmdarg_T *cap) |
685 | 4095 { |
4096 if (cap->oap->op_type != OP_NOP) | |
4097 clearopbeep(cap->oap); | |
4098 | |
4099 /* Even if an operator was pending, we still want to jump tabs. */ | |
4100 goto_tabpage(current_tab); | |
4101 } | |
686 | 4102 |
4103 /* | |
4104 * Selected item in tab line menu. | |
4105 */ | |
4106 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4107 nv_tabmenu(cmdarg_T *cap) |
686 | 4108 { |
4109 if (cap->oap->op_type != OP_NOP) | |
4110 clearopbeep(cap->oap); | |
4111 | |
4112 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 4113 handle_tabmenu(); |
4114 } | |
4115 | |
4116 /* | |
4117 * Handle selecting an item of the GUI tab line menu. | |
4118 * Used in Normal and Insert mode. | |
4119 */ | |
4120 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4121 handle_tabmenu(void) |
690 | 4122 { |
686 | 4123 switch (current_tabmenu) |
4124 { | |
4125 case TABLINE_MENU_CLOSE: | |
4126 if (current_tab == 0) | |
4127 do_cmdline_cmd((char_u *)"tabclose"); | |
4128 else | |
4129 { | |
4130 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
4131 current_tab); | |
4132 do_cmdline_cmd(IObuff); | |
4133 } | |
4134 break; | |
4135 | |
4136 case TABLINE_MENU_NEW: | |
6631 | 4137 if (current_tab == 0) |
4138 do_cmdline_cmd((char_u *)"$tabnew"); | |
4139 else | |
4140 { | |
4141 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
4142 current_tab - 1); | |
4143 do_cmdline_cmd(IObuff); | |
4144 } | |
686 | 4145 break; |
4146 | |
4147 case TABLINE_MENU_OPEN: | |
6631 | 4148 if (current_tab == 0) |
4149 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
4150 else | |
4151 { | |
4152 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
4153 current_tab - 1); | |
4154 do_cmdline_cmd(IObuff); | |
4155 } | |
686 | 4156 break; |
4157 } | |
4158 } | |
685 | 4159 #endif |
4160 | |
7 | 4161 /* |
4162 * "Q" command. | |
4163 */ | |
4164 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4165 nv_exmode(cmdarg_T *cap) |
7 | 4166 { |
4167 /* | |
4168 * Ignore 'Q' in Visual mode, just give a beep. | |
4169 */ | |
4170 if (VIsual_active) | |
6949 | 4171 vim_beep(BO_EX); |
5735 | 4172 else if (!checkclearop(cap->oap)) |
7 | 4173 do_exmode(FALSE); |
4174 } | |
4175 | |
4176 /* | |
4177 * Handle a ":" command. | |
4178 */ | |
4179 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4180 nv_colon(cmdarg_T *cap) |
7 | 4181 { |
4182 int old_p_im; | |
4256 | 4183 int cmd_result; |
7 | 4184 |
4185 if (VIsual_active) | |
4186 nv_operator(cap); | |
4187 else | |
4188 { | |
4189 if (cap->oap->op_type != OP_NOP) | |
4190 { | |
4191 /* Using ":" as a movement is characterwise exclusive. */ | |
4192 cap->oap->motion_type = MCHAR; | |
4193 cap->oap->inclusive = FALSE; | |
4194 } | |
4195 else if (cap->count0) | |
4196 { | |
4197 /* translate "count:" into ":.,.+(count - 1)" */ | |
4198 stuffcharReadbuff('.'); | |
4199 if (cap->count0 > 1) | |
4200 { | |
4201 stuffReadbuff((char_u *)",.+"); | |
4202 stuffnumReadbuff((long)cap->count0 - 1L); | |
4203 } | |
4204 } | |
4205 | |
4206 /* When typing, don't type below an old message */ | |
4207 if (KeyTyped) | |
4208 compute_cmdrow(); | |
4209 | |
4210 old_p_im = p_im; | |
4211 | |
4212 /* get a command line and execute it */ | |
4256 | 4213 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 4214 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
4215 | |
4216 /* If 'insertmode' changed, enter or exit Insert mode */ | |
4217 if (p_im != old_p_im) | |
4218 { | |
4219 if (p_im) | |
4220 restart_edit = 'i'; | |
4221 else | |
4222 restart_edit = 0; | |
4223 } | |
4224 | |
4256 | 4225 if (cmd_result == FAIL) |
4226 /* The Ex command failed, do not execute the operator. */ | |
4227 clearop(cap->oap); | |
4228 else if (cap->oap->op_type != OP_NOP | |
7 | 4229 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
4230 || cap->oap->start.col > | |
4256 | 4231 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
4232 || did_emsg | |
4233 )) | |
4234 /* The start of the operator has become invalid by the Ex command. | |
4235 */ | |
7 | 4236 clearopbeep(cap->oap); |
4237 } | |
4238 } | |
4239 | |
4240 /* | |
4241 * Handle CTRL-G command. | |
4242 */ | |
4243 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4244 nv_ctrlg(cmdarg_T *cap) |
7 | 4245 { |
4246 if (VIsual_active) /* toggle Selection/Visual mode */ | |
4247 { | |
4248 VIsual_select = !VIsual_select; | |
4249 showmode(); | |
4250 } | |
5735 | 4251 else if (!checkclearop(cap->oap)) |
7 | 4252 /* print full name if count given or :cd used */ |
4253 fileinfo((int)cap->count0, FALSE, TRUE); | |
4254 } | |
4255 | |
4256 /* | |
4257 * Handle CTRL-H <Backspace> command. | |
4258 */ | |
4259 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4260 nv_ctrlh(cmdarg_T *cap) |
7 | 4261 { |
4262 if (VIsual_active && VIsual_select) | |
4263 { | |
4264 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
4265 v_visop(cap); | |
4266 } | |
4267 else | |
4268 nv_left(cap); | |
4269 } | |
4270 | |
4271 /* | |
4272 * CTRL-L: clear screen and redraw. | |
4273 */ | |
4274 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4275 nv_clear(cmdarg_T *cap) |
7 | 4276 { |
4277 if (!checkclearop(cap->oap)) | |
4278 { | |
4279 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
4280 /* | |
4281 * Right now, the BeBox doesn't seem to have an easy way to detect | |
4282 * window resizing, so we cheat and make the user detect it | |
4283 * manually with CTRL-L instead | |
4284 */ | |
4285 ui_get_shellsize(); | |
4286 #endif | |
4287 #ifdef FEAT_SYN_HL | |
4288 /* 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
|
4289 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
|
4290 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4291 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4292 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4293 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4294 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
|
4295 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
|
4296 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4297 # endif |
7 | 4298 #endif |
4299 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
|
4300 #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
|
4301 # 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
|
4302 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
|
4303 # 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
|
4304 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
|
4305 #endif |
7 | 4306 } |
4307 } | |
4308 | |
4309 /* | |
4310 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
4311 * Otherwise: Go to older pcmark. | |
4312 */ | |
4313 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4314 nv_ctrlo(cmdarg_T *cap) |
7 | 4315 { |
4316 if (VIsual_active && VIsual_select) | |
4317 { | |
4318 VIsual_select = FALSE; | |
4319 showmode(); | |
4320 restart_VIsual_select = 2; /* restart Select mode later */ | |
4321 } | |
4322 else | |
4323 { | |
4324 cap->count1 = -cap->count1; | |
4325 nv_pcmark(cap); | |
4326 } | |
4327 } | |
4328 | |
4329 /* | |
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
|
4330 * 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
|
4331 * not named. |
7 | 4332 */ |
4333 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4334 nv_hat(cmdarg_T *cap) |
7 | 4335 { |
4336 if (!checkclearopq(cap->oap)) | |
4337 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
4338 GETF_SETMARK|GETF_ALT, FALSE); | |
4339 } | |
4340 | |
4341 /* | |
4342 * "Z" commands. | |
4343 */ | |
4344 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4345 nv_Zet(cmdarg_T *cap) |
7 | 4346 { |
4347 if (!checkclearopq(cap->oap)) | |
4348 { | |
4349 switch (cap->nchar) | |
4350 { | |
4351 /* "ZZ": equivalent to ":x". */ | |
4352 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
4353 break; | |
4354 | |
4355 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
4356 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
4357 break; | |
4358 | |
4359 default: clearopbeep(cap->oap); | |
4360 } | |
4361 } | |
4362 } | |
4363 | |
4364 /* | |
4365 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
4366 */ | |
4367 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4368 do_nv_ident(int c1, int c2) |
7 | 4369 { |
4370 oparg_T oa; | |
4371 cmdarg_T ca; | |
4372 | |
4373 clear_oparg(&oa); | |
4374 vim_memset(&ca, 0, sizeof(ca)); | |
4375 ca.oap = &oa; | |
4376 ca.cmdchar = c1; | |
4377 ca.nchar = c2; | |
4378 nv_ident(&ca); | |
4379 } | |
4380 | |
4381 /* | |
4382 * Handle the commands that use the word under the cursor. | |
4383 * [g] CTRL-] :ta to current identifier | |
4384 * [g] 'K' run program for current identifier | |
4385 * [g] '*' / to current identifier or string | |
4386 * [g] '#' ? to current identifier or string | |
4387 * g ']' :tselect for current identifier | |
4388 */ | |
4389 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4390 nv_ident(cmdarg_T *cap) |
7 | 4391 { |
4392 char_u *ptr = NULL; | |
4393 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4394 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
4395 char_u *newbuf; |
7 | 4396 char_u *p; |
4397 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
|
4398 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4399 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 4400 int n = 0; /* init for GCC */ |
4401 int cmdchar; | |
4402 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4403 int tag_cmd = FALSE; |
7 | 4404 char_u *aux_ptr; |
4405 int isman; | |
4406 int isman_s; | |
4407 | |
4408 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
4409 { | |
4410 cmdchar = cap->nchar; | |
4411 g_cmd = TRUE; | |
4412 } | |
4413 else | |
4414 { | |
4415 cmdchar = cap->cmdchar; | |
4416 g_cmd = FALSE; | |
4417 } | |
4418 | |
4419 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
4420 cmdchar = '#'; | |
4421 | |
4422 /* | |
4423 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
4424 */ | |
4425 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
4426 { | |
4427 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
4428 return; | |
4429 if (checkclearopq(cap->oap)) | |
4430 return; | |
4431 } | |
4432 | |
4433 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
4434 (cmdchar == '*' || cmdchar == '#') | |
4435 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
4436 { | |
4437 clearop(cap->oap); | |
4438 return; | |
4439 } | |
4440 | |
4441 /* Allocate buffer to put the command in. Inserting backslashes can | |
4442 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
4443 * and some numbers. */ | |
4444 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
4445 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
4446 || 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
|
4447 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
|
4448 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
4449 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
|
4450 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
|
4451 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4452 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4453 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
|
4454 buf = alloc(buflen); |
7 | 4455 if (buf == NULL) |
4456 return; | |
4457 buf[0] = NUL; | |
4458 | |
4459 switch (cmdchar) | |
4460 { | |
4461 case '*': | |
4462 case '#': | |
4463 /* | |
4464 * Put cursor at start of word, makes search skip the word | |
4465 * under the cursor. | |
4466 * Call setpcmark() first, so "*``" puts the cursor back where | |
4467 * it was. | |
4468 */ | |
4469 setpcmark(); | |
4470 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
4471 | |
4472 if (!g_cmd && vim_iswordp(ptr)) | |
4473 STRCPY(buf, "\\<"); | |
4474 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
4475 break; | |
4476 | |
4477 case 'K': | |
4478 if (kp_help) | |
4479 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4480 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4481 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4482 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4483 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
|
4484 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4485 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4486 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4487 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
4488 } |
7 | 4489 else |
4490 { | |
1712 | 4491 /* An external command will probably use an argument starting |
4492 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 4493 while (*ptr == '-' && n > 0) |
4494 { | |
1712 | 4495 ++ptr; |
1728 | 4496 --n; |
4497 } | |
4498 if (n == 0) | |
4499 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
4500 emsg(_(e_noident)); /* found dashes only */ |
1728 | 4501 vim_free(buf); |
4502 return; | |
4503 } | |
1712 | 4504 |
7 | 4505 /* When a count is given, turn it into a range. Is this |
4506 * really what we want? */ | |
4507 isman = (STRCMP(kp, "man") == 0); | |
4508 isman_s = (STRCMP(kp, "man -s") == 0); | |
4509 if (cap->count0 != 0 && !(isman || isman_s)) | |
4510 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
4511 | |
4512 STRCAT(buf, "! "); | |
4513 if (cap->count0 == 0 && isman_s) | |
4514 STRCAT(buf, "man"); | |
4515 else | |
4516 STRCAT(buf, kp); | |
4517 STRCAT(buf, " "); | |
4518 if (cap->count0 != 0 && (isman || isman_s)) | |
4519 { | |
4520 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
4521 STRCAT(buf, " "); | |
4522 } | |
4523 } | |
4524 break; | |
4525 | |
4526 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4527 tag_cmd = TRUE; |
7 | 4528 #ifdef FEAT_CSCOPE |
4529 if (p_cst) | |
4530 STRCPY(buf, "cstag "); | |
4531 else | |
4532 #endif | |
4533 STRCPY(buf, "ts "); | |
4534 break; | |
4535 | |
4536 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
4537 tag_cmd = TRUE; |
7 | 4538 if (curbuf->b_help) |
4539 STRCPY(buf, "he! "); | |
4540 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4541 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4542 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4543 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4544 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4545 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4546 } |
7 | 4547 } |
4548 | |
4549 /* | |
4550 * Now grab the chars in the identifier | |
4551 */ | |
1712 | 4552 if (cmdchar == 'K' && !kp_help) |
4553 { | |
1728 | 4554 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
4555 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
4556 /* 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
|
4557 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
4558 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
4559 /* 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
|
4560 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 4561 vim_free(ptr); |
1712 | 4562 if (p == NULL) |
4563 { | |
4564 vim_free(buf); | |
4565 return; | |
4566 } | |
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
|
4567 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
|
4568 if (newbuf == NULL) |
1712 | 4569 { |
4570 vim_free(buf); | |
4571 vim_free(p); | |
4572 return; | |
4573 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
4574 buf = newbuf; |
1712 | 4575 STRCAT(buf, p); |
4576 vim_free(p); | |
4577 } | |
7 | 4578 else |
1712 | 4579 { |
4580 if (cmdchar == '*') | |
4581 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
4582 else if (cmdchar == '#') | |
4583 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
4584 else if (tag_cmd) |
2603 | 4585 { |
4586 if (curbuf->b_help) | |
4587 /* ":help" handles unescaped argument */ | |
4588 aux_ptr = (char_u *)""; | |
4589 else | |
4590 aux_ptr = (char_u *)"\\|\"\n["; | |
4591 } | |
1712 | 4592 else |
4593 aux_ptr = (char_u *)"\\|\"\n*?["; | |
4594 | |
4595 p = buf + STRLEN(buf); | |
4596 while (n-- > 0) | |
4597 { | |
4598 /* put a backslash before \ and some others */ | |
4599 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
4600 *p++ = '\\'; | |
4601 /* When current byte is a part of multibyte character, copy all | |
4602 * bytes of that character. */ | |
4603 if (has_mbyte) | |
4604 { | |
4605 int i; | |
4606 int len = (*mb_ptr2len)(ptr) - 1; | |
4607 | |
4608 for (i = 0; i < len && n >= 1; ++i, --n) | |
4609 *p++ = *ptr++; | |
4610 } | |
4611 *p++ = *ptr++; | |
4612 } | |
4613 *p = NUL; | |
4614 } | |
7 | 4615 |
4616 /* | |
4617 * Execute the command. | |
4618 */ | |
4619 if (cmdchar == '*' || cmdchar == '#') | |
4620 { | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4621 if (!g_cmd && (has_mbyte |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4622 ? 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
|
4623 : vim_iswordc(ptr[-1]))) |
7 | 4624 STRCAT(buf, "\\>"); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
4625 |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
4626 // put pattern in search history |
2024 | 4627 init_history(); |
7 | 4628 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
|
4629 |
6620 | 4630 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 4631 } |
4632 else | |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4633 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4634 g_tag_at_cursor = TRUE; |
7 | 4635 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
|
4636 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
|
4637 } |
7 | 4638 |
4639 vim_free(buf); | |
4640 } | |
4641 | |
4642 /* | |
4643 * Get visually selected text, within one line only. | |
4644 * Returns FAIL if more than one line selected. | |
4645 */ | |
344 | 4646 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4647 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4648 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4649 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
|
4650 int *lenp) /* return: length of selected text */ |
7 | 4651 { |
4652 if (VIsual_mode != 'V') | |
4653 unadjust_for_sel(); | |
4654 if (VIsual.lnum != curwin->w_cursor.lnum) | |
4655 { | |
344 | 4656 if (cap != NULL) |
4657 clearopbeep(cap->oap); | |
7 | 4658 return FAIL; |
4659 } | |
4660 if (VIsual_mode == 'V') | |
4661 { | |
4662 *pp = ml_get_curline(); | |
4663 *lenp = (int)STRLEN(*pp); | |
4664 } | |
4665 else | |
4666 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4667 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 4668 { |
4669 *pp = ml_get_pos(&curwin->w_cursor); | |
4670 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
4671 } | |
4672 else | |
4673 { | |
4674 *pp = ml_get_pos(&VIsual); | |
4675 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
4676 } | |
4677 if (has_mbyte) | |
4678 /* Correct the length to include the whole last character. */ | |
474 | 4679 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 4680 } |
4681 reset_VIsual_and_resel(); | |
4682 return OK; | |
4683 } | |
4684 | |
4685 /* | |
4686 * CTRL-T: backwards in tag stack | |
4687 */ | |
4688 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4689 nv_tagpop(cmdarg_T *cap) |
7 | 4690 { |
4691 if (!checkclearopq(cap->oap)) | |
4692 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
4693 } | |
4694 | |
4695 /* | |
4696 * Handle scrolling command 'H', 'L' and 'M'. | |
4697 */ | |
4698 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4699 nv_scroll(cmdarg_T *cap) |
7 | 4700 { |
4701 int used = 0; | |
4702 long n; | |
4703 #ifdef FEAT_FOLDING | |
4704 linenr_T lnum; | |
4705 #endif | |
4706 int half; | |
4707 | |
4708 cap->oap->motion_type = MLINE; | |
4709 setpcmark(); | |
4710 | |
4711 if (cap->cmdchar == 'L') | |
4712 { | |
4713 validate_botline(); /* make sure curwin->w_botline is valid */ | |
4714 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
4715 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
4716 curwin->w_cursor.lnum = 1; | |
4717 else | |
9 | 4718 { |
4719 #ifdef FEAT_FOLDING | |
4720 if (hasAnyFolding(curwin)) | |
4721 { | |
4722 /* Count a fold for one screen line. */ | |
4723 for (n = cap->count1 - 1; n > 0 | |
4724 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
4725 { | |
4726 (void)hasFolding(curwin->w_cursor.lnum, | |
4727 &curwin->w_cursor.lnum, NULL); | |
4728 --curwin->w_cursor.lnum; | |
4729 } | |
4730 } | |
4731 else | |
4732 #endif | |
4733 curwin->w_cursor.lnum -= cap->count1 - 1; | |
4734 } | |
7 | 4735 } |
4736 else | |
4737 { | |
4738 if (cap->cmdchar == 'M') | |
4739 { | |
4740 #ifdef FEAT_DIFF | |
4741 /* Don't count filler lines above the window. */ | |
4742 used -= diff_check_fill(curwin, curwin->w_topline) | |
4743 - curwin->w_topfill; | |
4744 #endif | |
4745 validate_botline(); /* make sure w_empty_rows is valid */ | |
4746 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
4747 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
4748 { | |
4749 #ifdef FEAT_DIFF | |
4750 /* Count half he number of filler lines to be "below this | |
4751 * line" and half to be "above the next line". */ | |
4752 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
4753 + n) / 2 >= half) | |
4754 { | |
4755 --n; | |
4756 break; | |
4757 } | |
4758 #endif | |
4759 used += plines(curwin->w_topline + n); | |
4760 if (used >= half) | |
4761 break; | |
4762 #ifdef FEAT_FOLDING | |
4763 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
4764 n = lnum - curwin->w_topline; | |
4765 #endif | |
4766 } | |
4767 if (n > 0 && used > curwin->w_height) | |
4768 --n; | |
4769 } | |
9 | 4770 else /* (cap->cmdchar == 'H') */ |
4771 { | |
7 | 4772 n = cap->count1 - 1; |
9 | 4773 #ifdef FEAT_FOLDING |
4774 if (hasAnyFolding(curwin)) | |
4775 { | |
4776 /* Count a fold for one screen line. */ | |
4777 lnum = curwin->w_topline; | |
4778 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
4779 { | |
7009 | 4780 (void)hasFolding(lnum, NULL, &lnum); |
9 | 4781 ++lnum; |
4782 } | |
4783 n = lnum - curwin->w_topline; | |
4784 } | |
4785 #endif | |
4786 } | |
7 | 4787 curwin->w_cursor.lnum = curwin->w_topline + n; |
4788 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
4789 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4790 } | |
4791 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
4792 /* 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
|
4793 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
|
4794 cursor_correct(); |
7 | 4795 beginline(BL_SOL | BL_FIX); |
4796 } | |
4797 | |
4798 /* | |
4799 * Cursor right commands. | |
4800 */ | |
4801 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4802 nv_right(cmdarg_T *cap) |
7 | 4803 { |
4804 long n; | |
5735 | 4805 int past_line; |
7 | 4806 |
180 | 4807 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
4808 { | |
4809 /* <C-Right> and <S-Right> move a word or WORD right */ | |
4810 if (mod_mask & MOD_MASK_CTRL) | |
4811 cap->arg = TRUE; | |
4812 nv_wordcmd(cap); | |
4813 return; | |
4814 } | |
4815 | |
7 | 4816 cap->oap->motion_type = MCHAR; |
4817 cap->oap->inclusive = FALSE; | |
5735 | 4818 past_line = (VIsual_active && *p_sel != 'o'); |
4819 | |
7 | 4820 /* |
5735 | 4821 * In virtual edit mode, there's no such thing as "past_line", as lines |
4822 * are (theoretically) infinitely long. | |
7 | 4823 */ |
4824 if (virtual_active()) | |
5735 | 4825 past_line = 0; |
7 | 4826 |
4827 for (n = cap->count1; n > 0; --n) | |
4828 { | |
5735 | 4829 if ((!past_line && oneright() == FAIL) |
4830 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 4831 ) |
7 | 4832 { |
4833 /* | |
714 | 4834 * <Space> wraps to next line if 'whichwrap' has 's'. |
4835 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
4836 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 4837 */ |
4838 if ( ((cap->cmdchar == ' ' | |
4839 && vim_strchr(p_ww, 's') != NULL) | |
4840 || (cap->cmdchar == 'l' | |
4841 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 4842 || (cap->cmdchar == K_RIGHT |
7 | 4843 && vim_strchr(p_ww, '>') != NULL)) |
4844 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4845 { | |
4846 /* When deleting we also count the NL as a character. | |
4847 * Set cap->oap->inclusive when last char in the line is | |
4848 * included, move to next line after that */ | |
714 | 4849 if ( cap->oap->op_type != OP_NOP |
7 | 4850 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4851 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4852 cap->oap->inclusive = TRUE; |
4853 else | |
4854 { | |
4855 ++curwin->w_cursor.lnum; | |
4856 curwin->w_cursor.col = 0; | |
4857 curwin->w_cursor.coladd = 0; | |
4858 curwin->w_set_curswant = TRUE; | |
4859 cap->oap->inclusive = FALSE; | |
4860 } | |
4861 continue; | |
4862 } | |
4863 if (cap->oap->op_type == OP_NOP) | |
4864 { | |
4865 /* Only beep and flush if not moved at all */ | |
4866 if (n == cap->count1) | |
4867 beep_flush(); | |
4868 } | |
4869 else | |
4870 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4871 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4872 cap->oap->inclusive = TRUE; |
4873 } | |
4874 break; | |
4875 } | |
5735 | 4876 else if (past_line) |
7 | 4877 { |
4878 curwin->w_set_curswant = TRUE; | |
4879 if (virtual_active()) | |
4880 oneright(); | |
4881 else | |
5735 | 4882 { |
7 | 4883 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
|
4884 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 4885 else |
4886 ++curwin->w_cursor.col; | |
4887 } | |
4888 } | |
4889 } | |
4890 #ifdef FEAT_FOLDING | |
4891 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
4892 && cap->oap->op_type == OP_NOP) | |
4893 foldOpenCursor(); | |
4894 #endif | |
4895 } | |
4896 | |
4897 /* | |
4898 * Cursor left commands. | |
4899 * | |
4900 * Returns TRUE when operator end should not be adjusted. | |
4901 */ | |
4902 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4903 nv_left(cmdarg_T *cap) |
7 | 4904 { |
4905 long n; | |
4906 | |
180 | 4907 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
4908 { | |
4909 /* <C-Left> and <S-Left> move a word or WORD left */ | |
4910 if (mod_mask & MOD_MASK_CTRL) | |
4911 cap->arg = 1; | |
4912 nv_bck_word(cap); | |
4913 return; | |
4914 } | |
4915 | |
7 | 4916 cap->oap->motion_type = MCHAR; |
4917 cap->oap->inclusive = FALSE; | |
4918 for (n = cap->count1; n > 0; --n) | |
4919 { | |
4920 if (oneleft() == FAIL) | |
4921 { | |
4922 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
4923 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
4924 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
4925 */ | |
4926 if ( (((cap->cmdchar == K_BS | |
4927 || cap->cmdchar == Ctrl_H) | |
4928 && vim_strchr(p_ww, 'b') != NULL) | |
4929 || (cap->cmdchar == 'h' | |
4930 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 4931 || (cap->cmdchar == K_LEFT |
7 | 4932 && vim_strchr(p_ww, '<') != NULL)) |
4933 && curwin->w_cursor.lnum > 1) | |
4934 { | |
4935 --(curwin->w_cursor.lnum); | |
4936 coladvance((colnr_T)MAXCOL); | |
4937 curwin->w_set_curswant = TRUE; | |
4938 | |
4939 /* When the NL before the first char has to be deleted we | |
4940 * put the cursor on the NUL after the previous line. | |
4941 * This is a very special case, be careful! | |
1469 | 4942 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 4943 if ( (cap->oap->op_type == OP_DELETE |
4944 || 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
|
4945 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4946 { |
5682 | 4947 char_u *cp = ml_get_cursor(); |
4948 | |
4949 if (*cp != NUL) | |
4950 { | |
4951 if (has_mbyte) | |
4952 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
4953 else | |
4954 ++curwin->w_cursor.col; | |
4955 } | |
7 | 4956 cap->retval |= CA_NO_ADJ_OP_END; |
4957 } | |
4958 continue; | |
4959 } | |
4960 /* Only beep and flush if not moved at all */ | |
4961 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
4962 beep_flush(); | |
4963 break; | |
4964 } | |
4965 } | |
4966 #ifdef FEAT_FOLDING | |
4967 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
4968 && cap->oap->op_type == OP_NOP) | |
4969 foldOpenCursor(); | |
4970 #endif | |
4971 } | |
4972 | |
4973 /* | |
4974 * Cursor up commands. | |
4975 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
4976 */ | |
4977 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4978 nv_up(cmdarg_T *cap) |
7 | 4979 { |
180 | 4980 if (mod_mask & MOD_MASK_SHIFT) |
4981 { | |
4982 /* <S-Up> is page up */ | |
4983 cap->arg = BACKWARD; | |
4984 nv_page(cap); | |
4985 } | |
4986 else | |
4987 { | |
4988 cap->oap->motion_type = MLINE; | |
4989 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
4990 clearopbeep(cap->oap); | |
4991 else if (cap->arg) | |
4992 beginline(BL_WHITE | BL_FIX); | |
4993 } | |
7 | 4994 } |
4995 | |
4996 /* | |
4997 * Cursor down commands. | |
4998 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
4999 */ | |
5000 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
5001 nv_down(cmdarg_T *cap) |
7 | 5002 { |
180 | 5003 if (mod_mask & MOD_MASK_SHIFT) |
5004 { | |
5005 /* <S-Down> is page down */ | |
5006 cap->arg = FORWARD; | |
5007 nv_page(cap); | |
5008 } | |
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
|
5009 #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
|
5010 /* 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
|
5011 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
|
5012 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
|
5013 #endif |
180 | 5014 else |
7 | 5015 { |
5016 #ifdef FEAT_CMDWIN | |
5017 /* In the cmdline window a <CR> executes the command. */ | |
170 | 5018 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 5019 cmdwin_result = CAR; |
5020 else | |
5021 #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
|
5022 #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
|
5023 /* 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
|
5024 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
|
5025 && 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
|
5026 { |
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
|
5027 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
|
5028 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
|
5029 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
|
5030 } |
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
|
5031 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
|
5032 #endif |
7 | 5033 { |
5034 cap->oap->motion_type = MLINE; | |
5035 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
5036 clearopbeep(cap->oap); | |
5037 else if (cap->arg) | |
5038 beginline(BL_WHITE | BL_FIX); | |
5039 } | |
5040 } | |
5041 } | |
5042 | |
5043 #ifdef FEAT_SEARCHPATH | |
5044 /* | |
5045 * Grab the file name under the cursor and edit it. | |
5046 */ | |
5047 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5048 nv_gotofile(cmdarg_T *cap) |
7 | 5049 { |
5050 char_u *ptr; | |
681 | 5051 linenr_T lnum = -1; |
7 | 5052 |
633 | 5053 if (text_locked()) |
7 | 5054 { |
5055 clearopbeep(cap->oap); | |
633 | 5056 text_locked_msg(); |
7 | 5057 return; |
5058 } | |
819 | 5059 if (curbuf_locked()) |
5060 { | |
5061 clearop(cap->oap); | |
5062 return; | |
5063 } | |
7 | 5064 |
681 | 5065 ptr = grab_file_name(cap->count1, &lnum); |
7 | 5066 |
5067 if (ptr != NULL) | |
5068 { | |
5069 /* 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
|
5070 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 5071 (void)autowrite(curbuf, FALSE); |
7 | 5072 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
|
5073 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
|
5074 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
|
5075 && cap->nchar == 'F' && lnum >= 0) |
681 | 5076 { |
5077 curwin->w_cursor.lnum = lnum; | |
5078 check_cursor_lnum(); | |
5079 beginline(BL_SOL | BL_FIX); | |
5080 } | |
7 | 5081 vim_free(ptr); |
5082 } | |
5083 else | |
5084 clearop(cap->oap); | |
5085 } | |
5086 #endif | |
5087 | |
5088 /* | |
5089 * <End> command: to end of current line or last line. | |
5090 */ | |
5091 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5092 nv_end(cmdarg_T *cap) |
7 | 5093 { |
180 | 5094 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
5095 { | |
5096 cap->arg = TRUE; | |
7 | 5097 nv_goto(cap); |
5098 cap->count1 = 1; /* to end of current line */ | |
5099 } | |
5100 nv_dollar(cap); | |
5101 } | |
5102 | |
5103 /* | |
5104 * Handle the "$" command. | |
5105 */ | |
5106 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5107 nv_dollar(cmdarg_T *cap) |
7 | 5108 { |
5109 cap->oap->motion_type = MCHAR; | |
5110 cap->oap->inclusive = TRUE; | |
5111 /* In virtual mode when off the edge of a line and an operator | |
5112 * is pending (whew!) keep the cursor where it is. | |
5113 * Otherwise, send it to the end of the line. */ | |
5114 if (!virtual_active() || gchar_cursor() != NUL | |
5115 || cap->oap->op_type == OP_NOP) | |
5116 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
5117 if (cursor_down((long)(cap->count1 - 1), | |
5118 cap->oap->op_type == OP_NOP) == FAIL) | |
5119 clearopbeep(cap->oap); | |
5120 #ifdef FEAT_FOLDING | |
5121 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
5122 foldOpenCursor(); | |
5123 #endif | |
5124 } | |
5125 | |
5126 /* | |
5127 * Implementation of '?' and '/' commands. | |
5128 * If cap->arg is TRUE don't set PC mark. | |
5129 */ | |
5130 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5131 nv_search(cmdarg_T *cap) |
7 | 5132 { |
5133 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5134 pos_T save_cursor = curwin->w_cursor; |
7 | 5135 |
5136 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
5137 { | |
5138 /* Translate "g??" to "g?g?" */ | |
5139 cap->cmdchar = 'g'; | |
5140 cap->nchar = '?'; | |
5141 nv_operator(cap); | |
5142 return; | |
5143 } | |
5144 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5145 /* 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
|
5146 * start position. */ |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17041
diff
changeset
|
5147 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, TRUE); |
7 | 5148 |
5149 if (cap->searchbuf == NULL) | |
5150 { | |
5151 clearop(oap); | |
5152 return; | |
5153 } | |
5154 | |
6620 | 5155 (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
|
5156 (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
|
5157 ? 0 : SEARCH_MARK); |
7 | 5158 } |
5159 | |
5160 /* | |
5161 * Handle "N" and "n" commands. | |
5162 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
5163 */ | |
5164 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5165 nv_next(cmdarg_T *cap) |
7 | 5166 { |
6620 | 5167 pos_T old = curwin->w_cursor; |
5168 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
5169 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5170 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 5171 { |
5172 /* Avoid getting stuck on the current cursor position, which can | |
5173 * happen when an offset is given and the cursor is on the last char | |
5174 * in the buffer: Repeat with count + 1. */ | |
5175 cap->count1 += 1; | |
5176 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
5177 cap->count1 -= 1; | |
5178 } | |
7 | 5179 } |
5180 | |
5181 /* | |
5182 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
5183 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 5184 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
5185 */ | |
5186 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5187 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5188 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5189 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5190 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5191 int opt) /* extra flags for do_search() */ |
7 | 5192 { |
5193 int i; | |
5194 | |
5195 cap->oap->motion_type = MCHAR; | |
5196 cap->oap->inclusive = FALSE; | |
5197 cap->oap->use_reg_one = TRUE; | |
5198 curwin->w_set_curswant = TRUE; | |
5199 | |
5200 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
|
5201 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 5202 if (i == 0) |
5203 clearop(cap->oap); | |
5204 else | |
5205 { | |
5206 if (i == 2) | |
5207 cap->oap->motion_type = MLINE; | |
5208 curwin->w_cursor.coladd = 0; | |
5209 #ifdef FEAT_FOLDING | |
5210 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
5211 foldOpenCursor(); | |
5212 #endif | |
5213 } | |
5214 | |
5215 /* "/$" will put the cursor after the end of the line, may need to | |
5216 * correct that here */ | |
5217 check_cursor(); | |
6620 | 5218 return i; |
7 | 5219 } |
5220 | |
5221 /* | |
5222 * Character search commands. | |
5223 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
5224 * ',' and FALSE for ';'. | |
5225 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
5226 */ | |
5227 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5228 nv_csearch(cmdarg_T *cap) |
7 | 5229 { |
5230 int t_cmd; | |
5231 | |
5232 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
5233 t_cmd = TRUE; | |
5234 else | |
5235 t_cmd = FALSE; | |
5236 | |
5237 cap->oap->motion_type = MCHAR; | |
5238 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
5239 clearopbeep(cap->oap); | |
5240 else | |
5241 { | |
5242 curwin->w_set_curswant = TRUE; | |
5243 /* Include a Tab for "tx" and for "dfx". */ | |
5244 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
5245 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
5246 { | |
5247 colnr_T scol, ecol; | |
5248 | |
5249 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
5250 curwin->w_cursor.coladd = ecol - scol; | |
5251 } | |
5252 else | |
5253 curwin->w_cursor.coladd = 0; | |
5254 adjust_for_sel(cap); | |
5255 #ifdef FEAT_FOLDING | |
5256 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
5257 foldOpenCursor(); | |
5258 #endif | |
5259 } | |
5260 } | |
5261 | |
5262 /* | |
5263 * "[" and "]" commands. | |
5264 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
5265 */ | |
5266 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5267 nv_brackets(cmdarg_T *cap) |
7 | 5268 { |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5269 pos_T new_pos = {0, 0, 0}; |
7 | 5270 pos_T prev_pos; |
5271 pos_T *pos = NULL; /* init for GCC */ | |
5272 pos_T old_pos; /* cursor position before command */ | |
5273 int flag; | |
5274 long n; | |
5275 int findc; | |
5276 int c; | |
5277 | |
5278 cap->oap->motion_type = MCHAR; | |
5279 cap->oap->inclusive = FALSE; | |
5280 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
|
5281 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error. |
7 | 5282 |
5283 #ifdef FEAT_SEARCHPATH | |
5284 /* | |
5285 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
5286 */ | |
5287 if (cap->nchar == 'f') | |
5288 nv_gotofile(cap); | |
5289 else | |
5290 #endif | |
5291 | |
5292 #ifdef FEAT_FIND_ID | |
5293 /* | |
1188 | 5294 * Find the occurrence(s) of the identifier or define under cursor |
5295 * in current and included files or jump to the first occurrence. | |
7 | 5296 * |
5297 * search list jump | |
5298 * fwd bwd fwd bwd fwd bwd | |
5299 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
5300 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
5301 */ | |
5302 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
|
5303 # ifdef EBCDIC |
7 | 5304 "iI\005dD\067", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5305 # else |
7 | 5306 "iI\011dD\004", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5307 # endif |
7 | 5308 cap->nchar) != NULL) |
5309 { | |
5310 char_u *ptr; | |
5311 int len; | |
5312 | |
5313 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
5314 clearop(cap->oap); | |
5315 else | |
5316 { | |
5317 find_pattern_in_path(ptr, 0, len, TRUE, | |
5318 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
5319 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
5320 cap->count1, | |
5321 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
5322 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
5323 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
5324 (linenr_T)MAXLNUM); | |
5325 curwin->w_set_curswant = TRUE; | |
5326 } | |
5327 } | |
5328 else | |
5329 #endif | |
5330 | |
5331 /* | |
5332 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
5333 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
5334 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
5335 * "[m" or "]m" search for prev/next start of (Java) method. | |
5336 * "[M" or "]M" search for prev/next end of (Java) method. | |
5337 */ | |
5338 if ( (cap->cmdchar == '[' | |
5339 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
5340 || (cap->cmdchar == ']' | |
5341 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
5342 { | |
5343 if (cap->nchar == '*') | |
5344 cap->nchar = '/'; | |
5345 prev_pos.lnum = 0; | |
5346 if (cap->nchar == 'm' || cap->nchar == 'M') | |
5347 { | |
5348 if (cap->cmdchar == '[') | |
5349 findc = '{'; | |
5350 else | |
5351 findc = '}'; | |
5352 n = 9999; | |
5353 } | |
5354 else | |
5355 { | |
5356 findc = cap->nchar; | |
5357 n = cap->count1; | |
5358 } | |
5359 for ( ; n > 0; --n) | |
5360 { | |
5361 if ((pos = findmatchlimit(cap->oap, findc, | |
5362 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
5363 { | |
5364 if (new_pos.lnum == 0) /* nothing found */ | |
5365 { | |
5366 if (cap->nchar != 'm' && cap->nchar != 'M') | |
5367 clearopbeep(cap->oap); | |
5368 } | |
5369 else | |
5370 pos = &new_pos; /* use last one found */ | |
5371 break; | |
5372 } | |
5373 prev_pos = new_pos; | |
5374 curwin->w_cursor = *pos; | |
5375 new_pos = *pos; | |
5376 } | |
5377 curwin->w_cursor = old_pos; | |
5378 | |
5379 /* | |
5380 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
5381 * brought us to the match for "[m" and "]M" when inside a method. | |
5382 * Try finding the '{' or '}' we want to be at. | |
5383 * Also repeat for the given count. | |
5384 */ | |
5385 if (cap->nchar == 'm' || cap->nchar == 'M') | |
5386 { | |
5387 /* norm is TRUE for "]M" and "[m" */ | |
5388 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
5389 | |
5390 n = cap->count1; | |
5391 /* found a match: we were inside a method */ | |
5392 if (prev_pos.lnum != 0) | |
5393 { | |
5394 pos = &prev_pos; | |
5395 curwin->w_cursor = prev_pos; | |
5396 if (norm) | |
5397 --n; | |
5398 } | |
5399 else | |
5400 pos = NULL; | |
5401 while (n > 0) | |
5402 { | |
5403 for (;;) | |
5404 { | |
5405 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
5406 { | |
5407 /* if not found anything, that's an error */ | |
5408 if (pos == NULL) | |
5409 clearopbeep(cap->oap); | |
5410 n = 0; | |
5411 break; | |
5412 } | |
5413 c = gchar_cursor(); | |
5414 if (c == '{' || c == '}') | |
5415 { | |
5416 /* Must have found end/start of class: use it. | |
5417 * Or found the place to be at. */ | |
5418 if ((c == findc && norm) || (n == 1 && !norm)) | |
5419 { | |
5420 new_pos = curwin->w_cursor; | |
5421 pos = &new_pos; | |
5422 n = 0; | |
5423 } | |
5424 /* if no match found at all, we started outside of the | |
5425 * class and we're inside now. Just go on. */ | |
5426 else if (new_pos.lnum == 0) | |
5427 { | |
5428 new_pos = curwin->w_cursor; | |
5429 pos = &new_pos; | |
5430 } | |
5431 /* found start/end of other method: go to match */ | |
5432 else if ((pos = findmatchlimit(cap->oap, findc, | |
5433 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
5434 0)) == NULL) | |
5435 n = 0; | |
5436 else | |
5437 curwin->w_cursor = *pos; | |
5438 break; | |
5439 } | |
5440 } | |
5441 --n; | |
5442 } | |
5443 curwin->w_cursor = old_pos; | |
5444 if (pos == NULL && new_pos.lnum != 0) | |
5445 clearopbeep(cap->oap); | |
5446 } | |
5447 if (pos != NULL) | |
5448 { | |
5449 setpcmark(); | |
5450 curwin->w_cursor = *pos; | |
5451 curwin->w_set_curswant = TRUE; | |
5452 #ifdef FEAT_FOLDING | |
5453 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
5454 && cap->oap->op_type == OP_NOP) | |
5455 foldOpenCursor(); | |
5456 #endif | |
5457 } | |
5458 } | |
5459 | |
5460 /* | |
5461 * "[[", "[]", "]]" and "][": move to start or end of function | |
5462 */ | |
5463 else if (cap->nchar == '[' || cap->nchar == ']') | |
5464 { | |
5465 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
5466 flag = '{'; | |
5467 else | |
5468 flag = '}'; /* "][" or "[]" */ | |
5469 | |
5470 curwin->w_set_curswant = TRUE; | |
5471 /* | |
5472 * Imitate strange Vi behaviour: When using "]]" with an operator | |
5473 * we also stop at '}'. | |
5474 */ | |
503 | 5475 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 5476 (cap->oap->op_type != OP_NOP |
5477 && cap->arg == FORWARD && flag == '{'))) | |
5478 clearopbeep(cap->oap); | |
5479 else | |
5480 { | |
5481 if (cap->oap->op_type == OP_NOP) | |
5482 beginline(BL_WHITE | BL_FIX); | |
5483 #ifdef FEAT_FOLDING | |
5484 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
5485 foldOpenCursor(); | |
5486 #endif | |
5487 } | |
5488 } | |
5489 | |
5490 /* | |
5491 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
5492 */ | |
5493 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
5494 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
5495 nv_put_opt(cap, TRUE); |
7 | 5496 } |
5497 | |
5498 /* | |
5499 * "['", "[`", "]'" and "]`": jump to next mark | |
5500 */ | |
5501 else if (cap->nchar == '\'' || cap->nchar == '`') | |
5502 { | |
5503 pos = &curwin->w_cursor; | |
5504 for (n = cap->count1; n > 0; --n) | |
5505 { | |
5506 prev_pos = *pos; | |
5507 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
5508 cap->nchar == '\''); | |
5509 if (pos == NULL) | |
5510 break; | |
5511 } | |
5512 if (pos == NULL) | |
5513 pos = &prev_pos; | |
5514 nv_cursormark(cap, cap->nchar == '\'', pos); | |
5515 } | |
5516 | |
5517 #ifdef FEAT_MOUSE | |
5518 /* | |
5519 * [ or ] followed by a middle mouse click: put selected text with | |
5520 * indent adjustment. Any other button just does as usual. | |
5521 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
5522 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 5523 { |
5524 (void)do_mouse(cap->oap, cap->nchar, | |
5525 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
5526 cap->count1, PUT_FIXINDENT); | |
5527 } | |
5528 #endif /* FEAT_MOUSE */ | |
5529 | |
5530 #ifdef FEAT_FOLDING | |
5531 /* | |
5532 * "[z" and "]z": move to start or end of open fold. | |
5533 */ | |
5534 else if (cap->nchar == 'z') | |
5535 { | |
5536 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
5537 cap->count1) == FAIL) | |
5538 clearopbeep(cap->oap); | |
5539 } | |
5540 #endif | |
5541 | |
5542 #ifdef FEAT_DIFF | |
5543 /* | |
5544 * "[c" and "]c": move to next or previous diff-change. | |
5545 */ | |
5546 else if (cap->nchar == 'c') | |
5547 { | |
5548 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
5549 cap->count1) == FAIL) | |
5550 clearopbeep(cap->oap); | |
5551 } | |
5552 #endif | |
5553 | |
737 | 5554 #ifdef FEAT_SPELL |
236 | 5555 /* |
5556 * "[s", "[S", "]s" and "]S": move to next spell error. | |
5557 */ | |
5558 else if (cap->nchar == 's' || cap->nchar == 'S') | |
5559 { | |
249 | 5560 setpcmark(); |
5561 for (n = 0; n < cap->count1; ++n) | |
498 | 5562 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
5563 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 5564 { |
5565 clearopbeep(cap->oap); | |
5566 break; | |
5567 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
5568 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
5569 curwin->w_set_curswant = TRUE; |
819 | 5570 # ifdef FEAT_FOLDING |
5571 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
5572 foldOpenCursor(); | |
5573 # endif | |
236 | 5574 } |
5575 #endif | |
5576 | |
7 | 5577 /* Not a valid cap->nchar. */ |
5578 else | |
5579 clearopbeep(cap->oap); | |
5580 } | |
5581 | |
5582 /* | |
5583 * Handle Normal mode "%" command. | |
5584 */ | |
5585 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5586 nv_percent(cmdarg_T *cap) |
7 | 5587 { |
5588 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
|
5589 #if defined(FEAT_FOLDING) |
7 | 5590 linenr_T lnum = curwin->w_cursor.lnum; |
5591 #endif | |
5592 | |
5593 cap->oap->inclusive = TRUE; | |
5594 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
5595 { | |
5596 if (cap->count0 > 100) | |
5597 clearopbeep(cap->oap); | |
5598 else | |
5599 { | |
5600 cap->oap->motion_type = MLINE; | |
5601 setpcmark(); | |
5602 /* Round up, so CTRL-G will give same value. Watch out for a | |
5603 * large line count, the line number must not go negative! */ | |
5604 if (curbuf->b_ml.ml_line_count > 1000000) | |
5605 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
5606 / 100L * cap->count0; | |
5607 else | |
5608 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
5609 cap->count0 + 99L) / 100L; | |
5610 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5611 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5612 beginline(BL_SOL | BL_FIX); | |
5613 } | |
5614 } | |
5615 else /* "%" : go to matching paren */ | |
5616 { | |
5617 cap->oap->motion_type = MCHAR; | |
5618 cap->oap->use_reg_one = TRUE; | |
5619 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
5620 clearopbeep(cap->oap); | |
5621 else | |
5622 { | |
5623 setpcmark(); | |
5624 curwin->w_cursor = *pos; | |
5625 curwin->w_set_curswant = TRUE; | |
5626 curwin->w_cursor.coladd = 0; | |
5627 adjust_for_sel(cap); | |
5628 } | |
5629 } | |
5630 #ifdef FEAT_FOLDING | |
5631 if (cap->oap->op_type == OP_NOP | |
5632 && lnum != curwin->w_cursor.lnum | |
5633 && (fdo_flags & FDO_PERCENT) | |
5634 && KeyTyped) | |
5635 foldOpenCursor(); | |
5636 #endif | |
5637 } | |
5638 | |
5639 /* | |
5640 * Handle "(" and ")" commands. | |
5641 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
5642 */ | |
5643 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5644 nv_brace(cmdarg_T *cap) |
7 | 5645 { |
5646 cap->oap->motion_type = MCHAR; | |
5647 cap->oap->use_reg_one = TRUE; | |
620 | 5648 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
5649 cap->oap->inclusive = FALSE; | |
7 | 5650 curwin->w_set_curswant = TRUE; |
5651 | |
5652 if (findsent(cap->arg, cap->count1) == FAIL) | |
5653 clearopbeep(cap->oap); | |
5654 else | |
5655 { | |
1505 | 5656 /* Don't leave the cursor on the NUL past end of line. */ |
5657 adjust_cursor(cap->oap); | |
7 | 5658 curwin->w_cursor.coladd = 0; |
5659 #ifdef FEAT_FOLDING | |
5660 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
5661 foldOpenCursor(); | |
5662 #endif | |
5663 } | |
5664 } | |
5665 | |
5666 /* | |
5667 * "m" command: Mark a position. | |
5668 */ | |
5669 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5670 nv_mark(cmdarg_T *cap) |
7 | 5671 { |
5672 if (!checkclearop(cap->oap)) | |
5673 { | |
5674 if (setmark(cap->nchar) == FAIL) | |
5675 clearopbeep(cap->oap); | |
5676 } | |
5677 } | |
5678 | |
5679 /* | |
5680 * "{" and "}" commands. | |
5681 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
5682 */ | |
5683 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5684 nv_findpar(cmdarg_T *cap) |
7 | 5685 { |
5686 cap->oap->motion_type = MCHAR; | |
5687 cap->oap->inclusive = FALSE; | |
5688 cap->oap->use_reg_one = TRUE; | |
5689 curwin->w_set_curswant = TRUE; | |
503 | 5690 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 5691 clearopbeep(cap->oap); |
5692 else | |
5693 { | |
5694 curwin->w_cursor.coladd = 0; | |
5695 #ifdef FEAT_FOLDING | |
5696 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
5697 foldOpenCursor(); | |
5698 #endif | |
5699 } | |
5700 } | |
5701 | |
5702 /* | |
5703 * "u" command: Undo or make lower case. | |
5704 */ | |
5705 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5706 nv_undo(cmdarg_T *cap) |
7 | 5707 { |
5735 | 5708 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 5709 { |
5710 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
5711 cap->cmdchar = 'g'; | |
5712 cap->nchar = 'u'; | |
5713 nv_operator(cap); | |
5714 } | |
5715 else | |
5716 nv_kundo(cap); | |
5717 } | |
5718 | |
5719 /* | |
5720 * <Undo> command. | |
5721 */ | |
5722 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5723 nv_kundo(cmdarg_T *cap) |
7 | 5724 { |
5725 if (!checkclearopq(cap->oap)) | |
5726 { | |
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
|
5727 #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
|
5728 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
|
5729 { |
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
|
5730 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
|
5731 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
|
5732 } |
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
|
5733 #endif |
7 | 5734 u_undo((int)cap->count1); |
5735 curwin->w_set_curswant = TRUE; | |
5736 } | |
5737 } | |
5738 | |
5739 /* | |
5740 * Handle the "r" command. | |
5741 */ | |
5742 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5743 nv_replace(cmdarg_T *cap) |
7 | 5744 { |
5745 char_u *ptr; | |
5746 int had_ctrl_v; | |
5747 long n; | |
5748 | |
5749 if (checkclearop(cap->oap)) | |
5750 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
|
5751 #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
|
5752 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
|
5753 { |
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
|
5754 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
|
5755 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
|
5756 } |
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
|
5757 #endif |
7 | 5758 |
5759 /* get another character */ | |
5760 if (cap->nchar == Ctrl_V) | |
5761 { | |
5762 had_ctrl_v = Ctrl_V; | |
5763 cap->nchar = get_literal(); | |
5764 /* Don't redo a multibyte character with CTRL-V. */ | |
5765 if (cap->nchar > DEL) | |
5766 had_ctrl_v = NUL; | |
5767 } | |
5768 else | |
5769 had_ctrl_v = NUL; | |
5770 | |
1343 | 5771 /* Abort if the character is a special key. */ |
5772 if (IS_SPECIAL(cap->nchar)) | |
5773 { | |
5774 clearopbeep(cap->oap); | |
5775 return; | |
5776 } | |
5777 | |
7 | 5778 /* Visual mode "r" */ |
5779 if (VIsual_active) | |
5780 { | |
1797 | 5781 if (got_int) |
5782 reset_VIsual(); | |
5428 | 5783 if (had_ctrl_v) |
5784 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
5785 /* 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
|
5786 * 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
|
5787 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
5788 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
|
5789 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
|
5790 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 5791 } |
7 | 5792 nv_operator(cap); |
5793 return; | |
5794 } | |
5795 | |
5796 /* Break tabs, etc. */ | |
5797 if (virtual_active()) | |
5798 { | |
5799 if (u_save_cursor() == FAIL) | |
5800 return; | |
5801 if (gchar_cursor() == NUL) | |
5802 { | |
5803 /* Add extra space and put the cursor on the first one. */ | |
5804 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
5805 curwin->w_cursor.col -= cap->count1; | |
5806 } | |
5807 else if (gchar_cursor() == TAB) | |
5808 coladvance_force(getviscol()); | |
5809 } | |
5810 | |
1343 | 5811 /* Abort if not enough characters to replace. */ |
7 | 5812 ptr = ml_get_cursor(); |
1343 | 5813 if (STRLEN(ptr) < (unsigned)cap->count1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5814 || (has_mbyte && mb_charlen(ptr) < cap->count1)) |
7 | 5815 { |
5816 clearopbeep(cap->oap); | |
5817 return; | |
5818 } | |
5819 | |
5820 /* | |
5821 * Replacing with a TAB is done by edit() when it is complicated because | |
5822 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
5823 * Other characters are done below to avoid problems with things like | |
5824 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
5825 */ | |
5826 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
5827 { | |
5828 stuffnumReadbuff(cap->count1); | |
5829 stuffcharReadbuff('R'); | |
5830 stuffcharReadbuff('\t'); | |
5831 stuffcharReadbuff(ESC); | |
5832 return; | |
5833 } | |
5834 | |
5835 /* save line for undo */ | |
5836 if (u_save_cursor() == FAIL) | |
5837 return; | |
5838 | |
5839 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
5840 { | |
5841 /* | |
5842 * Replace character(s) by a single newline. | |
5843 * Strange vi behaviour: Only one newline is inserted. | |
5844 * Delete the characters here. | |
5845 * Insert the newline with an insert command, takes care of | |
5846 * autoindent. The insert command depends on being on the last | |
5847 * character of a line or not. | |
5848 */ | |
5849 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
5850 stuffcharReadbuff('\r'); | |
5851 stuffcharReadbuff(ESC); | |
5852 | |
5853 /* Give 'r' to edit(), to get the redo command right. */ | |
5854 invoke_edit(cap, TRUE, 'r', FALSE); | |
5855 } | |
5856 else | |
5857 { | |
5858 prep_redo(cap->oap->regname, cap->count1, | |
5859 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
5860 | |
5861 curbuf->b_op_start = curwin->w_cursor; | |
5862 if (has_mbyte) | |
5863 { | |
5864 int old_State = State; | |
5865 | |
5866 if (cap->ncharC1 != 0) | |
5867 AppendCharToRedobuff(cap->ncharC1); | |
5868 if (cap->ncharC2 != 0) | |
5869 AppendCharToRedobuff(cap->ncharC2); | |
5870 | |
5871 /* This is slow, but it handles replacing a single-byte with a | |
5872 * multi-byte and the other way around. Also handles adding | |
5873 * composing characters for utf-8. */ | |
5874 for (n = cap->count1; n > 0; --n) | |
5875 { | |
5876 State = REPLACE; | |
3501 | 5877 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
5878 { | |
5879 int c = ins_copychar(curwin->w_cursor.lnum | |
5880 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
5881 if (c != NUL) | |
5882 ins_char(c); | |
5883 else | |
5884 /* will be decremented further down */ | |
5885 ++curwin->w_cursor.col; | |
5886 } | |
5887 else | |
5888 ins_char(cap->nchar); | |
7 | 5889 State = old_State; |
5890 if (cap->ncharC1 != 0) | |
5891 ins_char(cap->ncharC1); | |
5892 if (cap->ncharC2 != 0) | |
5893 ins_char(cap->ncharC2); | |
5894 } | |
5895 } | |
5896 else | |
5897 { | |
5898 /* | |
5899 * Replace the characters within one line. | |
5900 */ | |
5901 for (n = cap->count1; n > 0; --n) | |
5902 { | |
5903 /* | |
5904 * Get ptr again, because u_save and/or showmatch() will have | |
5905 * released the line. At the same time we let know that the | |
5906 * line will be changed. | |
5907 */ | |
5908 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 5909 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
5910 { | |
5911 int c = ins_copychar(curwin->w_cursor.lnum | |
5912 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
5913 if (c != NUL) | |
5914 ptr[curwin->w_cursor.col] = c; | |
5915 } | |
5916 else | |
5917 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 5918 if (p_sm && msg_silent == 0) |
5919 showmatch(cap->nchar); | |
5920 ++curwin->w_cursor.col; | |
5921 } | |
5922 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5923 if (netbeans_active()) |
7 | 5924 { |
2210 | 5925 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 5926 |
33 | 5927 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 5928 (long)cap->count1); |
7 | 5929 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 5930 &ptr[start], (int)cap->count1); |
7 | 5931 } |
5932 #endif | |
5933 | |
5934 /* mark the buffer as changed and prepare for displaying */ | |
5935 changed_bytes(curwin->w_cursor.lnum, | |
5936 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
5937 } | |
5938 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
5939 /* if the character on the left of the current cursor is a multi-byte | |
5940 * character, move two characters left */ | |
5941 if (has_mbyte) | |
5942 mb_adjust_cursor(); | |
5943 curbuf->b_op_end = curwin->w_cursor; | |
5944 curwin->w_set_curswant = TRUE; | |
5945 set_last_insert(cap->nchar); | |
5946 } | |
5947 } | |
5948 | |
5949 /* | |
5950 * 'o': Exchange start and end of Visual area. | |
5951 * 'O': same, but in block mode exchange left and right corners. | |
5952 */ | |
5953 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5954 v_swap_corners(int cmdchar) |
7 | 5955 { |
5956 pos_T old_cursor; | |
5957 colnr_T left, right; | |
5958 | |
5959 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
5960 { | |
5961 old_cursor = curwin->w_cursor; | |
5962 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
5963 curwin->w_cursor.lnum = VIsual.lnum; | |
5964 coladvance(left); | |
5965 VIsual = curwin->w_cursor; | |
5966 | |
5967 curwin->w_cursor.lnum = old_cursor.lnum; | |
5968 curwin->w_curswant = right; | |
5969 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
5970 * right one column */ | |
5971 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
5972 ++curwin->w_curswant; | |
5973 coladvance(curwin->w_curswant); | |
5974 if (curwin->w_cursor.col == old_cursor.col | |
5975 && (!virtual_active() | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5976 || curwin->w_cursor.coladd == old_cursor.coladd)) |
7 | 5977 { |
5978 curwin->w_cursor.lnum = VIsual.lnum; | |
5979 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
5980 ++right; | |
5981 coladvance(right); | |
5982 VIsual = curwin->w_cursor; | |
5983 | |
5984 curwin->w_cursor.lnum = old_cursor.lnum; | |
5985 coladvance(left); | |
5986 curwin->w_curswant = left; | |
5987 } | |
5988 } | |
5989 else | |
5990 { | |
5991 old_cursor = curwin->w_cursor; | |
5992 curwin->w_cursor = VIsual; | |
5993 VIsual = old_cursor; | |
5994 curwin->w_set_curswant = TRUE; | |
5995 } | |
5996 } | |
5997 | |
5998 /* | |
5999 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
6000 */ | |
6001 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6002 nv_Replace(cmdarg_T *cap) |
7 | 6003 { |
6004 if (VIsual_active) /* "R" is replace lines */ | |
6005 { | |
6006 cap->cmdchar = 'c'; | |
6007 cap->nchar = NUL; | |
4213 | 6008 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 6009 VIsual_mode = 'V'; |
6010 nv_operator(cap); | |
6011 } | |
5735 | 6012 else if (!checkclearopq(cap->oap)) |
7 | 6013 { |
6014 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
|
6015 emsg(_(e_modifiable)); |
7 | 6016 else |
6017 { | |
6018 if (virtual_active()) | |
6019 coladvance(getviscol()); | |
6020 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
6021 } | |
6022 } | |
6023 } | |
6024 | |
6025 /* | |
6026 * "gr". | |
6027 */ | |
6028 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6029 nv_vreplace(cmdarg_T *cap) |
7 | 6030 { |
6031 if (VIsual_active) | |
6032 { | |
6033 cap->cmdchar = 'r'; | |
6034 cap->nchar = cap->extra_char; | |
6035 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
6036 } | |
5735 | 6037 else if (!checkclearopq(cap->oap)) |
7 | 6038 { |
6039 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
|
6040 emsg(_(e_modifiable)); |
7 | 6041 else |
6042 { | |
6043 if (cap->extra_char == Ctrl_V) /* get another character */ | |
6044 cap->extra_char = get_literal(); | |
6045 stuffcharReadbuff(cap->extra_char); | |
6046 stuffcharReadbuff(ESC); | |
6047 if (virtual_active()) | |
6048 coladvance(getviscol()); | |
6049 invoke_edit(cap, TRUE, 'v', FALSE); | |
6050 } | |
6051 } | |
6052 } | |
6053 | |
6054 /* | |
6055 * Swap case for "~" command, when it does not work like an operator. | |
6056 */ | |
6057 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6058 n_swapchar(cmdarg_T *cap) |
7 | 6059 { |
6060 long n; | |
6061 pos_T startpos; | |
6062 int did_change = 0; | |
6063 #ifdef FEAT_NETBEANS_INTG | |
6064 pos_T pos; | |
6065 char_u *ptr; | |
6066 int count; | |
6067 #endif | |
6068 | |
6069 if (checkclearopq(cap->oap)) | |
6070 return; | |
6071 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6072 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 6073 { |
6074 clearopbeep(cap->oap); | |
6075 return; | |
6076 } | |
6077 | |
6078 prep_redo_cmd(cap); | |
6079 | |
6080 if (u_save_cursor() == FAIL) | |
6081 return; | |
6082 | |
6083 startpos = curwin->w_cursor; | |
6084 #ifdef FEAT_NETBEANS_INTG | |
6085 pos = startpos; | |
6086 #endif | |
6087 for (n = cap->count1; n > 0; --n) | |
6088 { | |
6089 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
6090 inc_cursor(); | |
6091 if (gchar_cursor() == NUL) | |
6092 { | |
6093 if (vim_strchr(p_ww, '~') != NULL | |
6094 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6095 { | |
6096 #ifdef FEAT_NETBEANS_INTG | |
2210 | 6097 if (netbeans_active()) |
7 | 6098 { |
6099 if (did_change) | |
6100 { | |
6101 ptr = ml_get(pos.lnum); | |
835 | 6102 count = (int)STRLEN(ptr) - pos.col; |
33 | 6103 netbeans_removed(curbuf, pos.lnum, pos.col, |
6104 (long)count); | |
7 | 6105 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 6106 &ptr[pos.col], count); |
7 | 6107 } |
6108 pos.col = 0; | |
6109 pos.lnum++; | |
6110 } | |
6111 #endif | |
6112 ++curwin->w_cursor.lnum; | |
6113 curwin->w_cursor.col = 0; | |
6114 if (n > 1) | |
6115 { | |
6116 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
6117 break; | |
6118 u_clearline(); | |
6119 } | |
6120 } | |
6121 else | |
6122 break; | |
6123 } | |
6124 } | |
6125 #ifdef FEAT_NETBEANS_INTG | |
2210 | 6126 if (did_change && netbeans_active()) |
7 | 6127 { |
6128 ptr = ml_get(pos.lnum); | |
6129 count = curwin->w_cursor.col - pos.col; | |
33 | 6130 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
6131 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 6132 } |
6133 #endif | |
6134 | |
6135 | |
6136 check_cursor(); | |
6137 curwin->w_set_curswant = TRUE; | |
6138 if (did_change) | |
6139 { | |
6140 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
6141 0L); | |
6142 curbuf->b_op_start = startpos; | |
6143 curbuf->b_op_end = curwin->w_cursor; | |
6144 if (curbuf->b_op_end.col > 0) | |
6145 --curbuf->b_op_end.col; | |
6146 } | |
6147 } | |
6148 | |
6149 /* | |
6150 * Move cursor to mark. | |
6151 */ | |
6152 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6153 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 6154 { |
6155 if (check_mark(pos) == FAIL) | |
6156 clearop(cap->oap); | |
6157 else | |
6158 { | |
6159 if (cap->cmdchar == '\'' | |
6160 || cap->cmdchar == '`' | |
6161 || cap->cmdchar == '[' | |
6162 || cap->cmdchar == ']') | |
6163 setpcmark(); | |
6164 curwin->w_cursor = *pos; | |
6165 if (flag) | |
6166 beginline(BL_WHITE | BL_FIX); | |
6167 else | |
6168 check_cursor(); | |
6169 } | |
6170 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
6171 if (cap->cmdchar == '`') | |
6172 cap->oap->use_reg_one = TRUE; | |
6173 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
6174 curwin->w_set_curswant = TRUE; | |
6175 } | |
6176 | |
6177 /* | |
6178 * Handle commands that are operators in Visual mode. | |
6179 */ | |
6180 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6181 v_visop(cmdarg_T *cap) |
7 | 6182 { |
6183 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
6184 | |
6185 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 6186 * the end of the line, and "C" replaces till EOL */ |
7 | 6187 if (isupper(cap->cmdchar)) |
6188 { | |
6189 if (VIsual_mode != Ctrl_V) | |
4213 | 6190 { |
6191 VIsual_mode_orig = VIsual_mode; | |
7 | 6192 VIsual_mode = 'V'; |
4213 | 6193 } |
7 | 6194 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
6195 curwin->w_curswant = MAXCOL; | |
6196 } | |
6197 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
6198 nv_operator(cap); | |
6199 } | |
6200 | |
6201 /* | |
6202 * "s" and "S" commands. | |
6203 */ | |
6204 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6205 nv_subst(cmdarg_T *cap) |
7 | 6206 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6207 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6208 /* 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
|
6209 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
|
6210 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6211 #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
|
6212 #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
|
6213 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
|
6214 { |
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
|
6215 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
|
6216 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
|
6217 } |
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
|
6218 #endif |
7 | 6219 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
6220 { | |
6221 if (cap->cmdchar == 'S') | |
4213 | 6222 { |
6223 VIsual_mode_orig = VIsual_mode; | |
7 | 6224 VIsual_mode = 'V'; |
4213 | 6225 } |
7 | 6226 cap->cmdchar = 'c'; |
6227 nv_operator(cap); | |
6228 } | |
6229 else | |
6230 nv_optrans(cap); | |
6231 } | |
6232 | |
6233 /* | |
6234 * Abbreviated commands. | |
6235 */ | |
6236 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6237 nv_abbrev(cmdarg_T *cap) |
7 | 6238 { |
6239 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
6240 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
6241 | |
6242 /* in Visual mode these commands are operators */ | |
6243 if (VIsual_active) | |
6244 v_visop(cap); | |
6245 else | |
6246 nv_optrans(cap); | |
6247 } | |
6248 | |
6249 /* | |
6250 * Translate a command into another command. | |
6251 */ | |
6252 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6253 nv_optrans(cmdarg_T *cap) |
7 | 6254 { |
6255 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
6256 (char_u *)"d$", (char_u *)"c$", | |
6257 (char_u *)"cl", (char_u *)"cc", | |
6258 (char_u *)"yy", (char_u *)":s\r"}; | |
6259 static char_u *str = (char_u *)"xXDCsSY&"; | |
6260 | |
6261 if (!checkclearopq(cap->oap)) | |
6262 { | |
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
|
6263 // 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
|
6264 // either, because "2." should also not use the count. |
164 | 6265 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) |
6266 { | |
6267 cap->oap->start = curwin->w_cursor; | |
6268 cap->oap->op_type = OP_DELETE; | |
1490 | 6269 #ifdef FEAT_EVAL |
6270 set_op_var(OP_DELETE); | |
6271 #endif | |
164 | 6272 cap->count1 = 1; |
6273 nv_dollar(cap); | |
6274 finish_op = TRUE; | |
6275 ResetRedobuff(); | |
6276 AppendCharToRedobuff('D'); | |
6277 } | |
6278 else | |
6279 { | |
6280 if (cap->count0) | |
6281 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
|
6282 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); |
164 | 6283 } |
7 | 6284 } |
6285 cap->opcount = 0; | |
6286 } | |
6287 | |
6288 /* | |
6289 * "'" and "`" commands. Also for "g'" and "g`". | |
6290 * cap->arg is TRUE for "'" and "g'". | |
6291 */ | |
6292 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6293 nv_gomark(cmdarg_T *cap) |
7 | 6294 { |
6295 pos_T *pos; | |
6296 int c; | |
6297 #ifdef FEAT_FOLDING | |
4017 | 6298 pos_T old_cursor = curwin->w_cursor; |
7 | 6299 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
6300 #endif | |
6301 | |
6302 if (cap->cmdchar == 'g') | |
6303 c = cap->extra_char; | |
6304 else | |
6305 c = cap->nchar; | |
6306 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
6307 if (pos == (pos_T *)-1) /* jumped to other file */ | |
6308 { | |
6309 if (cap->arg) | |
6310 { | |
6311 check_cursor_lnum(); | |
6312 beginline(BL_WHITE | BL_FIX); | |
6313 } | |
6314 else | |
6315 check_cursor(); | |
6316 } | |
6317 else | |
6318 nv_cursormark(cap, cap->arg, pos); | |
6319 | |
6320 /* May need to clear the coladd that a mark includes. */ | |
6321 if (!virtual_active()) | |
6322 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
|
6323 check_cursor_col(); |
7 | 6324 #ifdef FEAT_FOLDING |
6325 if (cap->oap->op_type == OP_NOP | |
4057 | 6326 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6327 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 6328 && (fdo_flags & FDO_MARK) |
6329 && old_KeyTyped) | |
6330 foldOpenCursor(); | |
6331 #endif | |
6332 } | |
6333 | |
6334 /* | |
6335 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
6336 */ | |
6337 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6338 nv_pcmark(cmdarg_T *cap) |
7 | 6339 { |
6340 #ifdef FEAT_JUMPLIST | |
6341 pos_T *pos; | |
6342 # ifdef FEAT_FOLDING | |
6343 linenr_T lnum = curwin->w_cursor.lnum; | |
6344 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
6345 # endif | |
6346 | |
6347 if (!checkclearopq(cap->oap)) | |
6348 { | |
6349 if (cap->cmdchar == 'g') | |
6350 pos = movechangelist((int)cap->count1); | |
6351 else | |
6352 pos = movemark((int)cap->count1); | |
6353 if (pos == (pos_T *)-1) /* jump to other file */ | |
6354 { | |
6355 curwin->w_set_curswant = TRUE; | |
6356 check_cursor(); | |
6357 } | |
6358 else if (pos != NULL) /* can jump */ | |
6359 nv_cursormark(cap, FALSE, pos); | |
6360 else if (cap->cmdchar == 'g') | |
6361 { | |
6362 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
|
6363 emsg(_("E664: changelist is empty")); |
7 | 6364 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
|
6365 emsg(_("E662: At start of changelist")); |
7 | 6366 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
6367 emsg(_("E663: At end of changelist")); |
7 | 6368 } |
6369 else | |
6370 clearopbeep(cap->oap); | |
6371 # ifdef FEAT_FOLDING | |
6372 if (cap->oap->op_type == OP_NOP | |
6373 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
6374 && (fdo_flags & FDO_MARK) | |
6375 && old_KeyTyped) | |
6376 foldOpenCursor(); | |
6377 # endif | |
6378 } | |
6379 #else | |
6380 clearopbeep(cap->oap); | |
6381 #endif | |
6382 } | |
6383 | |
6384 /* | |
6385 * Handle '"' 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_regname(cmdarg_T *cap) |
7 | 6389 { |
6390 if (checkclearop(cap->oap)) | |
6391 return; | |
6392 #ifdef FEAT_EVAL | |
6393 if (cap->nchar == '=') | |
6394 cap->nchar = get_expr_register(); | |
6395 #endif | |
6396 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
6397 { | |
6398 cap->oap->regname = cap->nchar; | |
6399 cap->opcount = cap->count0; /* remember count before '"' */ | |
6400 #ifdef FEAT_EVAL | |
6401 set_reg_var(cap->oap->regname); | |
6402 #endif | |
6403 } | |
6404 else | |
6405 clearopbeep(cap->oap); | |
6406 } | |
6407 | |
6408 /* | |
6409 * Handle "v", "V" and "CTRL-V" commands. | |
6410 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
6411 * is TRUE. | |
167 | 6412 * Handle CTRL-Q just like CTRL-V. |
7 | 6413 */ |
6414 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6415 nv_visual(cmdarg_T *cap) |
7 | 6416 { |
167 | 6417 if (cap->cmdchar == Ctrl_Q) |
6418 cap->cmdchar = Ctrl_V; | |
6419 | |
7 | 6420 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
6421 * characterwise, linewise, or blockwise. */ | |
6422 if (cap->oap->op_type != OP_NOP) | |
6423 { | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
6424 motion_force = cap->oap->motion_force = cap->cmdchar; |
7 | 6425 finish_op = FALSE; /* operator doesn't finish now but later */ |
6426 return; | |
6427 } | |
6428 | |
6429 VIsual_select = cap->arg; | |
6430 if (VIsual_active) /* change Visual mode */ | |
6431 { | |
6432 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
6433 end_visual_mode(); | |
6434 else /* toggle char/block mode */ | |
6435 { /* or char/line mode */ | |
6436 VIsual_mode = cap->cmdchar; | |
6437 showmode(); | |
6438 } | |
6439 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
6440 } | |
6441 else /* start Visual mode */ | |
6442 { | |
6443 check_visual_highlight(); | |
3537 | 6444 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
6445 { | |
6446 /* use previously selected part */ | |
7 | 6447 VIsual = curwin->w_cursor; |
6448 | |
6449 VIsual_active = TRUE; | |
6450 VIsual_reselect = TRUE; | |
6451 if (!cap->arg) | |
6452 /* start Select mode when 'selectmode' contains "cmd" */ | |
6453 may_start_select('c'); | |
6454 setmouse(); | |
641 | 6455 if (p_smd && msg_silent == 0) |
7 | 6456 redraw_cmdline = TRUE; /* show visual mode later */ |
6457 /* | |
6458 * For V and ^V, we multiply the number of lines even if there | |
6459 * was only one -- webb | |
6460 */ | |
6461 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
6462 { | |
6463 curwin->w_cursor.lnum += | |
6464 resel_VIsual_line_count * cap->count0 - 1; | |
6465 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6466 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6467 } | |
6468 VIsual_mode = resel_VIsual_mode; | |
6469 if (VIsual_mode == 'v') | |
6470 { | |
6471 if (resel_VIsual_line_count <= 1) | |
3125 | 6472 { |
6473 validate_virtcol(); | |
6474 curwin->w_curswant = curwin->w_virtcol | |
6475 + resel_VIsual_vcol * cap->count0 - 1; | |
6476 } | |
7 | 6477 else |
3125 | 6478 curwin->w_curswant = resel_VIsual_vcol; |
6479 coladvance(curwin->w_curswant); | |
7 | 6480 } |
3125 | 6481 if (resel_VIsual_vcol == MAXCOL) |
7 | 6482 { |
6483 curwin->w_curswant = MAXCOL; | |
6484 coladvance((colnr_T)MAXCOL); | |
6485 } | |
6486 else if (VIsual_mode == Ctrl_V) | |
6487 { | |
6488 validate_virtcol(); | |
6489 curwin->w_curswant = curwin->w_virtcol | |
3125 | 6490 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 6491 coladvance(curwin->w_curswant); |
6492 } | |
6493 else | |
6494 curwin->w_set_curswant = TRUE; | |
6495 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
6496 } | |
6497 else | |
6498 { | |
6499 if (!cap->arg) | |
6500 /* start Select mode when 'selectmode' contains "cmd" */ | |
6501 may_start_select('c'); | |
6502 n_start_visual_mode(cap->cmdchar); | |
3537 | 6503 if (VIsual_mode != 'V' && *p_sel == 'e') |
6504 ++cap->count1; /* include one more char */ | |
6505 if (cap->count0 > 0 && --cap->count1 > 0) | |
6506 { | |
6507 /* With a count select that many characters or lines. */ | |
6508 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
6509 nv_right(cap); | |
6510 else if (VIsual_mode == 'V') | |
6511 nv_down(cap); | |
6512 } | |
7 | 6513 } |
6514 } | |
6515 } | |
6516 | |
6517 /* | |
6518 * Start selection for Shift-movement keys. | |
6519 */ | |
6520 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6521 start_selection(void) |
7 | 6522 { |
6523 /* if 'selectmode' contains "key", start Select mode */ | |
6524 may_start_select('k'); | |
6525 n_start_visual_mode('v'); | |
6526 } | |
6527 | |
6528 /* | |
6529 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
6530 */ | |
6531 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6532 may_start_select(int c) |
7 | 6533 { |
6534 VIsual_select = (stuff_empty() && typebuf_typed() | |
6535 && (vim_strchr(p_slm, c) != NULL)); | |
6536 } | |
6537 | |
6538 /* | |
6539 * Start Visual mode "c". | |
6540 * Should set VIsual_select before calling this. | |
6541 */ | |
6542 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6543 n_start_visual_mode(int c) |
7 | 6544 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
6545 #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
|
6546 /* Check for redraw before changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
6547 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
|
6548 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
6549 |
7 | 6550 VIsual_mode = c; |
6551 VIsual_active = TRUE; | |
6552 VIsual_reselect = TRUE; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
6553 |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
6554 // 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
|
6555 // virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. |
7 | 6556 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) |
3742 | 6557 { |
6558 validate_virtcol(); | |
7 | 6559 coladvance(curwin->w_virtcol); |
3742 | 6560 } |
7 | 6561 VIsual = curwin->w_cursor; |
6562 | |
6563 #ifdef FEAT_FOLDING | |
6564 foldAdjustVisual(); | |
6565 #endif | |
6566 | |
6567 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
|
6568 #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
|
6569 /* Check for redraw after changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
6570 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
|
6571 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
6572 |
641 | 6573 if (p_smd && msg_silent == 0) |
7 | 6574 redraw_cmdline = TRUE; /* show visual mode later */ |
6575 #ifdef FEAT_CLIPBOARD | |
6576 /* Make sure the clipboard gets updated. Needed because start and | |
6577 * end may still be the same, and the selection needs to be owned */ | |
6578 clip_star.vmode = NUL; | |
6579 #endif | |
6580 | |
6581 /* Only need to redraw this line, unless still need to redraw an old | |
6582 * Visual area (when 'lazyredraw' is set). */ | |
6583 if (curwin->w_redr_type < INVERTED) | |
6584 { | |
6585 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
6586 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
6587 } | |
6588 } | |
6589 | |
6590 | |
6591 /* | |
6592 * CTRL-W: Window commands | |
6593 */ | |
6594 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6595 nv_window(cmdarg_T *cap) |
7 | 6596 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
6597 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
6598 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
6599 /* "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
|
6600 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
6601 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
|
6602 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
6603 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
6604 else if (!checkclearop(cap->oap)) |
7 | 6605 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
6606 } | |
6607 | |
6608 /* | |
6609 * CTRL-Z: Suspend | |
6610 */ | |
6611 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6612 nv_suspend(cmdarg_T *cap) |
7 | 6613 { |
6614 clearop(cap->oap); | |
6615 if (VIsual_active) | |
6616 end_visual_mode(); /* stop Visual mode */ | |
6617 do_cmdline_cmd((char_u *)"st"); | |
6618 } | |
6619 | |
6620 /* | |
6621 * Commands starting with "g". | |
6622 */ | |
6623 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6624 nv_g_cmd(cmdarg_T *cap) |
7 | 6625 { |
6626 oparg_T *oap = cap->oap; | |
6627 pos_T tpos; | |
6628 int i; | |
6629 int flag = FALSE; | |
6630 | |
6631 switch (cap->nchar) | |
6632 { | |
6868 | 6633 case Ctrl_A: |
6634 case Ctrl_X: | |
7 | 6635 #ifdef MEM_PROFILE |
6636 /* | |
6637 * "g^A": dump log of used memory. | |
6638 */ | |
6868 | 6639 if (!VIsual_active && cap->nchar == Ctrl_A) |
6640 vim_mem_profile_dump(); | |
6641 else | |
6642 #endif | |
6643 /* | |
6644 * "g^A/g^X": sequentially increment visually selected region | |
6645 */ | |
6646 if (VIsual_active) | |
6647 { | |
6648 cap->arg = TRUE; | |
6649 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
6650 cap->nchar = NUL; |
6868 | 6651 nv_addsub(cap); |
6652 } | |
6653 else | |
6654 clearopbeep(oap); | |
7 | 6655 break; |
6656 | |
6657 /* | |
6658 * "gR": Enter virtual replace mode. | |
6659 */ | |
6660 case 'R': | |
6661 cap->arg = TRUE; | |
6662 nv_Replace(cap); | |
6663 break; | |
6664 | |
6665 case 'r': | |
6666 nv_vreplace(cap); | |
6667 break; | |
6668 | |
6669 case '&': | |
6670 do_cmdline_cmd((char_u *)"%s//~/&"); | |
6671 break; | |
6672 | |
6673 /* | |
6674 * "gv": Reselect the previous Visual area. If Visual already active, | |
6675 * exchange previous and current Visual area. | |
6676 */ | |
6677 case 'v': | |
6678 if (checkclearop(oap)) | |
6679 break; | |
6680 | |
690 | 6681 if ( curbuf->b_visual.vi_start.lnum == 0 |
6682 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
6683 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 6684 beep_flush(); |
6685 else | |
6686 { | |
6687 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
6688 if (VIsual_active) | |
6689 { | |
6690 i = VIsual_mode; | |
690 | 6691 VIsual_mode = curbuf->b_visual.vi_mode; |
6692 curbuf->b_visual.vi_mode = i; | |
7 | 6693 # ifdef FEAT_EVAL |
6694 curbuf->b_visual_mode_eval = i; | |
6695 # endif | |
6696 i = curwin->w_curswant; | |
690 | 6697 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
6698 curbuf->b_visual.vi_curswant = i; | |
6699 | |
6700 tpos = curbuf->b_visual.vi_end; | |
6701 curbuf->b_visual.vi_end = curwin->w_cursor; | |
6702 curwin->w_cursor = curbuf->b_visual.vi_start; | |
6703 curbuf->b_visual.vi_start = VIsual; | |
7 | 6704 } |
6705 else | |
6706 { | |
690 | 6707 VIsual_mode = curbuf->b_visual.vi_mode; |
6708 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
6709 tpos = curbuf->b_visual.vi_end; | |
6710 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 6711 } |
6712 | |
6713 VIsual_active = TRUE; | |
6714 VIsual_reselect = TRUE; | |
6715 | |
6716 /* Set Visual to the start and w_cursor to the end of the Visual | |
6717 * area. Make sure they are on an existing character. */ | |
6718 check_cursor(); | |
6719 VIsual = curwin->w_cursor; | |
6720 curwin->w_cursor = tpos; | |
6721 check_cursor(); | |
6722 update_topline(); | |
6723 /* | |
6724 * When called from normal "g" command: start Select mode when | |
6725 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
6726 * start Select mode. | |
6727 */ | |
6728 if (cap->arg) | |
6729 VIsual_select = TRUE; | |
6730 else | |
6731 may_start_select('c'); | |
6732 setmouse(); | |
6733 #ifdef FEAT_CLIPBOARD | |
6734 /* Make sure the clipboard gets updated. Needed because start and | |
6735 * end are still the same, and the selection needs to be owned */ | |
6736 clip_star.vmode = NUL; | |
6737 #endif | |
6738 redraw_curbuf_later(INVERTED); | |
6739 showmode(); | |
6740 } | |
6741 break; | |
6742 /* | |
6743 * "gV": Don't reselect the previous Visual area after a Select mode | |
6744 * mapping of menu. | |
6745 */ | |
6746 case 'V': | |
6747 VIsual_reselect = FALSE; | |
6748 break; | |
6749 | |
6750 /* | |
6751 * "gh": start Select mode. | |
6752 * "gH": start Select line mode. | |
6753 * "g^H": start Select block mode. | |
6754 */ | |
6755 case K_BS: | |
6756 cap->nchar = Ctrl_H; | |
6757 /* FALLTHROUGH */ | |
6758 case 'h': | |
6759 case 'H': | |
6760 case Ctrl_H: | |
6761 # ifdef EBCDIC | |
6762 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
6763 if (cap->nchar == Ctrl_H) | |
6764 cap->cmdchar = Ctrl_V; | |
6765 else | |
6766 # endif | |
6767 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
6768 cap->arg = TRUE; | |
6769 nv_visual(cap); | |
6770 break; | |
3701 | 6771 |
6772 /* "gn", "gN" visually select next/previous search match | |
6773 * "gn" selects next match | |
6774 * "gN" selects previous match | |
6775 */ | |
6776 case 'N': | |
6777 case 'n': | |
6778 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 6779 clearopbeep(oap); |
3701 | 6780 break; |
7 | 6781 |
6782 /* | |
6783 * "gj" and "gk" two new funny movement keys -- up and down | |
6784 * movement based on *screen* line rather than *file* line. | |
6785 */ | |
6786 case 'j': | |
6787 case K_DOWN: | |
6788 /* with 'nowrap' it works just like the normal "j" command; also when | |
6789 * in a closed fold */ | |
6790 if (!curwin->w_p_wrap | |
6791 #ifdef FEAT_FOLDING | |
6792 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
6793 #endif | |
6794 ) | |
6795 { | |
6796 oap->motion_type = MLINE; | |
6797 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
6798 } | |
6799 else | |
6800 i = nv_screengo(oap, FORWARD, cap->count1); | |
6801 if (i == FAIL) | |
6802 clearopbeep(oap); | |
6803 break; | |
6804 | |
6805 case 'k': | |
6806 case K_UP: | |
6807 /* with 'nowrap' it works just like the normal "k" command; also when | |
6808 * in a closed fold */ | |
6809 if (!curwin->w_p_wrap | |
6810 #ifdef FEAT_FOLDING | |
6811 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
6812 #endif | |
6813 ) | |
6814 { | |
6815 oap->motion_type = MLINE; | |
6816 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
6817 } | |
6818 else | |
6819 i = nv_screengo(oap, BACKWARD, cap->count1); | |
6820 if (i == FAIL) | |
6821 clearopbeep(oap); | |
6822 break; | |
6823 | |
6824 /* | |
6825 * "gJ": join two lines without inserting a space. | |
6826 */ | |
6827 case 'J': | |
6828 nv_join(cap); | |
6829 break; | |
6830 | |
6831 /* | |
6832 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
6833 * "gm": middle of "g0" and "g$". | |
6834 */ | |
6835 case '^': | |
6836 flag = TRUE; | |
6837 /* FALLTHROUGH */ | |
6838 | |
6839 case '0': | |
6840 case 'm': | |
6841 case K_HOME: | |
6842 case K_KHOME: | |
6843 oap->motion_type = MCHAR; | |
6844 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
|
6845 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 6846 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6847 int width1 = curwin->w_width - curwin_col_off(); |
7 | 6848 int width2 = width1 + curwin_col_off2(); |
6849 | |
6850 validate_virtcol(); | |
6851 i = 0; | |
6852 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
6853 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
6854 } | |
6855 else | |
6856 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
6857 /* 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
|
6858 * '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
|
6859 * to the left. */ |
7 | 6860 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
|
6861 i += (curwin->w_width - curwin_col_off() |
7 | 6862 + ((curwin->w_p_wrap && i > 0) |
6863 ? curwin_col_off2() : 0)) / 2; | |
6864 coladvance((colnr_T)i); | |
6865 if (flag) | |
6866 { | |
6867 do | |
6868 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
6869 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
|
6870 curwin->w_valid &= ~VALID_WCOL; |
7 | 6871 } |
6872 curwin->w_set_curswant = TRUE; | |
6873 break; | |
6874 | |
6875 case '_': | |
6876 /* "g_": to the last non-blank character in the line or <count> lines | |
6877 * downward. */ | |
6878 cap->oap->motion_type = MCHAR; | |
6879 cap->oap->inclusive = TRUE; | |
6880 curwin->w_curswant = MAXCOL; | |
6881 if (cursor_down((long)(cap->count1 - 1), | |
6882 cap->oap->op_type == OP_NOP) == FAIL) | |
6883 clearopbeep(cap->oap); | |
6884 else | |
6885 { | |
6886 char_u *ptr = ml_get_curline(); | |
6887 | |
6888 /* In Visual mode we may end up after the line. */ | |
6889 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
6890 --curwin->w_cursor.col; | |
6891 | |
6892 /* Decrease the cursor column until it's on a non-blank. */ | |
6893 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
|
6894 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 6895 --curwin->w_cursor.col; |
6896 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
6897 adjust_for_sel(cap); |
7 | 6898 } |
6899 break; | |
6900 | |
6901 case '$': | |
6902 case K_END: | |
6903 case K_KEND: | |
6904 { | |
6905 int col_off = curwin_col_off(); | |
6906 | |
6907 oap->motion_type = MCHAR; | |
6908 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
|
6909 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 6910 { |
6911 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6912 if (cap->count1 == 1) | |
6913 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6914 int width1 = curwin->w_width - col_off; |
7 | 6915 int width2 = width1 + curwin_col_off2(); |
6916 | |
6917 validate_virtcol(); | |
6918 i = width1 - 1; | |
6919 if (curwin->w_virtcol >= (colnr_T)width1) | |
6920 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
6921 * width2; | |
6922 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6923 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6924 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6925 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6926 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6927 curwin->w_set_curswant = FALSE; |
7 | 6928 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
6929 { | |
6930 /* | |
6931 * Check for landing on a character that got split at | |
6932 * the end of the line. We do not want to advance to | |
6933 * the next screen line. | |
6934 */ | |
6935 if (curwin->w_virtcol > (colnr_T)i) | |
6936 --curwin->w_cursor.col; | |
6937 } | |
6938 } | |
6939 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
6940 clearopbeep(oap); | |
6941 } | |
6942 else | |
6943 { | |
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
|
6944 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
|
6945 // 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
|
6946 (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
|
6947 |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6948 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 6949 coladvance((colnr_T)i); |
40 | 6950 |
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
|
6951 // Make sure we stick in this column. |
40 | 6952 validate_virtcol(); |
6953 curwin->w_curswant = curwin->w_virtcol; | |
6954 curwin->w_set_curswant = FALSE; | |
7 | 6955 } |
6956 } | |
6957 break; | |
6958 | |
6959 /* | |
6960 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
6961 */ | |
6962 case '*': | |
6963 case '#': | |
6964 #if POUND != '#' | |
6965 case POUND: /* pound sign (sometimes equal to '#') */ | |
6966 #endif | |
6967 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
6968 case ']': /* :tselect for current identifier */ | |
6969 nv_ident(cap); | |
6970 break; | |
6971 | |
6972 /* | |
6973 * ge and gE: go back to end of word | |
6974 */ | |
6975 case 'e': | |
6976 case 'E': | |
6977 oap->motion_type = MCHAR; | |
6978 curwin->w_set_curswant = TRUE; | |
6979 oap->inclusive = TRUE; | |
6980 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
6981 clearopbeep(oap); | |
6982 break; | |
6983 | |
6984 /* | |
6985 * "g CTRL-G": display info about cursor position | |
6986 */ | |
6987 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
6988 cursor_pos_info(NULL); |
7 | 6989 break; |
6990 | |
6991 /* | |
6992 * "gi": start Insert at the last position. | |
6993 */ | |
6994 case 'i': | |
6995 if (curbuf->b_last_insert.lnum != 0) | |
6996 { | |
6997 curwin->w_cursor = curbuf->b_last_insert; | |
6998 check_cursor_lnum(); | |
6999 i = (int)STRLEN(ml_get_curline()); | |
7000 if (curwin->w_cursor.col > (colnr_T)i) | |
7001 { | |
7002 if (virtual_active()) | |
7003 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
7004 curwin->w_cursor.col = i; | |
7005 } | |
7006 } | |
7007 cap->cmdchar = 'i'; | |
7008 nv_edit(cap); | |
7009 break; | |
7010 | |
7011 /* | |
7012 * "gI": Start insert in column 1. | |
7013 */ | |
7014 case 'I': | |
7015 beginline(0); | |
7016 if (!checkclearopq(oap)) | |
7017 invoke_edit(cap, FALSE, 'g', FALSE); | |
7018 break; | |
7019 | |
7020 #ifdef FEAT_SEARCHPATH | |
7021 /* | |
7022 * "gf": goto file, edit file under cursor | |
7023 * "]f" and "[f": can also be used. | |
7024 */ | |
7025 case 'f': | |
681 | 7026 case 'F': |
7 | 7027 nv_gotofile(cap); |
7028 break; | |
7029 #endif | |
7030 | |
7031 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
7032 case '\'': | |
7033 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
7034 /* FALLTHROUGH */ |
7 | 7035 case '`': |
7036 nv_gomark(cap); | |
7037 break; | |
7038 | |
7039 /* | |
7040 * "gs": Goto sleep. | |
7041 */ | |
7042 case 's': | |
7043 do_sleep(cap->count1 * 1000L); | |
7044 break; | |
7045 | |
7046 /* | |
7047 * "ga": Display the ascii value of the character under the | |
7048 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
7049 */ | |
7050 case 'a': | |
7051 do_ascii(NULL); | |
7052 break; | |
7053 | |
7054 /* | |
7055 * "g8": Display the bytes used for the UTF-8 character under the | |
7056 * cursor. It is displayed in hex. | |
775 | 7057 * "8g8" finds illegal byte sequence. |
7 | 7058 */ |
7059 case '8': | |
775 | 7060 if (cap->count0 == 8) |
7061 utf_find_illegal(); | |
7062 else | |
7063 show_utf8(); | |
7 | 7064 break; |
7065 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
7066 /* "g<": show scrollback text */ |
447 | 7067 case '<': |
7068 show_sb_text(); | |
7069 break; | |
7070 | |
7 | 7071 /* |
7072 * "gg": Goto the first line in file. With a count it goes to | |
7073 * that line number like for "G". -- webb | |
7074 */ | |
7075 case 'g': | |
7076 cap->arg = FALSE; | |
7077 nv_goto(cap); | |
7078 break; | |
7079 | |
7080 /* | |
7081 * Two-character operators: | |
7082 * "gq" Format text | |
7083 * "gw" Format text and keep cursor position | |
7084 * "g~" Toggle the case of the text. | |
7085 * "gu" Change text to lower case. | |
7086 * "gU" Change text to upper case. | |
7087 * "g?" rot13 encoding | |
602 | 7088 * "g@" call 'operatorfunc' |
7 | 7089 */ |
7090 case 'q': | |
7091 case 'w': | |
7092 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
|
7093 /* FALLTHROUGH */ |
7 | 7094 case '~': |
7095 case 'u': | |
7096 case 'U': | |
7097 case '?': | |
602 | 7098 case '@': |
7 | 7099 nv_operator(cap); |
7100 break; | |
7101 | |
7102 /* | |
1188 | 7103 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 7104 * current function |
7105 * "gD": idem, but in the current file. | |
7106 */ | |
7107 case 'd': | |
7108 case 'D': | |
523 | 7109 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 7110 break; |
7111 | |
7112 #ifdef FEAT_MOUSE | |
7113 /* | |
7114 * g<*Mouse> : <C-*mouse> | |
7115 */ | |
7116 case K_MIDDLEMOUSE: | |
7117 case K_MIDDLEDRAG: | |
7118 case K_MIDDLERELEASE: | |
7119 case K_LEFTMOUSE: | |
7120 case K_LEFTDRAG: | |
7121 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
7122 case K_MOUSEMOVE: |
7 | 7123 case K_RIGHTMOUSE: |
7124 case K_RIGHTDRAG: | |
7125 case K_RIGHTRELEASE: | |
7126 case K_X1MOUSE: | |
7127 case K_X1DRAG: | |
7128 case K_X1RELEASE: | |
7129 case K_X2MOUSE: | |
7130 case K_X2DRAG: | |
7131 case K_X2RELEASE: | |
7132 mod_mask = MOD_MASK_CTRL; | |
7133 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
7134 break; | |
7135 #endif | |
7136 | |
7137 case K_IGNORE: | |
7138 break; | |
7139 | |
7140 /* | |
7141 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
7142 */ | |
7143 case 'p': | |
7144 case 'P': | |
7145 nv_put(cap); | |
7146 break; | |
7147 | |
7148 #ifdef FEAT_BYTEOFF | |
7149 /* "go": goto byte count from start of buffer */ | |
7150 case 'o': | |
7151 goto_byte(cap->count0); | |
7152 break; | |
7153 #endif | |
7154 | |
7155 /* "gQ": improved Ex mode */ | |
7156 case 'Q': | |
633 | 7157 if (text_locked()) |
7 | 7158 { |
7159 clearopbeep(cap->oap); | |
633 | 7160 text_locked_msg(); |
7 | 7161 break; |
7162 } | |
631 | 7163 |
7 | 7164 if (!checkclearopq(oap)) |
7165 do_exmode(TRUE); | |
7166 break; | |
7167 | |
7168 #ifdef FEAT_JUMPLIST | |
7169 case ',': | |
7170 nv_pcmark(cap); | |
7171 break; | |
7172 | |
7173 case ';': | |
7174 cap->count1 = -cap->count1; | |
7175 nv_pcmark(cap); | |
7176 break; | |
7177 #endif | |
7178 | |
667 | 7179 case 't': |
3630 | 7180 if (!checkclearop(oap)) |
7181 goto_tabpage((int)cap->count0); | |
667 | 7182 break; |
682 | 7183 case 'T': |
3630 | 7184 if (!checkclearop(oap)) |
7185 goto_tabpage(-(int)cap->count1); | |
682 | 7186 break; |
667 | 7187 |
750 | 7188 case '+': |
7189 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
7190 if (!checkclearopq(oap)) | |
771 | 7191 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
|
7192 FALSE, FALSE, FALSE); |
750 | 7193 break; |
7194 | |
7 | 7195 default: |
7196 clearopbeep(oap); | |
7197 break; | |
7198 } | |
7199 } | |
7200 | |
7201 /* | |
7202 * Handle "o" and "O" commands. | |
7203 */ | |
7204 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7205 n_opencmd(cmdarg_T *cap) |
7 | 7206 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7207 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7208 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7209 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7210 |
7 | 7211 if (!checkclearopq(cap->oap)) |
7212 { | |
7213 #ifdef FEAT_FOLDING | |
7214 if (cap->cmdchar == 'O') | |
7215 /* Open above the first line of a folded sequence of lines */ | |
7216 (void)hasFolding(curwin->w_cursor.lnum, | |
7217 &curwin->w_cursor.lnum, NULL); | |
7218 else | |
7219 /* Open below the last line of a folded sequence of lines */ | |
7220 (void)hasFolding(curwin->w_cursor.lnum, | |
7221 NULL, &curwin->w_cursor.lnum); | |
7222 #endif | |
7223 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
7224 (cap->cmdchar == 'O' ? 1 : 0)), | |
7225 (linenr_T)(curwin->w_cursor.lnum + | |
7226 (cap->cmdchar == 'o' ? 1 : 0)) | |
7227 ) == OK | |
7228 && 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
|
7229 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
|
7230 0) == OK) |
7 | 7231 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7232 #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
|
7233 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
|
7234 redrawWinline(curwin, oldline); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7235 #endif |
6834 | 7236 #ifdef FEAT_SYN_HL |
6821 | 7237 if (curwin->w_p_cul) |
7238 /* force redraw of cursorline */ | |
7239 curwin->w_valid &= ~VALID_CROW; | |
6834 | 7240 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7241 /* 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
|
7242 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
|
7243 cap->count1 = 1; |
7 | 7244 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
7245 } | |
7246 } | |
7247 } | |
7248 | |
7249 /* | |
7250 * "." command: redo last change. | |
7251 */ | |
7252 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7253 nv_dot(cmdarg_T *cap) |
7 | 7254 { |
7255 if (!checkclearopq(cap->oap)) | |
7256 { | |
7257 /* | |
7258 * If "restart_edit" is TRUE, the last but one command is repeated | |
7259 * instead of the last command (inserting text). This is used for | |
7260 * CTRL-O <.> in insert mode. | |
7261 */ | |
7262 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
7263 clearopbeep(cap->oap); | |
7264 } | |
7265 } | |
7266 | |
7267 /* | |
7268 * CTRL-R: undo undo | |
7269 */ | |
7270 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7271 nv_redo(cmdarg_T *cap) |
7 | 7272 { |
7273 if (!checkclearopq(cap->oap)) | |
7274 { | |
7275 u_redo((int)cap->count1); | |
7276 curwin->w_set_curswant = TRUE; | |
7277 } | |
7278 } | |
7279 | |
7280 /* | |
7281 * Handle "U" command. | |
7282 */ | |
7283 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7284 nv_Undo(cmdarg_T *cap) |
7 | 7285 { |
7286 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 7287 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 7288 { |
7289 /* translate "gUU" to "gUgU" */ | |
7290 cap->cmdchar = 'g'; | |
7291 cap->nchar = 'U'; | |
7292 nv_operator(cap); | |
7293 } | |
7294 else if (!checkclearopq(cap->oap)) | |
7295 { | |
7296 u_undoline(); | |
7297 curwin->w_set_curswant = TRUE; | |
7298 } | |
7299 } | |
7300 | |
7301 /* | |
7302 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
7303 * single character. | |
7304 */ | |
7305 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7306 nv_tilde(cmdarg_T *cap) |
7 | 7307 { |
5735 | 7308 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
|
7309 { |
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
|
7310 #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
|
7311 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
|
7312 { |
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
|
7313 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
|
7314 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
|
7315 } |
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
|
7316 #endif |
7 | 7317 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
|
7318 } |
7 | 7319 else |
7320 nv_operator(cap); | |
7321 } | |
7322 | |
7323 /* | |
7324 * Handle an operator command. | |
7325 * The actual work is done by do_pending_operator(). | |
7326 */ | |
7327 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7328 nv_operator(cmdarg_T *cap) |
7 | 7329 { |
7330 int op_type; | |
7331 | |
7332 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
|
7333 #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
|
7334 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
|
7335 { |
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
|
7336 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
|
7337 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
|
7338 } |
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
|
7339 #endif |
7 | 7340 |
7341 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
7342 nv_lineop(cap); | |
7343 else if (!checkclearop(cap->oap)) | |
7344 { | |
7345 cap->oap->start = curwin->w_cursor; | |
7346 cap->oap->op_type = op_type; | |
1490 | 7347 #ifdef FEAT_EVAL |
7348 set_op_var(op_type); | |
7349 #endif | |
7350 } | |
7351 } | |
7352 | |
7353 #ifdef FEAT_EVAL | |
7354 /* | |
7355 * Set v:operator to the characters for "optype". | |
7356 */ | |
7357 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7358 set_op_var(int optype) |
1490 | 7359 { |
7360 char_u opchars[3]; | |
7361 | |
7362 if (optype == OP_NOP) | |
7363 set_vim_var_string(VV_OP, NULL, 0); | |
7364 else | |
7365 { | |
7366 opchars[0] = get_op_char(optype); | |
7367 opchars[1] = get_extra_op_char(optype); | |
7368 opchars[2] = NUL; | |
7369 set_vim_var_string(VV_OP, opchars, -1); | |
7370 } | |
7371 } | |
7372 #endif | |
7 | 7373 |
7374 /* | |
7375 * Handle linewise operator "dd", "yy", etc. | |
7376 * | |
7377 * "_" is is a strange motion command that helps make operators more logical. | |
7378 * It is actually implemented, but not documented in the real Vi. This motion | |
7379 * command actually refers to "the current line". Commands like "dd" and "yy" | |
7380 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
7381 * "d3_" works to delete 3 lines. | |
7382 */ | |
7383 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7384 nv_lineop(cmdarg_T *cap) |
7 | 7385 { |
7386 cap->oap->motion_type = MLINE; | |
7387 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
7388 clearopbeep(cap->oap); | |
4011 | 7389 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
7390 && cap->oap->motion_force != 'v' | |
7391 && cap->oap->motion_force != Ctrl_V) | |
7 | 7392 || cap->oap->op_type == OP_LSHIFT |
7393 || cap->oap->op_type == OP_RSHIFT) | |
7394 beginline(BL_SOL | BL_FIX); | |
7395 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
7396 beginline(BL_WHITE | BL_FIX); | |
7397 } | |
7398 | |
7399 /* | |
7400 * <Home> command. | |
7401 */ | |
7402 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7403 nv_home(cmdarg_T *cap) |
7 | 7404 { |
180 | 7405 /* CTRL-HOME is like "gg" */ |
7406 if (mod_mask & MOD_MASK_CTRL) | |
7407 nv_goto(cap); | |
7408 else | |
7409 { | |
7410 cap->count0 = 1; | |
7411 nv_pipe(cap); | |
7412 } | |
229 | 7413 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
7414 one-character line). */ | |
7 | 7415 } |
7416 | |
7417 /* | |
7418 * "|" command. | |
7419 */ | |
7420 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7421 nv_pipe(cmdarg_T *cap) |
7 | 7422 { |
7423 cap->oap->motion_type = MCHAR; | |
7424 cap->oap->inclusive = FALSE; | |
7425 beginline(0); | |
7426 if (cap->count0 > 0) | |
7427 { | |
7428 coladvance((colnr_T)(cap->count0 - 1)); | |
7429 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
7430 } | |
7431 else | |
7432 curwin->w_curswant = 0; | |
7433 /* keep curswant at the column where we wanted to go, not where | |
2667 | 7434 * we ended; differs if line is too short */ |
7 | 7435 curwin->w_set_curswant = FALSE; |
7436 } | |
7437 | |
7438 /* | |
7439 * Handle back-word command "b" and "B". | |
7440 * cap->arg is 1 for "B" | |
7441 */ | |
7442 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7443 nv_bck_word(cmdarg_T *cap) |
7 | 7444 { |
7445 cap->oap->motion_type = MCHAR; | |
7446 cap->oap->inclusive = FALSE; | |
7447 curwin->w_set_curswant = TRUE; | |
7448 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
7449 clearopbeep(cap->oap); | |
7450 #ifdef FEAT_FOLDING | |
7451 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
7452 foldOpenCursor(); | |
7453 #endif | |
7454 } | |
7455 | |
7456 /* | |
7457 * Handle word motion commands "e", "E", "w" and "W". | |
7458 * cap->arg is TRUE for "E" and "W". | |
7459 */ | |
7460 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7461 nv_wordcmd(cmdarg_T *cap) |
7 | 7462 { |
7463 int n; | |
7464 int word_end; | |
7465 int flag = FALSE; | |
1573 | 7466 pos_T startpos = curwin->w_cursor; |
7 | 7467 |
7468 /* | |
7469 * Set inclusive for the "E" and "e" command. | |
7470 */ | |
7471 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
7472 word_end = TRUE; | |
7473 else | |
7474 word_end = FALSE; | |
7475 cap->oap->inclusive = word_end; | |
7476 | |
7477 /* | |
7478 * "cw" and "cW" are a special case. | |
7479 */ | |
7480 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
7481 { | |
7482 n = gchar_cursor(); | |
7483 if (n != NUL) /* not an empty line */ | |
7484 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
7485 if (VIM_ISWHITE(n)) |
7 | 7486 { |
7487 /* | |
7488 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
7489 * changes one character, not all blanks until the start of | |
7490 * the next word. Only do this when the 'w' flag is included | |
7491 * in 'cpoptions'. | |
7492 */ | |
7493 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
7494 { | |
7495 cap->oap->inclusive = TRUE; | |
7496 cap->oap->motion_type = MCHAR; | |
7497 return; | |
7498 } | |
7499 } | |
7500 else | |
7501 { | |
7502 /* | |
7503 * This is a little strange. To match what the real Vi does, | |
7504 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
7505 * that we are not on a space or a TAB. This seems impolite | |
7506 * at first, but it's really more what we mean when we say | |
7507 * 'cw'. | |
7508 * Another strangeness: When standing on the end of a word | |
4352 | 7509 * "ce" will change until the end of the next word, but "cw" |
7 | 7510 * will change only one character! This is done by setting |
7511 * flag. | |
7512 */ | |
7513 cap->oap->inclusive = TRUE; | |
7514 word_end = TRUE; | |
7515 flag = TRUE; | |
7516 } | |
7517 } | |
7518 } | |
7519 | |
7520 cap->oap->motion_type = MCHAR; | |
7521 curwin->w_set_curswant = TRUE; | |
7522 if (word_end) | |
7523 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
7524 else | |
7525 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
7526 | |
1573 | 7527 /* Don't leave the cursor on the NUL past the end of line. Unless we |
7528 * 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
|
7529 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 7530 adjust_cursor(cap->oap); |
7 | 7531 |
7532 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
7533 clearopbeep(cap->oap); | |
7534 else | |
7535 { | |
7536 adjust_for_sel(cap); | |
7537 #ifdef FEAT_FOLDING | |
7538 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
7539 foldOpenCursor(); | |
7540 #endif | |
7541 } | |
7542 } | |
7543 | |
7544 /* | |
1505 | 7545 * Used after a movement command: If the cursor ends up on the NUL after the |
7546 * end of the line, may move it back to the last character and make the motion | |
7547 * inclusive. | |
7548 */ | |
7549 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7550 adjust_cursor(oparg_T *oap) |
1505 | 7551 { |
7552 /* The cursor cannot remain on the NUL when: | |
7553 * - the column is > 0 | |
7554 * - not in Visual mode or 'selection' is "o" | |
7555 * - 'virtualedit' is not "all" and not "onemore". | |
7556 */ | |
7557 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
7558 && (!VIsual_active || *p_sel == 'o') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7559 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0) |
1505 | 7560 { |
7561 --curwin->w_cursor.col; | |
7562 /* prevent cursor from moving on the trail byte */ | |
7563 if (has_mbyte) | |
7564 mb_adjust_cursor(); | |
7565 oap->inclusive = TRUE; | |
7566 } | |
7567 } | |
7568 | |
7569 /* | |
7 | 7570 * "0" and "^" commands. |
7571 * cap->arg is the argument for beginline(). | |
7572 */ | |
7573 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7574 nv_beginline(cmdarg_T *cap) |
7 | 7575 { |
7576 cap->oap->motion_type = MCHAR; | |
7577 cap->oap->inclusive = FALSE; | |
7578 beginline(cap->arg); | |
7579 #ifdef FEAT_FOLDING | |
7580 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
7581 foldOpenCursor(); | |
7582 #endif | |
557 | 7583 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
7584 one-character line). */ | |
7 | 7585 } |
7586 | |
7587 /* | |
7588 * In exclusive Visual mode, may include the last character. | |
7589 */ | |
7590 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7591 adjust_for_sel(cmdarg_T *cap) |
7 | 7592 { |
7593 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
|
7594 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 7595 { |
7596 if (has_mbyte) | |
7597 inc_cursor(); | |
7598 else | |
7599 ++curwin->w_cursor.col; | |
7600 cap->oap->inclusive = FALSE; | |
7601 } | |
7602 } | |
7603 | |
7604 /* | |
7605 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
7606 * Should check VIsual_mode before calling this. | |
7607 * Returns TRUE when backed up to the previous line. | |
7608 */ | |
7609 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7610 unadjust_for_sel(void) |
7 | 7611 { |
7612 pos_T *pp; | |
7613 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7614 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
|
7615 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7616 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7617 pp = &curwin->w_cursor; |
7618 else | |
7619 pp = &VIsual; | |
7620 if (pp->coladd > 0) | |
7621 --pp->coladd; | |
7622 else | |
7623 if (pp->col > 0) | |
7624 { | |
7625 --pp->col; | |
2933 | 7626 mb_adjustpos(curbuf, pp); |
7 | 7627 } |
7628 else if (pp->lnum > 1) | |
7629 { | |
7630 --pp->lnum; | |
7631 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
7632 return TRUE; | |
7633 } | |
7634 } | |
7635 return FALSE; | |
7636 } | |
7637 | |
7638 /* | |
7639 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
7640 */ | |
7641 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7642 nv_select(cmdarg_T *cap) |
7 | 7643 { |
7644 if (VIsual_active) | |
7645 VIsual_select = TRUE; | |
7646 else if (VIsual_reselect) | |
7647 { | |
7648 cap->nchar = 'v'; /* fake "gv" command */ | |
7649 cap->arg = TRUE; | |
7650 nv_g_cmd(cap); | |
7651 } | |
7652 } | |
7653 | |
7654 | |
7655 /* | |
7656 * "G", "gg", CTRL-END, CTRL-HOME. | |
7657 * cap->arg is TRUE for "G". | |
7658 */ | |
7659 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7660 nv_goto(cmdarg_T *cap) |
7 | 7661 { |
7662 linenr_T lnum; | |
7663 | |
7664 if (cap->arg) | |
7665 lnum = curbuf->b_ml.ml_line_count; | |
7666 else | |
7667 lnum = 1L; | |
7668 cap->oap->motion_type = MLINE; | |
7669 setpcmark(); | |
7670 | |
7671 /* When a count is given, use it instead of the default lnum */ | |
7672 if (cap->count0 != 0) | |
7673 lnum = cap->count0; | |
7674 if (lnum < 1L) | |
7675 lnum = 1L; | |
7676 else if (lnum > curbuf->b_ml.ml_line_count) | |
7677 lnum = curbuf->b_ml.ml_line_count; | |
7678 curwin->w_cursor.lnum = lnum; | |
7679 beginline(BL_SOL | BL_FIX); | |
7680 #ifdef FEAT_FOLDING | |
7681 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
7682 foldOpenCursor(); | |
7683 #endif | |
7684 } | |
7685 | |
7686 /* | |
7687 * CTRL-\ in Normal mode. | |
7688 */ | |
7689 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7690 nv_normal(cmdarg_T *cap) |
7 | 7691 { |
7692 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
7693 { | |
7694 clearop(cap->oap); | |
643 | 7695 if (restart_edit != 0 && mode_displayed) |
7 | 7696 clear_cmdline = TRUE; /* unshow mode later */ |
7697 restart_edit = 0; | |
7698 #ifdef FEAT_CMDWIN | |
7699 if (cmdwin_type != 0) | |
7700 cmdwin_result = Ctrl_C; | |
7701 #endif | |
7702 if (VIsual_active) | |
7703 { | |
7704 end_visual_mode(); /* stop Visual */ | |
7705 redraw_curbuf_later(INVERTED); | |
7706 } | |
7707 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
7708 if (cap->nchar == Ctrl_G && p_im) | |
7709 restart_edit = 'a'; | |
7710 } | |
7711 else | |
7712 clearopbeep(cap->oap); | |
7713 } | |
7714 | |
7715 /* | |
7716 * ESC in Normal mode: beep, but don't flush buffers. | |
7717 * Don't even beep if we are canceling a command. | |
7718 */ | |
7719 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7720 nv_esc(cmdarg_T *cap) |
7 | 7721 { |
7722 int no_reason; | |
7723 | |
7724 no_reason = (cap->oap->op_type == OP_NOP | |
7725 && cap->opcount == 0 | |
7726 && cap->count0 == 0 | |
7727 && cap->oap->regname == 0 | |
7728 && !p_im); | |
7729 | |
7730 if (cap->arg) /* TRUE for CTRL-C */ | |
7731 { | |
7732 if (restart_edit == 0 | |
7733 #ifdef FEAT_CMDWIN | |
7734 && cmdwin_type == 0 | |
7735 #endif | |
7736 && !VIsual_active | |
7737 && 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
|
7738 { |
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
|
7739 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
|
7740 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
|
7741 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
|
7742 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
|
7743 } |
7 | 7744 |
7745 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
7746 * set again below when halfway a mapping. */ | |
7747 if (!p_im) | |
7748 restart_edit = 0; | |
7749 #ifdef FEAT_CMDWIN | |
7750 if (cmdwin_type != 0) | |
7751 { | |
7752 cmdwin_result = K_IGNORE; | |
7753 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
7754 return; | |
7755 } | |
7756 #endif | |
7757 } | |
7758 | |
7759 if (VIsual_active) | |
7760 { | |
7761 end_visual_mode(); /* stop Visual */ | |
7762 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
7763 curwin->w_set_curswant = TRUE; | |
7764 redraw_curbuf_later(INVERTED); | |
7765 } | |
5735 | 7766 else if (no_reason) |
6949 | 7767 vim_beep(BO_ESC); |
7 | 7768 clearop(cap->oap); |
7769 | |
7770 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
7771 * 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
|
7772 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 7773 restart_edit = 'a'; |
7774 } | |
7775 | |
7776 /* | |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7777 * 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
|
7778 */ |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7779 void |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7780 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
|
7781 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7782 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
|
7783 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
|
7784 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7785 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
|
7786 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7787 /* 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
|
7788 * 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
|
7789 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
|
7790 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
|
7791 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
|
7792 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7793 else |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7794 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
|
7795 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7796 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7797 /* |
7 | 7798 * 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
|
7799 * Also handle K_PS, start bracketed paste. |
7 | 7800 */ |
7801 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7802 nv_edit(cmdarg_T *cap) |
7 | 7803 { |
7804 /* <Insert> is equal to "i" */ | |
7805 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
7806 cap->cmdchar = 'i'; | |
7807 | |
7808 /* in Visual mode "A" and "I" are an operator */ | |
7809 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
|
7810 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7811 #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
|
7812 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
|
7813 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7814 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
|
7815 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
|
7816 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
|
7817 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7818 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7819 #endif |
7 | 7820 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
|
7821 } |
7 | 7822 |
7823 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 7824 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
7825 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 7826 { |
7827 #ifdef FEAT_TEXTOBJ | |
7828 nv_object(cap); | |
7829 #else | |
7830 clearopbeep(cap->oap); | |
7831 #endif | |
7832 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7833 #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
|
7834 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
|
7835 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7836 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
|
7837 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
|
7838 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7839 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7840 #endif |
7 | 7841 else if (!curbuf->b_p_ma && !p_im) |
7842 { | |
7843 /* 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
|
7844 emsg(_(e_modifiable)); |
7 | 7845 clearop(cap->oap); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7846 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7847 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7848 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 7849 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7850 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
|
7851 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7852 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
|
7853 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
|
7854 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7855 /* 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
|
7856 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
|
7857 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7858 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
|
7859 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
|
7860 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7861 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7862 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
|
7863 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
|
7864 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
|
7865 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
|
7866 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
|
7867 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
|
7868 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7869 /* 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
|
7870 * 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
|
7871 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
|
7872 && 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
|
7873 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7874 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7875 /* 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
|
7876 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
|
7877 } |
7 | 7878 else if (!checkclearopq(cap->oap)) |
7879 { | |
7880 switch (cap->cmdchar) | |
7881 { | |
7882 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
|
7883 set_cursor_for_append_to_line(); |
7 | 7884 break; |
7885 | |
7886 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 7887 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
7888 beginline(BL_WHITE); | |
7889 else | |
7890 beginline(BL_WHITE|BL_FIX); | |
7 | 7891 break; |
7892 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7893 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
|
7894 /* 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
|
7895 * 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
|
7896 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
|
7897 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
7898 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
7899 |
7 | 7900 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
7901 /* increment coladd when in virtual space, increment the | |
7902 * column otherwise, also to append after an unprintable char */ | |
7903 if (virtual_active() | |
7904 && (curwin->w_cursor.coladd > 0 | |
7905 || *ml_get_cursor() == NUL | |
7906 || *ml_get_cursor() == TAB)) | |
7907 curwin->w_cursor.coladd++; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7908 else if (*ml_get_cursor() != NUL) |
7 | 7909 inc_cursor(); |
7910 break; | |
7911 } | |
7912 | |
7913 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
7914 { | |
7915 int save_State = State; | |
7916 | |
4352 | 7917 /* Pretend Insert mode here to allow the cursor on the |
7 | 7918 * character past the end of the line */ |
7919 State = INSERT; | |
7920 coladvance(getviscol()); | |
7921 State = save_State; | |
7922 } | |
7923 | |
7924 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
7925 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7926 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
|
7927 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7928 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 7929 } |
7930 | |
7931 /* | |
7932 * Invoke edit() and take care of "restart_edit" and the return value. | |
7933 */ | |
7934 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7935 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7936 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7937 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7938 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7939 int startln) |
7 | 7940 { |
7941 int restart_edit_save = 0; | |
7942 | |
7943 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
7944 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
7945 * it. */ | |
7946 if (repl || !stuff_empty()) | |
7947 restart_edit_save = restart_edit; | |
7948 else | |
7949 restart_edit_save = 0; | |
7950 | |
7951 /* Always reset "restart_edit", this is not a restarted edit. */ | |
7952 restart_edit = 0; | |
7953 | |
7954 if (edit(cmd, startln, cap->count1)) | |
7955 cap->retval |= CA_COMMAND_BUSY; | |
7956 | |
7957 if (restart_edit == 0) | |
7958 restart_edit = restart_edit_save; | |
7959 } | |
7960 | |
7961 #ifdef FEAT_TEXTOBJ | |
7962 /* | |
7963 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
7964 */ | |
7965 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7966 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7967 cmdarg_T *cap) |
7 | 7968 { |
7969 int flag; | |
7970 int include; | |
7971 char_u *mps_save; | |
7972 | |
7973 if (cap->cmdchar == 'i') | |
7974 include = FALSE; /* "ix" = inner object: exclude white space */ | |
7975 else | |
7976 include = TRUE; /* "ax" = an object: include white space */ | |
7977 | |
7978 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
7979 mps_save = curbuf->b_p_mps; | |
7980 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
7981 | |
7982 switch (cap->nchar) | |
7983 { | |
7984 case 'w': /* "aw" = a word */ | |
7985 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
7986 break; | |
7987 case 'W': /* "aW" = a WORD */ | |
7988 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
7989 break; | |
7990 case 'b': /* "ab" = a braces block */ | |
7991 case '(': | |
7992 case ')': | |
7993 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
7994 break; | |
7995 case 'B': /* "aB" = a Brackets block */ | |
7996 case '{': | |
7997 case '}': | |
7998 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
7999 break; | |
8000 case '[': /* "a[" = a [] block */ | |
8001 case ']': | |
8002 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
8003 break; | |
8004 case '<': /* "a<" = a <> block */ | |
8005 case '>': | |
8006 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
8007 break; | |
420 | 8008 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 8009 /* Do not adjust oap->end in do_pending_operator() |
8010 * otherwise there are different results for 'dit' | |
8011 * (note leading whitespace in last line): | |
8012 * 1) <b> 2) <b> | |
8013 * foobar foobar | |
8014 * </b> </b> | |
8015 */ | |
8016 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 8017 flag = current_tagblock(cap->oap, cap->count1, include); |
8018 break; | |
7 | 8019 case 'p': /* "ap" = a paragraph */ |
8020 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
8021 break; | |
8022 case 's': /* "as" = a sentence */ | |
8023 flag = current_sent(cap->oap, cap->count1, include); | |
8024 break; | |
12 | 8025 case '"': /* "a"" = a double quoted string */ |
8026 case '\'': /* "a'" = a single quoted string */ | |
8027 case '`': /* "a`" = a backtick quoted string */ | |
8028 flag = current_quote(cap->oap, cap->count1, include, | |
8029 cap->nchar); | |
8030 break; | |
7 | 8031 #if 0 /* TODO */ |
8032 case 'S': /* "aS" = a section */ | |
8033 case 'f': /* "af" = a filename */ | |
8034 case 'u': /* "au" = a URL */ | |
8035 #endif | |
8036 default: | |
8037 flag = FAIL; | |
8038 break; | |
8039 } | |
8040 | |
8041 curbuf->b_p_mps = mps_save; | |
8042 if (flag == FAIL) | |
8043 clearopbeep(cap->oap); | |
8044 adjust_cursor_col(); | |
8045 curwin->w_set_curswant = TRUE; | |
8046 } | |
8047 #endif | |
8048 | |
8049 /* | |
8050 * "q" command: Start/stop recording. | |
8051 * "q:", "q/", "q?": edit command-line in command-line window. | |
8052 */ | |
8053 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8054 nv_record(cmdarg_T *cap) |
7 | 8055 { |
8056 if (cap->oap->op_type == OP_FORMAT) | |
8057 { | |
8058 /* "gqq" is the same as "gqgq": format line */ | |
8059 cap->cmdchar = 'g'; | |
8060 cap->nchar = 'q'; | |
8061 nv_operator(cap); | |
8062 } | |
8063 else if (!checkclearop(cap->oap)) | |
8064 { | |
8065 #ifdef FEAT_CMDWIN | |
8066 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
8067 { | |
8068 stuffcharReadbuff(cap->nchar); | |
8069 stuffcharReadbuff(K_CMDWIN); | |
8070 } | |
8071 else | |
8072 #endif | |
8073 /* (stop) recording into a named register, unless executing a | |
8074 * 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
|
8075 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 8076 clearopbeep(cap->oap); |
8077 } | |
8078 } | |
8079 | |
8080 /* | |
8081 * Handle the "@r" command. | |
8082 */ | |
8083 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8084 nv_at(cmdarg_T *cap) |
7 | 8085 { |
8086 if (checkclearop(cap->oap)) | |
8087 return; | |
8088 #ifdef FEAT_EVAL | |
8089 if (cap->nchar == '=') | |
8090 { | |
8091 if (get_expr_register() == NUL) | |
8092 return; | |
8093 } | |
8094 #endif | |
8095 while (cap->count1-- && !got_int) | |
8096 { | |
1034 | 8097 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 8098 { |
8099 clearopbeep(cap->oap); | |
8100 break; | |
8101 } | |
8102 line_breakcheck(); | |
8103 } | |
8104 } | |
8105 | |
8106 /* | |
8107 * Handle the CTRL-U and CTRL-D commands. | |
8108 */ | |
8109 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8110 nv_halfpage(cmdarg_T *cap) |
7 | 8111 { |
8112 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
8113 || (cap->cmdchar == Ctrl_D | |
8114 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
8115 clearopbeep(cap->oap); | |
8116 else if (!checkclearop(cap->oap)) | |
8117 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
8118 } | |
8119 | |
8120 /* | |
8121 * Handle "J" or "gJ" command. | |
8122 */ | |
8123 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8124 nv_join(cmdarg_T *cap) |
7 | 8125 { |
8126 if (VIsual_active) /* join the visual lines */ | |
8127 nv_operator(cap); | |
5735 | 8128 else if (!checkclearop(cap->oap)) |
7 | 8129 { |
8130 if (cap->count0 <= 1) | |
8131 cap->count0 = 2; /* default for join is two lines! */ | |
8132 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
8133 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
|
8134 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8135 /* 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
|
8136 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8137 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8138 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8139 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8140 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8141 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
|
8142 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8143 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8144 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
8145 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
|
8146 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
|
8147 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 8148 } |
8149 } | |
8150 | |
8151 /* | |
8152 * "P", "gP", "p" and "gp" commands. | |
8153 */ | |
8154 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8155 nv_put(cmdarg_T *cap) |
7 | 8156 { |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8157 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
|
8158 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8159 |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8160 /* |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8161 * "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
|
8162 * "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
|
8163 */ |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8164 static void |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8165 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
|
8166 { |
7 | 8167 int regname = 0; |
8168 void *reg1 = NULL, *reg2 = NULL; | |
84 | 8169 int empty = FALSE; |
236 | 8170 int was_visual = FALSE; |
7 | 8171 int dir; |
8172 int flags = 0; | |
8173 | |
8174 if (cap->oap->op_type != OP_NOP) | |
8175 { | |
8176 #ifdef FEAT_DIFF | |
8177 /* "dp" is ":diffput" */ | |
8178 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
8179 { | |
8180 clearop(cap->oap); | |
6314 | 8181 nv_diffgetput(TRUE, cap->opcount); |
7 | 8182 } |
8183 else | |
8184 #endif | |
8185 clearopbeep(cap->oap); | |
8186 } | |
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
|
8187 #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
|
8188 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
|
8189 { |
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
|
8190 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
|
8191 } |
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
|
8192 #endif |
7 | 8193 else |
8194 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8195 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
|
8196 { |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8197 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
|
8198 ? FORWARD : BACKWARD; |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8199 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
|
8200 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8201 else |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
8202 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
|
8203 || (cap->cmdchar == 'g' && cap->nchar == 'P')) |
7 | 8204 ? BACKWARD : FORWARD; |
8205 prep_redo_cmd(cap); | |
8206 if (cap->cmdchar == 'g') | |
8207 flags |= PUT_CURSEND; | |
8208 | |
8209 if (VIsual_active) | |
8210 { | |
8211 /* Putting in Visual mode: The put text replaces the selected | |
8212 * text. First delete the selected text, then put the new text. | |
8213 * Need to save and restore the registers that the delete | |
8214 * overwrites if the old contents is being put. | |
8215 */ | |
236 | 8216 was_visual = TRUE; |
7 | 8217 regname = cap->oap->regname; |
5735 | 8218 #ifdef FEAT_CLIPBOARD |
7 | 8219 adjust_clip_reg(®name); |
5735 | 8220 #endif |
5682 | 8221 if (regname == 0 || regname == '"' |
4013 | 8222 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 8223 #ifdef FEAT_CLIPBOARD |
7 | 8224 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 8225 #endif |
7 | 8226 |
8227 ) | |
8228 { | |
4013 | 8229 /* The delete is going to overwrite the register we want to |
7 | 8230 * put, save it first. */ |
8231 reg1 = get_register(regname, TRUE); | |
8232 } | |
8233 | |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
8234 // Now delete the selected text. Avoid messages here. |
7 | 8235 cap->cmdchar = 'd'; |
8236 cap->nchar = NUL; | |
8237 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
|
8238 ++msg_silent; |
7 | 8239 nv_operator(cap); |
8240 do_pending_operator(cap, 0, FALSE); | |
84 | 8241 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
|
8242 --msg_silent; |
7 | 8243 |
8244 /* delete PUT_LINE_BACKWARD; */ | |
8245 cap->oap->regname = regname; | |
8246 | |
8247 if (reg1 != NULL) | |
8248 { | |
8249 /* Delete probably changed the register we want to put, save | |
8250 * it first. Then put back what was there before the delete. */ | |
8251 reg2 = get_register(regname, FALSE); | |
8252 put_register(regname, reg1); | |
8253 } | |
8254 | |
8255 /* When deleted a linewise Visual area, put the register as | |
8256 * lines to avoid it joined with the next line. When deletion was | |
8257 * characterwise, split a line when putting lines. */ | |
8258 if (VIsual_mode == 'V') | |
8259 flags |= PUT_LINE; | |
8260 else if (VIsual_mode == 'v') | |
8261 flags |= PUT_LINE_SPLIT; | |
8262 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
8263 flags |= PUT_LINE_FORWARD; | |
8264 dir = BACKWARD; | |
8265 if ((VIsual_mode != 'V' | |
8266 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
8267 || (VIsual_mode == 'V' | |
8268 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
8269 /* cursor is at the end of the line or end of file, put | |
8270 * forward. */ | |
8271 dir = FORWARD; | |
5365 | 8272 /* May have been reset in do_put(). */ |
8273 VIsual_active = TRUE; | |
7 | 8274 } |
8275 do_put(cap->oap->regname, dir, cap->count1, flags); | |
8276 | |
8277 /* If a register was saved, put it back now. */ | |
8278 if (reg2 != NULL) | |
8279 put_register(regname, reg2); | |
236 | 8280 |
8281 /* What to reselect with "gv"? Selecting the just put text seems to | |
8282 * be the most useful, since the original text was removed. */ | |
8283 if (was_visual) | |
8284 { | |
690 | 8285 curbuf->b_visual.vi_start = curbuf->b_op_start; |
8286 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
|
8287 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
8288 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
8289 inc(&curbuf->b_visual.vi_end); |
236 | 8290 } |
8291 | |
84 | 8292 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 8293 * line that needs to be deleted now. */ |
84 | 8294 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 8295 { |
84 | 8296 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
|
8297 deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); |
817 | 8298 |
8299 /* If the cursor was in that line, move it to the end of the last | |
8300 * line. */ | |
8301 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
8302 { | |
8303 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
8304 coladvance((colnr_T)MAXCOL); | |
8305 } | |
8306 } | |
7 | 8307 auto_format(FALSE, TRUE); |
8308 } | |
8309 } | |
8310 | |
8311 /* | |
8312 * "o" and "O" commands. | |
8313 */ | |
8314 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8315 nv_open(cmdarg_T *cap) |
7 | 8316 { |
8317 #ifdef FEAT_DIFF | |
8318 /* "do" is ":diffget" */ | |
8319 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
8320 { | |
8321 clearop(cap->oap); | |
6314 | 8322 nv_diffgetput(FALSE, cap->opcount); |
7 | 8323 } |
8324 else | |
8325 #endif | |
8326 if (VIsual_active) /* switch start and end of visual */ | |
8327 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
|
8328 #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
|
8329 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
|
8330 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
|
8331 #endif |
7 | 8332 else |
8333 n_opencmd(cap); | |
8334 } | |
8335 | |
8336 #ifdef FEAT_NETBEANS_INTG | |
8337 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8338 nv_nbcmd(cmdarg_T *cap) |
7 | 8339 { |
8340 netbeans_keycommand(cap->nchar); | |
8341 } | |
8342 #endif | |
8343 | |
8344 #ifdef FEAT_DND | |
8345 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8346 nv_drop(cmdarg_T *cap UNUSED) |
7 | 8347 { |
8348 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
8349 } | |
8350 #endif | |
203 | 8351 |
8352 /* | |
8353 * Trigger CursorHold event. | |
8354 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
8355 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
8356 */ | |
8357 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8358 nv_cursorhold(cmdarg_T *cap) |
203 | 8359 { |
8360 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
8361 did_cursorhold = TRUE; | |
226 | 8362 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
8363 } | |
6866 | 8364 |
8365 /* | |
7001 | 8366 * Calculate start/end virtual columns for operating in block mode. |
6866 | 8367 */ |
8368 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8369 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8370 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8371 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8372 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 8373 { |
8374 colnr_T start, end; | |
8375 | |
7001 | 8376 if (VIsual_mode != Ctrl_V |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8377 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 8378 return; |
8379 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
8380 oap->block_mode = TRUE; |
6866 | 8381 |
8382 /* prevent from moving onto a trail byte */ | |
8383 if (has_mbyte) | |
8384 mb_adjustpos(curwin->w_buffer, &oap->end); | |
8385 | |
8386 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 8387 |
8388 if (!redo_VIsual_busy) | |
8389 { | |
8390 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
8391 | |
8392 if (start < oap->start_vcol) | |
8393 oap->start_vcol = start; | |
8394 if (end > oap->end_vcol) | |
8395 { | |
8396 if (initial && *p_sel == 'e' && start >= 1 | |
8397 && start - 1 >= oap->end_vcol) | |
8398 oap->end_vcol = start - 1; | |
8399 else | |
8400 oap->end_vcol = end; | |
8401 } | |
8402 } | |
8403 | |
6866 | 8404 /* if '$' was used, get oap->end_vcol from longest line */ |
8405 if (curwin->w_curswant == MAXCOL) | |
8406 { | |
8407 curwin->w_cursor.col = MAXCOL; | |
8408 oap->end_vcol = 0; | |
8409 for (curwin->w_cursor.lnum = oap->start.lnum; | |
8410 curwin->w_cursor.lnum <= oap->end.lnum; | |
8411 ++curwin->w_cursor.lnum) | |
8412 { | |
8413 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
8414 if (end > oap->end_vcol) | |
8415 oap->end_vcol = end; | |
8416 } | |
8417 } | |
8418 else if (redo_VIsual_busy) | |
8419 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
8420 /* | |
8421 * Correct oap->end.col and oap->start.col to be the | |
8422 * upper-left and lower-right corner of the block area. | |
8423 * | |
8424 * (Actually, this does convert column positions into character | |
8425 * positions) | |
8426 */ | |
8427 curwin->w_cursor.lnum = oap->end.lnum; | |
8428 coladvance(oap->end_vcol); | |
8429 oap->end = curwin->w_cursor; | |
8430 | |
8431 curwin->w_cursor = oap->start; | |
8432 coladvance(oap->start_vcol); | |
8433 oap->start = curwin->w_cursor; | |
8434 } |