Hello, I wrote a patch which adds [count] to :colse, :hide and ^Wc normal command. When given the window with window number [count] will be closed/hidden. Sometimes I want to close not the current window but another one, this command let to do that without switching windows without ^Ww normal command.
Best regards, Marcin Szamotulski
diff -r 7090d7f160f7 -r 5f398504f605 runtime/doc/windows.txt
--- a/runtime/doc/windows.txt Sat Jul 26 13:40:44 2014 +0200
+++ b/runtime/doc/windows.txt Sat Aug 09 10:52:43 2014 +0100
@@ -279,12 +279,15 @@
the buffer are lost, even when 'hidden' is set.
CTRL-W c *CTRL-W_c* *:clo* *:close*
-:clo[se][!] Close current window. When the 'hidden' option is set, or
- when the buffer was changed and the [!] is used, the buffer
- becomes hidden (unless there is another window editing it).
- When there is only one window in the current tab page and
- there is another tab page, this closes the current tab page.
- |tab-page|.
+:[count]clo[se][!]
+ Close current window if [count] is not given, otherwise close
+ window with window number equal to [count]. When the 'hidden'
+ option is set, or when the buffer was changed and the [!] is
+ used, the buffer becomes hidden (unless there is another
+ window editing it). When there is only one window in the
+ current tab page and there is another tab page, this closes
+ the current tab page. |tab-page|. If [count] is greater than
+ the last window number the last window will be closed.
This command fails when: *E444*
- There is only one window on the screen.
- When 'hidden' is not set, [!] is not used, the buffer has
@@ -298,11 +301,12 @@
command.
*:hide*
-:hid[e] Quit current window, unless it is the last window on the
- screen. The buffer becomes hidden (unless there is another
- window editing it or 'bufhidden' is "unload" or "delete").
- If the window is the last one in the current tab page the tab
- page is closed. |tab-page|
+:[count]hid[e] Quit current window, unless it is the last window on the
+ screen. If [count] is given quit the window with window
+ number equal to [count]. The buffer becomes hidden (unless
+ there is another window editing it or 'bufhidden' is "unload"
+ or "delete"). If the window is the last one in the current
+ tab page the tab page is closed. |tab-page|
The value of 'hidden' is irrelevant for this command.
Changes to the buffer are not written and won't get lost, so
this is a "safe" command.
diff -r 7090d7f160f7 -r 5f398504f605 src/ex_cmds.h
--- a/src/ex_cmds.h Sat Jul 26 13:40:44 2014 +0200
+++ b/src/ex_cmds.h Sat Aug 09 10:52:43 2014 +0100
@@ -232,7 +232,7 @@
EX(CMD_clast, "clast", ex_cc,
RANGE|NOTADR|COUNT|TRLBAR|BANG),
EX(CMD_close, "close", ex_close,
- BANG|TRLBAR|CMDWIN),
+ BANG|RANGE|NOTADR|COUNT|TRLBAR|CMDWIN),
EX(CMD_cmap, "cmap", ex_map,
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN),
EX(CMD_cmapclear, "cmapclear", ex_mapclear,
@@ -428,7 +428,7 @@
EX(CMD_highlight, "highlight", ex_highlight,
BANG|EXTRA|TRLBAR|SBOXOK|CMDWIN),
EX(CMD_hide, "hide", ex_hide,
- BANG|EXTRA|NOTRLCOM),
+ BANG|RANGE|NOTADR|COUNT|EXTRA|NOTRLCOM),
EX(CMD_history, "history", ex_history,
EXTRA|TRLBAR|CMDWIN),
EX(CMD_insert, "insert", ex_append,
diff -r 7090d7f160f7 -r 5f398504f605 src/ex_docmd.c
--- a/src/ex_docmd.c Sat Jul 26 13:40:44 2014 +0200
+++ b/src/ex_docmd.c Sat Aug 09 10:52:43 2014 +0100
@@ -6657,6 +6657,8 @@
ex_close(eap)
exarg_T *eap;
{
+ win_T *win;
+ int winnr = 0;
# ifdef FEAT_CMDWIN
if (cmdwin_type != 0)
cmdwin_result = Ctrl_C;
@@ -6667,7 +6669,21 @@
&& !curbuf_locked()
#endif
)
- ex_win_close(eap->forceit, curwin, NULL);
+ {
+ if (eap->addr_count == 0)
+ ex_win_close(eap->forceit, curwin, NULL);
+ else {
+ for (win = firstwin; win != NULL; win = win->w_next)
+ {
+ winnr++;
+ if (winnr == eap->line2)
+ break;
+ }
+ if (win == NULL)
+ win = lastwin;
+ ex_win_close(eap->forceit, win, NULL);
+ }
+ }
}
# ifdef FEAT_QUICKFIX
@@ -6895,6 +6911,9 @@
ex_hide(eap)
exarg_T *eap;
{
+ win_T *win;
+ int winnr = 0;
+
if (*eap->arg != NUL && check_nextcmd(eap->arg) == NULL)
eap->errmsg = e_invarg;
else
@@ -6907,7 +6926,18 @@
# ifdef FEAT_GUI
need_mouse_correct = TRUE;
# endif
- win_close(curwin, FALSE); /* don't free buffer */
+ if (eap->addr_count == 0)
+ win_close(curwin, FALSE); /* don't free buffer */
+ else {
+ for(win = firstwin; win != NULL; win->w_next) {
+ winnr++;
+ if (winnr == eap->line2)
+ break;
+ }
+ if (win == NULL)
+ win = lastwin;
+ win_close(win, FALSE);
+ }
}
#endif
}
diff -r 7090d7f160f7 -r 5f398504f605 src/window.c
--- a/src/window.c Sat Jul 26 13:40:44 2014 +0200
+++ b/src/window.c Sat Aug 09 10:52:43 2014 +0100
@@ -206,7 +206,11 @@
case Ctrl_C:
case 'c':
reset_VIsual_and_resel(); /* stop Visual mode */
- do_cmdline_cmd((char_u *)"close");
+ STRCPY(cbuf, "close");
+ if (Prenum)
+ vim_snprintf((char *)cbuf + 5, sizeof(cbuf) - 5,
+ "%ld", Prenum);
+ do_cmdline_cmd(cbuf);
break;
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
signature.asc
Description: Digital signature
