diff options
Diffstat (limited to 'usr.bin/vim')
75 files changed, 3172 insertions, 1376 deletions
diff --git a/usr.bin/vim/README b/usr.bin/vim/README index 24135a45756..39dcfa5edcd 100644 --- a/usr.bin/vim/README +++ b/usr.bin/vim/README @@ -1,6 +1,6 @@ -$OpenBSD: README,v 1.1 1996/09/07 23:43:01 downsj Exp $ +$OpenBSD: README,v 1.2 1996/09/21 06:22:50 downsj Exp $ -README for version 4.2 of Vim: Vi IMproved. +README for version 4.4 of Vim: Vi IMproved. Vim is an almost compatible version of the UNIX editor vi. Only the "Q" command is missing. Many new features have been added: multi level undo, @@ -24,10 +24,22 @@ read doc/vim_help.txt. It contains pointers to the other documentation files. "tutor/readme" is a one hour training course for beginners. Copying: -Vim is Charityware. You can copy it as much as you like, but you are +Vim is Charityware. You can use and copy it as much as you like, but you are encouraged to make a donation to orphans in Uganda. Please read the file -"doc/vim_kcc.txt" for details. You are allowed to include Vim on a CD-ROM if -you send me one. +"doc/vim_kcc.txt" for details. + +If you include Vim on a CD-ROM, I would like to receive a copy. Just so I +know which Vim distributions exists in the world (and to show off to my +friends :-)). + +If you distribute a modified version of Vim, you must send me a copy, +including the source code. Or make it available to me through ftp; let me +know where I can find it. If the number of changes is small (e.g., a modified +Makefile) e-mailing me the diffs will do. I preserve the right to include +any changes in the official version of Vim. It is not allowed to distribute +a modified version of Vim without making the source code available to me. +It is not allowed to remove these restrictions from the distribution of the +Vim sources. Compiling: All stuff for compiling Vim is in the "src" directory. See src/INSTALL for diff --git a/usr.bin/vim/buffer.c b/usr.bin/vim/buffer.c index a1e8124ce94..9940a1588cb 100644 --- a/usr.bin/vim/buffer.c +++ b/usr.bin/vim/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.1 1996/09/07 21:40:27 downsj Exp $ */ +/* $OpenBSD: buffer.c,v 1.2 1996/09/21 06:22:51 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -31,11 +31,10 @@ #include "option.h" static void enter_buffer __ARGS((BUF *)); -static void free_buf_options __ARGS((BUF *)); static char_u *buflist_match __ARGS((regexp *prog, BUF *buf)); static void buflist_setlnum __ARGS((BUF *, linenr_t)); static linenr_t buflist_findlnum __ARGS((BUF *)); -static void append_arg_number __ARGS((char_u *, int)); +static int append_arg_number __ARGS((char_u *, int, int)); /* * Open current buffer, that is: open the memfile and read the file into memory @@ -45,6 +44,10 @@ static void append_arg_number __ARGS((char_u *, int)); open_buffer() { int retval = OK; +#ifdef AUTOCMD + BUF *old_curbuf; + BUF *new_curbuf; +#endif /* * The 'readonly' flag is only set when b_neverloaded is being reset. @@ -77,6 +80,11 @@ open_buffer() enter_buffer(curbuf); return FAIL; } +#ifdef AUTOCMD + /* The autocommands in readfile() may change the buffer, but only AFTER + * reading the file. */ + old_curbuf = curbuf; +#endif if (curbuf->b_filename != NULL) retval = readfile(curbuf->b_filename, curbuf->b_sfilename, (linenr_t)0, TRUE, (linenr_t)0, MAXLNUM, FALSE); @@ -105,14 +113,45 @@ open_buffer() if (retval != FAIL) { - do_modelines(); - curbuf->b_neverloaded = FALSE; +#ifdef AUTOCMD + /* + * The autocommands may have changed the current buffer. Apply the + * modelines to the correct buffer, if it still exists. + */ + if (buf_valid(old_curbuf)) + { + new_curbuf = curbuf; + curbuf = old_curbuf; + curwin->w_buffer = old_curbuf; +#endif + do_modelines(); + curbuf->b_neverloaded = FALSE; +#ifdef AUTOCMD + curbuf = new_curbuf; + curwin->w_buffer = new_curbuf; + } +#endif } return retval; } /* + * Return TRUE if "buf" points to a valid buffer (in the buffer list). + */ + int +buf_valid(buf) + BUF *buf; +{ + BUF *bp; + + for (bp = firstbuf; bp != NULL; bp = bp->b_next) + if (bp == buf) + return TRUE; + return FALSE; +} + +/* * Close the link to a buffer. If "free_buf" is TRUE free the buffer if it * becomes unreferenced. The caller should get a new buffer very soon! * if 'del_buf' is TRUE, remove the buffer from the buffer list. @@ -152,6 +191,7 @@ close_buffer(win, buf, free_buf, del_buf) else buf->b_next->b_prev = buf->b_prev; free_buf_options(buf); + vim_free(buf); } else buf_clear(buf); @@ -238,7 +278,7 @@ do_bufdel(command, arg, addr_count, start_bnr, end_bnr, forceit) if (bnr == curbuf->b_fnum) do_current = bnr; else if (do_buffer(command, DOBUF_FIRST, FORWARD, (int)bnr, - forceit) == OK) + forceit) == OK) ++deleted; /* @@ -267,7 +307,7 @@ do_bufdel(command, arg, addr_count, start_bnr, end_bnr, forceit) } } if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, - FORWARD, do_current, forceit) == OK) + FORWARD, do_current, forceit) == OK) ++deleted; if (deleted == 0) @@ -398,18 +438,20 @@ do_buffer(action, start, dir, count, forceit) EMSG("Cannot unload last buffer"); return FAIL; } - /* Close any other windows on this buffer */ + + /* Close any other windows on this buffer, then make it empty. */ close_others(FALSE); buf = curbuf; setpcmark(); - retval = do_ecmd(0, NULL, NULL, NULL, FALSE, (linenr_t)1, FALSE); + retval = do_ecmd(0, NULL, NULL, NULL, (linenr_t)1, + forceit ? ECMD_FORCEIT : 0); + /* - * The do_ecmd() may create a new buffer, then we have to delete + * do_ecmd() may create a new buffer, then we have to delete * the old one. But do_ecmd() may have done that already, check - * if the buffer still exists (it will be the first or second in - * the buffer list). + * if the buffer still exists. */ - if (buf != curbuf && (buf == firstbuf || buf == firstbuf->b_next)) + if (buf != curbuf && buf_valid(buf)) close_buffer(NULL, buf, TRUE, TRUE); return retval; } @@ -427,41 +469,63 @@ do_buffer(action, start, dir, count, forceit) if (buf != curbuf) { close_windows(buf); - close_buffer(NULL, buf, TRUE, action == DOBUF_DEL); + if (buf_valid(buf)) + close_buffer(NULL, buf, TRUE, action == DOBUF_DEL); return OK; } /* * Deleting the current buffer: Need to find another buffer to go to. * There must be another, otherwise it would have been handled above. + * First try to find one that is loaded. */ - if (curbuf->b_next != NULL) - buf = curbuf->b_next; - else - buf = curbuf->b_prev; + for (buf = firstbuf; buf != NULL; buf = buf->b_next) + if (buf != curbuf && buf->b_ml.ml_mfp != NULL) + break; + if (buf == NULL) /* No loaded buffers, just take anyone */ + { + if (curbuf->b_next != NULL) + buf = curbuf->b_next; + else + buf = curbuf->b_prev; + } } /* * make buf current buffer */ - setpcmark(); if (action == DOBUF_SPLIT) /* split window first */ { if (win_split(0, FALSE) == FAIL) return FAIL; } + + /* go to current buffer - nothing to do */ + if (buf == curbuf) + return OK; + + setpcmark(); curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */ buflist_altlnum(); /* remember curpos.lnum */ + /* close_windows() or apply_autocmds() may change curbuf */ + delbuf = curbuf; + #ifdef AUTOCMD apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); + if (buf_valid(delbuf)) #endif - delbuf = curbuf; /* close_windows() may change curbuf */ - if (action == DOBUF_UNLOAD || action == DOBUF_DEL) - close_windows(curbuf); - close_buffer(NULL, delbuf, action == DOBUF_UNLOAD || action == DOBUF_DEL, - action == DOBUF_DEL); - enter_buffer(buf); + { + if (action == DOBUF_UNLOAD || action == DOBUF_DEL) + close_windows(delbuf); + if (buf_valid(delbuf)) + close_buffer(NULL, delbuf, action == DOBUF_UNLOAD || + action == DOBUF_DEL, action == DOBUF_DEL); + } +#ifdef AUTOCMD + if (buf_valid(buf)) /* an autocommand may have deleted buf! */ +#endif + enter_buffer(buf); return OK; } @@ -473,7 +537,7 @@ do_buffer(action, start, dir, count, forceit) enter_buffer(buf) BUF *buf; { - buf_copy_options(curbuf, buf, TRUE); + buf_copy_options(curbuf, buf, TRUE, FALSE); curwin->w_buffer = buf; curbuf = buf; ++curbuf->b_nwindows; @@ -526,7 +590,7 @@ buflist_new(fname, sfname, lnum, use_curbuf) buflist_setlnum(buf, lnum); /* copy the options now, if 'cpo' doesn't have 's' and not done * already */ - buf_copy_options(curbuf, buf, FALSE); + buf_copy_options(curbuf, buf, FALSE, FALSE); return buf; } @@ -566,6 +630,7 @@ buflist_new(fname, sfname, lnum, use_curbuf) { vim_free(buf->b_winlnum); free_buf_options(buf); + vim_free(buf); } return NULL; } @@ -578,11 +643,6 @@ buflist_new(fname, sfname, lnum, use_curbuf) else { /* - * Copy the options from the current buffer. - */ - buf_copy_options(curbuf, buf, FALSE); - - /* * put new buffer at the end of the buffer list */ buf->b_next = NULL; @@ -610,6 +670,11 @@ buflist_new(fname, sfname, lnum, use_curbuf) buf->b_winlnum->wl_next = NULL; buf->b_winlnum->wl_prev = NULL; buf->b_winlnum->wl_win = curwin; + + /* + * Always copy the options from the current buffer. + */ + buf_copy_options(curbuf, buf, FALSE, TRUE); } if (did_cd) @@ -626,9 +691,9 @@ buflist_new(fname, sfname, lnum, use_curbuf) } /* - * Free the memory for a BUF structure and its options + * Free the memory for the options of a buffer. */ - static void + void free_buf_options(buf) BUF *buf; { @@ -642,7 +707,6 @@ free_buf_options(buf) #if defined(CINDENT) || defined(SMARTINDENT) free_string_option(buf->b_p_cinw); #endif - vim_free(buf); } /* @@ -654,10 +718,11 @@ free_buf_options(buf) * return FAIL for failure, OK for success */ int -buflist_getfile(n, lnum, options) +buflist_getfile(n, lnum, options, forceit) int n; linenr_t lnum; int options; + int forceit; { BUF *buf; @@ -679,7 +744,8 @@ buflist_getfile(n, lnum, options) if (lnum == 0) lnum = buflist_findlnum(buf); ++RedrawingDisabled; - if (getfile(buf->b_fnum, NULL, NULL, (options & GETF_SETMARK), lnum) <= 0) + if (getfile(buf->b_fnum, NULL, NULL, (options & GETF_SETMARK), + lnum, forceit) <= 0) { --RedrawingDisabled; return OK; @@ -1290,7 +1356,7 @@ fileinfo(fullname, shorthelp, dont_truncate) (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); } - append_arg_number(buffer, !shortmess(SHM_FILE)); + (void)append_arg_number(buffer, !shortmess(SHM_FILE), IOSIZE); if (dont_truncate) msg(buffer); @@ -1372,24 +1438,40 @@ maketitle() { char_u *t_name; char_u *i_name; + int maxlen; + int len; if (curbuf->b_filename == NULL) { - t_name = (char_u *)""; + t_name = (char_u *)"VIM -"; i_name = (char_u *)"No File"; } else { - home_replace(curbuf, curbuf->b_filename, IObuff, IOSIZE); - append_arg_number(IObuff, FALSE); + STRCPY(IObuff, "VIM - "); + home_replace(curbuf, curbuf->b_filename, IObuff + 6, IOSIZE - 6); + append_arg_number(IObuff, FALSE, IOSIZE); + if (p_titlelen > 0) + { + maxlen = p_titlelen * Columns / 100; + if (maxlen < 10) + maxlen = 10; + len = STRLEN(IObuff); + if (len > maxlen) + { + vim_memmove(IObuff + 6, IObuff + 6 + len - maxlen, + (size_t)maxlen - 5); + IObuff[5] = '<'; + } + } t_name = IObuff; i_name = gettail(curbuf->b_filename); /* use filename only for icon */ } vim_free(lasttitle); - if (p_title && (lasttitle = alloc((unsigned)(strsize(t_name) + 7))) != NULL) + if (p_title && (lasttitle = alloc((unsigned)(strsize(t_name) + 1))) != NULL) { - STRCPY(lasttitle, "VIM - "); + *lasttitle = NUL; while (*t_name) STRCAT(lasttitle, transchar(*t_name++)); } @@ -1410,26 +1492,33 @@ maketitle() } /* - * Append (file 2 of 8) to 'buf'. + * Append (file 2 of 8) to 'buf', if editing more than one file. + * Return TRUE if it was appended. */ - static void -append_arg_number(buf, add_file) + static int +append_arg_number(buf, add_file, maxlen) char_u *buf; - int add_file; /* Add "file" before the arg number */ + int add_file; /* Add "file" before the arg number */ + int maxlen; /* maximum nr of chars in buf */ { - if (arg_count <= 1) /* nothing to do */ - return; + char_u *p; + + if (arg_count <= 1) /* nothing to do */ + return FALSE; - buf += STRLEN(buf); /* go to the end of the buffer */ - *buf++ = ' '; - *buf++ = '('; + p = buf + STRLEN(buf); /* go to the end of the buffer */ + if (p - buf + 35 >= maxlen) /* getting too long */ + return FALSE; + *p++ = ' '; + *p++ = '('; if (add_file) { - STRCPY(buf, "file "); - buf += 5; + STRCPY(p, "file "); + p += 5; } - sprintf((char *)buf, curwin->w_arg_idx_invalid ? "(%d) of %d)" : - "%d of %d)", curwin->w_arg_idx + 1, arg_count); + sprintf((char *)p, curwin->w_arg_idx_invalid ? "(%d) of %d)" : + "%d of %d)", curwin->w_arg_idx + 1, arg_count); + return TRUE; } /* @@ -1501,10 +1590,12 @@ do_arg_all(count) /* EMSG("Argument list contains less than 2 files"); */ return; } + /* * 1. close all but first window * 2. make the desired number of windows - * 3. start editing in the windows + * 3. start editing one file in each window + * arg_count may change while doing this, because of autocommands. */ setpcmark(); close_others(FALSE); @@ -1512,22 +1603,46 @@ do_arg_all(count) if (count > arg_count || count <= 0) count = arg_count; count = make_windows(count); - for (i = 0; i < count; ++i) + +#ifdef AUTOCMD + /* + * Don't execute Win/Buf Enter/Leave autocommands here + */ + ++autocmd_no_enter; + ++autocmd_no_leave; +#endif + for (i = 0; i < count && i < arg_count && !got_int; ++i) { - /* edit file i */ - (void)do_ecmd(0, arg_files[i], NULL, NULL, TRUE, (linenr_t)1, FALSE); - curwin->w_arg_idx = i; if (i == arg_count - 1) arg_had_last = TRUE; + curwin->w_arg_idx = i; +#ifdef AUTOCMD + if (i == 0) /* first window: do autocmd for leaving this buffer */ + --autocmd_no_leave; +#endif + /* edit file i */ + (void)do_ecmd(0, arg_files[i], NULL, NULL, (linenr_t)1, + ECMD_HIDE + ECMD_OLDBUF); +#ifdef AUTOCMD + if (i == 0) + ++autocmd_no_leave; +#endif if (curwin->w_next == NULL) /* just checking */ break; win_enter(curwin->w_next, FALSE); + mch_breakcheck(); } +#ifdef AUTOCMD + --autocmd_no_enter; +#endif win_enter(firstwin, FALSE); /* back to first window */ +#ifdef AUTOCMD + --autocmd_no_leave; +#endif } /* - * do_arg_all: open a window for each buffer + * do_buffer_all: open a window for each buffer * * 'count' is the maximum number of windows to open. * when 'all' is TRUE, also load inactive buffers @@ -1559,27 +1674,70 @@ do_buffer_all(count, all) * 1. close all but first window * 2. make the desired number of windows * 3. stuff commands to fill the windows + * Watch out for autocommands that delete buffers or windows. */ close_others(FALSE); curwin->w_arg_idx = 0; if (buf_count > count) buf_count = count; buf_count = make_windows(buf_count); + +#ifdef AUTOCMD + /* + * Don't execute Win/Buf Enter/Leave autocommands here + */ + ++autocmd_no_enter; + ++autocmd_no_leave; +#endif buf = firstbuf; for (i = 0; i < buf_count; ++i) { + /* find buffer number to put in this window */ for ( ; buf != NULL; buf = buf->b_next) if (all || buf->b_ml.ml_mfp != NULL) break; if (buf == NULL) /* Cannot happen? */ break; + + /* advance to next window */ if (i != 0) - stuffReadbuff((char_u *)"\n\027\027:"); /* CTRL-W CTRL-W */ - stuffReadbuff((char_u *)":buf "); /* edit Nth buffer */ - stuffnumReadbuff((long)buf->b_fnum); + { + if (curwin->w_next == NULL) /* just checking */ + break; + win_enter(curwin->w_next, FALSE); + } + +#ifdef AUTOCMD + if (i == 0) /* first window: do autocmd for leaving this buffer */ + --autocmd_no_leave; +#endif + + /* get buffer for this window */ + (void)do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, (int)buf->b_fnum, 0); +#ifdef AUTOCMD + if (i == 0) + ++autocmd_no_leave; + if (!buf_valid(buf)) /* autocommands deleted the buffer!!! */ + break; +#endif + + mch_breakcheck(); + if (got_int) + { + (void)vgetc(); /* only break the file loading, not the rest */ + break; + } buf = buf->b_next; } - stuffReadbuff((char_u *)"\n100\027k"); /* back to first window */ +#ifdef AUTOCMD + --autocmd_no_enter; +#endif + win_enter(firstwin, FALSE); /* back to first window */ +#ifdef AUTOCMD + --autocmd_no_leave; +#endif + if (buf_count > 1) + win_equal(curwin, FALSE); /* adjust heights */ } /* diff --git a/usr.bin/vim/cmdcmds.c b/usr.bin/vim/cmdcmds.c index 6c2aa48fba2..c70a04cab74 100644 --- a/usr.bin/vim/cmdcmds.c +++ b/usr.bin/vim/cmdcmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdcmds.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: cmdcmds.c,v 1.2 1996/09/21 06:22:52 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -16,20 +16,14 @@ #include "proto.h" #include "option.h" -#ifdef USE_TMPNAM -# define mktemp(a) tmpnam(a) -#endif - -extern char *mktemp __ARGS((char *)); - -#ifdef OS2 -static void check_tmpenv __ARGS((void)); -#endif - +static void do_filter __ARGS((linenr_t line1, linenr_t line2, + char_u *buff, int do_in, int do_out)); #ifdef VIMINFO static char_u *viminfo_filename __ARGS((char_u *)); -static void do_viminfo __ARGS((FILE *fp_in, FILE *fp_out, int want_info, int want_marks, int force_read)); -static int read_viminfo_up_to_marks __ARGS((char_u *line, FILE *fp, int force)); +static void do_viminfo __ARGS((FILE *fp_in, FILE *fp_out, int want_info, + int want_marks, int force_read)); +static int read_viminfo_up_to_marks __ARGS((char_u *line, FILE *fp, + int forceit)); #endif /* VIMINFO */ void @@ -41,6 +35,11 @@ do_ascii() char_u buf3[3]; c = gchar_cursor(); + if (c == NUL) + { + MSG("empty line"); + return; + } if (c == NL) /* NUL is stored as NL */ c = NUL; if (isprintchar(c) && (c < ' ' || c > '~')) @@ -142,11 +141,11 @@ do_align(start, end, width, type) } void -do_retab(start, end, new_ts, force) +do_retab(start, end, new_ts, forceit) linenr_t start; linenr_t end; int new_ts; - int force; + int forceit; { linenr_t lnum; int got_tab = FALSE; @@ -189,7 +188,7 @@ do_retab(start, end, new_ts, force) } else { - if (got_tab || (force && num_spaces > 1)) + if (got_tab || (forceit && num_spaces > 1)) { /* Retabulate this string of white-space */ @@ -506,20 +505,34 @@ do_bang(addr_count, line1, line2, forceit, arg, do_in, do_out) AppendToRedobuff((char_u *)"\n"); bangredo = FALSE; } + /* + * Add quotes around the command, for shells that need them. + */ + if (*p_shq != NUL) + { + newcmd = alloc((unsigned)(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1)); + if (newcmd == NULL) + return; + STRCPY(newcmd, p_shq); + STRCAT(newcmd, prevcmd); + STRCAT(newcmd, p_shq); + } if (addr_count == 0) /* :! */ { /* echo the command */ msg_start(); msg_outchar(':'); msg_outchar('!'); - msg_outtrans(prevcmd); + msg_outtrans(newcmd); msg_clr_eos(); windgoto(msg_row, msg_col); - do_shell(prevcmd); + do_shell(newcmd); } else /* :range! */ - do_filter(line1, line2, prevcmd, do_in, do_out); + do_filter(line1, line2, newcmd, do_in, do_out); + if (newcmd != prevcmd) + vim_free(newcmd); } /* @@ -591,7 +604,9 @@ do_shell(cmd) msg_pos((int)Rows - 1, 0); #ifdef AUTOCMD - if (!autocmd_busy) + if (autocmd_busy) + must_redraw = CLEAR; + else #endif { /* @@ -630,10 +645,6 @@ do_shell(cmd) } #endif /* AMIGA */ } -#ifdef AUTOCMD - else - must_redraw = CLEAR; -#endif } /* @@ -649,21 +660,19 @@ do_shell(cmd) * We use input redirection if do_in is TRUE. * We use output redirection if do_out is TRUE. */ - void + static void do_filter(line1, line2, buff, do_in, do_out) linenr_t line1, line2; char_u *buff; int do_in, do_out; { -#ifdef USE_TMPNAM - char_u itmp[L_tmpnam]; /* use tmpnam() */ - char_u otmp[L_tmpnam]; -#else - char_u itmp[TMPNAMELEN]; - char_u otmp[TMPNAMELEN]; -#endif + char_u *itmp = NULL; + char_u *otmp = NULL; linenr_t linecount; FPOS cursor_save; +#ifdef AUTOCMD + BUF *old_curbuf = curbuf; +#endif /* * Disallow shell commands from .exrc and .vimrc in current directory for @@ -700,22 +709,11 @@ do_filter(line1, line2, buff, do_in, do_out) * 6. Remove the temp files */ -#ifndef USE_TMPNAM /* tmpnam() will make its own name */ -# ifdef OS2 - check_tmpenv(); - expand_env(TMPNAME1, itmp, TMPNAMELEN); - expand_env(TMPNAME2, otmp, TMPNAMELEN); -# else - STRCPY(itmp, TMPNAME1); - STRCPY(otmp, TMPNAME2); -# endif -#endif - - if ((do_in && *mktemp((char *)itmp) == NUL) || - (do_out && *mktemp((char *)otmp) == NUL)) + if ((do_in && (itmp = vim_tempname('i')) == NULL) || + (do_out && (otmp = vim_tempname('o')) == NULL)) { emsg(e_notmp); - return; + goto filterend; } /* @@ -724,13 +722,18 @@ do_filter(line1, line2, buff, do_in, do_out) */ ++no_wait_return; /* don't call wait_return() while busy */ if (do_in && buf_write(curbuf, itmp, NULL, line1, line2, - FALSE, 0, FALSE, TRUE) == FAIL) + FALSE, FALSE, FALSE, TRUE) == FAIL) { msg_outchar('\n'); /* keep message from buf_write() */ --no_wait_return; (void)emsg2(e_notcreate, itmp); /* will call wait_return */ goto filterend; } +#ifdef AUTOCMD + if (curbuf != old_curbuf) + goto filterend; +#endif + if (!do_out) msg_outchar('\n'); @@ -754,15 +757,17 @@ do_filter(line1, line2, buff, do_in, do_out) { char_u *p; /* - * If there is a pipe, we have to put the '<' in front of it + * If there is a pipe, we have to put the '<' in front of it. + * Don't do this when 'shellquote' is not empty, otherwise the redirection + * would be inside the quotes. */ p = vim_strchr(IObuff, '|'); - if (p) + if (p && *p_shq == NUL) *p = NUL; STRCAT(IObuff, " < "); STRCAT(IObuff, itmp); p = vim_strchr(buff, '|'); - if (p) + if (p && *p_shq == NUL) STRCAT(IObuff, p); } #endif @@ -824,6 +829,10 @@ do_filter(line1, line2, buff, do_in, do_out) emsg2(e_notread, otmp); goto error; } +#ifdef AUTOCMD + if (curbuf != old_curbuf) + goto filterend; +#endif if (do_in) { @@ -832,6 +841,8 @@ do_filter(line1, line2, buff, do_in, do_out) dellines(linecount, TRUE, TRUE); curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ curbuf->b_op_end.lnum -= linecount; /* adjust '] */ + write_lnum_adjust(-linecount); /* adjust last line + for next write */ } else { @@ -864,35 +875,26 @@ error: } filterend: - vim_remove(itmp); - vim_remove(otmp); -} - -#ifdef OS2 -/* - * If $TMP is not defined, construct a sensible default. - * This is required for TMPNAME1 and TMPNAME2 to work. - */ - static void -check_tmpenv() -{ - char_u *envent; - if (getenv("TMP") == NULL) +#ifdef AUTOCMD + if (curbuf != old_curbuf) { - envent = alloc(8); - if (envent != NULL) - { - strcpy(envent, "TMP=C:/"); - putenv(envent); - } + --no_wait_return; + EMSG("*Filter* Autocommands must not change current buffer"); } +#endif + if (itmp != NULL) + vim_remove(itmp); + if (otmp != NULL) + vim_remove(otmp); + vim_free(itmp); + vim_free(otmp); } -#endif /* OS2 */ #ifdef VIMINFO static int no_viminfo __ARGS((void)); +static int viminfo_errcnt; static int no_viminfo() @@ -902,15 +904,35 @@ no_viminfo() } /* + * Report an error for reading a viminfo file. + * Count the number of errors. When there are more than 10, return TRUE. + */ + int +viminfo_error(message, line) + char *message; + char_u *line; +{ + sprintf((char *)IObuff, "viminfo: %s in line: ", message); + STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff)); + emsg(IObuff); + if (++viminfo_errcnt >= 10) + { + EMSG("viminfo: Too many errors, skipping rest of file"); + return TRUE; + } + return FALSE; +} + +/* * read_viminfo() -- Read the viminfo file. Registers etc. which are already * set are not over-written unless force is TRUE. -- webb */ int -read_viminfo(file, want_info, want_marks, force) +read_viminfo(file, want_info, want_marks, forceit) char_u *file; int want_info; int want_marks; - int force; + int forceit; { FILE *fp; @@ -921,7 +943,8 @@ read_viminfo(file, want_info, want_marks, force) if ((fp = fopen((char *)file, READBIN)) == NULL) return FAIL; - do_viminfo(fp, NULL, want_info, want_marks, force); + viminfo_errcnt = 0; + do_viminfo(fp, NULL, want_info, want_marks, forceit); fclose(fp); @@ -932,34 +955,21 @@ read_viminfo(file, want_info, want_marks, force) * write_viminfo() -- Write the viminfo file. The old one is read in first so * that effectively a merge of current info and old info is done. This allows * multiple vims to run simultaneously, without losing any marks etc. If - * force is TRUE, then the old file is not read in, and only internal info is + * forceit is TRUE, then the old file is not read in, and only internal info is * written to the file. -- webb */ void -write_viminfo(file, force) +write_viminfo(file, forceit) char_u *file; - int force; + int forceit; { FILE *fp_in = NULL; FILE *fp_out = NULL; -#ifdef USE_TMPNAM - char_u tmpname[L_tmpnam]; /* use tmpnam() */ -#else - char_u tmpname[TMPNAMELEN]; -#endif + char_u *tempname = NULL; if (no_viminfo()) return; -#ifndef USE_TMPNAM /* tmpnam() will make its own name */ -# ifdef OS2 - check_tmpenv(); - expand_env(TMPNAME2, tmpname, TMPNAMELEN); -# else - STRCPY(tmpname, TMPNAME2); -# endif -#endif - file = viminfo_filename(file); /* may set to default if NULL */ file = strsave(file); /* make a copy, don't want NameBuff */ if (file != NULL) @@ -967,29 +977,34 @@ write_viminfo(file, force) fp_in = fopen((char *)file, READBIN); if (fp_in == NULL) fp_out = fopen((char *)file, WRITEBIN); - else if (*mktemp((char *)tmpname) != NUL) - fp_out = fopen((char *)tmpname, WRITEBIN); + else if ((tempname = vim_tempname('o')) != NULL) + fp_out = fopen((char *)tempname, WRITEBIN); } if (file == NULL || fp_out == NULL) { EMSG2("Can't write viminfo file %s!", file == NULL ? (char_u *)"" : - fp_in == NULL ? file : tmpname); + fp_in == NULL ? file : tempname); if (fp_in != NULL) fclose(fp_in); - vim_free(file); - return; + goto end; } - do_viminfo(fp_in, fp_out, !force, !force, FALSE); + viminfo_errcnt = 0; + do_viminfo(fp_in, fp_out, !forceit, !forceit, FALSE); fclose(fp_out); /* errors are ignored !? */ if (fp_in != NULL) { fclose(fp_in); - if (vim_rename(tmpname, file) == -1) - vim_remove(tmpname); + /* + * In case of an error, don't overwrite the original viminfo file. + */ + if (viminfo_errcnt || vim_rename(tempname, file) == -1) + vim_remove(tempname); } +end: vim_free(file); + vim_free(tempname); } static char_u * @@ -1055,14 +1070,14 @@ do_viminfo(fp_in, fp_out, want_info, want_marks, force_read) * are local to a file. Returns TRUE when end-of-file is reached. -- webb */ static int -read_viminfo_up_to_marks(line, fp, force) +read_viminfo_up_to_marks(line, fp, forceit) char_u *line; FILE *fp; - int force; + int forceit; { int eof; - prepare_viminfo_history(force ? 9999 : 0); + prepare_viminfo_history(forceit ? 9999 : 0); eof = vim_fgets(line, LSIZE, fp); while (!eof && line[0] != '>') { @@ -1075,15 +1090,15 @@ read_viminfo_up_to_marks(line, fp, force) eof = vim_fgets(line, LSIZE, fp); break; case '"': - eof = read_viminfo_register(line, fp, force); + eof = read_viminfo_register(line, fp, forceit); break; case '/': /* Search string */ case '&': /* Substitute search string */ case '~': /* Last search string, followed by '/' or '&' */ - eof = read_viminfo_search_pattern(line, fp, force); + eof = read_viminfo_search_pattern(line, fp, forceit); break; case '$': - eof = read_viminfo_sub_string(line, fp, force); + eof = read_viminfo_sub_string(line, fp, forceit); break; case ':': case '?': @@ -1093,7 +1108,7 @@ read_viminfo_up_to_marks(line, fp, force) /* How do we have a file mark when the file is not in the * buffer list? */ - eof = read_viminfo_filemark(line, fp, force); + eof = read_viminfo_filemark(line, fp, forceit); break; #if 0 case '+': @@ -1102,8 +1117,10 @@ read_viminfo_up_to_marks(line, fp, force) break; #endif default: - EMSG2("viminfo: Illegal starting char in line %s", line); - eof = vim_fgets(line, LSIZE, fp); + if (viminfo_error("Illegal starting char", line)) + eof = TRUE; + else + eof = vim_fgets(line, LSIZE, fp); break; } } @@ -1197,7 +1214,7 @@ print_line(lnum, use_number) } /* - * Implementation of ":file [fname]". + * Implementation of ":file[!] [fname]". */ void do_file(arg, forceit) diff --git a/usr.bin/vim/cmdline.c b/usr.bin/vim/cmdline.c index 7be28f5cfcf..e720addc5cf 100644 --- a/usr.bin/vim/cmdline.c +++ b/usr.bin/vim/cmdline.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdline.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: cmdline.c,v 1.2 1996/09/21 06:22:54 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -37,14 +37,6 @@ static int cmdfirstc; /* ':', '/' or '?' */ */ static int overstrike = FALSE; /* typing mode */ -/* - * The next two variables contain the bounds of any range given in a command. - * They are set by do_cmdline(). - */ -static linenr_t line1, line2; - -static int forceit; -static int regname; static int quitmore = 0; static int cmd_numfiles = -1; /* number of files found by filename completion */ @@ -70,16 +62,16 @@ static void cursorcmd __ARGS((void)); static int ccheck_abbr __ARGS((int)); static char_u *do_one_cmd __ARGS((char_u **, int *, int)); static int buf_write_all __ARGS((BUF *)); -static int do_write __ARGS((char_u *, int)); +static int do_write __ARGS((char_u *, linenr_t, linenr_t, int, int)); static char_u *getargcmd __ARGS((char_u **)); static void backslash_halve __ARGS((char_u *p, int expand_wildcards)); static void do_make __ARGS((char_u *)); static int do_arglist __ARGS((char_u *)); static int is_backslash __ARGS((char_u *str)); -static int check_readonly __ARGS((void)); -static int check_changed __ARGS((BUF *, int, int)); +static int check_readonly __ARGS((int)); +static int check_changed __ARGS((BUF *, int, int, int)); static int check_changed_any __ARGS((void)); -static int check_more __ARGS((int)); +static int check_more __ARGS((int, int)); static void vim_strncpy __ARGS((char_u *, char_u *, int)); static int nextwild __ARGS((int)); static int showmatches __ARGS((char_u *)); @@ -315,6 +307,7 @@ getcmdline(firstc, count) if (lookfor && c != K_S_DOWN && c != K_S_UP && c != K_DOWN && c != K_UP && c != K_PAGEDOWN && c != K_PAGEUP && + c != K_KPAGEDOWN && c != K_KPAGEUP && (cmd_numfiles > 0 || (c != Ctrl('P') && c != Ctrl('N')))) { vim_free(lookfor); @@ -545,12 +538,14 @@ getcmdline(firstc, count) case Ctrl('B'): /* begin of command line */ case K_HOME: + case K_KHOME: cmdpos = 0; cmdspos = 1; goto cmdline_not_changed; case Ctrl('E'): /* end of command line */ case K_END: + case K_KEND: cmdpos = cmdlen; cmdbuff[cmdlen] = NUL; cmdspos = strsize(cmdbuff) + 1; @@ -580,7 +575,9 @@ getcmdline(firstc, count) case K_S_UP: case K_S_DOWN: case K_PAGEUP: + case K_KPAGEUP: case K_PAGEDOWN: + case K_KPAGEDOWN: if (hislen == 0) /* no history */ goto cmdline_not_changed; @@ -596,7 +593,7 @@ getcmdline(firstc, count) { /* one step backwards */ if (c == K_UP || c == K_S_UP || c == Ctrl('P') || - c == K_PAGEUP) + c == K_PAGEUP || c == K_KPAGEUP) { if (hiscnt == hislen) /* first time */ hiscnt = hisidx[histype]; @@ -1164,14 +1161,18 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) long argt; register linenr_t lnum; long n = 0; /* init to shut up gcc */ + linenr_t line1 = 1, line2 = 1; /* the command range */ int addr_count; /* number of address specs */ + int forceit = FALSE; /* '!' after command */ FPOS pos; int append = FALSE; /* write with append */ int usefilter = FALSE; /* no read/write but filter */ + int regname = 0; /* register name flag */ char_u *nextcomm = NULL; /* no next command yet */ int amount = 0; /* for ":>"; init for gcc */ char_u *errormsg = NULL; /* error message */ WIN *old_curwin = NULL; /* init for GCC */ + static int if_level = 0; /* depth in :if */ /* when not editing the last file :q has to be typed twice */ if (quitmore) @@ -1206,6 +1207,9 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) */ addr_count = 0; + if (if_level) + goto skip_address; + --cmd; do { @@ -1261,6 +1265,7 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) if (lnum == MAXLNUM) addr_count = 0; } +skip_address: /* * 4. parse command @@ -1287,6 +1292,8 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) * ":3|..." prints line 3 * ":|" prints current line */ + if (if_level) /* skip this if inside :if */ + goto doend; if (*cmd == '|') { cmdidx = CMD_print; @@ -1341,17 +1348,33 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) break; if (i == 0 || cmdidx == CMD_SIZE) { - STRCPY(IObuff, "Not an editor command"); - if (!sourcing) + if (if_level == 0) { - STRCAT(IObuff, ": "); - STRNCAT(IObuff, *cmdlinep, 40); + STRCPY(IObuff, "Not an editor command"); + if (!sourcing) + { + STRCAT(IObuff, ": "); + STRNCAT(IObuff, *cmdlinep, 40); + } + errormsg = IObuff; } - errormsg = IObuff; goto doend; } } +/* + * Handle the future ":if" command. + * For version 4 everything between ":if" and ":endif" is ignored. + */ + if (cmdidx == CMD_if) + ++if_level; + if (if_level) + { + if (cmdidx == CMD_endif) + --if_level; + goto doend; + } + if (*p == '!') /* forced commands */ { ++p; @@ -1571,7 +1594,6 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) line2 = curbuf->b_ml.ml_line_count; } - regname = 0; /* accept numbered register only when no count allowed (:put) */ if ((argt & REGSTR) && *arg != NUL && is_yank_buffer(*arg, FALSE) && !((argt & COUNT) && isdigit(*arg))) @@ -1646,10 +1668,12 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) #define SPEC_CCWORD 3 "<cfile>", /* cursor path name */ #define SPEC_CFILE 4 +#ifdef AUTOCMD "<afile>" /* autocommand file name */ -#define SPEC_AFILE 5 +# define SPEC_AFILE 5 +#endif }; -#define SPEC_COUNT 6 +#define SPEC_COUNT (sizeof(spec_str) / sizeof(char *)) /* * Decide to expand wildcards *before* replacing '%', '#', etc. If @@ -1660,6 +1684,12 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) for (p = arg; *p; ++p) { /* + * Quick check if this cannot be the start of a special string. + */ + if (vim_strchr((char_u *)"%#<", *p) == NULL) + continue; + + /* * Check if there is something to do. */ for (spec_idx = 0; spec_idx < SPEC_COUNT; ++spec_idx) @@ -1733,6 +1763,7 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) buf = q; break; +#ifdef AUTOCMD case SPEC_AFILE: /* file name for autocommand */ q = autocmd_fname; if (q == NULL) @@ -1741,6 +1772,7 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) goto doend; } break; +#endif } len = STRLEN(q); /* length of new string */ @@ -1771,13 +1803,15 @@ do_one_cmd(cmdlinep, cmdlinelenp, sourcing) /* ":h" - head, remove "/filename" */ /* ":h" can be repeated */ + /* Don't remove the first "/" or "c:\" */ while (p[n] == ':' && p[n + 1] == 'h') { n += 2; - while (tail > q && ispathsep(tail[-1])) + s = get_past_head(q); + while (tail > s && ispathsep(tail[-1])) --tail; len = tail - q; - while (tail > q && !ispathsep(tail[-1])) + while (tail > s && !ispathsep(tail[-1])) --tail; } @@ -1975,11 +2009,11 @@ cmdswitch: */ case CMD_quit: /* if more files or windows we won't exit */ - if (check_more(FALSE) == OK && only_one_window()) + if (check_more(FALSE, forceit) == OK && only_one_window()) exiting = TRUE; - if (check_changed(curbuf, FALSE, FALSE) || - check_more(TRUE) == FAIL || - (only_one_window() && check_changed_any())) + if (check_changed(curbuf, FALSE, FALSE, forceit) || + check_more(TRUE, forceit) == FAIL || + (only_one_window() && !forceit && check_changed_any())) { exiting = FALSE; settmode(1); @@ -1995,7 +2029,7 @@ cmdswitch: */ case CMD_qall: exiting = TRUE; - if (!check_changed_any()) + if (forceit || !check_changed_any()) getout(0); exiting = FALSE; settmode(1); @@ -2043,12 +2077,12 @@ cmdswitch: case CMD_xit: case CMD_wq: /* if more files or windows we won't exit */ - if (check_more(FALSE) == OK && only_one_window()) + if (check_more(FALSE, forceit) == OK && only_one_window()) exiting = TRUE; if (((cmdidx == CMD_wq || curbuf->b_changed) && - do_write(arg, FALSE) == FAIL) || - check_more(TRUE) == FAIL || - (only_one_window() && check_changed_any())) + do_write(arg, line1, line2, FALSE, forceit) == FAIL) || + check_more(TRUE, forceit) == FAIL || + (only_one_window() && !forceit && check_changed_any())) { exiting = FALSE; settmode(1); @@ -2083,8 +2117,16 @@ cmdswitch: EMSG2("\"%s\" is readonly, use ! to write anyway", buf->b_xfilename); ++error; } - else if (buf_write_all(buf) == FAIL) - ++error; + else + { + if (buf_write_all(buf) == FAIL) + ++error; +#ifdef AUTOCMD + /* an autocommand may have deleted the buffer */ + if (!buf_valid(buf)) + buf = firstbuf; +#endif + } } } if (exiting) @@ -2103,7 +2145,7 @@ cmdswitch: case CMD_recover: /* recover file */ recoverymode = TRUE; - if (!check_changed(curbuf, FALSE, TRUE) && + if (!check_changed(curbuf, FALSE, TRUE, forceit) && (*arg == NUL || setfname(arg, NULL, TRUE) == OK)) ml_recover(); recoverymode = FALSE; @@ -2147,7 +2189,7 @@ cmdswitch: i = curwin->w_arg_idx - (int)line2; line1 = 1; line2 = curbuf->b_ml.ml_line_count; - if (do_write(arg, FALSE) == FAIL) + if (do_write(arg, line1, line2, FALSE, forceit) == FAIL) break; goto donextfile; @@ -2159,7 +2201,7 @@ do_next: * argument list is not redefined. */ if (!(p_hid || cmdidx == CMD_snext) && - check_changed(curbuf, TRUE, FALSE)) + check_changed(curbuf, TRUE, FALSE, forceit)) break; if (*arg != NUL) /* redefine file list */ @@ -2199,14 +2241,16 @@ donextfile: if (i < 0 || i >= arg_count) if (p_hid) other = otherfile(fix_fname(arg_files[i])); if ((!p_hid || !other) && - check_changed(curbuf, TRUE, !other)) + check_changed(curbuf, TRUE, !other, forceit)) break; } curwin->w_arg_idx = i; if (i == arg_count - 1) arg_had_last = TRUE; (void)do_ecmd(0, arg_files[curwin->w_arg_idx], - NULL, do_ecmd_cmd, p_hid, do_ecmd_lnum, FALSE); + NULL, do_ecmd_cmd, do_ecmd_lnum, + (p_hid ? ECMD_HIDE : 0) + + (forceit ? ECMD_FORCEIT : 0)); break; case CMD_previous: @@ -2319,7 +2363,7 @@ donextfile: if (i < 0 || i >= arg_count) if (usefilter) /* input lines to shell command */ do_bang(1, line1, line2, FALSE, arg, TRUE, FALSE); else - (void)do_write(arg, append); + (void)do_write(arg, line1, line2, append, forceit); break; /* @@ -2366,8 +2410,8 @@ donextfile: if (i < 0 || i >= arg_count) if ((cmdidx == CMD_new) && *arg == NUL) { setpcmark(); - (void)do_ecmd(0, NULL, NULL, do_ecmd_cmd, TRUE, - (linenr_t)1, FALSE); + (void)do_ecmd(0, NULL, NULL, do_ecmd_cmd, (linenr_t)1, + ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0)); } else if (cmdidx != CMD_split || *arg != NUL) { @@ -2375,8 +2419,9 @@ donextfile: if (i < 0 || i >= arg_count) if (cmdidx == CMD_view || cmdidx == CMD_sview) readonlymode = TRUE; setpcmark(); - (void)do_ecmd(0, arg, NULL, do_ecmd_cmd, p_hid, - do_ecmd_lnum, FALSE); + (void)do_ecmd(0, arg, NULL, do_ecmd_cmd, do_ecmd_lnum, + (p_hid ? ECMD_HIDE : 0) + + (forceit ? ECMD_FORCEIT : 0)); readonlymode = n; } else @@ -2385,6 +2430,7 @@ donextfile: if (i < 0 || i >= arg_count) * old window to new file */ if ((cmdidx == CMD_new || cmdidx == CMD_split) && *arg != NUL && curwin != old_curwin && + win_valid(old_curwin) && old_curwin->w_buffer != curbuf) old_curwin->w_alt_fnum = curbuf->b_fnum; break; @@ -2541,11 +2587,11 @@ donextfile: if (i < 0 || i >= arg_count) postponed_split = TRUE; /*FALLTHROUGH*/ case CMD_tag: - do_tag(arg, 0, addr_count ? (int)line2 : 1); + do_tag(arg, 0, addr_count ? (int)line2 : 1, forceit); break; case CMD_pop: - do_tag((char_u *)"", 1, addr_count ? (int)line2 : 1); + do_tag((char_u *)"", 1, addr_count ? (int)line2 : 1, forceit); break; case CMD_tags: @@ -2772,6 +2818,14 @@ doabbr: case CMD_put: yankbuffer = regname; + /* + * ":0put" works like ":1put!". + */ + if (line2 == 0) + { + line2 = 1; + forceit = TRUE; + } curwin->w_cursor.lnum = line2; do_put(forceit ? BACKWARD : FORWARD, -1L, FALSE); break; @@ -2940,7 +2994,7 @@ doabbr: } case CMD_cc: - qf_jump(0, addr_count ? (int)line2 : 0); + qf_jump(0, addr_count ? (int)line2 : 0, forceit); break; case CMD_cfile: @@ -2957,7 +3011,7 @@ doabbr: (void)do_set(arg); } if (qf_init() == OK) - qf_jump(0, 0); /* display first error */ + qf_jump(0, 0, forceit); /* display first error */ break; case CMD_clist: @@ -2965,16 +3019,17 @@ doabbr: break; case CMD_cnext: - qf_jump(FORWARD, addr_count ? (int)line2 : 1); + qf_jump(FORWARD, addr_count ? (int)line2 : 1, forceit); break; case CMD_cNext: case CMD_cprevious: - qf_jump(BACKWARD, addr_count ? (int)line2 : 1); + qf_jump(BACKWARD, addr_count ? (int)line2 : 1, forceit); break; case CMD_cquit: - getout(1); /* this does not always work. why? */ + getout(1); /* this does not always pass on the exit + code to the Manx compiler. why? */ case CMD_mark: case CMD_k: @@ -3095,7 +3150,6 @@ doend: } if (did_emsg) nextcomm = NULL; /* cancel nextcomm at an error */ - forceit = FALSE; /* reset now so it can be used in getfile() */ if (nextcomm && *nextcomm == NUL) /* not really a next command */ nextcomm = NULL; return nextcomm; @@ -3107,8 +3161,9 @@ doend: * return FAIL for failure, OK otherwise */ int -autowrite(buf) +autowrite(buf, forceit) BUF *buf; + int forceit; { if (!p_aw || (!forceit && buf->b_p_ro) || buf->b_filename == NULL) return FAIL; @@ -3127,7 +3182,14 @@ autowrite_all() return; for (buf = firstbuf; buf; buf = buf->b_next) if (buf->b_changed && !buf->b_p_ro) + { (void)buf_write_all(buf); +#ifdef AUTOCMD + /* an autocommand may have deleted the buffer */ + if (!buf_valid(buf)) + buf = firstbuf; +#endif + } } /* @@ -3139,8 +3201,19 @@ autowrite_all() buf_write_all(buf) BUF *buf; { - return (buf_write(buf, buf->b_filename, buf->b_sfilename, - (linenr_t)1, buf->b_ml.ml_line_count, 0, 0, TRUE, FALSE)); + int retval; +#ifdef AUTOCMD + BUF *old_curbuf = curbuf; +#endif + + retval = (buf_write(buf, buf->b_filename, buf->b_sfilename, + (linenr_t)1, buf->b_ml.ml_line_count, + FALSE, FALSE, TRUE, FALSE)); +#ifdef AUTOCMD + if (curbuf != old_curbuf) + MSG("Warning: Entered other buffer unexpectedly (check autocommands)"); +#endif + return retval; } /* @@ -3153,9 +3226,11 @@ buf_write_all(buf) * return FAIL for failure, OK otherwise */ static int -do_write(fname, append) - char_u *fname; - int append; +do_write(fname, line1, line2, append, forceit) + char_u *fname; + linenr_t line1, line2; + int append; + int forceit; { int other; char_u *sfname = NULL; /* init to shut up gcc */ @@ -3179,7 +3254,7 @@ do_write(fname, append) * writing to the current file is not allowed in readonly mode * and need a file name */ - if (!other && (check_readonly() || check_fname() == FAIL)) + if (!other && (check_readonly(forceit) || check_fname() == FAIL)) return FAIL; if (!other) @@ -3229,24 +3304,30 @@ do_write(fname, append) * - NULL to start an empty buffer * sfname: the short file name (or NULL) * command: the command to be executed after loading the file - * hide: if TRUE don't free the current buffer * newlnum: put cursor on this line number (if possible) - * set_help: set b_help flag of (new) buffer before opening file + * flags: + * ECMD_HIDE: if TRUE don't free the current buffer + * ECMD_SET_HELP: set b_help flag of (new) buffer before opening file + * ECMD_OLDBUF: use existing buffer if it exists + * ECMD_FORCEIT: ! used for Ex command * * return FAIL for failure, OK otherwise */ int -do_ecmd(fnum, fname, sfname, command, hide, newlnum, set_help) +do_ecmd(fnum, fname, sfname, command, newlnum, flags) int fnum; char_u *fname; char_u *sfname; char_u *command; - int hide; linenr_t newlnum; - int set_help; + int flags; { int other_file; /* TRUE if editing another file */ - int oldbuf = FALSE; /* TRUE if using existing buffer */ + int oldbuf; /* TRUE if using existing buffer */ +#ifdef AUTOCMD + int auto_buf = FALSE; /* TRUE if autocommands brought us + into the buffer unexpectedly */ +#endif BUF *buf; if (fnum != 0) @@ -3286,10 +3367,11 @@ do_ecmd(fnum, fname, sfname, command, hide, newlnum, set_help) /* * if the file was changed we may not be allowed to abandon it * - if we are going to re-edit the same file - * - or if we are the only window on this file and if hide is FALSE + * - or if we are the only window on this file and if ECMD_HIDE is FALSE */ - if ((!other_file || (curbuf->b_nwindows == 1 && !hide)) && - check_changed(curbuf, FALSE, !other_file)) + if (((!other_file && !(flags & ECMD_OLDBUF)) || + (curbuf->b_nwindows == 1 && !(flags & ECMD_HIDE))) && + check_changed(curbuf, FALSE, !other_file, (flags & ECMD_FORCEIT))) { if (fnum == 0 && other_file && fname != NULL) setaltfname(fname, sfname, (linenr_t)1); @@ -3321,57 +3403,94 @@ do_ecmd(fnum, fname, sfname, command, hide, newlnum, set_help) if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ { oldbuf = FALSE; - buf->b_nwindows = 1; + buf->b_nwindows = 0; } else /* existing memfile */ { oldbuf = TRUE; - ++buf->b_nwindows; buf_check_timestamp(buf); } /* - * make the (new) buffer the one used by the current window - * if the old buffer becomes unused, free it if hide is FALSE + * Make the (new) buffer the one used by the current window. + * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. * If the current buffer was empty and has no file name, curbuf * is returned by buflist_new(). */ if (buf != curbuf) { #ifdef AUTOCMD + BUF *old_curbuf; + char_u *new_name = NULL; + + /* + * Be careful: The autocommands may delete any buffer and change + * the current buffer. + * - If the buffer we are going to edit is deleted, give up. + * - If we ended up in the new buffer already, need to skip a few + * things, set auto_buf. + */ + old_curbuf = curbuf; + if (buf->b_xfilename != NULL) + new_name = strsave(buf->b_xfilename); apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); + if (!buf_valid(buf)) /* new buffer has been deleted */ + { + EMSG2("Autocommands unexpectedly deleted new buffer %s", + new_name == NULL ? (char_u *)"" : new_name); + vim_free(new_name); + return FAIL; + } + vim_free(new_name); + if (buf == curbuf) /* already in new buffer */ + auto_buf = TRUE; + else + { + if (curbuf == old_curbuf) #endif + { #ifdef VIMINFO - curbuf->b_last_cursor = curwin->w_cursor; + curbuf->b_last_cursor = curwin->w_cursor; +#endif + buf_copy_options(curbuf, buf, TRUE, FALSE); + } + close_buffer(curwin, curbuf, !(flags & ECMD_HIDE), FALSE); + curwin->w_buffer = buf; + curbuf = buf; + ++curbuf->b_nwindows; +#ifdef AUTOCMD + } #endif - buf_copy_options(curbuf, buf, TRUE); - close_buffer(curwin, curbuf, !hide, FALSE); - curwin->w_buffer = buf; - curbuf = buf; } + else + ++curbuf->b_nwindows; curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; } - else if (check_fname() == FAIL) - return FAIL; + else + { + if (check_fname() == FAIL) + return FAIL; + oldbuf = (flags & ECMD_OLDBUF); + } /* * If we get here we are sure to start editing */ /* don't redraw until the cursor is in the right line */ ++RedrawingDisabled; - if (set_help) + if (flags & ECMD_SET_HELP) curbuf->b_help = TRUE; /* * other_file oldbuf * FALSE FALSE re-edit same file, buffer is re-used - * FALSE TRUE not posible + * FALSE TRUE re-edit same file, nothing changes * TRUE FALSE start editing new file, new buffer * TRUE TRUE start editing in existing buffer (nothing to do) */ - if (!other_file) /* re-use the buffer */ + if (!other_file && !oldbuf) /* re-use the buffer */ { if (newlnum == 0) newlnum = curwin->w_cursor.lnum; @@ -3382,18 +3501,33 @@ do_ecmd(fnum, fname, sfname, command, hide, newlnum, set_help) } /* + * Reset cursor position, could be used by autocommands. + */ + adjust_cursor(); + + /* * Check if we are editing the w_arg_idx file in the argument list. */ check_arg_idx(); - if (!oldbuf) /* need to read the file */ - (void)open_buffer(); #ifdef AUTOCMD - else - apply_autocmds(EVENT_BUFENTER, NULL, NULL); + if (!auto_buf) +#endif + { + /* + * Careful: open_buffer() and apply_autocmds() may change the current + * buffer and window. + */ + if (!oldbuf) /* need to read the file */ + (void)open_buffer(); +#ifdef AUTOCMD + else + apply_autocmds(EVENT_BUFENTER, NULL, NULL); + check_arg_idx(); #endif - win_init(curwin); - maketitle(); + win_init(curwin); + maketitle(); + } if (command == NULL) { @@ -3411,7 +3545,11 @@ do_ecmd(fnum, fname, sfname, command, hide, newlnum, set_help) * Did not read the file, need to show some info about the file. * Do this after setting the cursor. */ - if (oldbuf) + if (oldbuf +#ifdef AUTOCMD + && !auto_buf +#endif + ) fileinfo(did_cd, TRUE, FALSE); if (command != NULL) @@ -3471,9 +3609,6 @@ backslash_halve(p, expand_wildcards) { for ( ; *p; ++p) if (is_backslash(p) -#if defined(MSDOS) || defined(WIN32) - && p[1] != '*' && p[1] != '?' -#endif #if defined(UNIX) || defined(OS2) && !(expand_wildcards && vim_strchr((char_u *)" *?[{`$\\", p[1])) @@ -3495,7 +3630,7 @@ do_make(arg) autowrite_all(); vim_remove(p_ef); - sprintf((char *)IObuff, "%s %s %s", arg, p_sp, p_ef); + sprintf((char *)IObuff, "%s%s%s %s %s", p_shq, arg, p_shq, p_sp, p_ef); MSG_OUTSTR(":!"); msg_outtrans(IObuff); /* show what we are doing */ do_shell(IObuff); @@ -3507,7 +3642,7 @@ do_make(arg) #endif if (qf_init() == OK) - qf_jump(0, 0); /* display first error */ + qf_jump(0, 0, FALSE); /* display first error */ vim_remove(p_ef); } @@ -3608,8 +3743,8 @@ is_backslash(str) char_u *str; { #ifdef BACKSLASH_IN_FILENAME - return (str[0] == '\\' && str[1] != NUL && - !(isfilechar(str[1]) && str[1] != '\\')); + return (str[0] == '\\' && str[1] != NUL && str[1] != '*' && str[1] != '?' + && !(isfilechar(str[1]) && str[1] != '\\')); #else return (str[0] == '\\' && str[1] != NUL); #endif @@ -3643,7 +3778,8 @@ gotocmdline(clr) } static int -check_readonly() +check_readonly(forceit) + int forceit; { if (!forceit && curbuf->b_p_ro) { @@ -3657,14 +3793,15 @@ check_readonly() * return TRUE if buffer was changed and cannot be abandoned. */ static int -check_changed(buf, checkaw, mult_win) +check_changed(buf, checkaw, mult_win, forceit) BUF *buf; int checkaw; /* do autowrite if buffer was changed */ int mult_win; /* check also when several windows for the buffer */ + int forceit; { if ( !forceit && buf->b_changed && (mult_win || buf->b_nwindows <= 1) && - (!checkaw || autowrite(buf) == FAIL)) + (!checkaw || autowrite(buf, forceit) == FAIL)) { emsg(e_nowrtmsg); return TRUE; @@ -3682,28 +3819,24 @@ check_changed_any() BUF *buf; int save; - if (!forceit) + for (buf = firstbuf; buf != NULL; buf = buf->b_next) { - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + if (buf->b_changed) { - if (buf->b_changed) + /* There must be a wait_return for this message, do_buffer + * will cause a redraw */ + exiting = FALSE; + if (EMSG2("No write since last change for buffer \"%s\"", + buf->b_xfilename == NULL ? (char_u *)"No File" : + buf->b_xfilename)) { - /* There must be a wait_return for this message, do_buffer - * will cause a redraw */ - exiting = FALSE; - if (EMSG2("No write since last change for buffer \"%s\"", - buf->b_xfilename == NULL ? (char_u *)"No File" : - buf->b_xfilename)) - { - save = no_wait_return; - no_wait_return = FALSE; - wait_return(FALSE); - no_wait_return = save; - } - (void)do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, - buf->b_fnum, 0); - return TRUE; + save = no_wait_return; + no_wait_return = FALSE; + wait_return(FALSE); + no_wait_return = save; } + (void)do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); + return TRUE; } } return FALSE; @@ -3733,8 +3866,9 @@ check_fname() * return OK otherwise */ static int -check_more(message) +check_more(message, forceit) int message; /* when FALSE check only, no messages */ + int forceit; { if (!forceit && only_one_window() && arg_count > 1 && !arg_had_last && quitmore == 0) @@ -3758,12 +3892,13 @@ check_more(message) * 'lnum' is the line number for the cursor in the new file (if non-zero). */ int -getfile(fnum, fname, sfname, setpm, lnum) +getfile(fnum, fname, sfname, setpm, lnum, forceit) int fnum; char_u *fname; char_u *sfname; int setpm; linenr_t lnum; + int forceit; { int other; @@ -3778,7 +3913,7 @@ getfile(fnum, fname, sfname, setpm, lnum) if (other) ++no_wait_return; /* don't wait for autowrite message */ if (other && !forceit && curbuf->b_nwindows == 1 && - !p_hid && curbuf->b_changed && autowrite(curbuf) == FAIL) + !p_hid && curbuf->b_changed && autowrite(curbuf, forceit) == FAIL) { if (other) --no_wait_return; @@ -3798,7 +3933,8 @@ getfile(fnum, fname, sfname, setpm, lnum) return 0; /* it's in the same file */ } - if (do_ecmd(fnum, fname, sfname, NULL, p_hid, lnum, FALSE) == OK) + if (do_ecmd(fnum, fname, sfname, NULL, lnum, + (p_hid ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0)) == OK) return -1; /* opened another file */ return 1; /* error encountered */ } @@ -3958,8 +4094,8 @@ ExpandOne(str, orig, options, mode) static char_u **cmd_files = NULL; /* list of input files */ static int findex; static char_u *orig_save = NULL; /* kept value of orig */ - int i, found = 0; - int multmatch = FALSE; + int i, j; + int non_suf_match; /* number without matching suffix */ long_u len; char_u *setsuf; int fnamelen, setsuflen; @@ -4036,21 +4172,10 @@ ExpandOne(str, orig, options, mode) else { /* - * If the pattern starts with a '~', replace the home diretory - * with '~' again. + * May change home directory back to "~" */ - if (*str == '~' && (options & WILD_HOME_REPLACE)) - { - for (i = 0; i < cmd_numfiles; ++i) - { - p = home_replace_save(NULL, cmd_files[i]); - if (p != NULL) - { - vim_free(cmd_files[i]); - cmd_files[i] = p; - } - } - } + if (options & WILD_HOME_REPLACE) + tilde_replace(str, cmd_numfiles, cmd_files); /* * Insert backslashes into a file name before a space, \, %, # and @@ -4079,9 +4204,10 @@ ExpandOne(str, orig, options, mode) if (mode != WILD_ALL && mode != WILD_LONGEST) { + non_suf_match = 1; if (cmd_numfiles > 1) /* more than one match; check suffix */ { - found = -2; + non_suf_match = 0; for (i = 0; i < cmd_numfiles; ++i) { fnamelen = STRLEN(cmd_files[i]); @@ -4098,15 +4224,17 @@ ExpandOne(str, orig, options, mode) } if (setsuflen) /* suffix matched: ignore file */ continue; - if (found >= 0) - { - multmatch = TRUE; - break; - } - found = i; + /* + * Move the name without matching suffix to the front + * of the list. This makes CTRL-N work nice. + */ + p = cmd_files[i]; + for (j = i; j > non_suf_match; --j) + cmd_files[j] = cmd_files[j - 1]; + cmd_files[non_suf_match++] = p; } } - if (multmatch || found < 0) + if (non_suf_match != 1) { /* Can we ever get here unless it's while expanding * interactively? If not, we can get rid of this all @@ -4117,11 +4245,9 @@ ExpandOne(str, orig, options, mode) emsg(e_toomany); else beep_flush(); - found = 0; /* return first one */ - multmatch = TRUE; /* for found < 0 */ } - if (found >= 0 && !(multmatch && mode == WILD_EXPAND_FREE)) - ss = strsave(cmd_files[found]); + if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) + ss = strsave(cmd_files[0]); } } } @@ -4187,6 +4313,33 @@ ExpandOne(str, orig, options, mode) } /* + * For each file name in files[num_files]: + * If 'orig_pat' starts with "~/", replace the home directory with "~". + */ + void +tilde_replace(orig_pat, num_files, files) + char_u *orig_pat; + int num_files; + char_u **files; +{ + int i; + char_u *p; + + if (orig_pat[0] == '~' && ispathsep(orig_pat[1])) + { + for (i = 0; i < num_files; ++i) + { + p = home_replace_save(NULL, files[i]); + if (p != NULL) + { + vim_free(files[i]); + files[i] = p; + } + } + } +} + +/* * show all matches for completion on the command line */ static int @@ -4738,7 +4891,7 @@ set_one_cmd_context(firstc, buff) int cmdidx; long argt; char_u delim; - int forced = FALSE; + int forceit = FALSE; int usefilter = FALSE; /* filter instead of file name */ expand_pattern = buff; @@ -4866,7 +5019,7 @@ set_one_cmd_context(firstc, buff) if (*p == '!') /* forced commands */ { - forced = TRUE; + forceit = TRUE; ++p; } @@ -4894,7 +5047,7 @@ set_one_cmd_context(firstc, buff) if (cmdidx == CMD_read) { - usefilter = forced; /* :r! filter if forced */ + usefilter = forceit; /* :r! filter if forced */ if (*arg == '!') /* :r !filter */ { ++arg; @@ -5116,7 +5269,7 @@ set_one_cmd_context(firstc, buff) case CMD_vmenu: case CMD_vnoremenu: case CMD_vunmenu: case CMD_imenu: case CMD_inoremenu: case CMD_iunmenu: case CMD_cmenu: case CMD_cnoremenu: case CMD_cunmenu: - return gui_set_context_in_menu_cmd(cmd, arg, forced); + return gui_set_context_in_menu_cmd(cmd, arg, forceit); break; #endif default: @@ -5194,7 +5347,7 @@ ExpandFromContext(pat, num_file, file, files_only, options) expand_context == EXPAND_BOOL_SETTINGS) ret = ExpandSettings(prog, num_file, file); else if (expand_context == EXPAND_TAGS) - ret = find_tags(NULL, prog, num_file, file, FALSE); + ret = find_tags(NULL, prog, num_file, file, FALSE, FALSE); #ifdef AUTOCMD else if (expand_context == EXPAND_EVENTS) ret = ExpandEvents(prog, num_file, file); diff --git a/usr.bin/vim/cmdtab.tab b/usr.bin/vim/cmdtab.tab index 4c7c5c799a7..b9639c8bd9d 100644 --- a/usr.bin/vim/cmdtab.tab +++ b/usr.bin/vim/cmdtab.tab @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdtab.tab,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: cmdtab.tab,v 1.2 1996/09/21 06:22:55 downsj Exp $ */ /* vi:ts=4:sw=4 * * VIM - Vi IMproved @@ -104,6 +104,7 @@ static struct {(char_u *)"dsearch", BANG+RANGE+DFLALL+EXTRA}, {(char_u *)"dsplit", BANG+RANGE+DFLALL+EXTRA+TRLBAR}, {(char_u *)"edit", BANG+FILE1+EDITCMD+TRLBAR}, + {(char_u *)"endif", RANGE+BANG+EXTRA}, {(char_u *)"ex", BANG+FILE1+EDITCMD+TRLBAR}, {(char_u *)"exit", RANGE+BANG+FILE1+DFLALL+TRLBAR}, {(char_u *)"file", BANG+FILE1+TRLBAR}, @@ -116,6 +117,7 @@ static struct {(char_u *)"insert", BANG+RANGE+TRLBAR}, /* not supported */ {(char_u *)"iabbrev", EXTRA+TRLBAR+NOTRLCOM+USECTRLV}, {(char_u *)"iabclear", TRLBAR}, + {(char_u *)"if", RANGE+BANG+EXTRA}, {(char_u *)"ijump", BANG+RANGE+DFLALL+EXTRA}, {(char_u *)"ilist", BANG+RANGE+DFLALL+EXTRA}, {(char_u *)"imap", EXTRA+TRLBAR+NOTRLCOM+USECTRLV}, @@ -167,7 +169,7 @@ static struct {(char_u *)"only", BANG+TRLBAR}, {(char_u *)"print", RANGE+COUNT+TRLBAR}, {(char_u *)"pop", RANGE+NOTADR+COUNT+TRLBAR+ZEROR}, - {(char_u *)"put", RANGE+BANG+REGSTR+TRLBAR}, + {(char_u *)"put", RANGE+BANG+REGSTR+TRLBAR+ZEROR}, {(char_u *)"preserve", TRLBAR}, {(char_u *)"previous", EXTRA+RANGE+NOTADR+COUNT+BANG+EDITCMD+TRLBAR}, {(char_u *)"pwd", TRLBAR}, diff --git a/usr.bin/vim/csearch.c b/usr.bin/vim/csearch.c index b9a1033a92c..049de7ca840 100644 --- a/usr.bin/vim/csearch.c +++ b/usr.bin/vim/csearch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: csearch.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: csearch.c,v 1.2 1996/09/21 06:22:56 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -647,7 +647,12 @@ do_glob(type, lp, up, cmd) global_busy = 0; - must_redraw = CLEAR; + /* + * Redraw everything. Could use CLEAR, which is faster in some + * situations, but when there are few changes this makes the display + * flicker. + */ + must_redraw = NOT_VALID; cursupdate(); /* If subsitutes done, report number of substitues, otherwise report diff --git a/usr.bin/vim/digraph.c b/usr.bin/vim/digraph.c index 957b793e1c5..bf36983c0ae 100644 --- a/usr.bin/vim/digraph.c +++ b/usr.bin/vim/digraph.c @@ -1,4 +1,4 @@ -/* $OpenBSD: digraph.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: digraph.c,v 1.2 1996/09/21 06:22:56 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -490,8 +490,7 @@ putdigraph(str) newtab = (char_u (*)[3])alloc(digraphcount * 3 + 3); if (newtab) { - vim_memmove((char *)newtab, (char *)digraphnew, - (size_t)(digraphcount * 3)); + vim_memmove(newtab, digraphnew, (size_t)(digraphcount * 3)); vim_free(digraphnew); digraphnew = newtab; digraphnew[digraphcount][0] = char1; diff --git a/usr.bin/vim/doc/doctags.c b/usr.bin/vim/doc/doctags.c index 64d436f0f15..c71d1cc5a7e 100644 --- a/usr.bin/vim/doc/doctags.c +++ b/usr.bin/vim/doc/doctags.c @@ -1,4 +1,4 @@ -/* $OpenBSD: doctags.c,v 1.1 1996/09/07 21:40:30 downsj Exp $ */ +/* $OpenBSD: doctags.c,v 1.2 1996/09/21 06:23:31 downsj Exp $ */ /* vim:set ts=4 sw=4: * this program makes a tags file for vim_ref.txt * @@ -54,7 +54,16 @@ main(argc, argv) characters */ { *p2 = '\0'; - printf("%s\t%s\t/\\*%s\\*\n", p1 + 1, argv[0], p1 + 1); + ++p1; + printf("%s\t%s\t/\\*", p1, argv[0]); + while (*p1) + { + if (*p1 == '\\') /* insert backslash */ + putchar('\\'); + putchar(*p1); + ++p1; + } + printf("\\*\n"); p2 = strchr(p2 + 1, '*'); } } diff --git a/usr.bin/vim/doc/vim_40.txt b/usr.bin/vim/doc/vim_40.txt index 720430400f1..6d4e1ba7a4c 100644 --- a/usr.bin/vim/doc/vim_40.txt +++ b/usr.bin/vim/doc/vim_40.txt @@ -1,4 +1,4 @@ -*vim_40.txt* For Vim version 4.2. Last modification: 1996 June 16 +*vim_40.txt* For Vim version 4.4. Last modification: 1996 Sep 1 Welcome to Vim Version 4.0! @@ -1406,6 +1406,10 @@ Added list of options that are enabled/disabled at compile time to ":version" command (+GUI -digraphs -eindent, etc.). For Unix, add a line to the ":version" command to show how it was compiled. |:version| +Added ":if" and ":endif" commands. Everything in between them is ignored. +This is just for being able to add future commands to vimrc files in a +backwards compatible way. |:if| + Made CTRL-N and CTRL-P for command-line completion line cyclic. |c_CTRL-N| "<cword>" in the command line where a file name is expected is expanded to diff --git a/usr.bin/vim/doc/vim_ami.txt b/usr.bin/vim/doc/vim_ami.txt index 6366564c2a5..2ba3374d7ca 100644 --- a/usr.bin/vim/doc/vim_ami.txt +++ b/usr.bin/vim/doc/vim_ami.txt @@ -1,4 +1,4 @@ -*vim_ami.txt* For Vim version 4.2. Last modification: 1996 Apr 19 +*vim_ami.txt* For Vim version 4.4. Last modification: 1996 Apr 19 This file contains the particularities for the Amiga version of Vim. diff --git a/usr.bin/vim/doc/vim_arch.txt b/usr.bin/vim/doc/vim_arch.txt index b5d40396146..a7fb9fb3b6f 100644 --- a/usr.bin/vim/doc/vim_arch.txt +++ b/usr.bin/vim/doc/vim_arch.txt @@ -1,4 +1,4 @@ -*vim_arch.txt* For Vim version 4.2. Last modification: 1996 Mar 6 +*vim_arch.txt* For Vim version 4.4. Last modification: 1996 Mar 6 This file contains the particularities for the Archimedes version of Vim. diff --git a/usr.bin/vim/doc/vim_diff.txt b/usr.bin/vim/doc/vim_diff.txt index 0b3ac232ed3..f9f0553718d 100644 --- a/usr.bin/vim/doc/vim_diff.txt +++ b/usr.bin/vim/doc/vim_diff.txt @@ -1,4 +1,4 @@ -*vim_diff.txt* For Vim version 4.2. Last modification: 1996 June 16 +*vim_diff.txt* For Vim version 4.4. Last modification: 1996 July 18 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}". @@ -700,7 +700,7 @@ the "-n" option. Use the 'directory' option for placing the .swp file somewhere else. The 'shortname' (sn) option, when set, tells Vim that ".bak" and ".swp" -filenames are to be MS-DOS-like: 8 characters plus 3 for extention. This +filenames are to be MS-DOS-like: 8 characters plus 3 for extension. This should be used on messydos or crossdos filesystems on the Amiga. If this option is off, Vim tries to guess if MS-DOS filename restrictions are effective. diff --git a/usr.bin/vim/doc/vim_digr.txt b/usr.bin/vim/doc/vim_digr.txt index 5635e49dbe2..a58d7723559 100644 --- a/usr.bin/vim/doc/vim_digr.txt +++ b/usr.bin/vim/doc/vim_digr.txt @@ -1,4 +1,4 @@ -*vim_digr.txt* For Vim version 4.2. Last modification: 1996 June 8 +*vim_digr.txt* For Vim version 4.4. Last modification: 1996 June 8 These are the default digraph characters for Vim. diff --git a/usr.bin/vim/doc/vim_dos.txt b/usr.bin/vim/doc/vim_dos.txt index 6e1ba5b8bcd..5a0860839ba 100644 --- a/usr.bin/vim/doc/vim_dos.txt +++ b/usr.bin/vim/doc/vim_dos.txt @@ -1,15 +1,21 @@ -*vim_dos.txt* For Vim version 4.2. Last modification: 1996 June 13 +*vim_dos.txt* For Vim version 4.4. Last modification: 1996 Aug 17 This file contains the particularities for the MS-DOS version of Vim. + +THREE VERSIONS FOR MS-DOS + There are Three versions of Vim that can be used with MS-DOS machines: 16-bit version Can be used on any MS-DOS system, only uses up to 640 Kbyte of memory. Also runs on OS/2, Windows 95, and NT. + Recommended for use on pre-386 machines. 32-bit version Requires 386 processor and a DPMI driver, uses all available memory. Supports long file names where available. + Recommended for MS-DOS, Windows 3.1 and Windows 95. Win32 version Requires Windows 95 or Windows NT, uses all available - memory, supports long file names, etc. See |vim_w32.txt| + memory, supports long file names, etc. Has some problems on + Windows 95. Recommended for Windows NT. See |vim_w32.txt| It is recommended to use the 32-bit or Win32 version. Although the 16-bit version is able to edit very big files, it quickly runs out of memory when @@ -23,7 +29,12 @@ run already. If you get the message "No DPMI", you need to install a DPMI driver. Such a driver is included with the executable. The latest version of "CWSDPMI.ZIP" can be obtained from: "ftp.neosoft.com:pub/users/s/sandmann". -Known problems: +If the 32-bit DOS version is run on Windows 95 or Windows NT, it can use long +filenames, as can the Win32 version. + + +KNOWN PROBLEMS + - When using smartdrive (MS-DOS 6.x) with write-behind caching, it is possible that Vim will try to create a swap file on a read-only file system (e.g. write protected floppy). You will then be given the message @@ -35,8 +46,45 @@ Known problems: - The 16 bits MS-DOS version can only have about 10 files open (in a window or hidden) at one time. With more files you will get error messages when trying to read or write a file, and for filter commands. -- The 32 bits MS-DOS version runs out of file descriptors when using a command - like ":r!ls"; Vim crashes after about five to twelve tries. +- The 32 bit version can work with long filenames. When doing filename + completion, matches for the short filename will also be found. But this + will result in the corresponding long filename. For example, if you have + the long file name "this_is_a_test" with the short filename "this_i~1", the + command ":e *1" will start editing "this_is_a_test". +- When using the 32 bit version and you run into problems with DPMI support, + check if there is a program in your config.sys that eats resources. One + program known to cause this problem is "netx", which says "NetWare v. 3.26 + Workstation shell". Replace it with version 3.32 to fix the problem. + + +LOCATION OF DOCUMENTATION and VIMRC FILE + +You should set the environment variable "VIM" to the directory where the Vim +documentation files are. If "VIM" is used but not defined, "HOME" is tried +too. + +If the HOME environment variable is not set, the value "C:/" is used as a +default. + +The default help filename is "$VIM\vim_help.txt". If the environment variable +$VIM is not defined or the file is not found, the DOS search path is used to +search for the file "vim_help.txt". If you do not want to put "vim_help.txt" +in your search path, use the command ":set helpfile=pathname" to tell Vim +where the help file is. |'helpfile'| + +Vim will look for initializations in eight places. The first that is found +is used and the others are ignored. The order is: + - The environment variable VIMINIT + - The file "$VIM/_vimrc" + - The file "$HOME/_vimrc" + - The file "$VIM/.vimrc" + - The file "$HOME/.vimrc" + - The environment variable EXINIT + - The file "$VIM/_exrc" + - The file "$HOME/_exrc" + + +USING BACKSLASHES Using backslashes in file names can be a problem. Vi halves the number of backslashes for some commands. Vim is a bit more tolerant and backslashes @@ -46,13 +94,15 @@ etc.), it is removed. Use slashes to avoid problems: ":e c:/foo/bar" works fine. Vim will replace the slashes with backslashes internally, to avoid problems with some MS-DOS programs. + +SCREEN OUTPUT AND COLORS + The default output method for the screen is to use bios calls. This will work right away on most systems. You do not need ansi.sys. You can use ":mode" to set the current screen mode. See vim_ref.txt, section 20.3 |:mode|. You can set the color used in five modes with nine termcap options. Which of -the five modes is used for which action depends on the 'highlight' ('hl') -option. See vim_ref.txt |'highlight'|. +the five modes is used for which action depends on the |'highlight'| option. ":set t_mr=^V^[\|xxm" start of invert mode ":set t_md=^V^[\|xxm" start of bold mode @@ -69,33 +119,60 @@ option. See vim_ref.txt |'highlight'|. ^V is CTRL-V ^[ is <Esc> -xx must be replaced with a decimal code: The foreground color number and - background color number added together: +xx must be replaced with a decimal code, which is the foreground color number + and background color number added together: COLOR FOREGROUND BACKGROUND -black 0 0 -blue 1 16 -green 2 32 -cyan 3 48 -red 4 64 -magenta 5 80 -brown 6 96 -lighgray 7 112 -darkgray 8 -lightblue 9 -lightgreen 10 -lighcyan 11 -lightred 12 -lighmagenta 13 -yellow 14 -white 15 -blink 128 - -When you use 0, the color is reset to the one used when you started Vim. This -is the default for t_me. The default for t_mr is black on grey, 0 + 112 = 112. -The default for t_md is white on cyan, 15 + 48 = 63. The default for t_so is -white on blue, 15 + 16 = 31. These colors were chosen, because they also look -good when using an inverted display. But you can change them as you like. + black 0 0 + blue 1 16 + green 2 32 + cyan 3 48 + red 4 64 + magenta 5 80 + brown 6 96 + lighgray 7 112 + darkgray 8 128 * + lightblue 9 144 * + lightgreen 10 160 * + lighcyan 11 176 * + lightred 12 192 * + lightmagenta 13 208 * + yellow 14 224 * + white 15 240 * + +* Depending on the display mode, the color codes above 128 may not be + available, and code 128 will make the text blink. + +When you use 0, the color is reset to the one used when you started Vim. +This is the default for t_me. + +The defaults for the various highlight modes are: + t_mr 112 reverse mode: black text (0) on lightgray (112) + t_md 63 bold mode: white text (15) on cyan (48) + t_me 0 normal mode (revert to default) + + t_so 31 standout mode: white (15) text on blue (16) + t_se 0 standout mode end (revert to default) + + t_czh 225 italic mode: blue text (1) on yellow (224) + t_czr 0 italic mode end (revert to default) + + t_us 67 underline mode: cyan text (3) on red (64) + t_ue 0 underline mode end (revert to default) + +These colors were chosen because they also look good when using an inverted +display, but you can change them to your liking. + +Example: +:set t_mr=^V^[\|97m " start of invert mode: blue (1) on brown (96) +:set t_md=^V^[\|67m " start of bold mode: cyan (3) on red (64) +:set t_me=^V^[\|112m " back to normal mode: black (0) on light gray (112) + +:set t_so=^V^[\|37m " start of standout mode: magenta (5) on green (32) +:set t_se=^V^[\|112m " back to normal mode: black (0) on light gray (112) + + +SPECIAL TERMCAP CODES and NOT USING VIM ON THE PC CONSOLE The termcap codes that are translated into bios calls are: t_cl <Esc>|J clear screen @@ -123,17 +200,19 @@ If you want to use Vim on a terminal connected to a COM: port, reset the 'bioskey' option. Otherwise the commands will be read from the PC keyboard. CTRL-C and CTRL-P may not work correctly with 'bioskey' reset. + +TEXTMODE or NON-MS-DOS FILES + If the "tx" (textmode) option is set (which is the default), Vim will accept a single <NL> or a <CR><NL> pair for end-of-line. When writing a file, Vim will use <CR><NL>. Thus, if you edit a file and write it, <NL> is replaced -with <CR><NL>. If the "tx" option is not set, the single <NL> will be used +with <CR><NL>. If the "tx" option is not set, a single <NL> will be used for end-of-line. A <CR> will be shown as ^M. You can use Vim to replace <NL> with <CR><NL> by reading in any mode and writing in text mode (":se tx"). You can use Vim to replace <CR><NL> with <NL> by reading in text mode and writing in non-text mode (":se notx"). 'textmode' is set automatically when 'textauto' is on (which is the default), so you don't really have to -worry about what you are doing. - |'textmode'| |'textauto'| +worry about what you are doing. |'textmode'| |'textauto'| If you want to edit a script file or a binary file, you should reset the 'textmode' and 'textauto' options before loading the file. Script files and @@ -141,47 +220,47 @@ binary files may contain single <NL> characters which would be replaced with <CR><NL>. You can reset 'textmode' and 'textauto' automatically by starting Vim with the "-b" (binary) option. -You should set the environment variable "VIM" to the directory where the Vim -documentation files are. If "VIM" is used but not defined, "HOME" is tried -too. -If the HOME environment variable is not set, the value "C:/" is used as a -default. - -The default help filename is "$VIM\vim_help.txt". If the environment variable -$VIM is not defined or the file is not found, the DOS search path is used to -search for the file "vim_help.txt". If you do not want to put "vim_help.txt" -in your search path, use the command ":set helpfile=pathname" to tell Vim -where the help file is. |'helpfile'| - -Vim will look for initializations in eight places. The first that is found -is used and the others are ignored. The order is - - The environment variable VIMINIT - - The file "$VIM/_vimrc" - - The file "$HOME/_vimrc" - - The file "$VIM/.vimrc" - - The file "$HOME/.vimrc" - - The environment variable EXINIT - - The file "$VIM/_exrc" - - The file "$HOME/_exrc" +:CD COMMAND The ":cd" command recognizes the drive specifier and changes the current drive. Use ":cd c:" to make drive C the active drive. Use ":cd d:\dos" to go to the directory "dos" in the root of drive D. |:cd| + +INTERRUPTING + Use CTRL-break instead of CTRL-C to interrupt searches. The CTRL-C is not detected until a key is read. + +SHIFTED ARROW KEYS + Use CTRL-arrow-left and CTRL-arrow-right instead of SHIFT-arrow-left and SHIFT-arrow-right. The arrow-up and arrow-down cannot be used with SHIFT or CTRL. -Temporary files (for filtering) are put in the current directory. + +TEMP FILES + +Temporary files (for filtering) are put in the first directory in the next +list that exists and where a file can be created: + $TMP + $TEMP + C:\TMP + C:\TEMP + current directory + + +SHELL OPTION DEFAULT The default for the sh (shell) option is "command". If COMSPEC is defined it -is used instead. External commands are started with "command /c -<command_name>". Typing CTRL-Z starts a new command shell. Return to Vim with -"exit". +is used instead. External commands are started with +"command /c <command_name>". Typing CTRL-Z starts a new command shell. +Return to Vim with "exit". + + +FILENAME EXTENSIONS MS-DOS allows for only one filename extension. Therefore, when appending an extension, the '.' in the original filename is replaced with a '_', the name @@ -192,8 +271,8 @@ becomes "thisisat.bak". To reduce these problems, the default for then becomes "thisisat.es~". The 'shortname' option is not available, because it would always be set. -If the 32-bit DOS version is run on Windows 95 or Windows NT, it can use long -filenames, as can the Win32 version. + +COMPILING The MS-DOS binary was compiled with Borland-C++ version 4.0, using makefile.bcc. Other compilers should also work. Use makefile.dos for @@ -204,21 +283,19 @@ be done with the addcr program: "make addcr". This will compile addcr.c to addcr.exe and then execute the addcr.bat file. Sometimes this fails. In that case, execute the addcr.bat file from the DOS prompt. - The "spawno" library by Ralf Brown was used in order to free memory when Vim starts a shell or other external command. Only about 200 bytes are taken from conventional memory. When recompiling get the spawno library from Simtel, directory "msdos/c". It is called something like "spwno413.zip". Or remove the library from the makefile. + +MEMORY USAGE and LIMITATIONS + A swap file is used to store most of the text. You should be able to edit very large files. However, memory is used for undo and other things. If you delete a lot of text, you can still run out of memory in the 16-bit version. -In the 16-bit version the line length is limited to about 32000 characters. -When reading a file the lines are automatically split. But editing a line -in such a way that it becomes too long may give unexpected results. - If Vim gives an "Out of memory" warning, you should stop editing. The result of further editing actions is unpredictable. Setting 'undolevels' to 0 saves some memory. Running the maze macros on a big maze is guaranteed to run out @@ -227,7 +304,13 @@ of memory, because each change is remembered for undo. In this case set In the 32-bit version, extended memory is used to avoid these problems. -About using Vim to edit a symbolically linked file on a Unix NFS file server: +In the 16-bit version the line length is limited to about 32000 characters. +When reading a file the lines are automatically split. But editing a line +in such a way that it becomes too long may give unexpected results. + + +USING VIM TO EDIT A SYMBOLICALLY LINKED FILE ON A UNIX NFS FILE SERVER + When writing the file, Vim does not "write through" the symlink. Instead, it deletes the symbolic link and creates a new file in its place. On Unix, Vim is prepared for links (symbolic or hard). A backup copy of @@ -238,3 +321,36 @@ bits are set like the original file. However, this doesn't work properly when working on an NFS-mounted file system where links and other things exist. The only way to fix this in the current version is not making a backup file, by ":set nobackup nowritebackup" |'writebackup'| + + +HOW TO COPY/PASTE TEXT FROM/TO VIM IN A DOS BOX + +(posted to comp.editors by John Velman <velman@igate1.hac.com>) + +1) to get VIM to run in a window, instead of full screen, press alt+enter + (I've always used alt+shift+enter, but either one seems to work). This + toggles back and forth between full screen and a dos window. + +2) To paste something *into* vim, put vim in insert mode. + +3) put the text you want to paste on the windows clipboard. + +4) Click the control box in the upper left of the vim window. (This looks + like a big minus sign). If you don't want to use the mouse, you can get + this with alt+spacebar. +5) on the resulting dropdown menu choose 'Edit' +6) on the child dropdown menu choose 'Paste' + +To copy something from the vim window to the clipboard, + +1) select the control box to get the control drop down menu. +2) select 'Edit.' +3) select 'Mark' +4) using either the the keys or the mouse, select the part of the vim window + that you want to copy. To use the keys, use the arrow keys, and hold down + shift to extend the selection. +5) when you've completed your selection, press 'enter.' The selection + is now in the windows clipboard. By the way, this can be any + rectangular selection, for example columns 4-25 in rows 7-10. It can + include anything in the VIM window: the output of a :!dir, for + example. diff --git a/usr.bin/vim/doc/vim_gui.txt b/usr.bin/vim/doc/vim_gui.txt index 755240937a7..017f6f49e09 100644 --- a/usr.bin/vim/doc/vim_gui.txt +++ b/usr.bin/vim/doc/vim_gui.txt @@ -1,4 +1,4 @@ -*vim_gui.txt* For Vim version 4.2. Last modification: 1996 June 11 +*vim_gui.txt* For Vim version 4.4. Last modification: 1996 Sep 12 Vim's Graphical User Interface @@ -31,10 +31,23 @@ that waits for gvim to exit), start gvim with "gvim -f", "vim -gf" or use color. If you want the GUI to run in the foreground always, include the 'f' flag in 'guioptions'. |-f|. -When the GUI starts up, the file ~/.gvimrc is sourced if it exists, and then -the file ./.gvimrc. This file may contain commands to set up your own -customised menus (see |:menu|) and initialise other things that you may want -to set up differently from the terminal version. + *gui_init* +When the GUI starts up initializations are carried out, in this order: +- If the system gvimrc exists, it is sourced. The name if this file is + something like "/usr/local/share/vim/gvimrc". You can check this with + ":version". +- If the GVIMINIT environment variable exists and is not empty, it is + executed as an Ex command. Otherwise, if the user gvimrc file exists, it + is sourced. The name of this file is something like "$HOME/.gvimrc". You + can check this with ":version". +- If the 'exrc' option is set (which is NOT the default) the file ./.gvimrc + is sourced, if it exist and isn't the same file as the system or user + gvimrc file. If this file is not owned by you, some security restrictions + apply. + +You can use the gvimrc files to set up your own customised menus (see |:menu|) +and initialise other things that you may want to set up differently from the +terminal version. There are a number of options which only have meaning in the GUI version of Vim. These are 'guifont', 'guipty' and 'guioptions'. They are documented @@ -461,7 +474,7 @@ scrollbars will remain the same, because Vim has its own, which are already - Window should be redrawn when resizing at the hit-return prompt. - - Use different cursor and mouse shapes/colours for different modes. + - Use different cursor and mouse shapes/colors for different modes. - Scrollbars with Motif 1.1 are ordered upside down! Do we care? @@ -474,8 +487,8 @@ scrollbars will remain the same, because Vim has its own, which are already current Vim window. - Add a new command :highlight for specifying how various things should - be highlighted, allowing colours to be given. Currently it's all hard - coded, the text colour, bg colour etc. + be highlighted, allowing colors to be given. Currently it's all hard + coded, the text color, bg color etc. - We need a nice little picture to go on the icon :-) But how do we do that? diff --git a/usr.bin/vim/doc/vim_help.txt b/usr.bin/vim/doc/vim_help.txt index e6183370efa..70989e96d14 100644 --- a/usr.bin/vim/doc/vim_help.txt +++ b/usr.bin/vim/doc/vim_help.txt @@ -1,4 +1,4 @@ -*vim_help.txt* For Vim version 4.2. Last modification: 1996 June 16 +*vim_help.txt* For Vim version 4.4. Last modification: 1996 Aug 3 VIM help file @@ -704,7 +704,9 @@ Short explanation of each option: *option_list* |'sections'| |'sect'| nroff macros that separate sections |'secure'| secure mode for reading .vimrc in current dir |'shell'| |'sh'| name of shell to use for external commands +|'shellcmdflag'| |'shcf'| flag to shell to execute one command |'shellpipe'| |'sp'| string to put output of ":make" in error file +|'shellquote'| |'shq'| quote character(s) for around shell command |'shellredir'| |'srr'| string to put output of filter in a temp file |'shelltype'| |'st'| Amiga: influences how to use a shell |'shiftround'| |'sr'| round indent to multiple of shiftwidth @@ -956,6 +958,7 @@ Short explanation of each option: *option_list* |:xit| :x[it][!] [file] Like ":wq" but write only when changes have been made |ZZ| ZZ Same as ":x". +|ZQ| ZQ Same as ":q!". |:xall| :xall[!] or :wqall[!] Write all changed buffers and exit @@ -1089,7 +1092,11 @@ Now that you've jumped here with CTRL-], g<LeftMouse>, or <C-LeftMouse>, you can use CTRL-T, g<RightMouse>, or <C-RightMouse> to go back to where you were. ------------------------------------------------------------------------------ -For the most recent information about Vim: *www* *faq* *FAQ* + *www* *faq* *FAQ* *ftp* *distribution* *download* +The Vim pages contain the most recent information about Vim. They also +contains links to the most recent version of Vim. The FAQ is a list of +Frequently Asked Questions, read this if you have problems. + VIM home page: <URL:http://www.math.fu-berlin.de/~guckes/vim/> VIM FAQ: <URL:http://www.grafnetix.com/~laurent/vim/> @@ -1124,7 +1131,7 @@ There are three mailing lists for Vim: NOTE: You can only send messages to these lists if you have subscribed! Also: you need to send the messages from the same location as the one you subscribed -from (yes, Majordomo is not flexible). +from (yes, Majordomo is inflexible). If you want to join, send a message to <majordomo@prz.tu-berlin.de> @@ -1151,7 +1158,7 @@ suggestions and discussing what is good and bad in Vim. Tony Andrews Stevie Gert van Antwerpen changes for DJGPP on MS-DOS Berkeley DB(3) ideas for swapfile - Keith Bostic nvi + Keith Bostic Nvi Ralf Brown SPAWNO library for MS-DOS Robert Colon many useful remarks Kayhan Demirel sent me news in Uganda diff --git a/usr.bin/vim/doc/vim_idx.txt b/usr.bin/vim/doc/vim_idx.txt index 7b15ce40236..83c82b06b3e 100644 --- a/usr.bin/vim/doc/vim_idx.txt +++ b/usr.bin/vim/doc/vim_idx.txt @@ -1,4 +1,4 @@ -*vim_idx.txt* For Vim version 4.2. Last modification: 1996 June 16 +*vim_idx.txt* For Vim version 4.4. Last modification: 1996 Aug 4 This file contains a list of all commands for each mode, with a tag and a short description. The list is sorted on ASCII value. @@ -38,7 +38,7 @@ tag char action line |i_CTRL-E| CTRL-E insert the character which is below the cursor CTRL-F not used - CTRL-G not used + CTRL-G reserved for future expansion |i_<BS>| <BS> delete character before the cursor |i_digraph| {char1}<BS>{char2} enter digraph (only when 'digraph' option set) @@ -292,6 +292,7 @@ tag char note action in Normal mode |Y| ["x]Y yank N lines [into buffer x]; synonym for "yy" |ZZ| ZZ store current file if modified, and exit +|ZQ| ZQ exit current file always |[| [{char} square bracket command (see below) \ not used |]| ]{char} square bracket command (see below) diff --git a/usr.bin/vim/doc/vim_kcc.txt b/usr.bin/vim/doc/vim_kcc.txt index 57884877629..4a0d35ca414 100644 --- a/usr.bin/vim/doc/vim_kcc.txt +++ b/usr.bin/vim/doc/vim_kcc.txt @@ -1,22 +1,26 @@ *vim_kcc.txt* *uganda* *copying* -Vim is Charityware. There are no restrictions on using or copying Vim, but I -encourage you to make a donation to charity, see below. If you include Vim on -a CD-ROM you should send me a copy. +Vim is Charityware. You can use and copy it as much as you like, but you are +encouraged to make a donation to orphans in Uganda. See below. + +If you include Vim on a CD-ROM, I would like to receive a copy. Just so I +know which Vim distributions exists in the world (and to show off to my +friends :-)). + +If you distribute a modified version of Vim, you must send me a copy, +including the source code. Or make it available to me through ftp; let me +know where I can find it. If the number of changes is small (e.g., a modified +Makefile) e-mailing me the diffs will do. I preserve the right to include +any changes in the official version of Vim. It is not allowed to distribute +a modified version of Vim without making the source code available to me. +It is not allowed to remove these restrictions from the distribution of the +Vim sources. + If you are happy with Vim, please express that by reading the rest of this file. -Summer 1993 I spent my holidays in Uganda, working for Kibaale Children's -Centre (KCC) with a Dutch team. I was very impressed with what I experienced -there. Of course I knew Africa from books and television, but actually being -there and talking and working with the people is very different. January 1994 -I spent another month there, which made me realize that I could be of help to -these people. Summer 1994 to summer 1995 I spent a whole year at the centre, -working as a volunteer. I have helped to expand the centre and worked in the -area of water and sanitation. - KCC is located in Kibaale, a small town in the south of Uganda, near Tanzania. The area is known as Rakai District. The population is mostly farmers. Although people are poor, there is enough food. But this district is @@ -63,9 +67,11 @@ to travel hours by bicycle, if they have one. There is no ambulance in the area and they don't have money to hire a taxi (if there is one). For most people KCC is the only help they can get. -Now that I'm back in Holland, I would like to continue supporting KCC. To do -this I'm raising funds and organizing the sponsorship program. Please -consider one of these options: +Summer 1994 to summer 1995 I spent a whole year at the centre, working as a +volunteer. I have helped to expand the centre and worked in the area of water +and sanitation. Now that I'm back in Holland, I would like to continue +supporting KCC. To do this I'm raising funds and organizing the sponsorship +program. Please consider one of these options: 1. Sponsor a child: $15 a month. (Holland: fl 25) 2. Sponsor a child and the improvement of its environment: $25 a month @@ -77,13 +83,13 @@ Compared with other organizations that do child sponsorship the amounts are very low. This is because the money goes directly to the centre. Less than 5% is used for administration. This is possible because this is a small organization that works with volunteers. If you would like to sponsor a -child, you should have the intention to do this for at least a year. +child, you should have the intention to do this for at least one year. -How do you know that the money will be spent right? First of all you have my -personal guarantee as the author of Vim. Further the centre is co-sponsored -and inspected by World Vision, Save the Children Fund and International Child -Care Fund. I have worked with the centre as a volunteer from September 1994 -to August 1995. I trust the people that are working there. +How do you know that the money will be spent right? First of all you have my +personal guarantee as the author of Vim. I trust the people that are working +at the centre, I know them personally. Further more the centre is +co-sponsored and inspected by World Vision, Save the Children Fund and +International Child Care Fund. If you have any further questions, send me e-mail: mool@oce.nl. diff --git a/usr.bin/vim/doc/vim_menu.txt b/usr.bin/vim/doc/vim_menu.txt index 24801b33942..5057e79c5e6 100644 --- a/usr.bin/vim/doc/vim_menu.txt +++ b/usr.bin/vim/doc/vim_menu.txt @@ -1,4 +1,5 @@ -" *vim_menu.txt* +" *vim_menu.txt* For Vim version 4.4. Last modification: 1996 May 29 +" " These menu commands should recreate the default Vim menus. " You can use this as a start for your own set of menus. " The colons at the start of each line are just to indicate these are colon diff --git a/usr.bin/vim/doc/vim_mint.txt b/usr.bin/vim/doc/vim_mint.txt index 6ae58bb2be0..5ac9d567653 100644 --- a/usr.bin/vim/doc/vim_mint.txt +++ b/usr.bin/vim/doc/vim_mint.txt @@ -1,4 +1,4 @@ -*vim_mint.txt* For Vim version 4.2. Last modification 1996 June 11 +*vim_mint.txt* For Vim version 4.4. Last modification 1996 June 11 This file contains the particularities for the Atari MiNT version of Vim. diff --git a/usr.bin/vim/doc/vim_os2.txt b/usr.bin/vim/doc/vim_os2.txt index 988a785a598..6a6c11226b9 100644 --- a/usr.bin/vim/doc/vim_os2.txt +++ b/usr.bin/vim/doc/vim_os2.txt @@ -1,46 +1,49 @@ -*vim_os2.txt* For Vim version 4.2. Last modification: 1996 June 13 +*vim_os2.txt* For Vim version 4.4. Last modification: 1996 July 20 This file contains the particularities for the OS/2 version of Vim. -Note: This OS/2 port works well for me and a couple of other OS/2 users; - however, since I haven't had much feedback, that either means no - (OS/2-specific) bugs exist (besides the one mentioned below), or no one - has yet created a situation in which any bugs are apparent. Report any - problems or other comments to paul@wau.mis.ah.nl (email valid up to at - least September 1996, after that try paul@wurtel.hobby.nl, - paul@murphy.nl, or paulS@toecompst.nl). Textmode/notextmode, binary - mode, and FAT handling all seem to work well, which would seem to be the - most likely places for trouble. +NOTE - A known problem is that files opened by Vim are inherited by other - programs that are started via a shell escape from within Vim. - This specifically means that Vim won't be able to remove the swap - file(s) associated with buffers open at the time the other program was - started, until the other program is stopped. At that time, the swap file - may be removed, but if Vim could not do that the first time, it won't be - removed at all. You'll get warnings that some other Vim session may be - editing the file when you start Vim up again on that file. This can be - reproduced with ":!start epm". Now quit Vim, and start Vim again with - the file that was in the buffer at the time epm was started. I'm - working on this! +This OS/2 port works well for me and a couple of other OS/2 users; however, +since I haven't had much feedback, that either means no (OS/2-specific) bugs +exist (besides the one mentioned below), or no one has yet created a situation +in which any bugs are apparent. Report any problems or other comments to +paul@wau.mis.ah.nl (email valid up to at least September 1996, after that try +paul@wurtel.hobby.nl, paul@murphy.nl, or paulS@toecompst.nl). +Textmode/notextmode, binary mode, and FAT handling all seem to work well, +which would seem to be the most likely places for trouble. +A known problem is that files opened by Vim are inherited by other programs +that are started via a shell escape from within Vim. This specifically means +that Vim won't be able to remove the swap file(s) associated with buffers open +at the time the other program was started, until the other program is stopped. +At that time, the swap file may be removed, but if Vim could not do that the +first time, it won't be removed at all. You'll get warnings that some other +Vim session may be editing the file when you start Vim up again on that file. +This can be reproduced with ":!start epm". Now quit Vim, and start Vim again +with the file that was in the buffer at the time epm was started. I'm working +on this! -Prerequisites: -- To run Vim, you need the emx runtime environment (at least rev. 0.9b). This - is generally available as (ask Archie about it): +PREREQUISITES + +To run Vim, you need the emx runtime environment (at least rev. 0.9b). This +is generally available as (ask Archie about it): emxrt.zip emx runtime package - I've included a copy of emx.dll, which should be copied to one of the - directories listed in your LIBPATH. Emx is GPL'ed, but the emx.dll library - is not (read COPYING.EMX to find out what that means to you). +I've included a copy of emx.dll, which should be copied to one of the +directories listed in your LIBPATH. Emx is GPL'ed, but the emx.dll library is +not (read COPYING.EMX to find out what that means to you). + +This emx.dll is from the emxfix04.zip package, which unfortunately has a bug +in select(). Versions of Vim before 3.27 will appear to hang when starting +(actually, while processing vimrc). Hit return a couple of times until Vim +starts working if this happens. Next, get an up to date version of Vim! - This emx.dll is from the emxfix04.zip package, which unfortunately has a bug - in select(). Versions of Vim before 3.27 will appear to hang when starting - (actually, while processing vimrc). Hit return a couple of times until Vim - starts working if this happens. Next, get an up to date version of Vim! + +HELP AND VIMRC FILE The VIM environment variable is used to find the location of the help files and the system .vimrc. Place an entry such as this in CONFIG.SYS: @@ -59,19 +62,44 @@ network drive (including .vimrc; this is then called the "system" vimrc file), and then use a personal copy of .vimrc (the "user" vimrc file). This should be located in a directory indicated by the HOME environment variable. + +ENVIRONMENT VARIABLES IN FILE NAMES + This HOME environment variable is also used when using ~ in file names, so ":e ~/textfile" will edit the file "textfile" in the directory referred to by HOME. Additionally you can use other environment variables in file names, as as ":n $SRC/*.c". +The HOME environment variable is also used to locate the .viminfo file +(see |viminfo_file|). There is no support yet for .viminfo on FAT file +systems yet, sorry. You could try the -i startup flag (as in "vim -i +$HOME/_viminfo") however. + If the HOME environment variable is not set, the value "C:/" is used as a default. + +BACKSLASHES + Using slashes ('/') and backslashes ('\') can be a bit of a problem (see vim_dos.txt for more explanation), but in almost all cases Vim does "The Right Thing". Vim itself uses backslashes in file names, but will happily accept forward slashes if they are entered (in fact, often that works better!). + +TEMP FILES + +Temporary files (for filtering) are put in the first directory in the next +list that exists and where a file can be created: + $TMP + $TEMP + C:\TMP + C:\TEMP + current directory + + +TERMINAL SETTING + Use "os2ansi" as the TERM environment variable (or don't set it at all, as the default is the correct value). You can set term to os2ansi in the .vimrc, in case you need TERM to be a different value for other applications. The diff --git a/usr.bin/vim/doc/vim_ref.txt b/usr.bin/vim/doc/vim_ref.txt index e9358ebe02d..ad163ba4c79 100644 --- a/usr.bin/vim/doc/vim_ref.txt +++ b/usr.bin/vim/doc/vim_ref.txt @@ -1,4 +1,4 @@ -*vim_ref.txt* For Vim version 4.2. Last modification: 1996 June 17 +*vim_ref.txt* For Vim version 4.4. Last modification: 1996 Sep 12 VIM REFERENCE MANUAL @@ -130,7 +130,9 @@ to the name of the help file, so you can put it in any place you like. CTRL-{char} {char} typed as a control character; that is, typing {char} while holding the CTRL key down. The case of {char} does not - matter; thus CTRL-A and CTRL-a are equivalent. + matter; thus CTRL-A and CTRL-a are equivalent. But on some + terminals, using the SHIFT key will produce another code, + don't use it then. 'option' An option, or parameter, that can be set to a value, is enclosed in single quotes. See chapter 19, |options|. @@ -169,6 +171,10 @@ notation meaning equivalent decimal value(s) <End> end *end* <PageUp> page-up *page_up* *page-up* <PageDown> page-down *page_down* *page-down* +<kHome> keypad home (upper left) *keypad_home* +<kEnd> keypad end (lower left) *keypad_end* +<kPageUp> keypad page-up (upper right) *keypad_page_up* +<kPageDown> keypad page-down (lower right) *keypad_page_down* <S-...> shift-key *shift* <C-...> control-key *control* *ctrl* <M-...> alt-key or meta-key *meta* *alt* @@ -180,10 +186,17 @@ available on a few terminals. On the Amiga, shifted function key 10 produces a code (CSI) that is also used by key sequences. It will be recognized only after typing another key. -Note: There are two codes for the delete key. 127 is the ASCII value for the -delete key, which is always recognized. Some delete keys send another value, -in which case this value is obtained from the termcap entry "kD". Both values -have the same effect. Also see |:fixdel|. +Note: There are two codes for the delete key. 127 is the decimal ASCII value +for the delete key, which is always recognized. Some delete keys send another +value, in which case this value is obtained from the termcap entry "kD". Both +values have the same effect. Also see |:fixdel|. + +Note: The keypad keys are used in the same way as the corresponding "normal" +keys. For example, <kHome> has the same effect as <Home>. If a keypad key +sends the same raw key code as it non-keypad equivalent, it will be recognized +as the non-keypad code. For example, when <kHome> sends the same code as +<Home>, when pressing <kHome> Vim will think <Home> was pressed. Mapping +<kHome> will not work then. *<>* Some of the examples are given in the <> notation. The rules are: @@ -201,9 +214,14 @@ Some of the examples are given in the <> notation. The rules are: <M-A> Meta- A ('A' with bit 8 set) <t_kd> "kd" termcap entry (cursor down key) -If you want to use this notation in Vim, you have to remove the 'B' flag from -'cpoptions' and make sure the '<' flag is excluded (it already is by default). +If you want to use the full <> notation in Vim, you have to remove the 'B' +flag from 'cpoptions' and make sure the '<' flag is excluded (it already is by +default). :set cpo=ceFs +If you have the 'B' flag in 'cpoptions', then <> notation mostly still works, +but you can't escape the special meaning of key names in <> with a backslash. +To distinguish using <> with and without the 'B' flag, it's called full <> +notation if the 'B' flag is excluded. For mapping, abbreviation and menu commands you can then copy-paste the examples and use them directly. Or type them literally, including the '<' and '>' characters. This does NOT work for other commands, like ":set" and @@ -717,6 +735,16 @@ can be used to load this information. You could even have different viminfos for different types of files (e.g., C code) and load them based on the file name, using the ":autocmd" command (see |:autocmd|). + *viminfo_errors* +When Vim detects an error while reading a viminfo file, it will not overwrite +that file. If there are more than 10 errors, Vim stops reading the viminfo +file. This was done to avoid accidently destroying a file when the filename +of the viminfo file is wrong. This could happen when accidently typing "vim +-i file" when you wanted "vim -v file" (yes, somebody accidently did that!). +If you want to overwrite a viminfo file with an error in it, you will either +have to fix the error, or delete the file (while Vim is running, so most of +the information will be restored). + *:rv* *:rviminfo* :rv[iminfo][!] [file] Read from viminfo file [file] (default: see above). If [!] is given, then any information that is @@ -1186,7 +1214,7 @@ Completing keywords in current file *compl_current* The keys CTRL-N and CTRL-P can be used to complete the keyword that is in front of the cursor. This is useful if you are writing a program that has complicated variable names, and you want to copy a name from the text before -of after the cursor. +or after the cursor. If there is a keyword in front of the cursor (a name made out of alphabetic characters and characters in 'iskeyword'), it is used as the search pattern, @@ -1351,12 +1379,12 @@ move around in the command line with the left and right cursor keys. With the Note that if your keyboard does not have working cursor keys or any of the other special keys, you can use ":cnoremap" to define another key for them. For example, to define tcsh style editing keys: *tcsh-style* - :cnoremap ^A <Home> - :cnoremap ^F <Right> - :cnoremap ^B <Left> - :cnoremap ^[b <S-Left> - :cnoremap ^[f <S-Right> -(All ^x characters entered with CTRL-V CTRL-x, <xx> typed literally). + :cnoremap <C-A> <Home> + :cnoremap <C-F> <Right> + :cnoremap <C-B> <Left> + :cnoremap <Esc>b <S-Left> + :cnoremap <Esc>f <S-Right> +(<> notation |<>|; type all this literally) *cmdline_history* The command lines that you enter are remembered in a history table. You can @@ -1590,10 +1618,12 @@ line. The commands ":global", "vglobal", ":!", ":r !", ":w !", ":help" and ":autocmd" see the '|' as their argument, and can therefore not be followed by another command. If you want '|' to be included in one of the other commands, precede it with '\'. Note that this is confusing (inherited from Vi). With -":g" the '|' is included in the command, with ":s" it is not. There is one -execption: When the 'b' flag is present in 'cpoptions', with the ":map" and -":abbr" commands and friends CTRL-V needs to be used instead of '\'. See also -|map_bar|. +":g" the '|' is included in the command, with ":s" it is not. + +There is one exception: When the 'b' flag is present in 'cpoptions', with the +":map" and ":abbr" commands and friends CTRL-V needs to be used instead of +'\'. You can also use "<Bar>" instead. See also |map_bar|. + Examples: :!ls | wc view the output of two commands :r !ls | wc insert the same output in the text @@ -1743,7 +1773,10 @@ order): :h Head of the file name (the last component and any separators removed). Cannot be used with :e, :r or :t. Can be repeated to remove several components at the end. - When there is no head the result is empty. + When the file name is an absolute path (starts with "/" for + Unix; "x:\" for MS-DOS, WIN32, OS/2; "drive:" for Amiga), + that part is not removed. When there is no head (path is + relative to current directory) the result is empty. :t Tail of the file name (last component of the name). Must precede any :r or :e. :r Root of the file name (the last extension removed). When @@ -2042,6 +2075,49 @@ Abbreviations are disabled if the 'paste' option is on. :cabc[lear] Remove all abbreviations for Command-line mode. {not in Vi} + *using_CTRL-V* +It is possible to use special characters in the rhs of an abbreviation. +CTRL-V has to be used to avoid the special meaning of most non printable +characters. How many CTRL-Vs need to be typed depends on how you enter the +abbreviation. This also applies to mappings. Let's use an example here. + +Suppose you want to abbreviate "esc" to enter an <Esc> character. When you +type the ":ab" command in Vim, you have to enter this: (here ^V is a CTRL-V +and ^[ is <Esc>) + +You type: ab esc ^V^V^V^V^V^[ + + All keyboard input is subjected to ^V quote interpretation, so + the first, third, and fifth ^V characters simply allow the second, + and fourth ^Vs, and the ^[, to be entered into the command line. + +You see: ab esc ^V^V^[ + + The command line contains two actual ^Vs before the ^[. This is + how it should appear in your .exrc file, if you choose to go that + route. The first ^V is there to quote the second ^V; the :ab + command uses ^V as its own quote character, so you can include quoted + whitespace or the | character in the abbreviation. The :ab command + doesn't do anything special with the ^[ character, so it doesn't need + to be quoted. (Although quoting isn't harmful; that's why typing 7 + [but not 8!] ^Vs works.) + +Stored as: esc ^V^[ + + After parsing, the abbreviation's short form ("esc") and long form + (the two characters "^V^[") are stored in the abbreviation table. + If you give the :ab command with no arguments, this is how the + abbreviation will be displayed. + + Later, when the abbreviation is expanded because the user typed in + the word "esc", the long form is subjected to the same type of + ^V interpretation as keyboard input. So the ^V protects the ^[ + character from being interpreted as the "exit input-mode" character. + Instead, the ^[ is inserted into the text. + +Expands to: ^[ + +[example given by Steve Kirkendall] 4.7 Digraphs *digraphs* @@ -2831,6 +2907,11 @@ ZZ Write current file, if modified, and exit (same as current file, the file is written if it was modified and the window is closed). + *ZQ* +ZQ Quit current file and exit (same as ":q!"). (Note: If + there are several windows for the current file, only + the window is closed). + *timestamp* Vim remembers the timestamp of the file when you start editing it. When you write a file the timestamp is checked. If the file has been changed since you @@ -2932,30 +3013,39 @@ match the error messages from your compiler (see below). The following commands can be used if you are in QuickFix mode: *:cc* -:cc [nr] Display error [nr]. If [nr] is omitted, the same - error is displayed again. {not in Vi} +:cc[!] [nr] Display error [nr]. If [nr] is omitted, the same + error is displayed again. Without [!] this doesn't + work when jumping to another buffer, the current buffer + has been changed, there is the only window for the + buffer and both 'hidden' and 'autowrite' are off. + When jumping to another buffer with [!] any changes to + the current buffer are lost, unless 'hidden' is set or + there is another window for this buffer. {not in Vi} *:cn* *:cnext* -:[count]cn[ext] Display the [count] next error in the list that +:[count]cn[ext][!] Display the [count] next error in the list that includes a file name. If there are no file names at - all, go the the [count] next error. {not in Vi} + all, go the the [count] next error. See |:cc| for + [!]. {not in Vi} -:[count]cN[ext] *:cp* *:cprevious* *:cN* *:cNext* -:[count]cp[revious] Display the [count] previous error in the list that +:[count]cN[ext][!] *:cp* *:cprevious* *:cN* *:cNext* +:[count]cp[revious][!] Display the [count] previous error in the list that includes a file name. If there are no file names at - all, go the the [count] previous error. {not in Vi} + all, go the the [count] previous error. See |:cc| for + [!]. {not in Vi} *:cq* *:cquit* :cq[uit] Quit Vim with an error code, so that the compiler will not compile the same file again. {not in Vi} *:cf* *:cfile* -:cf[ile] [errorfile] Read the error file and jump to the first error. +:cf[ile][!] [errorfile] Read the error file and jump to the first error. This is done automatically when Vim is started with the -e option. You can use this command when you keep Vim running while compiling. If you give the name of the errorfile, the 'errorfile' option will - be set to [errorfile] {not in Vi} + be set to [errorfile]. See |:cc| for [!]. {not in + Vi} *:cl* *:clist* :cl[ist] List all errors that inlcude a file name. {not in Vi} @@ -3176,7 +3266,7 @@ considered part of the command. Show the auto-commands associated with {event} and {pat}. -:au[tocmd] * {pat} Show the auto-commands associated with pat} for all +:au[tocmd] * {pat} Show the auto-commands associated with {pat} for all events. :au[tocmd] {event} Show all auto-commands for {event}. @@ -3206,6 +3296,7 @@ considered part of the command. match the right pattern, after changing settings, or to execute autocommands for a certain event. + *autocommand-events* These events are recognized. Case is ignored, for example "BUFread" and "bufread" can be used instead of "BufRead". @@ -3216,13 +3307,13 @@ BufNewFile When starting to edit a file that doesn't *BufReadPre* BufReadPre When starting to edit a new buffer, before reading the file into the buffer. Not used - when starting to edit a new file. + when the file doesn't exist. *BufRead* *BufReadPost* BufRead or BufReadPost When starting to edit a new buffer, after reading the file into the buffer, before executing the modelines. This does NOT work - for ":r file". Not used when starting to edit - a new file. + for ":r file". Not used when the file doesn't + exist. *FileReadPre* FileReadPre Before reading a file with a ":read" command. *FileReadPost* @@ -3298,11 +3389,16 @@ BufReadPre BufReadPost starting to edit an existing file FilterReadPre FilterReadPost read the temp file with filter output FileReadPre FileReadPost any other file read +Note that the autocommands for the *ReadPre and *Filter* events are not +allowed to change the current buffer. You will get an error message if this +happens anyway. This is to prevent the file to be read into the wrong buffer. + Before the *ReadPre event the '[ mark is set to the line just above where the new lines will be inserted. Before the *ReadPost event the '[ mark is set to the first line that was just read, the '] mark to the last line. Careful: '[ and '] will change when using commands that change the buffer. + "<afile>" can be used for the file name that is being read, in commands where a file name is expected (where you can also use "%" for the current file name) |:<afile>|. @@ -3326,9 +3422,18 @@ Note that the *WritePost commands should undo any changes to the buffer that were caused by the *WritePre commands, otherwise writing the file will have the side effect of changing the buffer. -Before the *WritePre event the '[ mark is set to the first line that will be -written, the '] mark to the last line. +Before executing the autocommands, the buffer from where the lines are to be +written is temporarily made the current buffer. Unless the autocommands +change the current buffer, or delete the previously current buffer, the +previously current buffer is made the current buffer again. + +The *WritePre and *AppendPre autocommands must not delete the buffer from +where the lines are to be written. + +Before executing the *WritePre and *AppendPre autocommands the '[ mark is set +to the first line that will be written, the '] mark to the last line. Careful: '[ and '] will change when using commands that change the buffer. + "<afile>" can be used for the file name that is being written, in commands where a file name is expected (where you can also use "%" for the current file name) |:<afile>|. @@ -3369,12 +3474,19 @@ There is currently no way to disable the autocommands. If you want to write a file without executing the autocommands for that type of file, write it under another name and rename it with a shell command. -Note: When doing a ":read file" command and the last line in the file does not -have an end-of-line character, this is remembered. When executing the -FileReadPost autocommands and the same line is written again as the last line -in a file, no end-of-line character is written if 'binary' is set. This makes -a filter command on the just read lines write the same file as was read. +Note: When reading a file (with ":read file" or with a filter command) and the +last line in the file does not have an end-of-line character, this is +remembered. At the next write (with ":write file" or with a filter command), +if the same line is written again as the last line in a file AND 'binary' is +set, no end-of-line character is written. This makes a filter command on the +just read lines write the same file as was read, and makes a write command on +just filtered lines write the same file as was read from the filter. For +example, another way to write a compressed file: + :autocmd FileWritePre *.gz set bin|'[,']!gzip + :autocmd FileWritePost *.gz undo|set nobin + + *autocommand-pattern* Multiple patterns may be given separated by commas. Here are some examples: :autocmd BufRead * set tw=79 nocin ic infercase fo=2croq @@ -3437,6 +3549,9 @@ against the full file name. For example: :autocmd BufRead */vim/src/* set wrap +Note that using ~ in a file name (for home directory) doesn't work. Use a +pattern that matches the full path name, for example "*home/user/.cshrc". + 6. Cursor motions *cursor_motions* ================= @@ -3693,12 +3808,14 @@ ge Backward to the end of word [count] (inclusive). *gE* gE Backward to the end of WORD [count] (inclusive). - *word* *WORD* -These commands move over words or WORDS. A word consists of a sequence of -letters, digits and underscores, or a sequence of other non-blank -characters, separated with white space (spaces, tabs, end of line). A WORD -consists of a sequence of non-blank characters, separated with white space. -An empty line is also considered to be a word and a WORD. +These commands move over words or WORDS. + *word* +A word consists of a sequence of letters, digits and underscores, or a +sequence of other non-blank characters, separated with white space (spaces, +tabs, end of line). This can be changed with the 'iskeyword' option. + *WORD* +A WORD consists of a sequence of non-blank characters, separated with white +space. An empty line is also considered to be a word and a WORD. Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is on a non-blank. This is because "cw" is interpreted as change-word, and a @@ -3767,9 +3884,9 @@ first column). A section boundary is also a paragraph boundary. Note that this does not include a '{' or '}' in the first column. *section* -A section begins after a form-feed in the first column and at each of a set -of section macros, specified by the pairs of characters in the 'sections' -option. The default is "SHNHH HUnhsh". +A section begins after a form-feed (<C-L>) in the first column and at each of +a set of section macros, specified by the pairs of characters in the +'sections' option. The default is "SHNHH HUnhsh". The "]" and "[" commands stop at the '{' or <}" in the first column. This is useful to find the start or end of a function in a C program. Note that the @@ -3887,11 +4004,16 @@ N Repeat the latest "/" or "?" [count] times in *star* * Search forward for the [count]'th occurrence of the - keyword after or under the cursor (exclusive). Only - whole keywords are search for, like with the command - "/\<keyword\>". If there is no keyword after or - under the cursor, any non-blank word is used to - search for. {not in Vi} + word nearest to the cursor. The word used for the + search is the first of: + 1. the keyword under the cursor |'iskeyword'| + 2. the first keyword after the cursor, in the + current line + 3. the non-blank word under the cursor + 4. the first non-blank word after the cursor, + in the current line + Only whole keywords are searched for, like with the + command "/\<keyword\>". (exclusive) {not in Vi} *#* # Same as "*", but search backward. The English pound @@ -3907,13 +4029,6 @@ g# Like "#", but don't put "\<" and "\>" around the word. This makes the search also find matches that are not a whole word. {not in Vi} - HINT: If you want to search for something else than a - whole word, you could use these mappings, to search - for Visually highlighted text: - :vmap / y/<C-R>"<CR> - :vmap ? y?<C-R>"<CR> - (<> notation, see |<>|). - *gd* gd Goto local Declaration. When the cursor is on a local variable, this command will jump to its declaration. @@ -3939,7 +4054,9 @@ gD Goto global Declaration. When the cursor is on a CTRL-C Interrupt current (search) command. While typing the search pattern the current match will be shown if the -'incsearch' option is on. +'incsearch' option is on. Remember that you still have to finish the search +command with <CR> to actually position the cursor at the displayed match. Or +use <Esc> to abandon the search. These commands search for the specified pattern. With "/" and "?" an additional offset may be given. There are two types of offsets: line offsets @@ -4013,15 +4130,17 @@ TOP" is given when searching backwards or forwards respectively. This can be switched off by setting the 's' flag in the 'shortmess' option. The highlight method 'w' is used for this message (default: standout). -The "*" and "#" commands search for the keyword currently under the cursor. -If there is no keyword under the cursor, the first one to the right is used. -This keyword may only contain letters and characters in 'iskeyword'. Note -that if you type with ten fingers, the characters are easy to remember: the -"#" is under your left hand middle finger (search to the left and up) and -the "*" is under your right hand middle finger (search to the right and -down). If there is no keyword under or after the cursor, a search is done -for any word under or after the cursor. Blanks (<Tab>s and/or <Space>s) are -then recognized as delimiters for the word. +The "*", "#", "g*" and "g#" commands look for a word near the cursor in this +order, the first one that is found is used: +- The keyword currently under the cursor. +- The first keyword to the right of the cursor, in the same line. +- The WORD currently under the cursor. +- The first WORD to the right of the cursor, in the same line. +The keyword may only contain letters and characters in 'iskeyword'. +The WORD may contain any non-blanks (<Tab>s and/or <Space>s). +Note that if you type with ten fingers, the characters are easy to remember: +the "#" is under your left hand middle finger (search to the left and up) and +the "*" is under your right hand middle finger (search to the right and down). The definition of a pattern: *search_pattern* @@ -4029,76 +4148,75 @@ The definition of a pattern: *search_pattern* Patterns may contain special characters, depending on the setting of the 'magic' option. + */bar* */\bar* 1. A pattern is one or more branches, separated by "\|". It matches anything - that matches one of the branches. Example: "foo\|bar" matches "foo" and - "bar". + that matches one of the branches. Example: "foo\|beep" matches "foo" and + "beep". 2. A branch is one or more pieces, concatenated. It matches a match for the - first, followed by a match for the second, etc. Example: "foo[0-9]bar", - first match "foo", then a digit and then "bar". + first, followed by a match for the second, etc. Example: "foo[0-9]beep", + first match "foo", then a digit and then "beep". 3. A piece is an atom, possibly followed by: - 'magic' 'nomagic' - option option - * \* matches 0 or more of the preceding atom - \+ \+ matches 1 or more of the preceding atom {not - in Vi} - \= \= matches 0 or 1 of the preceding atom {not in - Vi} + magic nomagic + */star* */\star* + * \* matches 0 or more of the preceding atom + */\+* + \+ \+ matches 1 or more of the preceding atom {not in Vi} + */\=* + \= \= matches 0 or 1 of the preceding atom {not in Vi} + Examples: - .* .\* matches anything, also empty string - ^.\+$ ^.\+$ matches any non-empty line - foo\= foo\= matches "fo" and "foo" + .* .\* matches anything, also empty string + ^.\+$ ^.\+$ matches any non-empty line + foo\= foo\= matches "fo" and "foo" 4. An atom can be: - One of these five: - magic nomagic - ^ ^ at beginning of pattern, matches start of - line - $ $ at end of pattern or in front of "\|", - matches end of line - . \. matches any single character - \< \< matches the beginning of a word - \> \> matches the end of a word - \i \i matches any identifier character (see - 'isident' option) {not in Vi} - \I \I like "\i", but excluding digits {not in Vi} - \k \k matches any keyword character (see - 'iskeyword' option) {not in Vi} - \K \K like "\k", but excluding digits {not in Vi} - \f \f matches any file name character (see - 'isfname' option) {not in Vi} - \F \F like "\f", but excluding digits {not in Vi} - \p \p matches any printable character (see - 'isprint' option) {not in Vi} - \P \P like "\p", but excluding digits {not in Vi} - \e \e <Esc> - \t \t <Tab> - \r \r <CR> - \b \b <BS> - ~ \~ matches the last given substitute pattern - \(\) \(\) A pattern enclosed by escaped parentheses - (e.g., "\(^a\)") matches that pattern - x x A single character, with no special meaning, - matches itself - \x \x A backslash followed by a single character, - with no special meaning, matches the single - character - [] \[] A range. This is a sequence of characters - enclosed in "[]" or "\[]". It matches any - single character from the sequence. If the - sequence begins with "^", it matches any - single character NOT in the sequence. If two - characters in the sequence are separated by - '-', this is shorthand for the full list of - ASCII characters between them. E.g., "[0-9]" - matches any decimal digit. To include a - literal "]" in the sequence, make it the - first character (following a possible "^"). - E.g., "[]xyz]" or "[^]xyz]". To include a - literal '-', make it the first or last - character. + magic nomagic + ^ ^ at beginning of pattern, matches start of line */^* + $ $ at end of pattern or in front of "\|", */$* + matches end of line + . \. matches any single character */.* */\.* + \< \< matches the beginning of a word */\<* + \> \> matches the end of a word */\>* + \i \i matches any identifier character (see */\i* + 'isident' option) {not in Vi} + \I \I like "\i", but excluding digits {not in Vi} */\I* + \k \k matches any keyword character (see */\k* + 'iskeyword' option) {not in Vi} + \K \K like "\k", but excluding digits {not in Vi} */\K* + \f \f matches any file name character (see */\f* + 'isfname' option) {not in Vi} + \F \F like "\f", but excluding digits {not in Vi} */\F* + \p \p matches any printable character (see */\p* + 'isprint' option) {not in Vi} + \P \P like "\p", but excluding digits {not in Vi} */\P* + \e \e <Esc> */\e* + \t \t <Tab> */\t* + \r \r <CR> */\r* + \b \b <BS> */\b* + ~ \~ matches the last given substitute string */~* */\~* + \(\) \(\) A pattern enclosed by escaped parentheses */\(\)* + (e.g., "\(^a\)") matches that pattern + x x A single character, with no special meaning, + matches itself + \x \x A backslash followed by a single character, */\* + with no special meaning, matches the single + character + [] \[] A range. This is a sequence of characters */[]* + enclosed in "[]" or "\[]". It matches any */\[]* + single character from the sequence. If the + sequence begins with "^", it matches any + single character NOT in the sequence. If two + characters in the sequence are separated by '-', this + is shorthand for the full list of ASCII characters + between them. E.g., "[0-9]" matches any decimal + digit. To include a literal "]" in the sequence, make + it the first character (following a possible "^"). + E.g., "[]xyz]" or "[^]xyz]". To include a literal + '-', make it the first or last character. If the 'ignorecase' option is on, the case of letters is ignored. @@ -5501,7 +5619,7 @@ magic nomagic action \U following characters made uppercase \l next character made lowercase \L following characters made lowercase - \e end of /u, /U, /l and /L + \e end of /u, /U, /l and /L (NOTE: not <Esc>!) \E end of /u, /U, /l and /L <CR> split line in two at this point \r idem @@ -6097,6 +6215,11 @@ be replaced with spaces to make this happen. However, if the width of the block is not a multiple of a <Tab> width and the text after the inserted block contains <Tab>s, that text may be misaligned. +Rationale: In Vi the "y" command followed by a backwards motion would + sometimes not move the cursor to the first yanked character, + because redisplaying was skipped. In Vim it always moves to + the first character, like specified by Posix. + There are five types of registers: *registers* - The unnamed register "" *quote_quote* *quotequote* - 10 numbered registers "0 to "9 *quote_number* *quote0* @@ -6265,7 +6388,7 @@ linewise Visual Visual blockwise Visual Normal For moving the end of the block many commands can be used, but you cannot use Ex commands, commands that make changes or abandon the file. Commands -(starting with) ".pPiIaAO&", CTRL-^, "ZZ", CTRL-], CTRL-T, CTRL-R, CTRL-I +(starting with) ".pPiIaAO&", CTRL-^, "Z", CTRL-], CTRL-T, CTRL-R, CTRL-I and CTRL-O cause a beep and Visual mode continues. If Visual mode is not active and the "v", "V" or CTRL-V is preceded with a @@ -6462,6 +6585,17 @@ ga Print the ascii value of the character under the is higher than the current Vim version this will result in an error message. {not in Vi} +:if *:if* *:endif* +:endif Every Ex command in between the ":if" and ":endif" is + ignored. These two commands are just to allow for + future expansions in a backwards compatible way. + Nesting is allowed. In Vim version 5 you are expected + to be able to do something like + :if version >= "5.0" + : version-5-specific-command + :endif + {not in Vi} + *K* K Run a program to lookup the keyword under the cursor. The name of the program is given with the @@ -6817,7 +6951,9 @@ with a space. *map_backslash* Note that only CTRL-V is mentioned here as a special character for mappings and abbreviations. When 'cpoptions' does not contain 'B', a backslash can -also be used like CTRL-V. The <> notation can be fully used then |<>|. +also be used like CTRL-V. The <> notation can be fully used then |<>|. But +you cannot use "<C-V>" like CTRL-V to escape the special meaning of what +follows. *map_space_in_lhs* To include a space in {lhs} precede it with a CTRL-V (type two CTRL-Vs for @@ -6827,24 +6963,36 @@ If you want a {rhs} that starts with a space, precede {rhs} with a single CTRL-V (you have to type CTRL-V two times). *map_empty_rhs* You can create an empty {rhs} by typing nothing after a single CTRL-V (you -have to type CTRL-V two times). +have to type CTRL-V two times). Unfortunately, you cannot do this in a vimrc +file. - *map_bar* It is not possible to put a comment after this command, because the '"' -character is considered to be part of the {rhs}. To put a '|' in {rhs} -escape it with a backslash or a CTRL-V (to get one CTRL-V you have to type -it twice). When 'b' is present in 'cpoptions', only CTRL-V can be used, "\|" -will be recognized as a mapping ending in a '\' and then another command. This -is vi compatible, but unlogical. Summary: - :map _l :!ls \| more^M works in Vim when 'b' is not in 'cpo' - :map _l :!ls ^V| more^M works always, in Vim and vi +character is considered to be part of the {rhs}. + + *map_bar* +Since the '|' character is used to separate a map command from the next +command, you will have to do something special to include a '|' in {rhs}. +There are three methods: + use works when example + <Bar> '<' is not in 'cpoptions' :map _l :!ls <Bar> more^M + \| 'b' is not in 'cpoptions' :map _l :!ls \| more^M + ^V| always, in Vim and Vi :map _l :!ls ^V| more^M + +(here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you +cannot use the <> notation "<C-V>" here). + +All three work when you use the default setting for 'cpoptions'. + +When 'b' is present in 'cpoptions', "\|" will be recognized as a mapping +ending in a '\' and then another command. This is Vi compatible, but +unlogical when compared to other commands. To avoid mapping of the characters you type in insert or Command-line mode, type a CTRL-V first. The mapping in Insert mode is disabled if the 'paste' option is on. Note that when an error is enountered (that causes an error message) the rest -of the mapping is not executed. This is vi-compatible. +of the mapping is not executed. This is Vi-compatible. Note that the second character (argument) of the commands @zZtTfF[]rm'`"v and CTRL-X is not mapped. This was done to be able to use all the named @@ -6875,10 +7023,11 @@ included in {rhs} is encountered it will be replaced with {rhs}, and so on. This makes it possible to repeat a command an infinite number of times. The only problem is that the only way to stop this is by causing an error. The macros to solve a maze uses this, look there for an example. There is one -exception: If the {rhs} starts with {lhs}, that part is not mapped again. +exception: If the {rhs} starts with {lhs}, the first character is not mapped +again (this is Vi compatible). For example: - :map a ab -will execute the "a" command and insert a 'b' in the text. The 'a' in the + :map ab abcd +will execute the "a" command and insert "bcd" in the text. The "ab" in the {rhs} will not be mapped again. If you want to exchange the meaning of two keys you should use the :noremap @@ -7464,9 +7613,11 @@ backupdir (bdir) string (default for Amiga: ".,t:", where this is possible. - Empty means that no backup file will be created ('patchmode' is impossible!). - - A directory '.' means to put the backup file in the same directory - as the edited file. Characters after the "." are ignored, "./temp" - is handled in the same way as ".". + - A directory "." means to put the backup file in the same directory + as the edited file. + - A directory starting with "./" (or ".\" for MS-DOS et.al.) means to + put the backup file relative to where the edited file is. The + leading "." is replaced with the path name of the edited file. - Spaces after the comma are ignored, other spaces are considered part of the directory name. To have a space at the start of a directory name, precede it with a backslash. @@ -7716,7 +7867,7 @@ cpoptions (cpo) string (default "BceFs", unless compiled with set when the buffer is created. S Set buffer options always when entering a buffer (except 'readonly' and 'textmode'). This is the - (most) vi compatible setting. + (most) Vi compatible setting. The options are set to the values in the current buffer. When you change an option and go to another buffer, the value is copied. Effectively makes the @@ -7725,8 +7876,7 @@ cpoptions (cpo) string (default "BceFs", unless compiled with 's' 'S' copy buffer options no no when buffer created yes no when buffer first entered (default) - no yes each time when buffer entered (vi comp.) - yes yes when buffer created or first entered + X yes each time when buffer entered (vi comp.) t Search pattern for the tag command is remembered for "n" command. Otherwise Vim only puts the pattern in @@ -7752,7 +7902,7 @@ cpoptions (cpo) string (default "BceFs", unless compiled with match the last one. When this flag is not included, parens inside single and double quotes are treated specially. When matching a paren outside of quotes, - everyting inside quotes is ignored. When matching a + everything inside quotes is ignored. When matching a paren inside quotes, it will find the matching one (if there is one). This works very well for C programs. @@ -7797,9 +7947,11 @@ directory (dir) string (default for Amiga: ".,t:", possible. - Empty means that no swap file will be used (recovery is impossible!). - - A directory '.' means to put the swap file in the same directory as - the edited file. Everything after the "." is ignored, "./temp" is - handled in the same way as ".". + - A directory "." means to put the swap file in the same directory as + the edited file. + - A directory starting with "./" (or ".\" for MS-DOS et.al.) means to + put the swap file relative to where the edited file is. The leading + "." is replaced with the path name of the edited file. - Spaces after the comma are ignored, other spaces are considered part of the directory name. To have a space at the start of a directory name, precede it with a backslash. @@ -7909,10 +8061,11 @@ expandtab (et) toggle (default off) exrc toggle (default off) global {not in Vi} - Enables the reading of .vimrc and .exrc in the current directory. If - you switch this option on you should also consider setting the - 'secure' option (see 3.4 |initialization|). Using a local .exrc or - .vimrc is a potential security leak, use with care! + Enables the reading of .vimrc, .exrc and .gvimrc in the current + directory. If you switch this option on you should also consider + setting the 'secure' option (see 3.4 |initialization|). Using a local + .exrc, .vimrc or .gvimrc is a potential security leak, use with care! + also see |.vimrc| and |gui_init|. *'formatoptions'* *'fo'* formatoptions (fo) string (default "tcq", "vt" when compiled with @@ -8134,7 +8287,10 @@ incsearch (is) toggle (default off) While typing a search pattern, show immediately where the so far typed pattern matches. The matched string is highlighted. If the pattern is invalid or not found, nothing is shown. The screen will - be updated often, this is only useful on fast terminals. + be updated often, this is only useful on fast terminals. Note that + the match will be shown, but the cursor is not actually positioned + there. You still need to finish the search command with <CR> to move + the cursor. *'infercase'* *'inf'* *'noinfercase'* *'noinf'* infercase (inf) toggle (default off) @@ -8216,11 +8372,11 @@ iskeyword (isk) string (default for MS-DOS and Win32: local to buffer {not in Vi} Keywords are used in searching and recognizing with many commands: - "*", "[i", etc. See 'isfname' for a description of the format of this - option. For C programs you could use "a-z,A-Z,48-57,_,.,-,>". For a - help file it is set to all non-blank printable characters except '*', - '"' and '|'. When the 'lisp' option is on the '-' character is always - included. + "w", "*", "[i", etc. See 'isfname' for a description of the format of + this option. For C programs you could use "a-z,A-Z,48-57,_,.,-,>". + For a help file it is set to all non-blank printable characters except + '*', '"' and '|'. When the 'lisp' option is on the '-' character is + always included. *'isprint'* *'isp'* isprint (isp) string (default for MS-DOS and Win32: "@,~-255" @@ -8677,6 +8833,18 @@ shell (sh) string (default $SHELL or "sh", "csh -f". See |option_backslash| about including spaces and backslashes. Environment variables are expanded |:set_env|. + *'shellcmdflag'* *'shcf'* +shellcmdflag (shcf) string (default: "-c", MS-DOS and Win32, when 'shell' + does not contain "sh" somewhere: "/c") + global + {not in Vi} + Flag passed to the shell to execute "!" and ":!" commands; e.g., + "bash.exe -c ls" or "command.com /c dir". For the MS-DOS-like + systems, the default is set according to the value of 'shell', to + reduce the need to set this option by the user. It's not used for + OS/2 (EMX figures this out itself). See |option_backslash| about + including spaces and backslashes. See |win32_shell| for Win32. + *'shellpipe'* *'sp'* shellpipe (sp) string (default ">", "| tee", "|& tee" or "2>&1| tee") global @@ -8698,6 +8866,18 @@ shellpipe (sp) string (default ">", "| tee", "|& tee" or "2>&1| tee") In the future pipes may be used for filtering and this option will become obsolete (at least for Unix). + *'shellquote'* *'shq'* +shellquote (shq) string (default: ""; MS-DOS and Win32, when 'shell' + contains "sh" somewhere: "\"") + global + {not in Vi} + Quoting character(s) passed to the shell to execute "!" and ":!" + commands. This is an empty string by default. Only known to be + useful for third-party shells on MS-DOS-like systems, such as the MKS + Korn Shell or bash, where it should be "\"". The default is adjusted + according the value of 'shell', to reduce the need to set this option + by the user. See |win32_shell| for Win32. + *'shellredir'* *'srr'* shellredir (srr) string (default ">", ">&" or ">%s 2>&1") global @@ -8730,8 +8910,8 @@ shelltype (st) number (default 0) 4 and 5: use shell only for ':sh' command When not using the shell, the command is executed directly. - 0 and 2: use 'shell -c cmd' to start external commands - 1 and 3: use 'shell cmd' to start external commands + 0 and 2: use "shell 'shellcmdflag' cmd" to start external commands + 1 and 3: use "shell cmd" to start external commands *'shiftround'* *'sr'* *'noshiftround'* *'nosr'* shiftround (sr) toggle (default off) @@ -8785,12 +8965,12 @@ shortmess (shm) string (default "") shortname (sn) toggle (default off) local to buffer {not in Vi} - Filenames can be 8 characters plus one extension of 3 characters. - Multiple dots in file names are not allowed. When this option is on, - dots in filenames are replaced with underscores when adding an - extension (".~" or ".swp"). This option is not available for - MS-DOS and Win32, because then it would always be on. This option is - useful when editing files on an MS-DOS compatible filesystem, e.g., + Filenames are assumed to be 8 characters plus one extension of 3 + characters. Multiple dots in file names are not allowed. When this + option is on, dots in filenames are replaced with underscores when + adding an extension (".~" or ".swp"). This option is not available + for MS-DOS and Win32, because then it would always be on. This option + is useful when editing files on an MS-DOS compatible filesystem, e.g., messydos or crossdos. *'showbreak'* *'sbr'* @@ -9063,7 +9243,7 @@ ttimeoutlen (ttm) number (default -1) {not in Vi} The time in milliseconds that is waited for a key code or mapped key sequence to complete. Normally only 'timeoutlen' is used and - 'ttimeoutline' is -1. When a different timeout value for key codes is + 'ttimeoutlen' is -1. When a different timeout value for key codes is desired set 'ttimeoutlen' to a non-negative number. ttimeoutlen mapping delay key code delay @@ -9072,7 +9252,7 @@ ttimeoutlen (ttm) number (default -1) The timeout only happens when the 'timeout' and 'ttimeout' options tell so. A useful setting would be - :set timeout timeoutlen=3000 ttimeloutlen=100 + :set timeout timeoutlen=3000 ttimeoutlen=100 (time out on mapping after three seconds, time out on key codes after a tenth of a second). @@ -9097,6 +9277,19 @@ title toggle (default off, on when title can be restored) title of the window should change back to what it should be after exiting Vim (rather than using the "Thanks..." message). + *'titlelen'* +titlelen number (default 85) + global + {not in Vi} + Gives the percentage of 'columns' to use for the length of the window + title. When the title is longer, only the end of the path name is + shown. A '>' character is used to indicate this. Using a percentage + makes this adapt to the width of the window. But it won't work + perfectly, because the actual number of characters available also + depends on the font used and other things in the title bar. When + 'titlelen' is zero the full path is used. Otherwise, values from 1 to + 30000 can be used. + *'ttybuiltin'* *'tbi'* *'nottybuiltin'* *'notbi'* ttybuiltin (tbi) toggle (default on) global @@ -9215,8 +9408,8 @@ visualbell (vb) toggle (default off) {not in Vi} Use visual bell instead of beeping. The terminal code to display the visual bell is given with 't_vb'. When no beep of flash is wanted, - Does not work on the Amiga, you always get a screen flash. use ":set - vb t_vb=". Also see 'errorbells'. + use ":set vb t_vb=". Does not work on the Amiga, you always get a + screen flash. Also see 'errorbells'. *'warn'* *'nowarn'* warn toggle (default on) @@ -9447,6 +9640,15 @@ The default termcap entry for xterm on sun and other platforms does not contain the entry for scroll regions. Add ":cs=\E[%i%d;%dr:" to the xterm entry in /etc/termcap and everything should work. + *xterm_end_home_keys* +On some systems (at least on FreeBSD with X386 3.1.2) the codes that the <End> +and <Home> keys send contain a <Nul> character. To make these keys send the +proper key code, add these lines to your ~/.Xdefaults file: + +*VT100.Translations: #override \n\ + <Key>Home: string("0x1b") string("[7~") \n\ + <Key>End: string("0x1b") string("[8~") + 20.2 Terminal options *terminal_options* @@ -9548,6 +9750,10 @@ Note: Use the <> form if possible t_@7 <End> end key *t_@7* *'t_@7'* t_kP <PageUp> page-up key *t_kP* *'t_kP'* t_kN <PageDown> page-down key *t_kN* *'t_kN'* + t_K1 <kHome> keypad home key *t_K1* *'t_K1'* + t_K4 <kEnd> keypad end key *t_K4* *'t_K4'* + t_K3 <kPageUp> keypad page-up key *t_K3* *'t_K3'* + t_K5 <kPageDown> keypad page-down key *t_K5* *'t_K5'* Note about t_so and t_mr: When the termcap entry "so" is not present the entry for "mr" is used. And vice versa. The same is done for "se" and "me". diff --git a/usr.bin/vim/doc/vim_rlh.txt b/usr.bin/vim/doc/vim_rlh.txt index fd667d043aa..9f8dcbfbbe8 100644 --- a/usr.bin/vim/doc/vim_rlh.txt +++ b/usr.bin/vim/doc/vim_rlh.txt @@ -1,4 +1,4 @@ -*vim_rlh.txt* For Vim version 4.2. Last modification: 1996 June 11 +*vim_rlh.txt* For Vim version 4.4. Last modification: 1996 June 11 Right to Left and Hebrew Mapping for Vim *hebrew* ======================================== diff --git a/usr.bin/vim/doc/vim_tags b/usr.bin/vim/doc/vim_tags index acd78b65659..a58adfe8025 100644 --- a/usr.bin/vim/doc/vim_tags +++ b/usr.bin/vim/doc/vim_tags @@ -324,8 +324,11 @@ $ vim_ref.txt /\*$\* 'sections' vim_ref.txt /\*'sections'\* 'secure' vim_ref.txt /\*'secure'\* 'sh' vim_ref.txt /\*'sh'\* +'shcf' vim_ref.txt /\*'shcf'\* 'shell' vim_ref.txt /\*'shell'\* +'shellcmdflag' vim_ref.txt /\*'shellcmdflag'\* 'shellpipe' vim_ref.txt /\*'shellpipe'\* +'shellquote' vim_ref.txt /\*'shellquote'\* 'shellredir' vim_ref.txt /\*'shellredir'\* 'shelltype' vim_ref.txt /\*'shelltype'\* 'shiftround' vim_ref.txt /\*'shiftround'\* @@ -337,6 +340,7 @@ $ vim_ref.txt /\*$\* 'showcmd' vim_ref.txt /\*'showcmd'\* 'showmatch' vim_ref.txt /\*'showmatch'\* 'showmode' vim_ref.txt /\*'showmode'\* +'shq' vim_ref.txt /\*'shq'\* 'si' vim_ref.txt /\*'si'\* 'sidescroll' vim_ref.txt /\*'sidescroll'\* 'sj' vim_ref.txt /\*'sj'\* @@ -374,6 +378,10 @@ $ vim_ref.txt /\*$\* 't_DL' vim_ref.txt /\*'t_DL'\* 't_F1' vim_ref.txt /\*'t_F1'\* 't_F2' vim_ref.txt /\*'t_F2'\* +'t_K1' vim_ref.txt /\*'t_K1'\* +'t_K3' vim_ref.txt /\*'t_K3'\* +'t_K4' vim_ref.txt /\*'t_K4'\* +'t_K5' vim_ref.txt /\*'t_K5'\* 't_RI' vim_ref.txt /\*'t_RI'\* 't_ZH' vim_ref.txt /\*'t_ZH'\* 't_ZR' vim_ref.txt /\*'t_ZR'\* @@ -442,6 +450,7 @@ $ vim_ref.txt /\*$\* 'timeout' vim_ref.txt /\*'timeout'\* 'timeoutlen' vim_ref.txt /\*'timeoutlen'\* 'title' vim_ref.txt /\*'title'\* +'titlelen' vim_ref.txt /\*'titlelen'\* 'tl' vim_ref.txt /\*'tl'\* 'tm' vim_ref.txt /\*'tm'\* 'to' vim_ref.txt /\*'to'\* @@ -568,9 +577,39 @@ $ vim_ref.txt /\*$\* .exrc vim_ref.txt /\*.exrc\* .vimrc vim_ref.txt /\*.vimrc\* / vim_ref.txt /\*/\* +/$ vim_ref.txt /\*/$\* +/. vim_ref.txt /\*/.\* //; vim_ref.txt /\*//;\* /<CR> vim_ref.txt /\*/<CR>\* +/[] vim_ref.txt /\*/[]\* +/\ vim_ref.txt /\*/\\\* +/\(\) vim_ref.txt /\*/\\(\\)\* +/\+ vim_ref.txt /\*/\\+\* +/\. vim_ref.txt /\*/\\.\* +/\< vim_ref.txt /\*/\\<\* +/\= vim_ref.txt /\*/\\=\* +/\> vim_ref.txt /\*/\\>\* +/\F vim_ref.txt /\*/\\F\* +/\I vim_ref.txt /\*/\\I\* +/\K vim_ref.txt /\*/\\K\* +/\P vim_ref.txt /\*/\\P\* +/\[] vim_ref.txt /\*/\\[]\* +/\b vim_ref.txt /\*/\\b\* +/\bar vim_ref.txt /\*/\\bar\* +/\e vim_ref.txt /\*/\\e\* +/\f vim_ref.txt /\*/\\f\* +/\i vim_ref.txt /\*/\\i\* +/\k vim_ref.txt /\*/\\k\* +/\p vim_ref.txt /\*/\\p\* +/\r vim_ref.txt /\*/\\r\* +/\star vim_ref.txt /\*/\\star\* +/\t vim_ref.txt /\*/\\t\* +/\~ vim_ref.txt /\*/\\~\* +/^ vim_ref.txt /\*/^\* +/bar vim_ref.txt /\*/bar\* +/star vim_ref.txt /\*/star\* /vim/src/ vim_ref.txt /\*/vim/src/\* +/~ vim_ref.txt /\*/~\* 0 vim_ref.txt /\*0\* : vim_ref.txt /\*:\* :! vim_ref.txt /\*:!\* @@ -712,6 +751,7 @@ $ vim_ref.txt /\*$\* :edit! vim_ref.txt /\*:edit!\* :edit!_f vim_ref.txt /\*:edit!_f\* :edit_f vim_ref.txt /\*:edit_f\* +:endif vim_ref.txt /\*:endif\* :ex vim_ref.txt /\*:ex\* :exi vim_ref.txt /\*:exi\* :exit vim_ref.txt /\*:exit\* @@ -735,6 +775,7 @@ $ vim_ref.txt /\*$\* :iabbrev vim_ref.txt /\*:iabbrev\* :iabc vim_ref.txt /\*:iabc\* :iabclear vim_ref.txt /\*:iabclear\* +:if vim_ref.txt /\*:if\* :ij vim_ref.txt /\*:ij\* :ijump vim_ref.txt /\*:ijump\* :il vim_ref.txt /\*:il\* @@ -1140,6 +1181,7 @@ FileReadPost vim_ref.txt /\*FileReadPost\* FileReadPre vim_ref.txt /\*FileReadPre\* FileWritePost vim_ref.txt /\*FileWritePost\* FileWritePre vim_ref.txt /\*FileWritePre\* +Filter vim_ref.txt /\*Filter\* FilterReadPost vim_ref.txt /\*FilterReadPost\* FilterReadPre vim_ref.txt /\*FilterReadPre\* FilterWritePost vim_ref.txt /\*FilterWritePost\* @@ -1214,6 +1256,7 @@ X_vm vim_help.txt /\*X_vm\* X_wi vim_help.txt /\*X_wi\* X_wq vim_help.txt /\*X_wq\* Y vim_ref.txt /\*Y\* +ZQ vim_ref.txt /\*ZQ\* ZZ vim_ref.txt /\*ZZ\* [ vim_idx.txt /\*[\* [# vim_ref.txt /\*[#\* @@ -1276,7 +1319,10 @@ argument_list vim_ref.txt /\*argument_list\* author vim_help.txt /\*author\* auto_setting vim_ref.txt /\*auto_setting\* auto_shortname vim_ref.txt /\*auto_shortname\* +autocmd-<> vim_tips.txt /\*autocmd-<>\* autocommand vim_ref.txt /\*autocommand\* +autocommand-events vim_ref.txt /\*autocommand-events\* +autocommand-pattern vim_ref.txt /\*autocommand-pattern\* b vim_ref.txt /\*b\* backspace vim_ref.txt /\*backspace\* backspace_delete vim_40.txt /\*backspace_delete\* @@ -1287,6 +1333,7 @@ backup_table vim_ref.txt /\*backup_table\* bar vim_ref.txt /\*bar\* bars vim_help.txt /\*bars\* beep vim_ref.txt /\*beep\* +buffer-menu vim_tips.txt /\*buffer-menu\* bug_fixes vim_40.txt /\*bug_fixes\* bugs vim_help.txt /\*bugs\* builtin_terms vim_ref.txt /\*builtin_terms\* @@ -1379,8 +1426,10 @@ deleting vim_ref.txt /\*deleting\* dh vim_ref.txt /\*dh\* digraph_table vim_digr.txt /\*digraph_table\* digraphs vim_ref.txt /\*digraphs\* +distribution vim_help.txt /\*distribution\* dl vim_ref.txt /\*dl\* doc_files vim_ref.txt /\*doc_files\* +download vim_help.txt /\*download\* dp vim_ref.txt /\*dp\* drag_status_line vim_ref.txt /\*drag_status_line\* ds vim_ref.txt /\*ds\* @@ -1407,6 +1456,7 @@ fork vim_unix.txt /\*fork\* format_bullet_list vim_tips.txt /\*format_bullet_list\* format_comments vim_ref.txt /\*format_comments\* formatting vim_ref.txt /\*formatting\* +ftp vim_help.txt /\*ftp\* function-key vim_ref.txt /\*function-key\* function_key vim_ref.txt /\*function_key\* g vim_idx.txt /\*g\* @@ -1445,6 +1495,7 @@ gui_delete_menus vim_gui.txt /\*gui_delete_menus\* gui_extras vim_gui.txt /\*gui_extras\* gui_fork vim_gui.txt /\*gui_fork\* gui_horiz_scroll vim_gui.txt /\*gui_horiz_scroll\* +gui_init vim_gui.txt /\*gui_init\* gui_intro vim_gui.txt /\*gui_intro\* gui_menus vim_gui.txt /\*gui_menus\* gui_mouse vim_gui.txt /\*gui_mouse\* @@ -1560,6 +1611,7 @@ insert vim_ref.txt /\*insert\* insert_expand vim_ref.txt /\*insert_expand\* insert_index vim_idx.txt /\*insert_index\* inserting vim_ref.txt /\*inserting\* +into vim_dos.txt /\*into\* intro vim_ref.txt /\*intro\* j vim_ref.txt /\*j\* jumplist vim_ref.txt /\*jumplist\* @@ -1567,6 +1619,10 @@ k vim_ref.txt /\*k\* key_codes_changed vim_40.txt /\*key_codes_changed\* key_mapping vim_ref.txt /\*key_mapping\* key_notation vim_ref.txt /\*key_notation\* +keypad_end vim_ref.txt /\*keypad_end\* +keypad_home vim_ref.txt /\*keypad_home\* +keypad_page_down vim_ref.txt /\*keypad_page_down\* +keypad_page_up vim_ref.txt /\*keypad_page_up\* l vim_ref.txt /\*l\* left_right_motions vim_ref.txt /\*left_right_motions\* limits vim_ref.txt /\*limits\* @@ -1705,6 +1761,10 @@ t_CS vim_ref.txt /\*t_CS\* t_DL vim_ref.txt /\*t_DL\* t_F1 vim_ref.txt /\*t_F1\* t_F2 vim_ref.txt /\*t_F2\* +t_K1 vim_ref.txt /\*t_K1\* +t_K3 vim_ref.txt /\*t_K3\* +t_K4 vim_ref.txt /\*t_K4\* +t_K5 vim_ref.txt /\*t_K5\* t_RI vim_ref.txt /\*t_RI\* t_ZH vim_ref.txt /\*t_ZH\* t_ZR vim_ref.txt /\*t_ZR\* @@ -1822,6 +1882,7 @@ up_down_motions vim_ref.txt /\*up_down_motions\* use_visual_cmds vim_40.txt /\*use_visual_cmds\* useful-mappings vim_tips.txt /\*useful-mappings\* usenet vim_help.txt /\*usenet\* +using_CTRL-V vim_ref.txt /\*using_CTRL-V\* v vim_ref.txt /\*v\* v_! vim_ref.txt /\*v_!\* v_: vim_ref.txt /\*v_:\* @@ -1888,6 +1949,7 @@ vim_unix.txt vim_unix.txt /\*vim_unix.txt\* vim_w32.txt vim_w32.txt /\*vim_w32.txt\* vim_win.txt vim_win.txt /\*vim_win.txt\* vimdev vim_help.txt /\*vimdev\* +viminfo_errors vim_ref.txt /\*viminfo_errors\* viminfo_file vim_ref.txt /\*viminfo_file\* viminfo_file_marks vim_ref.txt /\*viminfo_file_marks\* vimrc vim_ref.txt /\*vimrc\* @@ -1895,6 +1957,9 @@ visual_block vim_ref.txt /\*visual_block\* visual_index vim_idx.txt /\*visual_index\* vt100_cursor_keys vim_ref.txt /\*vt100_cursor_keys\* w vim_ref.txt /\*w\* +win32_faq vim_w32.txt /\*win32_faq\* +win32_shell vim_w32.txt /\*win32_shell\* +win32_term vim_w32.txt /\*win32_term\* window_contents vim_ref.txt /\*window_contents\* window_size vim_ref.txt /\*window_size\* word vim_ref.txt /\*word\* @@ -1908,6 +1973,7 @@ x vim_ref.txt /\*x\* xterm-screens vim_tips.txt /\*xterm-screens\* xterm_copy_paste vim_ref.txt /\*xterm_copy_paste\* xterm_cursor_keys vim_ref.txt /\*xterm_cursor_keys\* +xterm_end_home_keys vim_ref.txt /\*xterm_end_home_keys\* y vim_ref.txt /\*y\* ye_option_gone vim_40.txt /\*ye_option_gone\* yy vim_ref.txt /\*yy\* diff --git a/usr.bin/vim/doc/vim_tips.txt b/usr.bin/vim/doc/vim_tips.txt index 28ac34e8610..95c44523a76 100644 --- a/usr.bin/vim/doc/vim_tips.txt +++ b/usr.bin/vim/doc/vim_tips.txt @@ -1,4 +1,4 @@ -*vim_tips.txt* For Vim version 4.2. Last modification: 1996 June 16 +*vim_tips.txt* For Vim version 4.4. Last modification: 1996 Aug 30 Contents: @@ -15,6 +15,7 @@ Useful mappings |useful-mappings| Compressing the help files |gzip-helpfile| Executing shell commands in a window |shell_window| Pseudo-Ex mode |pseudo-Q| +Using <> notation in autocommands |autocmd-<>| Editing C programs *C-editing* @@ -304,4 +305,23 @@ cabbrev visual cunmap <C-V><CR><NL> In a following version of Vim the "Q" command will be made Vi compatible. Use "gq" for formatting text. + +Using <> notation in autocommands *autocmd-<>* +================================= + +The <> notation is not recognized in the argument for :autocmd. To avoid +having to use special characters, you could use a mapping to get the <> +notation and then call the mapping from the autocmd. Example: + + *buffer-menu* +" +" This is for automatically adding the name of the file to the menu list +" first we use the normal mode to convert the 'dots' in the filename to +" \., store that in register '"' and then add that name to the Buffers menu +" list. WARNING: this does have some side effects, like overwriting the +" current register contents. +" +nmap _xaddbufmenu O<C-R>%<Esc>:.g/\./s/\./\\./g<CR>0"9y$u:menu Buffers.<C-R>9 :buffer <C-R>%<C-V><C-M><C-M> +autocmd BufNewFile,BufReadPre * normal _xaddbufmenu + vim:ts=8:sw=8:js:tw=78: diff --git a/usr.bin/vim/doc/vim_unix.txt b/usr.bin/vim/doc/vim_unix.txt index 48631b983b7..1761d41698a 100644 --- a/usr.bin/vim/doc/vim_unix.txt +++ b/usr.bin/vim/doc/vim_unix.txt @@ -1,4 +1,4 @@ -*vim_unix.txt* For Vim version 4.2. Last modification: 1996 Apr 23 +*vim_unix.txt* For Vim version 4.4. Last modification: 1996 Apr 23 This file contains the particularities for the Unix version of Vim. diff --git a/usr.bin/vim/doc/vim_w32.txt b/usr.bin/vim/doc/vim_w32.txt index b6cd5e2f1eb..1abe28ae949 100644 --- a/usr.bin/vim/doc/vim_w32.txt +++ b/usr.bin/vim/doc/vim_w32.txt @@ -1,4 +1,4 @@ -*vim_w32.txt* For Vim version 4.2. Last modification: 1996 June 13 +*vim_w32.txt* For Vim version 4.4. Last modification: 1996 Aug 12 This file documents the idiosyncrasies of the Win32 version of Vim. @@ -11,13 +11,66 @@ box"). It is not a full-fledged Windows GUI application, although it may become one some day. It will not run in the Win32s subsystem in Windows 3.1; use the 32-bit DOS version of Vim instead. See |vim_dos.txt|. -Vim for Win32 compiles with the Microsoft Visual C++ 2.0 compiler and later, -and with the Borland C++ 4.5 32-bit compiler and later. It compiles on -Windows 95 and all four NT platforms: i386, Alpha, MIPS, and PowerPC. The -NT/i386 and the Windows 95 binaries are identical. Use Makefile.w32 to -compile with Visual C++ and Makefile.b32 to compile with Borland C++. -You can set the colour used in five modes with nine termcap options. Which of +KNOWN PROBLEMS + +There are a few known problems with running the Win32 Vim on Windows 95. +Comments from somebody working at Microsoft: "Win95 console support has always +been and will always be flaky". +- Dead key support doesn't work. +- Resizing the window with ":set columns=nn rows=n" works, but executing + external commands may cause the system to crash. + +If this bothers you, use the 32 bit MS-DOS version. + +- When doing filename completion, matches for the short filename will also be + found. But this will result in the corresponding long filename. For + example, if you have the long file name "this_is_a_test" with the short + filename "this_i~1", the command ":e *1" will start editing + "this_is_a_test". + + +LOCATION OF DOCUMENTATION and VIMRC FILE + +You should set the environment variable "VIM" to the directory where the Vim +documentation files are. If "VIM" is used but not defined, "HOME" is tried +too. + +If the HOME environment variable is not set, the value "C:/" is used as a +default. + +The default help filename is "$VIM\vim_help.txt". If the environment variable +$VIM is not defined or the file is not found, the Win32 search path is used to +search for the file "vim_help.txt". If you do not want to put "vim_help.txt" +in your search path, use the command ":set helpfile=pathname" to tell Vim +where the help file is. |'helpfile'| + +Vim will look for initializations in eight places. The first that is found +is used and the others are ignored. The order is: + - The environment variable VIMINIT + - The file "$VIM/_vimrc" + - The file "$HOME/_vimrc" + - The file "$VIM/.vimrc" + - The file "$HOME/.vimrc" + - The environment variable EXINIT + - The file "$VIM/_exrc" + - The file "$HOME/_exrc" + + +USING BACKSLASHES + +Using backslashes in file names can be a problem. Vi halves the number of +backslashes for some commands. Vim is a bit more tolerant and backslashes +are not removed from a file name, so ":e c:\foo\bar" works as expected. But +when a backslash is used before a special character (space, comma, backslash, +etc.), it is removed. Use slashes to avoid problems: ":e c:/foo/bar" works +fine. Vim will replace the slashes with backslashes internally, to avoid +problems with some MS-DOS programs and Win32 programs. + + +USING COLORS + +You can set the color used in five modes with nine termcap options. Which of the five modes is used for which action depends on the |'highlight'| option. ":set t_mr=^V^[\|xxm" start of invert mode @@ -34,11 +87,11 @@ the five modes is used for which action depends on the |'highlight'| option. ":set t_ZR=^V^[\|xxm" back to normal text ^V is CTRL-V -^[ is ESC -xx must be replaced by a decimal code, which is the foreground colour number - and background colour number added together: +^[ is <Esc> +xx must be replaced with a decimal code, which is the foreground color number + and background color number added together: -COLOUR FOREGROUND BACKGROUND +COLOR FOREGROUND BACKGROUND black 0 0 blue 1 16 green 2 32 @@ -56,35 +109,38 @@ COLOUR FOREGROUND BACKGROUND yellow 14 224 white 15 240 -When you use 0, the colour is reset to the one used when you started Vim +When you use 0, the color is reset to the one used when you started Vim (usually 7, lightgray on black, but you can override this in NT. If you have -overridden the default colours in a command prompt, you may need to adjust -some of the highlight colours in your vimrc---see below). +overridden the default colors in a command prompt, you may need to adjust +some of the highlight colors in your vimrc---see below). The defaults for the various highlight modes are: - t_mr 112 reverse mode: black text on lightgray - t_md 63 bold mode: white text on cyan - t_me 0 normal mode (revert to default) + t_mr 112 reverse mode: black text (0) on lightgray (112) + t_md 63 bold mode: white text (15) on cyan (48) + t_me 0 normal mode (revert to default) - t_so 31 standout mode: white text on blue - t_se 0 standout mode end (revert to default) + t_so 31 standout mode: white (15) text on blue (16) + t_se 0 standout mode end (revert to default) - t_czh 225 italic mode: blue text on yellow - t_czr 0 italic mode end (revert to default) + t_czh 225 italic mode: blue text (1) on yellow (224) + t_czr 0 italic mode end (revert to default) - t_us 67 underline mode: cyan text on red - t_ue 0 underline mode end (revert to default) + t_us 67 underline mode: cyan text (3) on red (64) + t_ue 0 underline mode end (revert to default) -These colours were chosen because they also look good when using an inverted +These colors were chosen because they also look good when using an inverted display, but you can change them to your liking. Example: -:set t_mr=^V^[\|97m " start of invert mode: blue on brown -:set t_md=^V^[\|67m " start of bold mode: cyan on red -:set t_me=^V^[\|112m " back to normal mode: black on light gray +:set t_mr=^V^[\|97m " start of invert mode: blue (1) on brown (96) +:set t_md=^V^[\|67m " start of bold mode: cyan (3) on red (64) +:set t_me=^V^[\|112m " back to normal mode: black (0) on light gray (112) -:set t_so=^V^[\|37m " start of standout mode: magenta on green -:set t_se=^V^[\|112m " back to normal mode: black on light gray +:set t_so=^V^[\|37m " start of standout mode: magenta (5) on green (32) +:set t_se=^V^[\|112m " back to normal mode: black (0) on light gray (112) + + +TEXTMODE or NON-MS-DOS FILES If the "tx" (textmode) option is set (which is the default), Vim will accept a single <NL> or a <CR><NL> pair for end-of-line. When writing a file, Vim @@ -97,71 +153,81 @@ and writing in non-text mode (":se notx"). 'textmode' is set automatically when 'textauto' is on (which is the default), so you don't really have to worry about what you are doing. |'textmode'| |'textauto'| -When 'restorescreen' is set (which is the default), Vim will restore the -original contents of the console when exiting or when executing external -commands. If you don't want this, use ":set nors". |'restorescreen'| - -Using backslashes in file names can be a problem. Vi halves the number of -backslashes for some commands. Vim is a bit more tolerant and backslashes -are not removed from a file name, so ":e c:\foo\bar" works as expected. But -when a backslash is used before a special character (space, comma, backslash, -etc.), it is removed. Use slashes to avoid problems: ":e c:/foo/bar" works -fine. Vim will replace the slashes with backslashes internally, to avoid -problems with some MS-DOS programs and Win32 programs. - If you want to edit a script file or a binary file, you should reset the 'textmode' and 'textauto' options before loading the file. Script files and binary files may contain single <NL> characters which would be replaced with <CR><NL>. You can reset 'textmode' and 'textauto' automatically by starting Vim with the "-b" (binary) option. -You should set the environment variable "VIM" to the directory where the Vim -documentation files are. If "VIM" is used but not defined, "HOME" is tried -too. - -If the HOME environment variable is not set, the value "C:/" is used as a -default. - -The default help filename is "$VIM\vim_help.txt". If the environment variable -$VIM is not defined or the file is not found, the Win32 search path is used to -search for the file "vim_help.txt". If you do not want to put "vim_help.txt" -in your search path, use the command ":set helpfile=pathname" to tell Vim -where the help file is. |'helpfile'| - -Vim will look for initializations in eight places. The first that is found -is used and the others are ignored. The order is: - - The environment variable VIMINIT - - The file "$VIM/_vimrc" - - The file "$HOME/_vimrc" - - The file "$VIM/.vimrc" - - The file "$HOME/.vimrc" - - The environment variable EXINIT - - The file "$VIM/_exrc" - - The file "$HOME/_exrc" -The only kind of terminal type that the Win32 version of Vim understands is -"win32", which is built-in. If you set the TERM environment variable to -anything else, you will probably get very strange behaviour from Vim. This is -most likely to happen when running a non-standard shell such as Cygnus's -GNU-Win32 bash (http://www.cygnus.com/misc/gnu-win32) or the one in the MKS -toolkit. Use "unset TERM" before starting Vim! +:CD COMMAND The ":cd" command recognizes the drive specifier and changes the current drive. Use ":cd c:" to make drive C the active drive. Use ":cd d:\foo" to go to the directory "foo" in the root of drive D. UNC names are also recognized; e.g., ":cd \\server\share\dir". |:cd| + +INTERRUPTING + Use CTRL-BREAK instead of CTRL-C to interrupt searches. The CTRL-C is not detected until a key is read. -Temporary files (for filtering) are put in the current directory. +TEMP FILES + +Temporary files (for filtering) are put in the first directory in the next +list that exists and where a file can be created: + $TMP + $TEMP + C:\TMP + C:\TEMP + current directory + + +SHELL OPTION DEFAULT + *win32_shell* The default for the 'sh' ('shell') option is "command.com" on Windows 95 and "cmd.exe" on Windows NT. If SHELL is defined, it is used instead, and if SHELL is not defined but COMSPEC is, COMPSPEC is used. External commands are -started with "command /c <command_name>". Typing CTRL-Z starts a new +started with "<shell> /c <command_name>". Typing CTRL-Z starts a new command subshell. Return to Vim with "exit". |'shell'| |CTRL-Z| +If you are running a third-party shell, you may need to set the +|'shellcmdflag'| ('shcf') and |'shellquote'| ('shq') options. For example, +with the MKS Korn shell or with bash, the values of the options should be: + 'shellcmdflag' -c + 'shellquote' " +This will start the shell as + <shell> -c "<command name>" +"-c" is needed in place of "/c" and double quotes are needed around the +command passed to the shell. Vim will check for the presence of "sh" anywhere +in the 'shell' option. If it is present, the 'shellcmdflag' and 'shellquote' +option will be set to "-c" and "\"". + +TERM OPTION DEFAULT + *win32_term* +The only kind of terminal type that the Win32 version of Vim understands is +"win32", which is built-in. If you set 'term' to anything else, you will +probably get very strange behaviour from Vim. Therefore the default value of +'term' is not obtained from the environment variable "TERM". + + +RESTORE SCREEN CONTENTS + +When 'restorescreen' is set (which is the default), Vim will restore the +original contents of the console when exiting or when executing external +commands. If you don't want this, use ":set nors". |'restorescreen'| + + +COMPILING + +Vim for Win32 compiles with the Microsoft Visual C++ 2.0 compiler and later, +and with the Borland C++ 4.5 32-bit compiler and later. It compiles on +Windows 95 and all four NT platforms: i386, Alpha, MIPS, and PowerPC. The +NT/i386 and the Windows 95 binaries are identical. Use Makefile.w32 to +compile with Visual C++ and Makefile.b32 to compile with Borland C++. + The Win32 binary was compiled with Visual C++ version 4.0, using Makefile.w32. Other compilers should also work. If you get all kinds of strange error messages when compiling (you shouldn't with the Microsoft or Borland 32-bit @@ -170,10 +236,16 @@ done with the addcr program: "nmake -f makefile.w32 addcr". This will compile addcr.c to addcr.exe and then execute the addcr.bat file. Sometimes this fails. In that case, execute the addcr.bat file from the DOS prompt. + +USING THE MOUSE + The Win32 version of Vim supports using the mouse. If you have a two-button mouse, the middle button can be emulated by pressing both left and right buttons simultaneously. |mouse_using| + +WIN32 FAQ *win32_faq* + Q. Why does the Win32 version of Vim update the screen so slowly on Windows 95? A. The support for Win32 console mode applications is very buggy in Win95. For some unknown reason, the screen updates very slowly when Vim is run at diff --git a/usr.bin/vim/doc/vim_win.txt b/usr.bin/vim/doc/vim_win.txt index 1a3b5d7a388..1e62bc8b439 100644 --- a/usr.bin/vim/doc/vim_win.txt +++ b/usr.bin/vim/doc/vim_win.txt @@ -1,4 +1,4 @@ -*vim_win.txt* For Vim version 4.2. Last modification: 1996 June 16 +*vim_win.txt* For Vim version 4.4. Last modification: 1996 Aug 6 Editing with multiple windows and buffers. @@ -51,6 +51,9 @@ be editing empty buffers. If there are many filenames, the windows will become very small. You might want to set the 'winheight' option to create a workable situation. +Buf/Win Enter/Leave autocommands are not executed when opening the new windows +and reading the files, that's only done when they are really entered. + *status_line* A status line will be used to separate windows. The 'laststatus' option tells when the last window also has a status line: @@ -322,6 +325,8 @@ can also get to them with the buffer list commands, like ":bnext". :[N]sal[l] [N] Rearrange the screen to open one window for each argument. All other windows are closed (buffers become hidden). When a count is given, this is the maximum number of windows to open. + Buf/Win Enter/Leave autocommands are not executed for the new + windows here, that's only done when they are really entered. :[N]sa[rgument][!] [N] *:sa* *:sargument* Short for ":split | argument [N]": split window and go to Nth @@ -540,7 +545,9 @@ Be careful: there may be more hidden, modified buffers! :[N]ba[ll] [N] *:ba* *:ball* *:sba* *:sball* :[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in the buffer list. When a count is given, this is the maximum - number of windows to open. + number of windows to open. Buf/Win Enter/Leave autocommands + are not executed for the new windows here, that's only done + when they are really entered. Memory usage limits diff --git a/usr.bin/vim/edit.c b/usr.bin/vim/edit.c index 1c2d604b5ed..8ac5ed01d63 100644 --- a/usr.bin/vim/edit.c +++ b/usr.bin/vim/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: edit.c,v 1.2 1996/09/21 06:22:57 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -119,7 +119,6 @@ edit(initstr, startln, count) char_u *complete_pat = NULL; char_u *tmp_ptr; char_u *mesg = NULL; /* Message about completion */ - char_u *quick_m; /* Message without sleep */ int started_completion = FALSE; colnr_t complete_col = 0; /* init for gcc */ int complete_direction; @@ -136,22 +135,6 @@ edit(initstr, startln, count) #endif FPOS tpos; - /* sleep before redrawing, needed for "CTRL-O :" that results in an - * error message */ - if (msg_scroll || emsg_on_display) - { - mch_delay(1000L, TRUE); - msg_scroll = FALSE; - emsg_on_display = FALSE; - } -#ifdef SLEEP_IN_EMSG - if (need_sleep) - { - mch_delay(1000L, TRUE); - need_sleep = FALSE; - } -#endif - #ifdef USE_MOUSE /* * When doing a paste with the middle mouse button, Insstart is set to @@ -236,11 +219,17 @@ edit(initstr, startln, count) can_cindent = TRUE; #endif + /* + * If 'showmode' is set, show the current (insert/replace/..) mode. + * A warning message for changing a readonly file is given here, before + * actually changing anything. It's put after the mode, if any. + */ + i = 0; if (p_smd) - showmode(); + i = showmode(); if (!p_im) - change_warning(); /* give a warning if readonly */ + change_warning(i + 1); #ifdef DIGRAPHS do_digraph(-1); /* clear digraphs */ @@ -617,6 +606,10 @@ doESCkey: else if (p_smd) MSG(""); old_indent = 0; + + /* + * This is the ONLY return from edit(). + */ return (c == Ctrl('O')); /* @@ -1061,6 +1054,7 @@ redraw: break; case K_HOME: + case K_KHOME: undisplay_dollar(); tpos = curwin->w_cursor; if ((mod_mask & MOD_MASK_CTRL)) @@ -1071,6 +1065,7 @@ redraw: break; case K_END: + case K_KEND: undisplay_dollar(); tpos = curwin->w_cursor; if ((mod_mask & MOD_MASK_CTRL)) @@ -1146,6 +1141,7 @@ redraw: case K_S_UP: case K_PAGEUP: + case K_KPAGEUP: undisplay_dollar(); tpos = curwin->w_cursor; if (onepage(BACKWARD, 1L) == OK) @@ -1175,6 +1171,7 @@ redraw: case K_S_DOWN: case K_PAGEDOWN: + case K_KPAGEDOWN: undisplay_dollar(); tpos = curwin->w_cursor; if (onepage(FORWARD, 1L) == OK) @@ -1353,7 +1350,7 @@ docomplete: complete_direction = BACKWARD; else complete_direction = FORWARD; - quick_m = mesg = NULL; /* No message by default */ + mesg = NULL; /* No message by default */ if (!started_completion) { /* First time we hit ^N or ^P (in a row, I mean) */ @@ -1493,8 +1490,8 @@ docomplete: set_reg_ic(complete_pat); prog = vim_regcomp(complete_pat); if (prog != NULL && - find_tags(NULL, prog, &num_matches, &matches, FALSE) - == OK && num_matches > 0) + find_tags(NULL, prog, &num_matches, &matches, + FALSE, FALSE) == OK && num_matches > 0) { for (i = 0; i < num_matches; i++) if (add_completion(matches[i], -1, NULL, @@ -1524,6 +1521,10 @@ docomplete: if (ExpandWildCards(1, &complete_pat, &num_matches, &matches, FALSE, FALSE) == OK) { + /* + * May change home directory back to "~". + */ + tilde_replace(complete_pat, num_matches, matches); for (i = 0; i < num_matches; i++) if (add_completion(matches[i], -1, NULL, FORWARD) == RET_ERROR) @@ -1563,7 +1564,10 @@ docomplete: complete_pos = NULL; if (started_completion && curr_match == NULL && (p_ws || done_dir == BOTH_DIRECTIONS)) - quick_m = e_patnotf; + { + edit_submode_extra = e_patnotf; + edit_submode_highl = TRUE; + } else if (curr_match != NULL && complete_direction == FORWARD && curr_match->next != NULL) curr_match = curr_match->next; @@ -1650,7 +1654,10 @@ docomplete: mesg = IObuff; } else if (tot == 0) - quick_m = e_patnotf; + { + edit_submode_extra = e_patnotf; + edit_submode_highl = TRUE; + } } /* eat the ESC to avoid leaving insert mode */ @@ -1668,17 +1675,21 @@ docomplete: else /* back to what has been typed */ ptr = original_text; - if (curr_match == NULL || curr_match->original) + if (edit_submode_extra == NULL) { - edit_submode_extra = (char_u *)"Back at original"; - edit_submode_highl = TRUE; - } - else if (first_match != NULL && first_match->next != NULL && - (first_match->next == first_match || - first_match->next->original)) - { - edit_submode_extra = (char_u *)"(the only match)"; - edit_submode_highl = FALSE; + if (curr_match == NULL || curr_match->original) + { + edit_submode_extra = (char_u *)"Back at original"; + edit_submode_highl = TRUE; + } + else if (first_match != NULL && + first_match->next != NULL && + (first_match->next == first_match || + first_match->next->original)) + { + edit_submode_extra = (char_u *)"(the only match)"; + edit_submode_highl = FALSE; + } } /* @@ -1691,19 +1702,19 @@ docomplete: started_completion = TRUE; need_redraw = TRUE; - (void)set_highlight('r'); - msg_highlight = TRUE; + if (mesg != NULL) { + (void)set_highlight('r'); + msg_highlight = TRUE; msg(mesg); - mch_delay(1000L, FALSE); + mch_delay(2000L, FALSE); } - else if (quick_m != NULL) - msg(quick_m); - else if (edit_submode_extra != NULL) + if (edit_submode_extra != NULL) + { showmode(); - edit_submode_extra = NULL; - msg_highlight = FALSE; + edit_submode_extra = NULL; + } /* * If there is a file name for the match, overwrite any @@ -1712,8 +1723,7 @@ docomplete: * Truncate the file name to avoid a wait for return. */ if (curr_match != NULL && curr_match->fname != NULL && - (ctrl_x_mode != CTRL_X_DICTIONARY || - (mesg == NULL && quick_m == NULL))) + (ctrl_x_mode != CTRL_X_DICTIONARY || mesg == NULL)) { STRCPY(IObuff, "match in file "); i = (strsize(curr_match->fname) + 16) - sc_col; @@ -1723,7 +1733,9 @@ docomplete: STRCAT(IObuff, "<"); STRCAT(IObuff, curr_match->fname + i); msg(IObuff); + redraw_cmdline = FALSE; /* don't overwrite! */ } + break; #endif /* INSERT_EXPAND */ @@ -2901,7 +2913,7 @@ beginline(flag) * oneright oneleft cursor_down cursor_up * * Move one char {right,left,down,up}. - * Return OK when sucessful, FAIL when we hit a line of file boundary. + * Return OK when successful, FAIL when we hit a line of file boundary. */ int @@ -3076,8 +3088,16 @@ onepage(dir, count) return FAIL; for ( ; count > 0; --count) { - if (dir == FORWARD ? (curwin->w_topline >= - curbuf->b_ml.ml_line_count - 1) : (curwin->w_topline == 1)) + /* + * It's an error to move a page up when the first line is already on + * the screen. It's an error to move a page down when the last line + * is on the screen and the topline is 'scrolloff' lines from the + * last line. + */ + if (dir == FORWARD + ? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - p_so) && + curwin->w_botline > curbuf->b_ml.ml_line_count) + : (curwin->w_topline == 1)) { beep_flush(); return FAIL; @@ -3087,12 +3107,21 @@ onepage(dir, count) /* at end of file */ if (curwin->w_botline > curbuf->b_ml.ml_line_count) curwin->w_topline = curbuf->b_ml.ml_line_count; - /* next line is big */ - /* or just three lines on screen */ else { - if (plines(curwin->w_botline) >= curwin->w_height - 2 || - curwin->w_botline - curwin->w_topline <= 3) + /* + * When there are three or less lines on the screen, move them + * all to above the screen. + */ + if (curwin->w_botline - curwin->w_topline <= 3) + off = 0; + /* + * Make sure at least w_botline gets onto the screen, also + * when 'scrolloff' is non-zero and with very long lines. + */ + else if (plines(curwin->w_botline) + + plines(curwin->w_botline - 1) + + plines(curwin->w_botline - 2) >= curwin->w_height - 2) off = 0; else off = 2; @@ -3140,6 +3169,11 @@ onepage(dir, count) } cursor_correct(); beginline(MAYBE); + /* + * Avoid the screen jumping up and down when 'scrolloff' is non-zero. + */ + if (dir == FORWARD && curwin->w_cursor.lnum < curwin->w_topline + p_so) + scroll_cursor_top(1, FALSE); updateScreen(VALID); return OK; } diff --git a/usr.bin/vim/fileio.c b/usr.bin/vim/fileio.c index db0656cc057..42cd96f255b 100644 --- a/usr.bin/vim/fileio.c +++ b/usr.bin/vim/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: fileio.c,v 1.2 1996/09/21 06:22:58 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -36,11 +36,12 @@ static void check_marks_read __ARGS((void)); static void msg_add_fname __ARGS((BUF *, char_u *)); static int msg_add_textmode __ARGS((int)); static void msg_add_lines __ARGS((int, long, long)); +static void msg_add_eol __ARGS((void)); static int write_buf __ARGS((int, char_u *, int)); static linenr_t write_no_eol_lnum = 0; /* non-zero lnum when last line of next binary write should not have - an eol */ + an end-of-line */ void filemess(buf, name, s) @@ -100,10 +101,10 @@ readfile(fname, sfname, from, newfile, lines_to_skip, lines_to_read, filtering) long filesize = 0; int split = 0; /* number of split lines */ #define UNKNOWN 0x0fffffff /* file size is unknown */ - linenr_t linecnt = curbuf->b_ml.ml_line_count; + linenr_t linecnt; int error = FALSE; /* errors encountered */ int tx_error = FALSE; /* textmode, but no CR */ - long linerest = 0; /* remaining characters in line */ + long linerest = 0; /* remaining chars in line */ int firstpart = TRUE; /* reading first part */ #ifdef UNIX int perm; @@ -119,6 +120,10 @@ readfile(fname, sfname, from, newfile, lines_to_skip, lines_to_read, filtering) missing the eol */ +#ifdef AUTOCMD + write_no_eol_lnum = 0; /* in case it was set by the previous read */ +#endif + /* * If there is no file name yet, use the one for the read file. * b_notedited is set to reflect this. @@ -306,6 +311,13 @@ readfile(fname, sfname, from, newfile, lines_to_skip, lines_to_read, filtering) { int m = msg_scroll; int n = msg_scrolled; + BUF *old_curbuf = curbuf; + + /* + * The file must be closed again, the autocommands may want to change + * the file before reading it. + */ + close(fd); /* ignore errors */ /* * The output from the autocommands should not overwrite anything and @@ -321,6 +333,22 @@ readfile(fname, sfname, from, newfile, lines_to_skip, lines_to_read, filtering) apply_autocmds(EVENT_FILEREADPRE, fname, fname); if (msg_scrolled == n) msg_scroll = m; + + /* + * Don't allow the autocommands to change the current buffer. + * Try to re-open the file. + */ + if (curbuf != old_curbuf || + (fd = open((char *)fname, O_RDONLY | O_EXTRA)) < 0) + { + --no_wait_return; + msg_scroll = msg_save; + if (fd < 0) + EMSG("*ReadPre autocommands made the file unreadable"); + else + EMSG("*ReadPre autocommands must not change current buffer"); + return FAIL; + } } #endif @@ -330,10 +358,11 @@ readfile(fname, sfname, from, newfile, lines_to_skip, lines_to_read, filtering) msg_scroll = FALSE; /* overwrite the file message */ /* - * Set textmode now, before the "retry" caused by 'textauto' and after the - * autocommands, that may reset it. + * Set textmode and linecnt now, before the "retry" caused by 'textauto' + * and after the autocommands, which may change them. */ textmode = curbuf->b_p_tx; + linecnt = curbuf->b_ml.ml_line_count; retry: while (!error && !got_int) @@ -571,8 +600,7 @@ retry: } if (read_no_eol_lnum) { - STRCAT(IObuff, shortmess(SHM_LAST) ? "[noeol]" : - "[Incomplete last line]"); + msg_add_eol(); c = TRUE; } if (tx_error) @@ -625,7 +653,7 @@ retry: /* * Trick: We remember if the last line of the read didn't have * an eol for when writing it again. This is required for - * ":autocmd FileReadPost *.gz set bin|%!gunzip" to work. + * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. */ write_no_eol_lnum = read_no_eol_lnum; @@ -643,8 +671,6 @@ retry: apply_autocmds(EVENT_FILEREADPOST, fname, fname); if (msg_scrolled == n) msg_scroll = m; - - write_no_eol_lnum = 0; } #endif @@ -670,7 +696,7 @@ check_marks_read() #endif /* VIMINFO */ /* - * writeit - write to file 'fname' lines 'start' through 'end' + * buf_write() - write to file 'fname' lines 'start' through 'end' * * We do our own buffering here because fwrite() is so slow. * @@ -718,6 +744,7 @@ buf_write(buf, fname, sfname, start, end, append, forceit, int newfile = FALSE; /* TRUE if file doesn't exist yet */ int msg_save = msg_scroll; int overwriting; /* TRUE if writing over original */ + int no_eol = FALSE; /* no end-of-line written */ #if defined(UNIX) || defined(__EMX__XX) /*XXX fix me sometime? */ struct stat st_old; int made_writable = FALSE; /* 'w' bit has been set */ @@ -800,6 +827,7 @@ buf_write(buf, fname, sfname, start, end, append, forceit, #ifdef AUTOCMD /* * Apply PRE aucocommands. + * Set curbuf to the buffer to be written. * Careful: The autocommands may call buf_write() recursively! */ save_buf = curbuf; @@ -813,8 +841,26 @@ buf_write(buf, fname, sfname, start, end, append, forceit, apply_autocmds(EVENT_BUFWRITEPRE, fname, fname); else apply_autocmds(EVENT_FILEWRITEPRE, fname, fname); - curbuf = save_buf; - curwin->w_buffer = save_buf; + /* + * If the autocommands deleted or unloaded the buffer, give an error + * message. + */ + if (!buf_valid(buf) || buf->b_ml.ml_mfp == NULL) + { + --no_wait_return; + msg_scroll = msg_save; + EMSG("Autocommands deleted or unloaded buffer to be written"); + return FAIL; + } + /* + * If the autocommands didn't change the current buffer, go back to the + * original current buffer, if it still exists. + */ + if (curbuf == buf && buf_valid(save_buf)) + { + curbuf = save_buf; + curwin->w_buffer = save_buf; + } /* * The autocommands may have changed the number of lines in the file. @@ -834,6 +880,7 @@ buf_write(buf, fname, sfname, start, end, append, forceit, if (end < start) { --no_wait_return; + msg_scroll = msg_save; EMSG("Autocommand changed number of lines in unexpected way"); return FAIL; } @@ -919,6 +966,7 @@ buf_write(buf, fname, sfname, start, end, append, forceit, int some_error = FALSE; struct stat st_new; char_u *dirp; + char_u *rootname; #ifndef SHORT_FNAME int did_set_shortname; #endif @@ -942,19 +990,17 @@ buf_write(buf, fname, sfname, start, end, append, forceit, st_new.st_gid = 0; /* - * Isolate one directory name. + * Isolate one directory name, using an entry in 'bdir'. */ - len = copy_option_part(&dirp, copybuf, BUFSIZE, ","); - - if (*copybuf == '.') /* use same dir as file */ - STRCPY(copybuf, fname); - else /* use dir from 'bdir' option */ + (void)copy_option_part(&dirp, copybuf, BUFSIZE, ","); + rootname = get_file_in_dir(fname, copybuf); + if (rootname == NULL) { - if (!ispathsep(copybuf[len - 1])) - copybuf[len++] = PATHSEP; - STRCPY(copybuf + len, gettail(fname)); + some_error = TRUE; /* out of memory */ + goto nobackup; } + #ifndef SHORT_FNAME did_set_shortname = FALSE; #endif @@ -967,10 +1013,11 @@ buf_write(buf, fname, sfname, start, end, append, forceit, /* * Make backup file name. */ - backup = buf_modname(buf, copybuf, backup_ext); + backup = buf_modname(buf, rootname, backup_ext); if (backup == NULL) { some_error = TRUE; /* out of memory */ + vim_free(rootname); goto nobackup; } @@ -1031,6 +1078,7 @@ buf_write(buf, fname, sfname, start, end, append, forceit, } break; } + vim_free(rootname); /* * Try to create the backup file @@ -1123,6 +1171,7 @@ nobackup: { char_u *dirp; char_u *p; + char_u *rootname; /* * Form the backup file name - change path/fo.o.h to path/fo.o.h.bak @@ -1132,23 +1181,18 @@ nobackup: while (*dirp) { /* - * Isolate one directory name. + * Isolate one directory name and make the backup file name. */ - len = copy_option_part(&dirp, IObuff, IOSIZE, ","); - -#ifdef VMS - if (!memcmp(IObuff, "sys$disk:", 9)) -#else - if (*IObuff == '.') /* use same dir as file */ -#endif - backup = buf_modname(buf, fname, backup_ext); - else /* use dir from 'bdir' option */ + (void)copy_option_part(&dirp, IObuff, IOSIZE, ","); + rootname = get_file_in_dir(fname, IObuff); + if (rootname == NULL) + backup = NULL; + else { - if (!ispathsep(IObuff[len - 1])) - IObuff[len++] = PATHSEP; - STRCPY(IObuff + len, gettail(fname)); - backup = buf_modname(buf, IObuff, backup_ext); + backup = buf_modname(buf, rootname, backup_ext); + vim_free(rootname); } + if (backup != NULL) { /* @@ -1338,7 +1382,11 @@ nobackup: if (end == 0 || (lnum == end && buf->b_p_bin && (lnum == write_no_eol_lnum || (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol)))) + { + ++lnum; /* written the line, count it */ + no_eol = TRUE; break; + } if (buf->b_p_tx) /* write CR-NL */ { *s = CR; @@ -1445,6 +1493,11 @@ nobackup: STRCAT(IObuff, shortmess(SHM_NEW) ? "[New]" : "[New File]"); c = TRUE; } + if (no_eol) + { + msg_add_eol(); + c = TRUE; + } if (msg_add_textmode(buf->b_p_tx)) /* may add [textmode] */ c = TRUE; msg_add_lines(c, (long)lnum, nchars); /* add line/char count */ @@ -1552,14 +1605,16 @@ nofail: if (end == 0) { MSG_OUTSTR("\nWARNING: Original file may be lost or damaged\n"); - MSG_OUTSTR("don't quit the editor until the file is sucessfully written!"); + MSG_OUTSTR("don't quit the editor until the file is successfully written!"); } } msg_scroll = msg_save; #ifdef AUTOCMD + write_no_eol_lnum = 0; /* in case it was set by the previous read */ + /* - * Apply POST aucocommands. + * Apply POST autocommands. * Careful: The autocommands may call buf_write() recursively! */ save_buf = curbuf; @@ -1573,8 +1628,15 @@ nofail: apply_autocmds(EVENT_BUFWRITEPOST, fname, fname); else apply_autocmds(EVENT_FILEWRITEPOST, fname, fname); - curbuf = save_buf; - curwin->w_buffer = save_buf; + /* + * If the autocommands didn't change the current buffer, go back to the + * original current buffer, if it still exists. + */ + if (curbuf == buf && buf_valid(save_buf)) + { + curbuf = save_buf; + curwin->w_buffer = save_buf; + } #endif return retval; @@ -1642,6 +1704,15 @@ msg_add_lines(insert_space, lnum, nchars) } /* + * Append message for missing line separator to IObuff. + */ + static void +msg_add_eol() +{ + STRCAT(IObuff, shortmess(SHM_LAST) ? "[noeol]" : "[Incomplete last line]"); +} + +/* * write_buf: call write() to write a buffer * * return FAIL for failure, OK otherwise @@ -1989,3 +2060,95 @@ buf_check_timestamp(buf) } } } + +/* + * Adjust the line with missing eol, used for the next write. + * Used for do_filter(), when the input lines for the filter are deleted. + */ + void +write_lnum_adjust(offset) + linenr_t offset; +{ + if (write_no_eol_lnum) /* only if there is a missing eol */ + write_no_eol_lnum += offset; +} + +#ifdef USE_TMPNAM +extern char *tmpnam __ARGS((char *)); +#else +extern char *mktemp __ARGS((char *)); +#endif + +/* + * vim_tempname(): Return a unique name that can be used for a temp file. + * + * The temp file is NOT created. + * + * The returned pointer is to allocated memory. + * The returned pointer is NULL if no valid name was found. + */ + char_u * +vim_tempname(extra_char) + int extra_char; /* character to use in the name instead of '?' */ +{ +#ifdef USE_TMPNAM + char_u itmp[L_tmpnam]; /* use tmpnam() */ +#else + char_u itmp[TEMPNAMELEN]; +#endif + char_u *p; + +#if defined(TEMPDIRNAMES) + static char *(tempdirs[]) = {TEMPDIRNAMES}; + static int first_dir = 0; + int first_try = TRUE; + int i; + + /* + * Try a few places to put the temp file. + * To avoid waisting time with non-existing environment variables and + * directories, they are skipped next time. + */ + for (i = first_dir; i < sizeof(tempdirs) / sizeof(char *); ++i) + { + /* expand $TMP, leave room for '/', "v?XXXXXX" and NUL */ + expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 10); + if (mch_isdir(itmp)) /* directory exists */ + { + if (first_try) + first_dir = i; /* start here next time */ + first_try = FALSE; +#ifdef BACKSLASH_IN_FILENAME + /* + * really want a backslash here, because the filename will + * probably be used in a command line + */ + STRCAT(itmp, "\\"); +#else + STRCAT(itmp, PATHSEPSTR); +#endif + STRCAT(itmp, TEMPNAME); + if ((p = vim_strchr(itmp, '?')) != NULL) + *p = extra_char; + if (*mktemp((char *)itmp) == NUL) + continue; + return strsave(itmp); + } + } + return NULL; +#else + +# ifndef USE_TMPNAM /* tmpnam() will make its own name */ + STRCPY(itmp, TEMPNAME); +# endif + if ((p = vim_strchr(itmp, '?')) != NULL) + *p = extra_char; +# ifdef USE_TMPNAM + if (*tmpnam((char *)itmp) == NUL) +# else + if (*mktemp((char *)itmp) == NUL) +# endif + return NULL; + return strsave(itmp); +#endif +} diff --git a/usr.bin/vim/getchar.c b/usr.bin/vim/getchar.c index c1650459638..e3f31e3af49 100644 --- a/usr.bin/vim/getchar.c +++ b/usr.bin/vim/getchar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getchar.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: getchar.c,v 1.2 1996/09/21 06:22:59 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -108,6 +108,7 @@ static int read_redo __ARGS((int, int)); static void copy_redo __ARGS((int)); static void init_typebuf __ARGS((void)); static void gotchars __ARGS((char_u *, int)); +static void may_sync_undo __ARGS((void)); static int vgetorpeek __ARGS((int)); static int inchar __ARGS((char_u *, int, long)); static void map_free __ARGS((struct mapblock *)); @@ -805,11 +806,18 @@ gotchars(s, len) add_buff(&recordbuff, buf); } } + may_sync_undo(); +} - /* - * Do not sync in insert mode, unless cursor key has been used. - * Also don't sync while reading a script file. - */ +/* + * Sync undo. Called when typed characters are obtained from the typeahead + * buffer, or when a menu is used. + * Do not sync in insert mode, unless cursor key has been used. + * Also don't sync while reading a script file. + */ + static void +may_sync_undo() +{ if ((!(State & (INSERT + CMDLINE)) || arrow_used) && scriptin[curscript] == NULL) u_sync(); @@ -1230,9 +1238,11 @@ vgetorpeek(advance) typebuf[typeoff + 1] == KS_MENU) { /* - * Using a menu causes a break in undo! + * Using a menu may cause a break in undo! + * It's like using gotchars(), but without + * recording or writing to a script file. */ - u_sync(); + may_sync_undo(); del_typebuf(3, 0); idx = gui_get_menu_index(current_menu, local_State); @@ -1279,13 +1289,13 @@ vgetorpeek(advance) /* * Insert the 'to' part in the typebuf. * If 'from' field is the same as the start of the - * 'to' field, don't remap this part. + * 'to' field, don't remap the first character. * If m_noremap is set, don't remap the whole 'to' * part. */ if (ins_typebuf(mp->m_str, mp->m_noremap ? -1 : STRNCMP(mp->m_str, mp->m_keys, - (size_t)keylen) ? 0 : keylen, + (size_t)keylen) ? 0 : 1, 0, TRUE) == FAIL) { c = -1; @@ -1845,15 +1855,15 @@ map_free(mprev) * 'abbr' should be FALSE for mappings, TRUE for abbreviations. */ void -map_clear(modec, force, abbr) +map_clear(modec, forceit, abbr) int modec; - int force; + int forceit; int abbr; { struct mapblock *mp; int mode; - if (force) /* :mapclear! */ + if (forceit) /* :mapclear! */ mode = INSERT + CMDLINE; else if (modec == 'i') mode = INSERT; @@ -2014,7 +2024,7 @@ check_abbr(c, ptr, col, mincol) /* insert the last typed char */ (void)ins_typebuf(tb, TRUE, 0, TRUE); /* insert the to string */ - (void)ins_typebuf(mp->m_str, mp->m_noremap, 0, TRUE); + (void)ins_typebuf(mp->m_str, mp->m_noremap ? -1 : 0, 0, TRUE); /* no abbrev. for these chars */ no_abbr_cnt += STRLEN(mp->m_str) + j + 1; diff --git a/usr.bin/vim/globals.h b/usr.bin/vim/globals.h index a5298f18b7a..c52a48b407f 100644 --- a/usr.bin/vim/globals.h +++ b/usr.bin/vim/globals.h @@ -1,4 +1,4 @@ -/* $OpenBSD: globals.h,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: globals.h,v 1.2 1996/09/21 06:23:00 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -121,6 +121,8 @@ EXTERN int need_check_timestamps INIT(= FALSE); /* got STOP signal */ #ifdef AUTOCMD EXTERN int autocmd_busy INIT(= FALSE); /* Is apply_autocmds() busy? */ +EXTERN int autocmd_no_enter INIT(= FALSE); /* *Enter autocmds disabled */ +EXTERN int autocmd_no_leave INIT(= FALSE); /* *Leave autocmds disabled */ #endif #ifdef USE_MOUSE @@ -333,7 +335,9 @@ EXTERN int dont_wait_return INIT(= 0); /* no need to wait for return */ EXTERN int quit_more INIT(= FALSE); /* 'q' hit at "--more--" msg */ EXTERN char_u *last_cmdline INIT(= NULL); /* last command line (for ":) */ EXTERN char_u *new_last_cmdline INIT(= NULL); /* new value for last_cmdline */ -EXTERN char_u *autocmd_fname INIT(= NULL); /* fname for "^Vf" on cmdline */ +#ifdef AUTOCMD +EXTERN char_u *autocmd_fname INIT(= NULL); /* fname for <afile> on cmdline */ +#endif EXTERN int postponed_split INIT(= FALSE); /* for CTRL-W CTRL-] command */ EXTERN int replace_offset INIT(= 0); /* offset for replace_push() */ diff --git a/usr.bin/vim/gui.c b/usr.bin/vim/gui.c index 7ddd00f8a6b..1c41d15c2bb 100644 --- a/usr.bin/vim/gui.c +++ b/usr.bin/vim/gui.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gui.c,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: gui.c,v 1.2 1996/09/21 06:23:01 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -51,12 +51,18 @@ static void gui_update_horiz_scrollbar __ARGS((void)); gui_start() { char_u *old_term; + int pid; old_term = strsave(term_strings[KS_NAME]); mch_setmouse(FALSE); /* first switch mouse off */ - /* set_termname() will call gui_init() to start the GUI */ + /* + * Set_termname() will call gui_init() to start the GUI. + * Set the "starting" flag, to indicate that the GUI will start. + */ + gui.starting = TRUE; termcapinit((char_u *)"builtin_gui"); + gui.starting = FALSE; if (!gui.in_use) /* failed to start GUI */ termcapinit(old_term); @@ -69,9 +75,24 @@ gui_start() * Don't do this when Vim was started with "-f" or the 'f' flag is present * in 'guioptions'. */ - if (gui.in_use && gui.dofork && - vim_strchr(p_guioptions, GO_FORG) == NULL && fork() > 0) - exit(0); + if (gui.in_use && gui.dofork && vim_strchr(p_guioptions, GO_FORG) == NULL) + { + pid = fork(); + if (pid > 0) /* parent */ + exit(0); +#if defined(HAVE_SETSID) || defined(HAVE_SETPGID) + /* + * Change our process group. On some systems/shells a CTRL-C in the + * shell where Vim was started would otherwise kill gvim! + */ + if (pid == 0) /* child */ +# if defined(HAVE_SETSID) + (void)setsid(); +# else + (void)setpgid(0, 0); +# endif +#endif + } } /* @@ -360,7 +381,7 @@ gui_resize_window(pixel_width, pixel_height) gui_reset_scroll_region(); /* * At the "more" prompt there is no redraw, put the cursor at the last - * line here (why does it have to be one row too low???). + * line here (why does it have to be one row too low?). */ if (State == ASKMORE) gui.row = gui.num_rows; @@ -935,9 +956,9 @@ gui_get_menu_index(menu, state) * according to whether the command is an "unmenu" command. */ static int -gui_get_menu_cmd_modes(cmd, force, noremap, unmenu) +gui_get_menu_cmd_modes(cmd, forceit, noremap, unmenu) char_u *cmd; - int force; /* Was there a "!" after the command? */ + int forceit; /* Was there a "!" after the command? */ int *noremap; int *unmenu; { @@ -963,7 +984,7 @@ gui_get_menu_cmd_modes(cmd, force, noremap, unmenu) modes |= MENU_CMDLINE_MODE; cmd++; } - else if (force) /* menu!, noremenu! */ + else if (forceit) /* menu!, noremenu! */ modes |= MENU_INSERT_MODE | MENU_CMDLINE_MODE; else /* menu, noremenu */ modes |= MENU_NORMAL_MODE | MENU_VISUAL_MODE; @@ -979,10 +1000,10 @@ gui_get_menu_cmd_modes(cmd, force, noremap, unmenu) * Do the :menu commands. */ void -gui_do_menu(cmd, arg, force) +gui_do_menu(cmd, arg, forceit) char_u *cmd; char_u *arg; - int force; + int forceit; { char_u *menu_path; int modes; @@ -991,7 +1012,7 @@ gui_do_menu(cmd, arg, force) int unmenu; char_u *map_buf; - modes = gui_get_menu_cmd_modes(cmd, force, &noremap, &unmenu); + modes = gui_get_menu_cmd_modes(cmd, forceit, &noremap, &unmenu); menu_path = arg; if (*menu_path == NUL) { @@ -1277,7 +1298,9 @@ gui_free_menu(menu) { int i; - gui_mch_destroy_menu(menu); /* Free machine specific menu structures */ + /* Free machine specific menu structures (only when already created) */ + if (gui.in_use) + gui_mch_destroy_menu(menu); vim_free(menu->name); for (i = 0; i < 4; i++) gui_free_menu_string(menu, i); @@ -1441,10 +1464,10 @@ static int expand_modes = 0x0; * Work out what to complete when doing command line completion of menu names. */ char_u * -gui_set_context_in_menu_cmd(cmd, arg, force) +gui_set_context_in_menu_cmd(cmd, arg, forceit) char_u *cmd; char_u *arg; - int force; + int forceit; { char_u *after_dot; char_u *p; @@ -1470,7 +1493,7 @@ gui_set_context_in_menu_cmd(cmd, arg, force) * With :menu though you might want to add a menu with the same name as * one in another mode, so match menus fom other modes too. */ - expand_modes = gui_get_menu_cmd_modes(cmd, force, NULL, &unmenu); + expand_modes = gui_get_menu_cmd_modes(cmd, forceit, NULL, &unmenu); if (!unmenu) expand_modes = MENU_ALL_MODES; @@ -1628,7 +1651,7 @@ gui_init_which_components(oldval) int grey_old, grey_new; char_u *temp; - if (oldval != NULL) + if (oldval != NULL && gui.in_use) { /* * Check if the menu's go from grey to non-grey or vise versa. @@ -1977,6 +2000,7 @@ gui_do_horiz_scroll() int i; int vcol; int ret_val = FALSE; + int width; /* no wrapping, no scrolling */ if (curwin->w_p_wrap) @@ -1984,6 +2008,9 @@ gui_do_horiz_scroll() curwin->w_leftcol = scrollbar_value; + width = Columns; + if (curwin->w_p_nu) /* 8 characters of window used by line number */ + width -= 8; i = 0; vcol = 0; p = ml_get_curline(); @@ -2003,9 +2030,9 @@ gui_do_horiz_scroll() } while (p[i] && i <= curwin->w_cursor.col - && vcol <= curwin->w_leftcol + Columns) + && vcol <= curwin->w_leftcol + width) vcol += chartabsize(p[i++], (colnr_t)vcol); - if (vcol > curwin->w_leftcol + Columns) + if (vcol > curwin->w_leftcol + width) { /* * Cursor is on a character that is at least partly off the right hand diff --git a/usr.bin/vim/gui_at_sb.c b/usr.bin/vim/gui_at_sb.c index b279ddd03d6..e321c2d4ed7 100644 --- a/usr.bin/vim/gui_at_sb.c +++ b/usr.bin/vim/gui_at_sb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gui_at_sb.c,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: gui_at_sb.c,v 1.2 1996/09/21 06:23:02 downsj Exp $ */ /* vi:set ts=4 sw=4: */ /* MODIFIED ATHENA SCROLLBAR (USING ARROWHEADS AT ENDS OF TRAVEL) */ /* Modifications Copyright 1992 by Mitch Trachtenberg */ @@ -136,7 +136,7 @@ static void MoveThumb __ARGS((Widget, XEvent *, String *, Cardinal *)); static void NotifyThumb __ARGS((Widget, XEvent *, String *, Cardinal *)); static void NotifyScroll __ARGS((Widget, XEvent *, String *, Cardinal *)); static void EndScroll __ARGS((Widget, XEvent *, String *, Cardinal *)); -static void _Xaw3dDrawShadows __ARGS((Widget, XEvent *, Region, Boolean)); +static void _Xaw3dDrawShadows __ARGS((Widget, XEvent *, Region, int)); static void AllocTopShadowGC __ARGS((Widget)); static void AllocBotShadowGC __ARGS((Widget)); @@ -1063,7 +1063,7 @@ _Xaw3dDrawShadows(gw, event, region, out) Widget gw; XEvent *event; Region region; - Boolean out; + int out; { XPoint pt[6]; ScrollbarWidget sbw = (ScrollbarWidget) gw; diff --git a/usr.bin/vim/gui_athena.c b/usr.bin/vim/gui_athena.c index 75382c2902f..781147644f3 100644 --- a/usr.bin/vim/gui_athena.c +++ b/usr.bin/vim/gui_athena.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gui_athena.c,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: gui_athena.c,v 1.2 1996/09/21 06:23:03 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -28,7 +28,7 @@ #define puller_width 19 #define puller_height 19 -static char puller_bits[] = +static char_u puller_bits[] = { 0x00,0x00,0xf8,0x00,0x00,0xf8,0xf8,0x7f,0xf8,0x04,0x80,0xf8,0x04,0x80,0xf9, 0x84,0x81,0xf9,0x84,0x83,0xf9,0x84,0x87,0xf9,0x84,0x8f,0xf9,0x84,0x8f,0xf9, @@ -100,7 +100,7 @@ gui_athena_scroll_cb_jump(w, client_data, call_data) sb = &wp->w_scrollbar; - value = *((float *)call_data) * (float)sb->max + 0.5; + value = *((float *)call_data) * (float)(sb->max - 1) + 0.5; ++value; /* range is 1 to line_count */ sb->value = value; @@ -562,9 +562,9 @@ gui_mch_add_menu(menu, parent) XtAddCallback(menu->id, XtNcallback, gui_x11_menu_cb, (XtPointer)menu); - pullright_name = strnsave(menu->name, strlen(menu->name) + - strlen("-pullright")); - strcat(pullright_name, "-pullright"); + pullright_name = strnsave(menu->name, + STRLEN(menu->name) + strlen("-pullright")); + strcat((char *)pullright_name, "-pullright"); menu->submenu_id = XtVaCreatePopupShell(pullright_name, simpleMenuWidgetClass, parent->submenu_id, XtNforeground, gui.menu_fg_pixel, @@ -1016,9 +1016,9 @@ gui_athena_pullright_action(w, event, args, nargs) if (event->xmotion.x < (width * 3) / 4) return; - pullright_name = strnsave(XtName(menuw), strlen(XtName(menuw)) + - strlen("-pullright")); - strcat(pullright_name, "-pullright"); + pullright_name = strnsave((char_u *)XtName(menuw), + strlen(XtName(menuw)) + strlen("-pullright")); + strcat((char *)pullright_name, "-pullright"); popup = XtNameToWidget(w, pullright_name); vim_free(pullright_name); diff --git a/usr.bin/vim/gui_motif.c b/usr.bin/vim/gui_motif.c index 71787e4d1ae..4dccb7c744a 100644 --- a/usr.bin/vim/gui_motif.c +++ b/usr.bin/vim/gui_motif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gui_motif.c,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: gui_motif.c,v 1.2 1996/09/21 06:23:03 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -330,6 +330,11 @@ gui_mch_set_winsize() base_height += menu_height; } + /* + * Need to unmanage vimForm here for a moment, to avoid an error message + * when .gvimrc contains ":set guioptions=r". + */ + XtUnmanageChild(vimForm); XtVaSetValues(vimShell, #ifdef XmNbaseWidth XmNbaseWidth, base_width, @@ -342,6 +347,7 @@ gui_mch_set_winsize() XmNwidth, base_width + Columns * gui.char_width, XmNheight, base_height + Rows * gui.char_height, NULL); + XtManageChild(vimForm); } /* diff --git a/usr.bin/vim/help.c b/usr.bin/vim/help.c index b3d3a8cd4de..f7f71f924ae 100644 --- a/usr.bin/vim/help.c +++ b/usr.bin/vim/help.c @@ -1,4 +1,4 @@ -/* $OpenBSD: help.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: help.c,v 1.2 1996/09/21 06:23:04 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -40,7 +40,7 @@ do_help(arg) return; } - /* The first file is the best match */ + /* The first match is the best match */ arg = strsave(matches[0]); need_free = TRUE; FreeWild(num_matches, matches); @@ -98,7 +98,8 @@ do_help(arg) * open help file (do_ecmd() will set b_help flag, readfile() will * set b_p_ro flag) */ - (void)do_ecmd(0, fnamep, NULL, NULL, TRUE, (linenr_t)0, TRUE); + (void)do_ecmd(0, fnamep, NULL, NULL, (linenr_t)0, + ECMD_HIDE + ECMD_SET_HELP); /* save the values of the options we change */ vim_free(help_save_isk); @@ -202,34 +203,42 @@ find_help_tags(arg, num_matches, matches) regexp *prog; int attempt; int retval = FAIL; + int i; + static char *(mtable[]) = {"*", "g*", "[*", "]*", + "/*", "/\\*", "/\\(\\)", + "?", ":?", "?<CR>"}; + static char *(rtable[]) = {"star", "gstar", "[star", "]star", + "/star", "/\\\\star", "/\\\\(\\\\)", + "?", ":?", "?<CR>"}; reg_magic = p_magic; d = IObuff; /* assume IObuff is long enough! */ /* - * Replace "|" with "bar", """ with "quote" and "*" with "star" to - * match the name of the tags for these commands. - * Replace "*" with ".*" and "?" with "." to match command line - * completion. - * Insert a backslash before '~', '$' and '.' to avoid their - * special meaning. - * Replace "^x" by "CTRL-X". Don't do this for "^_" to make - * ":help i_^_CTRL-D" work. - * If tag starts with ', toss everything after a second '. Fixes - * CTRL-] on 'option'. (would include the trailing '.'). + * Recognize a few exceptions to the rule. Some strings that contain '*' + * with "star". Otherwise '*' is recognized as a wildcard. */ - if (STRCMP(arg, "*") == 0 || STRCMP(arg, "[*") == 0 || - STRCMP(arg, "]*") == 0) + for (i = sizeof(mtable) / sizeof(char *); --i >= 0; ) { - if (*arg != '*') - *d++ = *arg; - STRCPY(d, "star"); - d += 4; + if (STRCMP(arg, mtable[i]) == 0) + { + STRCPY(d, rtable[i]); + break; + } } - else + + if (i < 0) /* no match in table, replace single characters */ { for (s = arg; *s; ++s) { + /* + * Replace "|" with "bar" and """ with "quote" to match the name of + * the tags for these commands. + * Replace "*" with ".*" and "?" with "." to match command line + * completion. + * Insert a backslash before '~', '$' and '.' to avoid their + * special meaning. + */ if (d - IObuff > IOSIZE - 10) /* getting too long!? */ break; switch (*s) @@ -242,18 +251,18 @@ find_help_tags(arg, num_matches, matches) continue; case '*': *d++ = '.'; break; - /* "?", ":?" and "?<CR>" are real tags */ - case '?': if (arg[1] == NUL || - STRCMP(arg, ":?") == 0 || - STRCMP(arg, "?<CR>") == 0) - break; - *d++ = '.'; + case '?': *d++ = '.'; continue; case '$': case '.': case '~': *d++ = '\\'; break; } + + /* + * Replace "^x" by "CTRL-X". Don't do this for "^_" to make + * ":help i_^_CTRL-D" work. + */ if (*s < ' ' || (*s == '^' && s[1] && s[1] != '_')) /* ^x */ { STRCPY(d, "CTRL-"); @@ -267,12 +276,26 @@ find_help_tags(arg, num_matches, matches) } else if (*s == '^') /* "^" or "CTRL-^" or "^_" */ *d++ = '\\'; + + /* + * Insert a backslash before a backslash after a slash, for search + * pattern tags: "/\|" --> "/\\|". + */ + else if (s[0] == '\\' && s[1] != '\\' && + *arg == '/' && s == arg + 1) + *d++ = '\\'; + *d++ = *s; + + /* + * If tag starts with ', toss everything after a second '. Fixes + * CTRL-] on 'option'. (would include the trailing '.'). + */ if (*s == '\'' && s > arg && *arg == '\'') break; } + *d = NUL; } - *d = NUL; reg_ic = FALSE; prog = vim_regcomp(IObuff); @@ -284,7 +307,7 @@ find_help_tags(arg, num_matches, matches) { *matches = (char_u **)""; *num_matches = 0; - retval = find_tags(NULL, prog, num_matches, matches, TRUE); + retval = find_tags(NULL, prog, num_matches, matches, TRUE, FALSE); if (retval == FAIL || *num_matches) break; } diff --git a/usr.bin/vim/keymap.h b/usr.bin/vim/keymap.h index 8aff893a291..676617fbcb4 100644 --- a/usr.bin/vim/keymap.h +++ b/usr.bin/vim/keymap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: keymap.h,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: keymap.h,v 1.2 1996/09/21 06:23:05 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -272,6 +272,10 @@ #define K_END TERMCAP2KEY('@', '7') #define K_PAGEUP TERMCAP2KEY('k', 'P') #define K_PAGEDOWN TERMCAP2KEY('k', 'N') +#define K_KHOME TERMCAP2KEY('K', '1') /* keypad home (upper left) */ +#define K_KEND TERMCAP2KEY('K', '4') /* keypad end (lower left) */ +#define K_KPAGEUP TERMCAP2KEY('K', '3') /* keypad pageup (upper R.) */ +#define K_KPAGEDOWN TERMCAP2KEY('K', '5') /* keypad pagedown (lower R.) */ #define K_MOUSE TERMCAP2KEY(KS_MOUSE, K_FILLER) #define K_MENU TERMCAP2KEY(KS_MENU, K_FILLER) diff --git a/usr.bin/vim/main.c b/usr.bin/vim/main.c index 43d9841e981..eff7a9afaa2 100644 --- a/usr.bin/vim/main.c +++ b/usr.bin/vim/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: main.c,v 1.2 1996/09/21 06:23:05 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -758,7 +758,6 @@ main(argc, argv) if (gui.starting) { gui_start(); - gui.starting = FALSE; full_screen = TRUE; } #endif @@ -792,6 +791,16 @@ main(argc, argv) curbuf->b_p_bin = 1; /* binary file I/O */ } +/* + * "-e errorfile": Load the error file now. + * If the error file can't be read, exit before doing anything else. + */ + if (doqf && qf_init() == FAIL) /* if reading error file fails: exit */ + { + outchar('\n'); + mch_windexit(3); + } + /* Don't set the file name if there was a command in .vimrc that already * loaded the file */ if (curbuf->b_filename == NULL) @@ -815,13 +824,6 @@ main(argc, argv) window_count = 1; /* - * "-e errorfile": Load the error file now. - * If the error file can't be read, exit before doing anything else. - */ - if (doqf && qf_init() == FAIL) /* if reading error file fails: exit */ - mch_windexit(3); - -/* * Start putting things on the screen. * Scroll screen down before drawing over it * Clear screen now, so file message will not be cleared. @@ -872,28 +874,69 @@ main(argc, argv) msg_scroll = FALSE; if (curbuf->b_ml.ml_mfp == NULL) /* failed */ getout(1); + do_modelines(); /* do modelines */ + } + else + { + /* + * Open a buffer for windows that don't have one yet. + * Commands in the .vimrc might have loaded a file or split the window. + * Watch out for autocommands that delete a window. + */ +#ifdef AUTOCMD + /* + * Don't execute Win/Buf Enter/Leave autocommands here + */ + ++autocmd_no_enter; + ++autocmd_no_leave; +#endif + for (curwin = firstwin; curwin != NULL; curwin = curwin->w_next) + { + curbuf = curwin->w_buffer; + if (curbuf->b_ml.ml_mfp == NULL) + { + (void)open_buffer(); /* create memfile and read file */ #ifdef AUTOCMD - apply_autocmds(EVENT_BUFENTER, NULL, NULL); + curwin = firstwin; /* start again */ #endif - do_modelines(); /* do modelines */ + } + mch_breakcheck(); + if (got_int) + { + (void)vgetc(); /* only break the file loading, not the rest */ + break; + } + } +#ifdef AUTOCMD + --autocmd_no_enter; + --autocmd_no_leave; +#endif + curwin = firstwin; + curbuf = curwin->w_buffer; } - /* Only read the file if there is none for the current buffer, a command - * in the .vimrc might have loaded a file */ - else if (curbuf->b_ml.ml_mfp == NULL) - (void)open_buffer(); /* create memfile and read file */ +#ifdef AUTOCMD + apply_autocmds(EVENT_BUFENTER, NULL, NULL); +#endif setpcmark(); /* * When started with "-e errorfile" jump to first error now. */ if (doqf) - qf_jump(0, 0); + qf_jump(0, 0, FALSE); /* * If opened more than one window, start editing files in the other windows. * Make_windows() has already opened the windows. */ +#ifdef AUTOCMD + /* + * Don't execute Win/Buf Enter/Leave autocommands here + */ + ++autocmd_no_enter; + ++autocmd_no_leave; +#endif for (i = 1; i < window_count; ++i) { if (curwin->w_next == NULL) /* just checking */ @@ -907,7 +950,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, TRUE, (linenr_t)1, FALSE); + NULL, NULL, (linenr_t)1, ECMD_HIDE); if (arg_idx == arg_count - 1) arg_had_last = TRUE; ++arg_idx; @@ -919,7 +962,13 @@ main(argc, argv) break; } } +#ifdef AUTOCMD + --autocmd_no_enter; +#endif win_enter(firstwin, FALSE); /* back to first window */ +#ifdef AUTOCMD + --autocmd_no_leave; +#endif if (window_count > 1) win_equal(curwin, FALSE); /* adjust heights */ @@ -1070,12 +1119,16 @@ getout(r) #endif #ifdef VIMINFO + msg_didany = FALSE; /* Write out the registers, history, marks etc, to the viminfo file */ if (*p_viminfo != NUL) write_viminfo(NULL, FALSE); + if (msg_didany) /* make the user read the error message */ + { + no_wait_return = FALSE; + wait_return(FALSE); + } #endif /* VIMINFO */ - outchar('\r'); - outchar('\n'); mch_windexit(r); } diff --git a/usr.bin/vim/mark.c b/usr.bin/vim/mark.c index 75cc373e238..d73fffc17d8 100644 --- a/usr.bin/vim/mark.c +++ b/usr.bin/vim/mark.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mark.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: mark.c,v 1.2 1996/09/21 06:23:06 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -186,7 +186,7 @@ movemark(count) { if (buflist_getfile(curwin->w_jumplist[curwin->w_jumplistidx].fnum, curwin->w_jumplist[curwin->w_jumplistidx].mark.lnum, - 0) == FAIL) + 0, FALSE) == FAIL) return (FPOS *)NULL; curwin->w_cursor.col = curwin->w_jumplist[curwin->w_jumplistidx].mark.col; @@ -278,7 +278,7 @@ getmark(c, changefile) if (namedfm[c].mark.lnum != 0 && changefile && namedfm[c].fnum) { if (buflist_getfile(namedfm[c].fnum, - namedfm[c].mark.lnum, GETF_SETMARK) == OK) + namedfm[c].mark.lnum, GETF_SETMARK, FALSE) == OK) { curwin->w_cursor.col = namedfm[c].mark.col; return (FPOS *)-1; @@ -677,7 +677,10 @@ read_viminfo_filemark(line, fp, force) /* We only get here (hopefully) if line[0] == '\'' */ str = line + 1; if (*str > 127 || (!isdigit(*str) && !isupper(*str))) - EMSG2("viminfo: Illegal file mark name in line %s", line); + { + if (viminfo_error("Illegal file mark name", line)) + return TRUE; /* Too many errors, pretend end-of-file */ + } else { if (isdigit(*str)) @@ -876,7 +879,10 @@ copy_viminfo_marks(line, fp_in, fp_out, count, eof) if (line[0] != '>') { if (line[0] != '\n' && line[0] != '\r' && line[0] != '#') - EMSG2("viminfo: Illegal starting char in line %s", line); + { + if (viminfo_error("Missing '>'", line)) + return; /* too many errors, return now */ + } eof = vim_fgets(line, LSIZE, fp_in); continue; /* Skip this dud line */ } diff --git a/usr.bin/vim/memfile.c b/usr.bin/vim/memfile.c index 43022ab85be..1d05aa49655 100644 --- a/usr.bin/vim/memfile.c +++ b/usr.bin/vim/memfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memfile.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ +/* $OpenBSD: memfile.c,v 1.2 1996/09/21 06:23:07 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -130,7 +130,7 @@ mf_open(fname, trunc_file) { MEMFILE *mfp; int i; - long size; + off_t size; #ifdef UNIX struct STATFS stf; #endif @@ -346,6 +346,12 @@ mf_new(mfp, negative, page_count) mf_ins_used(mfp, hp); mf_ins_hash(mfp, hp); + /* + * Init the data to all zero, to avoid reading uninitialized data. + * This also avoids that the passwd file ends up in the swap file! + */ + (void)vim_memset((char *)(hp->bh_data), 0, (size_t)mfp->mf_page_size); + return hp; } @@ -847,7 +853,7 @@ mf_read(mfp, hp) MEMFILE *mfp; BHDR *hp; { - long_u offset; + off_t offset; unsigned page_size; unsigned size; @@ -857,7 +863,7 @@ mf_read(mfp, hp) page_size = mfp->mf_page_size; offset = page_size * hp->bh_bnum; size = page_size * hp->bh_page_count; - if ((long_u)lseek(mfp->mf_fd, offset, SEEK_SET) != offset) + if (lseek(mfp->mf_fd, offset, SEEK_SET) != offset) { EMSG("Seek error in swap file read"); return FAIL; @@ -880,7 +886,7 @@ mf_write(mfp, hp) MEMFILE *mfp; BHDR *hp; { - long_u offset; /* offset in the file */ + off_t offset; /* offset in the file */ blocknr_t nr; /* block nr which is being written */ BHDR *hp2; unsigned page_size; /* number of bytes in a page */ @@ -914,7 +920,7 @@ mf_write(mfp, hp) hp2 = hp; offset = page_size * nr; - if ((long_u)lseek(mfp->mf_fd, offset, SEEK_SET) != offset) + if (lseek(mfp->mf_fd, offset, SEEK_SET) != offset) { EMSG("Seek error in swap file write"); return FAIL; diff --git a/usr.bin/vim/memline.c b/usr.bin/vim/memline.c index 79d045b73e7..32c8c06ab4b 100644 --- a/usr.bin/vim/memline.c +++ b/usr.bin/vim/memline.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memline.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: memline.c,v 1.2 1996/09/21 06:23:08 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -332,8 +332,6 @@ ml_open() } b0p = (ZERO_BL *)(hp->bh_data); - (void)vim_memset(b0p, 0, sizeof(ZERO_BL)); /* init all to zero */ - b0p->b0_id[0] = BLOCK0_ID0; b0p->b0_id[1] = BLOCK0_ID1; b0p->b0_magic_long = (long)B0_MAGIC_LONG; @@ -726,7 +724,7 @@ ml_recover() int idx; int top; int txt_start; - long size; + off_t size; int called_from_main; int serious_error = TRUE; long mtime; @@ -1161,20 +1159,22 @@ recover_names(fname, list, nr) msg_outchar('\n'); } expand_interactively = TRUE; + /* * Do the loop for every directory in 'directory'. + * First allocate some memory to put the directory name in. */ + dir_name = alloc((unsigned)STRLEN(p_dir) + 1); dirp = p_dir; - while (*dirp) + while (dir_name != NULL && *dirp) { - /* find character after directory name */ - dir_name = dirp; - while (*dirp && *dirp != ',') - ++dirp; - dir_name = strnsave(dir_name, (int)(dirp - dir_name)); - if (dir_name == NULL) /* out of memory */ - break; - if (*dir_name == '.') /* check current dir */ + /* + * Isolate a directory name from *dirp and put it in dir_name. + * Advance dirp to next directory name. + */ + (void)copy_option_part(&dirp, dir_name, 31000, ","); + + if (dir_name[0] == '.' && dir_name[1] == NUL) /* check current dir */ { if (fname == NULL || *fname == NULL) { @@ -1264,7 +1264,7 @@ recover_names(fname, list, nr) } else if (list) { - if (*dir_name == '.') + if (dir_name[0] == '.' && dir_name[1] == NUL) { if (fname == NULL || *fname == NULL) MSG_OUTSTR(" In current directory:\n"); @@ -1300,13 +1300,8 @@ recover_names(fname, list, nr) for (i = 0; i < num_names; ++i) vim_free(names[i]); FreeWild(num_files, files); - - /* advance dirp to next directory name */ - vim_free(dir_name); - if (*dirp == ',') - ++dirp; - dirp = skipwhite(dirp); } + vim_free(dir_name); expand_interactively = FALSE; return file_count; } @@ -2900,33 +2895,76 @@ makeswapname(buf, dir_name) BUF *buf; char_u *dir_name; { - char_u *r, *s, *fname; + char_u *r, *s; #ifdef VMS r = modname(buf->b_xfilename, (char_u *)"_swp"); #else r = modname(buf->b_xfilename, (char_u *)".swp"); #endif - /* - * do not use dir_name - * - if dir_name starts with '.' (use current directory) - * - if out of memory - */ - if (*dir_name == '.' || r == NULL) - return r; + if (r == NULL) /* out of memory */ + return NULL; - fname = gettail(r); - s = concat_fnames(dir_name, fname, TRUE); + s = get_file_in_dir(r, dir_name); vim_free(r); return s; } /* + * Get file name to use for swap file or backup file. + * Use the name of the edited file "fname" and an entry in the 'dir' or 'bdir' + * option "dirname". + * - If "dirname" is ".", return "fname". + * - If "dirname" starts with "./", insert "dirname" in "fname". + * - Otherwise, prepend "dirname" to the tail of "fname". + * + * The return value is an allocated string and can be NULL. + */ + char_u * +get_file_in_dir(fname, dirname) + char_u *fname; + char_u *dirname; +{ + char_u *t; + char_u *tail; + char_u *retval; + int save_char; + + tail = gettail(fname); + + if (dirname[0] == '.' && dirname[1] == NUL) + retval = strsave(fname); + else if (dirname[0] == '.' && ispathsep(dirname[1])) + { + if (tail == fname) /* no path before file name */ + retval = concat_fnames(dirname + 2, tail, TRUE); + else + { + save_char = *tail; + *tail = NUL; + t = concat_fnames(fname, dirname + 2, TRUE); + *tail = save_char; + if (t == NULL) /* out of memory */ + retval = NULL; + else + { + retval = concat_fnames(t, tail, TRUE); + vim_free(t); + } + } + } + else + retval = concat_fnames(dirname, tail, TRUE); + + return retval; +} + +/* * Find out what name to use for the swap file for buffer 'buf'. * * Several names are tried to find one that does not exist * - * Note: if MAXNAMLEN is not correct, you will get error messages for + * Note: if BASENAMELEN is not correct, you will get error messages for * not being able to open the swapfile */ static char_u * @@ -2961,7 +2999,7 @@ findswapname(buf, dirp, old_fname) /* * Isolate a directory name from *dirp and put it in dir_name. - * First allocate some memore to put the directory name in. + * First allocate some memory to put the directory name in. */ dir_name = alloc((unsigned)STRLEN(*dirp) + 1); if (dir_name != NULL) diff --git a/usr.bin/vim/message.c b/usr.bin/vim/message.c index 1aa4177308f..07b07a32aa0 100644 --- a/usr.bin/vim/message.c +++ b/usr.bin/vim/message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: message.c,v 1.2 1996/09/21 06:23:09 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -16,6 +16,9 @@ #define MESSAGE /* don't include prototype for smsg() */ #include "proto.h" #include "option.h" +#ifdef __QNX__ +# include <stdarg.h> +#endif static void msg_screen_outchar __ARGS((int c)); static int msg_check_screen __ARGS((void)); @@ -48,6 +51,7 @@ msg(s) * automatic prototype generation does not understand this function */ #ifndef PROTO +#ifndef __QNX__ int smsg __ARGS((char_u *, long, long, long, long, long, long, long, long, long, long)); @@ -60,6 +64,16 @@ smsg(s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) sprintf((char *)IObuff, (char *)s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); return msg(IObuff); } +#else /* __QNX__ */ +void smsg(char_u *s, ...) +{ + va_list arglist; + va_start(arglist, s); + vsprintf((char *)IObuff, (char *)s, arglist); + va_end(arglist); + msg(IObuff); +} +#endif /* __QNX__ */ #endif /* @@ -162,7 +176,7 @@ emsg2(s, a1) if (a1 == NULL) a1 = (char_u *)"[NULL]"; /* Check for very long strings (can happen with ":help ^A<CR>") */ - if (STRLEN(s) + STRLEN(a1) >= IOSIZE) + if (STRLEN(s) + STRLEN(a1) >= (size_t)IOSIZE) a1 = (char_u *)"[string too long]"; sprintf((char *)IObuff, (char *)s, (char *)a1); return emsg(IObuff); diff --git a/usr.bin/vim/misccmds.c b/usr.bin/vim/misccmds.c index ff08529ab07..01e2c5dae5e 100644 --- a/usr.bin/vim/misccmds.c +++ b/usr.bin/vim/misccmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misccmds.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: misccmds.c,v 1.2 1996/09/21 06:23:10 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -1390,7 +1390,7 @@ set_Changed() { if (!curbuf->b_changed) { - change_warning(); + change_warning(0); curbuf->b_changed = TRUE; check_status(curbuf); } @@ -1441,7 +1441,9 @@ check_status(buf) * will be TRUE. */ void -change_warning() +change_warning(col) + int col; /* column for message; non-zero when in insert + mode and 'showmode' is on */ { if (curbuf->b_did_warn == FALSE && curbuf->b_changed == 0 && #ifdef AUTOCMD @@ -1449,9 +1451,16 @@ change_warning() #endif curbuf->b_p_ro) { - curbuf->b_did_warn = TRUE; - MSG("Warning: Changing a readonly file"); + /* + * Do what msg() does, but with a column offset. + */ + msg_start(); + msg_col = col; + MSG_OUTSTR("Warning: Changing a readonly file"); + msg_clr_eos(); + (void)msg_end(); mch_delay(1000L, TRUE); /* give him some time to think about it */ + curbuf->b_did_warn = TRUE; } } @@ -1800,8 +1809,8 @@ expand_env(src, dst, dstlen) } /* - * Replace home directory by "~/" in each space or comma separated filename in - * 'src'. If anything fails (except when out of space) dst equals src. + * Replace home directory by "~" in each space or comma separated filename in + * 'src'. If anything fails (except when out of space) dst equals src. */ void home_replace(buf, src, dst, dstlen) @@ -1862,8 +1871,9 @@ home_replace(buf, src, dst, dstlen) src += len; if (--dstlen > 0) *dst++ = '~'; + /* - * If it's just the home directory, make it "~/". + * If it's just the home directory, add "/". */ if (!ispathsep(src[0]) && --dstlen > 0) *dst++ = '/'; @@ -1898,10 +1908,9 @@ home_replace_save(buf, src) char_u *dst; unsigned len; - if (src == NULL) /* just in case */ - len = 3; - else - len = STRLEN(src) + 3; /* extra space for "~/" and trailing NUL */ + len = 3; /* space for "~/" and trailing NUL */ + if (src != NULL) /* just in case */ + len += STRLEN(src); dst = alloc(len); if (dst != NULL) home_replace(buf, src, dst, len); @@ -1984,6 +1993,40 @@ gettail(fname) } /* + * Get a pointer to one character past the head of a path name. + * Unix: after "/"; DOS: after "c:\"; Amiga: after "disk:/". + * If there is no head, path is returned. + */ + char_u * +get_past_head(path) + char_u *path; +{ + char_u *retval; + +#if defined(MSDOS) || defined(WIN32) || defined(OS2) + /* may skip "c:" */ + if (isalpha(path[0]) && path[1] == ':') + retval = path + 2; + else + retval = path; +#else +# if defined(AMIGA) + /* may skip "label:" */ + retval = vim_strchr(path, ':'); + if (retval == NULL) + retval = path; +# else /* Unix */ + retval = path; +# endif +#endif + + while (ispathsep(*retval)) + ++retval; + + return retval; +} + +/* * return TRUE if 'c' is a path separator. */ int @@ -2307,6 +2350,7 @@ commentorempty(s) /* * Recognize a line that starts with '{' or '}', or ends with ';' or '}'. + * Don't consider "} else" a terminated line. * Also consider a line terminated if it ends in ','. This is not 100% * correct, but this mostly means we are in initializations and then it's OK. */ @@ -2316,7 +2360,7 @@ isterminated(s) { s = skipwhite(s); - if (*s == '{' || *s == '}') + if (*s == '{' || (*s == '}' && !iselse(s))) return TRUE; while (*s) @@ -2416,6 +2460,8 @@ isif(p) iselse(p) char_u *p; { + if (*p == '}') /* accept "} else" */ + p = skipwhite(p + 1); return (STRNCMP(p, "else", 4) == 0 && !isidchar(p[4])); } @@ -2442,11 +2488,19 @@ iswhileofdo(p, lnum, ind_maxparen) /* XXX */ int retval = FALSE; p = skipwhite(p); + if (*p == '}') /* accept "} while (cond);" */ + p = skipwhite(p + 1); if (STRNCMP(p, "while", 5) == 0 && !isidchar(p[5])) { cursor_save = curwin->w_cursor; curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; + p = ml_get_curline(); + while (*p && *p != 'w') /* skip any '}', until the 'w' of the "while" */ + { + ++p; + ++curwin->w_cursor.col; + } if ((trypos = findmatchlimit(0, 0, ind_maxparen)) != NULL) { p = ml_get_pos(trypos) + 1; @@ -3254,8 +3308,9 @@ get_c_indent() /* * Check if we are after an "if", "while", etc. + * Also allow "} else". */ - if (is_cinword(l)) + if (is_cinword(l) || iselse(l)) { /* * Found an unterminated line after an if (), line up @@ -3349,7 +3404,7 @@ get_c_indent() /* * Check if we are after a while (cond); - * If so: Ignore the matching "do". + * If so: Ignore until the matching "do". */ /* XXX */ else if (iswhileofdo(l, curwin->w_cursor.lnum, ind_maxparen)) diff --git a/usr.bin/vim/normal.c b/usr.bin/vim/normal.c index b832f2b1d51..0988d74efd9 100644 --- a/usr.bin/vim/normal.c +++ b/usr.bin/vim/normal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: normal.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: normal.c,v 1.2 1996/09/21 06:23:11 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -102,6 +102,8 @@ normal() int ctrl_w = FALSE; /* got CTRL-W command */ int old_col = 0; int dont_adjust_op_end = FALSE; + static int search_dont_set_mark = FALSE; /* for "*" and "#" */ + FPOS old_pos; /* cursor position before command */ Prenum = 0; /* @@ -136,10 +138,20 @@ getcount: Prenum = Prenum * 10 + (c - '0'); if (Prenum < 0) /* got too large! */ Prenum = 999999999; + if (ctrl_w) + { + ++no_mapping; + ++allow_keys; /* no mapping for nchar, but keys */ + } c = vgetc(); #ifdef HAVE_LANGMAP LANGMAP_ADJUST(c, TRUE); #endif + if (ctrl_w) + { + --no_mapping; + --allow_keys; + } (void)add_to_showcmd(c, FALSE); } @@ -226,6 +238,7 @@ getcount: } msg_didout = FALSE; /* don't scroll screen up for normal command */ msg_col = 0; + old_pos = curwin->w_cursor; /* remember where cursor was */ #ifdef RIGHTLEFT if (curwin->w_p_rl && KeyTyped) /* invert horizontal operations */ @@ -288,11 +301,13 @@ getcount: case Ctrl('B'): case K_S_UP: case K_PAGEUP: + case K_KPAGEUP: dir = BACKWARD; case Ctrl('F'): case K_S_DOWN: case K_PAGEDOWN: + case K_KPAGEDOWN: if (checkclearop()) break; (void)onepage(dir, Prenum1); @@ -530,34 +545,28 @@ dozet: break; /* print full name if count given or :cd used */ fileinfo(did_cd | (int)Prenum, FALSE, FALSE); - - /* - * In Visual mode and "^O^G" in Insert mode, the message will be - * overwritten by the mode message. Wait a bit, until a key is hit. - */ - if ((VIsual_active || (restart_edit && p_smd)) && KeyTyped) - { - setcursor(); - flushbuf(); - mch_delay(10000L, FALSE); - } break; case K_CCIRCM: /* CTRL-^, short for ":e #" */ if (checkclearopq()) break; - (void)buflist_getfile((int)Prenum, (linenr_t)0, GETF_SETMARK|GETF_ALT); + (void)buflist_getfile((int)Prenum, (linenr_t)0, + GETF_SETMARK|GETF_ALT, FALSE); break; - case 'Z': /* write, if changed, and exit */ + /* + * "ZZ": write if changed, and exit window + * "ZQ": quit window (Elvis compatible) + */ + case 'Z': if (checkclearopq()) break; - if (nchar != 'Z') - { + if (nchar == 'Z') + stuffReadbuff((char_u *)":x\n"); + else if (nchar == 'Q') + stuffReadbuff((char_u *)":q!\n"); + else clearopbeep(); - break; - } - stuffReadbuff((char_u *)":x\n"); break; case Ctrl(']'): /* :ta to current identifier */ @@ -620,9 +629,14 @@ search_word: stuffReadbuff((char_u *)"?"); /* - * put cursor at start of word, makes search skip the word - * under the cursor + * Put cursor at start of word, makes search skip the word + * under the cursor. + * Call setpcmark() first, so "*``" puts the cursor back where + * it was, and set search_dont_set_mark to avoid doing it + * again when searching. */ + setpcmark(); + search_dont_set_mark = TRUE; curwin->w_cursor.col = ptr - ml_get_curline(); if (c != 'g' && iswordchar(*ptr)) @@ -670,7 +684,7 @@ search_word: case Ctrl('T'): /* backwards in tag stack */ if (checkclearopq()) break; - do_tag((char_u *)"", 2, (int)Prenum1); + do_tag((char_u *)"", 2, (int)Prenum1, FALSE); break; /* @@ -874,6 +888,7 @@ lineop: break; case K_HOME: + case K_KHOME: if ((mod_mask & MOD_MASK_CTRL)) goto goto_line_one; Prenum = 1; @@ -957,6 +972,7 @@ dowrdcmd: break; case K_END: + case K_KEND: if ((mod_mask & MOD_MASK_CTRL)) goto goto_line; /* FALLTHROUGH */ @@ -997,11 +1013,13 @@ dowrdcmd: curwin->w_set_curswant = TRUE; n = do_search(c, searchbuff, Prenum1, - SEARCH_MARK | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG); + (search_dont_set_mark ? 0 : SEARCH_MARK) | + SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG); if (n == 0) clearop(); else if (n == 2) op_motion_type = MLINE; + search_dont_set_mark = FALSE; break; case 'N': @@ -1107,12 +1125,10 @@ docsearch: if ((c == '[' && vim_strchr((char_u *)"{(*/#", nchar) != NULL) || (c == ']' && vim_strchr((char_u *)"})*/#", nchar) != NULL)) { - FPOS old_pos; FPOS new_pos; if (nchar == '*') nchar = '/'; - old_pos = curwin->w_cursor; new_pos.lnum = 0; while (Prenum1--) { @@ -1912,12 +1928,13 @@ cursormark: case '0': case K_HOME: + case K_KHOME: op_motion_type = MCHAR; op_inclusive = FALSE; if (curwin->w_p_wrap) { n = ((curwin->w_virtcol + (curwin->w_p_nu ? 8 : 0)) / - Columns) * Columns; + Columns) * Columns; if (curwin->w_p_nu && n > 8) n -= 8; } @@ -1932,15 +1949,16 @@ cursormark: case '$': case K_END: + case K_KEND: op_motion_type = MCHAR; op_inclusive = TRUE; if (curwin->w_p_wrap) { - curwin->w_curswant = MAXCOL; /* so we stay at the end */ + curwin->w_curswant = MAXCOL; /* so we stay at the end */ if (Prenum1 == 1) { n = ((curwin->w_virtcol + (curwin->w_p_nu ? 8 : 0)) / - Columns + 1) * Columns - 1; + Columns + 1) * Columns - 1; if (curwin->w_p_nu && n > 8) n -= 8; coladvance((colnr_t)n); @@ -2002,10 +2020,10 @@ gotofile: { /* do autowrite if necessary */ if (curbuf->b_changed && curbuf->b_nwindows <= 1 && !p_hid) - autowrite(curbuf); + autowrite(curbuf, FALSE); setpcmark(); - (void)do_ecmd(0, ptr, NULL, NULL, p_hid, (linenr_t)0, - FALSE); + (void)do_ecmd(0, ptr, NULL, NULL, (linenr_t)0, + p_hid ? ECMD_HIDE : 0); vim_free(ptr); } else @@ -2178,6 +2196,47 @@ goto_line_one: do_pending_operator(c, nchar, finish_op, searchbuff, &command_busy, old_col, FALSE, dont_adjust_op_end); + /* + * Wait when a message is displayed that will be overwritten by the mode + * message. + * In Visual mode and with "^O" in Insert mode, a short message will be + * overwritten by the mode message. Wait a bit, until a key is hit. + * In Visual mode, it's more important to keep the Visual area updated + * than keeping a message (e.g. from a /pat search). + * Only do this if the command was typed, not from a mapping. + * Also wait a bit after an error message, e.g. for "^O:". + * Don't redraw the screen, it would remove the message. + */ + if (((p_smd && ((VIsual_active && old_pos.lnum == curwin->w_cursor.lnum && + old_pos.col == curwin->w_cursor.col) || restart_edit) && + (clear_cmdline || redraw_cmdline) && msg_didany && KeyTyped) || + (restart_edit && !VIsual_active && (msg_scroll || emsg_on_display +#ifdef SLEEP_IN_EMSG + || need_sleep +#endif + ))) && + yankbuffer == 0 && !command_busy && stuff_empty() && op_type == NOP) + { + ++RedrawingDisabled; + cursupdate(); + --RedrawingDisabled; + setcursor(); + flushbuf(); + if (msg_scroll || emsg_on_display +#ifdef SLEEP_IN_EMSG + || need_sleep +#endif + ) + mch_delay(1000L, TRUE); /* wait at least one second */ + mch_delay(10000L, FALSE); /* wait up to ten seconds */ + + msg_scroll = FALSE; + emsg_on_display = FALSE; +#ifdef SLEEP_IN_EMSG + need_sleep = FALSE; +#endif + } + normal_end: if (op_type == NOP && yankbuffer == 0) clear_showcmd(); @@ -2186,7 +2245,8 @@ normal_end: && !command_busy && stuff_empty() && yankbuffer == 0) (void)edit(restart_edit, FALSE, 1L); - checkpcmark(); /* check if we moved since setting pcmark */ + if (!search_dont_set_mark) + checkpcmark(); /* check if we moved since setting pcmark */ vim_free(searchbuff); /* diff --git a/usr.bin/vim/ops.c b/usr.bin/vim/ops.c index 332aa96157a..c95fb1571ad 100644 --- a/usr.bin/vim/ops.c +++ b/usr.bin/vim/ops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ops.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: ops.c,v 1.2 1996/09/21 06:23:13 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -1323,7 +1323,8 @@ do_put(dir, count, fix_indent) if (y_size == 0 || y_array == NULL) { - EMSG2("Nothing in register %s", transchar(yankbuffer)); + EMSG2("Nothing in register %s", + yankbuffer == 0 ? (char_u *)"\"" : transchar(yankbuffer)); return; } @@ -1666,6 +1667,8 @@ do_dis(arg) for (p = yb->y_array[j]; *p && (n -= charsize(*p)) >= 0; ++p) msg_outtrans_len(p, 1); } + if (n > 1 && yb->y_type == MLINE) + MSG_OUTSTR("^J"); flushbuf(); /* show one line at a time */ } } @@ -2374,7 +2377,8 @@ read_viminfo_register(line, fp, force) } if (!isalnum(*str) && *str != '-') { - EMSG2("viminfo: Illegal register name in line %s", line); + if (viminfo_error("Illegal register name", line)) + return TRUE; /* too many errors, pretend end-of-file */ do_it = FALSE; } yankbuffer = *str++; diff --git a/usr.bin/vim/option.c b/usr.bin/vim/option.c index 437d14ce1cc..c9201ce4e05 100644 --- a/usr.bin/vim/option.c +++ b/usr.bin/vim/option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: option.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: option.c,v 1.2 1996/09/21 06:23:14 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -194,10 +194,16 @@ static struct option options[] = #else # if defined MSDOS || defined WIN32 (char_u *)"%*[^\"]\"%f\"%*[^0-9]%l: %m,%f(%l) : %m,%*[^ ] %f %l: %m,%f:%l:%m"}, -# elif defined(__EMX__) /* put most common here (i.e. gcc format) at front */ - (char_u *)"%f:%l:%m,%*[^\"]\"%f\"%*[^0-9]%l: %m,\"%f\"%*[^0-9]%l: %m"}, # else - (char_u *)"%*[^\"]\"%f\"%*[^0-9]%l: %m,\"%f\"%*[^0-9]%l: %m,%f:%l:%m"}, +# if defined(__EMX__) /* put most common here (i.e. gcc format) at front */ + (char_u *)"%f:%l:%m,%*[^\"]\"%f\"%*[^0-9]%l: %m,\"%f\"%*[^0-9]%l: %m,%f(%l:%c) : %m"}, +# else +# if defined(__QNX__) + (char_u *)"%f(%l):%*[^WE]%t%*[^0123456789]%n:%m"}, +# else /* Unix, probably */ + (char_u *)"%*[^\"]\"%f\"%*[^0-9]%l: %m,\"%f\"%*[^0-9]%l: %m,%f:%l:%m,\"%f\"\\, line %l%*[^0-9]%c%*[^ ] %m"}, +# endif +# endif # endif #endif {"esckeys", "ek", P_BOOL, (char_u *)&p_ek, @@ -236,9 +242,9 @@ static struct option options[] = #ifdef USE_GUI (char_u *)&p_guioptions, # ifdef UNIX - (char_u *)"aAgmr"}, + (char_u *)"agmr"}, # else - (char_u *)"Agmr"}, + (char_u *)"gmr"}, # endif #else (char_u *)NULL, @@ -395,10 +401,12 @@ static struct option options[] = {"path", "pa", P_STRING|P_EXPAND, (char_u *)&p_path, #if defined AMIGA || defined MSDOS || defined WIN32 (char_u *)".,,"}, -#elif defined(__EMX__) - (char_u *)".,/emx/include,,"}, #else +# if defined(__EMX__) + (char_u *)".,/emx/include,,"}, +# else /* Unix, probably */ (char_u *)".,/usr/include,,"}, +# endif #endif {"prompt", NULL, P_BOOL, (char_u *)NULL, (char_u *)FALSE}, @@ -433,16 +441,28 @@ static struct option options[] = {"secure", NULL, P_BOOL, (char_u *)&p_secure, (char_u *)FALSE}, {"shell", "sh", P_STRING|P_EXPAND, (char_u *)&p_sh, -#if defined(MSDOS) +#if defined(MSDOS) (char_u *)"command"}, -#elif defined(WIN32) +#else +# if defined(WIN32) (char_u *)""}, /* set in set_init_1() */ -#elif defined(__EMX__) +# else +# if defined(__EMX__) (char_u *)"cmd.exe"}, -#elif defined(ARCHIE) +# else +# if defined(ARCHIE) (char_u *)"gos"}, -#else +# else (char_u *)"sh"}, +# endif +# endif +# endif +#endif + {"shellcmdflag","shcf", P_STRING, (char_u *)&p_shcf, +#if defined(MSDOS) || defined(WIN32) + (char_u *)"/c"}, +#else + (char_u *)"-c"}, #endif {"shellpipe", "sp", P_STRING, (char_u *)&p_sp, #if defined(UNIX) || defined(OS2) @@ -454,6 +474,8 @@ static struct option options[] = #else (char_u *)">"}, #endif + {"shellquote", "shq", P_STRING, (char_u *)&p_shq, + (char_u *)""}, {"shellredir", "srr", P_STRING, (char_u *)&p_srr, (char_u *)">"}, {"shelltype", "st", P_NUM, (char_u *)&p_st, @@ -554,6 +576,8 @@ static struct option options[] = (char_u *)1000L}, {"title", NULL, P_BOOL, (char_u *)&p_title, (char_u *)FALSE}, + {"titlelen", NULL, P_NUM, (char_u *)&p_titlelen, + (char_u *)85L}, {"ttimeout", NULL, P_BOOL, (char_u *)&p_ttimeout, (char_u *)FALSE}, {"ttimeoutlen", "ttm", P_NUM, (char_u *)&p_ttm, @@ -1015,11 +1039,37 @@ set_init_3() } #endif +#if defined(MSDOS) || defined(WIN32) + /* + * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option. + * This is done after other initializations, where 'shell' might have been + * set, but only if they have not been set before. Default for p_shcf is + * "/c", for p_shq is "". For "sh" like shells it is changed here to + * "-c" and "\"". + */ + if (strstr((char *)p_sh, "sh") != NULL) + { + idx1 = findoption((char_u *)"shcf"); + if (!(options[idx1].flags & P_WAS_SET)) + { + p_shcf = (char_u *)"-c"; + options[idx1].def_val = p_shcf; + } + + idx1 = findoption((char_u *)"shq"); + if (!(options[idx1].flags & P_WAS_SET)) + { + p_shq = (char_u *)"\""; + options[idx1].def_val = p_shq; + } + } +#endif + /* * 'title' and 'icon' only default to true if they have not been set or reset * in .vimrc and we can read the old value. * When 'title' and 'icon' have been reset in .vimrc, we won't even check if - * they can be reset. this reduces startup time when using X on a remote + * they can be reset. This reduces startup time when using X on a remote * machine. */ idx1 = findoption((char_u *)"title"); @@ -1304,8 +1354,11 @@ do_set(arg) else if (varp == (char_u *)&(curbuf->b_p_lisp)) init_chartab(); /* ignore errors */ - else if (!starting && ((int *)varp == &p_title || - (int *)varp == &p_icon)) + else if (!starting && +#ifdef USE_GUI + !gui.starting && +#endif + ((int *)varp == &p_title || (int *)varp == &p_icon)) { /* * When setting 'title' or 'icon' on, call maketitle() @@ -1414,6 +1467,8 @@ do_set(arg) /* (re)set last window status line */ if ((long *)varp == &p_ls) last_status(); + if ((long *)varp == &p_titlelen && !starting) + maketitle(); } else if (opt_idx >= 0) /* string */ { @@ -1594,7 +1649,7 @@ do_set(arg) } if (*s++ == NUL) errmsg = (char_u *)"Missing colon"; - else if (*s == ',') + else if (*s == ',' || *s == NUL) errmsg = (char_u *)"Zero length string"; if (errmsg != NULL) break; @@ -1811,6 +1866,11 @@ skip: errmsg = e_positive; p_tm = 0; } + if (p_titlelen <= 0) + { + errmsg = e_positive; + p_titlelen = 85; + } if ((curwin->w_p_scroll <= 0 || curwin->w_p_scroll > curwin->w_height) && full_screen) { @@ -2585,126 +2645,134 @@ win_copy_options(wp_from, wp_to) /* * Copy options from one buffer to another. - * Used when creating a new buffer and when entering a buffer. - * Only do this once for a new buffer, otherwise allocated memory for the - * string option will be lost. + * Used when creating a new buffer and sometimes when entering a buffer. * When "entering" is TRUE we will enter the bp_to buffer. + * When "always" is TRUE, always copy the options, but only set + * b_p_initialized when appropriate. */ void -buf_copy_options(bp_from, bp_to, entering) +buf_copy_options(bp_from, bp_to, entering, always) BUF *bp_from; BUF *bp_to; int entering; + int always; { - /* - * Don't copy if one of the pointers is NULL or they are the same. - */ - if (bp_from == NULL || bp_to == NULL || bp_from == bp_to) - return; + int should_copy = TRUE; /* - * Always copy when entering and 'cpo' contains 'S'. - * Don't copy when already initialized. - * Don't copy when 'cpo' contains 's' and not entering. + * Don't do anything of the "to" buffer is invalid. */ - if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !entering) && - (bp_to->b_p_initialized || - (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) - { - check_buf_options(bp_to); /* make sure we don't have NULLs */ + if (bp_to == NULL || !buf_valid(bp_to)) return; - } /* - * If already initialized, need to free the allocated strings. - * Copy 'readonly' and 'textmode' only when not initialized. + * Only copy if the "from" buffer is valid and "to" and "from" are + * different. */ - if (bp_to->b_p_initialized) + if (bp_from != NULL && buf_valid(bp_from) && bp_from != bp_to) { - free_string_option(bp_to->b_p_fo); - free_string_option(bp_to->b_p_isk); - free_string_option(bp_to->b_p_com); -#ifdef CINDENT - free_string_option(bp_to->b_p_cink); - free_string_option(bp_to->b_p_cino); -#endif -#if defined(CINDENT) || defined(SMARTINDENT) - free_string_option(bp_to->b_p_cinw); -#endif - } - else - { - bp_to->b_p_ro = FALSE; /* don't copy readonly */ - bp_to->b_p_tx = bp_from->b_p_tx; - bp_to->b_p_tx_nobin = bp_from->b_p_tx_nobin; - } + /* + * Always copy when entering and 'cpo' contains 'S'. + * Don't copy when already initialized. + * Don't copy when 'cpo' contains 's' and not entering. + * 'S' entering initialized 's' should_copy + * yes yes X X TRUE + * yes no yes X FALSE + * no X yes X FALSE + * X no no yes FALSE + * X no no no TRUE + * no yes no X TRUE + */ + if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !entering) && + (bp_to->b_p_initialized || + (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) + should_copy = FALSE; + + if (should_copy || always) + { + /* + * Always free the allocated strings. + * If not already initialized, set 'readonly' and copy 'textmode'. + */ + free_buf_options(bp_to); + if (!bp_to->b_p_initialized) + { + bp_to->b_p_ro = FALSE; /* don't copy readonly */ + bp_to->b_p_tx = bp_from->b_p_tx; + bp_to->b_p_tx_nobin = bp_from->b_p_tx_nobin; + } - bp_to->b_p_ai = bp_from->b_p_ai; - bp_to->b_p_ai_save = bp_from->b_p_ai_save; - bp_to->b_p_sw = bp_from->b_p_sw; - bp_to->b_p_tw = bp_from->b_p_tw; - bp_to->b_p_tw_save = bp_from->b_p_tw_save; - bp_to->b_p_tw_nobin = bp_from->b_p_tw_nobin; - bp_to->b_p_wm = bp_from->b_p_wm; - bp_to->b_p_wm_save = bp_from->b_p_wm_save; - bp_to->b_p_wm_nobin = bp_from->b_p_wm_nobin; - bp_to->b_p_bin = bp_from->b_p_bin; - bp_to->b_p_et = bp_from->b_p_et; - bp_to->b_p_et_nobin = bp_from->b_p_et_nobin; - bp_to->b_p_ml = bp_from->b_p_ml; - bp_to->b_p_ml_nobin = bp_from->b_p_ml_nobin; - bp_to->b_p_inf = bp_from->b_p_inf; + bp_to->b_p_ai = bp_from->b_p_ai; + bp_to->b_p_ai_save = bp_from->b_p_ai_save; + bp_to->b_p_sw = bp_from->b_p_sw; + bp_to->b_p_tw = bp_from->b_p_tw; + bp_to->b_p_tw_save = bp_from->b_p_tw_save; + bp_to->b_p_tw_nobin = bp_from->b_p_tw_nobin; + bp_to->b_p_wm = bp_from->b_p_wm; + bp_to->b_p_wm_save = bp_from->b_p_wm_save; + bp_to->b_p_wm_nobin = bp_from->b_p_wm_nobin; + bp_to->b_p_bin = bp_from->b_p_bin; + bp_to->b_p_et = bp_from->b_p_et; + bp_to->b_p_et_nobin = bp_from->b_p_et_nobin; + bp_to->b_p_ml = bp_from->b_p_ml; + bp_to->b_p_ml_nobin = bp_from->b_p_ml_nobin; + bp_to->b_p_inf = bp_from->b_p_inf; #ifndef SHORT_FNAME - bp_to->b_p_sn = bp_from->b_p_sn; + bp_to->b_p_sn = bp_from->b_p_sn; #endif - bp_to->b_p_com = strsave(bp_from->b_p_com); - bp_to->b_p_fo = strsave(bp_from->b_p_fo); + bp_to->b_p_com = strsave(bp_from->b_p_com); + bp_to->b_p_fo = strsave(bp_from->b_p_fo); #ifdef SMARTINDENT - bp_to->b_p_si = bp_from->b_p_si; - bp_to->b_p_si_save = bp_from->b_p_si_save; + bp_to->b_p_si = bp_from->b_p_si; + bp_to->b_p_si_save = bp_from->b_p_si_save; #endif #ifdef CINDENT - bp_to->b_p_cin = bp_from->b_p_cin; - bp_to->b_p_cin_save = bp_from->b_p_cin_save; - bp_to->b_p_cink = strsave(bp_from->b_p_cink); - bp_to->b_p_cino = strsave(bp_from->b_p_cino); + bp_to->b_p_cin = bp_from->b_p_cin; + bp_to->b_p_cin_save = bp_from->b_p_cin_save; + bp_to->b_p_cink = strsave(bp_from->b_p_cink); + bp_to->b_p_cino = strsave(bp_from->b_p_cino); #endif #if defined(SMARTINDENT) || defined(CINDENT) - bp_to->b_p_cinw = strsave(bp_from->b_p_cinw); + bp_to->b_p_cinw = strsave(bp_from->b_p_cinw); #endif #ifdef LISPINDENT - bp_to->b_p_lisp = bp_from->b_p_lisp; - bp_to->b_p_lisp_save = bp_from->b_p_lisp_save; + bp_to->b_p_lisp = bp_from->b_p_lisp; + bp_to->b_p_lisp_save = bp_from->b_p_lisp_save; #endif - bp_to->b_p_ta_nobin = bp_from->b_p_ta_nobin; + bp_to->b_p_ta_nobin = bp_from->b_p_ta_nobin; - /* - * Don't copy the options set by do_help(), use the saved values - */ - if (!keep_help_flag && bp_from->b_help && help_save_isk != NULL) - { - bp_to->b_p_isk = strsave(help_save_isk); - if (bp_to->b_p_isk != NULL) - init_chartab(); - bp_to->b_p_ts = help_save_ts; - bp_to->b_help = FALSE; - } - else - { - bp_to->b_p_isk = strsave(bp_from->b_p_isk); - vim_memmove(bp_to->b_chartab, bp_from->b_chartab, (size_t)256); - bp_to->b_p_ts = bp_from->b_p_ts; - bp_to->b_help = bp_from->b_help; + /* + * Don't copy the options set by do_help(), use the saved values + */ + if (!keep_help_flag && bp_from->b_help && help_save_isk != NULL) + { + bp_to->b_p_isk = strsave(help_save_isk); + if (bp_to->b_p_isk != NULL) + init_chartab(); + bp_to->b_p_ts = help_save_ts; + bp_to->b_help = FALSE; + } + else + { + bp_to->b_p_isk = strsave(bp_from->b_p_isk); + vim_memmove(bp_to->b_chartab, bp_from->b_chartab, (size_t)256); + bp_to->b_p_ts = bp_from->b_p_ts; + bp_to->b_help = bp_from->b_help; + } + } + + /* + * When the options should be copied (ignoring "always"), set the flag + * that indicates that the options have been initialized. + */ + if (should_copy) + bp_to->b_p_initialized = TRUE; } - check_buf_options(bp_to); - /* - * Set the flag that indicates that the options have been ininitialized. - * Avoids loosing allocated memory. - */ - bp_to->b_p_initialized = TRUE; + check_buf_options(bp_to); /* make sure we don't have NULLs */ } + static int expand_option_idx = -1; static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; @@ -2856,6 +2924,7 @@ ExpandSettings(prog, num_file, file) int loop; int is_term_opt; char_u name_buf[MAX_KEY_NAME_LEN]; + int save_reg_ic; /* do this loop twice: * loop == 0: count the number of matching options @@ -2974,6 +3043,7 @@ ExpandSettings(prog, num_file, file) STRCPY(name_buf + 1, str); STRCAT(name_buf, ">"); + save_reg_ic = reg_ic; reg_ic = TRUE; /* ignore case here */ if (vim_regexec(prog, name_buf, TRUE)) { @@ -2982,6 +3052,7 @@ ExpandSettings(prog, num_file, file) else (*file)[count++] = strsave(name_buf); } + reg_ic = save_reg_ic; } } if (loop == 0) @@ -3243,7 +3314,7 @@ static int event_name2nr __ARGS((char_u *start, char_u **end)); static char *event_nr2name __ARGS((int event)); static char_u *find_end_event __ARGS((char_u *arg)); static int do_autocmd_event __ARGS((int event, char_u *pat, - char_u *cmd, int force)); + char_u *cmd, int forceit)); static void show_autocmd(ap, event) @@ -3412,9 +3483,9 @@ find_end_event(arg) * :autocmd * *.c show all autocommands for *.c files. */ void -do_autocmd(arg, force) +do_autocmd(arg, forceit) char_u *arg; - int force; + int forceit; { char_u *pat; char_u *cmd; @@ -3452,7 +3523,7 @@ do_autocmd(arg, force) /* * Print header when showing autocommands. */ - if (!force && *cmd == NUL) + if (!forceit && *cmd == NUL) { set_highlight('t'); /* Highlight title */ start_highlight(); @@ -3466,14 +3537,14 @@ do_autocmd(arg, force) if (*arg == '*' || *arg == NUL) { for (event = 0; event < NUM_EVENTS; ++event) - if (do_autocmd_event(event, pat, cmd, force) == FAIL) + if (do_autocmd_event(event, pat, cmd, forceit) == FAIL) break; } else { while (*arg && !vim_iswhite(*arg)) if (do_autocmd_event(event_name2nr(arg, &arg), pat, - cmd, force) == FAIL) + cmd, forceit) == FAIL) break; } } @@ -3482,14 +3553,14 @@ do_autocmd(arg, force) * do_autocmd() for one event. * If *pat == NUL do for all patterns. * If *cmd == NUL show entries. - * If force == TRUE delete entries. + * If forceit == TRUE delete entries. */ static int -do_autocmd_event(event, pat, cmd, force) +do_autocmd_event(event, pat, cmd, forceit) int event; char_u *pat; char_u *cmd; - int force; + int forceit; { AutoPat *ap; AutoPat *ap2; @@ -3508,12 +3579,12 @@ do_autocmd_event(event, pat, cmd, force) for (ap = first_autopat[event]; ap != NULL; ap = ap2) { ap2 = ap->next; - if (force) + if (forceit) del_autocmd(ap); else show_autocmd(ap, event); } - if (force) + if (forceit) first_autopat[event] = NULL; } @@ -3588,7 +3659,7 @@ do_autocmd_event(event, pat, cmd, force) * If not adding any new autocmd's for this pattern, delete the * pattern from the autopat list */ - else if (force) + else if (forceit) { del_autocmd_cmds(ap); if (*cmd == NUL) @@ -3610,7 +3681,7 @@ do_autocmd_event(event, pat, cmd, force) /* * Show autocmd's for this autopat */ - if (*cmd == NUL && !force) + if (*cmd == NUL && !forceit) { show_autocmd(ap, event); } @@ -3697,12 +3768,22 @@ apply_autocmds(event, fname, fname_io) AutoCmd *ac; int temp; int save_changed = curbuf->b_changed; + BUF *old_curbuf = curbuf; char_u *save_name; char_u *full_fname = NULL; int retval = FALSE; if (autocmd_busy) /* no nesting allowed */ return retval; + /* + * Check if these autocommands are disabled. Used when doing ":all" or + * ":ball". + */ + if ( (autocmd_no_enter && + (event == EVENT_WINENTER || event == EVENT_BUFENTER)) || + (autocmd_no_leave && + (event == EVENT_WINLEAVE || event == EVENT_BUFLEAVE))) + return retval; /* Don't redraw while doing auto commands. */ temp = RedrawingDisabled; @@ -3735,7 +3816,7 @@ apply_autocmds(event, fname, fname_io) tail = gettail(fname); - for (ap = first_autopat[event]; ap != NULL; ap = ap->next) + for (ap = first_autopat[event]; ap != NULL && !got_int; ap = ap->next) { #ifdef CASE_INSENSITIVE_FILENAME reg_ic = TRUE; /* Always ignore case */ @@ -3760,6 +3841,7 @@ apply_autocmds(event, fname, fname_io) vim_free(sourcing_name); } vim_free(prog); + mch_breakcheck(); } RedrawingDisabled = temp; autocmd_busy = FALSE; @@ -3767,9 +3849,13 @@ apply_autocmds(event, fname, fname_io) autocmd_fname = NULL; vim_free(full_fname); - /* Some events don't set or reset the Changed flag */ - if (event == EVENT_BUFREADPOST || event == EVENT_BUFWRITEPOST || - event == EVENT_FILEAPPENDPOST || event == EVENT_VIMLEAVE) + /* + * Some events don't set or reset the Changed flag. + * Check if still in the same buffer! + */ + if (curbuf == old_curbuf && + (event == EVENT_BUFREADPOST || event == EVENT_BUFWRITEPOST || + event == EVENT_FILEAPPENDPOST || event == EVENT_VIMLEAVE)) curbuf->b_changed = save_changed; return retval; diff --git a/usr.bin/vim/option.h b/usr.bin/vim/option.h index 37b1e5de6b2..47d7578da73 100644 --- a/usr.bin/vim/option.h +++ b/usr.bin/vim/option.h @@ -1,4 +1,4 @@ -/* $OpenBSD: option.h,v 1.1 1996/09/07 21:40:27 downsj Exp $ */ +/* $OpenBSD: option.h,v 1.2 1996/09/21 06:23:15 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -199,7 +199,9 @@ EXTERN long p_so; /* scroll offset */ EXTERN char_u *p_sections; /* sections */ EXTERN int p_secure; /* do .exrc and .vimrc in secure mode */ EXTERN char_u *p_sh; /* name of shell to use */ +EXTERN char_u *p_shcf; /* flag to shell to execute one command */ EXTERN char_u *p_sp; /* string for output of make */ +EXTERN char_u *p_shq; /* quote character(s) for shell */ EXTERN char_u *p_srr; /* string for output of filter */ EXTERN long p_st; /* type of shell */ EXTERN int p_sr; /* shift round off (for < and >) */ @@ -224,6 +226,7 @@ EXTERN int p_to; /* tilde is an operator */ EXTERN int p_timeout; /* mappings entered within one second */ EXTERN long p_tm; /* timeoutlen (msec) */ EXTERN int p_title; /* set window title if possible */ +EXTERN long p_titlelen; /* length of window title in % of Columns */ EXTERN int p_ttimeout; /* key codes entered within one second */ EXTERN long p_ttm; /* key code timeoutlen (msec) */ EXTERN int p_tbi; /* 'ttybuiltin' use builtin termcap first */ diff --git a/usr.bin/vim/proto/buffer.pro b/usr.bin/vim/proto/buffer.pro index 1b69b9aad2d..947c57916e6 100644 --- a/usr.bin/vim/proto/buffer.pro +++ b/usr.bin/vim/proto/buffer.pro @@ -1,13 +1,15 @@ -/* $OpenBSD: buffer.pro,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: buffer.pro,v 1.2 1996/09/21 06:23:49 downsj Exp $ */ /* buffer.c */ int open_buffer __PARMS((void)); +int buf_valid __PARMS((BUF *buf)); void close_buffer __PARMS((WIN *win, BUF *buf, int free_buf, int del_buf)); void buf_clear __PARMS((BUF *buf)); void buf_freeall __PARMS((BUF *buf)); char_u *do_bufdel __PARMS((int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit)); int do_buffer __PARMS((int action, int start, int dir, int count, int forceit)); BUF *buflist_new __PARMS((char_u *fname, char_u *sfname, linenr_t lnum, int use_curbuf)); -int buflist_getfile __PARMS((int n, linenr_t lnum, int options)); +void free_buf_options __PARMS((BUF *buf)); +int buflist_getfile __PARMS((int n, linenr_t lnum, int options, int forceit)); void buflist_getlnum __PARMS((void)); BUF *buflist_findname __PARMS((char_u *fname)); int buflist_findpat __PARMS((char_u *pattern, char_u *pattern_end)); diff --git a/usr.bin/vim/proto/cmdcmds.pro b/usr.bin/vim/proto/cmdcmds.pro index 5e73bf8b0e9..1bf7078bfd7 100644 --- a/usr.bin/vim/proto/cmdcmds.pro +++ b/usr.bin/vim/proto/cmdcmds.pro @@ -1,15 +1,15 @@ -/* $OpenBSD: cmdcmds.pro,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: cmdcmds.pro,v 1.2 1996/09/21 06:23:50 downsj Exp $ */ /* cmdcmds.c */ void do_ascii __PARMS((void)); void do_align __PARMS((linenr_t start, linenr_t end, int width, int type)); -void do_retab __PARMS((linenr_t start, linenr_t end, int new_ts, int force)); +void do_retab __PARMS((linenr_t start, linenr_t end, int new_ts, int forceit)); int do_move __PARMS((linenr_t line1, linenr_t line2, linenr_t n)); void do_copy __PARMS((linenr_t line1, linenr_t line2, linenr_t n)); void do_bang __PARMS((int addr_count, linenr_t line1, linenr_t line2, int forceit, char_u *arg, int do_in, int do_out)); void do_shell __PARMS((char_u *cmd)); -void do_filter __PARMS((linenr_t line1, linenr_t line2, char_u *buff, int do_in, int do_out)); -int read_viminfo __PARMS((char_u *file, int want_info, int want_marks, int force)); -void write_viminfo __PARMS((char_u *file, int force)); +int viminfo_error __PARMS((char *message, char_u *line)); +int read_viminfo __PARMS((char_u *file, int want_info, int want_marks, int forceit)); +void write_viminfo __PARMS((char_u *file, int forceit)); void viminfo_readstring __PARMS((char_u *p)); void viminfo_writestring __PARMS((FILE *fd, char_u *p)); void do_fixdel __PARMS((void)); diff --git a/usr.bin/vim/proto/cmdline.pro b/usr.bin/vim/proto/cmdline.pro index 293108aee1c..80dc5e13ffb 100644 --- a/usr.bin/vim/proto/cmdline.pro +++ b/usr.bin/vim/proto/cmdline.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdline.pro,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: cmdline.pro,v 1.2 1996/09/21 06:23:50 downsj Exp $ */ /* cmdline.c */ void add_to_history __PARMS((int histype, char_u *new_entry)); char_u *getcmdline __PARMS((int firstc, long count)); @@ -8,14 +8,15 @@ int realloc_cmdbuff __PARMS((int len)); void redrawcmdline __PARMS((void)); void compute_cmdrow __PARMS((void)); int do_cmdline __PARMS((char_u *cmdline, int sourcing, int repeating)); -int autowrite __PARMS((BUF *buf)); +int autowrite __PARMS((BUF *buf, int forceit)); void autowrite_all __PARMS((void)); -int do_ecmd __PARMS((int fnum, char_u *fname, char_u *sfname, char_u *command, int hide, linenr_t newlnum, int set_help)); +int do_ecmd __PARMS((int fnum, char_u *fname, char_u *sfname, char_u *command, linenr_t newlnum, int flags)); void check_arg_idx __PARMS((void)); void gotocmdline __PARMS((int clr)); int check_fname __PARMS((void)); -int getfile __PARMS((int fnum, char_u *fname, char_u *sfname, int setpm, linenr_t lnum)); +int getfile __PARMS((int fnum, char_u *fname, char_u *sfname, int setpm, linenr_t lnum, int forceit)); char_u *ExpandOne __PARMS((char_u *str, char_u *orig, int options, int mode)); +void tilde_replace __PARMS((char_u *orig_pat, int num_files, char_u **files)); char_u *addstar __PARMS((char_u *fname, int len)); int do_source __PARMS((register char_u *fname, int check_other)); void prepare_viminfo_history __PARMS((int len)); diff --git a/usr.bin/vim/proto/fileio.pro b/usr.bin/vim/proto/fileio.pro index 0330a055bb9..61582f14f78 100644 --- a/usr.bin/vim/proto/fileio.pro +++ b/usr.bin/vim/proto/fileio.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: fileio.pro,v 1.2 1996/09/21 06:23:51 downsj Exp $ */ /* fileio.c */ void filemess __PARMS((BUF *buf, char_u *name, char_u *s)); int readfile __PARMS((char_u *fname, char_u *sfname, linenr_t from, int newfile, linenr_t lines_to_skip, linenr_t lines_to_read, int filtering)); @@ -9,3 +9,5 @@ int vim_fgets __PARMS((char_u *buf, int size, FILE *fp)); int vim_rename __PARMS((char_u *from, char_u *to)); void check_timestamps __PARMS((void)); void buf_check_timestamp __PARMS((BUF *buf)); +void write_lnum_adjust __PARMS((linenr_t offset)); +char_u *vim_tempname __PARMS((int extra_char)); diff --git a/usr.bin/vim/proto/getchar.pro b/usr.bin/vim/proto/getchar.pro index 683534003f1..591688d548a 100644 --- a/usr.bin/vim/proto/getchar.pro +++ b/usr.bin/vim/proto/getchar.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: getchar.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: getchar.pro,v 1.2 1996/09/21 06:23:51 downsj Exp $ */ /* getchar.c */ char_u *get_recorded __PARMS((void)); char_u *get_inserted __PARMS((void)); @@ -25,7 +25,7 @@ int vpeekc __PARMS((void)); int char_avail __PARMS((void)); void vungetc __PARMS((int c)); int do_map __PARMS((int maptype, char_u *keys, int mode)); -void map_clear __PARMS((int modec, int force, int abbr)); +void map_clear __PARMS((int modec, int forceit, int abbr)); int check_abbr __PARMS((int c, char_u *ptr, int col, int mincol)); int makemap __PARMS((FILE *fd)); int putescstr __PARMS((FILE *fd, char_u *str, int set)); diff --git a/usr.bin/vim/proto/gui.pro b/usr.bin/vim/proto/gui.pro index 87f9f5b711e..8776a806dc2 100644 --- a/usr.bin/vim/proto/gui.pro +++ b/usr.bin/vim/proto/gui.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: gui.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: gui.pro,v 1.2 1996/09/21 06:23:52 downsj Exp $ */ /* gui.c */ void gui_start __PARMS((void)); void gui_prepare __PARMS((int *argc, char **argv)); @@ -24,8 +24,8 @@ void gui_copy_selection __PARMS((void)); void gui_auto_select __PARMS((void)); void gui_menu_cb __PARMS((GuiMenu *menu)); int gui_get_menu_index __PARMS((GuiMenu *menu, int state)); -void gui_do_menu __PARMS((char_u *cmd, char_u *arg, int force)); -char_u *gui_set_context_in_menu_cmd __PARMS((char_u *cmd, char_u *arg, int force)); +void gui_do_menu __PARMS((char_u *cmd, char_u *arg, int forceit)); +char_u *gui_set_context_in_menu_cmd __PARMS((char_u *cmd, char_u *arg, int forceit)); int gui_ExpandMenuNames __PARMS((regexp *prog, int *num_file, char_u ***file)); void gui_init_which_components __PARMS((char_u *oldval)); int gui_do_scroll __PARMS((void)); diff --git a/usr.bin/vim/proto/memline.pro b/usr.bin/vim/proto/memline.pro index 9309eb76139..8484cc49eb1 100644 --- a/usr.bin/vim/proto/memline.pro +++ b/usr.bin/vim/proto/memline.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: memline.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: memline.pro,v 1.2 1996/09/21 06:23:52 downsj Exp $ */ /* memline.c */ int ml_open __PARMS((void)); void ml_setname __PARMS((void)); @@ -24,3 +24,4 @@ void ml_setmarked __PARMS((linenr_t lnum)); linenr_t ml_firstmarked __PARMS((void)); int ml_has_mark __PARMS((linenr_t lnum)); void ml_clearmarked __PARMS((void)); +char_u *get_file_in_dir __PARMS((char_u *fname, char_u *dirname)); diff --git a/usr.bin/vim/proto/misccmds.pro b/usr.bin/vim/proto/misccmds.pro index 44df8fea740..275b34d271c 100644 --- a/usr.bin/vim/proto/misccmds.pro +++ b/usr.bin/vim/proto/misccmds.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: misccmds.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: misccmds.pro,v 1.2 1996/09/21 06:23:53 downsj Exp $ */ /* misccmds.c */ int get_indent __PARMS((void)); int get_indent_lnum __PARMS((linenr_t lnum)); @@ -28,7 +28,7 @@ char_u *skip_to_option_part __PARMS((char_u *p)); char *plural __PARMS((long n)); void set_Changed __PARMS((void)); void unset_Changed __PARMS((BUF *buf)); -void change_warning __PARMS((void)); +void change_warning __PARMS((int col)); int ask_yesno __PARMS((char_u *str, int direct)); int get_number __PARMS((void)); void msgmore __PARMS((long n)); @@ -40,6 +40,7 @@ void home_replace __PARMS((BUF *buf, char_u *src, char_u *dst, int dstlen)); char_u *home_replace_save __PARMS((BUF *buf, char_u *src)); int fullpathcmp __PARMS((char_u *s1, char_u *s2)); char_u *gettail __PARMS((char_u *fname)); +char_u *get_past_head __PARMS((char_u *path)); int ispathsep __PARMS((int c)); char_u *concat_fnames __PARMS((char_u *fname1, char_u *fname2, int sep)); char_u *FullName_save __PARMS((char_u *fname)); diff --git a/usr.bin/vim/proto/option.pro b/usr.bin/vim/proto/option.pro index 2736d7484f2..ec608099acf 100644 --- a/usr.bin/vim/proto/option.pro +++ b/usr.bin/vim/proto/option.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: option.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: option.pro,v 1.2 1996/09/21 06:23:53 downsj Exp $ */ /* option.c */ void set_init_1 __PARMS((void)); void set_init_2 __PARMS((void)); @@ -16,12 +16,12 @@ void clear_termoptions __PARMS((void)); void set_term_defaults __PARMS((void)); void comp_col __PARMS((void)); void win_copy_options __PARMS((WIN *wp_from, WIN *wp_to)); -void buf_copy_options __PARMS((BUF *bp_from, BUF *bp_to, int entering)); +void buf_copy_options __PARMS((BUF *bp_from, BUF *bp_to, int entering, int always)); void set_context_in_set_cmd __PARMS((char_u *arg)); int ExpandSettings __PARMS((regexp *prog, int *num_file, char_u ***file)); int ExpandOldSetting __PARMS((int *num_file, char_u ***file)); char_u *file_pat_to_reg_pat __PARMS((char_u *pat, char_u *pat_end, int *allow_directories)); -void do_autocmd __PARMS((char_u *arg, int force)); +void do_autocmd __PARMS((char_u *arg, int forceit)); void do_doautocmd __PARMS((char_u *arg)); int apply_autocmds __PARMS((int event, char_u *fname, char_u *fname_io)); char_u *set_context_in_autocmd __PARMS((char_u *arg, int doautocmd)); diff --git a/usr.bin/vim/proto/quickfix.pro b/usr.bin/vim/proto/quickfix.pro index 8e7117e149b..5112f547e6c 100644 --- a/usr.bin/vim/proto/quickfix.pro +++ b/usr.bin/vim/proto/quickfix.pro @@ -1,6 +1,6 @@ -/* $OpenBSD: quickfix.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: quickfix.pro,v 1.2 1996/09/21 06:23:54 downsj Exp $ */ /* quickfix.c */ int qf_init __PARMS((void)); -void qf_jump __PARMS((int dir, int errornr)); +void qf_jump __PARMS((int dir, int errornr, int forceit)); void qf_list __PARMS((int all)); void qf_mark_adjust __PARMS((linenr_t line1, linenr_t line2, long amount, long amount_after)); diff --git a/usr.bin/vim/proto/screen.pro b/usr.bin/vim/proto/screen.pro index 3cf54f35e31..7a271aa9396 100644 --- a/usr.bin/vim/proto/screen.pro +++ b/usr.bin/vim/proto/screen.pro @@ -1,4 +1,4 @@ -/* $OpenBSD: screen.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: screen.pro,v 1.2 1996/09/21 06:23:54 downsj Exp $ */ /* screen.c */ void updateline __PARMS((void)); void update_curbuf __PARMS((int type)); @@ -38,7 +38,7 @@ int win_ins_lines __PARMS((WIN *wp, int row, int line_count, int invalid, int ma int win_del_lines __PARMS((WIN *wp, int row, int line_count, int invalid, int mayclear)); void win_rest_invalid __PARMS((WIN *wp)); int screen_del_lines __PARMS((int off, int row, int line_count, int end, int force)); -void showmode __PARMS((void)); +int showmode __PARMS((void)); void delmode __PARMS((void)); void showruler __PARMS((int always)); void win_redr_ruler __PARMS((WIN *wp, int always)); diff --git a/usr.bin/vim/proto/tag.pro b/usr.bin/vim/proto/tag.pro index 3f5c4c68fc1..d2e11c917dd 100644 --- a/usr.bin/vim/proto/tag.pro +++ b/usr.bin/vim/proto/tag.pro @@ -1,5 +1,5 @@ -/* $OpenBSD: tag.pro,v 1.1 1996/09/07 21:40:29 downsj Exp $ */ +/* $OpenBSD: tag.pro,v 1.2 1996/09/21 06:23:55 downsj Exp $ */ /* tag.c */ -void do_tag __PARMS((char_u *tag, int type, int count)); +void do_tag __PARMS((char_u *tag, int type, int count, int forceit)); void do_tags __PARMS((void)); -int find_tags __PARMS((char_u *tag, regexp *prog, int *num_file, char_u ***file, int help_only)); +int find_tags __PARMS((char_u *tag, regexp *prog, int *num_file, char_u ***file, int help_only, int forceit)); diff --git a/usr.bin/vim/proto/window.pro b/usr.bin/vim/proto/window.pro index c584a11bacf..ff9a1cfe525 100644 --- a/usr.bin/vim/proto/window.pro +++ b/usr.bin/vim/proto/window.pro @@ -1,7 +1,8 @@ -/* $OpenBSD: window.pro,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: window.pro,v 1.2 1996/09/21 06:23:55 downsj Exp $ */ /* window.c */ void do_window __PARMS((int nchar, long Prenum)); int win_split __PARMS((int new_height, int redraw)); +int win_valid __PARMS((WIN *win)); int win_count __PARMS((void)); int make_windows __PARMS((int count)); void win_equal __PARMS((WIN *next_curwin, int redraw)); diff --git a/usr.bin/vim/quickfix.c b/usr.bin/vim/quickfix.c index 859f3f9c2bf..fffbfff932d 100644 --- a/usr.bin/vim/quickfix.c +++ b/usr.bin/vim/quickfix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quickfix.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: quickfix.c,v 1.2 1996/09/21 06:23:16 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -374,9 +374,10 @@ qf_init_end: * else go to entry "errornr" */ void -qf_jump(dir, errornr) +qf_jump(dir, errornr, forceit) int dir; int errornr; + int forceit; { struct qf_line *old_qf_ptr; int old_qf_index; @@ -463,7 +464,7 @@ qf_jump(dir, errornr) * read the wanted file if needed, and check autowrite etc. */ if (qf_ptr->qf_fnum == 0 || buflist_getfile(qf_ptr->qf_fnum, - (linenr_t)1, GETF_SETMARK) == OK) + (linenr_t)1, GETF_SETMARK, forceit) == OK) { /* * Go to line with error, unless qf_lnum is 0. diff --git a/usr.bin/vim/regexp.c b/usr.bin/vim/regexp.c index 145842e2899..3123ca8b1c6 100644 --- a/usr.bin/vim/regexp.c +++ b/usr.bin/vim/regexp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: regexp.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */ +/* $OpenBSD: regexp.c,v 1.2 1996/09/21 06:23:17 downsj Exp $ */ /* vi:set ts=4 sw=4: * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE * @@ -36,8 +36,19 @@ * regular-expression syntax might require a total rethink. * * $Log: regexp.c,v $ - * Revision 1.1 1996/09/07 21:40:25 downsj - * Initial revision + * Revision 1.2 1996/09/21 06:23:17 downsj + * update to vim 4.4beta + * + * Revision 1.1.1.1 1996/09/07 21:40:25 downsj + * Initial import of vim 4.2. + * + * This is meant to replace nvi in the tree. Vim, in general, works better, + * provides more features, and does not suffer from the license problems + * being imposed upon nvi. + * + * On the other hand, vim lacks a non-visual ex mode, in addition to open mode. + * + * This includes the GUI (X11) code, but doesn't try to compile it. * * Revision 1.2 88/04/28 08:09:45 tony * First modification of the regexp library. Added an external variable @@ -300,7 +311,8 @@ skip_regexp(p, dirc) { if (p[0] == dirc && !in_range) /* found end of regexp */ break; - if ((p[0] == '[' && p_magic) || (p[0] == '\\' && p[1] == '[' && !p_magic)) + if (!in_range && ((p[0] == '[' && p_magic) || + (p[0] == '\\' && p[1] == '[' && !p_magic))) { in_range = TRUE; if (p[0] == '\\') diff --git a/usr.bin/vim/screen.c b/usr.bin/vim/screen.c index 4ec3a82d9b5..dbf54324566 100644 --- a/usr.bin/vim/screen.c +++ b/usr.bin/vim/screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: screen.c,v 1.2 1996/09/21 06:23:18 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -2953,11 +2953,13 @@ screen_del_lines(off, row, line_count, end, force) * If clear_cmdline is TRUE, clear the rest of the cmdline. * If clear_cmdline is FALSE there may be a message there that needs to be * cleared only if a mode is shown. + * Return the lenght of the message (0 if no message). */ - void + int showmode() { int need_clear = FALSE; + int length = 0; int do_mode = (p_smd && ((State & INSERT) || restart_edit || VIsual_active)); @@ -3045,6 +3047,7 @@ showmode() if (need_clear || clear_cmdline) msg_clr_eos(); msg_didout = FALSE; /* overwrite this message */ + length = msg_col; msg_col = 0; } else if (clear_cmdline) /* just clear anything */ @@ -3055,6 +3058,8 @@ showmode() } win_redr_ruler(lastwin, TRUE); redraw_cmdline = FALSE; + + return length; } /* @@ -3224,7 +3229,7 @@ jump_to_mouse(flags) on_status_line = row - wp->w_height + 1; else on_status_line = 0; - win_enter(wp, TRUE); + win_enter(wp, TRUE); /* can make wp invalid! */ if (on_status_line) /* In (or below) status line */ { /* Don't use start_arrow() if we're in the same window */ @@ -3286,10 +3291,6 @@ jump_to_mouse(flags) col = Columns - 1 - col; #endif - if (curwin->w_p_nu) /* skip number in front of the line */ - if ((col -= 8) < 0) - col = 0; - if (curwin->w_p_wrap) /* lines wrap */ { while (row) @@ -3319,6 +3320,11 @@ jump_to_mouse(flags) } col += curwin->w_leftcol; } + + if (curwin->w_p_nu) /* skip number in front of the line */ + if ((col -= 8) < 0) + col = 0; + curwin->w_curswant = col; curwin->w_set_curswant = FALSE; /* May still have been TRUE */ if (coladvance(col) == FAIL) diff --git a/usr.bin/vim/search.c b/usr.bin/vim/search.c index acbec11b596..7e11f0c7613 100644 --- a/usr.bin/vim/search.c +++ b/usr.bin/vim/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: search.c,v 1.2 1996/09/21 06:23:19 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -70,8 +70,6 @@ static int last_magic = TRUE; static int last_no_scs = FALSE; static char_u *mr_pattern = NULL; /* pattern used by myregcomp() */ -static int want_start; /* looking for start of line? */ - /* * Type used by find_pattern_in_path() to remember which included files have * been searched already. @@ -190,7 +188,6 @@ myregcomp(pat, sub_cmd, which_pat, options) } } - want_start = (*pat == '^'); /* looking for start of line? */ set_reg_ic(pat); /* tell the vim_regexec routine how to search */ return vim_regcomp(pat); } @@ -298,15 +295,10 @@ searchit(pos, dir, str, count, options, which_pat) for ( ; lnum > 0 && lnum <= curbuf->b_ml.ml_line_count; lnum += dir, at_first_line = FALSE) { - ptr = ml_get(lnum); - /* forward search, first line */ - if (dir == FORWARD && at_first_line && start_pos.col > 0 && - want_start) - continue; /* match not possible */ - /* * Look for a match somewhere in the line. */ + ptr = ml_get(lnum); if (vim_regexec(prog, ptr, TRUE)) { match = prog->startp[0]; @@ -323,11 +315,10 @@ searchit(pos, dir, str, count, options, which_pat) /* * When *match == NUL the cursor will be put one back * afterwards, compare with that position, otherwise - * "/$" will get stuck on end of line. Same for - * matchend. + * "/$" will get stuck on end of line. */ while ((options & SEARCH_END) ? - ((int)(matchend - ptr) - 1 - (int)(*matchend == NUL) < + ((int)(matchend - ptr) - 1 < (int)start_pos.col + extra_col) : ((int)(match - ptr) - (int)(*match == NUL) < (int)start_pos.col + extra_col)) @@ -363,7 +354,7 @@ searchit(pos, dir, str, count, options, which_pat) if (!match_ok) continue; } - if (dir == BACKWARD && !want_start) + if (dir == BACKWARD) { /* * Now, if there are multiple matches on this line, @@ -500,6 +491,7 @@ searchit(pos, dir, str, count, options, which_pat) * If 'options & SEARCH_NOOF': don't add offset to position * If 'options & SEARCH_MARK': set previous context mark * If 'options & SEARCH_KEEP': keep previous search pattern + * If 'options & SEARCH_START': accept match at curpos itself * * Careful: If lastoffline == TRUE and lastoff == 0 this makes the * movement linewise without moving the match position. @@ -699,7 +691,7 @@ do_search(dirc, str, count, options) c = searchit(&pos, dirc == '/' ? FORWARD : BACKWARD, searchstr, count, lastend + (options & - (SEARCH_KEEP + SEARCH_HIS + SEARCH_MSG + + (SEARCH_KEEP + SEARCH_HIS + SEARCH_MSG + SEARCH_START + ((str != NULL && *str == ';') ? 0 : SEARCH_NOOF))), 2); if (dircp != NULL) @@ -2922,7 +2914,7 @@ find_pattern_in_path(ptr, len, whole, skip_comments, } else if (getfile(0, files[depth].name, NULL, TRUE, - files[depth].lnum) > 0) + files[depth].lnum, FALSE) > 0) break; /* failed to jump to file */ } if (action != ACTION_SHOW) diff --git a/usr.bin/vim/tables.c b/usr.bin/vim/tables.c index d41ac29066c..41c8ea5e953 100644 --- a/usr.bin/vim/tables.c +++ b/usr.bin/vim/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: tables.c,v 1.2 1996/09/21 06:23:20 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -133,6 +133,7 @@ static struct key_name_entry {CR, (char_u *)"CR"}, {CR, (char_u *)"Return"}, /* Alternative name */ {ESC, (char_u *)"Esc"}, + {'|', (char_u *)"Bar"}, {K_UP, (char_u *)"Up"}, {K_DOWN, (char_u *)"Down"}, {K_LEFT, (char_u *)"Left"}, @@ -189,6 +190,11 @@ static struct key_name_entry {K_END, (char_u *)"End"}, {K_PAGEUP, (char_u *)"PageUp"}, {K_PAGEDOWN, (char_u *)"PageDown"}, + {K_KHOME, (char_u *)"kHome"}, + {K_KEND, (char_u *)"kEnd"}, + {K_KPAGEUP, (char_u *)"kPageUp"}, + {K_KPAGEDOWN, (char_u *)"kPageDown"}, + {K_MOUSE, (char_u *)"Mouse"}, {K_LEFTMOUSE, (char_u *)"LeftMouse"}, {K_LEFTDRAG, (char_u *)"LeftDrag"}, diff --git a/usr.bin/vim/tag.c b/usr.bin/vim/tag.c index 6880db5cbd1..10371571f6f 100644 --- a/usr.bin/vim/tag.c +++ b/usr.bin/vim/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: tag.c,v 1.2 1996/09/21 06:23:21 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -21,11 +21,11 @@ static int get_tagfname __ARGS((int, char_u *)); #ifdef EMACS_TAGS static int parse_tag_line __ARGS((char_u *, int, char_u **, char_u **, char_u **, char_u **, char_u **)); -static int jumpto_tag __ARGS((char_u *, int, char_u *, char_u *)); +static int jumpto_tag __ARGS((char_u *, int, char_u *, char_u *, int)); #else static int parse_tag_line __ARGS((char_u *, char_u **, char_u **, char_u **, char_u **, char_u **)); -static int jumpto_tag __ARGS((char_u *, char_u *)); +static int jumpto_tag __ARGS((char_u *, char_u *, int)); #endif static int test_for_static __ARGS((char_u **, char_u *, char_u *, char_u *)); static char_u *expand_rel_name __ARGS((char_u *fname, char_u *tag_fname)); @@ -47,10 +47,11 @@ static char_u *topmsg = (char_u *)"at top of tag stack"; * type == 0 (:tag): jump to old tag */ void -do_tag(tag, type, count) +do_tag(tag, type, count, forceit) char_u *tag; int type; int count; + int forceit; /* :ta with ! */ { int i; struct taggy *tagstack = curwin->w_tagstack; @@ -116,7 +117,8 @@ do_tag(tag, type, count) * changed) keep original position in tag stack. */ if (buflist_getfile(tagstack[tagstackidx].fmark.fnum, - tagstack[tagstackidx].fmark.mark.lnum, GETF_SETMARK) == FAIL) + tagstack[tagstackidx].fmark.mark.lnum, + GETF_SETMARK, forceit) == FAIL) { tagstackidx = oldtagstackidx; /* back to old position */ goto end_do_tag; @@ -157,7 +159,8 @@ do_tag(tag, type, count) /* curwin will change in the call to find_tags() if ^W^] was used -- webb */ curwin->w_tagstackidx = tagstackidx; curwin->w_tagstacklen = tagstacklen; - if (find_tags(tagstack[tagstackidx].tagname, NULL, NULL, NULL, FALSE) > 0) + if (find_tags(tagstack[tagstackidx].tagname, NULL, NULL, NULL, + FALSE, forceit) > 0) ++tagstackidx; end_do_tag: @@ -230,12 +233,13 @@ do_tags() #define PRI_FULL_MATCH 4 /* case of tag matches */ int -find_tags(tag, prog, num_file, file, help_only) +find_tags(tag, prog, num_file, file, help_only, forceit) char_u *tag; /* NULL or tag to search for */ regexp *prog; /* regexp program or NULL */ int *num_file; /* return value: number of matches found */ char_u ***file; /* return value: array of matches found */ int help_only; /* if TRUE: only tags for help files */ + int forceit; /* :ta with ! */ { FILE *fp; char_u *lbuf; /* line buffer */ @@ -585,7 +589,7 @@ find_tags(tag, prog, num_file, file, help_only) #ifdef EMACS_TAGS is_etag, ebuf, #endif - tag_fname); + tag_fname, forceit); stop_searching = TRUE; break; } @@ -672,7 +676,7 @@ find_tags(tag, prog, num_file, file, help_only) #ifdef EMACS_TAGS bestmatch_is_etag, bestmatch_ebuf, #endif - bestmatch_tag_fname); + bestmatch_tag_fname, forceit); } else EMSG("tag not found"); @@ -990,13 +994,14 @@ jumpto_tag(lbuf, #ifdef EMACS_TAGS is_etag, etag_fname, #endif - tag_fname) + tag_fname, forceit) char_u *lbuf; /* line from the tags file for this tag */ #ifdef EMACS_TAGS int is_etag; /* TRUE if it's from an emacs tags file */ char_u *etag_fname; /* file name for tag if is_etag is TRUE */ #endif char_u *tag_fname; /* file name of the tags file itself */ + int forceit; /* :ta with ! */ { int save_secure; int save_p_ws, save_p_scs, save_p_ic; @@ -1141,7 +1146,7 @@ jumpto_tag(lbuf, * A :ta from a help file will keep the b_help flag set. */ keep_help_flag = curbuf->b_help; - getfile_result = getfile(0, fname, NULL, TRUE, (linenr_t)0); + getfile_result = getfile(0, fname, NULL, TRUE, (linenr_t)0, forceit); if (getfile_result <= 0) /* got to the right file */ { diff --git a/usr.bin/vim/term.c b/usr.bin/vim/term.c index 502c722ebae..cc7e4483580 100644 --- a/usr.bin/vim/term.c +++ b/usr.bin/vim/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: term.c,v 1.2 1996/09/21 06:23:22 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -365,6 +365,10 @@ struct builtin_term builtin_termcaps[] = {KS_MD, "\033|63m"}, {KS_SE, "\033|0m"}, {KS_SO, "\033|31m"}, + {KS_CZH, "\033|225m"}, /* italic mode: blue text on yellow */ + {KS_CZR, "\033|0m"}, /* italic mode end */ + {KS_US, "\033|67m"}, /* underscore mode: cyan text on red */ + {KS_UE, "\033|0m"}, /* underscore mode end */ {KS_MS, "\001"}, # ifdef TERMINFO {KS_CM, "\033|%i%p1%d;%p2%dH"}, @@ -633,8 +637,10 @@ struct builtin_term builtin_termcaps[] = {K_HELP, "\033[28~"}, {K_UNDO, "\033[26~"}, {K_INS, "\033[2~"}, - {K_HOME, "\033[7~"}, /* also seen: "\033[1~" */ - {K_END, "\033[8~"}, /* also seen: "\033[4~" */ + {K_HOME, "\033[7~"}, + {K_KHOME, "\033[1~"}, + {K_END, "\033[8~"}, + {K_KEND, "\033[4~"}, {K_PAGEUP, "\033[5~"}, {K_PAGEDOWN, "\033[6~"}, /* {K_DEL, "\033[3~"}, not used */ @@ -832,6 +838,10 @@ struct builtin_term builtin_termcaps[] = {K_END, "[END]"}, {K_PAGEUP, "[PAGEUP]"}, {K_PAGEDOWN, "[PAGEDOWN]"}, + {K_KHOME, "[KHOME]"}, + {K_KEND, "[KEND]"}, + {K_KPAGEUP, "[KPAGEUP]"}, + {K_KPAGEDOWN, "[KPAGEDOWN]"}, {K_MOUSE, "[MOUSE]"}, # endif @@ -1015,7 +1025,7 @@ set_termname(term) "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9", "k;", "F1", "F2", "%1", "&8", "kb", "kI", "kD", "kh", - "@7", "kP", "kN", + "@7", "kP", "kN", "K1", "K3", "K4", "K5", NULL }; static struct { @@ -1051,9 +1061,9 @@ set_termname(term) for (i = 0; string_names[i].name != NULL; ++i) { if (term_strings[string_names[i].dest] == NULL || - term_strings[string_names[i].dest] == empty_option) + term_strings[string_names[i].dest] == empty_option) term_strings[string_names[i].dest] = - TGETSTR(string_names[i].name, &tp); + TGETSTR(string_names[i].name, &tp); } if ((T_MS == NULL || T_MS == empty_option) && tgetflag("ms")) @@ -1070,7 +1080,7 @@ set_termname(term) { if (find_termcode((char_u *)key_names[i]) == NULL) add_termcode((char_u *)key_names[i], - TGETSTR(key_names[i], &tp)); + TGETSTR(key_names[i], &tp)); } /* if cursor-left == backspace, ignore it (televideo 925) */ @@ -1569,8 +1579,10 @@ tgoto(cm, x, y) termcapinit(term) char_u *term; { +#ifndef WIN32 if (!term || !*term) term = vim_getenv((char_u *)"TERM"); +#endif if (!term || !*term) term = DEFAULT_TERM; set_string_option((char_u *)"term", -1, term, TRUE); @@ -1755,7 +1767,7 @@ setcursor() ttest(pairs) int pairs; { - char *t = NULL; + char *t = NULL; check_options(); /* make sure no options are NULL */ @@ -1974,6 +1986,7 @@ set_winsize(width, height, mustset) if (!starting) { comp_Botline_all(); + maketitle(); if (State == ASKMORE || State == EXTERNCMD) { screenalloc(FALSE); /* don't redraw, just adjust screen size */ @@ -2212,7 +2225,7 @@ clear_termcodes() #ifdef HAVE_TGETENT BC = (char *)empty_option; UP = (char *)empty_option; - PC = ' '; /* set pad character to space */ + PC = NUL; /* set pad character to NUL */ ospeed = 0; #endif @@ -2368,7 +2381,7 @@ check_termcode(max_offset) int new_slen; int extra; char_u string[MAX_KEY_CODE_LEN + 1]; - int i; + int i, j; #ifdef USE_GUI long_u val; #endif @@ -2476,6 +2489,25 @@ check_termcode(max_offset) if (len < slen) /* got a partial sequence */ return -1; /* need to get more chars */ + /* + * When found a keypad key, check if there is another key + * that matches and use that one. This makes <Home> to be + * found instead of <kHome> when they produce the same + * key code. + */ + if (termcodes[i].name[0] == 'K' && + isdigit(termcodes[i].name[1])) + { + for (j = i + 1; j < tc_len; ++j) + if (termcodes[j].len == slen && + STRNCMP(termcodes[i].code, + termcodes[j].code, slen) == 0) + { + i = j; + break; + } + } + key_name[0] = termcodes[i].name[0]; key_name[1] = termcodes[i].name[1]; diff --git a/usr.bin/vim/undo.c b/usr.bin/vim/undo.c index 9b23c6daf9f..edb04da7ad9 100644 --- a/usr.bin/vim/undo.c +++ b/usr.bin/vim/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: undo.c,v 1.2 1996/09/21 06:23:23 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -190,8 +190,7 @@ u_savecommon(top, bot, newbot) ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0); /* save named marks for undo */ - vim_memmove((char *)uhp->uh_namedm, (char *)curbuf->b_namedm, - sizeof(FPOS) * NMARKS); + vim_memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(FPOS) * NMARKS); curbuf->b_u_newhead = uhp; if (curbuf->b_u_oldhead == NULL) curbuf->b_u_oldhead = uhp; @@ -357,8 +356,7 @@ u_undoredo() /* * save marks before undo/redo */ - vim_memmove((char *)namedm, (char *)curbuf->b_namedm, - sizeof(FPOS) * NMARKS); + vim_memmove(namedm, curbuf->b_namedm, sizeof(FPOS) * NMARKS); curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count; curbuf->b_op_start.col = 0; curbuf->b_op_end.lnum = 0; diff --git a/usr.bin/vim/unix.c b/usr.bin/vim/unix.c index bdb7bf55124..3003ef20f5e 100644 --- a/usr.bin/vim/unix.c +++ b/usr.bin/vim/unix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unix.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: unix.c,v 1.2 1996/09/21 06:23:24 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -875,8 +875,6 @@ mch_settitle(title, icon) /* * Note: if terminal is xterm, title is set with escape sequence rather * than x11 calls, because the x11 calls don't always work - * Check only if the start of the terminal name is "xterm", also catch - * "xterms". */ if (is_xterm(term_strings[KS_NAME])) type = 2; @@ -1310,6 +1308,7 @@ mch_windexit(r) exiting = TRUE; mch_settitle(oldtitle, oldicon); /* restore xterm title */ stoptermcap(); + outchar('\n'); flushbuf(); ml_close_all(TRUE); /* remove all memfiles */ may_core_dump(); @@ -1374,6 +1373,9 @@ mch_settmode(raw) /* but it breaks function keys on MINT */ # endif ); +# ifdef ONLCR /* don't map NL -> CR NL, we do it ourselves */ + tnew.c_oflag &= ~ONLCR; +# endif tnew.c_cc[VMIN] = 1; /* return after 1 char */ tnew.c_cc[VTIME] = 0; /* don't wait */ # if defined(HAVE_TERMIOS_H) @@ -1686,8 +1688,9 @@ call_shell(cmd, options) x = system(p_sh); else { - sprintf(newcmd, "%s %s -c \"%s\"", p_sh, + sprintf(newcmd, "%s %s %s \"%s\"", p_sh, extra_shell_arg == NULL ? "" : (char *)extra_shell_arg, + (char *)p_shcf, (char *)cmd); x = system(newcmd); } @@ -1787,7 +1790,7 @@ call_shell(cmd, options) { if (extra_shell_arg != NULL) argv[argc++] = (char *)extra_shell_arg; - argv[argc++] = "-c"; + argv[argc++] = (char *)p_shcf; argv[argc++] = (char *)cmd; } argv[argc] = NULL; @@ -2061,14 +2064,8 @@ call_shell(cmd, options) { #ifdef SIGINT if (buffer[0] == Ctrl('C')) - { - /* Use both kill() and killpg(), in case one - * of the two fails */ - kill(pid, SIGINT); -# ifdef HAVE_KILLPG - killpg(0, SIGINT); -# endif - } + /* send SIGINT to all processes in our group */ + kill(0, SIGINT); #endif if (pty_master_fd < 0 && toshell_fd >= 0 && buffer[0] == Ctrl('D')) @@ -2445,7 +2442,6 @@ RealWaitForChar(fd, msec) * list_notfound is ignored */ -extern char *mktemp __ARGS((char *)); #ifndef SEEK_SET # define SEEK_SET 0 #endif @@ -2469,16 +2465,15 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) # define EXPL_ALLOC_INC 16 char_u **expl_files; size_t files_alloced, files_free; + char_u *buf; + int has_wildcard; *num_file = 0; /* default: no files found */ files_alloced = EXPL_ALLOC_INC; /* how much space is allocated */ files_free = EXPL_ALLOC_INC; /* how much space is not used */ *file = (char_u **) alloc(sizeof(char_u **) * files_alloced); - if (!*file) - { - emsg(e_outofmem); + if (*file == NULL) return FAIL; - } for (; num_pat > 0; num_pat--, pat++) { @@ -2486,98 +2481,89 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) if (vim_strchr(*pat, '$') || vim_strchr(*pat, '~')) { /* expand environment var or home dir */ - char_u *buf = alloc(1024); - if (!buf) - { - emsg(e_outofmem); + buf = alloc(MAXPATHL); + if (buf == NULL) return FAIL; - } - expand_env(*pat, buf, 1024); - if (mch_has_wildcard(buf)) /* still wildcards in there? */ - { - expl_files = (char_u **)_fnexplode(buf); - } - if (expl_files == NULL) - { - /* - * If no wildcard still remaining, simply add - * the pattern to the results. - * If wildcard did not match, add the pattern to - * the list of results anyway. This way, doing - * :n exist.c notexist* - * will at least edits exist.c and then say - * notexist* [new file] - */ - expl_files = (char_u **)alloc(sizeof(char_u **) * 2); - expl_files[0] = strsave(buf); - expl_files[1] = NULL; - } - vim_free(buf); + expand_env(*pat, buf, MAXPATHL); } else { - expl_files = (char_u **)_fnexplode(*pat); - if (expl_files == NULL) + buf = strsave(*pat); + } + expl_files = NULL; + has_wildcard = mch_has_wildcard(buf); /* (still) wildcards in there? */ + if (has_wildcard) /* yes, so expand them */ + expl_files = (char_u **)_fnexplode(buf); + /* + * return value of buf if no wildcards left, + * OR if no match AND list_notfound is true. + */ + if (!has_wildcard || (expl_files == NULL && list_notfound)) + { /* simply save the current contents of *buf */ + expl_files = (char_u **)alloc(sizeof(char_u **) * 2); + if (expl_files != NULL) { - /* see above for explanation */ - expl_files = (char_u **)alloc(sizeof(char_u **) * 2); - expl_files[0] = strsave(*pat); + expl_files[0] = strsave(buf); expl_files[1] = NULL; } } - if (!expl_files) - { - /* Can't happen */ - char_u msg[128]; - sprintf(msg, "%s (unix.c:%d)", e_internal, __LINE__); - emsg(msg); - *file = (char_u **)""; - *num_file = 0; - return OK; - } + vim_free(buf); + /* * Count number of names resulting from expansion, - * At the same time add a backslash to the end of names that happen to be - * directories, and replace slashes with backslashes. + * At the same time add a backslash to the end of names that happen to + * be directories, and replace slashes with backslashes. */ - for (i = 0; (p = expl_files[i]) != NULL; i++, (*num_file)++) + if (expl_files) { - if (--files_free == 0) - { - /* need more room in table of pointers */ - files_alloced += EXPL_ALLOC_INC; - *file = (char_u **) realloc(*file, - sizeof(char_u **) * files_alloced); - files_free = EXPL_ALLOC_INC; - } - slash_adjust(p); - if (mch_isdir(p)) + for (i = 0; (p = expl_files[i]) != NULL; i++, (*num_file)++) { - len = strlen(p); - p = realloc(p, len + 2); - if (!p) + if (--files_free == 0) { - emsg(e_outofmem); - return FAIL; + /* need more room in table of pointers */ + files_alloced += EXPL_ALLOC_INC; + *file = (char_u **) realloc(*file, + sizeof(char_u **) * files_alloced); + if (*file == NULL) + { + emsg(e_outofmem); + *num_file = 0; + return FAIL; + } + files_free = EXPL_ALLOC_INC; } - (*file)[*num_file] = p; - p += len; - *p++ = '\\'; - *p = 0; - } - else - { - (*file)[*num_file] = strsave(p); + slash_adjust(p); + if (mch_isdir(p)) + { + len = strlen(p); + if (((*file)[*num_file] = alloc(len + 2)) != NULL) + { + strcpy((*file)[*num_file], p); + (*file)[*num_file][len] = '\\'; + (*file)[*num_file][len+1] = 0; + } + } + else + { + (*file)[*num_file] = strsave(p); + } + + /* + * Error message already given by either alloc or strsave. + * Should return FAIL, but returning OK works also. + */ + if ((*file)[*num_file] == NULL) + break; } + _fnexplodefree((char **)expl_files); } - _fnexplodefree(expl_files); } return OK; #else /* __EMX__ */ int dir; - char_u tmpname[TMPNAMELEN]; + char_u *tempname; char_u *command; FILE *fd; char_u *buffer; @@ -2607,8 +2593,7 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) /* * get a name for the temp file */ - STRCPY(tmpname, TMPNAME2); - if (*mktemp((char *)tmpname) == NUL) + if ((tempname = vim_tempname('o')) == NULL) { emsg(e_notmp); return FAIL; @@ -2621,17 +2606,20 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) if ((len = STRLEN(p_sh)) >= 3 && STRCMP(p_sh + len - 3, "csh") == 0) use_glob = TRUE; - len = TMPNAMELEN + 11; + len = STRLEN(tempname) + 12; for (i = 0; i < num_pat; ++i) /* count the length of the patterns */ len += STRLEN(pat[i]) + 3; command = alloc(len); if (command == NULL) + { + vim_free(tempname); return FAIL; + } if (use_glob) STRCPY(command, "glob >"); /* build the shell command */ else STRCPY(command, "echo >"); /* build the shell command */ - STRCAT(command, tmpname); + STRCAT(command, tempname); for (i = 0; i < num_pat; ++i) { #ifdef USE_SYSTEM @@ -2658,7 +2646,8 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) vim_free(command); if (i == FAIL) /* call_shell failed */ { - vim_remove(tmpname); + vim_remove(tempname); + vim_free(tempname); /* * With interactive completion, the error message is not printed. * However with USE_SYSTEM, I don't know how to turn off error messages @@ -2678,10 +2667,11 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) /* * read the names from the file into memory */ - fd = fopen((char *)tmpname, "r"); + fd = fopen((char *)tempname, "r"); if (fd == NULL) { - emsg2(e_notopen, tmpname); + emsg2(e_notopen, tempname); + vim_free(tempname); return FAIL; } fseek(fd, 0L, SEEK_END); @@ -2690,19 +2680,22 @@ ExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound) buffer = alloc(len + 1); if (buffer == NULL) { - vim_remove(tmpname); + vim_remove(tempname); + vim_free(tempname); fclose(fd); return FAIL; } i = fread((char *)buffer, 1, len, fd); fclose(fd); - vim_remove(tmpname); + vim_remove(tempname); if (i != len) { - emsg2(e_notread, tmpname); + emsg2(e_notread, tempname); + vim_free(tempname); vim_free(buffer); return FAIL; } + vim_free(tempname); if (use_glob) /* file names are separated with NUL */ { diff --git a/usr.bin/vim/unix.h b/usr.bin/vim/unix.h index b06739bf7b9..bf67c8c91d4 100644 --- a/usr.bin/vim/unix.h +++ b/usr.bin/vim/unix.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unix.h,v 1.1 1996/09/07 21:40:27 downsj Exp $ */ +/* $OpenBSD: unix.h,v 1.2 1996/09/21 06:23:25 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -90,7 +90,9 @@ #if HAVE_DIRENT_H # include <dirent.h> +# ifndef NAMLEN # define NAMLEN(dirent) strlen((dirent)->d_name) +# endif #else # define dirent direct # define NAMLEN(dirent) (dirent)->d_namlen @@ -135,6 +137,8 @@ # define MAXNAMLEN 512 /* for all other Unix */ #endif +#define BASENAMELEN (MAXNAMLEN - 5) + #ifdef HAVE_ERRNO_H # include <errno.h> #endif @@ -206,13 +210,15 @@ #endif #ifdef OS2 -#define TMPNAME1 "$TMP/viXXXXXX" -#define TMPNAME2 "$TMP/voXXXXXX" -#define TMPNAMELEN 128 +/* + * Try several directories to put the temp files. + */ +#define TEMPDIRNAMES "$TMP", "$TEMP", "c:\\TMP", "c:\\TEMP", "" +#define TEMPNAME "v?XXXXXX" +#define TEMPNAMELEN 128 #else -#define TMPNAME1 "/tmp/viXXXXXX" -#define TMPNAME2 "/tmp/voXXXXXX" -#define TMPNAMELEN 15 +#define TEMPNAME "/tmp/v?XXXXXX" +#define TEMPNAMELEN 15 #endif /* @@ -232,8 +238,6 @@ # define MAXMEMTOT 2048 /* use up to 2048Kbyte for Vim */ #endif -#define BASENAMELEN (MAXNAMLEN - 5) - /* memmove is not present on all systems, use memmove, bcopy, memcpy or our * own version */ /* Some systems have (void *) arguments, some (char *). If we use (char *) it diff --git a/usr.bin/vim/version.c b/usr.bin/vim/version.c index 18a45015bd2..8c599644fe9 100644 --- a/usr.bin/vim/version.c +++ b/usr.bin/vim/version.c @@ -1,4 +1,4 @@ -/* $OpenBSD: version.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: version.c,v 1.2 1996/09/21 06:23:25 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -16,9 +16,173 @@ * It has been changed beyond recognition since then. * * All the remarks about older versions have been removed, they are not very - * interesting. Differences between version 3.0 and 4.0 can be found in + * interesting. Differences between version 3.0 and 4.x can be found in * "../doc/vim_40.txt". * + * Changes between version 4.3 BETA and 4.4 BETA: + * - Moved outputting newline from getout() to mch_windexit(). Helps when + * switching display pages in xterm after an error message for ":!". + * - Fixed problem: Not executing BufEnter autocommands for first buffer. + * - Fixed Makefile: "make shadow" didn't make ctags and xxd directories. Now + * passes CC and CFLAGS to ctags and xxd makefiles. + * - Removed use of #elif, some old compilers don't understand it. + * - Included version 1.4 of ctags. New Makefile.bcc, supports wildcards for + * 16 bit DOS version. + * - Fixed mouse positioning in wrong column for MSDOS 16 and 32 bit versions. + * - Fixed: Delay in updating Visual area when using "/pat". + * - Fixed: With some shells gvim could be killed with CTRL-C in the shell + * where it was started. + * - Fixed: For abbreviations entered with ":noreab" only the first two + * characters were not re-mapped instead of all. + * - Added help tags for search pattern special characters. Adjusted + * doctags.c to insert a backslash before a backslash. + * - Fixed Vi incompatibility: If the rhs of a mapping starts with the lhs, + * remapping is only disabled for the first character, not the whole lhs. + * - Fixed: Default padding character was a space, which caused trouble on + * some systems. Now it's a NUL. + * - Fixed: With GUI Athena the scrollbar could get stuck at the bottom. + * - Fixed: When using :imenu to insert more than one line of text, only the + * first line could be undone. + * - Fixed: Word completion (CTRL-N) in Insert mode, when there was not + * matching word, the "Pattern not found" message was not shown. + * - Fixed: Pattern completion (CTRL-X I) in Insert mode; the file name shown + * was overwritten with the mode message. + * - Added ":if" and ":endif" commands. Everything in between them is + * ingored. Just to allow for future expansion that is backwards compatible. + * - Fixed: Starting Vim without a file, then ":e file", ":sp" and ":q" + * unloaded the buffer. + * - Fixed: execution of autocommands could not be interrupted. + * - Fixed: "ga" on an empty line gave a misleading message, now it prints + * "empty line". + * - Fixed: With 'number' set mouse positioning was wrong when lines wrap, and + * in the GUI horizontal scrolling didn't work properly. + * - Removed "src/tags" from the source distribution; you can generate it + * yourself now that ctags is included. + * - Included "macros/life", macros to run Conway's game of life. + * - Fixed using "set go=r" in gvimrc problem for Motif GUI. + * - Fixed problems when using autocommands with ":next" et. al.. Made + * "line1", "line2" and "forceit" local variables, instead of global. Lots + * of function have to pass it as an argument, which is required to avoid + * the vars to get mixed up with recursive Ex commands. + * - Removed the use of "want_start" in search.c. Fixes bug when using a + * search string that starts with "^" and contains "\|". + * + * Changes between version 4.2 and 4.3 BETA: + * - Moved ctags, tee and xxd sources from the binary to the source archive. + * - OS/2: Adjusted ExpandWildCards again, fixed alloc/free error. + * - Fixed: "Nothing in register ^@", ^@ for buffer 0 is now " + * - Fixed: Was outputting CR CR LF instead of CR LF for termios. + * - Fixed: cindent didn't handle "} else" and "} while (cond);". + * - Fixed: Was using killpg(0, SIGINT) to interrupt external commands in the + * GUI, which isn't documented on all systems. Use kill(0, SIGINT) instead. + * - Updated version number that is compared with for the ":version" command. + * - Fixed: ":0put" inserted text below line 1; now it inserts above line 1. + * - Fixed: "/t/e" would not find the last character in a line. + * - Fixed: Unloading the current buffer could load another unloaded buffer. + * Use a loaded buffer if there is one. + * - Improved: ":dis" now shows "^J" at the end of linewise registers. + * - Fixed: Using ":q" to close a window didn't execute the BufEnter + * autocommands for the new current window. + * - Forbid the reading of a file after *ReadPre autocommands, this could give + * unpredictable results. + * - Fixed: ":sball" didn't work correctly with autocommands that contain a + * ":normal" command. + * - Fixed: was accepting a mapping after CTRL-W count. + * - Fixed: a '[' in a regexp was special, made "/[z[]/" fail. + * - Amiga, DICE: included a few patches to amiga.c. + * - Fixed: Could crash when completing a setting, e.g. ":set <t_K<Tab>" + * - Fixed: Using "new fname" in a vimrc caused a window with a non-existing + * buffer. + * - Added support for keypad keys <kHome>, <kEnd>, <kPageUp> and <kPageDown>. + * They only work when they send a different code from <Home>, etc.. + * - Swapped the arguments to LINKIT in Makefile, was making a link from Vim, + * instead of to Vim. + * - Fixed: Not all parts of the swap file were cleared before using them, + * could include any data in the swap file (mostly the password file!). + * - Fixed: Could get an extra swap file when using ":au BufLeave xx bd xx". + * - Fixed: ":set comment=n:" didn't give an error message; formatting would + * cause a hang. + * - Use off_t for lseek; FreeBSD and others use long long instead of long. + * - Fixed: ":/pat" didn't match at first column in the next line. + * - Fixed: CTRL-F at end of file with 'scrolloff' non-zero would make the + * screen jump up and down and didn't beep when no more scrolling was + * possible. When last two lines didn't fit on the screen together, the + * last one was never shown. + * - When Vim is not compiled with AUTOCMD, "<afile>" is not included. + * - Fixed: ":au BufWritePre xx bunload" caused empty file to be written, now + * it gives an error message. + * - Added "<Bar>", to be used in mappings where a '|' is needed. + * - Moved "Changing readonly file" message, In insert mode, to after the mode + * message, it would otherwise be hidden. + * - Fixed: Putting a temp file in current directory for MS-DOS causes + * problems on readonly devices. Try several directories to put the temp + * file in. + * - Changed default for Unix 'errorformat' to include a few more compilers. + * - Fixed: When exiting because of a non-existing file after the "-e" + * argument, there was no newline. + * - When writing part of a buffer to a file, don't add a end-of-line for the + * last line, if 'binary' is set and the previous read didn't have an + * end-of-line for the same line. For FileWritePre autocommands that filter + * the lines through gzip. + * - Fixed: When not writing the eol for the last line, this was not visible, + * and the line count was one too low. + * - Fixed: BufNewFile autocommands that do ":r file" sometimes didn't work, + * because the cursor was in an invalid line. + * - Fixed: a *ReadFile autocommand that changed the file to be read didn't + * work, because the file was already opened. + * - Fixed: When doing ":bdel", buf_copy_options() could copy options from + * already freed memory. Would cause any combination of strange settings. + * - Check for errors while reading the viminfo file. When there are more + * than 10 errors, quit reading it. When there is any error, don't + * overwrite it with a new viminfo file. Prevents trashing a file when + * accidently doing "vim -i file" instead of "vim -v file". + * - Added "ZQ", alias for ":q!". Elvis compatible. + * - Fixed: "vim -g" would crash when .gvimrc contains ":set go=r". + * - Fixed: ":set go&" didn't work, the default contained an illegal 'A'. + * - Added 'titlelen' option: percentage of 'columns' to use for the title. + * Reduces problems with truncating long path names. + * - Added "tee" for OS/2. Very useful for ":make". + * - Fixed: Setting 'title' in the gvimrc messed up the title of the xterm + * where Vim was started when doing ":gui". + * - Fixed: When expanding "~/file" with CTRL-X CTRL-F in insert mode, the + * "~/" would get expanded into a full path. For "~user/file" the problem + * still exists though. + * - Fixed: ":set path=../b" didn't work as expected, any path starting with a + * dot would get expanded to the directory of the current file. + * - Fixed: Any dir name in 'directory' and 'backupdir' starting with '.' was + * considered to be in the current directory, also "..". Now using "./dir" + * means using a directory relative to where the file is. + * - Fixed: ":all", ":ball" and "-o" command line option would execute + * Buf/Win Enter/Leave autocommands for first buffer a few times. Now + * they are only done when really entering a buffer/window. + * - Fixed: ":all", change in first buffer, ":all" would give an error message + * for not writing the file. + * - Added 'shellcmdflag' and 'shellquote' options, mainly for Win32 when + * using different kinds of shell. + * - Fixed: "unmenu *" in .gvimrc caused a crash on some machines. + * - Fixed: ":buf" (go to current buffer) should not do anything. It executed + * autocommands and set the previous context mark. + * - Fixed: "*``" moved the cursor back to the start of the word, instead of + * where the cursor was within or before the word. + * - Fixed: ":e %:p:h" removed the head of the path ("/" for unix, "d:\" for + * DOS, "drive:" for Amiga. + * - Fixed: for the Win32 version, 'term' must be "win32", don't init it with + * $TERM. + * - Fixed: Filename completion with <Tab>, when there are several matches, + * but only one without ignored suffix, next <Tab> obtained second match, + * not the one after the previous one. Now the files without matching + * suffix are put in front of the list. + * - Fixed: DJGPP version of system() was eating file descriptors, after a few + * filter commands there would be an "Out of file handles" error. + * - Fixed: for MS-DOS: ":n doc\*.txt" didn't work, it became "doc*.txt". + * - Added: MS-DOS and WIN32 now expand $ENV in a filename. ":e $VIM/_vimrc" + * works now. + * - Fixed: MS-DOS: after ":mode 1" mouse didn't move correctly. Now it + * mostly works for the display modes up to 0x13. + * - Fixed: In Insert mode, the message from "^O:set tw" would be overwritten + * by "--INSERT--". Now there is a 10 second delay to be able to read the + * message. + * * Changes between version 4.1 and 4.2: * - Included ctags version 1.3. * - Included xxd.c version 1.4 (only one change since 1.3m) @@ -134,11 +298,13 @@ * Don't forget to update the numbers in version.h for Win32!!! */ -char *Version = "VIM 4.2"; +#include "version.h" + +char *Version = "VIM 4.4"; #ifdef HAVE_DATE_TIME -char *longVersion = "VIM - Vi IMproved 4.2 (1996 June 17, compiled " __DATE__ " " __TIME__ ")"; +char *longVersion = "VIM - Vi IMproved 4.4 BETA (1996 Sep 11, compiled " __DATE__ " " __TIME__ ")"; #else -char *longVersion = "VIM - Vi IMproved 4.2 (1996 June 17)"; +char *longVersion = "VIM - Vi IMproved 4.4 BETA (1996 Sep 11)"; #endif static void version_msg __ARGS((char *s)); @@ -161,7 +327,7 @@ do_version(arg) else found_version += n; } - if (found_version > 400) + if (found_version > VIM_VERSION_MAJOR * 100 + VIM_VERSION_MINOR) { MSG("Warning: Found newer version command"); if (sourcing_name != NULL) diff --git a/usr.bin/vim/version.h b/usr.bin/vim/version.h index cf9b0423e6f..5949316faee 100644 --- a/usr.bin/vim/version.h +++ b/usr.bin/vim/version.h @@ -1,4 +1,4 @@ -/* $OpenBSD: version.h,v 1.1 1996/09/07 21:40:27 downsj Exp $ */ +/* $OpenBSD: version.h,v 1.2 1996/09/21 06:23:26 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -22,8 +22,8 @@ #define VIM_VERSION_MAJOR 4 #define VIM_VERSION_MAJOR_STR "4" -#define VIM_VERSION_MINOR 2 -#define VIM_VERSION_MINOR_STR "2" +#define VIM_VERSION_MINOR 4 +#define VIM_VERSION_MINOR_STR "4" #define VIM_VERSION_BUILD 1 #define VIM_VERSION_BUILD_STR "1" diff --git a/usr.bin/vim/vim.h b/usr.bin/vim/vim.h index d6f2cdff670..0bfd8a88bf6 100644 --- a/usr.bin/vim/vim.h +++ b/usr.bin/vim/vim.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vim.h,v 1.1 1996/09/07 21:40:28 downsj Exp $ */ +/* $OpenBSD: vim.h,v 1.2 1996/09/21 06:23:27 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -111,14 +111,15 @@ #endif /* - * maximum length of a file name and a path (for non-unix systems) + * Maximum length of a path (for non-unix systems) Make it a bit long, to stay + * on the safe side. But not too long to put on the stack. */ -#ifndef MAXNAMLEN -# define MAXNAMLEN 31 -#endif - #ifndef MAXPATHL -# define MAXPATHL 128 /* not too long to put name on stack */ +# ifdef MAXPATHLEN +# define MAXPATHL MAXPATHLEN +# else +# define MAXPATHL 256 +# endif #endif /* @@ -335,6 +336,13 @@ typedef unsigned long long_u; #define FPC_NOTX 3 /* both don't exist. */ #define FPC_DIFFX 4 /* one of them doesn't exist. */ +/* flags for do_ecmd() */ +#define ECMD_HIDE 1 /* don't free the current buffer */ +#define ECMD_SET_HELP 2 /* set b_help flag of (new) buffer before + opening file */ +#define ECMD_OLDBUF 4 /* use existing buffer if it exists */ +#define ECMD_FORCEIT 8 /* ! used in Ex command */ + /* * Events for autocommands. */ diff --git a/usr.bin/vim/window.c b/usr.bin/vim/window.c index ae23d08b665..8e57b4ae1fc 100644 --- a/usr.bin/vim/window.c +++ b/usr.bin/vim/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.1 1996/09/07 21:40:24 downsj Exp $ */ +/* $OpenBSD: window.c,v 1.2 1996/09/21 06:23:27 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar @@ -238,7 +238,8 @@ new_win: { setpcmark(); if (win_split(0, FALSE) == OK) - (void)do_ecmd(0, ptr, NULL, NULL, p_hid, (linenr_t)0, FALSE); + (void)do_ecmd(0, ptr, NULL, NULL, (linenr_t)0, + p_hid ? ECMD_HIDE : 0); vim_free(ptr); } break; @@ -442,6 +443,21 @@ win_split(new_height, redraw) } /* + * Check if "win" is a pointer to an existing window. + */ + int +win_valid(win) + WIN *win; +{ + WIN *wp; + + for (wp = firstwin; wp != NULL; wp = wp->w_next) + if (wp == win) + return TRUE; + return FALSE; +} + +/* * Return the number of windows. */ int @@ -490,6 +506,14 @@ make_windows(count) win_new_height(curwin, curwin->w_height - STATUS_HEIGHT); } +#ifdef AUTOCMD +/* + * Don't execute autocommands while creating the windows. Must do that + * when putting the buffers in the windows. + */ + ++autocmd_busy; +#endif + /* * set 'splitbelow' off for a moment, don't want that now */ @@ -502,6 +526,10 @@ make_windows(count) break; p_sb = p_sb_save; +#ifdef AUTOCMD + --autocmd_busy; +#endif + /* return actual number of windows */ return (count - todo); } @@ -750,6 +778,9 @@ close_window(win, free_buf) int free_buf; { WIN *wp; +#ifdef AUTOCMD + int other_buffer = FALSE; +#endif if (lastwin == firstwin) { @@ -757,6 +788,34 @@ close_window(win, free_buf) return; } +#ifdef AUTOCMD + if (win == curwin) + { + /* + * Guess which window is going to be the new current window. + * This may change because of the autocommands (sigh). + */ + if ((!p_sb && win->w_next != NULL) || win->w_prev == NULL) + wp = win->w_next; + else + wp = win->w_prev; + + /* + * Be careful: If autocommands delete the window, return now. + */ + if (wp->w_buffer != curbuf) + { + other_buffer = TRUE; + apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); + if (!win_valid(win)) + return; + } + apply_autocmds(EVENT_WINLEAVE, NULL, NULL); + if (!win_valid(win)) + return; + } +#endif + /* * Remove the window. * if 'splitbelow' the free space goes to the window above it. @@ -774,15 +833,6 @@ close_window(win, free_buf) wp = win->w_prev; win_new_height(wp, wp->w_height + win->w_height + win->w_status_height); -#ifdef AUTOCMD - if (win == curwin) - { - if (wp->w_buffer != curbuf) - apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); - apply_autocmds(EVENT_WINLEAVE, NULL, NULL); - } -#endif - /* * Close the link to the buffer. */ @@ -794,7 +844,15 @@ close_window(win, free_buf) if (p_ea) win_equal(wp, FALSE); if (curwin == NULL) + { win_enter(wp, FALSE); +#ifdef AUTOCMD + if (other_buffer) + /* careful: after this wp and win may be invalid! */ + apply_autocmds(EVENT_BUFENTER, NULL, NULL); +#endif + } + /* * if last window has status line now and we don't want one, * remove the status line @@ -808,7 +866,7 @@ close_window(win, free_buf) } updateScreen(NOT_VALID); - if (RedrawingDisabled) + if (RedrawingDisabled && win_valid(wp)) comp_Botline(wp); /* need to do this before cursupdate() */ } @@ -889,7 +947,8 @@ win_init(wp) } /* - * make window wp the current window + * Make window wp the current window. + * Can be called when curwin == NULL, if curwin already has been closed. */ void win_enter(wp, undo_sync) @@ -906,12 +965,19 @@ win_enter(wp, undo_sync) #ifdef AUTOCMD if (curwin != NULL) { + /* + * Be careful: If autocommands delete the window, return now. + */ if (wp->w_buffer != curbuf) { apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); other_buffer = TRUE; + if (!win_valid(wp)) + return; } apply_autocmds(EVENT_WINLEAVE, NULL, NULL); + if (!win_valid(wp)) + return; } #endif @@ -920,7 +986,7 @@ win_enter(wp, undo_sync) u_sync(); /* may have to copy the buffer options when 'cpo' contains 'S' */ if (wp->w_buffer != curbuf) - buf_copy_options(curbuf, wp->w_buffer, TRUE); + buf_copy_options(curbuf, wp->w_buffer, TRUE, FALSE); if (curwin != NULL) prevwin = curwin; /* remember for CTRL-W p */ curwin = wp; @@ -1507,7 +1573,8 @@ get_file_name_in_path(ptr, col, options) if (len != 0) { /* Look for file relative to current file */ - if (file_name[0] == '.' && curr_path_len > 0) + if (file_name[0] == '.' && curr_path_len > 0 && + (len == 1 || ispathsep(file_name[1]))) { if (len == 1) /* just a "." */ len = 0; |