Mercurial > vim
annotate src/normal.c @ 25790:16a7d1154be8 v8.2.3430
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Commit: https://github.com/vim/vim/commit/f1e8876fa2359b572d262772747405d3616db670
Author: =?UTF-8?q?Magnus=20Gro=C3=9F?= <magnus.gross@rwth-aachen.de>
Date: Sun Sep 12 13:39:55 2021 +0200
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Problem: No generic way to trigger an autocommand on mode change.
Solution: Add the ModeChanged autocommand event. (Magnus Gross, closes https://github.com/vim/vim/issues/8856)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Sep 2021 13:45:05 +0200 |
parents | ec62e0764ffa |
children | 203b0f3a741a |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * normal.c: Contains the main routine for processing characters in command | |
11 * mode. Communicates closely with the code in ops.c to handle | |
12 * the operators. | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
17 static int VIsual_mode_orig = NUL; // saved Visual mode |
7 | 18 |
2667 | 19 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
20 static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
2667 | 21 #endif |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16598
diff
changeset
|
22 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
|
23 static void unshift_special(cmdarg_T *cap); |
7 | 24 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
25 static void del_from_showcmd(int); |
7 | 26 #endif |
27 | |
28 /* | |
29 * nv_*(): functions called to handle Normal and Visual mode commands. | |
30 * n_*(): functions called to handle Normal mode commands. | |
31 * v_*(): functions called to handle Visual mode commands. | |
32 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 static void nv_zet(cmdarg_T *cap); |
7 | 40 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
41 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
|
42 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 43 #endif |
685 | 44 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
45 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
|
46 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
|
47 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 static void nv_next(cmdarg_T *cap); |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
67 static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt, int *wrapped); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 static void nv_replace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
78 static void nv_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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 static void nv_operator(cmdarg_T *cap); |
1490 | 96 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
97 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
|
98 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 113 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
114 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
|
115 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 static void nv_open(cmdarg_T *cap); |
7 | 123 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
124 static void nv_nbcmd(cmdarg_T *cap); |
7 | 125 #endif |
126 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
127 static void nv_drop(cmdarg_T *cap); |
7 | 128 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
129 static void nv_cursorhold(cmdarg_T *cap); |
7 | 130 |
1728 | 131 static char *e_noident = N_("E349: No identifier under cursor"); |
132 | |
7 | 133 /* |
134 * Function to be called for a Normal or Visual mode command. | |
135 * The argument is a cmdarg_T. | |
136 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
137 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 138 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
139 // Values for cmd_flags. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
140 #define NV_NCH 0x01 // may need to get a second char |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
141 #define NV_NCH_NOP (0x02|NV_NCH) // get second char when no operator pending |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
142 #define NV_NCH_ALW (0x04|NV_NCH) // always get a second char |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
143 #define NV_LANG 0x08 // second char needs language adjustment |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
144 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
145 #define NV_SS 0x10 // may start selection |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
146 #define NV_SSS 0x20 // may start selection with shift modifier |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
147 #define NV_STS 0x40 // may stop selection without shift modif. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
148 #define NV_RL 0x80 // 'rightleft' modifies command |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
149 #define NV_KEEPREG 0x100 // don't clear regname |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
150 #define NV_NCW 0x200 // not allowed in command-line window |
7 | 151 |
152 /* | |
153 * Generally speaking, every Normal mode command should either clear any | |
154 * pending operator (with *clearop*()), or set the motion type variable | |
155 * oap->motion_type. | |
156 * | |
157 * When a cursor motion command is made, it is marked as being a character or | |
158 * line oriented motion. Then, if an operator is in effect, the operation | |
159 * becomes character or line oriented accordingly. | |
160 */ | |
161 | |
162 /* | |
163 * This table contains one entry for every Normal or Visual mode command. | |
164 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
165 * It is faster when all keys from zero to '~' are present. | |
166 */ | |
167 static const struct nv_cmd | |
168 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
169 int cmd_char; // (first) command character |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
170 nv_func_T cmd_func; // function for this command |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
171 short_u cmd_flags; // NV_ flags |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
172 short cmd_arg; // value for ca.arg |
7 | 173 } nv_cmds[] = |
174 { | |
175 {NUL, nv_error, 0, 0}, | |
176 {Ctrl_A, nv_addsub, 0, 0}, | |
177 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
178 {Ctrl_C, nv_esc, 0, TRUE}, | |
179 {Ctrl_D, nv_halfpage, 0, 0}, | |
180 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
181 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
182 {Ctrl_G, nv_ctrlg, 0, 0}, | |
183 {Ctrl_H, nv_ctrlh, 0, 0}, | |
184 {Ctrl_I, nv_pcmark, 0, 0}, | |
185 {NL, nv_down, 0, FALSE}, | |
186 {Ctrl_K, nv_error, 0, 0}, | |
187 {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
|
188 {CAR, nv_down, 0, TRUE}, |
7 | 189 {Ctrl_N, nv_down, NV_STS, FALSE}, |
190 {Ctrl_O, nv_ctrlo, 0, 0}, | |
191 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 192 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 193 {Ctrl_R, nv_redo, 0, 0}, |
194 {Ctrl_S, nv_ignore, 0, 0}, | |
195 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
196 {Ctrl_U, nv_halfpage, 0, 0}, | |
197 {Ctrl_V, nv_visual, 0, FALSE}, | |
198 {'V', nv_visual, 0, FALSE}, | |
199 {'v', nv_visual, 0, FALSE}, | |
200 {Ctrl_W, nv_window, 0, 0}, | |
201 {Ctrl_X, nv_addsub, 0, 0}, | |
202 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
203 {Ctrl_Z, nv_suspend, 0, 0}, | |
204 {ESC, nv_esc, 0, FALSE}, | |
205 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
206 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
207 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
208 {Ctrl__, nv_error, 0, 0}, | |
209 {' ', nv_right, 0, 0}, | |
210 {'!', nv_operator, 0, 0}, | |
211 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
212 {'#', nv_ident, 0, 0}, | |
213 {'$', nv_dollar, 0, 0}, | |
214 {'%', nv_percent, 0, 0}, | |
215 {'&', nv_optrans, 0, 0}, | |
216 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
217 {'(', nv_brace, 0, BACKWARD}, | |
218 {')', nv_brace, 0, FORWARD}, | |
219 {'*', nv_ident, 0, 0}, | |
220 {'+', nv_down, 0, TRUE}, | |
221 {',', nv_csearch, 0, TRUE}, | |
222 {'-', nv_up, 0, TRUE}, | |
223 {'.', nv_dot, NV_KEEPREG, 0}, | |
224 {'/', nv_search, 0, FALSE}, | |
225 {'0', nv_beginline, 0, 0}, | |
226 {'1', nv_ignore, 0, 0}, | |
227 {'2', nv_ignore, 0, 0}, | |
228 {'3', nv_ignore, 0, 0}, | |
229 {'4', nv_ignore, 0, 0}, | |
230 {'5', nv_ignore, 0, 0}, | |
231 {'6', nv_ignore, 0, 0}, | |
232 {'7', nv_ignore, 0, 0}, | |
233 {'8', nv_ignore, 0, 0}, | |
234 {'9', nv_ignore, 0, 0}, | |
235 {':', nv_colon, 0, 0}, | |
236 {';', nv_csearch, 0, FALSE}, | |
237 {'<', nv_operator, NV_RL, 0}, | |
238 {'=', nv_operator, 0, 0}, | |
239 {'>', nv_operator, NV_RL, 0}, | |
240 {'?', nv_search, 0, FALSE}, | |
241 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
242 {'A', nv_edit, 0, 0}, | |
243 {'B', nv_bck_word, 0, 1}, | |
244 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
245 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
246 {'E', nv_wordcmd, 0, TRUE}, | |
247 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
248 {'G', nv_goto, 0, TRUE}, | |
249 {'H', nv_scroll, 0, 0}, | |
250 {'I', nv_edit, 0, 0}, | |
251 {'J', nv_join, 0, 0}, | |
252 {'K', nv_ident, 0, 0}, | |
253 {'L', nv_scroll, 0, 0}, | |
254 {'M', nv_scroll, 0, 0}, | |
255 {'N', nv_next, 0, SEARCH_REV}, | |
256 {'O', nv_open, 0, 0}, | |
257 {'P', nv_put, 0, 0}, | |
258 {'Q', nv_exmode, NV_NCW, 0}, | |
259 {'R', nv_Replace, 0, FALSE}, | |
260 {'S', nv_subst, NV_KEEPREG, 0}, | |
261 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
262 {'U', nv_Undo, 0, 0}, | |
263 {'W', nv_wordcmd, 0, TRUE}, | |
264 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
265 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
266 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
267 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
268 {'\\', nv_error, 0, 0}, | |
269 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
270 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
271 {'_', nv_lineop, 0, 0}, | |
272 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
273 {'a', nv_edit, NV_NCH, 0}, | |
274 {'b', nv_bck_word, 0, 0}, | |
275 {'c', nv_operator, 0, 0}, | |
276 {'d', nv_operator, 0, 0}, | |
277 {'e', nv_wordcmd, 0, FALSE}, | |
278 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
279 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
280 {'h', nv_left, NV_RL, 0}, | |
281 {'i', nv_edit, NV_NCH, 0}, | |
282 {'j', nv_down, 0, FALSE}, | |
283 {'k', nv_up, 0, FALSE}, | |
284 {'l', nv_right, NV_RL, 0}, | |
285 {'m', nv_mark, NV_NCH_NOP, 0}, | |
286 {'n', nv_next, 0, 0}, | |
287 {'o', nv_open, 0, 0}, | |
288 {'p', nv_put, 0, 0}, | |
289 {'q', nv_record, NV_NCH, 0}, | |
290 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
291 {'s', nv_subst, NV_KEEPREG, 0}, | |
292 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
293 {'u', nv_undo, 0, 0}, | |
294 {'w', nv_wordcmd, 0, FALSE}, | |
295 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
296 {'y', nv_operator, 0, 0}, | |
297 {'z', nv_zet, NV_NCH_ALW, 0}, | |
298 {'{', nv_findpar, 0, BACKWARD}, | |
299 {'|', nv_pipe, 0, 0}, | |
300 {'}', nv_findpar, 0, FORWARD}, | |
301 {'~', nv_tilde, 0, 0}, | |
302 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
303 // pound sign |
7 | 304 {POUND, nv_ident, 0, 0}, |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
305 {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
|
306 {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
|
307 {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
|
308 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 309 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
310 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
311 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
312 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
313 {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
|
314 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 315 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
316 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
317 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
318 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
319 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
320 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
321 {K_X1MOUSE, nv_mouse, 0, 0}, | |
322 {K_X1DRAG, nv_mouse, 0, 0}, | |
323 {K_X1RELEASE, nv_mouse, 0, 0}, | |
324 {K_X2MOUSE, nv_mouse, 0, 0}, | |
325 {K_X2DRAG, nv_mouse, 0, 0}, | |
326 {K_X2RELEASE, nv_mouse, 0, 0}, | |
819 | 327 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 328 {K_NOP, nv_nop, 0, 0}, |
7 | 329 {K_INS, nv_edit, 0, 0}, |
330 {K_KINS, nv_edit, 0, 0}, | |
331 {K_BS, nv_ctrlh, 0, 0}, | |
332 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
333 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
334 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
335 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
336 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
337 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
338 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
339 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
340 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
341 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
342 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
343 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
344 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
345 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
346 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
347 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
348 {K_S_END, nv_end, NV_SS, FALSE}, | |
349 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
350 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
351 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
352 {K_S_HOME, nv_home, NV_SS, 0}, | |
353 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
354 {K_DEL, nv_abbrev, 0, 0}, | |
355 {K_KDEL, nv_abbrev, 0, 0}, | |
356 {K_UNDO, nv_kundo, 0, 0}, | |
357 {K_HELP, nv_help, NV_NCW, 0}, | |
358 {K_F1, nv_help, NV_NCW, 0}, | |
359 {K_XF1, nv_help, NV_NCW, 0}, | |
360 {K_SELECT, nv_select, 0, 0}, | |
361 #ifdef FEAT_GUI | |
362 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
363 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
364 #endif | |
685 | 365 #ifdef FEAT_GUI_TABLINE |
366 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 367 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 368 #endif |
7 | 369 #ifdef FEAT_NETBEANS_INTG |
370 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
371 #endif | |
372 #ifdef FEAT_DND | |
373 {K_DROP, nv_drop, NV_STS, 0}, | |
374 #endif | |
819 | 375 {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
|
376 {K_PS, nv_edit, 0, 0}, |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
377 {K_COMMAND, nv_colon, 0, 0}, |
7 | 378 }; |
379 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
380 // Number of commands in nv_cmds[]. |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24752
diff
changeset
|
381 #define NV_CMDS_SIZE ARRAY_LENGTH(nv_cmds) |
7 | 382 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
383 // Sorted index of commands in nv_cmds[]. |
7 | 384 static short nv_cmd_idx[NV_CMDS_SIZE]; |
385 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
386 // The highest index for which |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
387 // nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] |
7 | 388 static int nv_max_linear; |
389 | |
390 /* | |
391 * Compare functions for qsort() below, that checks the command character | |
392 * through the index in nv_cmd_idx[]. | |
393 */ | |
394 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
395 nv_compare(const void *s1, const void *s2) |
7 | 396 { |
397 int c1, c2; | |
398 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
399 // The commands are sorted on absolute value. |
7 | 400 c1 = nv_cmds[*(const short *)s1].cmd_char; |
401 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
402 if (c1 < 0) | |
403 c1 = -c1; | |
404 if (c2 < 0) | |
405 c2 = -c2; | |
406 return c1 - c2; | |
407 } | |
408 | |
409 /* | |
410 * Initialize the nv_cmd_idx[] table. | |
411 */ | |
412 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
413 init_normal_cmds(void) |
7 | 414 { |
415 int i; | |
416 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
417 // Fill the index table with a one to one relation. |
1877 | 418 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 419 nv_cmd_idx[i] = i; |
420 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
421 // Sort the commands by the command character. |
7 | 422 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); |
423 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
424 // Find the first entry that can't be indexed by the command character. |
1877 | 425 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 426 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
427 break; | |
428 nv_max_linear = i - 1; | |
429 } | |
430 | |
431 /* | |
432 * Search for a command in the commands table. | |
433 * Returns -1 for invalid command. | |
434 */ | |
435 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
436 find_command(int cmdchar) |
7 | 437 { |
438 int i; | |
439 int idx; | |
440 int top, bot; | |
441 int c; | |
442 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
443 // A multi-byte character is never a command. |
7 | 444 if (cmdchar >= 0x100) |
445 return -1; | |
446 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
447 // We use the absolute value of the character. Special keys have a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
448 // negative value, but are sorted on their absolute value. |
7 | 449 if (cmdchar < 0) |
450 cmdchar = -cmdchar; | |
451 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
452 // If the character is in the first part: The character is the index into |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
453 // nv_cmd_idx[]. |
7 | 454 if (cmdchar <= nv_max_linear) |
455 return nv_cmd_idx[cmdchar]; | |
456 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
457 // Perform a binary search. |
7 | 458 bot = nv_max_linear + 1; |
459 top = NV_CMDS_SIZE - 1; | |
460 idx = -1; | |
461 while (bot <= top) | |
462 { | |
463 i = (top + bot) / 2; | |
464 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
465 if (c < 0) | |
466 c = -c; | |
467 if (cmdchar == c) | |
468 { | |
469 idx = nv_cmd_idx[i]; | |
470 break; | |
471 } | |
472 if (cmdchar > c) | |
473 bot = i + 1; | |
474 else | |
475 top = i - 1; | |
476 } | |
477 return idx; | |
478 } | |
479 | |
480 /* | |
481 * Execute a command in Normal mode. | |
482 */ | |
483 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
484 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
485 oparg_T *oap, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
486 int toplevel UNUSED) // TRUE when called from main() |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
487 { |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
488 cmdarg_T ca; // command arguments |
7 | 489 int c; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
490 int ctrl_w = FALSE; // got CTRL-W command |
7 | 491 int old_col = curwin->w_curswant; |
492 #ifdef FEAT_CMDL_INFO | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
493 int need_flushbuf; // need to call out_flush() |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
494 #endif |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
495 pos_T old_pos; // cursor position before command |
7 | 496 int mapped_len; |
497 static int old_mapped_len = 0; | |
498 int idx; | |
1751 | 499 #ifdef FEAT_EVAL |
500 int set_prevcount = FALSE; | |
501 #endif | |
21405
5324acb43fea
patch 8.2.1253: CTRL-K in Insert mode gets <CursorHold> inserted
Bram Moolenaar <Bram@vim.org>
parents:
20754
diff
changeset
|
502 int save_did_cursorhold = did_cursorhold; |
7 | 503 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19681
diff
changeset
|
504 CLEAR_FIELD(ca); // also resets ca.retval |
7 | 505 ca.oap = oap; |
1692 | 506 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
507 // Use a count remembered from before entering an operator. After typing |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
508 // "3d" we return from normal_cmd() and come back here, the "3" is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
509 // remembered in "opcount". |
7 | 510 ca.opcount = opcount; |
511 | |
512 /* | |
513 * If there is an operator pending, then the command we take this time | |
514 * will terminate it. Finish_op tells us to finish the operation before | |
515 * returning this time (unless the operation was cancelled). | |
516 */ | |
517 #ifdef CURSOR_SHAPE | |
518 c = finish_op; | |
519 #endif | |
520 finish_op = (oap->op_type != OP_NOP); | |
521 #ifdef CURSOR_SHAPE | |
522 if (finish_op != c) | |
523 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
524 ui_cursor_shape(); // may show different cursor shape |
7 | 525 # ifdef FEAT_MOUSESHAPE |
526 update_mouseshape(-1); | |
527 # endif | |
528 } | |
529 #endif | |
530 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
531 // When not finishing an operator and no register name typed, reset the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
532 // count. |
7 | 533 if (!finish_op && !oap->regname) |
1751 | 534 { |
7 | 535 ca.opcount = 0; |
1751 | 536 #ifdef FEAT_EVAL |
537 set_prevcount = TRUE; | |
538 #endif | |
539 } | |
7 | 540 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
541 // Restore counts from before receiving K_CURSORHOLD. This means after |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
542 // typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
543 // "3 * 2". |
1692 | 544 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) |
545 { | |
546 ca.opcount = oap->prev_opcount; | |
547 ca.count0 = oap->prev_count0; | |
548 oap->prev_opcount = 0; | |
549 oap->prev_count0 = 0; | |
550 } | |
551 | |
7 | 552 mapped_len = typebuf_maplen(); |
553 | |
554 State = NORMAL_BUSY; | |
555 #ifdef USE_ON_FLY_SCROLL | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
556 dont_scroll = FALSE; // allow scrolling here |
7 | 557 #endif |
558 | |
2667 | 559 #ifdef FEAT_EVAL |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
560 // Set v:count here, when called from main() and not a stuffed |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
561 // command, so that v:count can be used in an expression mapping |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
562 // when there is no count. Do set it for redo. |
5649 | 563 if (toplevel && readbuf1_empty()) |
2667 | 564 set_vcount_ca(&ca, &set_prevcount); |
565 #endif | |
566 | |
7 | 567 /* |
568 * Get the command character from the user. | |
569 */ | |
570 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
571 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 572 |
573 /* | |
574 * If a mapping was started in Visual or Select mode, remember the length | |
575 * of the mapping. This is used below to not return to Insert mode for as | |
576 * long as the mapping is being executed. | |
577 */ | |
578 if (restart_edit == 0) | |
579 old_mapped_len = 0; | |
580 else if (old_mapped_len | |
819 | 581 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 582 old_mapped_len = typebuf_maplen(); |
583 | |
584 if (c == NUL) | |
585 c = K_ZERO; | |
586 | |
587 /* | |
588 * In Select mode, typed text replaces the selection. | |
589 */ | |
590 if (VIsual_active | |
591 && VIsual_select | |
592 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
593 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
594 // Fake a "c"hange command. When "restart_edit" is set (e.g., because |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
595 // 'insertmode' is set) fake a "d"elete command, Insert mode will |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
596 // restart automatically. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
597 // Insert the typed character in the typeahead buffer, so that it can |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
598 // be mapped in Insert mode. Required for ":lmap" to work. |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20375
diff
changeset
|
599 ins_char_typebuf(vgetc_char, vgetc_mod_mask); |
275 | 600 if (restart_edit != 0) |
601 c = 'd'; | |
602 else | |
603 c = 'c'; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
604 msg_nowait = TRUE; // don't delay going to insert mode |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
605 old_mapped_len = 0; // do go to Insert mode |
7 | 606 } |
607 | |
608 #ifdef FEAT_CMDL_INFO | |
609 need_flushbuf = add_to_showcmd(c); | |
610 #endif | |
611 | |
612 getcount: | |
613 if (!(VIsual_active && VIsual_select)) | |
614 { | |
615 /* | |
616 * Handle a count before a command and compute ca.count0. | |
617 * Note that '0' is a command and not the start of a count, but it's | |
618 * part of a count after other digits. | |
619 */ | |
620 while ( (c >= '1' && c <= '9') | |
621 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
622 { | |
623 if (c == K_DEL || c == K_KDEL) | |
624 { | |
625 ca.count0 /= 10; | |
626 #ifdef FEAT_CMDL_INFO | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
627 del_from_showcmd(4); // delete the digit and ~@% |
7 | 628 #endif |
629 } | |
630 else | |
631 ca.count0 = ca.count0 * 10 + (c - '0'); | |
23762
0f89d58eb3e3
patch 8.2.2422: crash when deleting with line number out of range
Bram Moolenaar <Bram@vim.org>
parents:
23687
diff
changeset
|
632 if (ca.count0 < 0) // overflow |
7 | 633 ca.count0 = 999999999L; |
1425 | 634 #ifdef FEAT_EVAL |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
635 // Set v:count here, when called from main() and not a stuffed |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
636 // command, so that v:count can be used in an expression mapping |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
637 // right after the count. Do set it for redo. |
5649 | 638 if (toplevel && readbuf1_empty()) |
2667 | 639 set_vcount_ca(&ca, &set_prevcount); |
1425 | 640 #endif |
7 | 641 if (ctrl_w) |
642 { | |
643 ++no_mapping; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
644 ++allow_keys; // no mapping for nchar, but keys |
7 | 645 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
646 ++no_zero_mapping; // don't map zero here |
1389 | 647 c = plain_vgetc(); |
7 | 648 LANGMAP_ADJUST(c, TRUE); |
649 --no_zero_mapping; | |
650 if (ctrl_w) | |
651 { | |
652 --no_mapping; | |
653 --allow_keys; | |
654 } | |
655 #ifdef FEAT_CMDL_INFO | |
656 need_flushbuf |= add_to_showcmd(c); | |
657 #endif | |
658 } | |
659 | |
660 /* | |
661 * If we got CTRL-W there may be a/another count | |
662 */ | |
663 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
664 { | |
665 ctrl_w = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
666 ca.opcount = ca.count0; // remember first count |
7 | 667 ca.count0 = 0; |
668 ++no_mapping; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
669 ++allow_keys; // no mapping for nchar, but keys |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
670 c = plain_vgetc(); // get next character |
7 | 671 LANGMAP_ADJUST(c, TRUE); |
672 --no_mapping; | |
673 --allow_keys; | |
674 #ifdef FEAT_CMDL_INFO | |
675 need_flushbuf |= add_to_showcmd(c); | |
676 #endif | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
677 goto getcount; // jump back |
7 | 678 } |
679 } | |
680 | |
1692 | 681 if (c == K_CURSORHOLD) |
682 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
683 // Save the count values so that ca.opcount and ca.count0 are exactly |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
684 // the same when coming back here after handling K_CURSORHOLD. |
1692 | 685 oap->prev_opcount = ca.opcount; |
686 oap->prev_count0 = ca.count0; | |
687 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
688 else if (ca.opcount != 0) |
1692 | 689 { |
690 /* | |
691 * If we're in the middle of an operator (including after entering a | |
692 * yank buffer with '"') AND we had a count before the operator, then | |
693 * that count overrides the current value of ca.count0. | |
694 * What this means effectively, is that commands like "3dw" get turned | |
695 * into "d3w" which makes things fall into place pretty neatly. | |
696 * If you give a count before AND after the operator, they are | |
697 * multiplied. | |
698 */ | |
7 | 699 if (ca.count0) |
700 ca.count0 *= ca.opcount; | |
701 else | |
702 ca.count0 = ca.opcount; | |
23762
0f89d58eb3e3
patch 8.2.2422: crash when deleting with line number out of range
Bram Moolenaar <Bram@vim.org>
parents:
23687
diff
changeset
|
703 if (ca.count0 < 0) // overflow |
0f89d58eb3e3
patch 8.2.2422: crash when deleting with line number out of range
Bram Moolenaar <Bram@vim.org>
parents:
23687
diff
changeset
|
704 ca.count0 = 999999999L; |
7 | 705 } |
706 | |
707 /* | |
708 * Always remember the count. It will be set to zero (on the next call, | |
709 * above) when there is no pending operator. | |
710 * When called from main(), save the count for use by the "count" built-in | |
711 * variable. | |
712 */ | |
713 ca.opcount = ca.count0; | |
714 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
715 | |
716 #ifdef FEAT_EVAL | |
717 /* | |
718 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 719 * Do set it for redo. |
7 | 720 */ |
5649 | 721 if (toplevel && readbuf1_empty()) |
1751 | 722 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 723 #endif |
724 | |
725 /* | |
726 * Find the command character in the table of commands. | |
727 * For CTRL-W we already got nchar when looking for a count. | |
728 */ | |
729 if (ctrl_w) | |
730 { | |
731 ca.nchar = c; | |
732 ca.cmdchar = Ctrl_W; | |
733 } | |
734 else | |
735 ca.cmdchar = c; | |
736 idx = find_command(ca.cmdchar); | |
737 if (idx < 0) | |
738 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
739 // Not a known command: beep. |
7 | 740 clearopbeep(oap); |
741 goto normal_end; | |
742 } | |
631 | 743 |
633 | 744 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 745 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
746 // This command is not allowed while editing a cmdline: beep. |
7 | 747 clearopbeep(oap); |
633 | 748 text_locked_msg(); |
7 | 749 goto normal_end; |
750 } | |
819 | 751 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
752 goto normal_end; | |
7 | 753 |
754 /* | |
755 * In Visual/Select mode, a few keys are handled in a special way. | |
756 */ | |
757 if (VIsual_active) | |
758 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
759 // when 'keymodel' contains "stopsel" may stop Select/Visual mode |
7 | 760 if (km_stopsel |
761 && (nv_cmds[idx].cmd_flags & NV_STS) | |
762 && !(mod_mask & MOD_MASK_SHIFT)) | |
763 { | |
764 end_visual_mode(); | |
765 redraw_curbuf_later(INVERTED); | |
766 } | |
767 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
768 // Keys that work different when 'keymodel' contains "startsel" |
7 | 769 if (km_startsel) |
770 { | |
771 if (nv_cmds[idx].cmd_flags & NV_SS) | |
772 { | |
773 unshift_special(&ca); | |
774 idx = find_command(ca.cmdchar); | |
840 | 775 if (idx < 0) |
776 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
777 // Just in case |
840 | 778 clearopbeep(oap); |
779 goto normal_end; | |
780 } | |
7 | 781 } |
782 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
783 && (mod_mask & MOD_MASK_SHIFT)) | |
784 mod_mask &= ~MOD_MASK_SHIFT; | |
785 } | |
786 } | |
787 | |
788 #ifdef FEAT_RIGHTLEFT | |
789 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
790 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
791 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
792 // Invert horizontal movements and operations. Only when typed by the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
793 // user directly, not when the result of a mapping or "x" translated |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
794 // to "dl". |
7 | 795 switch (ca.cmdchar) |
796 { | |
797 case 'l': ca.cmdchar = 'h'; break; | |
798 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
799 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
800 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
801 case 'h': ca.cmdchar = 'l'; break; | |
802 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
803 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
804 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
805 case '>': ca.cmdchar = '<'; break; | |
806 case '<': ca.cmdchar = '>'; break; | |
807 } | |
808 idx = find_command(ca.cmdchar); | |
809 } | |
810 #endif | |
811 | |
812 /* | |
813 * Get an additional character if we need one. | |
814 */ | |
815 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
816 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
817 && oap->op_type == OP_NOP) | |
818 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
819 || (ca.cmdchar == 'q' | |
820 && 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
|
821 && 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
|
822 && reg_executing == 0) |
7 | 823 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 824 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 825 { |
826 int *cp; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
827 int repl = FALSE; // get character for replace mode |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
828 int lit = FALSE; // get extra character literally |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
829 int langmap_active = FALSE; // using :lmap mappings |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
830 int lang; // getting a text character |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
831 #ifdef HAVE_INPUT_METHOD |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
832 int save_smd; // saved value of p_smd |
7 | 833 #endif |
834 | |
835 ++no_mapping; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
836 ++allow_keys; // no mapping for nchar, but allow key codes |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
837 // Don't generate a CursorHold event here, most commands can't handle |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
838 // it, e.g., nv_replace(), nv_csearch(). |
1343 | 839 did_cursorhold = TRUE; |
7 | 840 if (ca.cmdchar == 'g') |
841 { | |
842 /* | |
843 * For 'g' get the next character now, so that we can check for | |
844 * "gr", "g'" and "g`". | |
845 */ | |
1389 | 846 ca.nchar = plain_vgetc(); |
7 | 847 LANGMAP_ADJUST(ca.nchar, TRUE); |
848 #ifdef FEAT_CMDL_INFO | |
849 need_flushbuf |= add_to_showcmd(ca.nchar); | |
850 #endif | |
851 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 852 || ca.nchar == Ctrl_BSL) |
7 | 853 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
854 cp = &ca.extra_char; // need to get a third character |
7 | 855 if (ca.nchar != 'r') |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
856 lit = TRUE; // get it literally |
7 | 857 else |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
858 repl = TRUE; // get it in replace mode |
7 | 859 } |
860 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
861 cp = NULL; // no third character needed |
7 | 862 } |
863 else | |
864 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
865 if (ca.cmdchar == 'r') // get it in replace mode |
7 | 866 repl = TRUE; |
867 cp = &ca.nchar; | |
868 } | |
869 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
870 | |
871 /* | |
872 * Get a second or third character. | |
873 */ | |
874 if (cp != NULL) | |
875 { | |
876 if (repl) | |
877 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
878 State = REPLACE; // pretend Replace mode |
18485
63ee3c2b140f
patch 8.1.2237: mode() result depends on whether CURSOR_SHAPE is defined
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
879 #ifdef CURSOR_SHAPE |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
880 ui_cursor_shape(); // show different cursor shape |
18485
63ee3c2b140f
patch 8.1.2237: mode() result depends on whether CURSOR_SHAPE is defined
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
881 #endif |
7 | 882 } |
883 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
884 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
885 // Allow mappings defined with ":lmap". |
7 | 886 --no_mapping; |
887 --allow_keys; | |
888 if (repl) | |
889 State = LREPLACE; | |
890 else | |
891 State = LANGMAP; | |
892 langmap_active = TRUE; | |
893 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
894 #ifdef HAVE_INPUT_METHOD |
7 | 895 save_smd = p_smd; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
896 p_smd = FALSE; // Don't let the IM code show the mode here |
7 | 897 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) |
898 im_set_active(TRUE); | |
899 #endif | |
22000
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
900 if ((State & INSERT) && !p_ek) |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
901 { |
22091
9bb1c984c4da
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Bram Moolenaar <Bram@vim.org>
parents:
22000
diff
changeset
|
902 #ifdef FEAT_JOB_CHANNEL |
9bb1c984c4da
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Bram Moolenaar <Bram@vim.org>
parents:
22000
diff
changeset
|
903 ch_log_output = TRUE; |
9bb1c984c4da
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Bram Moolenaar <Bram@vim.org>
parents:
22000
diff
changeset
|
904 #endif |
22000
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
905 // Disable bracketed paste and modifyOtherKeys here, we won't |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
906 // recognize the escape sequences with 'esckeys' off. |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
907 out_str(T_BD); |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
908 out_str(T_CTE); |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
909 } |
7 | 910 |
1389 | 911 *cp = plain_vgetc(); |
7 | 912 |
22000
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
913 if ((State & INSERT) && !p_ek) |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
914 { |
22091
9bb1c984c4da
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Bram Moolenaar <Bram@vim.org>
parents:
22000
diff
changeset
|
915 #ifdef FEAT_JOB_CHANNEL |
9bb1c984c4da
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Bram Moolenaar <Bram@vim.org>
parents:
22000
diff
changeset
|
916 ch_log_output = TRUE; |
9bb1c984c4da
patch 8.2.1595: cannot easily see what Vim sends to the terminal
Bram Moolenaar <Bram@vim.org>
parents:
22000
diff
changeset
|
917 #endif |
22000
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
918 // Re-enable bracketed paste mode and modifyOtherKeys |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
919 out_str(T_BE); |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
920 out_str(T_CTI); |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
921 } |
afa3080a96ae
patch 8.2.1549: "r" fails if 'esckeys' is off and modifyOtherKeys is used
Bram Moolenaar <Bram@vim.org>
parents:
21941
diff
changeset
|
922 |
7 | 923 if (langmap_active) |
924 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
925 // Undo the decrement done above |
7 | 926 ++no_mapping; |
927 ++allow_keys; | |
928 State = NORMAL_BUSY; | |
929 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
930 #ifdef HAVE_INPUT_METHOD |
7 | 931 if (lang) |
932 { | |
933 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
934 im_save_status(&curbuf->b_p_iminsert); | |
935 im_set_active(FALSE); | |
936 } | |
937 p_smd = save_smd; | |
938 #endif | |
939 State = NORMAL_BUSY; | |
940 #ifdef FEAT_CMDL_INFO | |
941 need_flushbuf |= add_to_showcmd(*cp); | |
942 #endif | |
943 | |
944 if (!lit) | |
945 { | |
946 #ifdef FEAT_DIGRAPHS | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
947 // Typing CTRL-K gets a digraph. |
7 | 948 if (*cp == Ctrl_K |
949 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
950 || cp == &ca.extra_char) | |
951 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
952 { | |
953 c = get_digraph(FALSE); | |
954 if (c > 0) | |
955 { | |
956 *cp = c; | |
957 # ifdef FEAT_CMDL_INFO | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
958 // Guessing how to update showcmd here... |
7 | 959 del_from_showcmd(3); |
960 need_flushbuf |= add_to_showcmd(*cp); | |
961 # endif | |
962 } | |
963 } | |
964 #endif | |
965 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
966 // adjust chars > 127, except after "tTfFr" commands |
7 | 967 LANGMAP_ADJUST(*cp, !lang); |
968 #ifdef FEAT_RIGHTLEFT | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
969 // adjust Hebrew mapped char |
7 | 970 if (p_hkmap && lang && KeyTyped) |
971 *cp = hkmap(*cp); | |
972 #endif | |
973 } | |
974 | |
975 /* | |
976 * When the next character is CTRL-\ a following CTRL-N means the | |
977 * command is aborted and we go to Normal mode. | |
978 */ | |
979 if (cp == &ca.extra_char | |
980 && ca.nchar == Ctrl_BSL | |
981 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
982 { | |
983 ca.cmdchar = Ctrl_BSL; | |
984 ca.nchar = ca.extra_char; | |
985 idx = find_command(ca.cmdchar); | |
986 } | |
3908 | 987 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 988 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 989 else if (*cp == Ctrl_BSL) |
990 { | |
991 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
992 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
993 // There is a busy wait here when typing "f<C-\>" and then |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
994 // something different from CTRL-N. Can't be avoided. |
7 | 995 while ((c = vpeekc()) <= 0 && towait > 0L) |
996 { | |
23648
b7d3c79075c5
patch 8.2.2366: when using ":sleep" the cursor is always displayed
Bram Moolenaar <Bram@vim.org>
parents:
23272
diff
changeset
|
997 do_sleep(towait > 50L ? 50L : towait, FALSE); |
7 | 998 towait -= 50L; |
999 } | |
1000 if (c > 0) | |
1001 { | |
1389 | 1002 c = plain_vgetc(); |
7 | 1003 if (c != Ctrl_N && c != Ctrl_G) |
1004 vungetc(c); | |
1005 else | |
1006 { | |
1007 ca.cmdchar = Ctrl_BSL; | |
1008 ca.nchar = c; | |
1009 idx = find_command(ca.cmdchar); | |
1010 } | |
1011 } | |
1012 } | |
1013 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1014 // When getting a text character and the next character is a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1015 // multi-byte character, it could be a composing character. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1016 // However, don't wait for it to arrive. Also, do enable mapping, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1017 // because if it's put back with vungetc() it's too late to apply |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1018 // mapping. |
6071 | 1019 --no_mapping; |
7 | 1020 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1021 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1022 { | |
1389 | 1023 c = plain_vgetc(); |
7 | 1024 if (!utf_iscomposing(c)) |
1025 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1026 vungetc(c); // it wasn't, put it back |
7 | 1027 break; |
1028 } | |
1029 else if (ca.ncharC1 == 0) | |
1030 ca.ncharC1 = c; | |
1031 else | |
1032 ca.ncharC2 = c; | |
1033 } | |
6071 | 1034 ++no_mapping; |
7 | 1035 } |
1036 --no_mapping; | |
1037 --allow_keys; | |
1038 } | |
1039 | |
1040 #ifdef FEAT_CMDL_INFO | |
1041 /* | |
1042 * Flush the showcmd characters onto the screen so we can see them while | |
1043 * the command is being executed. Only do this when the shown command was | |
1044 * actually displayed, otherwise this will slow down a lot when executing | |
1045 * mappings. | |
1046 */ | |
1047 if (need_flushbuf) | |
1048 out_flush(); | |
1049 #endif | |
1727 | 1050 if (ca.cmdchar != K_IGNORE) |
21415
b530a433fe7d
patch 8.2.1258: CursorHold does not work well
Bram Moolenaar <Bram@vim.org>
parents:
21405
diff
changeset
|
1051 { |
b530a433fe7d
patch 8.2.1258: CursorHold does not work well
Bram Moolenaar <Bram@vim.org>
parents:
21405
diff
changeset
|
1052 if (ex_normal_busy) |
b530a433fe7d
patch 8.2.1258: CursorHold does not work well
Bram Moolenaar <Bram@vim.org>
parents:
21405
diff
changeset
|
1053 did_cursorhold = save_did_cursorhold; |
b530a433fe7d
patch 8.2.1258: CursorHold does not work well
Bram Moolenaar <Bram@vim.org>
parents:
21405
diff
changeset
|
1054 else |
b530a433fe7d
patch 8.2.1258: CursorHold does not work well
Bram Moolenaar <Bram@vim.org>
parents:
21405
diff
changeset
|
1055 did_cursorhold = FALSE; |
b530a433fe7d
patch 8.2.1258: CursorHold does not work well
Bram Moolenaar <Bram@vim.org>
parents:
21405
diff
changeset
|
1056 } |
7 | 1057 |
1058 State = NORMAL; | |
1059 | |
1060 if (ca.nchar == ESC) | |
1061 { | |
1062 clearop(oap); | |
1063 if (restart_edit == 0 && goto_im()) | |
1064 restart_edit = 'a'; | |
1065 goto normal_end; | |
1066 } | |
1067 | |
24 | 1068 if (ca.cmdchar != K_IGNORE) |
1069 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1070 msg_didout = FALSE; // don't scroll screen up for normal command |
24 | 1071 msg_col = 0; |
1072 } | |
7 | 1073 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1074 old_pos = curwin->w_cursor; // remember where cursor was |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1075 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1076 // When 'keymodel' contains "startsel" some keys start Select/Visual |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1077 // mode. |
7 | 1078 if (!VIsual_active && km_startsel) |
1079 { | |
1080 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1081 { | |
1082 start_selection(); | |
1083 unshift_special(&ca); | |
1084 idx = find_command(ca.cmdchar); | |
1085 } | |
1086 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1087 && (mod_mask & MOD_MASK_SHIFT)) | |
1088 { | |
1089 start_selection(); | |
1090 mod_mask &= ~MOD_MASK_SHIFT; | |
1091 } | |
1092 } | |
1093 | |
1094 /* | |
1095 * Execute the command! | |
1096 * Call the command function found in the commands table. | |
1097 */ | |
1098 ca.arg = nv_cmds[idx].cmd_arg; | |
1099 (nv_cmds[idx].cmd_func)(&ca); | |
1100 | |
1101 /* | |
1102 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1103 * need it later. | |
1104 */ | |
1105 if (!finish_op | |
1106 && !oap->op_type | |
1107 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1108 { | |
1109 clearop(oap); | |
1110 #ifdef FEAT_EVAL | |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
1111 reset_reg_var(); |
7 | 1112 #endif |
1113 } | |
1114 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1115 // Get the length of mapped chars again after typing a count, second |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1116 // character or "z333<cr>". |
36 | 1117 if (old_mapped_len > 0) |
1118 old_mapped_len = typebuf_maplen(); | |
1119 | |
7 | 1120 /* |
24586
b7f58be68c02
patch 8.2.2832: operator cancelled by moving mouse when using popup
Bram Moolenaar <Bram@vim.org>
parents:
24341
diff
changeset
|
1121 * If an operation is pending, handle it. But not for K_IGNORE or |
b7f58be68c02
patch 8.2.2832: operator cancelled by moving mouse when using popup
Bram Moolenaar <Bram@vim.org>
parents:
24341
diff
changeset
|
1122 * K_MOUSEMOVE. |
7 | 1123 */ |
24586
b7f58be68c02
patch 8.2.2832: operator cancelled by moving mouse when using popup
Bram Moolenaar <Bram@vim.org>
parents:
24341
diff
changeset
|
1124 if (ca.cmdchar != K_IGNORE && ca.cmdchar != K_MOUSEMOVE) |
18775
5da1ad9165f0
patch 8.1.2377: GUI: when losing focus a pending operator is executed
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
1125 do_pending_operator(&ca, old_col, FALSE); |
7 | 1126 |
1127 /* | |
1128 * Wait for a moment when a message is displayed that will be overwritten | |
1129 * by the mode message. | |
1130 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1131 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1132 * In Visual mode, it's more important to keep the Visual area updated | |
1133 * than keeping a message (e.g. from a /pat search). | |
1134 * Only do this if the command was typed, not from a mapping. | |
1135 * Don't wait when emsg_silent is non-zero. | |
1136 * Also wait a bit after an error message, e.g. for "^O:". | |
1137 * Don't redraw the screen, it would remove the message. | |
1138 */ | |
1139 if ( ((p_smd | |
641 | 1140 && msg_silent == 0 |
7 | 1141 && (restart_edit != 0 |
1142 || (VIsual_active | |
1143 && old_pos.lnum == curwin->w_cursor.lnum | |
1144 && old_pos.col == curwin->w_cursor.col) | |
1145 ) | |
1146 && (clear_cmdline | |
1147 || redraw_cmdline) | |
1148 && (msg_didout || (msg_didany && msg_scroll)) | |
1149 && !msg_nowait | |
1150 && KeyTyped) | |
1151 || (restart_edit != 0 | |
1152 && !VIsual_active | |
1153 && (msg_scroll | |
1154 || emsg_on_display))) | |
1155 && oap->regname == 0 | |
1156 && !(ca.retval & CA_COMMAND_BUSY) | |
1157 && stuff_empty() | |
1158 && typebuf_typed() | |
1159 && emsg_silent == 0 | |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22176
diff
changeset
|
1160 && !in_assert_fails |
7 | 1161 && !did_wait_return |
1162 && oap->op_type == OP_NOP) | |
1163 { | |
1164 int save_State = State; | |
1165 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1166 // Draw the cursor with the right shape here |
7 | 1167 if (restart_edit != 0) |
1168 State = INSERT; | |
1169 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1170 // If need to redraw, and there is a "keep_msg", redraw before the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1171 // delay |
7 | 1172 if (must_redraw && keep_msg != NULL && !emsg_on_display) |
1173 { | |
1174 char_u *kmsg; | |
1175 | |
1176 kmsg = keep_msg; | |
1177 keep_msg = NULL; | |
19681
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1178 // Showmode() will clear keep_msg, but we want to use it anyway. |
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1179 // First update w_topline. |
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1180 setcursor(); |
7 | 1181 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
|
1182 // now reset it, otherwise it's put in the history again |
7 | 1183 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
|
1184 |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1185 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
|
1186 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
|
1187 { |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1188 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
|
1189 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
|
1190 } |
7 | 1191 } |
1192 setcursor(); | |
19681
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1193 #ifdef CURSOR_SHAPE |
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1194 ui_cursor_shape(); // may show different cursor shape |
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1195 #endif |
7 | 1196 cursor_on(); |
1197 out_flush(); | |
1198 if (msg_scroll || emsg_on_display) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1199 ui_delay(1003L, TRUE); // wait at least one second |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1200 ui_delay(3003L, FALSE); // wait up to three seconds |
7 | 1201 State = save_State; |
1202 | |
1203 msg_scroll = FALSE; | |
1204 emsg_on_display = FALSE; | |
1205 } | |
1206 | |
1207 /* | |
1208 * Finish up after executing a Normal mode command. | |
1209 */ | |
1210 normal_end: | |
1211 | |
1212 msg_nowait = FALSE; | |
1213 | |
20754
e6a5a5ef4034
patch 8.2.0929: v:register is not cleared after an operator was executed
Bram Moolenaar <Bram@vim.org>
parents:
20721
diff
changeset
|
1214 #ifdef FEAT_EVAL |
e6a5a5ef4034
patch 8.2.0929: v:register is not cleared after an operator was executed
Bram Moolenaar <Bram@vim.org>
parents:
20721
diff
changeset
|
1215 if (finish_op) |
e6a5a5ef4034
patch 8.2.0929: v:register is not cleared after an operator was executed
Bram Moolenaar <Bram@vim.org>
parents:
20721
diff
changeset
|
1216 reset_reg_var(); |
e6a5a5ef4034
patch 8.2.0929: v:register is not cleared after an operator was executed
Bram Moolenaar <Bram@vim.org>
parents:
20721
diff
changeset
|
1217 #endif |
e6a5a5ef4034
patch 8.2.0929: v:register is not cleared after an operator was executed
Bram Moolenaar <Bram@vim.org>
parents:
20721
diff
changeset
|
1218 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1219 // Reset finish_op, in case it was set |
7 | 1220 #ifdef CURSOR_SHAPE |
1221 c = finish_op; | |
1222 #endif | |
1223 finish_op = FALSE; | |
1224 #ifdef CURSOR_SHAPE | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1225 // Redraw the cursor with another shape, if we were in Operator-pending |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1226 // mode or did a replace command. |
7 | 1227 if (c || ca.cmdchar == 'r') |
1228 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1229 ui_cursor_shape(); // may show different cursor shape |
7 | 1230 # ifdef FEAT_MOUSESHAPE |
1231 update_mouseshape(-1); | |
1232 # endif | |
1233 } | |
1234 #endif | |
1235 | |
1236 #ifdef FEAT_CMDL_INFO | |
1692 | 1237 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
|
1238 && ca.cmdchar != K_CURSORHOLD) |
7 | 1239 clear_showcmd(); |
1240 #endif | |
1241 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1242 checkpcmark(); // check if we moved since setting pcmark |
7 | 1243 vim_free(ca.searchbuf); |
1244 | |
1245 if (has_mbyte) | |
1246 mb_adjust_cursor(); | |
1247 | |
1248 if (curwin->w_p_scb && toplevel) | |
1249 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1250 validate_cursor(); // may need to update w_leftcol |
7 | 1251 do_check_scrollbind(TRUE); |
1252 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1253 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1254 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1255 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1256 validate_cursor(); // may need to update w_leftcol |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1257 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1258 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1259 |
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
|
1260 #ifdef FEAT_TERMINAL |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1261 // don't go to Insert mode if a terminal has a running job |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
1262 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
|
1263 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
|
1264 #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
|
1265 |
7 | 1266 /* |
1267 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1268 * if still inside a mapping that started in Visual mode). | |
1269 * May switch from Visual to Select mode after CTRL-O command. | |
1270 */ | |
1271 if ( oap->op_type == OP_NOP | |
1272 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1273 || restart_VIsual_select == 1) | |
1274 && !(ca.retval & CA_COMMAND_BUSY) | |
1275 && stuff_empty() | |
1276 && oap->regname == 0) | |
1277 { | |
1278 if (restart_VIsual_select == 1) | |
1279 { | |
1280 VIsual_select = TRUE; | |
1281 showmode(); | |
1282 restart_VIsual_select = 0; | |
1283 } | |
5735 | 1284 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1285 (void)edit(restart_edit, FALSE, 1L); |
1286 } | |
1287 | |
1288 if (restart_VIsual_select == 2) | |
1289 restart_VIsual_select = 1; | |
1290 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1291 // Save count before an operator for next time. |
7 | 1292 opcount = ca.opcount; |
1293 } | |
1294 | |
2667 | 1295 #ifdef FEAT_EVAL |
1296 /* | |
1297 * Set v:count and v:count1 according to "cap". | |
1298 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1299 */ | |
1300 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1301 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1302 { |
1303 long count = cap->count0; | |
1304 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1305 // multiply with cap->opcount the same way as above |
2667 | 1306 if (cap->opcount != 0) |
1307 count = cap->opcount * (count == 0 ? 1 : count); | |
1308 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1309 *set_prevcount = FALSE; // only set v:prevcount once |
2667 | 1310 } |
1311 #endif | |
1312 | |
7 | 1313 /* |
19681
e21c22c58e2b
patch 8.2.0397: delayed screen update when using undo from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
1314 * Check if highlighting for Visual mode is possible, give a warning message |
7 | 1315 * if not. |
1316 */ | |
1317 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1318 check_visual_highlight(void) |
7 | 1319 { |
1320 static int did_check = FALSE; | |
1321 | |
1322 if (full_screen) | |
1323 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1324 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
|
1325 msg(_("Warning: terminal cannot highlight")); |
7 | 1326 did_check = TRUE; |
1327 } | |
1328 } | |
1329 | |
23021
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1330 #if defined(FEAT_CLIPBOARD) && defined(FEAT_EVAL) |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1331 /* |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1332 * Call yank_do_autocmd() for "regname". |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1333 */ |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1334 static void |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1335 call_yank_do_autocmd(int regname) |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1336 { |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1337 oparg_T oa; |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1338 yankreg_T *reg; |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1339 |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1340 clear_oparg(&oa); |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1341 oa.regname = regname; |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1342 oa.op_type = OP_YANK; |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1343 oa.is_VIsual = TRUE; |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1344 reg = get_register(regname, TRUE); |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1345 yank_do_autocmd(&oa, reg); |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1346 free_register(reg); |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1347 } |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1348 #endif |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1349 |
7 | 1350 /* |
638 | 1351 * End Visual mode. |
24788
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1352 * This function or the next should ALWAYS be called to end Visual mode, except |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1353 * from do_pending_operator(). |
7 | 1354 */ |
1355 void | |
24788
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1356 end_visual_mode() |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1357 { |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1358 end_visual_mode_keep_button(); |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1359 reset_held_button(); |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1360 } |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1361 |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1362 void |
b36ceac30454
patch 8.2.2932: select mode test fails
Bram Moolenaar <Bram@vim.org>
parents:
24784
diff
changeset
|
1363 end_visual_mode_keep_button() |
7 | 1364 { |
1365 #ifdef FEAT_CLIPBOARD | |
1366 /* | |
1367 * If we are using the clipboard, then remember what was selected in case | |
1368 * we need to paste it somewhere while we still own the selection. | |
1369 * Only do this when the clipboard is already owned. Don't want to grab | |
1370 * the selection when hitting ESC. | |
1371 */ | |
1372 if (clip_star.available && clip_star.owned) | |
1373 clip_auto_select(); | |
23021
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1374 |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1375 # if defined(FEAT_EVAL) |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1376 // Emit a TextYankPost for the automatic copy of the selection into the |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1377 // star and/or plus register. |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1378 if (has_textyankpost()) |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1379 { |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1380 if (clip_isautosel_star()) |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1381 call_yank_do_autocmd('*'); |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1382 if (clip_isautosel_plus()) |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1383 call_yank_do_autocmd('+'); |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1384 } |
d10a37eb91ee
patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1385 # endif |
7 | 1386 #endif |
1387 | |
1388 VIsual_active = FALSE; | |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25786
diff
changeset
|
1389 trigger_modechanged(); |
7 | 1390 setmouse(); |
1391 mouse_dragging = 0; | |
1392 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1393 // Save the current VIsual area for '< and '> marks, and "gv" |
690 | 1394 curbuf->b_visual.vi_mode = VIsual_mode; |
1395 curbuf->b_visual.vi_start = VIsual; | |
1396 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1397 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 1398 #ifdef FEAT_EVAL |
1399 curbuf->b_visual_mode_eval = VIsual_mode; | |
1400 #endif | |
1401 if (!virtual_active()) | |
1402 curwin->w_cursor.coladd = 0; | |
6979 | 1403 may_clear_cmdline(); |
7 | 1404 |
844 | 1405 adjust_cursor_eol(); |
7 | 1406 } |
1407 | |
1408 /* | |
1409 * Reset VIsual_active and VIsual_reselect. | |
1410 */ | |
1411 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1412 reset_VIsual_and_resel(void) |
7 | 1413 { |
1414 if (VIsual_active) | |
1415 { | |
1416 end_visual_mode(); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1417 redraw_curbuf_later(INVERTED); // delete the inversion later |
7 | 1418 } |
1419 VIsual_reselect = FALSE; | |
1420 } | |
1421 | |
1422 /* | |
1423 * Reset VIsual_active and VIsual_reselect if it's set. | |
1424 */ | |
1425 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1426 reset_VIsual(void) |
7 | 1427 { |
1428 if (VIsual_active) | |
1429 { | |
1430 end_visual_mode(); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1431 redraw_curbuf_later(INVERTED); // delete the inversion later |
7 | 1432 VIsual_reselect = FALSE; |
1433 } | |
1434 } | |
1435 | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1436 void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1437 restore_visual_mode(void) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1438 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1439 if (VIsual_mode_orig != NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1440 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1441 curbuf->b_visual.vi_mode = VIsual_mode_orig; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1442 VIsual_mode_orig = NUL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1443 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1444 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1445 |
7 | 1446 /* |
1447 * Check for a balloon-eval special item to include when searching for an | |
1448 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
1449 * Returns TRUE if the character at "*ptr" should be included. | |
1450 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
1451 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
1452 * "bnp" points to a counter for square brackets. | |
1453 */ | |
1454 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1455 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1456 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1457 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1458 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1459 int dir) |
7 | 1460 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1461 // Accept everything inside []. |
7 | 1462 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) |
1463 ++*bnp; | |
1464 if (*bnp > 0) | |
1465 { | |
1466 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
1467 --*bnp; | |
1468 return TRUE; | |
1469 } | |
1470 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1471 // skip over "s.var" |
7 | 1472 if (*ptr == '.') |
1473 return TRUE; | |
1474 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1475 // two-character item: s->var |
7 | 1476 if (ptr[dir == BACKWARD ? 0 : 1] == '>' |
1477 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
1478 { | |
1479 *colp += dir; | |
1480 return TRUE; | |
1481 } | |
1482 return FALSE; | |
1483 } | |
1484 | |
1485 /* | |
1486 * Find the identifier under or to the right of the cursor. | |
1487 * "find_type" can have one of three values: | |
1488 * 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
|
1489 * 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
|
1490 * FIND_IDENT + FIND_STRING: find any non-white text, identifier preferred. |
184 | 1491 * FIND_EVAL: find text useful for C program debugging |
7 | 1492 * |
1493 * 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
|
1494 * 1. Search forward for the start of an identifier/text. Doesn't move if |
7 | 1495 * 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
|
1496 * 2. Search backward for the start of this identifier/text. |
7 | 1497 * This doesn't match the real Vi but I like it a little better and it |
1498 * 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
|
1499 * 3. Search forward to the end of this identifier/text. |
7 | 1500 * When FIND_IDENT isn't defined, we backup until a blank. |
1501 * | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1502 * 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
|
1503 * 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
|
1504 * points into the current buffer line and is not always NUL terminated. |
7 | 1505 */ |
1506 int | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1507 find_ident_under_cursor(char_u **text, int find_type) |
7 | 1508 { |
1509 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
|
1510 curwin->w_cursor.col, text, NULL, find_type); |
7 | 1511 } |
1512 | |
1513 /* | |
1514 * Like find_ident_under_cursor(), but for any window and any position. | |
1515 * However: Uses 'iskeyword' from the current window!. | |
1516 */ | |
1517 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1518 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1519 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1520 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1521 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
|
1522 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
|
1523 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
|
1524 int find_type) |
7 | 1525 { |
1526 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
|
1527 int col = 0; // init to shut up GCC |
7 | 1528 int i; |
1529 int this_class = 0; | |
1530 int prev_class; | |
1531 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
|
1532 int bn = 0; // bracket nesting |
7 | 1533 |
1534 /* | |
1535 * 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
|
1536 * if i == 1: try to find any non-white text |
7 | 1537 */ |
1538 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
1539 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
1540 { | |
1541 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1542 * 1. skip to start of identifier/text |
7 | 1543 */ |
1544 col = startcol; | |
1545 if (has_mbyte) | |
1546 { | |
1547 while (ptr[col] != NUL) | |
1548 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1549 // Stop at a ']' to evaluate "a[x]". |
7 | 1550 if ((find_type & FIND_EVAL) && ptr[col] == ']') |
1551 break; | |
1552 this_class = mb_get_class(ptr + col); | |
1553 if (this_class != 0 && (i == 1 || this_class != 1)) | |
1554 break; | |
474 | 1555 col += (*mb_ptr2len)(ptr + col); |
7 | 1556 } |
1557 } | |
1558 else | |
1559 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
|
1560 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 1561 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
1562 ) | |
1563 ++col; | |
1564 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1565 // When starting on a ']' count it, so that we include the '['. |
7 | 1566 bn = ptr[col] == ']'; |
1567 | |
1568 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1569 * 2. Back up to start of identifier/text. |
7 | 1570 */ |
1571 if (has_mbyte) | |
1572 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1573 // Remember class of character under cursor. |
7 | 1574 if ((find_type & FIND_EVAL) && ptr[col] == ']') |
1575 this_class = mb_get_class((char_u *)"a"); | |
1576 else | |
1577 this_class = mb_get_class(ptr + col); | |
835 | 1578 while (col > 0 && this_class != 0) |
7 | 1579 { |
1580 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
1581 prev_class = mb_get_class(ptr + prevcol); | |
1582 if (this_class != prev_class | |
1583 && (i == 0 | |
1584 || prev_class == 0 | |
1585 || (find_type & FIND_IDENT)) | |
1586 && (!(find_type & FIND_EVAL) | |
1587 || prevcol == 0 | |
1588 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
1589 &bn, BACKWARD)) | |
1590 ) | |
1591 break; | |
1592 col = prevcol; | |
1593 } | |
1594 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1595 // 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
|
1596 // identifier, stop searching. |
7 | 1597 if (this_class > 2) |
1598 this_class = 2; | |
1599 if (!(find_type & FIND_STRING) || this_class == 2) | |
1600 break; | |
1601 } | |
1602 else | |
1603 { | |
1604 while (col > 0 | |
1605 && ((i == 0 | |
1606 ? 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
|
1607 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 1608 && (!(find_type & FIND_IDENT) |
1609 || !vim_iswordc(ptr[col - 1])))) | |
1610 || ((find_type & FIND_EVAL) | |
1611 && col > 1 | |
1612 && find_is_eval_item(ptr + col - 1, &col, | |
1613 &bn, BACKWARD)) | |
1614 )) | |
1615 --col; | |
1616 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1617 // 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
|
1618 // identifier, stop searching. |
7 | 1619 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) |
1620 break; | |
1621 } | |
1622 } | |
1623 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1624 if (ptr[col] == NUL || (i == 0 |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1625 && (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col])))) |
7 | 1626 { |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1627 // 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
|
1628 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
|
1629 { |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1630 if (find_type & FIND_STRING) |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1631 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
|
1632 else |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1633 emsg(_(e_noident)); |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1634 } |
7 | 1635 return 0; |
1636 } | |
1637 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
|
1638 *text = ptr; |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1639 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
|
1640 *textcol = col; |
7 | 1641 |
1642 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1643 * 3. Find the end if the identifier/text. |
7 | 1644 */ |
1645 bn = 0; | |
1646 startcol -= col; | |
1647 col = 0; | |
1648 if (has_mbyte) | |
1649 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1650 // Search for point of changing multibyte character class. |
7 | 1651 this_class = mb_get_class(ptr); |
1652 while (ptr[col] != NUL | |
1653 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
1654 : mb_get_class(ptr + col) != 0) | |
1655 || ((find_type & FIND_EVAL) | |
1656 && col <= (int)startcol | |
1657 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
1658 )) | |
474 | 1659 col += (*mb_ptr2len)(ptr + col); |
7 | 1660 } |
1661 else | |
1662 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
|
1663 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 1664 || ((find_type & FIND_EVAL) |
1665 && col <= (int)startcol | |
1666 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
1667 ) | |
1668 ++col; | |
1669 | |
1670 return col; | |
1671 } | |
1672 | |
1673 /* | |
1674 * Prepare for redo of a normal command. | |
1675 */ | |
1676 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1677 prep_redo_cmd(cmdarg_T *cap) |
7 | 1678 { |
1679 prep_redo(cap->oap->regname, cap->count0, | |
1680 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
1681 } | |
1682 | |
1683 /* | |
1684 * Prepare for redo of any command. | |
1685 * Note that only the last argument can be a multi-byte char. | |
1686 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
1687 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1688 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1689 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1690 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1691 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1692 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1693 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1694 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1695 int cmd5) |
7 | 1696 { |
1697 ResetRedobuff(); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1698 if (regname != 0) // yank from specified buffer |
7 | 1699 { |
1700 AppendCharToRedobuff('"'); | |
1701 AppendCharToRedobuff(regname); | |
1702 } | |
1703 if (num) | |
1704 AppendNumberToRedobuff(num); | |
1705 | |
1706 if (cmd1 != NUL) | |
1707 AppendCharToRedobuff(cmd1); | |
1708 if (cmd2 != NUL) | |
1709 AppendCharToRedobuff(cmd2); | |
1710 if (cmd3 != NUL) | |
1711 AppendCharToRedobuff(cmd3); | |
1712 if (cmd4 != NUL) | |
1713 AppendCharToRedobuff(cmd4); | |
1714 if (cmd5 != NUL) | |
1715 AppendCharToRedobuff(cmd5); | |
1716 } | |
1717 | |
1718 /* | |
1719 * check for operator active and clear it | |
1720 * | |
1721 * return TRUE if operator was active | |
1722 */ | |
1723 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1724 checkclearop(oparg_T *oap) |
7 | 1725 { |
1726 if (oap->op_type == OP_NOP) | |
1727 return FALSE; | |
1728 clearopbeep(oap); | |
1729 return TRUE; | |
1730 } | |
1731 | |
1732 /* | |
1131 | 1733 * Check for operator or Visual active. Clear active operator. |
7 | 1734 * |
1131 | 1735 * Return TRUE if operator or Visual was active. |
7 | 1736 */ |
1737 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1738 checkclearopq(oparg_T *oap) |
7 | 1739 { |
5735 | 1740 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 1741 return FALSE; |
1742 clearopbeep(oap); | |
1743 return TRUE; | |
1744 } | |
1745 | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
1746 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1747 clearop(oparg_T *oap) |
7 | 1748 { |
1749 oap->op_type = OP_NOP; | |
1750 oap->regname = 0; | |
1751 oap->motion_force = NUL; | |
1752 oap->use_reg_one = FALSE; | |
24800
b032da736676
patch 8.2.2938: after using motion force from feedkeys() it sticks
Bram Moolenaar <Bram@vim.org>
parents:
24788
diff
changeset
|
1753 motion_force = NUL; |
7 | 1754 } |
1755 | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
1756 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1757 clearopbeep(oparg_T *oap) |
7 | 1758 { |
1759 clearop(oap); | |
1760 beep_flush(); | |
1761 } | |
1762 | |
1763 /* | |
1764 * Remove the shift modifier from a special key. | |
1765 */ | |
1766 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1767 unshift_special(cmdarg_T *cap) |
7 | 1768 { |
1769 switch (cap->cmdchar) | |
1770 { | |
1771 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
1772 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
1773 case K_S_UP: cap->cmdchar = K_UP; break; | |
1774 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
1775 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
1776 case K_S_END: cap->cmdchar = K_END; break; | |
1777 } | |
1778 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
1779 } | |
1780 | |
6979 | 1781 /* |
1782 * If the mode is currently displayed clear the command line or update the | |
1783 * command displayed. | |
1784 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1785 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1786 may_clear_cmdline(void) |
6979 | 1787 { |
1788 if (mode_displayed) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1789 clear_cmdline = TRUE; // unshow visual mode later |
6979 | 1790 #ifdef FEAT_CMDL_INFO |
1791 else | |
1792 clear_showcmd(); | |
1793 #endif | |
1794 } | |
1795 | |
7 | 1796 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
1797 /* | |
1798 * Routines for displaying a partly typed command | |
1799 */ | |
1800 | |
5735 | 1801 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 1802 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1803 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; // For push_showcmd() |
7 | 1804 static int showcmd_is_clear = TRUE; |
1805 static int showcmd_visual = FALSE; | |
1806 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
1807 static void display_showcmd(void); |
7 | 1808 |
1809 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1810 clear_showcmd(void) |
7 | 1811 { |
1812 if (!p_sc) | |
1813 return; | |
1814 | |
1815 if (VIsual_active && !char_avail()) | |
1816 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1817 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 1818 long lines; |
1819 colnr_T leftcol, rightcol; | |
1820 linenr_T top, bot; | |
1821 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1822 // Show the size of the Visual area. |
1866 | 1823 if (cursor_bot) |
7 | 1824 { |
1825 top = VIsual.lnum; | |
1826 bot = curwin->w_cursor.lnum; | |
1827 } | |
1828 else | |
1829 { | |
1830 top = curwin->w_cursor.lnum; | |
1831 bot = VIsual.lnum; | |
1832 } | |
1833 # ifdef FEAT_FOLDING | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1834 // Include closed folds as a whole. |
7009 | 1835 (void)hasFolding(top, &top, NULL); |
1836 (void)hasFolding(bot, NULL, &bot); | |
7 | 1837 # endif |
1838 lines = bot - top + 1; | |
1839 | |
1840 if (VIsual_mode == Ctrl_V) | |
1841 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1842 # ifdef FEAT_LINEBREAK |
1866 | 1843 char_u *saved_sbr = p_sbr; |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18485
diff
changeset
|
1844 char_u *saved_w_sbr = curwin->w_p_sbr; |
1866 | 1845 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1846 // Make 'sbr' empty for a moment to get the correct size. |
1866 | 1847 p_sbr = empty_option; |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18485
diff
changeset
|
1848 curwin->w_p_sbr = empty_option; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1849 # endif |
7 | 1850 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
|
1851 # ifdef FEAT_LINEBREAK |
1866 | 1852 p_sbr = saved_sbr; |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18485
diff
changeset
|
1853 curwin->w_p_sbr = saved_w_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
1854 # endif |
7 | 1855 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
1856 (long)(rightcol - leftcol + 1)); | |
1857 } | |
1858 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
1859 sprintf((char *)showcmd_buf, "%ld", lines); | |
1860 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1861 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1862 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
|
1863 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1864 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
|
1865 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
|
1866 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1867 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
|
1868 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1869 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
|
1870 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
|
1871 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1872 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1873 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1874 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
|
1875 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
|
1876 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1877 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
|
1878 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1879 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
|
1880 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
|
1881 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1882 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1883 ++chars; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1884 break; // end of line |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1885 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1886 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1887 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1888 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1889 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1890 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
|
1891 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
|
1892 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
1893 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
|
1894 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1895 showcmd_buf[SHOWCMD_COLS] = NUL; // truncate |
7 | 1896 showcmd_visual = TRUE; |
1897 } | |
1898 else | |
1899 { | |
1900 showcmd_buf[0] = NUL; | |
1901 showcmd_visual = FALSE; | |
1902 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1903 // Don't actually display something if there is nothing to clear. |
7 | 1904 if (showcmd_is_clear) |
1905 return; | |
1906 } | |
1907 | |
1908 display_showcmd(); | |
1909 } | |
1910 | |
1911 /* | |
1912 * Add 'c' to string of shown command chars. | |
1913 * Return TRUE if output has been written (and setcursor() has been called). | |
1914 */ | |
1915 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1916 add_to_showcmd(int c) |
7 | 1917 { |
1918 char_u *p; | |
1919 int old_len; | |
1920 int extra_len; | |
1921 int overflow; | |
1922 int i; | |
1923 static int ignore[] = | |
1924 { | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18291
diff
changeset
|
1925 #ifdef FEAT_GUI |
7 | 1926 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
1927 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18291
diff
changeset
|
1928 #endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1929 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
|
1930 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 1931 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
1932 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
|
1933 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 1934 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 1935 K_CURSORHOLD, |
7 | 1936 0 |
1937 }; | |
1938 | |
641 | 1939 if (!p_sc || msg_silent != 0) |
7 | 1940 return FALSE; |
1941 | |
1942 if (showcmd_visual) | |
1943 { | |
1944 showcmd_buf[0] = NUL; | |
1945 showcmd_visual = FALSE; | |
1946 } | |
1947 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
1948 // Ignore keys that are scrollbar updates and mouse clicks |
7 | 1949 if (IS_SPECIAL(c)) |
1950 for (i = 0; ignore[i] != 0; ++i) | |
1951 if (ignore[i] == c) | |
1952 return FALSE; | |
1953 | |
1954 p = transchar(c); | |
5535 | 1955 if (*p == ' ') |
1956 STRCPY(p, "<20>"); | |
7 | 1957 old_len = (int)STRLEN(showcmd_buf); |
1958 extra_len = (int)STRLEN(p); | |
1959 overflow = old_len + extra_len - SHOWCMD_COLS; | |
1960 if (overflow > 0) | |
1362 | 1961 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
1962 old_len - overflow + 1); | |
7 | 1963 STRCAT(showcmd_buf, p); |
1964 | |
1965 if (char_avail()) | |
1966 return FALSE; | |
1967 | |
1968 display_showcmd(); | |
1969 | |
1970 return TRUE; | |
1971 } | |
1972 | |
1973 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1974 add_to_showcmd_c(int c) |
7 | 1975 { |
1976 if (!add_to_showcmd(c)) | |
1977 setcursor(); | |
1978 } | |
1979 | |
1980 /* | |
1981 * Delete 'len' characters from the end of the shown command. | |
1982 */ | |
1983 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1984 del_from_showcmd(int len) |
7 | 1985 { |
1986 int old_len; | |
1987 | |
1988 if (!p_sc) | |
1989 return; | |
1990 | |
1991 old_len = (int)STRLEN(showcmd_buf); | |
1992 if (len > old_len) | |
1993 len = old_len; | |
1994 showcmd_buf[old_len - len] = NUL; | |
1995 | |
1996 if (!char_avail()) | |
1997 display_showcmd(); | |
1998 } | |
1999 | |
2000 /* | |
2001 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
2002 * something and there is a partial mapping. | |
2003 */ | |
2004 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2005 push_showcmd(void) |
7 | 2006 { |
2007 if (p_sc) | |
2008 STRCPY(old_showcmd_buf, showcmd_buf); | |
2009 } | |
2010 | |
2011 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2012 pop_showcmd(void) |
7 | 2013 { |
2014 if (!p_sc) | |
2015 return; | |
2016 | |
2017 STRCPY(showcmd_buf, old_showcmd_buf); | |
2018 | |
2019 display_showcmd(); | |
2020 } | |
2021 | |
2022 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2023 display_showcmd(void) |
7 | 2024 { |
2025 int len; | |
2026 | |
2027 cursor_off(); | |
2028 | |
2029 len = (int)STRLEN(showcmd_buf); | |
2030 if (len == 0) | |
2031 showcmd_is_clear = TRUE; | |
2032 else | |
2033 { | |
2034 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
2035 showcmd_is_clear = FALSE; | |
2036 } | |
2037 | |
2038 /* | |
1188 | 2039 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
2040 * spaces | |
7 | 2041 */ |
2042 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
2043 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2044 setcursor(); // put cursor back where it belongs |
7 | 2045 } |
2046 #endif | |
2047 | |
2048 /* | |
2049 * When "check" is FALSE, prepare for commands that scroll the window. | |
2050 * When "check" is TRUE, take care of scroll-binding after the window has | |
2051 * scrolled. Called from normal_cmd() and edit(). | |
2052 */ | |
2053 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2054 do_check_scrollbind(int check) |
7 | 2055 { |
2056 static win_T *old_curwin = NULL; | |
2057 static linenr_T old_topline = 0; | |
2058 #ifdef FEAT_DIFF | |
2059 static int old_topfill = 0; | |
2060 #endif | |
2061 static buf_T *old_buf = NULL; | |
2062 static colnr_T old_leftcol = 0; | |
2063 | |
2064 if (check && curwin->w_p_scb) | |
2065 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2066 // If a ":syncbind" command was just used, don't scroll, only reset |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2067 // the values. |
7 | 2068 if (did_syncbind) |
2069 did_syncbind = FALSE; | |
2070 else if (curwin == old_curwin) | |
2071 { | |
2072 /* | |
2073 * Synchronize other windows, as necessary according to | |
2074 * 'scrollbind'. Don't do this after an ":edit" command, except | |
2075 * when 'diff' is set. | |
2076 */ | |
2077 if ((curwin->w_buffer == old_buf | |
2078 #ifdef FEAT_DIFF | |
2079 || curwin->w_p_diff | |
2080 #endif | |
2081 ) | |
2082 && (curwin->w_topline != old_topline | |
2083 #ifdef FEAT_DIFF | |
2084 || curwin->w_topfill != old_topfill | |
2085 #endif | |
2086 || curwin->w_leftcol != old_leftcol)) | |
2087 { | |
2088 check_scrollbind(curwin->w_topline - old_topline, | |
2089 (long)(curwin->w_leftcol - old_leftcol)); | |
2090 } | |
2091 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2092 else if (vim_strchr(p_sbo, 'j')) // jump flag set in 'scrollopt' |
7 | 2093 { |
2094 /* | |
2095 * When switching between windows, make sure that the relative | |
2096 * vertical offset is valid for the new window. The relative | |
2097 * offset is invalid whenever another 'scrollbind' window has | |
2098 * scrolled to a point that would force the current window to | |
2099 * scroll past the beginning or end of its buffer. When the | |
2100 * resync is performed, some of the other 'scrollbind' windows may | |
2101 * need to jump so that the current window's relative position is | |
2102 * visible on-screen. | |
2103 */ | |
2104 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
2105 } | |
2106 curwin->w_scbind_pos = curwin->w_topline; | |
2107 } | |
2108 | |
2109 old_curwin = curwin; | |
2110 old_topline = curwin->w_topline; | |
2111 #ifdef FEAT_DIFF | |
2112 old_topfill = curwin->w_topfill; | |
2113 #endif | |
2114 old_buf = curwin->w_buffer; | |
2115 old_leftcol = curwin->w_leftcol; | |
2116 } | |
2117 | |
2118 /* | |
2119 * Synchronize any windows that have "scrollbind" set, based on the | |
2120 * number of rows by which the current window has changed | |
2121 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
2122 */ | |
2123 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2124 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 2125 { |
2126 int want_ver; | |
2127 int want_hor; | |
2128 win_T *old_curwin = curwin; | |
2129 buf_T *old_curbuf = curbuf; | |
2130 int old_VIsual_select = VIsual_select; | |
2131 int old_VIsual_active = VIsual_active; | |
2132 colnr_T tgt_leftcol = curwin->w_leftcol; | |
2133 long topline; | |
2134 long y; | |
2135 | |
2136 /* | |
2137 * check 'scrollopt' string for vertical and horizontal scroll options | |
2138 */ | |
2139 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
2140 #ifdef FEAT_DIFF | |
2141 want_ver |= old_curwin->w_p_diff; | |
2142 #endif | |
2143 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
2144 | |
2145 /* | |
2146 * loop through the scrollbound windows and scroll accordingly | |
2147 */ | |
2148 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
2149 FOR_ALL_WINDOWS(curwin) |
7 | 2150 { |
2151 curbuf = curwin->w_buffer; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2152 // skip original window and windows with 'noscrollbind' |
7 | 2153 if (curwin != old_curwin && curwin->w_p_scb) |
2154 { | |
2155 /* | |
2156 * do the vertical scroll | |
2157 */ | |
2158 if (want_ver) | |
2159 { | |
2160 #ifdef FEAT_DIFF | |
2161 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
2162 { | |
2163 diff_set_topline(old_curwin, curwin); | |
2164 } | |
2165 else | |
2166 #endif | |
2167 { | |
2168 curwin->w_scbind_pos += topline_diff; | |
2169 topline = curwin->w_scbind_pos; | |
2170 if (topline > curbuf->b_ml.ml_line_count) | |
2171 topline = curbuf->b_ml.ml_line_count; | |
2172 if (topline < 1) | |
2173 topline = 1; | |
2174 | |
2175 y = topline - curwin->w_topline; | |
2176 if (y > 0) | |
2177 scrollup(y, FALSE); | |
2178 else | |
2179 scrolldown(-y, FALSE); | |
2180 } | |
2181 | |
2182 redraw_later(VALID); | |
2183 cursor_correct(); | |
2184 curwin->w_redr_status = TRUE; | |
2185 } | |
2186 | |
2187 /* | |
2188 * do the horizontal scroll | |
2189 */ | |
2190 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
2191 { | |
2192 curwin->w_leftcol = tgt_leftcol; | |
2193 leftcol_changed(); | |
2194 } | |
2195 } | |
2196 } | |
2197 | |
2198 /* | |
2199 * reset current-window | |
2200 */ | |
2201 VIsual_select = old_VIsual_select; | |
2202 VIsual_active = old_VIsual_active; | |
2203 curwin = old_curwin; | |
2204 curbuf = old_curbuf; | |
2205 } | |
2206 | |
2207 /* | |
2208 * Command character that's ignored. | |
2209 * 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
|
2210 * xon/xoff. |
7 | 2211 */ |
2212 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2213 nv_ignore(cmdarg_T *cap) |
7 | 2214 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2215 cap->retval |= CA_COMMAND_BUSY; // don't call edit() now |
7 | 2216 } |
2217 | |
2218 /* | |
620 | 2219 * Command character that doesn't do anything, but unlike nv_ignore() does |
2220 * start edit(). Used for "startinsert" executed while starting up. | |
2221 */ | |
2222 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2223 nv_nop(cmdarg_T *cap UNUSED) |
620 | 2224 { |
2225 } | |
2226 | |
2227 /* | |
7 | 2228 * Command character doesn't exist. |
2229 */ | |
2230 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2231 nv_error(cmdarg_T *cap) |
7 | 2232 { |
2233 clearopbeep(cap->oap); | |
2234 } | |
2235 | |
2236 /* | |
2237 * <Help> and <F1> commands. | |
2238 */ | |
2239 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2240 nv_help(cmdarg_T *cap) |
7 | 2241 { |
2242 if (!checkclearopq(cap->oap)) | |
2243 ex_help(NULL); | |
2244 } | |
2245 | |
2246 /* | |
2247 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
2248 */ | |
2249 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2250 nv_addsub(cmdarg_T *cap) |
7 | 2251 { |
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
|
2252 #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
|
2253 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
|
2254 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
|
2255 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
|
2256 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2257 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
|
2258 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2259 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2260 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
|
2261 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
|
2262 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2263 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2264 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2265 nv_operator(cap); |
6868 | 2266 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2267 clearop(cap->oap); |
7 | 2268 } |
2269 | |
2270 /* | |
2271 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
2272 */ | |
2273 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2274 nv_page(cmdarg_T *cap) |
7 | 2275 { |
2276 if (!checkclearop(cap->oap)) | |
819 | 2277 { |
2278 if (mod_mask & MOD_MASK_CTRL) | |
2279 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2280 // <C-PageUp>: tab page back; <C-PageDown>: tab page forward |
819 | 2281 if (cap->arg == BACKWARD) |
2282 goto_tabpage(-(int)cap->count1); | |
2283 else | |
2284 goto_tabpage((int)cap->count0); | |
2285 } | |
2286 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2287 (void)onepage(cap->arg, cap->count1); |
819 | 2288 } |
7 | 2289 } |
2290 | |
2291 /* | |
2292 * Implementation of "gd" and "gD" command. | |
2293 */ | |
2294 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2295 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2296 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2297 int nchar, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2298 int thisblock) // 1 for "1gd" and "1gD" |
7 | 2299 { |
2300 int len; | |
503 | 2301 char_u *ptr; |
2302 | |
2303 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
|
2304 || 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
|
2305 == FAIL) |
503 | 2306 clearopbeep(oap); |
2307 #ifdef FEAT_FOLDING | |
2308 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
2309 foldOpenCursor(); | |
2310 #endif | |
2311 } | |
2312 | |
2313 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2314 * 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
|
2315 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2316 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2317 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2318 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
|
2319 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2320 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2321 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2322 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2323 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2324 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2325 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
|
2326 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2327 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2328 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2329 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2330 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2331 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2332 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
|
2333 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2334 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2335 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2336 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2337 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2338 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2339 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2340 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2341 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2342 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2343 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2344 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2345 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2346 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2347 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2348 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2349 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2350 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2351 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2352 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2353 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2354 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2355 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2356 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2357 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2358 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2359 /* |
523 | 2360 * Search for variable declaration of "ptr[len]". |
2361 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
2362 * current file ("gD"). | |
2363 * When "thisblock" is TRUE check the {} block scope. | |
503 | 2364 * Return FAIL when not found. |
2365 */ | |
2366 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2367 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2368 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2369 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2370 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2371 int thisblock, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2372 int flags_arg) // flags passed to searchit() |
503 | 2373 { |
7 | 2374 char_u *pat; |
2375 pos_T old_pos; | |
503 | 2376 pos_T par_pos; |
2377 pos_T found_pos; | |
7 | 2378 int t; |
2379 int save_p_ws; | |
2380 int save_p_scs; | |
503 | 2381 int retval = OK; |
944 | 2382 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
2383 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2384 int valid; |
503 | 2385 |
2386 if ((pat = alloc(len + 7)) == NULL) | |
2387 return FAIL; | |
268 | 2388 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2389 // Put "\V" before the pattern to avoid that the special meaning of "." |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2390 // and "~" causes trouble. |
268 | 2391 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", |
2392 len, ptr); | |
7 | 2393 old_pos = curwin->w_cursor; |
2394 save_p_ws = p_ws; | |
2395 save_p_scs = p_scs; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2396 p_ws = FALSE; // don't wrap around end of file now |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2397 p_scs = FALSE; // don't switch ignorecase off now |
7 | 2398 |
2399 /* | |
2400 * With "gD" go to line 1. | |
2401 * With "gd" Search back for the start of the current function, then go | |
2402 * back until a blank line. If this fails go to line 1. | |
2403 */ | |
944 | 2404 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 2405 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2406 setpcmark(); // Set in findpar() otherwise |
7 | 2407 curwin->w_cursor.lnum = 1; |
539 | 2408 par_pos = curwin->w_cursor; |
7 | 2409 } |
2410 else | |
2411 { | |
539 | 2412 par_pos = curwin->w_cursor; |
7 | 2413 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
2414 --curwin->w_cursor.lnum; | |
2415 } | |
2416 curwin->w_cursor.col = 0; | |
2417 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2418 // 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
|
2419 CLEAR_POS(&found_pos); |
503 | 2420 for (;;) |
2421 { | |
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
|
2422 t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, FORWARD, |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2423 pat, 1L, searchflags, RE_LAST, NULL); |
503 | 2424 if (curwin->w_cursor.lnum >= old_pos.lnum) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2425 t = FAIL; // match after start is failure too |
523 | 2426 |
718 | 2427 if (thisblock && t != FAIL) |
523 | 2428 { |
2429 pos_T *pos; | |
2430 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2431 // Check that the block the match is in doesn't end before the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2432 // position where we started the search from. |
523 | 2433 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, |
2434 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
2435 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2436 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2437 // There can't be a useful match before the end of this block. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2438 // Skip to the end. |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2439 curwin->w_cursor = *pos; |
523 | 2440 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2441 } |
523 | 2442 } |
2443 | |
503 | 2444 if (t == FAIL) |
2445 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2446 // If we previously found a valid position, use it. |
503 | 2447 if (found_pos.lnum != 0) |
2448 { | |
2449 curwin->w_cursor = found_pos; | |
2450 t = OK; | |
2451 } | |
2452 break; | |
2453 } | |
3562 | 2454 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 2455 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2456 // Ignore this line, continue at start of next line. |
503 | 2457 ++curwin->w_cursor.lnum; |
2458 curwin->w_cursor.col = 0; | |
2459 continue; | |
2460 } | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2461 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
|
2462 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2463 // If the current position is not a valid identifier and a previous |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2464 // match is present, favor that one instead. |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2465 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2466 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2467 curwin->w_cursor = found_pos; |
503 | 2468 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2469 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2470 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2471 // Global search: use first valid match found |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2472 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2473 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2474 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 2475 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2476 // If we previously found a valid position, use it. |
503 | 2477 if (found_pos.lnum != 0) |
2478 curwin->w_cursor = found_pos; | |
2479 break; | |
2480 } | |
2481 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2482 // For finding a local variable and the match is before the "{" or |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2483 // inside a comment, continue searching. For K&R style function |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2484 // declarations this skips the function header without types. |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2485 if (!valid) |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2486 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2487 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
2488 found_pos = curwin->w_cursor; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2489 // Remove SEARCH_START from flags to avoid getting stuck at one |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2490 // position. |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
2491 searchflags &= ~SEARCH_START; |
503 | 2492 } |
2493 | |
2494 if (t == FAIL) | |
2495 { | |
2496 retval = FAIL; | |
7 | 2497 curwin->w_cursor = old_pos; |
2498 } | |
2499 else | |
2500 { | |
2501 curwin->w_set_curswant = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2502 // "n" searches forward now |
7 | 2503 reset_search_dir(); |
2504 } | |
2505 | |
2506 vim_free(pat); | |
2507 p_ws = save_p_ws; | |
2508 p_scs = save_p_scs; | |
503 | 2509 |
2510 return retval; | |
7 | 2511 } |
2512 | |
2513 /* | |
2514 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
2515 * lines rather than lines in the file. | |
2516 * 'dist' must be positive. | |
2517 * | |
2518 * Return OK if able to move cursor, FAIL otherwise. | |
2519 */ | |
2520 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2521 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 2522 { |
2523 int linelen = linetabsize(ml_get_curline()); | |
2524 int retval = OK; | |
2525 int atend = FALSE; | |
2526 int n; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2527 int col_off1; // margin offset for first screen line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2528 int col_off2; // margin offset for wrapped screen line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2529 int width1; // text width for first screen line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2530 int width2; // test width for wrapped screen line |
7 | 2531 |
2532 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
2533 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 2534 |
2535 col_off1 = curwin_col_off(); | |
2536 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
|
2537 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
|
2538 width2 = curwin->w_width - col_off2; |
6559 | 2539 if (width2 == 0) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2540 width2 = 1; // avoid divide by zero |
7 | 2541 |
2542 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
2543 { |
7 | 2544 /* |
2545 * Instead of sticking at the last character of the buffer line we | |
2546 * try to stick in the last column of the screen. | |
2547 */ | |
2548 if (curwin->w_curswant == MAXCOL) | |
2549 { | |
2550 atend = TRUE; | |
2551 validate_virtcol(); | |
2552 if (width1 <= 0) | |
2553 curwin->w_curswant = 0; | |
2554 else | |
2555 { | |
2556 curwin->w_curswant = width1 - 1; | |
2557 if (curwin->w_virtcol > curwin->w_curswant) | |
2558 curwin->w_curswant += ((curwin->w_virtcol | |
2559 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
2560 } | |
2561 } | |
2562 else | |
2563 { | |
2564 if (linelen > width1) | |
2565 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
2566 else | |
2567 n = width1; | |
18291
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2568 if (curwin->w_curswant >= (colnr_T)n) |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2569 curwin->w_curswant = n - 1; |
7 | 2570 } |
2571 | |
2572 while (dist--) | |
2573 { | |
2574 if (dir == BACKWARD) | |
2575 { | |
24341
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2576 if ((long)curwin->w_curswant >= width1 |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2577 #ifdef FEAT_FOLDING |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2578 && !hasFolding(curwin->w_cursor.lnum, NULL, NULL) |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2579 #endif |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2580 ) |
18291
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2581 // Move back within the line. This can give a negative value |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2582 // for w_curswant if width1 < width2 (with cpoptions+=n), |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2583 // which will get clipped to column 0. |
7 | 2584 curwin->w_curswant -= width2; |
2585 else | |
2586 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2587 // to previous line |
23687
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2588 #ifdef FEAT_FOLDING |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2589 // Move to the start of a closed fold. Don't do that when |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2590 // 'foldopen' contains "all": it will open in a moment. |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2591 if (!(fdo_flags & FDO_ALL)) |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2592 (void)hasFolding(curwin->w_cursor.lnum, |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2593 &curwin->w_cursor.lnum, NULL); |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2594 #endif |
7 | 2595 if (curwin->w_cursor.lnum == 1) |
2596 { | |
2597 retval = FAIL; | |
2598 break; | |
2599 } | |
2600 --curwin->w_cursor.lnum; | |
23687
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
2601 |
7 | 2602 linelen = linetabsize(ml_get_curline()); |
2603 if (linelen > width1) | |
2604 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
2605 + 1) * width2; | |
2606 } | |
2607 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2608 else // dir == FORWARD |
7 | 2609 { |
2610 if (linelen > width1) | |
2611 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
2612 else | |
2613 n = width1; | |
24341
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2614 if (curwin->w_curswant + width2 < (colnr_T)n |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2615 #ifdef FEAT_FOLDING |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2616 && !hasFolding(curwin->w_cursor.lnum, NULL, NULL) |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2617 #endif |
0e1b8b98f9f4
patch 8.2.2711: "gj" in a closed fold does not move out of the fold
Bram Moolenaar <Bram@vim.org>
parents:
24012
diff
changeset
|
2618 ) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2619 // move forward within line |
7 | 2620 curwin->w_curswant += width2; |
2621 else | |
2622 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2623 // to next line |
7 | 2624 #ifdef FEAT_FOLDING |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2625 // Move to the end of a closed fold. |
7 | 2626 (void)hasFolding(curwin->w_cursor.lnum, NULL, |
2627 &curwin->w_cursor.lnum); | |
2628 #endif | |
2629 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
2630 { | |
2631 retval = FAIL; | |
2632 break; | |
2633 } | |
2634 curwin->w_cursor.lnum++; | |
2635 curwin->w_curswant %= width2; | |
18291
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2636 // Check if the cursor has moved below the number display |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2637 // when width1 < width2 (with cpoptions+=n). Subtract width2 |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2638 // to get a negative value for w_curswant, which will get |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2639 // clipped to column 0. |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2640 if (curwin->w_curswant >= width1) |
11f68eb58fda
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2641 curwin->w_curswant -= width2; |
2911 | 2642 linelen = linetabsize(ml_get_curline()); |
7 | 2643 } |
2644 } | |
2645 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
2646 } |
7 | 2647 |
5600 | 2648 if (virtual_active() && atend) |
2649 coladvance(MAXCOL); | |
2650 else | |
2651 coladvance(curwin->w_curswant); | |
7 | 2652 |
2653 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
2654 { | |
6178 | 2655 colnr_T virtcol; |
2656 | |
7 | 2657 /* |
2658 * Check for landing on a character that got split at the end of the | |
2659 * last line. We want to advance a screenline, not end up in the same | |
2660 * screenline or move two screenlines. | |
2661 */ | |
2662 validate_virtcol(); | |
6178 | 2663 virtcol = curwin->w_virtcol; |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2664 #if defined(FEAT_LINEBREAK) |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18485
diff
changeset
|
2665 if (virtcol > (colnr_T)width1 && *get_showbreak_value(curwin) != NUL) |
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18485
diff
changeset
|
2666 virtcol -= vim_strsize(get_showbreak_value(curwin)); |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2667 #endif |
6178 | 2668 |
2669 if (virtcol > curwin->w_curswant | |
7 | 2670 && (curwin->w_curswant < (colnr_T)width1 |
2671 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
2672 : ((curwin->w_curswant - width1) % width2 | |
2673 > (colnr_T)width2 / 2))) | |
2674 --curwin->w_cursor.col; | |
2675 } | |
2676 | |
2677 if (atend) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2678 curwin->w_curswant = MAXCOL; // stick in the last column |
7 | 2679 |
2680 return retval; | |
2681 } | |
2682 | |
2683 /* | |
2684 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
2685 * cap->arg must be TRUE for CTRL-E. | |
2686 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18128
diff
changeset
|
2687 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2688 nv_scroll_line(cmdarg_T *cap) |
7 | 2689 { |
2690 if (!checkclearop(cap->oap)) | |
2691 scroll_redraw(cap->arg, cap->count1); | |
2692 } | |
2693 | |
2694 /* | |
2695 * Scroll "count" lines up or down, and redraw. | |
2696 */ | |
2697 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2698 scroll_redraw(int up, long count) |
7 | 2699 { |
2700 linenr_T prev_topline = curwin->w_topline; | |
2701 #ifdef FEAT_DIFF | |
2702 int prev_topfill = curwin->w_topfill; | |
2703 #endif | |
2704 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
2705 | |
2706 if (up) | |
2707 scrollup(count, TRUE); | |
2708 else | |
2709 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
|
2710 if (get_scrolloff_value()) |
7 | 2711 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2712 // Adjust the cursor position for 'scrolloff'. Mark w_topline as |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2713 // valid, otherwise the screen jumps back at the end of the file. |
7 | 2714 cursor_correct(); |
2715 check_cursor_moved(curwin); | |
2716 curwin->w_valid |= VALID_TOPLINE; | |
2717 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2718 // If moved back to where we were, at least move the cursor, otherwise |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2719 // we get stuck at one position. Don't move the cursor up if the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2720 // first line of the buffer is already on the screen |
7 | 2721 while (curwin->w_topline == prev_topline |
2722 #ifdef FEAT_DIFF | |
2723 && curwin->w_topfill == prev_topfill | |
2724 #endif | |
2725 ) | |
2726 { | |
2727 if (up) | |
2728 { | |
2729 if (curwin->w_cursor.lnum > prev_lnum | |
2730 || cursor_down(1L, FALSE) == FAIL) | |
2731 break; | |
2732 } | |
2733 else | |
2734 { | |
2735 if (curwin->w_cursor.lnum < prev_lnum | |
2736 || prev_topline == 1L | |
2737 || cursor_up(1L, FALSE) == FAIL) | |
2738 break; | |
2739 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2740 // Mark w_topline as valid, otherwise the screen jumps back at the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2741 // end of the file. |
7 | 2742 check_cursor_moved(curwin); |
2743 curwin->w_valid |= VALID_TOPLINE; | |
2744 } | |
2745 } | |
2746 if (curwin->w_cursor.lnum != prev_lnum) | |
2747 coladvance(curwin->w_curswant); | |
2748 redraw_later(VALID); | |
2749 } | |
2750 | |
2751 /* | |
2752 * Commands that start with "z". | |
2753 */ | |
2754 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2755 nv_zet(cmdarg_T *cap) |
7 | 2756 { |
2757 long n; | |
2758 colnr_T col; | |
2759 int nchar = cap->nchar; | |
2760 #ifdef FEAT_FOLDING | |
2761 long old_fdl = curwin->w_p_fdl; | |
2762 int old_fen = curwin->w_p_fen; | |
2763 #endif | |
737 | 2764 #ifdef FEAT_SPELL |
710 | 2765 int undo = FALSE; |
2766 #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
|
2767 long siso = get_sidescrolloff_value(); |
7 | 2768 |
2769 if (VIM_ISDIGIT(nchar)) | |
2770 { | |
2771 /* | |
2772 * "z123{nchar}": edit the count before obtaining {nchar} | |
2773 */ | |
2774 if (checkclearop(cap->oap)) | |
2775 return; | |
2776 n = nchar - '0'; | |
2777 for (;;) | |
2778 { | |
2779 #ifdef USE_ON_FLY_SCROLL | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2780 dont_scroll = TRUE; // disallow scrolling here |
7 | 2781 #endif |
2782 ++no_mapping; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2783 ++allow_keys; // no mapping for nchar, but allow key codes |
1389 | 2784 nchar = plain_vgetc(); |
7 | 2785 LANGMAP_ADJUST(nchar, TRUE); |
2786 --no_mapping; | |
2787 --allow_keys; | |
2788 #ifdef FEAT_CMDL_INFO | |
2789 (void)add_to_showcmd(nchar); | |
2790 #endif | |
2791 if (nchar == K_DEL || nchar == K_KDEL) | |
2792 n /= 10; | |
2793 else if (VIM_ISDIGIT(nchar)) | |
2794 n = n * 10 + (nchar - '0'); | |
2795 else if (nchar == CAR) | |
2796 { | |
2797 #ifdef FEAT_GUI | |
2798 need_mouse_correct = TRUE; | |
2799 #endif | |
2800 win_setheight((int)n); | |
2801 break; | |
2802 } | |
2803 else if (nchar == 'l' | |
2804 || nchar == 'h' | |
2805 || nchar == K_LEFT | |
229 | 2806 || nchar == K_RIGHT) |
7 | 2807 { |
2808 cap->count1 = n ? n * cap->count1 : cap->count1; | |
2809 goto dozet; | |
2810 } | |
2811 else | |
2812 { | |
2813 clearopbeep(cap->oap); | |
2814 break; | |
2815 } | |
2816 } | |
2817 cap->oap->op_type = OP_NOP; | |
2818 return; | |
2819 } | |
2820 | |
2821 dozet: | |
2822 if ( | |
2823 #ifdef FEAT_FOLDING | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2824 // "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2825 // and "zC" only in Visual mode. "zj" and "zk" are motion |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2826 // commands. |
7 | 2827 cap->nchar != 'f' && cap->nchar != 'F' |
2828 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
2829 && cap->nchar != 'j' && cap->nchar != 'k' | |
2830 && | |
2831 #endif | |
2832 checkclearop(cap->oap)) | |
2833 return; | |
2834 | |
2835 /* | |
2836 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
2837 * If line number given, set cursor. | |
2838 */ | |
2839 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
2840 && cap->count0 | |
2841 && cap->count0 != curwin->w_cursor.lnum) | |
2842 { | |
2843 setpcmark(); | |
2844 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
2845 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2846 else | |
2847 curwin->w_cursor.lnum = cap->count0; | |
22 | 2848 check_cursor_col(); |
7 | 2849 } |
2850 | |
2851 switch (nchar) | |
2852 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2853 // "z+", "z<CR>" and "zt": put cursor at top of screen |
7 | 2854 case '+': |
2855 if (cap->count0 == 0) | |
2856 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2857 // No count given: put cursor at the line below screen |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2858 validate_botline(); // make sure w_botline is valid |
7 | 2859 if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
2860 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2861 else | |
2862 curwin->w_cursor.lnum = curwin->w_botline; | |
2863 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2864 // FALLTHROUGH |
7 | 2865 case NL: |
2866 case CAR: | |
2867 case K_KENTER: | |
2868 beginline(BL_WHITE | BL_FIX); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2869 // FALLTHROUGH |
7 | 2870 |
2871 case 't': scroll_cursor_top(0, TRUE); | |
2872 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
2873 set_fraction(curwin); |
7 | 2874 break; |
2875 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2876 // "z." and "zz": put cursor in middle of screen |
7 | 2877 case '.': beginline(BL_WHITE | BL_FIX); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2878 // FALLTHROUGH |
7 | 2879 |
2880 case 'z': scroll_cursor_halfway(TRUE); | |
2881 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
2882 set_fraction(curwin); |
7 | 2883 break; |
2884 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2885 // "z^", "z-" and "zb": put cursor at bottom of screen |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2886 case '^': // Strange Vi behavior: <count>z^ finds line at top of window |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2887 // when <count> is at bottom of window, and puts that one at |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2888 // bottom of window. |
7 | 2889 if (cap->count0 != 0) |
2890 { | |
2891 scroll_cursor_bot(0, TRUE); | |
2892 curwin->w_cursor.lnum = curwin->w_topline; | |
2893 } | |
2894 else if (curwin->w_topline == 1) | |
2895 curwin->w_cursor.lnum = 1; | |
2896 else | |
2897 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2898 // FALLTHROUGH |
7 | 2899 case '-': |
2900 beginline(BL_WHITE | BL_FIX); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2901 // FALLTHROUGH |
7 | 2902 |
2903 case 'b': scroll_cursor_bot(0, TRUE); | |
2904 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
2905 set_fraction(curwin); |
7 | 2906 break; |
2907 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2908 // "zH" - scroll screen right half-page |
7 | 2909 case 'H': |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2910 cap->count1 *= curwin->w_width / 2; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2911 // FALLTHROUGH |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2912 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2913 // "zh" - scroll screen to the right |
7 | 2914 case 'h': |
2915 case K_LEFT: | |
2916 if (!curwin->w_p_wrap) | |
2917 { | |
2918 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
2919 curwin->w_leftcol = 0; | |
2920 else | |
2921 curwin->w_leftcol -= (colnr_T)cap->count1; | |
2922 leftcol_changed(); | |
2923 } | |
2924 break; | |
2925 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2926 // "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
|
2927 case 'L': cap->count1 *= curwin->w_width / 2; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2928 // FALLTHROUGH |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2929 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2930 // "zl" - scroll screen to the left |
7 | 2931 case 'l': |
2932 case K_RIGHT: | |
2933 if (!curwin->w_p_wrap) | |
2934 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2935 // scroll the window left |
7 | 2936 curwin->w_leftcol += (colnr_T)cap->count1; |
2937 leftcol_changed(); | |
2938 } | |
2939 break; | |
2940 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2941 // "zs" - scroll screen, cursor at the start |
7 | 2942 case 's': if (!curwin->w_p_wrap) |
2943 { | |
2944 #ifdef FEAT_FOLDING | |
2945 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2946 col = 0; // like the cursor is in col 0 |
7 | 2947 else |
2948 #endif | |
2949 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
|
2950 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
|
2951 col -= siso; |
7 | 2952 else |
2953 col = 0; | |
2954 if (curwin->w_leftcol != col) | |
2955 { | |
2956 curwin->w_leftcol = col; | |
2957 redraw_later(NOT_VALID); | |
2958 } | |
2959 } | |
2960 break; | |
2961 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2962 // "ze" - scroll screen, cursor at the end |
7 | 2963 case 'e': if (!curwin->w_p_wrap) |
2964 { | |
2965 #ifdef FEAT_FOLDING | |
2966 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2967 col = 0; // like the cursor is in col 0 |
7 | 2968 else |
2969 #endif | |
2970 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
|
2971 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
|
2972 if ((long)col + siso < n) |
7 | 2973 col = 0; |
2974 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
|
2975 col = col + siso - n + 1; |
7 | 2976 if (curwin->w_leftcol != col) |
2977 { | |
2978 curwin->w_leftcol = col; | |
2979 redraw_later(NOT_VALID); | |
2980 } | |
2981 } | |
2982 break; | |
2983 | |
24752
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
2984 // "zp", "zP" in block mode put without addind trailing spaces |
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
2985 case 'P': |
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
2986 case 'p': nv_put(cap); |
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
2987 break; |
24866
f1121eb17e14
patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents:
24800
diff
changeset
|
2988 // "zy" Yank without trailing spaces |
f1121eb17e14
patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents:
24800
diff
changeset
|
2989 case 'y': nv_operator(cap); |
f1121eb17e14
patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents:
24800
diff
changeset
|
2990 break; |
7 | 2991 #ifdef FEAT_FOLDING |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2992 // "zF": create fold command |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
2993 // "zf": create fold operator |
7 | 2994 case 'F': |
2995 case 'f': if (foldManualAllowed(TRUE)) | |
2996 { | |
2997 cap->nchar = 'f'; | |
2998 nv_operator(cap); | |
2999 curwin->w_p_fen = TRUE; | |
3000 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3001 // "zF" is like "zfzf" |
7 | 3002 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) |
3003 { | |
3004 nv_operator(cap); | |
3005 finish_op = TRUE; | |
3006 } | |
3007 } | |
3008 else | |
3009 clearopbeep(cap->oap); | |
3010 break; | |
3011 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3012 // "zd": delete fold at cursor |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3013 // "zD": delete fold at cursor recursively |
7 | 3014 case 'd': |
3015 case 'D': if (foldManualAllowed(FALSE)) | |
3016 { | |
3017 if (VIsual_active) | |
3018 nv_operator(cap); | |
3019 else | |
3020 deleteFold(curwin->w_cursor.lnum, | |
3021 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
3022 } | |
3023 break; | |
3024 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3025 // "zE": erase all folds |
7 | 3026 case 'E': if (foldmethodIsManual(curwin)) |
3027 { | |
3028 clearFolding(curwin); | |
3029 changed_window_setting(); | |
3030 } | |
3031 else if (foldmethodIsMarker(curwin)) | |
3032 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
3033 TRUE, FALSE); | |
3034 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3035 emsg(_("E352: Cannot erase folds with current 'foldmethod'")); |
7 | 3036 break; |
3037 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3038 // "zn": fold none: reset 'foldenable' |
7 | 3039 case 'n': curwin->w_p_fen = FALSE; |
3040 break; | |
3041 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3042 // "zN": fold Normal: set 'foldenable' |
7 | 3043 case 'N': curwin->w_p_fen = TRUE; |
3044 break; | |
3045 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3046 // "zi": invert folding: toggle 'foldenable' |
7 | 3047 case 'i': curwin->w_p_fen = !curwin->w_p_fen; |
3048 break; | |
3049 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3050 // "za": open closed fold or close open fold at cursor |
7 | 3051 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
3052 openFold(curwin->w_cursor.lnum, cap->count1); | |
3053 else | |
3054 { | |
3055 closeFold(curwin->w_cursor.lnum, cap->count1); | |
3056 curwin->w_p_fen = TRUE; | |
3057 } | |
3058 break; | |
3059 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3060 // "zA": open fold at cursor recursively |
7 | 3061 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
3062 openFoldRecurse(curwin->w_cursor.lnum); | |
3063 else | |
3064 { | |
3065 closeFoldRecurse(curwin->w_cursor.lnum); | |
3066 curwin->w_p_fen = TRUE; | |
3067 } | |
3068 break; | |
3069 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3070 // "zo": open fold at cursor or Visual area |
7 | 3071 case 'o': if (VIsual_active) |
3072 nv_operator(cap); | |
3073 else | |
3074 openFold(curwin->w_cursor.lnum, cap->count1); | |
3075 break; | |
3076 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3077 // "zO": open fold recursively |
7 | 3078 case 'O': if (VIsual_active) |
3079 nv_operator(cap); | |
3080 else | |
3081 openFoldRecurse(curwin->w_cursor.lnum); | |
3082 break; | |
3083 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3084 // "zc": close fold at cursor or Visual area |
7 | 3085 case 'c': if (VIsual_active) |
3086 nv_operator(cap); | |
3087 else | |
3088 closeFold(curwin->w_cursor.lnum, cap->count1); | |
3089 curwin->w_p_fen = TRUE; | |
3090 break; | |
3091 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3092 // "zC": close fold recursively |
7 | 3093 case 'C': if (VIsual_active) |
3094 nv_operator(cap); | |
3095 else | |
3096 closeFoldRecurse(curwin->w_cursor.lnum); | |
3097 curwin->w_p_fen = TRUE; | |
3098 break; | |
3099 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3100 // "zv": open folds at the cursor |
7 | 3101 case 'v': foldOpenCursor(); |
3102 break; | |
3103 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3104 // "zx": re-apply 'foldlevel' and open folds at the cursor |
7 | 3105 case 'x': curwin->w_p_fen = TRUE; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3106 curwin->w_foldinvalid = TRUE; // recompute folds |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3107 newFoldLevel(); // update right now |
7 | 3108 foldOpenCursor(); |
3109 break; | |
3110 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3111 // "zX": undo manual opens/closes, re-apply 'foldlevel' |
7 | 3112 case 'X': curwin->w_p_fen = TRUE; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3113 curwin->w_foldinvalid = TRUE; // recompute folds |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3114 old_fdl = -1; // force an update |
7 | 3115 break; |
3116 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3117 // "zm": fold more |
7 | 3118 case 'm': if (curwin->w_p_fdl > 0) |
6725 | 3119 { |
3120 curwin->w_p_fdl -= cap->count1; | |
3121 if (curwin->w_p_fdl < 0) | |
3122 curwin->w_p_fdl = 0; | |
3123 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3124 old_fdl = -1; // force an update |
7 | 3125 curwin->w_p_fen = TRUE; |
3126 break; | |
3127 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3128 // "zM": close all folds |
7 | 3129 case 'M': curwin->w_p_fdl = 0; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3130 old_fdl = -1; // force an update |
7 | 3131 curwin->w_p_fen = TRUE; |
3132 break; | |
3133 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3134 // "zr": reduce folding |
6725 | 3135 case 'r': curwin->w_p_fdl += cap->count1; |
3136 { | |
3137 int d = getDeepestNesting(); | |
3138 | |
3139 if (curwin->w_p_fdl >= d) | |
3140 curwin->w_p_fdl = d; | |
3141 } | |
7 | 3142 break; |
3143 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3144 // "zR": open all folds |
7 | 3145 case 'R': curwin->w_p_fdl = getDeepestNesting(); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3146 old_fdl = -1; // force an update |
7 | 3147 break; |
3148 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3149 case 'j': // "zj" move to next fold downwards |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3150 case 'k': // "zk" move to next fold upwards |
7 | 3151 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, |
3152 cap->count1) == FAIL) | |
3153 clearopbeep(cap->oap); | |
3154 break; | |
3155 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3156 #endif // FEAT_FOLDING |
7 | 3157 |
737 | 3158 #ifdef FEAT_SPELL |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3159 case 'u': // "zug" and "zuw": undo "zg" and "zw" |
710 | 3160 ++no_mapping; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3161 ++allow_keys; // no mapping for nchar, but allow key codes |
1389 | 3162 nchar = plain_vgetc(); |
710 | 3163 LANGMAP_ADJUST(nchar, TRUE); |
3164 --no_mapping; | |
3165 --allow_keys; | |
3166 #ifdef FEAT_CMDL_INFO | |
3167 (void)add_to_showcmd(nchar); | |
3168 #endif | |
3169 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
3170 { | |
3171 clearopbeep(cap->oap); | |
3172 break; | |
3173 } | |
3174 undo = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3175 // FALLTHROUGH |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3176 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3177 case 'g': // "zg": add good word to word list |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3178 case 'w': // "zw": add wrong word to word list |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3179 case 'G': // "zG": add good word to temp word list |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3180 case 'W': // "zW": add wrong word to temp word list |
310 | 3181 { |
3182 char_u *ptr = NULL; | |
3183 int len; | |
3184 | |
3185 if (checkclearop(cap->oap)) | |
3186 break; | |
3187 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
3188 == FAIL) | |
3189 return; | |
501 | 3190 if (ptr == NULL) |
3191 { | |
3192 pos_T pos = curwin->w_cursor; | |
3193 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3194 // Find bad word under the cursor. When 'spell' is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3195 // off this fails and find_ident_under_cursor() is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3196 // used below. |
5374 | 3197 emsg_off++; |
534 | 3198 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 3199 emsg_off--; |
501 | 3200 if (len != 0 && curwin->w_cursor.col <= pos.col) |
3201 ptr = ml_get_pos(&curwin->w_cursor); | |
3202 curwin->w_cursor = pos; | |
3203 } | |
3204 | |
310 | 3205 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
3206 FIND_IDENT)) == 0) | |
3207 return; | |
17682
3dbff5d37520
patch 8.1.1838: there is :spellwrong and :spellgood but not :spellrare
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3208 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
|
3209 ? SPELL_ADD_BAD : SPELL_ADD_GOOD, |
710 | 3210 (nchar == 'G' || nchar == 'W') |
3211 ? 0 : (int)cap->count1, | |
3212 undo); | |
310 | 3213 } |
316 | 3214 break; |
323 | 3215 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3216 case '=': // "z=": suggestions for a badly spelled word |
638 | 3217 if (!checkclearop(cap->oap)) |
485 | 3218 spell_suggest((int)cap->count0); |
323 | 3219 break; |
310 | 3220 #endif |
3221 | |
7 | 3222 default: clearopbeep(cap->oap); |
3223 } | |
3224 | |
3225 #ifdef FEAT_FOLDING | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3226 // Redraw when 'foldenable' changed |
7 | 3227 if (old_fen != curwin->w_p_fen) |
3228 { | |
3229 # ifdef FEAT_DIFF | |
3230 win_T *wp; | |
3231 | |
3232 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
3233 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3234 // Adjust 'foldenable' in diff-synced windows. |
7 | 3235 FOR_ALL_WINDOWS(wp) |
3236 { | |
3237 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
3238 { | |
3239 wp->w_p_fen = curwin->w_p_fen; | |
3240 changed_window_setting_win(wp); | |
3241 } | |
3242 } | |
3243 } | |
3244 # endif | |
3245 changed_window_setting(); | |
3246 } | |
3247 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3248 // Redraw when 'foldlevel' changed. |
7 | 3249 if (old_fdl != curwin->w_p_fdl) |
3250 newFoldLevel(); | |
3251 #endif | |
3252 } | |
3253 | |
3254 #ifdef FEAT_GUI | |
3255 /* | |
3256 * Vertical scrollbar movement. | |
3257 */ | |
3258 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3259 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 3260 { |
3261 if (cap->oap->op_type != OP_NOP) | |
3262 clearopbeep(cap->oap); | |
3263 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3264 // Even if an operator was pending, we still want to scroll |
7 | 3265 gui_do_scroll(); |
3266 } | |
3267 | |
3268 /* | |
3269 * Horizontal scrollbar movement. | |
3270 */ | |
3271 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3272 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 3273 { |
3274 if (cap->oap->op_type != OP_NOP) | |
3275 clearopbeep(cap->oap); | |
3276 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3277 // 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
|
3278 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 3279 } |
3280 #endif | |
3281 | |
690 | 3282 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 3283 /* |
3284 * Click in GUI tab. | |
3285 */ | |
3286 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3287 nv_tabline(cmdarg_T *cap) |
685 | 3288 { |
3289 if (cap->oap->op_type != OP_NOP) | |
3290 clearopbeep(cap->oap); | |
3291 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3292 // Even if an operator was pending, we still want to jump tabs. |
685 | 3293 goto_tabpage(current_tab); |
3294 } | |
686 | 3295 |
3296 /* | |
3297 * Selected item in tab line menu. | |
3298 */ | |
3299 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3300 nv_tabmenu(cmdarg_T *cap) |
686 | 3301 { |
3302 if (cap->oap->op_type != OP_NOP) | |
3303 clearopbeep(cap->oap); | |
3304 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3305 // Even if an operator was pending, we still want to jump tabs. |
690 | 3306 handle_tabmenu(); |
3307 } | |
3308 | |
3309 /* | |
3310 * Handle selecting an item of the GUI tab line menu. | |
3311 * Used in Normal and Insert mode. | |
3312 */ | |
3313 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3314 handle_tabmenu(void) |
690 | 3315 { |
686 | 3316 switch (current_tabmenu) |
3317 { | |
3318 case TABLINE_MENU_CLOSE: | |
3319 if (current_tab == 0) | |
3320 do_cmdline_cmd((char_u *)"tabclose"); | |
3321 else | |
3322 { | |
3323 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
3324 current_tab); | |
3325 do_cmdline_cmd(IObuff); | |
3326 } | |
3327 break; | |
3328 | |
3329 case TABLINE_MENU_NEW: | |
6631 | 3330 if (current_tab == 0) |
3331 do_cmdline_cmd((char_u *)"$tabnew"); | |
3332 else | |
3333 { | |
3334 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
3335 current_tab - 1); | |
3336 do_cmdline_cmd(IObuff); | |
3337 } | |
686 | 3338 break; |
3339 | |
3340 case TABLINE_MENU_OPEN: | |
6631 | 3341 if (current_tab == 0) |
3342 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
3343 else | |
3344 { | |
3345 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
3346 current_tab - 1); | |
3347 do_cmdline_cmd(IObuff); | |
3348 } | |
686 | 3349 break; |
3350 } | |
3351 } | |
685 | 3352 #endif |
3353 | |
7 | 3354 /* |
3355 * "Q" command. | |
3356 */ | |
3357 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3358 nv_exmode(cmdarg_T *cap) |
7 | 3359 { |
3360 /* | |
3361 * Ignore 'Q' in Visual mode, just give a beep. | |
3362 */ | |
3363 if (VIsual_active) | |
6949 | 3364 vim_beep(BO_EX); |
5735 | 3365 else if (!checkclearop(cap->oap)) |
7 | 3366 do_exmode(FALSE); |
3367 } | |
3368 | |
3369 /* | |
3370 * Handle a ":" command. | |
3371 */ | |
3372 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3373 nv_colon(cmdarg_T *cap) |
7 | 3374 { |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3375 int old_p_im; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3376 int cmd_result; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3377 int is_cmdkey = cap->cmdchar == K_COMMAND; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3378 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3379 if (VIsual_active && !is_cmdkey) |
7 | 3380 nv_operator(cap); |
3381 else | |
3382 { | |
3383 if (cap->oap->op_type != OP_NOP) | |
3384 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3385 // Using ":" as a movement is characterwise exclusive. |
7 | 3386 cap->oap->motion_type = MCHAR; |
3387 cap->oap->inclusive = FALSE; | |
3388 } | |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3389 else if (cap->count0 && !is_cmdkey) |
7 | 3390 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3391 // translate "count:" into ":.,.+(count - 1)" |
7 | 3392 stuffcharReadbuff('.'); |
3393 if (cap->count0 > 1) | |
3394 { | |
3395 stuffReadbuff((char_u *)",.+"); | |
3396 stuffnumReadbuff((long)cap->count0 - 1L); | |
3397 } | |
3398 } | |
3399 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3400 // When typing, don't type below an old message |
7 | 3401 if (KeyTyped) |
3402 compute_cmdrow(); | |
3403 | |
3404 old_p_im = p_im; | |
3405 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3406 // get a command line and execute it |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
3407 cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL, |
7 | 3408 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
3409 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3410 // If 'insertmode' changed, enter or exit Insert mode |
7 | 3411 if (p_im != old_p_im) |
3412 { | |
3413 if (p_im) | |
3414 restart_edit = 'i'; | |
3415 else | |
3416 restart_edit = 0; | |
3417 } | |
3418 | |
4256 | 3419 if (cmd_result == FAIL) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3420 // The Ex command failed, do not execute the operator. |
4256 | 3421 clearop(cap->oap); |
3422 else if (cap->oap->op_type != OP_NOP | |
7 | 3423 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
3424 || cap->oap->start.col > | |
4256 | 3425 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
3426 || did_emsg | |
3427 )) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3428 // The start of the operator has become invalid by the Ex command. |
7 | 3429 clearopbeep(cap->oap); |
3430 } | |
3431 } | |
3432 | |
3433 /* | |
3434 * Handle CTRL-G command. | |
3435 */ | |
3436 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3437 nv_ctrlg(cmdarg_T *cap) |
7 | 3438 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3439 if (VIsual_active) // toggle Selection/Visual mode |
7 | 3440 { |
3441 VIsual_select = !VIsual_select; | |
3442 showmode(); | |
3443 } | |
5735 | 3444 else if (!checkclearop(cap->oap)) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3445 // print full name if count given or :cd used |
7 | 3446 fileinfo((int)cap->count0, FALSE, TRUE); |
3447 } | |
3448 | |
3449 /* | |
3450 * Handle CTRL-H <Backspace> command. | |
3451 */ | |
3452 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3453 nv_ctrlh(cmdarg_T *cap) |
7 | 3454 { |
3455 if (VIsual_active && VIsual_select) | |
3456 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3457 cap->cmdchar = 'x'; // BS key behaves like 'x' in Select mode |
7 | 3458 v_visop(cap); |
3459 } | |
3460 else | |
3461 nv_left(cap); | |
3462 } | |
3463 | |
3464 /* | |
3465 * CTRL-L: clear screen and redraw. | |
3466 */ | |
3467 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3468 nv_clear(cmdarg_T *cap) |
7 | 3469 { |
3470 if (!checkclearop(cap->oap)) | |
3471 { | |
3472 #ifdef FEAT_SYN_HL | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3473 // 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
|
3474 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
|
3475 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3476 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3477 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3478 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3479 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
|
3480 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
|
3481 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3482 # endif |
7 | 3483 #endif |
3484 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
|
3485 #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
|
3486 # 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
|
3487 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
|
3488 # 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
|
3489 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
|
3490 #endif |
7 | 3491 } |
3492 } | |
3493 | |
3494 /* | |
3495 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
3496 * Otherwise: Go to older pcmark. | |
3497 */ | |
3498 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3499 nv_ctrlo(cmdarg_T *cap) |
7 | 3500 { |
3501 if (VIsual_active && VIsual_select) | |
3502 { | |
3503 VIsual_select = FALSE; | |
3504 showmode(); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3505 restart_VIsual_select = 2; // restart Select mode later |
7 | 3506 } |
3507 else | |
3508 { | |
3509 cap->count1 = -cap->count1; | |
3510 nv_pcmark(cap); | |
3511 } | |
3512 } | |
3513 | |
3514 /* | |
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
|
3515 * 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
|
3516 * not named. |
7 | 3517 */ |
3518 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3519 nv_hat(cmdarg_T *cap) |
7 | 3520 { |
3521 if (!checkclearopq(cap->oap)) | |
3522 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
3523 GETF_SETMARK|GETF_ALT, FALSE); | |
3524 } | |
3525 | |
3526 /* | |
3527 * "Z" commands. | |
3528 */ | |
3529 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3530 nv_Zet(cmdarg_T *cap) |
7 | 3531 { |
3532 if (!checkclearopq(cap->oap)) | |
3533 { | |
3534 switch (cap->nchar) | |
3535 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3536 // "ZZ": equivalent to ":x". |
7 | 3537 case 'Z': do_cmdline_cmd((char_u *)"x"); |
3538 break; | |
3539 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3540 // "ZQ": equivalent to ":q!" (Elvis compatible). |
7 | 3541 case 'Q': do_cmdline_cmd((char_u *)"q!"); |
3542 break; | |
3543 | |
3544 default: clearopbeep(cap->oap); | |
3545 } | |
3546 } | |
3547 } | |
3548 | |
3549 /* | |
3550 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
3551 */ | |
3552 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3553 do_nv_ident(int c1, int c2) |
7 | 3554 { |
3555 oparg_T oa; | |
3556 cmdarg_T ca; | |
3557 | |
3558 clear_oparg(&oa); | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19681
diff
changeset
|
3559 CLEAR_FIELD(ca); |
7 | 3560 ca.oap = &oa; |
3561 ca.cmdchar = c1; | |
3562 ca.nchar = c2; | |
3563 nv_ident(&ca); | |
3564 } | |
3565 | |
3566 /* | |
3567 * Handle the commands that use the word under the cursor. | |
3568 * [g] CTRL-] :ta to current identifier | |
3569 * [g] 'K' run program for current identifier | |
3570 * [g] '*' / to current identifier or string | |
3571 * [g] '#' ? to current identifier or string | |
3572 * g ']' :tselect for current identifier | |
3573 */ | |
3574 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3575 nv_ident(cmdarg_T *cap) |
7 | 3576 { |
3577 char_u *ptr = NULL; | |
3578 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3579 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
3580 char_u *newbuf; |
7 | 3581 char_u *p; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3582 char_u *kp; // value of 'keywordprg' |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3583 int kp_help; // 'keywordprg' is ":he" |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3584 int kp_ex; // 'keywordprg' starts with ":" |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3585 int n = 0; // init for GCC |
7 | 3586 int cmdchar; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3587 int g_cmd; // "g" command |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3588 int tag_cmd = FALSE; |
7 | 3589 char_u *aux_ptr; |
3590 int isman; | |
3591 int isman_s; | |
3592 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3593 if (cap->cmdchar == 'g') // "g*", "g#", "g]" and "gCTRL-]" |
7 | 3594 { |
3595 cmdchar = cap->nchar; | |
3596 g_cmd = TRUE; | |
3597 } | |
3598 else | |
3599 { | |
3600 cmdchar = cap->cmdchar; | |
3601 g_cmd = FALSE; | |
3602 } | |
3603 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3604 if (cmdchar == POUND) // the pound sign, '#' for English keyboards |
7 | 3605 cmdchar = '#'; |
3606 | |
3607 /* | |
3608 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
3609 */ | |
3610 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
3611 { | |
3612 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
3613 return; | |
3614 if (checkclearopq(cap->oap)) | |
3615 return; | |
3616 } | |
3617 | |
3618 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
3619 (cmdchar == '*' || cmdchar == '#') | |
3620 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
3621 { | |
3622 clearop(cap->oap); | |
3623 return; | |
3624 } | |
3625 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3626 // Allocate buffer to put the command in. Inserting backslashes can |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3627 // double the length of the word. p_kp / curbuf->b_p_kp could be added |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3628 // and some numbers. |
7 | 3629 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); |
3630 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
3631 || 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
|
3632 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
|
3633 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3634 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
|
3635 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
|
3636 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3637 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3638 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
|
3639 buf = alloc(buflen); |
7 | 3640 if (buf == NULL) |
3641 return; | |
3642 buf[0] = NUL; | |
3643 | |
3644 switch (cmdchar) | |
3645 { | |
3646 case '*': | |
3647 case '#': | |
3648 /* | |
3649 * Put cursor at start of word, makes search skip the word | |
3650 * under the cursor. | |
3651 * Call setpcmark() first, so "*``" puts the cursor back where | |
3652 * it was. | |
3653 */ | |
3654 setpcmark(); | |
3655 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
3656 | |
3657 if (!g_cmd && vim_iswordp(ptr)) | |
3658 STRCPY(buf, "\\<"); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3659 no_smartcase = TRUE; // don't use 'smartcase' now |
7 | 3660 break; |
3661 | |
3662 case 'K': | |
3663 if (kp_help) | |
3664 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3665 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3666 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3667 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3668 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
|
3669 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3670 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3671 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3672 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
3673 } |
7 | 3674 else |
3675 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3676 // An external command will probably use an argument starting |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3677 // with "-" as an option. To avoid trouble we skip the "-". |
1728 | 3678 while (*ptr == '-' && n > 0) |
3679 { | |
1712 | 3680 ++ptr; |
1728 | 3681 --n; |
3682 } | |
3683 if (n == 0) | |
3684 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3685 emsg(_(e_noident)); // found dashes only |
1728 | 3686 vim_free(buf); |
3687 return; | |
3688 } | |
1712 | 3689 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3690 // When a count is given, turn it into a range. Is this |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3691 // really what we want? |
7 | 3692 isman = (STRCMP(kp, "man") == 0); |
3693 isman_s = (STRCMP(kp, "man -s") == 0); | |
3694 if (cap->count0 != 0 && !(isman || isman_s)) | |
3695 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
3696 | |
3697 STRCAT(buf, "! "); | |
3698 if (cap->count0 == 0 && isman_s) | |
3699 STRCAT(buf, "man"); | |
3700 else | |
3701 STRCAT(buf, kp); | |
3702 STRCAT(buf, " "); | |
3703 if (cap->count0 != 0 && (isman || isman_s)) | |
3704 { | |
3705 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
3706 STRCAT(buf, " "); | |
3707 } | |
3708 } | |
3709 break; | |
3710 | |
3711 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3712 tag_cmd = TRUE; |
7 | 3713 #ifdef FEAT_CSCOPE |
3714 if (p_cst) | |
3715 STRCPY(buf, "cstag "); | |
3716 else | |
3717 #endif | |
3718 STRCPY(buf, "ts "); | |
3719 break; | |
3720 | |
3721 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
3722 tag_cmd = TRUE; |
7 | 3723 if (curbuf->b_help) |
3724 STRCPY(buf, "he! "); | |
3725 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3726 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3727 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3728 STRCPY(buf, "tj "); |
21941
f65e76638eb5
patch 8.2.1520: Vim9: CTRL-] used in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
21703
diff
changeset
|
3729 else if (cap->count0 == 0) |
f65e76638eb5
patch 8.2.1520: Vim9: CTRL-] used in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
21703
diff
changeset
|
3730 STRCPY(buf, "ta "); |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3731 else |
21941
f65e76638eb5
patch 8.2.1520: Vim9: CTRL-] used in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
21703
diff
changeset
|
3732 sprintf((char *)buf, ":%ldta ", cap->count0); |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3733 } |
7 | 3734 } |
3735 | |
3736 /* | |
3737 * Now grab the chars in the identifier | |
3738 */ | |
1712 | 3739 if (cmdchar == 'K' && !kp_help) |
3740 { | |
1728 | 3741 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3742 if (kp_ex) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3743 // Escape the argument properly for an Ex command |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3744 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3745 else |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3746 // Escape the argument properly for a shell command |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
3747 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 3748 vim_free(ptr); |
1712 | 3749 if (p == NULL) |
3750 { | |
3751 vim_free(buf); | |
3752 return; | |
3753 } | |
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
|
3754 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
|
3755 if (newbuf == NULL) |
1712 | 3756 { |
3757 vim_free(buf); | |
3758 vim_free(p); | |
3759 return; | |
3760 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
3761 buf = newbuf; |
1712 | 3762 STRCAT(buf, p); |
3763 vim_free(p); | |
3764 } | |
7 | 3765 else |
1712 | 3766 { |
3767 if (cmdchar == '*') | |
23272
a84e7abb0c92
patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
3768 aux_ptr = (char_u *)(magic_isset() ? "/.*~[^$\\" : "/^$\\"); |
1712 | 3769 else if (cmdchar == '#') |
23272
a84e7abb0c92
patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
3770 aux_ptr = (char_u *)(magic_isset() ? "/?.*~[^$\\" : "/?^$\\"); |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
3771 else if (tag_cmd) |
2603 | 3772 { |
3773 if (curbuf->b_help) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3774 // ":help" handles unescaped argument |
2603 | 3775 aux_ptr = (char_u *)""; |
3776 else | |
3777 aux_ptr = (char_u *)"\\|\"\n["; | |
3778 } | |
1712 | 3779 else |
3780 aux_ptr = (char_u *)"\\|\"\n*?["; | |
3781 | |
3782 p = buf + STRLEN(buf); | |
3783 while (n-- > 0) | |
3784 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3785 // put a backslash before \ and some others |
1712 | 3786 if (vim_strchr(aux_ptr, *ptr) != NULL) |
3787 *p++ = '\\'; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3788 // When current byte is a part of multibyte character, copy all |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3789 // bytes of that character. |
1712 | 3790 if (has_mbyte) |
3791 { | |
3792 int i; | |
3793 int len = (*mb_ptr2len)(ptr) - 1; | |
3794 | |
3795 for (i = 0; i < len && n >= 1; ++i, --n) | |
3796 *p++ = *ptr++; | |
3797 } | |
3798 *p++ = *ptr++; | |
3799 } | |
3800 *p = NUL; | |
3801 } | |
7 | 3802 |
3803 /* | |
3804 * Execute the command. | |
3805 */ | |
3806 if (cmdchar == '*' || cmdchar == '#') | |
3807 { | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3808 if (!g_cmd && (has_mbyte |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3809 ? 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
|
3810 : vim_iswordc(ptr[-1]))) |
7 | 3811 STRCAT(buf, "\\>"); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
3812 |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
3813 // put pattern in search history |
2024 | 3814 init_history(); |
7 | 3815 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
|
3816 |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
3817 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0, NULL); |
7 | 3818 } |
3819 else | |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3820 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3821 g_tag_at_cursor = TRUE; |
7 | 3822 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
|
3823 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
|
3824 } |
7 | 3825 |
3826 vim_free(buf); | |
3827 } | |
3828 | |
3829 /* | |
3830 * Get visually selected text, within one line only. | |
3831 * Returns FAIL if more than one line selected. | |
3832 */ | |
344 | 3833 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3834 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3835 cmdarg_T *cap, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3836 char_u **pp, // return: start of selected text |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3837 int *lenp) // return: length of selected text |
7 | 3838 { |
3839 if (VIsual_mode != 'V') | |
3840 unadjust_for_sel(); | |
3841 if (VIsual.lnum != curwin->w_cursor.lnum) | |
3842 { | |
344 | 3843 if (cap != NULL) |
3844 clearopbeep(cap->oap); | |
7 | 3845 return FAIL; |
3846 } | |
3847 if (VIsual_mode == 'V') | |
3848 { | |
3849 *pp = ml_get_curline(); | |
3850 *lenp = (int)STRLEN(*pp); | |
3851 } | |
3852 else | |
3853 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3854 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3855 { |
3856 *pp = ml_get_pos(&curwin->w_cursor); | |
3857 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
3858 } | |
3859 else | |
3860 { | |
3861 *pp = ml_get_pos(&VIsual); | |
3862 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
3863 } | |
3864 if (has_mbyte) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3865 // Correct the length to include the whole last character. |
474 | 3866 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 3867 } |
3868 reset_VIsual_and_resel(); | |
3869 return OK; | |
3870 } | |
3871 | |
3872 /* | |
3873 * CTRL-T: backwards in tag stack | |
3874 */ | |
3875 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3876 nv_tagpop(cmdarg_T *cap) |
7 | 3877 { |
3878 if (!checkclearopq(cap->oap)) | |
3879 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
3880 } | |
3881 | |
3882 /* | |
3883 * Handle scrolling command 'H', 'L' and 'M'. | |
3884 */ | |
3885 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3886 nv_scroll(cmdarg_T *cap) |
7 | 3887 { |
3888 int used = 0; | |
3889 long n; | |
3890 #ifdef FEAT_FOLDING | |
3891 linenr_T lnum; | |
3892 #endif | |
3893 int half; | |
3894 | |
3895 cap->oap->motion_type = MLINE; | |
3896 setpcmark(); | |
3897 | |
3898 if (cap->cmdchar == 'L') | |
3899 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3900 validate_botline(); // make sure curwin->w_botline is valid |
7 | 3901 curwin->w_cursor.lnum = curwin->w_botline - 1; |
3902 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
3903 curwin->w_cursor.lnum = 1; | |
3904 else | |
9 | 3905 { |
3906 #ifdef FEAT_FOLDING | |
3907 if (hasAnyFolding(curwin)) | |
3908 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3909 // Count a fold for one screen line. |
9 | 3910 for (n = cap->count1 - 1; n > 0 |
3911 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
3912 { | |
3913 (void)hasFolding(curwin->w_cursor.lnum, | |
3914 &curwin->w_cursor.lnum, NULL); | |
3915 --curwin->w_cursor.lnum; | |
3916 } | |
3917 } | |
3918 else | |
3919 #endif | |
3920 curwin->w_cursor.lnum -= cap->count1 - 1; | |
3921 } | |
7 | 3922 } |
3923 else | |
3924 { | |
3925 if (cap->cmdchar == 'M') | |
3926 { | |
3927 #ifdef FEAT_DIFF | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3928 // Don't count filler lines above the window. |
7 | 3929 used -= diff_check_fill(curwin, curwin->w_topline) |
3930 - curwin->w_topfill; | |
3931 #endif | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3932 validate_botline(); // make sure w_empty_rows is valid |
7 | 3933 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; |
3934 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
3935 { | |
3936 #ifdef FEAT_DIFF | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3937 // Count half he number of filler lines to be "below this |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3938 // line" and half to be "above the next line". |
7 | 3939 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline |
3940 + n) / 2 >= half) | |
3941 { | |
3942 --n; | |
3943 break; | |
3944 } | |
3945 #endif | |
3946 used += plines(curwin->w_topline + n); | |
3947 if (used >= half) | |
3948 break; | |
3949 #ifdef FEAT_FOLDING | |
3950 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
3951 n = lnum - curwin->w_topline; | |
3952 #endif | |
3953 } | |
3954 if (n > 0 && used > curwin->w_height) | |
3955 --n; | |
3956 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3957 else // (cap->cmdchar == 'H') |
9 | 3958 { |
7 | 3959 n = cap->count1 - 1; |
9 | 3960 #ifdef FEAT_FOLDING |
3961 if (hasAnyFolding(curwin)) | |
3962 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3963 // Count a fold for one screen line. |
9 | 3964 lnum = curwin->w_topline; |
3965 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
3966 { | |
7009 | 3967 (void)hasFolding(lnum, NULL, &lnum); |
9 | 3968 ++lnum; |
3969 } | |
3970 n = lnum - curwin->w_topline; | |
3971 } | |
3972 #endif | |
3973 } | |
7 | 3974 curwin->w_cursor.lnum = curwin->w_topline + n; |
3975 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3976 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3977 } | |
3978 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3979 // Correct for 'so', except when an operator is pending. |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
3980 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
|
3981 cursor_correct(); |
7 | 3982 beginline(BL_SOL | BL_FIX); |
3983 } | |
3984 | |
3985 /* | |
3986 * Cursor right commands. | |
3987 */ | |
3988 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3989 nv_right(cmdarg_T *cap) |
7 | 3990 { |
3991 long n; | |
5735 | 3992 int past_line; |
7 | 3993 |
180 | 3994 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
3995 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
3996 // <C-Right> and <S-Right> move a word or WORD right |
180 | 3997 if (mod_mask & MOD_MASK_CTRL) |
3998 cap->arg = TRUE; | |
3999 nv_wordcmd(cap); | |
4000 return; | |
4001 } | |
4002 | |
7 | 4003 cap->oap->motion_type = MCHAR; |
4004 cap->oap->inclusive = FALSE; | |
5735 | 4005 past_line = (VIsual_active && *p_sel != 'o'); |
4006 | |
7 | 4007 /* |
5735 | 4008 * In virtual edit mode, there's no such thing as "past_line", as lines |
4009 * are (theoretically) infinitely long. | |
7 | 4010 */ |
4011 if (virtual_active()) | |
5735 | 4012 past_line = 0; |
7 | 4013 |
4014 for (n = cap->count1; n > 0; --n) | |
4015 { | |
5735 | 4016 if ((!past_line && oneright() == FAIL) |
4017 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 4018 ) |
7 | 4019 { |
4020 /* | |
714 | 4021 * <Space> wraps to next line if 'whichwrap' has 's'. |
4022 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
4023 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 4024 */ |
4025 if ( ((cap->cmdchar == ' ' | |
4026 && vim_strchr(p_ww, 's') != NULL) | |
4027 || (cap->cmdchar == 'l' | |
4028 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 4029 || (cap->cmdchar == K_RIGHT |
7 | 4030 && vim_strchr(p_ww, '>') != NULL)) |
4031 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4032 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4033 // When deleting we also count the NL as a character. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4034 // Set cap->oap->inclusive when last char in the line is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4035 // included, move to next line after that |
714 | 4036 if ( cap->oap->op_type != OP_NOP |
7 | 4037 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4038 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4039 cap->oap->inclusive = TRUE; |
4040 else | |
4041 { | |
4042 ++curwin->w_cursor.lnum; | |
4043 curwin->w_cursor.col = 0; | |
4044 curwin->w_cursor.coladd = 0; | |
4045 curwin->w_set_curswant = TRUE; | |
4046 cap->oap->inclusive = FALSE; | |
4047 } | |
4048 continue; | |
4049 } | |
4050 if (cap->oap->op_type == OP_NOP) | |
4051 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4052 // Only beep and flush if not moved at all |
7 | 4053 if (n == cap->count1) |
4054 beep_flush(); | |
4055 } | |
4056 else | |
4057 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4058 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4059 cap->oap->inclusive = TRUE; |
4060 } | |
4061 break; | |
4062 } | |
5735 | 4063 else if (past_line) |
7 | 4064 { |
4065 curwin->w_set_curswant = TRUE; | |
4066 if (virtual_active()) | |
4067 oneright(); | |
4068 else | |
5735 | 4069 { |
7 | 4070 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
|
4071 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 4072 else |
4073 ++curwin->w_cursor.col; | |
4074 } | |
4075 } | |
4076 } | |
4077 #ifdef FEAT_FOLDING | |
4078 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
4079 && cap->oap->op_type == OP_NOP) | |
4080 foldOpenCursor(); | |
4081 #endif | |
4082 } | |
4083 | |
4084 /* | |
4085 * Cursor left commands. | |
4086 * | |
4087 * Returns TRUE when operator end should not be adjusted. | |
4088 */ | |
4089 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4090 nv_left(cmdarg_T *cap) |
7 | 4091 { |
4092 long n; | |
4093 | |
180 | 4094 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
4095 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4096 // <C-Left> and <S-Left> move a word or WORD left |
180 | 4097 if (mod_mask & MOD_MASK_CTRL) |
4098 cap->arg = 1; | |
4099 nv_bck_word(cap); | |
4100 return; | |
4101 } | |
4102 | |
7 | 4103 cap->oap->motion_type = MCHAR; |
4104 cap->oap->inclusive = FALSE; | |
4105 for (n = cap->count1; n > 0; --n) | |
4106 { | |
4107 if (oneleft() == FAIL) | |
4108 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4109 // <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4110 // 'h' wraps to previous line if 'whichwrap' has 'h'. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4111 // CURS_LEFT wraps to previous line if 'whichwrap' has '<'. |
7 | 4112 if ( (((cap->cmdchar == K_BS |
4113 || cap->cmdchar == Ctrl_H) | |
4114 && vim_strchr(p_ww, 'b') != NULL) | |
4115 || (cap->cmdchar == 'h' | |
4116 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 4117 || (cap->cmdchar == K_LEFT |
7 | 4118 && vim_strchr(p_ww, '<') != NULL)) |
4119 && curwin->w_cursor.lnum > 1) | |
4120 { | |
4121 --(curwin->w_cursor.lnum); | |
4122 coladvance((colnr_T)MAXCOL); | |
4123 curwin->w_set_curswant = TRUE; | |
4124 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4125 // When the NL before the first char has to be deleted we |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4126 // put the cursor on the NUL after the previous line. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4127 // This is a very special case, be careful! |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4128 // Don't adjust op_end now, otherwise it won't work. |
7 | 4129 if ( (cap->oap->op_type == OP_DELETE |
4130 || 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
|
4131 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 4132 { |
5682 | 4133 char_u *cp = ml_get_cursor(); |
4134 | |
4135 if (*cp != NUL) | |
4136 { | |
4137 if (has_mbyte) | |
4138 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
4139 else | |
4140 ++curwin->w_cursor.col; | |
4141 } | |
7 | 4142 cap->retval |= CA_NO_ADJ_OP_END; |
4143 } | |
4144 continue; | |
4145 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4146 // Only beep and flush if not moved at all |
7 | 4147 else if (cap->oap->op_type == OP_NOP && n == cap->count1) |
4148 beep_flush(); | |
4149 break; | |
4150 } | |
4151 } | |
4152 #ifdef FEAT_FOLDING | |
4153 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
4154 && cap->oap->op_type == OP_NOP) | |
4155 foldOpenCursor(); | |
4156 #endif | |
4157 } | |
4158 | |
4159 /* | |
4160 * Cursor up commands. | |
4161 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
4162 */ | |
4163 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4164 nv_up(cmdarg_T *cap) |
7 | 4165 { |
180 | 4166 if (mod_mask & MOD_MASK_SHIFT) |
4167 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4168 // <S-Up> is page up |
180 | 4169 cap->arg = BACKWARD; |
4170 nv_page(cap); | |
4171 } | |
4172 else | |
4173 { | |
4174 cap->oap->motion_type = MLINE; | |
4175 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
4176 clearopbeep(cap->oap); | |
4177 else if (cap->arg) | |
4178 beginline(BL_WHITE | BL_FIX); | |
4179 } | |
7 | 4180 } |
4181 | |
4182 /* | |
4183 * Cursor down commands. | |
4184 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
4185 */ | |
4186 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
4187 nv_down(cmdarg_T *cap) |
7 | 4188 { |
180 | 4189 if (mod_mask & MOD_MASK_SHIFT) |
4190 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4191 // <S-Down> is page down |
180 | 4192 cap->arg = FORWARD; |
4193 nv_page(cap); | |
4194 } | |
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
|
4195 #if defined(FEAT_QUICKFIX) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4196 // Quickfix window only: view the result under the cursor. |
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
|
4197 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
|
4198 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
|
4199 #endif |
180 | 4200 else |
7 | 4201 { |
4202 #ifdef FEAT_CMDWIN | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4203 // In the cmdline window a <CR> executes the command. |
170 | 4204 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 4205 cmdwin_result = CAR; |
4206 else | |
4207 #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
|
4208 #ifdef FEAT_JOB_CHANNEL |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4209 // In a prompt buffer a <CR> in the last line invokes the callback. |
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
|
4210 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
|
4211 && 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
|
4212 { |
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
|
4213 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
|
4214 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
|
4215 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
|
4216 } |
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
|
4217 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
|
4218 #endif |
7 | 4219 { |
4220 cap->oap->motion_type = MLINE; | |
4221 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
4222 clearopbeep(cap->oap); | |
4223 else if (cap->arg) | |
4224 beginline(BL_WHITE | BL_FIX); | |
4225 } | |
4226 } | |
4227 } | |
4228 | |
4229 #ifdef FEAT_SEARCHPATH | |
4230 /* | |
4231 * Grab the file name under the cursor and edit it. | |
4232 */ | |
4233 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4234 nv_gotofile(cmdarg_T *cap) |
7 | 4235 { |
4236 char_u *ptr; | |
681 | 4237 linenr_T lnum = -1; |
7 | 4238 |
633 | 4239 if (text_locked()) |
7 | 4240 { |
4241 clearopbeep(cap->oap); | |
633 | 4242 text_locked_msg(); |
7 | 4243 return; |
4244 } | |
819 | 4245 if (curbuf_locked()) |
4246 { | |
4247 clearop(cap->oap); | |
4248 return; | |
4249 } | |
20375
b790d00d5ccb
patch 8.2.0743: can move to another buffer from a terminal in popup window
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4250 #ifdef FEAT_PROP_POPUP |
b790d00d5ccb
patch 8.2.0743: can move to another buffer from a terminal in popup window
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4251 if (ERROR_IF_TERM_POPUP_WINDOW) |
b790d00d5ccb
patch 8.2.0743: can move to another buffer from a terminal in popup window
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4252 return; |
b790d00d5ccb
patch 8.2.0743: can move to another buffer from a terminal in popup window
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4253 #endif |
7 | 4254 |
681 | 4255 ptr = grab_file_name(cap->count1, &lnum); |
7 | 4256 |
4257 if (ptr != NULL) | |
4258 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4259 // 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
|
4260 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 4261 (void)autowrite(curbuf, FALSE); |
7 | 4262 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
|
4263 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
|
4264 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
|
4265 && cap->nchar == 'F' && lnum >= 0) |
681 | 4266 { |
4267 curwin->w_cursor.lnum = lnum; | |
4268 check_cursor_lnum(); | |
4269 beginline(BL_SOL | BL_FIX); | |
4270 } | |
7 | 4271 vim_free(ptr); |
4272 } | |
4273 else | |
4274 clearop(cap->oap); | |
4275 } | |
4276 #endif | |
4277 | |
4278 /* | |
4279 * <End> command: to end of current line or last line. | |
4280 */ | |
4281 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4282 nv_end(cmdarg_T *cap) |
7 | 4283 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4284 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) // CTRL-END = goto last line |
180 | 4285 { |
4286 cap->arg = TRUE; | |
7 | 4287 nv_goto(cap); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4288 cap->count1 = 1; // to end of current line |
7 | 4289 } |
4290 nv_dollar(cap); | |
4291 } | |
4292 | |
4293 /* | |
4294 * Handle the "$" command. | |
4295 */ | |
4296 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4297 nv_dollar(cmdarg_T *cap) |
7 | 4298 { |
4299 cap->oap->motion_type = MCHAR; | |
4300 cap->oap->inclusive = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4301 // In virtual mode when off the edge of a line and an operator |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4302 // is pending (whew!) keep the cursor where it is. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4303 // Otherwise, send it to the end of the line. |
7 | 4304 if (!virtual_active() || gchar_cursor() != NUL |
4305 || cap->oap->op_type == OP_NOP) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4306 curwin->w_curswant = MAXCOL; // so we stay at the end |
7 | 4307 if (cursor_down((long)(cap->count1 - 1), |
4308 cap->oap->op_type == OP_NOP) == FAIL) | |
4309 clearopbeep(cap->oap); | |
4310 #ifdef FEAT_FOLDING | |
4311 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4312 foldOpenCursor(); | |
4313 #endif | |
4314 } | |
4315 | |
4316 /* | |
4317 * Implementation of '?' and '/' commands. | |
4318 * If cap->arg is TRUE don't set PC mark. | |
4319 */ | |
4320 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4321 nv_search(cmdarg_T *cap) |
7 | 4322 { |
4323 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4324 pos_T save_cursor = curwin->w_cursor; |
7 | 4325 |
4326 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
4327 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4328 // Translate "g??" to "g?g?" |
7 | 4329 cap->cmdchar = 'g'; |
4330 cap->nchar = '?'; | |
4331 nv_operator(cap); | |
4332 return; | |
4333 } | |
4334 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4335 // When using 'incsearch' the cursor may be moved to set a different search |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4336 // start position. |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17041
diff
changeset
|
4337 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, TRUE); |
7 | 4338 |
4339 if (cap->searchbuf == NULL) | |
4340 { | |
4341 clearop(oap); | |
4342 return; | |
4343 } | |
4344 | |
6620 | 4345 (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
|
4346 (cap->arg || !EQUAL_POS(save_cursor, curwin->w_cursor)) |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4347 ? 0 : SEARCH_MARK, NULL); |
7 | 4348 } |
4349 | |
4350 /* | |
4351 * Handle "N" and "n" commands. | |
4352 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
4353 */ | |
4354 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4355 nv_next(cmdarg_T *cap) |
7 | 4356 { |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4357 pos_T old = curwin->w_cursor; |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4358 int wrapped = FALSE; |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4359 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, &wrapped); |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4360 |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4361 if (i == 1 && !wrapped && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 4362 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4363 // Avoid getting stuck on the current cursor position, which can |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4364 // happen when an offset is given and the cursor is on the last char |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4365 // in the buffer: Repeat with count + 1. |
6620 | 4366 cap->count1 += 1; |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4367 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL); |
6620 | 4368 cap->count1 -= 1; |
4369 } | |
7 | 4370 } |
4371 | |
4372 /* | |
4373 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
4374 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 4375 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
4376 */ | |
4377 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4378 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4379 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4380 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4381 char_u *pat, |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4382 int opt, // extra flags for do_search() |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4383 int *wrapped) |
7 | 4384 { |
4385 int i; | |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4386 searchit_arg_T sia; |
7 | 4387 |
4388 cap->oap->motion_type = MCHAR; | |
4389 cap->oap->inclusive = FALSE; | |
4390 cap->oap->use_reg_one = TRUE; | |
4391 curwin->w_set_curswant = TRUE; | |
4392 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19681
diff
changeset
|
4393 CLEAR_FIELD(sia); |
19475
5512aa74cb62
patch 8.2.0295: highlighting for :s wrong when using different separator
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
4394 i = do_search(cap->oap, dir, dir, pat, cap->count1, |
18358
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4395 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia); |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4396 if (wrapped != NULL) |
34d5cd432cac
patch 8.1.2173: searchit() has too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4397 *wrapped = sia.sa_wrapped; |
7 | 4398 if (i == 0) |
4399 clearop(cap->oap); | |
4400 else | |
4401 { | |
4402 if (i == 2) | |
4403 cap->oap->motion_type = MLINE; | |
4404 curwin->w_cursor.coladd = 0; | |
4405 #ifdef FEAT_FOLDING | |
4406 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
4407 foldOpenCursor(); | |
4408 #endif | |
4409 } | |
4410 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4411 // "/$" will put the cursor after the end of the line, may need to |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4412 // correct that here |
7 | 4413 check_cursor(); |
6620 | 4414 return i; |
7 | 4415 } |
4416 | |
4417 /* | |
4418 * Character search commands. | |
4419 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
4420 * ',' and FALSE for ';'. | |
4421 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
4422 */ | |
4423 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4424 nv_csearch(cmdarg_T *cap) |
7 | 4425 { |
4426 int t_cmd; | |
4427 | |
4428 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
4429 t_cmd = TRUE; | |
4430 else | |
4431 t_cmd = FALSE; | |
4432 | |
4433 cap->oap->motion_type = MCHAR; | |
4434 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
4435 clearopbeep(cap->oap); | |
4436 else | |
4437 { | |
4438 curwin->w_set_curswant = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4439 // Include a Tab for "tx" and for "dfx". |
7 | 4440 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD |
4441 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
4442 { | |
4443 colnr_T scol, ecol; | |
4444 | |
4445 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4446 curwin->w_cursor.coladd = ecol - scol; | |
4447 } | |
4448 else | |
4449 curwin->w_cursor.coladd = 0; | |
4450 adjust_for_sel(cap); | |
4451 #ifdef FEAT_FOLDING | |
4452 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4453 foldOpenCursor(); | |
4454 #endif | |
4455 } | |
4456 } | |
4457 | |
4458 /* | |
4459 * "[" and "]" commands. | |
4460 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
4461 */ | |
4462 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4463 nv_brackets(cmdarg_T *cap) |
7 | 4464 { |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
4465 pos_T new_pos = {0, 0, 0}; |
7 | 4466 pos_T prev_pos; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4467 pos_T *pos = NULL; // init for GCC |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4468 pos_T old_pos; // cursor position before command |
7 | 4469 int flag; |
4470 long n; | |
4471 int findc; | |
4472 int c; | |
4473 | |
4474 cap->oap->motion_type = MCHAR; | |
4475 cap->oap->inclusive = FALSE; | |
4476 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
|
4477 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error. |
7 | 4478 |
4479 #ifdef FEAT_SEARCHPATH | |
4480 /* | |
4481 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
4482 */ | |
4483 if (cap->nchar == 'f') | |
4484 nv_gotofile(cap); | |
4485 else | |
4486 #endif | |
4487 | |
4488 #ifdef FEAT_FIND_ID | |
4489 /* | |
1188 | 4490 * Find the occurrence(s) of the identifier or define under cursor |
4491 * in current and included files or jump to the first occurrence. | |
7 | 4492 * |
4493 * search list jump | |
4494 * fwd bwd fwd bwd fwd bwd | |
4495 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
4496 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
4497 */ | |
4498 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
|
4499 # ifdef EBCDIC |
7 | 4500 "iI\005dD\067", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4501 # else |
7 | 4502 "iI\011dD\004", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4503 # endif |
7 | 4504 cap->nchar) != NULL) |
4505 { | |
4506 char_u *ptr; | |
4507 int len; | |
4508 | |
4509 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
4510 clearop(cap->oap); | |
4511 else | |
4512 { | |
4513 find_pattern_in_path(ptr, 0, len, TRUE, | |
4514 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
4515 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
4516 cap->count1, | |
4517 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
4518 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
4519 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
4520 (linenr_T)MAXLNUM); | |
4521 curwin->w_set_curswant = TRUE; | |
4522 } | |
4523 } | |
4524 else | |
4525 #endif | |
4526 | |
4527 /* | |
4528 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
4529 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
4530 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
4531 * "[m" or "]m" search for prev/next start of (Java) method. | |
4532 * "[M" or "]M" search for prev/next end of (Java) method. | |
4533 */ | |
4534 if ( (cap->cmdchar == '[' | |
4535 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
4536 || (cap->cmdchar == ']' | |
4537 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
4538 { | |
4539 if (cap->nchar == '*') | |
4540 cap->nchar = '/'; | |
4541 prev_pos.lnum = 0; | |
4542 if (cap->nchar == 'm' || cap->nchar == 'M') | |
4543 { | |
4544 if (cap->cmdchar == '[') | |
4545 findc = '{'; | |
4546 else | |
4547 findc = '}'; | |
4548 n = 9999; | |
4549 } | |
4550 else | |
4551 { | |
4552 findc = cap->nchar; | |
4553 n = cap->count1; | |
4554 } | |
4555 for ( ; n > 0; --n) | |
4556 { | |
4557 if ((pos = findmatchlimit(cap->oap, findc, | |
4558 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
4559 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4560 if (new_pos.lnum == 0) // nothing found |
7 | 4561 { |
4562 if (cap->nchar != 'm' && cap->nchar != 'M') | |
4563 clearopbeep(cap->oap); | |
4564 } | |
4565 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4566 pos = &new_pos; // use last one found |
7 | 4567 break; |
4568 } | |
4569 prev_pos = new_pos; | |
4570 curwin->w_cursor = *pos; | |
4571 new_pos = *pos; | |
4572 } | |
4573 curwin->w_cursor = old_pos; | |
4574 | |
4575 /* | |
4576 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
4577 * brought us to the match for "[m" and "]M" when inside a method. | |
4578 * Try finding the '{' or '}' we want to be at. | |
4579 * Also repeat for the given count. | |
4580 */ | |
4581 if (cap->nchar == 'm' || cap->nchar == 'M') | |
4582 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4583 // norm is TRUE for "]M" and "[m" |
7 | 4584 int norm = ((findc == '{') == (cap->nchar == 'm')); |
4585 | |
4586 n = cap->count1; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4587 // found a match: we were inside a method |
7 | 4588 if (prev_pos.lnum != 0) |
4589 { | |
4590 pos = &prev_pos; | |
4591 curwin->w_cursor = prev_pos; | |
4592 if (norm) | |
4593 --n; | |
4594 } | |
4595 else | |
4596 pos = NULL; | |
4597 while (n > 0) | |
4598 { | |
4599 for (;;) | |
4600 { | |
4601 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
4602 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4603 // if not found anything, that's an error |
7 | 4604 if (pos == NULL) |
4605 clearopbeep(cap->oap); | |
4606 n = 0; | |
4607 break; | |
4608 } | |
4609 c = gchar_cursor(); | |
4610 if (c == '{' || c == '}') | |
4611 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4612 // Must have found end/start of class: use it. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4613 // Or found the place to be at. |
7 | 4614 if ((c == findc && norm) || (n == 1 && !norm)) |
4615 { | |
4616 new_pos = curwin->w_cursor; | |
4617 pos = &new_pos; | |
4618 n = 0; | |
4619 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4620 // if no match found at all, we started outside of the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4621 // class and we're inside now. Just go on. |
7 | 4622 else if (new_pos.lnum == 0) |
4623 { | |
4624 new_pos = curwin->w_cursor; | |
4625 pos = &new_pos; | |
4626 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4627 // found start/end of other method: go to match |
7 | 4628 else if ((pos = findmatchlimit(cap->oap, findc, |
4629 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
4630 0)) == NULL) | |
4631 n = 0; | |
4632 else | |
4633 curwin->w_cursor = *pos; | |
4634 break; | |
4635 } | |
4636 } | |
4637 --n; | |
4638 } | |
4639 curwin->w_cursor = old_pos; | |
4640 if (pos == NULL && new_pos.lnum != 0) | |
4641 clearopbeep(cap->oap); | |
4642 } | |
4643 if (pos != NULL) | |
4644 { | |
4645 setpcmark(); | |
4646 curwin->w_cursor = *pos; | |
4647 curwin->w_set_curswant = TRUE; | |
4648 #ifdef FEAT_FOLDING | |
4649 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
4650 && cap->oap->op_type == OP_NOP) | |
4651 foldOpenCursor(); | |
4652 #endif | |
4653 } | |
4654 } | |
4655 | |
4656 /* | |
4657 * "[[", "[]", "]]" and "][": move to start or end of function | |
4658 */ | |
4659 else if (cap->nchar == '[' || cap->nchar == ']') | |
4660 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4661 if (cap->nchar == cap->cmdchar) // "]]" or "[[" |
7 | 4662 flag = '{'; |
4663 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4664 flag = '}'; // "][" or "[]" |
7 | 4665 |
4666 curwin->w_set_curswant = TRUE; | |
4667 /* | |
4668 * Imitate strange Vi behaviour: When using "]]" with an operator | |
4669 * we also stop at '}'. | |
4670 */ | |
503 | 4671 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 4672 (cap->oap->op_type != OP_NOP |
4673 && cap->arg == FORWARD && flag == '{'))) | |
4674 clearopbeep(cap->oap); | |
4675 else | |
4676 { | |
4677 if (cap->oap->op_type == OP_NOP) | |
4678 beginline(BL_WHITE | BL_FIX); | |
4679 #ifdef FEAT_FOLDING | |
4680 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4681 foldOpenCursor(); | |
4682 #endif | |
4683 } | |
4684 } | |
4685 | |
4686 /* | |
4687 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
4688 */ | |
4689 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
4690 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4691 nv_put_opt(cap, TRUE); |
7 | 4692 } |
4693 | |
4694 /* | |
4695 * "['", "[`", "]'" and "]`": jump to next mark | |
4696 */ | |
4697 else if (cap->nchar == '\'' || cap->nchar == '`') | |
4698 { | |
4699 pos = &curwin->w_cursor; | |
4700 for (n = cap->count1; n > 0; --n) | |
4701 { | |
4702 prev_pos = *pos; | |
4703 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
4704 cap->nchar == '\''); | |
4705 if (pos == NULL) | |
4706 break; | |
4707 } | |
4708 if (pos == NULL) | |
4709 pos = &prev_pos; | |
4710 nv_cursormark(cap, cap->nchar == '\'', pos); | |
4711 } | |
4712 | |
4713 /* | |
4714 * [ or ] followed by a middle mouse click: put selected text with | |
4715 * indent adjustment. Any other button just does as usual. | |
4716 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
4717 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 4718 { |
4719 (void)do_mouse(cap->oap, cap->nchar, | |
4720 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
4721 cap->count1, PUT_FIXINDENT); | |
4722 } | |
4723 | |
4724 #ifdef FEAT_FOLDING | |
4725 /* | |
4726 * "[z" and "]z": move to start or end of open fold. | |
4727 */ | |
4728 else if (cap->nchar == 'z') | |
4729 { | |
4730 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
4731 cap->count1) == FAIL) | |
4732 clearopbeep(cap->oap); | |
4733 } | |
4734 #endif | |
4735 | |
4736 #ifdef FEAT_DIFF | |
4737 /* | |
4738 * "[c" and "]c": move to next or previous diff-change. | |
4739 */ | |
4740 else if (cap->nchar == 'c') | |
4741 { | |
4742 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
4743 cap->count1) == FAIL) | |
4744 clearopbeep(cap->oap); | |
4745 } | |
4746 #endif | |
4747 | |
737 | 4748 #ifdef FEAT_SPELL |
236 | 4749 /* |
4750 * "[s", "[S", "]s" and "]S": move to next spell error. | |
4751 */ | |
4752 else if (cap->nchar == 's' || cap->nchar == 'S') | |
4753 { | |
249 | 4754 setpcmark(); |
4755 for (n = 0; n < cap->count1; ++n) | |
498 | 4756 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
4757 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 4758 { |
4759 clearopbeep(cap->oap); | |
4760 break; | |
4761 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
4762 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
4763 curwin->w_set_curswant = TRUE; |
819 | 4764 # ifdef FEAT_FOLDING |
4765 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
4766 foldOpenCursor(); | |
4767 # endif | |
236 | 4768 } |
4769 #endif | |
4770 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4771 // Not a valid cap->nchar. |
7 | 4772 else |
4773 clearopbeep(cap->oap); | |
4774 } | |
4775 | |
4776 /* | |
4777 * Handle Normal mode "%" command. | |
4778 */ | |
4779 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4780 nv_percent(cmdarg_T *cap) |
7 | 4781 { |
4782 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
|
4783 #if defined(FEAT_FOLDING) |
7 | 4784 linenr_T lnum = curwin->w_cursor.lnum; |
4785 #endif | |
4786 | |
4787 cap->oap->inclusive = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4788 if (cap->count0) // {cnt}% : goto {cnt} percentage in file |
7 | 4789 { |
4790 if (cap->count0 > 100) | |
4791 clearopbeep(cap->oap); | |
4792 else | |
4793 { | |
4794 cap->oap->motion_type = MLINE; | |
4795 setpcmark(); | |
24010
c9849ed1ce05
patch 8.2.2547: "%" command not accurate for big files
Bram Moolenaar <Bram@vim.org>
parents:
23762
diff
changeset
|
4796 // Round up, so 'normal 100%' always jumps at the line line. |
c9849ed1ce05
patch 8.2.2547: "%" command not accurate for big files
Bram Moolenaar <Bram@vim.org>
parents:
23762
diff
changeset
|
4797 // Beyond 21474836 lines, (ml_line_count * 100 + 99) would |
c9849ed1ce05
patch 8.2.2547: "%" command not accurate for big files
Bram Moolenaar <Bram@vim.org>
parents:
23762
diff
changeset
|
4798 // overflow on 32-bits, so use a formula with less accuracy |
c9849ed1ce05
patch 8.2.2547: "%" command not accurate for big files
Bram Moolenaar <Bram@vim.org>
parents:
23762
diff
changeset
|
4799 // to avoid overflows. |
c9849ed1ce05
patch 8.2.2547: "%" command not accurate for big files
Bram Moolenaar <Bram@vim.org>
parents:
23762
diff
changeset
|
4800 if (curbuf->b_ml.ml_line_count >= 21474836) |
7 | 4801 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) |
4802 / 100L * cap->count0; | |
4803 else | |
4804 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
4805 cap->count0 + 99L) / 100L; | |
23762
0f89d58eb3e3
patch 8.2.2422: crash when deleting with line number out of range
Bram Moolenaar <Bram@vim.org>
parents:
23687
diff
changeset
|
4806 if (curwin->w_cursor.lnum < 1) |
0f89d58eb3e3
patch 8.2.2422: crash when deleting with line number out of range
Bram Moolenaar <Bram@vim.org>
parents:
23687
diff
changeset
|
4807 curwin->w_cursor.lnum = 1; |
7 | 4808 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
4809 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4810 beginline(BL_SOL | BL_FIX); | |
4811 } | |
4812 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4813 else // "%" : go to matching paren |
7 | 4814 { |
4815 cap->oap->motion_type = MCHAR; | |
4816 cap->oap->use_reg_one = TRUE; | |
4817 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
4818 clearopbeep(cap->oap); | |
4819 else | |
4820 { | |
4821 setpcmark(); | |
4822 curwin->w_cursor = *pos; | |
4823 curwin->w_set_curswant = TRUE; | |
4824 curwin->w_cursor.coladd = 0; | |
4825 adjust_for_sel(cap); | |
4826 } | |
4827 } | |
4828 #ifdef FEAT_FOLDING | |
4829 if (cap->oap->op_type == OP_NOP | |
4830 && lnum != curwin->w_cursor.lnum | |
4831 && (fdo_flags & FDO_PERCENT) | |
4832 && KeyTyped) | |
4833 foldOpenCursor(); | |
4834 #endif | |
4835 } | |
4836 | |
4837 /* | |
4838 * Handle "(" and ")" commands. | |
4839 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
4840 */ | |
4841 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4842 nv_brace(cmdarg_T *cap) |
7 | 4843 { |
4844 cap->oap->motion_type = MCHAR; | |
4845 cap->oap->use_reg_one = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4846 // The motion used to be inclusive for "(", but that is not what Vi does. |
620 | 4847 cap->oap->inclusive = FALSE; |
7 | 4848 curwin->w_set_curswant = TRUE; |
4849 | |
4850 if (findsent(cap->arg, cap->count1) == FAIL) | |
4851 clearopbeep(cap->oap); | |
4852 else | |
4853 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4854 // Don't leave the cursor on the NUL past end of line. |
1505 | 4855 adjust_cursor(cap->oap); |
7 | 4856 curwin->w_cursor.coladd = 0; |
4857 #ifdef FEAT_FOLDING | |
4858 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4859 foldOpenCursor(); | |
4860 #endif | |
4861 } | |
4862 } | |
4863 | |
4864 /* | |
4865 * "m" command: Mark a position. | |
4866 */ | |
4867 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4868 nv_mark(cmdarg_T *cap) |
7 | 4869 { |
4870 if (!checkclearop(cap->oap)) | |
4871 { | |
4872 if (setmark(cap->nchar) == FAIL) | |
4873 clearopbeep(cap->oap); | |
4874 } | |
4875 } | |
4876 | |
4877 /* | |
4878 * "{" and "}" commands. | |
4879 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
4880 */ | |
4881 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4882 nv_findpar(cmdarg_T *cap) |
7 | 4883 { |
4884 cap->oap->motion_type = MCHAR; | |
4885 cap->oap->inclusive = FALSE; | |
4886 cap->oap->use_reg_one = TRUE; | |
4887 curwin->w_set_curswant = TRUE; | |
503 | 4888 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 4889 clearopbeep(cap->oap); |
4890 else | |
4891 { | |
4892 curwin->w_cursor.coladd = 0; | |
4893 #ifdef FEAT_FOLDING | |
4894 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
4895 foldOpenCursor(); | |
4896 #endif | |
4897 } | |
4898 } | |
4899 | |
4900 /* | |
4901 * "u" command: Undo or make lower case. | |
4902 */ | |
4903 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4904 nv_undo(cmdarg_T *cap) |
7 | 4905 { |
5735 | 4906 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 4907 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4908 // translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" |
7 | 4909 cap->cmdchar = 'g'; |
4910 cap->nchar = 'u'; | |
4911 nv_operator(cap); | |
4912 } | |
4913 else | |
4914 nv_kundo(cap); | |
4915 } | |
4916 | |
4917 /* | |
4918 * <Undo> command. | |
4919 */ | |
4920 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4921 nv_kundo(cmdarg_T *cap) |
7 | 4922 { |
4923 if (!checkclearopq(cap->oap)) | |
4924 { | |
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
|
4925 #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
|
4926 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
|
4927 { |
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
|
4928 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
|
4929 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
|
4930 } |
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
|
4931 #endif |
7 | 4932 u_undo((int)cap->count1); |
4933 curwin->w_set_curswant = TRUE; | |
4934 } | |
4935 } | |
4936 | |
4937 /* | |
4938 * Handle the "r" command. | |
4939 */ | |
4940 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4941 nv_replace(cmdarg_T *cap) |
7 | 4942 { |
4943 char_u *ptr; | |
4944 int had_ctrl_v; | |
4945 long n; | |
4946 | |
4947 if (checkclearop(cap->oap)) | |
4948 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
|
4949 #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
|
4950 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
|
4951 { |
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
|
4952 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
|
4953 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
|
4954 } |
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
|
4955 #endif |
7 | 4956 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4957 // get another character |
7 | 4958 if (cap->nchar == Ctrl_V) |
4959 { | |
4960 had_ctrl_v = Ctrl_V; | |
23076
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23021
diff
changeset
|
4961 cap->nchar = get_literal(FALSE); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4962 // Don't redo a multibyte character with CTRL-V. |
7 | 4963 if (cap->nchar > DEL) |
4964 had_ctrl_v = NUL; | |
4965 } | |
4966 else | |
4967 had_ctrl_v = NUL; | |
4968 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4969 // Abort if the character is a special key. |
1343 | 4970 if (IS_SPECIAL(cap->nchar)) |
4971 { | |
4972 clearopbeep(cap->oap); | |
4973 return; | |
4974 } | |
4975 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4976 // Visual mode "r" |
7 | 4977 if (VIsual_active) |
4978 { | |
1797 | 4979 if (got_int) |
4980 reset_VIsual(); | |
5428 | 4981 if (had_ctrl_v) |
4982 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4983 // Use a special (negative) number to make a difference between a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4984 // literal CR or NL and a line break. |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4985 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
4986 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
|
4987 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
|
4988 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 4989 } |
7 | 4990 nv_operator(cap); |
4991 return; | |
4992 } | |
4993 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
4994 // Break tabs, etc. |
7 | 4995 if (virtual_active()) |
4996 { | |
4997 if (u_save_cursor() == FAIL) | |
4998 return; | |
4999 if (gchar_cursor() == NUL) | |
5000 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5001 // Add extra space and put the cursor on the first one. |
7 | 5002 coladvance_force((colnr_T)(getviscol() + cap->count1)); |
5003 curwin->w_cursor.col -= cap->count1; | |
5004 } | |
5005 else if (gchar_cursor() == TAB) | |
5006 coladvance_force(getviscol()); | |
5007 } | |
5008 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5009 // Abort if not enough characters to replace. |
7 | 5010 ptr = ml_get_cursor(); |
1343 | 5011 if (STRLEN(ptr) < (unsigned)cap->count1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5012 || (has_mbyte && mb_charlen(ptr) < cap->count1)) |
7 | 5013 { |
5014 clearopbeep(cap->oap); | |
5015 return; | |
5016 } | |
5017 | |
5018 /* | |
5019 * Replacing with a TAB is done by edit() when it is complicated because | |
5020 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
5021 * Other characters are done below to avoid problems with things like | |
5022 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
5023 */ | |
5024 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
5025 { | |
5026 stuffnumReadbuff(cap->count1); | |
5027 stuffcharReadbuff('R'); | |
5028 stuffcharReadbuff('\t'); | |
5029 stuffcharReadbuff(ESC); | |
5030 return; | |
5031 } | |
5032 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5033 // save line for undo |
7 | 5034 if (u_save_cursor() == FAIL) |
5035 return; | |
5036 | |
5037 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
5038 { | |
5039 /* | |
5040 * Replace character(s) by a single newline. | |
5041 * Strange vi behaviour: Only one newline is inserted. | |
5042 * Delete the characters here. | |
5043 * Insert the newline with an insert command, takes care of | |
5044 * autoindent. The insert command depends on being on the last | |
5045 * character of a line or not. | |
5046 */ | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5047 (void)del_chars(cap->count1, FALSE); // delete the characters |
7 | 5048 stuffcharReadbuff('\r'); |
5049 stuffcharReadbuff(ESC); | |
5050 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5051 // Give 'r' to edit(), to get the redo command right. |
7 | 5052 invoke_edit(cap, TRUE, 'r', FALSE); |
5053 } | |
5054 else | |
5055 { | |
5056 prep_redo(cap->oap->regname, cap->count1, | |
5057 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
5058 | |
5059 curbuf->b_op_start = curwin->w_cursor; | |
5060 if (has_mbyte) | |
5061 { | |
5062 int old_State = State; | |
5063 | |
5064 if (cap->ncharC1 != 0) | |
5065 AppendCharToRedobuff(cap->ncharC1); | |
5066 if (cap->ncharC2 != 0) | |
5067 AppendCharToRedobuff(cap->ncharC2); | |
5068 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5069 // This is slow, but it handles replacing a single-byte with a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5070 // multi-byte and the other way around. Also handles adding |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5071 // composing characters for utf-8. |
7 | 5072 for (n = cap->count1; n > 0; --n) |
5073 { | |
5074 State = REPLACE; | |
3501 | 5075 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
5076 { | |
5077 int c = ins_copychar(curwin->w_cursor.lnum | |
5078 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
5079 if (c != NUL) | |
5080 ins_char(c); | |
5081 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5082 // will be decremented further down |
3501 | 5083 ++curwin->w_cursor.col; |
5084 } | |
5085 else | |
5086 ins_char(cap->nchar); | |
7 | 5087 State = old_State; |
5088 if (cap->ncharC1 != 0) | |
5089 ins_char(cap->ncharC1); | |
5090 if (cap->ncharC2 != 0) | |
5091 ins_char(cap->ncharC2); | |
5092 } | |
5093 } | |
5094 else | |
5095 { | |
5096 /* | |
5097 * Replace the characters within one line. | |
5098 */ | |
5099 for (n = cap->count1; n > 0; --n) | |
5100 { | |
5101 /* | |
5102 * Get ptr again, because u_save and/or showmatch() will have | |
25786
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5103 * released the line. This may also happen in ins_copychar(). |
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5104 * At the same time we let know that the line will be changed. |
7 | 5105 */ |
3501 | 5106 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
5107 { | |
5108 int c = ins_copychar(curwin->w_cursor.lnum | |
5109 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
25786
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5110 |
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5111 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); |
3501 | 5112 if (c != NUL) |
5113 ptr[curwin->w_cursor.col] = c; | |
5114 } | |
5115 else | |
25786
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5116 { |
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5117 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); |
3501 | 5118 ptr[curwin->w_cursor.col] = cap->nchar; |
25786
ec62e0764ffa
patch 8.2.3428: using freed memory when replacing
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
5119 } |
7 | 5120 if (p_sm && msg_silent == 0) |
5121 showmatch(cap->nchar); | |
5122 ++curwin->w_cursor.col; | |
5123 } | |
5124 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5125 if (netbeans_active()) |
7 | 5126 { |
2210 | 5127 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 5128 |
33 | 5129 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 5130 (long)cap->count1); |
7 | 5131 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 5132 &ptr[start], (int)cap->count1); |
7 | 5133 } |
5134 #endif | |
5135 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5136 // mark the buffer as changed and prepare for displaying |
7 | 5137 changed_bytes(curwin->w_cursor.lnum, |
5138 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
5139 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5140 --curwin->w_cursor.col; // cursor on the last replaced char |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5141 // if the character on the left of the current cursor is a multi-byte |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5142 // character, move two characters left |
7 | 5143 if (has_mbyte) |
5144 mb_adjust_cursor(); | |
5145 curbuf->b_op_end = curwin->w_cursor; | |
5146 curwin->w_set_curswant = TRUE; | |
5147 set_last_insert(cap->nchar); | |
5148 } | |
5149 } | |
5150 | |
5151 /* | |
5152 * 'o': Exchange start and end of Visual area. | |
5153 * 'O': same, but in block mode exchange left and right corners. | |
5154 */ | |
5155 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5156 v_swap_corners(int cmdchar) |
7 | 5157 { |
5158 pos_T old_cursor; | |
5159 colnr_T left, right; | |
5160 | |
5161 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
5162 { | |
5163 old_cursor = curwin->w_cursor; | |
5164 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
5165 curwin->w_cursor.lnum = VIsual.lnum; | |
5166 coladvance(left); | |
5167 VIsual = curwin->w_cursor; | |
5168 | |
5169 curwin->w_cursor.lnum = old_cursor.lnum; | |
5170 curwin->w_curswant = right; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5171 // 'selection "exclusive" and cursor at right-bottom corner: move it |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5172 // right one column |
7 | 5173 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') |
5174 ++curwin->w_curswant; | |
5175 coladvance(curwin->w_curswant); | |
5176 if (curwin->w_cursor.col == old_cursor.col | |
5177 && (!virtual_active() | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5178 || curwin->w_cursor.coladd == old_cursor.coladd)) |
7 | 5179 { |
5180 curwin->w_cursor.lnum = VIsual.lnum; | |
5181 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
5182 ++right; | |
5183 coladvance(right); | |
5184 VIsual = curwin->w_cursor; | |
5185 | |
5186 curwin->w_cursor.lnum = old_cursor.lnum; | |
5187 coladvance(left); | |
5188 curwin->w_curswant = left; | |
5189 } | |
5190 } | |
5191 else | |
5192 { | |
5193 old_cursor = curwin->w_cursor; | |
5194 curwin->w_cursor = VIsual; | |
5195 VIsual = old_cursor; | |
5196 curwin->w_set_curswant = TRUE; | |
5197 } | |
5198 } | |
5199 | |
5200 /* | |
5201 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
5202 */ | |
5203 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5204 nv_Replace(cmdarg_T *cap) |
7 | 5205 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5206 if (VIsual_active) // "R" is replace lines |
7 | 5207 { |
5208 cap->cmdchar = 'c'; | |
5209 cap->nchar = NUL; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5210 VIsual_mode_orig = VIsual_mode; // remember original area for gv |
7 | 5211 VIsual_mode = 'V'; |
5212 nv_operator(cap); | |
5213 } | |
5735 | 5214 else if (!checkclearopq(cap->oap)) |
7 | 5215 { |
5216 if (!curbuf->b_p_ma) | |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24866
diff
changeset
|
5217 emsg(_(e_cannot_make_changes_modifiable_is_off)); |
7 | 5218 else |
5219 { | |
5220 if (virtual_active()) | |
5221 coladvance(getviscol()); | |
5222 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
5223 } | |
5224 } | |
5225 } | |
5226 | |
5227 /* | |
5228 * "gr". | |
5229 */ | |
5230 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5231 nv_vreplace(cmdarg_T *cap) |
7 | 5232 { |
5233 if (VIsual_active) | |
5234 { | |
5235 cap->cmdchar = 'r'; | |
5236 cap->nchar = cap->extra_char; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5237 nv_replace(cap); // Do same as "r" in Visual mode for now |
7 | 5238 } |
5735 | 5239 else if (!checkclearopq(cap->oap)) |
7 | 5240 { |
5241 if (!curbuf->b_p_ma) | |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24866
diff
changeset
|
5242 emsg(_(e_cannot_make_changes_modifiable_is_off)); |
7 | 5243 else |
5244 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5245 if (cap->extra_char == Ctrl_V) // get another character |
23076
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23021
diff
changeset
|
5246 cap->extra_char = get_literal(FALSE); |
7 | 5247 stuffcharReadbuff(cap->extra_char); |
5248 stuffcharReadbuff(ESC); | |
5249 if (virtual_active()) | |
5250 coladvance(getviscol()); | |
5251 invoke_edit(cap, TRUE, 'v', FALSE); | |
5252 } | |
5253 } | |
5254 } | |
5255 | |
5256 /* | |
5257 * Swap case for "~" command, when it does not work like an operator. | |
5258 */ | |
5259 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5260 n_swapchar(cmdarg_T *cap) |
7 | 5261 { |
5262 long n; | |
5263 pos_T startpos; | |
5264 int did_change = 0; | |
5265 #ifdef FEAT_NETBEANS_INTG | |
5266 pos_T pos; | |
5267 char_u *ptr; | |
5268 int count; | |
5269 #endif | |
5270 | |
5271 if (checkclearopq(cap->oap)) | |
5272 return; | |
5273 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5274 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 5275 { |
5276 clearopbeep(cap->oap); | |
5277 return; | |
5278 } | |
5279 | |
5280 prep_redo_cmd(cap); | |
5281 | |
5282 if (u_save_cursor() == FAIL) | |
5283 return; | |
5284 | |
5285 startpos = curwin->w_cursor; | |
5286 #ifdef FEAT_NETBEANS_INTG | |
5287 pos = startpos; | |
5288 #endif | |
5289 for (n = cap->count1; n > 0; --n) | |
5290 { | |
5291 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
5292 inc_cursor(); | |
5293 if (gchar_cursor() == NUL) | |
5294 { | |
5295 if (vim_strchr(p_ww, '~') != NULL | |
5296 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
5297 { | |
5298 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5299 if (netbeans_active()) |
7 | 5300 { |
5301 if (did_change) | |
5302 { | |
5303 ptr = ml_get(pos.lnum); | |
835 | 5304 count = (int)STRLEN(ptr) - pos.col; |
33 | 5305 netbeans_removed(curbuf, pos.lnum, pos.col, |
5306 (long)count); | |
7 | 5307 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 5308 &ptr[pos.col], count); |
7 | 5309 } |
5310 pos.col = 0; | |
5311 pos.lnum++; | |
5312 } | |
5313 #endif | |
5314 ++curwin->w_cursor.lnum; | |
5315 curwin->w_cursor.col = 0; | |
5316 if (n > 1) | |
5317 { | |
5318 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
5319 break; | |
5320 u_clearline(); | |
5321 } | |
5322 } | |
5323 else | |
5324 break; | |
5325 } | |
5326 } | |
5327 #ifdef FEAT_NETBEANS_INTG | |
2210 | 5328 if (did_change && netbeans_active()) |
7 | 5329 { |
5330 ptr = ml_get(pos.lnum); | |
5331 count = curwin->w_cursor.col - pos.col; | |
33 | 5332 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
5333 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 5334 } |
5335 #endif | |
5336 | |
5337 | |
5338 check_cursor(); | |
5339 curwin->w_set_curswant = TRUE; | |
5340 if (did_change) | |
5341 { | |
5342 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
5343 0L); | |
5344 curbuf->b_op_start = startpos; | |
5345 curbuf->b_op_end = curwin->w_cursor; | |
5346 if (curbuf->b_op_end.col > 0) | |
5347 --curbuf->b_op_end.col; | |
5348 } | |
5349 } | |
5350 | |
5351 /* | |
5352 * Move cursor to mark. | |
5353 */ | |
5354 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5355 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 5356 { |
5357 if (check_mark(pos) == FAIL) | |
5358 clearop(cap->oap); | |
5359 else | |
5360 { | |
5361 if (cap->cmdchar == '\'' | |
5362 || cap->cmdchar == '`' | |
5363 || cap->cmdchar == '[' | |
5364 || cap->cmdchar == ']') | |
5365 setpcmark(); | |
5366 curwin->w_cursor = *pos; | |
5367 if (flag) | |
5368 beginline(BL_WHITE | BL_FIX); | |
5369 else | |
5370 check_cursor(); | |
5371 } | |
5372 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
5373 if (cap->cmdchar == '`') | |
5374 cap->oap->use_reg_one = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5375 cap->oap->inclusive = FALSE; // ignored if not MCHAR |
7 | 5376 curwin->w_set_curswant = TRUE; |
5377 } | |
5378 | |
5379 /* | |
5380 * Handle commands that are operators in Visual mode. | |
5381 */ | |
5382 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5383 v_visop(cmdarg_T *cap) |
7 | 5384 { |
5385 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
5386 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5387 // Uppercase means linewise, except in block mode, then "D" deletes till |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5388 // the end of the line, and "C" replaces till EOL |
7 | 5389 if (isupper(cap->cmdchar)) |
5390 { | |
5391 if (VIsual_mode != Ctrl_V) | |
4213 | 5392 { |
5393 VIsual_mode_orig = VIsual_mode; | |
7 | 5394 VIsual_mode = 'V'; |
4213 | 5395 } |
7 | 5396 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
5397 curwin->w_curswant = MAXCOL; | |
5398 } | |
5399 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
5400 nv_operator(cap); | |
5401 } | |
5402 | |
5403 /* | |
5404 * "s" and "S" commands. | |
5405 */ | |
5406 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5407 nv_subst(cmdarg_T *cap) |
7 | 5408 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5409 #ifdef FEAT_TERMINAL |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23165
diff
changeset
|
5410 // When showing output of term_dumpdiff() swap the top and bottom. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5411 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
|
5412 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5413 #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
|
5414 #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
|
5415 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
|
5416 { |
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
|
5417 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
|
5418 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
|
5419 } |
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
|
5420 #endif |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5421 if (VIsual_active) // "vs" and "vS" are the same as "vc" |
7 | 5422 { |
5423 if (cap->cmdchar == 'S') | |
4213 | 5424 { |
5425 VIsual_mode_orig = VIsual_mode; | |
7 | 5426 VIsual_mode = 'V'; |
4213 | 5427 } |
7 | 5428 cap->cmdchar = 'c'; |
5429 nv_operator(cap); | |
5430 } | |
5431 else | |
5432 nv_optrans(cap); | |
5433 } | |
5434 | |
5435 /* | |
5436 * Abbreviated commands. | |
5437 */ | |
5438 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5439 nv_abbrev(cmdarg_T *cap) |
7 | 5440 { |
5441 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5442 cap->cmdchar = 'x'; // DEL key behaves like 'x' |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5443 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5444 // in Visual mode these commands are operators |
7 | 5445 if (VIsual_active) |
5446 v_visop(cap); | |
5447 else | |
5448 nv_optrans(cap); | |
5449 } | |
5450 | |
5451 /* | |
5452 * Translate a command into another command. | |
5453 */ | |
5454 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5455 nv_optrans(cmdarg_T *cap) |
7 | 5456 { |
5457 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
5458 (char_u *)"d$", (char_u *)"c$", | |
5459 (char_u *)"cl", (char_u *)"cc", | |
5460 (char_u *)"yy", (char_u *)":s\r"}; | |
5461 static char_u *str = (char_u *)"xXDCsSY&"; | |
5462 | |
5463 if (!checkclearopq(cap->oap)) | |
5464 { | |
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
|
5465 // 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
|
5466 // either, because "2." should also not use the count. |
164 | 5467 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) |
5468 { | |
5469 cap->oap->start = curwin->w_cursor; | |
5470 cap->oap->op_type = OP_DELETE; | |
1490 | 5471 #ifdef FEAT_EVAL |
5472 set_op_var(OP_DELETE); | |
5473 #endif | |
164 | 5474 cap->count1 = 1; |
5475 nv_dollar(cap); | |
5476 finish_op = TRUE; | |
5477 ResetRedobuff(); | |
5478 AppendCharToRedobuff('D'); | |
5479 } | |
5480 else | |
5481 { | |
5482 if (cap->count0) | |
5483 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
|
5484 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); |
164 | 5485 } |
7 | 5486 } |
5487 cap->opcount = 0; | |
5488 } | |
5489 | |
5490 /* | |
5491 * "'" and "`" commands. Also for "g'" and "g`". | |
5492 * cap->arg is TRUE for "'" and "g'". | |
5493 */ | |
5494 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5495 nv_gomark(cmdarg_T *cap) |
7 | 5496 { |
5497 pos_T *pos; | |
5498 int c; | |
5499 #ifdef FEAT_FOLDING | |
4017 | 5500 pos_T old_cursor = curwin->w_cursor; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5501 int old_KeyTyped = KeyTyped; // getting file may reset it |
7 | 5502 #endif |
5503 | |
5504 if (cap->cmdchar == 'g') | |
5505 c = cap->extra_char; | |
5506 else | |
5507 c = cap->nchar; | |
5508 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5509 if (pos == (pos_T *)-1) // jumped to other file |
7 | 5510 { |
5511 if (cap->arg) | |
5512 { | |
5513 check_cursor_lnum(); | |
5514 beginline(BL_WHITE | BL_FIX); | |
5515 } | |
5516 else | |
5517 check_cursor(); | |
5518 } | |
5519 else | |
5520 nv_cursormark(cap, cap->arg, pos); | |
5521 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5522 // May need to clear the coladd that a mark includes. |
7 | 5523 if (!virtual_active()) |
5524 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
|
5525 check_cursor_col(); |
7 | 5526 #ifdef FEAT_FOLDING |
5527 if (cap->oap->op_type == OP_NOP | |
4057 | 5528 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5529 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 5530 && (fdo_flags & FDO_MARK) |
5531 && old_KeyTyped) | |
5532 foldOpenCursor(); | |
5533 #endif | |
5534 } | |
5535 | |
5536 /* | |
21703
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5537 * Handle CTRL-O, CTRL-I, "g;", "g," and "CTRL-Tab" commands. |
7 | 5538 */ |
5539 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5540 nv_pcmark(cmdarg_T *cap) |
7 | 5541 { |
5542 #ifdef FEAT_JUMPLIST | |
5543 pos_T *pos; | |
5544 # ifdef FEAT_FOLDING | |
5545 linenr_T lnum = curwin->w_cursor.lnum; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5546 int old_KeyTyped = KeyTyped; // getting file may reset it |
7 | 5547 # endif |
5548 | |
5549 if (!checkclearopq(cap->oap)) | |
5550 { | |
21703
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5551 if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL) |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5552 { |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5553 if (goto_tabpage_lastused() == FAIL) |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5554 clearopbeep(cap->oap); |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5555 return; |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
5556 } |
7 | 5557 if (cap->cmdchar == 'g') |
5558 pos = movechangelist((int)cap->count1); | |
5559 else | |
5560 pos = movemark((int)cap->count1); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5561 if (pos == (pos_T *)-1) // jump to other file |
7 | 5562 { |
5563 curwin->w_set_curswant = TRUE; | |
5564 check_cursor(); | |
5565 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5566 else if (pos != NULL) // can jump |
7 | 5567 nv_cursormark(cap, FALSE, pos); |
5568 else if (cap->cmdchar == 'g') | |
5569 { | |
5570 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
|
5571 emsg(_("E664: changelist is empty")); |
7 | 5572 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
|
5573 emsg(_("E662: At start of changelist")); |
7 | 5574 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5575 emsg(_("E663: At end of changelist")); |
7 | 5576 } |
5577 else | |
5578 clearopbeep(cap->oap); | |
5579 # ifdef FEAT_FOLDING | |
5580 if (cap->oap->op_type == OP_NOP | |
5581 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
5582 && (fdo_flags & FDO_MARK) | |
5583 && old_KeyTyped) | |
5584 foldOpenCursor(); | |
5585 # endif | |
5586 } | |
5587 #else | |
5588 clearopbeep(cap->oap); | |
5589 #endif | |
5590 } | |
5591 | |
5592 /* | |
5593 * Handle '"' command. | |
5594 */ | |
5595 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5596 nv_regname(cmdarg_T *cap) |
7 | 5597 { |
5598 if (checkclearop(cap->oap)) | |
5599 return; | |
5600 #ifdef FEAT_EVAL | |
5601 if (cap->nchar == '=') | |
5602 cap->nchar = get_expr_register(); | |
5603 #endif | |
5604 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
5605 { | |
5606 cap->oap->regname = cap->nchar; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5607 cap->opcount = cap->count0; // remember count before '"' |
7 | 5608 #ifdef FEAT_EVAL |
5609 set_reg_var(cap->oap->regname); | |
5610 #endif | |
5611 } | |
5612 else | |
5613 clearopbeep(cap->oap); | |
5614 } | |
5615 | |
5616 /* | |
5617 * Handle "v", "V" and "CTRL-V" commands. | |
5618 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
5619 * is TRUE. | |
167 | 5620 * Handle CTRL-Q just like CTRL-V. |
7 | 5621 */ |
5622 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5623 nv_visual(cmdarg_T *cap) |
7 | 5624 { |
167 | 5625 if (cap->cmdchar == Ctrl_Q) |
5626 cap->cmdchar = Ctrl_V; | |
5627 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5628 // 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5629 // characterwise, linewise, or blockwise. |
7 | 5630 if (cap->oap->op_type != OP_NOP) |
5631 { | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
5632 motion_force = cap->oap->motion_force = cap->cmdchar; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5633 finish_op = FALSE; // operator doesn't finish now but later |
7 | 5634 return; |
5635 } | |
5636 | |
5637 VIsual_select = cap->arg; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5638 if (VIsual_active) // change Visual mode |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5639 { |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5640 if (VIsual_mode == cap->cmdchar) // stop visual mode |
7 | 5641 end_visual_mode(); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5642 else // toggle char/block mode |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5643 { // or char/line mode |
7 | 5644 VIsual_mode = cap->cmdchar; |
5645 showmode(); | |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25786
diff
changeset
|
5646 trigger_modechanged(); |
7 | 5647 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5648 redraw_curbuf_later(INVERTED); // update the inversion |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5649 } |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5650 else // start Visual mode |
7 | 5651 { |
5652 check_visual_highlight(); | |
3537 | 5653 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
5654 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5655 // use previously selected part |
7 | 5656 VIsual = curwin->w_cursor; |
5657 | |
5658 VIsual_active = TRUE; | |
5659 VIsual_reselect = TRUE; | |
5660 if (!cap->arg) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5661 // start Select mode when 'selectmode' contains "cmd" |
7 | 5662 may_start_select('c'); |
5663 setmouse(); | |
641 | 5664 if (p_smd && msg_silent == 0) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5665 redraw_cmdline = TRUE; // show visual mode later |
7 | 5666 /* |
5667 * For V and ^V, we multiply the number of lines even if there | |
5668 * was only one -- webb | |
5669 */ | |
5670 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
5671 { | |
5672 curwin->w_cursor.lnum += | |
5673 resel_VIsual_line_count * cap->count0 - 1; | |
5674 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5675 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5676 } | |
5677 VIsual_mode = resel_VIsual_mode; | |
5678 if (VIsual_mode == 'v') | |
5679 { | |
5680 if (resel_VIsual_line_count <= 1) | |
3125 | 5681 { |
5682 validate_virtcol(); | |
5683 curwin->w_curswant = curwin->w_virtcol | |
5684 + resel_VIsual_vcol * cap->count0 - 1; | |
5685 } | |
7 | 5686 else |
3125 | 5687 curwin->w_curswant = resel_VIsual_vcol; |
5688 coladvance(curwin->w_curswant); | |
7 | 5689 } |
3125 | 5690 if (resel_VIsual_vcol == MAXCOL) |
7 | 5691 { |
5692 curwin->w_curswant = MAXCOL; | |
5693 coladvance((colnr_T)MAXCOL); | |
5694 } | |
5695 else if (VIsual_mode == Ctrl_V) | |
5696 { | |
5697 validate_virtcol(); | |
5698 curwin->w_curswant = curwin->w_virtcol | |
3125 | 5699 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 5700 coladvance(curwin->w_curswant); |
5701 } | |
5702 else | |
5703 curwin->w_set_curswant = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5704 redraw_curbuf_later(INVERTED); // show the inversion |
7 | 5705 } |
5706 else | |
5707 { | |
5708 if (!cap->arg) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5709 // start Select mode when 'selectmode' contains "cmd" |
7 | 5710 may_start_select('c'); |
5711 n_start_visual_mode(cap->cmdchar); | |
3537 | 5712 if (VIsual_mode != 'V' && *p_sel == 'e') |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5713 ++cap->count1; // include one more char |
3537 | 5714 if (cap->count0 > 0 && --cap->count1 > 0) |
5715 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5716 // With a count select that many characters or lines. |
3537 | 5717 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) |
5718 nv_right(cap); | |
5719 else if (VIsual_mode == 'V') | |
5720 nv_down(cap); | |
5721 } | |
7 | 5722 } |
5723 } | |
5724 } | |
5725 | |
5726 /* | |
5727 * Start selection for Shift-movement keys. | |
5728 */ | |
5729 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5730 start_selection(void) |
7 | 5731 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5732 // if 'selectmode' contains "key", start Select mode |
7 | 5733 may_start_select('k'); |
5734 n_start_visual_mode('v'); | |
5735 } | |
5736 | |
5737 /* | |
5738 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
5739 */ | |
5740 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5741 may_start_select(int c) |
7 | 5742 { |
5743 VIsual_select = (stuff_empty() && typebuf_typed() | |
5744 && (vim_strchr(p_slm, c) != NULL)); | |
5745 } | |
5746 | |
5747 /* | |
5748 * Start Visual mode "c". | |
5749 * Should set VIsual_select before calling this. | |
5750 */ | |
5751 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5752 n_start_visual_mode(int c) |
7 | 5753 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5754 #ifdef FEAT_CONCEAL |
25074
aa55d6d17625
patch 8.2.3074: popup_atcursor() uses wrong position with concealing
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
5755 int cursor_line_was_concealed = curwin->w_p_cole > 0 |
aa55d6d17625
patch 8.2.3074: popup_atcursor() uses wrong position with concealing
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
5756 && conceal_cursor_line(curwin); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5757 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5758 |
7 | 5759 VIsual_mode = c; |
5760 VIsual_active = TRUE; | |
5761 VIsual_reselect = TRUE; | |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25786
diff
changeset
|
5762 trigger_modechanged(); |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5763 |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
5764 // Corner case: the 0 position in a tab may change when going into |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
18808
diff
changeset
|
5765 // virtualedit. Recalculate curwin->w_cursor to avoid bad highlighting. |
25380
ac88cd21ae88
patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents:
25074
diff
changeset
|
5766 if (c == Ctrl_V && (get_ve_flags() & VE_BLOCK) && gchar_cursor() == TAB) |
3742 | 5767 { |
5768 validate_virtcol(); | |
7 | 5769 coladvance(curwin->w_virtcol); |
3742 | 5770 } |
7 | 5771 VIsual = curwin->w_cursor; |
5772 | |
5773 #ifdef FEAT_FOLDING | |
5774 foldAdjustVisual(); | |
5775 #endif | |
5776 | |
5777 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
|
5778 #ifdef FEAT_CONCEAL |
25074
aa55d6d17625
patch 8.2.3074: popup_atcursor() uses wrong position with concealing
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
5779 // Check if redraw is needed after changing the state. |
aa55d6d17625
patch 8.2.3074: popup_atcursor() uses wrong position with concealing
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
5780 conceal_check_cursor_line(cursor_line_was_concealed); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5781 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5782 |
641 | 5783 if (p_smd && msg_silent == 0) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5784 redraw_cmdline = TRUE; // show visual mode later |
7 | 5785 #ifdef FEAT_CLIPBOARD |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5786 // Make sure the clipboard gets updated. Needed because start and |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5787 // end may still be the same, and the selection needs to be owned |
7 | 5788 clip_star.vmode = NUL; |
5789 #endif | |
5790 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5791 // Only need to redraw this line, unless still need to redraw an old |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5792 // Visual area (when 'lazyredraw' is set). |
7 | 5793 if (curwin->w_redr_type < INVERTED) |
5794 { | |
5795 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
5796 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
5797 } | |
5798 } | |
5799 | |
5800 | |
5801 /* | |
5802 * CTRL-W: Window commands | |
5803 */ | |
5804 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5805 nv_window(cmdarg_T *cap) |
7 | 5806 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
5807 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5808 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5809 // "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
|
5810 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5811 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
|
5812 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5813 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
5814 else if (!checkclearop(cap->oap)) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5815 do_window(cap->nchar, cap->count0, NUL); // everything is in window.c |
7 | 5816 } |
5817 | |
5818 /* | |
5819 * CTRL-Z: Suspend | |
5820 */ | |
5821 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5822 nv_suspend(cmdarg_T *cap) |
7 | 5823 { |
5824 clearop(cap->oap); | |
5825 if (VIsual_active) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5826 end_visual_mode(); // stop Visual mode |
23165
a916fca16d4b
patch 8.2.2128: there is no way to do something on CTRL-Z
Bram Moolenaar <Bram@vim.org>
parents:
23076
diff
changeset
|
5827 do_cmdline_cmd((char_u *)"stop"); |
7 | 5828 } |
5829 | |
5830 /* | |
5831 * Commands starting with "g". | |
5832 */ | |
5833 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5834 nv_g_cmd(cmdarg_T *cap) |
7 | 5835 { |
5836 oparg_T *oap = cap->oap; | |
5837 pos_T tpos; | |
5838 int i; | |
5839 int flag = FALSE; | |
5840 | |
5841 switch (cap->nchar) | |
5842 { | |
6868 | 5843 case Ctrl_A: |
5844 case Ctrl_X: | |
7 | 5845 #ifdef MEM_PROFILE |
5846 /* | |
5847 * "g^A": dump log of used memory. | |
5848 */ | |
6868 | 5849 if (!VIsual_active && cap->nchar == Ctrl_A) |
5850 vim_mem_profile_dump(); | |
5851 else | |
5852 #endif | |
5853 /* | |
5854 * "g^A/g^X": sequentially increment visually selected region | |
5855 */ | |
5856 if (VIsual_active) | |
5857 { | |
5858 cap->arg = TRUE; | |
5859 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
5860 cap->nchar = NUL; |
6868 | 5861 nv_addsub(cap); |
5862 } | |
5863 else | |
5864 clearopbeep(oap); | |
7 | 5865 break; |
5866 | |
5867 /* | |
5868 * "gR": Enter virtual replace mode. | |
5869 */ | |
5870 case 'R': | |
5871 cap->arg = TRUE; | |
5872 nv_Replace(cap); | |
5873 break; | |
5874 | |
5875 case 'r': | |
5876 nv_vreplace(cap); | |
5877 break; | |
5878 | |
5879 case '&': | |
5880 do_cmdline_cmd((char_u *)"%s//~/&"); | |
5881 break; | |
5882 | |
5883 /* | |
5884 * "gv": Reselect the previous Visual area. If Visual already active, | |
5885 * exchange previous and current Visual area. | |
5886 */ | |
5887 case 'v': | |
5888 if (checkclearop(oap)) | |
5889 break; | |
5890 | |
690 | 5891 if ( curbuf->b_visual.vi_start.lnum == 0 |
5892 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
5893 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 5894 beep_flush(); |
5895 else | |
5896 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5897 // set w_cursor to the start of the Visual area, tpos to the end |
7 | 5898 if (VIsual_active) |
5899 { | |
5900 i = VIsual_mode; | |
690 | 5901 VIsual_mode = curbuf->b_visual.vi_mode; |
5902 curbuf->b_visual.vi_mode = i; | |
7 | 5903 # ifdef FEAT_EVAL |
5904 curbuf->b_visual_mode_eval = i; | |
5905 # endif | |
5906 i = curwin->w_curswant; | |
690 | 5907 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
5908 curbuf->b_visual.vi_curswant = i; | |
5909 | |
5910 tpos = curbuf->b_visual.vi_end; | |
5911 curbuf->b_visual.vi_end = curwin->w_cursor; | |
5912 curwin->w_cursor = curbuf->b_visual.vi_start; | |
5913 curbuf->b_visual.vi_start = VIsual; | |
7 | 5914 } |
5915 else | |
5916 { | |
690 | 5917 VIsual_mode = curbuf->b_visual.vi_mode; |
5918 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
5919 tpos = curbuf->b_visual.vi_end; | |
5920 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 5921 } |
5922 | |
5923 VIsual_active = TRUE; | |
5924 VIsual_reselect = TRUE; | |
5925 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5926 // Set Visual to the start and w_cursor to the end of the Visual |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5927 // area. Make sure they are on an existing character. |
7 | 5928 check_cursor(); |
5929 VIsual = curwin->w_cursor; | |
5930 curwin->w_cursor = tpos; | |
5931 check_cursor(); | |
5932 update_topline(); | |
5933 /* | |
5934 * When called from normal "g" command: start Select mode when | |
5935 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
5936 * start Select mode. | |
5937 */ | |
5938 if (cap->arg) | |
5939 VIsual_select = TRUE; | |
5940 else | |
5941 may_start_select('c'); | |
5942 setmouse(); | |
5943 #ifdef FEAT_CLIPBOARD | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5944 // Make sure the clipboard gets updated. Needed because start and |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5945 // end are still the same, and the selection needs to be owned |
7 | 5946 clip_star.vmode = NUL; |
5947 #endif | |
5948 redraw_curbuf_later(INVERTED); | |
5949 showmode(); | |
5950 } | |
5951 break; | |
5952 /* | |
5953 * "gV": Don't reselect the previous Visual area after a Select mode | |
5954 * mapping of menu. | |
5955 */ | |
5956 case 'V': | |
5957 VIsual_reselect = FALSE; | |
5958 break; | |
5959 | |
5960 /* | |
5961 * "gh": start Select mode. | |
5962 * "gH": start Select line mode. | |
5963 * "g^H": start Select block mode. | |
5964 */ | |
5965 case K_BS: | |
5966 cap->nchar = Ctrl_H; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5967 // FALLTHROUGH |
7 | 5968 case 'h': |
5969 case 'H': | |
5970 case Ctrl_H: | |
5971 # ifdef EBCDIC | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5972 // EBCDIC: 'v'-'h' != '^v'-'^h' |
7 | 5973 if (cap->nchar == Ctrl_H) |
5974 cap->cmdchar = Ctrl_V; | |
5975 else | |
5976 # endif | |
5977 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
5978 cap->arg = TRUE; | |
5979 nv_visual(cap); | |
5980 break; | |
3701 | 5981 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5982 // "gn", "gN" visually select next/previous search match |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5983 // "gn" selects next match |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
5984 // "gN" selects previous match |
3701 | 5985 case 'N': |
5986 case 'n': | |
5987 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 5988 clearopbeep(oap); |
3701 | 5989 break; |
7 | 5990 |
5991 /* | |
5992 * "gj" and "gk" two new funny movement keys -- up and down | |
5993 * movement based on *screen* line rather than *file* line. | |
5994 */ | |
5995 case 'j': | |
5996 case K_DOWN: | |
23687
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
5997 // with 'nowrap' it works just like the normal "j" command. |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
5998 if (!curwin->w_p_wrap) |
7 | 5999 { |
6000 oap->motion_type = MLINE; | |
6001 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
6002 } | |
6003 else | |
6004 i = nv_screengo(oap, FORWARD, cap->count1); | |
6005 if (i == FAIL) | |
6006 clearopbeep(oap); | |
6007 break; | |
6008 | |
6009 case 'k': | |
6010 case K_UP: | |
23687
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
6011 // with 'nowrap' it works just like the normal "k" command. |
09ad3f1b9714
patch 8.2.2385: "gj" and "gk" do not work correctly when inside a fold
Bram Moolenaar <Bram@vim.org>
parents:
23648
diff
changeset
|
6012 if (!curwin->w_p_wrap) |
7 | 6013 { |
6014 oap->motion_type = MLINE; | |
6015 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
6016 } | |
6017 else | |
6018 i = nv_screengo(oap, BACKWARD, cap->count1); | |
6019 if (i == FAIL) | |
6020 clearopbeep(oap); | |
6021 break; | |
6022 | |
6023 /* | |
6024 * "gJ": join two lines without inserting a space. | |
6025 */ | |
6026 case 'J': | |
6027 nv_join(cap); | |
6028 break; | |
6029 | |
6030 /* | |
6031 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
6032 * "gm": middle of "g0" and "g$". | |
6033 */ | |
6034 case '^': | |
6035 flag = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6036 // FALLTHROUGH |
7 | 6037 |
6038 case '0': | |
6039 case 'm': | |
6040 case K_HOME: | |
6041 case K_KHOME: | |
6042 oap->motion_type = MCHAR; | |
6043 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
|
6044 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 6045 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6046 int width1 = curwin->w_width - curwin_col_off(); |
7 | 6047 int width2 = width1 + curwin_col_off2(); |
6048 | |
6049 validate_virtcol(); | |
6050 i = 0; | |
6051 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
6052 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
6053 } | |
6054 else | |
6055 i = curwin->w_leftcol; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6056 // Go to the middle of the screen line. When 'number' or |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6057 // 'relativenumber' is on and lines are wrapping the middle can be more |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6058 // to the left. |
7 | 6059 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
|
6060 i += (curwin->w_width - curwin_col_off() |
7 | 6061 + ((curwin->w_p_wrap && i > 0) |
6062 ? curwin_col_off2() : 0)) / 2; | |
6063 coladvance((colnr_T)i); | |
6064 if (flag) | |
6065 { | |
6066 do | |
6067 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
6068 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
|
6069 curwin->w_valid &= ~VALID_WCOL; |
7 | 6070 } |
6071 curwin->w_set_curswant = TRUE; | |
6072 break; | |
6073 | |
18475
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6074 case 'M': |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6075 { |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6076 char_u *ptr = ml_get_curline(); |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6077 |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6078 oap->motion_type = MCHAR; |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6079 oap->inclusive = FALSE; |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6080 if (has_mbyte) |
18477
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18475
diff
changeset
|
6081 i = mb_string2cells(ptr, (int)STRLEN(ptr)); |
18475
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6082 else |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6083 i = (int)STRLEN(ptr); |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6084 if (cap->count0 > 0 && cap->count0 <= 100) |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6085 coladvance((colnr_T)(i * cap->count0 / 100)); |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6086 else |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6087 coladvance((colnr_T)(i / 2)); |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6088 curwin->w_set_curswant = TRUE; |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6089 } |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6090 break; |
709c6b0dc78f
patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
6091 |
7 | 6092 case '_': |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6093 // "g_": to the last non-blank character in the line or <count> lines |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6094 // downward. |
7 | 6095 cap->oap->motion_type = MCHAR; |
6096 cap->oap->inclusive = TRUE; | |
6097 curwin->w_curswant = MAXCOL; | |
6098 if (cursor_down((long)(cap->count1 - 1), | |
6099 cap->oap->op_type == OP_NOP) == FAIL) | |
6100 clearopbeep(cap->oap); | |
6101 else | |
6102 { | |
6103 char_u *ptr = ml_get_curline(); | |
6104 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6105 // In Visual mode we may end up after the line. |
7 | 6106 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) |
6107 --curwin->w_cursor.col; | |
6108 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6109 // Decrease the cursor column until it's on a non-blank. |
7 | 6110 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
|
6111 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 6112 --curwin->w_cursor.col; |
6113 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
6114 adjust_for_sel(cap); |
7 | 6115 } |
6116 break; | |
6117 | |
6118 case '$': | |
6119 case K_END: | |
6120 case K_KEND: | |
6121 { | |
6122 int col_off = curwin_col_off(); | |
6123 | |
6124 oap->motion_type = MCHAR; | |
6125 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
|
6126 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 6127 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6128 curwin->w_curswant = MAXCOL; // so we stay at the end |
7 | 6129 if (cap->count1 == 1) |
6130 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6131 int width1 = curwin->w_width - col_off; |
7 | 6132 int width2 = width1 + curwin_col_off2(); |
6133 | |
6134 validate_virtcol(); | |
6135 i = width1 - 1; | |
6136 if (curwin->w_virtcol >= (colnr_T)width1) | |
6137 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
6138 * width2; | |
6139 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6140 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6141 // Make sure we stick in this column. |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6142 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6143 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
6144 curwin->w_set_curswant = FALSE; |
7 | 6145 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
6146 { | |
6147 /* | |
6148 * Check for landing on a character that got split at | |
6149 * the end of the line. We do not want to advance to | |
6150 * the next screen line. | |
6151 */ | |
6152 if (curwin->w_virtcol > (colnr_T)i) | |
6153 --curwin->w_cursor.col; | |
6154 } | |
6155 } | |
6156 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
6157 clearopbeep(oap); | |
6158 } | |
6159 else | |
6160 { | |
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
|
6161 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
|
6162 // 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
|
6163 (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
|
6164 |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6165 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 6166 coladvance((colnr_T)i); |
40 | 6167 |
24731
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6168 // if the character doesn't fit move one back |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6169 if (curwin->w_cursor.col > 0 |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6170 && (*mb_ptr2cells)(ml_get_cursor()) > 1) |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6171 { |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6172 colnr_T vcol; |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6173 |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6174 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol); |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6175 if (vcol >= curwin->w_leftcol + curwin->w_width - col_off) |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6176 --curwin->w_cursor.col; |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6177 } |
a6a4224902f5
patch 8.2.2904: "g$" causes scroll if half a double width char is visible
Bram Moolenaar <Bram@vim.org>
parents:
24586
diff
changeset
|
6178 |
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
|
6179 // Make sure we stick in this column. |
40 | 6180 validate_virtcol(); |
6181 curwin->w_curswant = curwin->w_virtcol; | |
6182 curwin->w_set_curswant = FALSE; | |
7 | 6183 } |
6184 } | |
6185 break; | |
6186 | |
6187 /* | |
6188 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
6189 */ | |
6190 case '*': | |
6191 case '#': | |
6192 #if POUND != '#' | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6193 case POUND: // pound sign (sometimes equal to '#') |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6194 #endif |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6195 case Ctrl_RSB: // :tag or :tselect for current identifier |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6196 case ']': // :tselect for current identifier |
7 | 6197 nv_ident(cap); |
6198 break; | |
6199 | |
6200 /* | |
6201 * ge and gE: go back to end of word | |
6202 */ | |
6203 case 'e': | |
6204 case 'E': | |
6205 oap->motion_type = MCHAR; | |
6206 curwin->w_set_curswant = TRUE; | |
6207 oap->inclusive = TRUE; | |
6208 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
6209 clearopbeep(oap); | |
6210 break; | |
6211 | |
6212 /* | |
6213 * "g CTRL-G": display info about cursor position | |
6214 */ | |
6215 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
6216 cursor_pos_info(NULL); |
7 | 6217 break; |
6218 | |
6219 /* | |
6220 * "gi": start Insert at the last position. | |
6221 */ | |
6222 case 'i': | |
6223 if (curbuf->b_last_insert.lnum != 0) | |
6224 { | |
6225 curwin->w_cursor = curbuf->b_last_insert; | |
6226 check_cursor_lnum(); | |
6227 i = (int)STRLEN(ml_get_curline()); | |
6228 if (curwin->w_cursor.col > (colnr_T)i) | |
6229 { | |
6230 if (virtual_active()) | |
6231 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
6232 curwin->w_cursor.col = i; | |
6233 } | |
6234 } | |
6235 cap->cmdchar = 'i'; | |
6236 nv_edit(cap); | |
6237 break; | |
6238 | |
6239 /* | |
6240 * "gI": Start insert in column 1. | |
6241 */ | |
6242 case 'I': | |
6243 beginline(0); | |
6244 if (!checkclearopq(oap)) | |
6245 invoke_edit(cap, FALSE, 'g', FALSE); | |
6246 break; | |
6247 | |
6248 #ifdef FEAT_SEARCHPATH | |
6249 /* | |
6250 * "gf": goto file, edit file under cursor | |
6251 * "]f" and "[f": can also be used. | |
6252 */ | |
6253 case 'f': | |
681 | 6254 case 'F': |
7 | 6255 nv_gotofile(cap); |
6256 break; | |
6257 #endif | |
6258 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6259 // "g'm" and "g`m": jump to mark without setting pcmark |
7 | 6260 case '\'': |
6261 cap->arg = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6262 // FALLTHROUGH |
7 | 6263 case '`': |
6264 nv_gomark(cap); | |
6265 break; | |
6266 | |
6267 /* | |
6268 * "gs": Goto sleep. | |
6269 */ | |
6270 case 's': | |
23648
b7d3c79075c5
patch 8.2.2366: when using ":sleep" the cursor is always displayed
Bram Moolenaar <Bram@vim.org>
parents:
23272
diff
changeset
|
6271 do_sleep(cap->count1 * 1000L, FALSE); |
7 | 6272 break; |
6273 | |
6274 /* | |
6275 * "ga": Display the ascii value of the character under the | |
6276 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
6277 */ | |
6278 case 'a': | |
6279 do_ascii(NULL); | |
6280 break; | |
6281 | |
6282 /* | |
6283 * "g8": Display the bytes used for the UTF-8 character under the | |
6284 * cursor. It is displayed in hex. | |
775 | 6285 * "8g8" finds illegal byte sequence. |
7 | 6286 */ |
6287 case '8': | |
775 | 6288 if (cap->count0 == 8) |
6289 utf_find_illegal(); | |
6290 else | |
6291 show_utf8(); | |
7 | 6292 break; |
6293 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6294 // "g<": show scrollback text |
447 | 6295 case '<': |
6296 show_sb_text(); | |
6297 break; | |
6298 | |
7 | 6299 /* |
6300 * "gg": Goto the first line in file. With a count it goes to | |
6301 * that line number like for "G". -- webb | |
6302 */ | |
6303 case 'g': | |
6304 cap->arg = FALSE; | |
6305 nv_goto(cap); | |
6306 break; | |
6307 | |
6308 /* | |
6309 * Two-character operators: | |
6310 * "gq" Format text | |
6311 * "gw" Format text and keep cursor position | |
6312 * "g~" Toggle the case of the text. | |
6313 * "gu" Change text to lower case. | |
6314 * "gU" Change text to upper case. | |
6315 * "g?" rot13 encoding | |
602 | 6316 * "g@" call 'operatorfunc' |
7 | 6317 */ |
6318 case 'q': | |
6319 case 'w': | |
6320 oap->cursor_start = curwin->w_cursor; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6321 // FALLTHROUGH |
7 | 6322 case '~': |
6323 case 'u': | |
6324 case 'U': | |
6325 case '?': | |
602 | 6326 case '@': |
7 | 6327 nv_operator(cap); |
6328 break; | |
6329 | |
6330 /* | |
1188 | 6331 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 6332 * current function |
6333 * "gD": idem, but in the current file. | |
6334 */ | |
6335 case 'd': | |
6336 case 'D': | |
523 | 6337 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 6338 break; |
6339 | |
6340 /* | |
6341 * g<*Mouse> : <C-*mouse> | |
6342 */ | |
6343 case K_MIDDLEMOUSE: | |
6344 case K_MIDDLEDRAG: | |
6345 case K_MIDDLERELEASE: | |
6346 case K_LEFTMOUSE: | |
6347 case K_LEFTDRAG: | |
6348 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
6349 case K_MOUSEMOVE: |
7 | 6350 case K_RIGHTMOUSE: |
6351 case K_RIGHTDRAG: | |
6352 case K_RIGHTRELEASE: | |
6353 case K_X1MOUSE: | |
6354 case K_X1DRAG: | |
6355 case K_X1RELEASE: | |
6356 case K_X2MOUSE: | |
6357 case K_X2DRAG: | |
6358 case K_X2RELEASE: | |
6359 mod_mask = MOD_MASK_CTRL; | |
6360 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
6361 break; | |
6362 | |
6363 case K_IGNORE: | |
6364 break; | |
6365 | |
6366 /* | |
6367 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
6368 */ | |
6369 case 'p': | |
6370 case 'P': | |
6371 nv_put(cap); | |
6372 break; | |
6373 | |
6374 #ifdef FEAT_BYTEOFF | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6375 // "go": goto byte count from start of buffer |
7 | 6376 case 'o': |
6377 goto_byte(cap->count0); | |
6378 break; | |
6379 #endif | |
6380 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6381 // "gQ": improved Ex mode |
7 | 6382 case 'Q': |
633 | 6383 if (text_locked()) |
7 | 6384 { |
6385 clearopbeep(cap->oap); | |
633 | 6386 text_locked_msg(); |
7 | 6387 break; |
6388 } | |
631 | 6389 |
7 | 6390 if (!checkclearopq(oap)) |
6391 do_exmode(TRUE); | |
6392 break; | |
6393 | |
6394 #ifdef FEAT_JUMPLIST | |
6395 case ',': | |
6396 nv_pcmark(cap); | |
6397 break; | |
6398 | |
6399 case ';': | |
6400 cap->count1 = -cap->count1; | |
6401 nv_pcmark(cap); | |
6402 break; | |
6403 #endif | |
6404 | |
667 | 6405 case 't': |
3630 | 6406 if (!checkclearop(oap)) |
6407 goto_tabpage((int)cap->count0); | |
667 | 6408 break; |
682 | 6409 case 'T': |
3630 | 6410 if (!checkclearop(oap)) |
6411 goto_tabpage(-(int)cap->count1); | |
682 | 6412 break; |
667 | 6413 |
21703
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
6414 case TAB: |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
6415 if (!checkclearop(oap) && goto_tabpage_lastused() == FAIL) |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
6416 clearopbeep(oap); |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
6417 break; |
22583b9d4efd
patch 8.2.1401: cannot jump to the last used tabpage
Bram Moolenaar <Bram@vim.org>
parents:
21415
diff
changeset
|
6418 |
750 | 6419 case '+': |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6420 case '-': // "g+" and "g-": undo or redo along the timeline |
750 | 6421 if (!checkclearopq(oap)) |
771 | 6422 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
|
6423 FALSE, FALSE, FALSE); |
750 | 6424 break; |
6425 | |
7 | 6426 default: |
6427 clearopbeep(oap); | |
6428 break; | |
6429 } | |
6430 } | |
6431 | |
6432 /* | |
6433 * Handle "o" and "O" commands. | |
6434 */ | |
6435 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6436 n_opencmd(cmdarg_T *cap) |
7 | 6437 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6438 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6439 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6440 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6441 |
7 | 6442 if (!checkclearopq(cap->oap)) |
6443 { | |
6444 #ifdef FEAT_FOLDING | |
6445 if (cap->cmdchar == 'O') | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6446 // Open above the first line of a folded sequence of lines |
7 | 6447 (void)hasFolding(curwin->w_cursor.lnum, |
6448 &curwin->w_cursor.lnum, NULL); | |
6449 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6450 // Open below the last line of a folded sequence of lines |
7 | 6451 (void)hasFolding(curwin->w_cursor.lnum, |
6452 NULL, &curwin->w_cursor.lnum); | |
6453 #endif | |
6454 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
6455 (cap->cmdchar == 'O' ? 1 : 0)), | |
6456 (linenr_T)(curwin->w_cursor.lnum + | |
6457 (cap->cmdchar == 'o' ? 1 : 0)) | |
6458 ) == OK | |
6459 && 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
|
6460 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
|
6461 0) == OK) |
7 | 6462 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6463 #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
|
6464 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
|
6465 redrawWinline(curwin, oldline); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6466 #endif |
6834 | 6467 #ifdef FEAT_SYN_HL |
6821 | 6468 if (curwin->w_p_cul) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6469 // force redraw of cursorline |
6821 | 6470 curwin->w_valid &= ~VALID_CROW; |
6834 | 6471 #endif |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6472 // When '#' is in 'cpoptions' ignore the count. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
6473 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
|
6474 cap->count1 = 1; |
7 | 6475 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
6476 } | |
6477 } | |
6478 } | |
6479 | |
6480 /* | |
6481 * "." command: redo last change. | |
6482 */ | |
6483 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6484 nv_dot(cmdarg_T *cap) |
7 | 6485 { |
6486 if (!checkclearopq(cap->oap)) | |
6487 { | |
6488 /* | |
6489 * If "restart_edit" is TRUE, the last but one command is repeated | |
6490 * instead of the last command (inserting text). This is used for | |
6491 * CTRL-O <.> in insert mode. | |
6492 */ | |
6493 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
6494 clearopbeep(cap->oap); | |
6495 } | |
6496 } | |
6497 | |
6498 /* | |
6499 * CTRL-R: undo undo | |
6500 */ | |
6501 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6502 nv_redo(cmdarg_T *cap) |
7 | 6503 { |
6504 if (!checkclearopq(cap->oap)) | |
6505 { | |
6506 u_redo((int)cap->count1); | |
6507 curwin->w_set_curswant = TRUE; | |
6508 } | |
6509 } | |
6510 | |
6511 /* | |
6512 * Handle "U" command. | |
6513 */ | |
6514 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6515 nv_Undo(cmdarg_T *cap) |
7 | 6516 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6517 // In Visual mode and typing "gUU" triggers an operator |
5735 | 6518 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 6519 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6520 // translate "gUU" to "gUgU" |
7 | 6521 cap->cmdchar = 'g'; |
6522 cap->nchar = 'U'; | |
6523 nv_operator(cap); | |
6524 } | |
6525 else if (!checkclearopq(cap->oap)) | |
6526 { | |
6527 u_undoline(); | |
6528 curwin->w_set_curswant = TRUE; | |
6529 } | |
6530 } | |
6531 | |
6532 /* | |
6533 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
6534 * single character. | |
6535 */ | |
6536 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6537 nv_tilde(cmdarg_T *cap) |
7 | 6538 { |
5735 | 6539 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
|
6540 { |
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
|
6541 #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
|
6542 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
|
6543 { |
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
|
6544 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
|
6545 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
|
6546 } |
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
|
6547 #endif |
7 | 6548 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
|
6549 } |
7 | 6550 else |
6551 nv_operator(cap); | |
6552 } | |
6553 | |
6554 /* | |
6555 * Handle an operator command. | |
6556 * The actual work is done by do_pending_operator(). | |
6557 */ | |
6558 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6559 nv_operator(cmdarg_T *cap) |
7 | 6560 { |
6561 int op_type; | |
6562 | |
6563 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
|
6564 #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
|
6565 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
|
6566 { |
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
|
6567 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
|
6568 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
|
6569 } |
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
|
6570 #endif |
7 | 6571 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6572 if (op_type == cap->oap->op_type) // double operator works on lines |
7 | 6573 nv_lineop(cap); |
6574 else if (!checkclearop(cap->oap)) | |
6575 { | |
6576 cap->oap->start = curwin->w_cursor; | |
6577 cap->oap->op_type = op_type; | |
1490 | 6578 #ifdef FEAT_EVAL |
6579 set_op_var(op_type); | |
6580 #endif | |
6581 } | |
6582 } | |
6583 | |
6584 #ifdef FEAT_EVAL | |
6585 /* | |
6586 * Set v:operator to the characters for "optype". | |
6587 */ | |
6588 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6589 set_op_var(int optype) |
1490 | 6590 { |
6591 char_u opchars[3]; | |
6592 | |
6593 if (optype == OP_NOP) | |
6594 set_vim_var_string(VV_OP, NULL, 0); | |
6595 else | |
6596 { | |
6597 opchars[0] = get_op_char(optype); | |
6598 opchars[1] = get_extra_op_char(optype); | |
6599 opchars[2] = NUL; | |
6600 set_vim_var_string(VV_OP, opchars, -1); | |
6601 } | |
6602 } | |
6603 #endif | |
7 | 6604 |
6605 /* | |
6606 * Handle linewise operator "dd", "yy", etc. | |
6607 * | |
6608 * "_" is is a strange motion command that helps make operators more logical. | |
6609 * It is actually implemented, but not documented in the real Vi. This motion | |
6610 * command actually refers to "the current line". Commands like "dd" and "yy" | |
6611 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
6612 * "d3_" works to delete 3 lines. | |
6613 */ | |
6614 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6615 nv_lineop(cmdarg_T *cap) |
7 | 6616 { |
6617 cap->oap->motion_type = MLINE; | |
6618 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
6619 clearopbeep(cap->oap); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6620 else if ( (cap->oap->op_type == OP_DELETE // only with linewise motions |
4011 | 6621 && cap->oap->motion_force != 'v' |
6622 && cap->oap->motion_force != Ctrl_V) | |
7 | 6623 || cap->oap->op_type == OP_LSHIFT |
6624 || cap->oap->op_type == OP_RSHIFT) | |
6625 beginline(BL_SOL | BL_FIX); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6626 else if (cap->oap->op_type != OP_YANK) // 'Y' does not move cursor |
7 | 6627 beginline(BL_WHITE | BL_FIX); |
6628 } | |
6629 | |
6630 /* | |
6631 * <Home> command. | |
6632 */ | |
6633 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6634 nv_home(cmdarg_T *cap) |
7 | 6635 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6636 // CTRL-HOME is like "gg" |
180 | 6637 if (mod_mask & MOD_MASK_CTRL) |
6638 nv_goto(cap); | |
6639 else | |
6640 { | |
6641 cap->count0 = 1; | |
6642 nv_pipe(cap); | |
6643 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6644 ins_at_eol = FALSE; // Don't move cursor past eol (only necessary in a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6645 // one-character line). |
7 | 6646 } |
6647 | |
6648 /* | |
6649 * "|" command. | |
6650 */ | |
6651 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6652 nv_pipe(cmdarg_T *cap) |
7 | 6653 { |
6654 cap->oap->motion_type = MCHAR; | |
6655 cap->oap->inclusive = FALSE; | |
6656 beginline(0); | |
6657 if (cap->count0 > 0) | |
6658 { | |
6659 coladvance((colnr_T)(cap->count0 - 1)); | |
6660 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
6661 } | |
6662 else | |
6663 curwin->w_curswant = 0; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6664 // keep curswant at the column where we wanted to go, not where |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6665 // we ended; differs if line is too short |
7 | 6666 curwin->w_set_curswant = FALSE; |
6667 } | |
6668 | |
6669 /* | |
6670 * Handle back-word command "b" and "B". | |
6671 * cap->arg is 1 for "B" | |
6672 */ | |
6673 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6674 nv_bck_word(cmdarg_T *cap) |
7 | 6675 { |
6676 cap->oap->motion_type = MCHAR; | |
6677 cap->oap->inclusive = FALSE; | |
6678 curwin->w_set_curswant = TRUE; | |
6679 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
6680 clearopbeep(cap->oap); | |
6681 #ifdef FEAT_FOLDING | |
6682 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6683 foldOpenCursor(); | |
6684 #endif | |
6685 } | |
6686 | |
6687 /* | |
6688 * Handle word motion commands "e", "E", "w" and "W". | |
6689 * cap->arg is TRUE for "E" and "W". | |
6690 */ | |
6691 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6692 nv_wordcmd(cmdarg_T *cap) |
7 | 6693 { |
6694 int n; | |
6695 int word_end; | |
6696 int flag = FALSE; | |
1573 | 6697 pos_T startpos = curwin->w_cursor; |
7 | 6698 |
6699 /* | |
6700 * Set inclusive for the "E" and "e" command. | |
6701 */ | |
6702 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
6703 word_end = TRUE; | |
6704 else | |
6705 word_end = FALSE; | |
6706 cap->oap->inclusive = word_end; | |
6707 | |
6708 /* | |
6709 * "cw" and "cW" are a special case. | |
6710 */ | |
6711 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
6712 { | |
6713 n = gchar_cursor(); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6714 if (n != NUL) // not an empty line |
7 | 6715 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
6716 if (VIM_ISWHITE(n)) |
7 | 6717 { |
6718 /* | |
6719 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
6720 * changes one character, not all blanks until the start of | |
6721 * the next word. Only do this when the 'w' flag is included | |
6722 * in 'cpoptions'. | |
6723 */ | |
6724 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
6725 { | |
6726 cap->oap->inclusive = TRUE; | |
6727 cap->oap->motion_type = MCHAR; | |
6728 return; | |
6729 } | |
6730 } | |
6731 else | |
6732 { | |
6733 /* | |
6734 * This is a little strange. To match what the real Vi does, | |
6735 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
6736 * that we are not on a space or a TAB. This seems impolite | |
6737 * at first, but it's really more what we mean when we say | |
6738 * 'cw'. | |
6739 * Another strangeness: When standing on the end of a word | |
4352 | 6740 * "ce" will change until the end of the next word, but "cw" |
7 | 6741 * will change only one character! This is done by setting |
6742 * flag. | |
6743 */ | |
6744 cap->oap->inclusive = TRUE; | |
6745 word_end = TRUE; | |
6746 flag = TRUE; | |
6747 } | |
6748 } | |
6749 } | |
6750 | |
6751 cap->oap->motion_type = MCHAR; | |
6752 curwin->w_set_curswant = TRUE; | |
6753 if (word_end) | |
6754 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
6755 else | |
6756 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
6757 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6758 // Don't leave the cursor on the NUL past the end of line. Unless we |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6759 // 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
|
6760 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 6761 adjust_cursor(cap->oap); |
7 | 6762 |
6763 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
6764 clearopbeep(cap->oap); | |
6765 else | |
6766 { | |
6767 adjust_for_sel(cap); | |
6768 #ifdef FEAT_FOLDING | |
6769 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6770 foldOpenCursor(); | |
6771 #endif | |
6772 } | |
6773 } | |
6774 | |
6775 /* | |
1505 | 6776 * Used after a movement command: If the cursor ends up on the NUL after the |
6777 * end of the line, may move it back to the last character and make the motion | |
6778 * inclusive. | |
6779 */ | |
6780 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6781 adjust_cursor(oparg_T *oap) |
1505 | 6782 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6783 // The cursor cannot remain on the NUL when: |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6784 // - the column is > 0 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6785 // - not in Visual mode or 'selection' is "o" |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6786 // - 'virtualedit' is not "all" and not "onemore". |
1505 | 6787 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL |
6788 && (!VIsual_active || *p_sel == 'o') | |
25380
ac88cd21ae88
patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents:
25074
diff
changeset
|
6789 && !virtual_active() && (get_ve_flags() & VE_ONEMORE) == 0) |
1505 | 6790 { |
6791 --curwin->w_cursor.col; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6792 // prevent cursor from moving on the trail byte |
1505 | 6793 if (has_mbyte) |
6794 mb_adjust_cursor(); | |
6795 oap->inclusive = TRUE; | |
6796 } | |
6797 } | |
6798 | |
6799 /* | |
7 | 6800 * "0" and "^" commands. |
6801 * cap->arg is the argument for beginline(). | |
6802 */ | |
6803 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6804 nv_beginline(cmdarg_T *cap) |
7 | 6805 { |
6806 cap->oap->motion_type = MCHAR; | |
6807 cap->oap->inclusive = FALSE; | |
6808 beginline(cap->arg); | |
6809 #ifdef FEAT_FOLDING | |
6810 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6811 foldOpenCursor(); | |
6812 #endif | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6813 ins_at_eol = FALSE; // Don't move cursor past eol (only necessary in a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6814 // one-character line). |
7 | 6815 } |
6816 | |
6817 /* | |
6818 * In exclusive Visual mode, may include the last character. | |
6819 */ | |
6820 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6821 adjust_for_sel(cmdarg_T *cap) |
7 | 6822 { |
6823 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
|
6824 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 6825 { |
6826 if (has_mbyte) | |
6827 inc_cursor(); | |
6828 else | |
6829 ++curwin->w_cursor.col; | |
6830 cap->oap->inclusive = FALSE; | |
6831 } | |
6832 } | |
6833 | |
6834 /* | |
6835 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
6836 * Should check VIsual_mode before calling this. | |
6837 * Returns TRUE when backed up to the previous line. | |
6838 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
6839 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6840 unadjust_for_sel(void) |
7 | 6841 { |
6842 pos_T *pp; | |
6843 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6844 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
|
6845 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6846 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 6847 pp = &curwin->w_cursor; |
6848 else | |
6849 pp = &VIsual; | |
6850 if (pp->coladd > 0) | |
6851 --pp->coladd; | |
6852 else | |
6853 if (pp->col > 0) | |
6854 { | |
6855 --pp->col; | |
2933 | 6856 mb_adjustpos(curbuf, pp); |
7 | 6857 } |
6858 else if (pp->lnum > 1) | |
6859 { | |
6860 --pp->lnum; | |
6861 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
6862 return TRUE; | |
6863 } | |
6864 } | |
6865 return FALSE; | |
6866 } | |
6867 | |
6868 /* | |
6869 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
6870 */ | |
6871 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6872 nv_select(cmdarg_T *cap) |
7 | 6873 { |
6874 if (VIsual_active) | |
6875 VIsual_select = TRUE; | |
6876 else if (VIsual_reselect) | |
6877 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6878 cap->nchar = 'v'; // fake "gv" command |
7 | 6879 cap->arg = TRUE; |
6880 nv_g_cmd(cap); | |
6881 } | |
6882 } | |
6883 | |
6884 | |
6885 /* | |
6886 * "G", "gg", CTRL-END, CTRL-HOME. | |
6887 * cap->arg is TRUE for "G". | |
6888 */ | |
6889 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6890 nv_goto(cmdarg_T *cap) |
7 | 6891 { |
6892 linenr_T lnum; | |
6893 | |
6894 if (cap->arg) | |
6895 lnum = curbuf->b_ml.ml_line_count; | |
6896 else | |
6897 lnum = 1L; | |
6898 cap->oap->motion_type = MLINE; | |
6899 setpcmark(); | |
6900 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6901 // When a count is given, use it instead of the default lnum |
7 | 6902 if (cap->count0 != 0) |
6903 lnum = cap->count0; | |
6904 if (lnum < 1L) | |
6905 lnum = 1L; | |
6906 else if (lnum > curbuf->b_ml.ml_line_count) | |
6907 lnum = curbuf->b_ml.ml_line_count; | |
6908 curwin->w_cursor.lnum = lnum; | |
6909 beginline(BL_SOL | BL_FIX); | |
6910 #ifdef FEAT_FOLDING | |
6911 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6912 foldOpenCursor(); | |
6913 #endif | |
6914 } | |
6915 | |
6916 /* | |
6917 * CTRL-\ in Normal mode. | |
6918 */ | |
6919 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6920 nv_normal(cmdarg_T *cap) |
7 | 6921 { |
6922 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
6923 { | |
6924 clearop(cap->oap); | |
643 | 6925 if (restart_edit != 0 && mode_displayed) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6926 clear_cmdline = TRUE; // unshow mode later |
7 | 6927 restart_edit = 0; |
6928 #ifdef FEAT_CMDWIN | |
6929 if (cmdwin_type != 0) | |
6930 cmdwin_result = Ctrl_C; | |
6931 #endif | |
6932 if (VIsual_active) | |
6933 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6934 end_visual_mode(); // stop Visual |
7 | 6935 redraw_curbuf_later(INVERTED); |
6936 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6937 // CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. |
7 | 6938 if (cap->nchar == Ctrl_G && p_im) |
6939 restart_edit = 'a'; | |
6940 } | |
6941 else | |
6942 clearopbeep(cap->oap); | |
6943 } | |
6944 | |
6945 /* | |
6946 * ESC in Normal mode: beep, but don't flush buffers. | |
6947 * Don't even beep if we are canceling a command. | |
6948 */ | |
6949 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6950 nv_esc(cmdarg_T *cap) |
7 | 6951 { |
6952 int no_reason; | |
6953 | |
6954 no_reason = (cap->oap->op_type == OP_NOP | |
6955 && cap->opcount == 0 | |
6956 && cap->count0 == 0 | |
6957 && cap->oap->regname == 0 | |
6958 && !p_im); | |
6959 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6960 if (cap->arg) // TRUE for CTRL-C |
7 | 6961 { |
6962 if (restart_edit == 0 | |
6963 #ifdef FEAT_CMDWIN | |
6964 && cmdwin_type == 0 | |
6965 #endif | |
6966 && !VIsual_active | |
6967 && 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
|
6968 { |
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
|
6969 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
|
6970 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
|
6971 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
|
6972 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
|
6973 } |
7 | 6974 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6975 // Don't reset "restart_edit" when 'insertmode' is set, it won't be |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6976 // set again below when halfway a mapping. |
7 | 6977 if (!p_im) |
6978 restart_edit = 0; | |
6979 #ifdef FEAT_CMDWIN | |
6980 if (cmdwin_type != 0) | |
6981 { | |
6982 cmdwin_result = K_IGNORE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
6983 got_int = FALSE; // don't stop executing autocommands et al. |
7 | 6984 return; |
6985 } | |
6986 #endif | |
6987 } | |
24012
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6988 #ifdef FEAT_CMDWIN |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6989 else if (cmdwin_type != 0 && ex_normal_busy) |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6990 { |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6991 // When :normal runs out of characters while in the command line window |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6992 // vgetorpeek() will return ESC. Exit the cmdline window to break the |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6993 // loop. |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6994 cmdwin_result = K_IGNORE; |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6995 return; |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6996 } |
59b59a5f75d4
patch 8.2.2548: May get stuck in the cmdline window using :normal
Bram Moolenaar <Bram@vim.org>
parents:
24010
diff
changeset
|
6997 #endif |
7 | 6998 |
6999 if (VIsual_active) | |
7000 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7001 end_visual_mode(); // stop Visual |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7002 check_cursor_col(); // make sure cursor is not beyond EOL |
7 | 7003 curwin->w_set_curswant = TRUE; |
7004 redraw_curbuf_later(INVERTED); | |
7005 } | |
5735 | 7006 else if (no_reason) |
6949 | 7007 vim_beep(BO_ESC); |
7 | 7008 clearop(cap->oap); |
7009 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7010 // A CTRL-C is often used at the start of a menu. When 'insertmode' is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7011 // 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
|
7012 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 7013 restart_edit = 'a'; |
7014 } | |
7015 | |
7016 /* | |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7017 * 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
|
7018 */ |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7019 void |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7020 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
|
7021 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7022 curwin->w_set_curswant = TRUE; |
25380
ac88cd21ae88
patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents:
25074
diff
changeset
|
7023 if (get_ve_flags() == VE_ALL) |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7024 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7025 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
|
7026 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7027 // Pretend Insert mode here to allow the cursor on the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7028 // character past the end of 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
|
7029 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
|
7030 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
|
7031 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
|
7032 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7033 else |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7034 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
|
7035 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7036 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
7037 /* |
7 | 7038 * 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
|
7039 * Also handle K_PS, start bracketed paste. |
7 | 7040 */ |
7041 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7042 nv_edit(cmdarg_T *cap) |
7 | 7043 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7044 // <Insert> is equal to "i" |
7 | 7045 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) |
7046 cap->cmdchar = 'i'; | |
7047 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7048 // in Visual mode "A" and "I" are an operator |
7 | 7049 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
|
7050 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7051 #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
|
7052 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
|
7053 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7054 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
|
7055 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
|
7056 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
|
7057 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7058 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
7059 #endif |
7 | 7060 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
|
7061 } |
7 | 7062 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7063 // in Visual mode and after an operator "a" and "i" are for text objects |
5735 | 7064 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
7065 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 7066 { |
7067 #ifdef FEAT_TEXTOBJ | |
7068 nv_object(cap); | |
7069 #else | |
7070 clearopbeep(cap->oap); | |
7071 #endif | |
7072 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7073 #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
|
7074 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
|
7075 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7076 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
|
7077 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
|
7078 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7079 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
7080 #endif |
7 | 7081 else if (!curbuf->b_p_ma && !p_im) |
7082 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7083 // Only give this error when 'insertmode' is off. |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24866
diff
changeset
|
7084 emsg(_(e_cannot_make_changes_modifiable_is_off)); |
7 | 7085 clearop(cap->oap); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7086 if (cap->cmdchar == K_PS) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7087 // drop the pasted text |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7088 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 7089 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7090 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
|
7091 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7092 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
|
7093 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
|
7094 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7095 // In Visual mode the selected text is deleted. |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7096 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
|
7097 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7098 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
|
7099 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
|
7100 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7101 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7102 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
|
7103 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
|
7104 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
|
7105 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
|
7106 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
|
7107 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
|
7108 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7109 // When the last char in the line was deleted then append. Detect this |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7110 // 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
|
7111 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
|
7112 && 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
|
7113 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7114 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7115 // Insert to replace the deleted text with the pasted text. |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7116 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
|
7117 } |
7 | 7118 else if (!checkclearopq(cap->oap)) |
7119 { | |
7120 switch (cap->cmdchar) | |
7121 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7122 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
|
7123 set_cursor_for_append_to_line(); |
7 | 7124 break; |
7125 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7126 case 'I': // "I"nsert before the first non-blank |
164 | 7127 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
7128 beginline(BL_WHITE); | |
7129 else | |
7130 beginline(BL_WHITE|BL_FIX); | |
7 | 7131 break; |
7132 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
7133 case K_PS: |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7134 // Bracketed paste works like "a"ppend, unless the cursor is in |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7135 // 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
|
7136 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
|
7137 break; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7138 // FALLTHROUGH |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7139 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7140 case 'a': // "a"ppend is like "i"nsert on the next character. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7141 // increment coladd when in virtual space, increment the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7142 // column otherwise, also to append after an unprintable char |
7 | 7143 if (virtual_active() |
7144 && (curwin->w_cursor.coladd > 0 | |
7145 || *ml_get_cursor() == NUL | |
7146 || *ml_get_cursor() == TAB)) | |
7147 curwin->w_cursor.coladd++; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7148 else if (*ml_get_cursor() != NUL) |
7 | 7149 inc_cursor(); |
7150 break; | |
7151 } | |
7152 | |
7153 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
7154 { | |
7155 int save_State = State; | |
7156 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7157 // Pretend Insert mode here to allow the cursor on the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7158 // character past the end of the line |
7 | 7159 State = INSERT; |
7160 coladvance(getviscol()); | |
7161 State = save_State; | |
7162 } | |
7163 | |
7164 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
7165 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7166 else if (cap->cmdchar == K_PS) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7167 // drop the pasted text |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
7168 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 7169 } |
7170 | |
7171 /* | |
7172 * Invoke edit() and take care of "restart_edit" and the return value. | |
7173 */ | |
7174 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7175 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7176 cmdarg_T *cap, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7177 int repl, // "r" or "gr" command |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7178 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7179 int startln) |
7 | 7180 { |
7181 int restart_edit_save = 0; | |
7182 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7183 // Complicated: When the user types "a<C-O>a" we don't want to do Insert |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7184 // mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7185 // it. |
7 | 7186 if (repl || !stuff_empty()) |
7187 restart_edit_save = restart_edit; | |
7188 else | |
7189 restart_edit_save = 0; | |
7190 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7191 // Always reset "restart_edit", this is not a restarted edit. |
7 | 7192 restart_edit = 0; |
7193 | |
7194 if (edit(cmd, startln, cap->count1)) | |
7195 cap->retval |= CA_COMMAND_BUSY; | |
7196 | |
7197 if (restart_edit == 0) | |
7198 restart_edit = restart_edit_save; | |
7199 } | |
7200 | |
7201 #ifdef FEAT_TEXTOBJ | |
7202 /* | |
7203 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
7204 */ | |
7205 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7206 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7207 cmdarg_T *cap) |
7 | 7208 { |
7209 int flag; | |
7210 int include; | |
7211 char_u *mps_save; | |
7212 | |
7213 if (cap->cmdchar == 'i') | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7214 include = FALSE; // "ix" = inner object: exclude white space |
7 | 7215 else |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7216 include = TRUE; // "ax" = an object: include white space |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7217 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7218 // Make sure (), [], {} and <> are in 'matchpairs' |
7 | 7219 mps_save = curbuf->b_p_mps; |
7220 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
7221 | |
7222 switch (cap->nchar) | |
7223 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7224 case 'w': // "aw" = a word |
7 | 7225 flag = current_word(cap->oap, cap->count1, include, FALSE); |
7226 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7227 case 'W': // "aW" = a WORD |
7 | 7228 flag = current_word(cap->oap, cap->count1, include, TRUE); |
7229 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7230 case 'b': // "ab" = a braces block |
7 | 7231 case '(': |
7232 case ')': | |
7233 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
7234 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7235 case 'B': // "aB" = a Brackets block |
7 | 7236 case '{': |
7237 case '}': | |
7238 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
7239 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7240 case '[': // "a[" = a [] block |
7 | 7241 case ']': |
7242 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
7243 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7244 case '<': // "a<" = a <> block |
7 | 7245 case '>': |
7246 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
7247 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7248 case 't': // "at" = a tag block (xml and html) |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7249 // Do not adjust oap->end in do_pending_operator() |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7250 // otherwise there are different results for 'dit' |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7251 // (note leading whitespace in last line): |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7252 // 1) <b> 2) <b> |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7253 // foobar foobar |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7254 // </b> </b> |
6661 | 7255 cap->retval |= CA_NO_ADJ_OP_END; |
420 | 7256 flag = current_tagblock(cap->oap, cap->count1, include); |
7257 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7258 case 'p': // "ap" = a paragraph |
7 | 7259 flag = current_par(cap->oap, cap->count1, include, 'p'); |
7260 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7261 case 's': // "as" = a sentence |
7 | 7262 flag = current_sent(cap->oap, cap->count1, include); |
7263 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7264 case '"': // "a"" = a double quoted string |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7265 case '\'': // "a'" = a single quoted string |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7266 case '`': // "a`" = a backtick quoted string |
12 | 7267 flag = current_quote(cap->oap, cap->count1, include, |
7268 cap->nchar); | |
7269 break; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7270 #if 0 // TODO |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7271 case 'S': // "aS" = a section |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7272 case 'f': // "af" = a filename |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7273 case 'u': // "au" = a URL |
7 | 7274 #endif |
7275 default: | |
7276 flag = FAIL; | |
7277 break; | |
7278 } | |
7279 | |
7280 curbuf->b_p_mps = mps_save; | |
7281 if (flag == FAIL) | |
7282 clearopbeep(cap->oap); | |
7283 adjust_cursor_col(); | |
7284 curwin->w_set_curswant = TRUE; | |
7285 } | |
7286 #endif | |
7287 | |
7288 /* | |
7289 * "q" command: Start/stop recording. | |
7290 * "q:", "q/", "q?": edit command-line in command-line window. | |
7291 */ | |
7292 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7293 nv_record(cmdarg_T *cap) |
7 | 7294 { |
7295 if (cap->oap->op_type == OP_FORMAT) | |
7296 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7297 // "gqq" is the same as "gqgq": format line |
7 | 7298 cap->cmdchar = 'g'; |
7299 cap->nchar = 'q'; | |
7300 nv_operator(cap); | |
7301 } | |
7302 else if (!checkclearop(cap->oap)) | |
7303 { | |
7304 #ifdef FEAT_CMDWIN | |
7305 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
7306 { | |
7307 stuffcharReadbuff(cap->nchar); | |
7308 stuffcharReadbuff(K_CMDWIN); | |
7309 } | |
7310 else | |
7311 #endif | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7312 // (stop) recording into a named register, unless executing a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7313 // 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
|
7314 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 7315 clearopbeep(cap->oap); |
7316 } | |
7317 } | |
7318 | |
7319 /* | |
7320 * Handle the "@r" command. | |
7321 */ | |
7322 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7323 nv_at(cmdarg_T *cap) |
7 | 7324 { |
7325 if (checkclearop(cap->oap)) | |
7326 return; | |
7327 #ifdef FEAT_EVAL | |
7328 if (cap->nchar == '=') | |
7329 { | |
7330 if (get_expr_register() == NUL) | |
7331 return; | |
7332 } | |
7333 #endif | |
7334 while (cap->count1-- && !got_int) | |
7335 { | |
1034 | 7336 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 7337 { |
7338 clearopbeep(cap->oap); | |
7339 break; | |
7340 } | |
7341 line_breakcheck(); | |
7342 } | |
7343 } | |
7344 | |
7345 /* | |
7346 * Handle the CTRL-U and CTRL-D commands. | |
7347 */ | |
7348 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7349 nv_halfpage(cmdarg_T *cap) |
7 | 7350 { |
7351 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
7352 || (cap->cmdchar == Ctrl_D | |
7353 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
7354 clearopbeep(cap->oap); | |
7355 else if (!checkclearop(cap->oap)) | |
7356 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
7357 } | |
7358 | |
7359 /* | |
7360 * Handle "J" or "gJ" command. | |
7361 */ | |
7362 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7363 nv_join(cmdarg_T *cap) |
7 | 7364 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7365 if (VIsual_active) // join the visual lines |
7 | 7366 nv_operator(cap); |
5735 | 7367 else if (!checkclearop(cap->oap)) |
7 | 7368 { |
7369 if (cap->count0 <= 1) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7370 cap->count0 = 2; // default for join is two lines! |
7 | 7371 if (curwin->w_cursor.lnum + cap->count0 - 1 > |
7372 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
|
7373 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7374 // can't join when on the last line |
8445
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7375 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7376 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7377 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7378 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7379 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7380 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
|
7381 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7382 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7383 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7384 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
|
7385 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
|
7386 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 7387 } |
7388 } | |
7389 | |
7390 /* | |
7391 * "P", "gP", "p" and "gp" commands. | |
7392 */ | |
7393 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7394 nv_put(cmdarg_T *cap) |
7 | 7395 { |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7396 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
|
7397 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7398 |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7399 /* |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7400 * "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
|
7401 * "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
|
7402 */ |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7403 static void |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7404 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
|
7405 { |
7 | 7406 int regname = 0; |
7407 void *reg1 = NULL, *reg2 = NULL; | |
84 | 7408 int empty = FALSE; |
236 | 7409 int was_visual = FALSE; |
7 | 7410 int dir; |
7411 int flags = 0; | |
7412 | |
7413 if (cap->oap->op_type != OP_NOP) | |
7414 { | |
7415 #ifdef FEAT_DIFF | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7416 // "dp" is ":diffput" |
7 | 7417 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') |
7418 { | |
7419 clearop(cap->oap); | |
6314 | 7420 nv_diffgetput(TRUE, cap->opcount); |
7 | 7421 } |
7422 else | |
7423 #endif | |
7424 clearopbeep(cap->oap); | |
7425 } | |
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
|
7426 #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
|
7427 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
|
7428 { |
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
|
7429 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
|
7430 } |
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
|
7431 #endif |
7 | 7432 else |
7433 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7434 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
|
7435 { |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7436 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
|
7437 ? FORWARD : BACKWARD; |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7438 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
|
7439 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7440 else |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
7441 dir = (cap->cmdchar == 'P' |
24752
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
7442 || ((cap->cmdchar == 'g' || cap->cmdchar == 'z') |
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
7443 && cap->nchar == 'P')) ? BACKWARD : FORWARD; |
7 | 7444 prep_redo_cmd(cap); |
7445 if (cap->cmdchar == 'g') | |
7446 flags |= PUT_CURSEND; | |
24752
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
7447 else if (cap->cmdchar == 'z') |
1ce39e257f1b
patch 8.2.2914: cannot paste a block without adding padding
Bram Moolenaar <Bram@vim.org>
parents:
24731
diff
changeset
|
7448 flags |= PUT_BLOCK_INNER; |
7 | 7449 |
7450 if (VIsual_active) | |
7451 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7452 // Putting in Visual mode: The put text replaces the selected |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7453 // text. First delete the selected text, then put the new text. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7454 // Need to save and restore the registers that the delete |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7455 // overwrites if the old contents is being put. |
236 | 7456 was_visual = TRUE; |
7 | 7457 regname = cap->oap->regname; |
5735 | 7458 #ifdef FEAT_CLIPBOARD |
7 | 7459 adjust_clip_reg(®name); |
5735 | 7460 #endif |
5682 | 7461 if (regname == 0 || regname == '"' |
4013 | 7462 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 7463 #ifdef FEAT_CLIPBOARD |
7 | 7464 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 7465 #endif |
7 | 7466 |
7467 ) | |
7468 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7469 // The delete is going to overwrite the register we want to |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7470 // put, save it first. |
7 | 7471 reg1 = get_register(regname, TRUE); |
7472 } | |
7473 | |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
7474 // Now delete the selected text. Avoid messages here. |
7 | 7475 cap->cmdchar = 'd'; |
7476 cap->nchar = NUL; | |
7477 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
|
7478 ++msg_silent; |
7 | 7479 nv_operator(cap); |
7480 do_pending_operator(cap, 0, FALSE); | |
84 | 7481 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
|
7482 --msg_silent; |
7 | 7483 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7484 // delete PUT_LINE_BACKWARD; |
7 | 7485 cap->oap->regname = regname; |
7486 | |
7487 if (reg1 != NULL) | |
7488 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7489 // Delete probably changed the register we want to put, save |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7490 // it first. Then put back what was there before the delete. |
7 | 7491 reg2 = get_register(regname, FALSE); |
7492 put_register(regname, reg1); | |
7493 } | |
7494 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7495 // When deleted a linewise Visual area, put the register as |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7496 // lines to avoid it joined with the next line. When deletion was |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7497 // characterwise, split a line when putting lines. |
7 | 7498 if (VIsual_mode == 'V') |
7499 flags |= PUT_LINE; | |
7500 else if (VIsual_mode == 'v') | |
7501 flags |= PUT_LINE_SPLIT; | |
7502 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
7503 flags |= PUT_LINE_FORWARD; | |
7504 dir = BACKWARD; | |
7505 if ((VIsual_mode != 'V' | |
7506 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
7507 || (VIsual_mode == 'V' | |
7508 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7509 // cursor is at the end of the line or end of file, put |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7510 // forward. |
7 | 7511 dir = FORWARD; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7512 // May have been reset in do_put(). |
5365 | 7513 VIsual_active = TRUE; |
7 | 7514 } |
22176
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22091
diff
changeset
|
7515 do_put(cap->oap->regname, NULL, dir, cap->count1, flags); |
7 | 7516 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7517 // If a register was saved, put it back now. |
7 | 7518 if (reg2 != NULL) |
7519 put_register(regname, reg2); | |
236 | 7520 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7521 // What to reselect with "gv"? Selecting the just put text seems to |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7522 // be the most useful, since the original text was removed. |
236 | 7523 if (was_visual) |
7524 { | |
690 | 7525 curbuf->b_visual.vi_start = curbuf->b_op_start; |
7526 curbuf->b_visual.vi_end = curbuf->b_op_end; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7527 // need to adjust cursor position |
7241
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
7528 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
7529 inc(&curbuf->b_visual.vi_end); |
236 | 7530 } |
7531 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7532 // When all lines were selected and deleted do_put() leaves an empty |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7533 // line that needs to be deleted now. |
84 | 7534 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 7535 { |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
7536 ml_delete_flags(curbuf->b_ml.ml_line_count, ML_DEL_MESSAGE); |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
7537 deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); |
817 | 7538 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7539 // If the cursor was in that line, move it to the end of the last |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7540 // line. |
817 | 7541 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
7542 { | |
7543 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7544 coladvance((colnr_T)MAXCOL); | |
7545 } | |
7546 } | |
7 | 7547 auto_format(FALSE, TRUE); |
7548 } | |
7549 } | |
7550 | |
7551 /* | |
7552 * "o" and "O" commands. | |
7553 */ | |
7554 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7555 nv_open(cmdarg_T *cap) |
7 | 7556 { |
7557 #ifdef FEAT_DIFF | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7558 // "do" is ":diffget" |
7 | 7559 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') |
7560 { | |
7561 clearop(cap->oap); | |
6314 | 7562 nv_diffgetput(FALSE, cap->opcount); |
7 | 7563 } |
7564 else | |
7565 #endif | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7566 if (VIsual_active) // switch start and end of visual |
7 | 7567 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
|
7568 #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
|
7569 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
|
7570 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
|
7571 #endif |
7 | 7572 else |
7573 n_opencmd(cap); | |
7574 } | |
7575 | |
7576 #ifdef FEAT_NETBEANS_INTG | |
7577 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7578 nv_nbcmd(cmdarg_T *cap) |
7 | 7579 { |
7580 netbeans_keycommand(cap->nchar); | |
7581 } | |
7582 #endif | |
7583 | |
7584 #ifdef FEAT_DND | |
7585 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7586 nv_drop(cmdarg_T *cap UNUSED) |
7 | 7587 { |
22176
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22091
diff
changeset
|
7588 do_put('~', NULL, BACKWARD, 1L, PUT_CURSEND); |
7 | 7589 } |
7590 #endif | |
203 | 7591 |
7592 /* | |
7593 * Trigger CursorHold event. | |
7594 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
7595 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
7596 */ | |
7597 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7598 nv_cursorhold(cmdarg_T *cap) |
203 | 7599 { |
7600 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
7601 did_cursorhold = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18775
diff
changeset
|
7602 cap->retval |= CA_COMMAND_BUSY; // don't call edit() now |
226 | 7603 } |