summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJason Downs <downsj@cvs.openbsd.org>1996-09-22 01:18:21 +0000
committerJason Downs <downsj@cvs.openbsd.org>1996-09-22 01:18:21 +0000
commit80eddc88a7f881b7952a49a23f25677f09e6b4ba (patch)
treee8bff9fae669ff7d0df46d220225e67dd7927d49 /usr.bin
parent668eaf227d07b7361ec35e886a1de97ad5188c55 (diff)
Add ex mode to vim, from eric@rainbow.uchicago.edu via mool@oce.nl.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/vim/Makefile8
-rw-r--r--usr.bin/vim/cmdcmds.c183
-rw-r--r--usr.bin/vim/cmdline.c84
-rw-r--r--usr.bin/vim/cmdtab.tab4
-rw-r--r--usr.bin/vim/doc/vim_40.txt43
-rw-r--r--usr.bin/vim/doc/vim_diff.txt17
-rw-r--r--usr.bin/vim/doc/vim_help.txt1
-rw-r--r--usr.bin/vim/doc/vim_idx.txt14
-rw-r--r--usr.bin/vim/doc/vim_ref.txt86
-rw-r--r--usr.bin/vim/doc/vim_tags3
-rw-r--r--usr.bin/vim/globals.h16
-rw-r--r--usr.bin/vim/main.c42
-rw-r--r--usr.bin/vim/message.c20
-rw-r--r--usr.bin/vim/misccmds.c3
-rw-r--r--usr.bin/vim/normal.c8
-rw-r--r--usr.bin/vim/proto/cmdcmds.pro6
-rw-r--r--usr.bin/vim/proto/cmdline.pro3
-rw-r--r--usr.bin/vim/term.c14
18 files changed, 480 insertions, 75 deletions
diff --git a/usr.bin/vim/Makefile b/usr.bin/vim/Makefile
index 59cc8913738..bd4e61d2595 100644
--- a/usr.bin/vim/Makefile
+++ b/usr.bin/vim/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.3 1996/09/07 23:41:00 downsj Exp $
+# $OpenBSD: Makefile,v 1.4 1996/09/22 01:17:57 downsj Exp $
.PATH: ${.CURDIR}/doc
@@ -7,6 +7,12 @@ CFLAGS+=-I${.CURDIR} -I${.OBJDIR} -DHAVE_CONFIG_H
LDADD+= -ltermlib
DPADD+= ${LIBTERMLIB}
PROG= vim
+LINKS= ${BINDIR}/vim ${BINDIR}/vi
+LINKS+= ${BINDIR}/vim ${BINDIR}/view
+LINKS+= ${BINDIR}/vim ${BINDIR}/ex
+MLINKS= vim.1 vi.1
+MLINKS+=vim.1 view.1
+MLINKS+=vim.1 ex.1
SRCS= alloc.c buffer.c charset.c cmdcmds.c cmdline.c csearch.c \
digraph.c edit.c fileio.c getchar.c help.c linefunc.c main.c mark.c \
diff --git a/usr.bin/vim/cmdcmds.c b/usr.bin/vim/cmdcmds.c
index c70a04cab74..b4018aea983 100644
--- a/usr.bin/vim/cmdcmds.c
+++ b/usr.bin/vim/cmdcmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdcmds.c,v 1.2 1996/09/21 06:22:52 downsj Exp $ */
+/* $OpenBSD: cmdcmds.c,v 1.3 1996/09/22 01:17:58 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -1194,14 +1194,13 @@ do_fixdel()
(char_u *)"\010" : (char_u *)"\177");
}
- void
-print_line(lnum, use_number)
+ static void
+print_line_no_prefix(lnum, use_number)
linenr_t lnum;
int use_number;
{
char_u numbuf[20];
- msg_outchar('\n');
if (curwin->w_p_nu || use_number)
{
sprintf((char *)numbuf, "%7ld ", (long)lnum);
@@ -1213,6 +1212,24 @@ print_line(lnum, use_number)
msg_prt_line(ml_get(lnum));
}
+ void
+print_line(lnum, use_number)
+ linenr_t lnum;
+ int use_number;
+{
+ msg_outchar('\n');
+ print_line_no_prefix (lnum, use_number);
+}
+
+ void
+print_line_cr(lnum, use_number)
+ linenr_t lnum;
+ int use_number;
+{
+ msg_outchar('\r');
+ print_line_no_prefix (lnum, use_number);
+}
+
/*
* Implementation of ":file[!] [fname]".
*/
@@ -1251,3 +1268,161 @@ do_file(arg, forceit)
/* print full filename if :cd used */
fileinfo(did_cd, FALSE, forceit);
}
+
+/*
+ * do the Ex mode :insert and :append commands
+ */
+
+void
+ex_insert (int before, linenr_t whatline)
+{
+ /* put the cursor somewhere sane if we insert nothing */
+
+ if (whatline > curbuf->b_ml.ml_line_count) {
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ } else {
+ curwin->w_cursor.lnum = whatline;
+ }
+
+ while (1) {
+ char_u *theline;
+
+ if (((theline = getcmdline (' ', 1L)) == 0) ||
+ ((theline[0] == '.') && (theline[1] == 0))) {
+ break;
+ }
+
+ if (before) {
+ mark_adjust (whatline, MAXLNUM, 1, 0L);
+ ml_append (whatline - 1, theline, (colnr_t) 0, FALSE);
+ curwin->w_cursor.lnum = whatline;
+ } else {
+ mark_adjust (whatline + 1, MAXLNUM, 1, 0L);
+ ml_append (whatline, theline, (colnr_t) 0, FALSE);
+ curwin->w_cursor.lnum = whatline + 1;
+ }
+
+ vim_free (theline);
+ whatline++;
+ }
+
+ CHANGED;
+ beginline (MAYBE);
+ updateScreen (NOT_VALID);
+}
+
+/*
+ * do the Ex mode :change command
+ */
+
+void
+ex_change (linenr_t start, linenr_t end)
+{
+ while (end >= start) {
+ ml_delete (start, FALSE);
+ end--;
+ }
+
+ ex_insert (TRUE, start);
+}
+
+void
+ex_z (linenr_t line, char_u *arg)
+{
+ char_u *x;
+ int bigness = curwin->w_height - 3;
+ char_u kind;
+ int minus = 0;
+ linenr_t start, end, curs, i;
+
+ if (arg == 0) { /* is this possible? I don't remember */
+ arg = "";
+ }
+
+ if (bigness < 1) {
+ bigness = 1;
+ }
+
+ x = arg;
+ if (*x == '-' || *x == '+' || *x == '=' || *x == '^' || *x == '.') x++;
+
+ if (*x != 0) {
+ if (!isdigit (*x)) {
+ EMSG ("non-numeric argument to :z");
+ return;
+ } else {
+ bigness = atoi (x);
+ }
+ }
+
+ kind = *arg;
+
+ switch (kind) {
+ case '-':
+ start = line - bigness;
+ end = line;
+ curs = line;
+ break;
+
+ case '=':
+ start = line - bigness / 2 + 1;
+ end = line + bigness / 2 - 1;
+ curs = line;
+ minus = 1;
+ break;
+
+ case '^':
+ start = line - bigness * 2;
+ end = line - bigness;
+ curs = line - bigness;
+ break;
+
+ case '.':
+ start = line - bigness / 2;
+ end = line + bigness / 2;
+ curs = end;
+ break;
+
+ default: /* '+' */
+ start = line;
+ end = line + bigness;
+ curs = end;
+ break;
+ }
+
+ if (start < 1) {
+ start = 1;
+ }
+
+ if (end > curbuf->b_ml.ml_line_count) {
+ end = curbuf->b_ml.ml_line_count;
+ }
+
+ if (curs > curbuf->b_ml.ml_line_count) {
+ curs = curbuf->b_ml.ml_line_count;
+ }
+
+ for (i = start; i <= end; i++) {
+ int j;
+
+ if (minus && (i == line)) {
+ msg_outchar ('\n');
+
+ for (j = 1; j < Columns; j++) {
+ msg_outchar ('-');
+ }
+ }
+
+ print_line (i, FALSE);
+
+ if (minus && (i == line)) {
+ msg_outchar ('\n');
+
+ for (j = 1; j < Columns; j++) {
+ msg_outchar ('-');
+ }
+ }
+ }
+
+ curwin->w_cursor.lnum = curs;
+}
diff --git a/usr.bin/vim/cmdline.c b/usr.bin/vim/cmdline.c
index 57036e817ea..7e50783fdb0 100644
--- a/usr.bin/vim/cmdline.c
+++ b/usr.bin/vim/cmdline.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdline.c,v 1.3 1996/09/21 23:23:28 downsj Exp $ */
+/* $OpenBSD: cmdline.c,v 1.4 1996/09/22 01:18:00 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -272,6 +272,7 @@ getcmdline(firstc, count)
#endif
gotocmdline(TRUE);
msg_outchar(firstc);
+
/*
* Avoid scrolling when called by a recursive do_cmdline(), e.g. when doing
* ":@0" when register 0 doesn't contain a CR.
@@ -999,6 +1000,47 @@ ccheck_abbr(c)
}
/*
+ * do_exmode(): repeatedly get ex commands for the Q command, until we
+ * return to visual mode.
+ */
+
+static int ex_pressedreturn = FALSE;
+
+void
+do_exmode()
+{
+ int save_msg_scroll;
+
+ save_msg_scroll = msg_scroll;
+ ++RedrawingDisabled;
+
+ exmode_active = TRUE;
+ msg_scroll = TRUE;
+ need_wait_return = FALSE;
+
+ while (exmode_active) {
+ linenr_t oldline = curwin->w_cursor.lnum;
+
+ do_cmdline ((char_u *) 0, TRUE, TRUE);
+ lines_left = Rows - 1;
+
+ if (oldline != curwin->w_cursor.lnum && !ex_no_reprint) {
+ if (ex_pressedreturn) {
+ print_line_cr (curwin->w_cursor.lnum, FALSE);
+ ex_pressedreturn = FALSE;
+ } else {
+ print_line (curwin->w_cursor.lnum, FALSE);
+ }
+ }
+
+ ex_no_reprint = FALSE;
+ }
+
+ --RedrawingDisabled;
+ msg_scroll = save_msg_scroll;
+}
+
+/*
* do_cmdline(): execute an Ex command line
*
* 1. If no line given, get one.
@@ -1186,6 +1228,13 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing)
for (cmd = *cmdlinep; vim_strchr((char_u *)" \t:", *cmd) != NULL; cmd++)
;
+ /* in ex mode, an empty line works like :+ */
+
+ if (*cmd == NUL && exmode_active) {
+ cmd = "+";
+ ex_pressedreturn = TRUE;
+ }
+
if (*cmd == '"' || *cmd == NUL) /* ignore comment and empty lines */
goto doend;
@@ -2407,6 +2456,12 @@ donextfile: if (i < 0 || i >= arg_count)
case CMD_ex:
case CMD_visual:
case CMD_view:
+ if (cmdidx == CMD_visual || cmdidx == CMD_view) {
+ exmode_active = FALSE;
+
+ if (*arg == NUL) break;
+ }
+
if ((cmdidx == CMD_new) && *arg == NUL)
{
setpcmark();
@@ -2567,6 +2622,8 @@ donextfile: if (i < 0 || i >= arg_count)
if (cmdidx == CMD_list)
curwin->w_p_list = i;
+ ex_no_reprint = TRUE;
+
break;
case CMD_shell:
@@ -3132,6 +3189,23 @@ find_pat:
}
break;
+ case CMD_insert:
+ ex_insert (TRUE, line2);
+ break;
+
+ case CMD_append:
+ ex_insert (FALSE, line2);
+ break;
+
+ case CMD_change:
+ ex_change (line1, line2);
+ break;
+
+ case CMD_z:
+ ex_z (line2, arg);
+ ex_no_reprint = TRUE;
+ break;
+
default:
/* Normal illegal commands have already been handled */
errormsg = (char_u *)"Sorry, this command is not implemented";
@@ -3538,7 +3612,15 @@ do_ecmd(fnum, fname, sfname, command, newlnum, flags)
beginline(MAYBE);
}
else
+ {
+ if (exmode_active)
+ {
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ check_cursor();
+ }
+
beginline(TRUE);
+ }
}
/*
diff --git a/usr.bin/vim/cmdtab.tab b/usr.bin/vim/cmdtab.tab
index b9639c8bd9d..33e71176c3e 100644
--- a/usr.bin/vim/cmdtab.tab
+++ b/usr.bin/vim/cmdtab.tab
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdtab.tab,v 1.2 1996/09/21 06:22:55 downsj Exp $ */
+/* $OpenBSD: cmdtab.tab,v 1.3 1996/09/22 01:18:01 downsj Exp $ */
/* vi:ts=4:sw=4
*
* VIM - Vi IMproved
@@ -242,7 +242,7 @@ static struct
{(char_u *)"xit", RANGE+BANG+FILE1+DFLALL+TRLBAR},
{(char_u *)"xall", BANG+TRLBAR},
{(char_u *)"yank", RANGE+REGSTR+COUNT+TRLBAR},
- {(char_u *)"z", RANGE+COUNT+TRLBAR}, /* not supported */
+ {(char_u *)"z", RANGE+EXTRA+TRLBAR}, /* not supported */
{(char_u *)"@", RANGE+EXTRA+TRLBAR},
{(char_u *)"!", RANGE+BANG+NAMEDFS},
{(char_u *)"<", RANGE+COUNT+TRLBAR},
diff --git a/usr.bin/vim/doc/vim_40.txt b/usr.bin/vim/doc/vim_40.txt
index 6d4e1ba7a4c..8a9e986b2a2 100644
--- a/usr.bin/vim/doc/vim_40.txt
+++ b/usr.bin/vim/doc/vim_40.txt
@@ -28,6 +28,7 @@ INCOMPATIBLE CHANGES |Incompatible_changes|
'tildeop' and 'weirdinvert' short names changed |short_name_changed|
Use of "v", "V" and "CTRL-V" in Visual mode |use_visual_cmds|
CTRL-B in Insert mode removed |toggle_revins|
+ Q command changed to "gq" |Q_renamed|
NEW AND IMPROVED FEATURES |new_features|
New on-line help system |new_help|
@@ -49,6 +50,7 @@ NEW AND IMPROVED FEATURES |new_features|
Support for Windows NT and Windows 95 |new_win32|
Support for OS/2 |new_os2|
Support for MiNT |new_mint|
+ Ex mode commands added |new_ex|
Miscellaneous |new_misc|
VI COMPATIBILITY IMPROVEMENTS |vi_compat|
@@ -401,6 +403,13 @@ this and accidentally hit CTRL-B, it is very difficult to find out how to undo
it. Since hardly anybody uses this feature, it is disabled by default. If
you want to use it, define RIGHTLEFT in feature.h before compiling. |'revins'|
+Q command in normal mode renamed to "gq" *Q_renamed*
+----------------------------------------
+
+The Q command was used in vim 3.0 to rewrap paragraphs, but in standard vi
+Q is the command to switch from "visual" mode to "ex" mode, and vim now has
+an "ex" mode.
+
NEW AND IMPROVED FEATURES *new_features*
=========================
@@ -729,8 +738,8 @@ Moved initialization of 'shellpipe' and 'shellredir' to after other
initializations, so that they work correctly when 'shell' option is set.
|'shellpipe'|
-Added '2' to 'formatoptions': 'Q' will keep the indent of the second line of a
-paragraph. |'formatoptions'|
+Added '2' to 'formatoptions': 'gq' (formerly Q) will keep the indent of the
+second line of a paragraph. |'formatoptions'|
Added 'maxmapdepth' option: maximum recursiveness of mapping.
|'maxmapdepth'|
@@ -1024,7 +1033,7 @@ this port quite easy. It mostly uses the Unix files and settings.
|vim_os2.txt|
-Support for MiNT *new_mint*
+Support for MiNT *new_mint*
----------------
There is now a version of Vim for MiNT. It was compiled with gcc under
@@ -1032,6 +1041,14 @@ a Unix-like environment.
|vim_mint.txt|
+Ex mode commands added *new_ex*
+----------------------
+
+Vim now works in Ex mode when invoked as "ex" or when the Q command is
+used. The :append, :change, :insert, and :z commands now function like
+standard vi.
+
+
Miscellaneous new features *new_misc*
--------------------------
@@ -1133,22 +1150,22 @@ insert is still possible. |'revins'|
Added "gq" as an alias to "Q". The "Q" command will be changed in a following
version of Vim, to make it Vi compatible (start Ex mode). |gq|
-The "Q" operator no longer affects empty lines. You can now format a lot of
-paragraphs without losing the separating blank lines. Use "Qp..." to format a
-few consecutive paragraphs. |Q|
+The "gq" operator (formerly Q) no longer affects empty lines. You can now
+format a lot of paragraphs without losing the separating blank lines. Use
+"gqp..." to format a few consecutive paragraphs. |gq|
-Formatting with "Q" fixes up the indent of the first line (replace with
-minimal number of tabs/spaces). |Q|
+Formatting with "gq" fixes up the indent of the first line (replace with
+minimal number of tabs/spaces). |gq|
-After "Q", put cursor at first non-blank of the last formatted line. This
+After "gq", put cursor at first non-blank of the last formatted line. This
makes it easier to repeat the formatting.
-Made "Q}" put the cursor on the line after the paragraph (where the "}"
+Made "gq}" put the cursor on the line after the paragraph (where the "}"
command would have taken the cursor). Makes it possible to use "." to format
-the next paragraph. |Q|
+the next paragraph. |gq|
-When formatting with "Q" while 'tw' and 'wm' are both zero, use a textwidth of
+When formatting with "gq" while 'tw' and 'wm' are both zero, use a textwidth of
79, or the screen width minus one if that is smaller. Joining all the lines
-doesn't make sense for the "Q" command. |Q|
+doesn't make sense for the "gq" command. |gq|
Added CTRL-W CTRL-T (go to top window) and CTRL-W CTRL-B (go to bottom
window). |CTRL-W_CTRL-T|.
diff --git a/usr.bin/vim/doc/vim_diff.txt b/usr.bin/vim/doc/vim_diff.txt
index f9f0553718d..654fff63343 100644
--- a/usr.bin/vim/doc/vim_diff.txt
+++ b/usr.bin/vim/doc/vim_diff.txt
@@ -3,9 +3,8 @@
This is a summary of the differences between VIM and vi. It is not complete.
see also |vim_ref.txt|, look for comments in {}, like "{not in Vi}".
-Vim is mostly POSIX 1003.2-1 compliant. The commands known to be missing
-are "Q", ":append", ":change", ":insert", ":open" and ":z". There are
-probably a lot of small differences.
+Vim is mostly POSIX 1003.2-1 compliant. The only command known to be missing
+is ":open". There are probably a lot of small differences.
THE MOST INTERESTING ADDITIONS
@@ -77,7 +76,6 @@ Visual mode. |Visual_mode|
! filter through external program
= filter through indent
: start ":" command for the Visual lines.
- Q format text to 'textwidth' columns (obsolete)
gq format text to 'textwidth' columns
J join lines
~ swap case
@@ -321,6 +319,11 @@ Support for Windows 95/NT |new_win32|
runs under Windows 3.1 and MS-DOS. It supports long file names where
available.
+Ex mode |new_ex|
+ You now get Ex mode when you invoke vim as "ex" or use the |Q|
+ command. The |:append|, |:insert|, |:change|, and |:z| commands
+ now function like in standard vi.
+
Miscellaneous new features |new_misc|
Implemented incremental search.
A whole bunch of commands that start with "g": Goto declaration, show
@@ -329,7 +332,7 @@ Miscellaneous new features |new_misc|
Added the ":retab" command. Can be used to change the size of a
<Tab>, replace spaces with a <Tab> or a <Tab> with spaces.
Implemented "Vim -r" to list any swap files that can be found.
- The "Q" operator no longer affects empty lines.
+ The "gq" operator no longer affects empty lines.
Added '-' register for deletes of less than one line, see |registers|.
Quickfix: Support for several error formats at the same time.
Added separate mapping for normal mode and visual mode.
@@ -380,7 +383,6 @@ The "-o" option opens a window for each argument. "-o4" opens four windows.
In command mode:
-Missing command: "Q" (go to Ex mode) (but see |pseudo-Q|).
Missing Ex commands: append, change, insert, open and z.
The command characters are shown in the last line of the screen. They are
@@ -556,6 +558,9 @@ by using a CTRL-M. For Vi this means you cannot insert a real CTRL-M in the
text. With Vim you can put a real CTRL-M in the text by preceding it with a
CTRL-V.
+The "Q" operator has been renamed to "gq" so that the "Q" command can switch
+to "ex" mode.
+
In insert mode:
diff --git a/usr.bin/vim/doc/vim_help.txt b/usr.bin/vim/doc/vim_help.txt
index 70989e96d14..ea2d5d6d27b 100644
--- a/usr.bin/vim/doc/vim_help.txt
+++ b/usr.bin/vim/doc/vim_help.txt
@@ -803,6 +803,7 @@ Short explanation of each option: *option_list*
C4350, etc.)
|:normal| :norm[al][!] {commands}
Execute Normal mode commands.
+|Q| Q switch to "ex" mode.
------------------------------------------------------------------------------
*X_ce* Command-line editing
diff --git a/usr.bin/vim/doc/vim_idx.txt b/usr.bin/vim/doc/vim_idx.txt
index 83c82b06b3e..f7f28c96c2e 100644
--- a/usr.bin/vim/doc/vim_idx.txt
+++ b/usr.bin/vim/doc/vim_idx.txt
@@ -275,7 +275,7 @@ tag char note action in Normal mode
insert text, repeat N times
|P| ["x]P 2 put the text [from buffer x] before the
cursor N times
-|Q| Q{motion} 2 format Nmove lines (obsolete)
+|Q| Q switch to "ex" mode
|R| R 2 enter replace mode: overtype existing
characters, repeat the entered text N-1
times
@@ -588,7 +588,7 @@ tag char note action in Normal mode
lines down
|gk| gk 1 like "k", but when 'wrap' on go N screen
lines up
-|gq| gq{motion} 2 format Nmove text (same as "Q")
+|gq| gq{motion} 2 format Nmove text
|gs| gs goto sleep for N seconds (default 1)
|gu| gu{motion} 2 make Nmove text lowercase
|gv| gv reselect the previous Visual area
@@ -752,7 +752,7 @@ arguments.
|:@| :@ execute contents of a register
|:@@| :@@ repeat the previous ":@"
|:Next| :N[ext] go to previous file in the argument list
-|:append| :a[ppend] append text (not implemented)
+|:append| :a[ppend] append text
|:abbreviate| :ab[breviate] enter abbreviation
|:abclear| :abc[lear] remove all abbreviations
|:all| :al[l] open a window for each file in the argument
@@ -774,7 +774,7 @@ arguments.
|:brewind| :br[ewind] go to last file in the buffer list
|:buffers| :buffers list all files in the buffer list
|:bunload| :bun[load] unload a specific buffer
-|:change| :c[hange] replace a line (not implemented)
+|:change| :c[hange] replace a line or series of lines
|:cNext| :cN[ext] go to previous error
|:cabbrev| :ca[bbrev] like ":abbreviate" but for command-line mode
|:cabclear| :cabc[lear] clear all abbreviations for command-line mode
@@ -814,7 +814,7 @@ arguments.
|:gui| :gu[i] start the GUI
|:gvim| :gv[im] start the GUI
|:help| :h[elp] open a help window
-|:insert| :i[nsert] insert text (not implemented)
+|:insert| :i[nsert] insert text
|:iabbrev| :ia[bbrev] like ":abbrev" but for Insert mode
|:iabclear| :iabc[lear] like ":abclear" but for Insert mode
|:ijump| :ij[ump] jump to definition of identifier
@@ -926,7 +926,7 @@ arguments.
|:unmap| :unm[ap] remove mapping
|:version| :ve[rsion] print version number and other info
|:vglobal| :v[global] execute commands for not matching lines
-|:visual| :vi[sual] same as ":edit"
+|:visual| :vi[sual] same as ":edit", but turns off "ex" mode.
|:view| :vie[w] edit a file read-only
|:vmap| :vm[ap] like ":map" but for Visual mode
|:vmapclear| :vmapc[lear] remove all mappings for Visual mode
@@ -946,5 +946,5 @@ arguments.
|:xit| :x[it] write if buffer changed and quit window or Vim
|:xall| :xa[ll] same as ":wqall"
|:yank| :y[ank] yank lines into a register
-|:z| :z print some lines (not implemented)
+|:z| :z print some lines
|:~| :~ repeat last ":substitute"
diff --git a/usr.bin/vim/doc/vim_ref.txt b/usr.bin/vim/doc/vim_ref.txt
index ad163ba4c79..72a1ffb15a8 100644
--- a/usr.bin/vim/doc/vim_ref.txt
+++ b/usr.bin/vim/doc/vim_ref.txt
@@ -442,8 +442,9 @@ Example for using a script file to change a name in several files:
foreach i ( *.let ) vim -s subs.vi $i
If the executable is called "view", Vim will start in Readonly mode. This is
-useful if you can make a hard or symbolic link from "view" to "vim".
-Starting in Readonly mode can also be done with "vim -v".
+useful if you can make a hard or symbolic link from "view" to "vim". Starting
+in Readonly mode can also be done with "vim -v". If the executable is called
+"ex", Vim will start in Ex mode rather than visual mode.
3.2 Workbench (Amiga only) *workbench*
@@ -2585,9 +2586,10 @@ the string "[Modified]" if the buffer has been changed.
*:ex*
:ex [+cmd] [file] Same as :edit. {Vi: go from visual to Ex mode}
+ Use the |Q| command to switch to Ex mode.
*:vi* *:visual*
-:vi[sual] [+cmd] [file] Same as :edit. {Vi: go from Ex to visual mode}
+:vi[sual] [+cmd] [file] Same as :edit, but also go from Ex to visual mode.
*:vie* *:view*
:vie[w] [+cmd] file Same as :edit, but set 'readonly' option for this
@@ -3574,7 +3576,6 @@ or change text. The following operators are available:
|gU| gU make upper case
|!| ! filter through an external program
|=| = filter through 'equalprg' or C-indenting if empty
- |Q| Q text formatting (obsolete)
|gq| gq text formatting
|>| > shift right
|<| < shift left
@@ -3781,6 +3782,29 @@ or the last line. The first two commands put the cursor in the same column
except after the "$" command, then the cursor will be put on the last
character of the line.
+ *:z*
+:{range}z[+-^.=]{count} Display several lines of text surrounding the line
+ specified with {range}, or around the current line
+ if there is no {range}. If there is a {count}, that's
+ how many lines you'll see; otherwise, the current
+ window size is used.
+
+ :z can be used either alone or followed by any of
+ several punctuation marks. These have the following
+ effect:
+
+ mark first line last line new location
+ ---- ---------- --------- ------------
+ + current line 1 scr forward 1 scr forward
+ - 1 scr back current line current line
+ ^ 2 scr back 1 scr back 1 scr back
+ . 1/2 scr back 1/2 scr fwd 1/2 src fwd
+ = 1/2 src back 1/2 scr fwd current line
+
+ Specifying no mark at all is the same as "+".
+ If the mark is "=", a line of dashes is printed
+ around the current line.
+
6.3 Word motions *word_motions*
@@ -5175,6 +5199,18 @@ This command reads "binfile", uuencodes it and reads it into the current
buffer. Useful when you are editing e-mail and want to include a binary
file.
+ *:a* *:append*
+:{range}a[ppend] Insert several lines of text below the specified
+ line. Type a line containing only "." to stop
+ inserting. If the {range} is missing, the text
+ will be inserted after the current line.
+
+ *:i* *:insert*
+:{range}a[ppend] Insert several lines of text above the specified
+ line. Type a line containing only "." to stop
+ inserting. If the {range} is missing, the text
+ will be inserted before the current line.
+
10. Deleting text *deleting*
=================
@@ -5333,6 +5369,12 @@ word does not include the following white space. {Vi: "cw" when on a blank
followed by other blanks changes only the first blank; this is probably a
bug, because "dw" deletes all the blanks}
+ *:c* *:change*
+:{range}c[hange] Replace lines of text with some different text.
+ Type a line containing only "." to stop replacing.
+ If the {range} is missing, the current line will
+ be replaced with the new text.
+
11.2 Simple changes *simple_change*
@@ -5681,19 +5723,15 @@ either the first or second pattern in parentheses did not match, so either
:[range]le[ft] [indent] left align lines in [range]. Sets the indent in the
lines to [indent] (default 0). {not in Vi}
-gq{motion} *Q* *gq*
-Q{motion} Format the lines that were moved over. The length of
+ *gq*
+gq{motion} Format the lines that were moved over. The length of
each line will be restricted to the width given with
the 'textwidth' option. See below. If the
'textwidth' option is 0, the width of the screen is
used (with a maximum of 79). {not in Vi}
- NOTE: The "Q" command is used in Vi to go to Ex mode.
- In a future version of Vim this will be made
- compatible. Use "gq" for formatting now, to avoid
- problems when upgrading to a newer version of Vim.
-{Visual}gq *v_Q* *v_gq*
-{Visual}Q Format the highlighted text. (see the chapter on
+ *v_gq*
+{Visual}gq Format the highlighted text. (see the chapter on
Visual mode |Visual_mode|). {not in Vi}
Example: To format the current paragraph use "gqp".
@@ -5797,10 +5835,10 @@ r Automatically insert the current comment leader after hitting
<return> in insert mode.
o Automatically insert the current comment leader after hitting 'o' or
'O' in Normal mode.
-q Allow formatting of comments with "gq" (or "Q", which is obsolete).
- Note that blank lines, or lines containing only the comment leader
- will be left untouched. A new paragraph starts after such a line, or
- when the comment leader changes.
+q Allow formatting of comments with "gq". Note that blank lines, or
+ lines containing only the comment leader will be left untouched. A
+ new paragraph starts after such a line, or when the comment leader
+ changes.
2 When formatting text the indent of the second line of a paragraph is
used for the rest of the paragraph. This allows for paragraphs with
a different indent for the first line.
@@ -6419,7 +6457,6 @@ The operators that can be used are:
< shift left (1)(*) |v_<|
! filter through external command (1) |v_!|
= filter through 'equalprg' option command (1) |v_=|
- Q format lines to 'textwidth' length (1)(obsolete)|v_Q|
gq format lines to 'textwidth' length (1) |v_gq|
The objects that can be used are:
@@ -6622,6 +6659,15 @@ K Run a program to lookup the keyword under the
sleep". While sleeping the cursor is positioned in
the text (if visible). {not in Vi}
+ *Q*
+Q Switch to "ex" mode. This is just like typing ":"
+ commands one after another, except you don't have to
+ keep pressing ":" and the screen doesn't get updated
+ after each command. Use the |:visual| command to
+ return to the normal visual editor. Vim will enter
+ this mode by default if it's invoked as "ex" on the
+ command line.
+
15. Repeating commands *repeating*
======================
@@ -9908,13 +9954,7 @@ are included. However, there is no Ex mode.
These commands are in Vi, but not in Vim.
-Q {Vi: go to Ex mode} See |pseudo-Q|.
-
-:a[ppend] {Vi: append text} *:a* *:append*
-:c[hange] {Vi: replace lines} *:c* *:change*
-:i[nsert] {Vi: insert text} *:i* *:insert*
:o[pen] {Vi: start editing in open mode}*:o* *:open*
-:z {Vi: print some lines} *:z*
21.2 Missing options *missing_options*
diff --git a/usr.bin/vim/doc/vim_tags b/usr.bin/vim/doc/vim_tags
index a58adfe8025..6af387cac7e 100644
--- a/usr.bin/vim/doc/vim_tags
+++ b/usr.bin/vim/doc/vim_tags
@@ -1202,6 +1202,7 @@ N<Del> vim_ref.txt /\*N<Del>\*
O vim_ref.txt /\*O\*
P vim_ref.txt /\*P\*
Q vim_ref.txt /\*Q\*
+Q_renamed vim_40.txt /\*Q_renamed\*
R vim_ref.txt /\*R\*
S vim_ref.txt /\*S\*
SHELL vim_ref.txt /\*SHELL\*
@@ -1650,6 +1651,7 @@ new_autocmd vim_40.txt /\*new_autocmd\*
new_cindent vim_40.txt /\*new_cindent\*
new_commandline vim_40.txt /\*new_commandline\*
new_complete vim_40.txt /\*new_complete\*
+new_ex vim_40.txt /\*new_ex\*
new_features vim_40.txt /\*new_features\*
new_gui vim_40.txt /\*new_gui\*
new_help vim_40.txt /\*new_help\*
@@ -1898,7 +1900,6 @@ v_D vim_ref.txt /\*v_D\*
v_J vim_ref.txt /\*v_J\*
v_K vim_ref.txt /\*v_K\*
v_P vim_ref.txt /\*v_P\*
-v_Q vim_ref.txt /\*v_Q\*
v_R vim_ref.txt /\*v_R\*
v_S vim_ref.txt /\*v_S\*
v_U vim_ref.txt /\*v_U\*
diff --git a/usr.bin/vim/globals.h b/usr.bin/vim/globals.h
index c52a48b407f..d6d9515645e 100644
--- a/usr.bin/vim/globals.h
+++ b/usr.bin/vim/globals.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: globals.h,v 1.2 1996/09/21 06:23:00 downsj Exp $ */
+/* $OpenBSD: globals.h,v 1.3 1996/09/22 01:18:02 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -384,6 +384,20 @@ extern char_u *all_cflags; /* this is in pathdef.c */
EXTERN char_u no_lines_msg[] INIT(="--No lines in buffer--");
/*
+ * ex mode (Q) state
+ */
+
+EXTERN int exmode_active INIT(= FALSE);
+EXTERN int ex_no_reprint INIT(= FALSE); /* no need to print after z or p */
+
+/*
+ * message.c: lines left before a "more" message. Ex mode needs to
+ * be able to reset this after you type something.
+ */
+
+EXTERN int lines_left INIT(= -1); /* lines left for listing */
+
+/*
* The error messages that can be shared are included here.
* Excluded are very specific errors and debugging messages.
*/
diff --git a/usr.bin/vim/main.c b/usr.bin/vim/main.c
index eff7a9afaa2..53715b9ed9e 100644
--- a/usr.bin/vim/main.c
+++ b/usr.bin/vim/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.2 1996/09/21 06:23:05 downsj Exp $ */
+/* $OpenBSD: main.c,v 1.3 1996/09/22 01:18:02 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -153,6 +153,7 @@ main(argc, argv)
int arg_idx = 0; /* index for arg_files[] */
int check_version = FALSE; /* check .vimrc version number */
int argv_idx; /* index in argv[n][] */
+ int invoked_as_ex = FALSE; /* argv[0] is "ex" */
#if defined(MSDOS) || defined(WIN32) || defined(OS2)
static struct initmap
@@ -249,6 +250,15 @@ main(argc, argv)
}
/*
+ * If the executable is called "ex" we start in ex mode.
+ */
+
+ if (STRCMP(gettail((char_u *)argv[0]), (char_u *)"ex") == 0)
+ {
+ invoked_as_ex = TRUE;
+ }
+
+/*
* If the executable is called "gvim" we run the GUI version.
*/
if (STRCMP(gettail((char_u *)argv[0]), (char_u *)"gvim") == 0)
@@ -863,7 +873,10 @@ main(argc, argv)
secure = 0;
scroll_start();
- screenclear(); /* clear screen */
+
+ if (!invoked_as_ex) {
+ screenclear(); /* clear screen */
+ }
no_wait_return = TRUE;
@@ -899,6 +912,10 @@ main(argc, argv)
#ifdef AUTOCMD
curwin = firstwin; /* start again */
#endif
+ if (invoked_as_ex) { /* move to end of file if running as
+ex */
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
}
mch_breakcheck();
if (got_int)
@@ -950,7 +967,7 @@ main(argc, argv)
curwin->w_arg_idx = arg_idx;
/* edit file from arg list, if there is one */
(void)do_ecmd(0, arg_idx < arg_count ? arg_files[arg_idx] : NULL,
- NULL, NULL, (linenr_t)1, ECMD_HIDE);
+ NULL, NULL, (linenr_t)0, ECMD_HIDE);
if (arg_idx == arg_count - 1)
arg_had_last = TRUE;
++arg_idx;
@@ -1045,7 +1062,7 @@ main(argc, argv)
* If there is nothing in the stuff_buffer or do_redraw is TRUE,
* update cursor and redraw.
*/
- if (skip_redraw)
+ if (skip_redraw || invoked_as_ex)
skip_redraw = FALSE;
else if (do_redraw || stuff_empty())
{
@@ -1088,6 +1105,23 @@ main(argc, argv)
cursor_on();
}
+ /*
+ * if we're invoked as ex, do a round of ex commands before
+ * going on to normal mode
+ */
+
+ if (invoked_as_ex) {
+ do_exmode();
+
+ cursupdate();
+ updateScreen(TRUE);
+ showmode();
+ setcursor();
+ cursor_on();
+
+ invoked_as_ex = FALSE;
+ }
+
/*
* get and execute a normal mode command
*/
diff --git a/usr.bin/vim/message.c b/usr.bin/vim/message.c
index 07b07a32aa0..bbd32768b87 100644
--- a/usr.bin/vim/message.c
+++ b/usr.bin/vim/message.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: message.c,v 1.2 1996/09/21 06:23:09 downsj Exp $ */
+/* $OpenBSD: message.c,v 1.3 1996/09/22 01:18:03 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -23,7 +23,7 @@
static void msg_screen_outchar __ARGS((int c));
static int msg_check_screen __ARGS((void));
-static int lines_left = -1; /* lines left for listing */
+/* lines_left moved to globals so do_exmode could see it */
/*
* msg(s) - displays the string 's' on the status line
@@ -245,6 +245,12 @@ wait_return(redraw)
quit_more = FALSE;
got_int = FALSE;
}
+ else if (exmode_active)
+ {
+ MSG_OUTSTR(" "); /* make sure the cursor is on the right line */
+ c = CR; /* no need for a return in ex mode */
+ got_int = FALSE;
+ }
else
{
State = HITRETURN;
@@ -547,6 +553,16 @@ msg_prt_line(s)
char_u *p = NULL; /* init to make SASC shut up */
int n;
+ /*
+ * if it's a blank line, echo a space, because otherwise if we're
+ * in ex mode, the : for the next command will end up on the wrong
+ * line. I don't know why -- hooray for cargo cult programming!
+ */
+
+ if (*s == 0) {
+ msg_outchar(' ');
+ }
+
for (;;)
{
if (n_extra)
diff --git a/usr.bin/vim/misccmds.c b/usr.bin/vim/misccmds.c
index 01e2c5dae5e..c7631498cf7 100644
--- a/usr.bin/vim/misccmds.c
+++ b/usr.bin/vim/misccmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misccmds.c,v 1.2 1996/09/21 06:23:10 downsj Exp $ */
+/* $OpenBSD: misccmds.c,v 1.3 1996/09/22 01:18:04 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -1459,6 +1459,7 @@ change_warning(col)
MSG_OUTSTR("Warning: Changing a readonly file");
msg_clr_eos();
(void)msg_end();
+ flushbuf();
mch_delay(1000L, TRUE); /* give him some time to think about it */
curbuf->b_did_warn = TRUE;
}
diff --git a/usr.bin/vim/normal.c b/usr.bin/vim/normal.c
index 0988d74efd9..4a37eb6562a 100644
--- a/usr.bin/vim/normal.c
+++ b/usr.bin/vim/normal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: normal.c,v 1.2 1996/09/21 06:23:11 downsj Exp $ */
+/* $OpenBSD: normal.c,v 1.3 1996/09/22 01:18:06 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -527,6 +527,11 @@ dozet:
do_cmdline(NULL, FALSE, FALSE);
break;
+ case 'Q':
+ do_exmode();
+ updateScreen(CLEAR);
+ break;
+
case K_HELP:
case K_F1:
if (checkclearopq())
@@ -1590,7 +1595,6 @@ insert_command:
case '<':
case '!':
case '=':
- case 'Q': /* should start Ex mode */
dooperator:
n = vim_strchr(opchars, c) - opchars + 1;
if (n == op_type) /* double operator works on lines */
diff --git a/usr.bin/vim/proto/cmdcmds.pro b/usr.bin/vim/proto/cmdcmds.pro
index 1bf7078bfd7..fa8cbc18f6f 100644
--- a/usr.bin/vim/proto/cmdcmds.pro
+++ b/usr.bin/vim/proto/cmdcmds.pro
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdcmds.pro,v 1.2 1996/09/21 06:23:50 downsj Exp $ */
+/* $OpenBSD: cmdcmds.pro,v 1.3 1996/09/22 01:18:20 downsj Exp $ */
/* cmdcmds.c */
void do_ascii __PARMS((void));
void do_align __PARMS((linenr_t start, linenr_t end, int width, int type));
@@ -14,4 +14,8 @@ void viminfo_readstring __PARMS((char_u *p));
void viminfo_writestring __PARMS((FILE *fd, char_u *p));
void do_fixdel __PARMS((void));
void print_line __PARMS((linenr_t lnum, int use_number));
+void print_line_cr __PARMS((linenr_t lnum, int use_number));
void do_file __PARMS((char_u *arg, int forceit));
+void ex_insert __PARMS((int before, linenr_t whatline));
+void ex_change __PARMS((linenr_t start, linenr_t end));
+void ex_z __PARMS((linenr_t line, char_u *arg));
diff --git a/usr.bin/vim/proto/cmdline.pro b/usr.bin/vim/proto/cmdline.pro
index 80dc5e13ffb..c3fa56d03d6 100644
--- a/usr.bin/vim/proto/cmdline.pro
+++ b/usr.bin/vim/proto/cmdline.pro
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdline.pro,v 1.2 1996/09/21 06:23:50 downsj Exp $ */
+/* $OpenBSD: cmdline.pro,v 1.3 1996/09/22 01:18:20 downsj Exp $ */
/* cmdline.c */
void add_to_history __PARMS((int histype, char_u *new_entry));
char_u *getcmdline __PARMS((int firstc, long count));
@@ -23,3 +23,4 @@ void prepare_viminfo_history __PARMS((int len));
int read_viminfo_history __PARMS((char_u *line, FILE *fp));
void finish_viminfo_history __PARMS((void));
void write_viminfo_history __PARMS((FILE *fp));
+void do_exmode __PARMS((void));
diff --git a/usr.bin/vim/term.c b/usr.bin/vim/term.c
index cc7e4483580..cbd619e34fb 100644
--- a/usr.bin/vim/term.c
+++ b/usr.bin/vim/term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: term.c,v 1.2 1996/09/21 06:23:22 downsj Exp $ */
+/* $OpenBSD: term.c,v 1.3 1996/09/22 01:18:07 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -2000,10 +2000,14 @@ set_winsize(width, height, mustset)
}
else
{
- tmp = RedrawingDisabled;
- RedrawingDisabled = FALSE;
- updateScreen(CURSUPD);
- RedrawingDisabled = tmp;
+ if (!exmode_active)
+ {
+ tmp = RedrawingDisabled;
+ RedrawingDisabled = FALSE;
+ updateScreen(CURSUPD);
+ RedrawingDisabled = tmp;
+ }
+
if (State == CMDLINE)
redrawcmdline();
else