Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ":curwin" command modifier that makes split commands use current window #3251

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions runtime/doc/index.txt
Expand Up @@ -1252,6 +1252,7 @@ tag command action ~
|:cunmap| :cu[nmap] like ":unmap" but for Command-line mode
|:cunabbrev| :cuna[bbrev] like ":unabbrev" but for Command-line mode
|:cunmenu| :cunme[nu] remove menu for Command-line mode
|:curwin| :cur[win] make new split use current window instead
|:cwindow| :cw[indow] open or close quickfix window
|:delete| :d[elete] delete lines
|:delmarks| :delm[arks] delete marks
Expand Down
8 changes: 4 additions & 4 deletions runtime/doc/map.txt
Expand Up @@ -1453,10 +1453,10 @@ The valid escape sequences are
*<mods>*
<mods> The command modifiers, if specified. Otherwise, expands to
nothing. Supported modifiers are |:aboveleft|, |:belowright|,
|:botright|, |:browse|, |:confirm|, |:hide|, |:keepalt|,
|:keepjumps|, |:keepmarks|, |:keeppatterns|, |:leftabove|,
|:lockmarks|, |:noswapfile| |:rightbelow|, |:silent|, |:tab|,
|:topleft|, |:verbose|, and |:vertical|.
|:botright|, |:browse|, |:confirm|, |:curwin|, |:hide|,
|:keepalt|, |:keepjumps|, |:keepmarks|, |:keeppatterns|,
|:leftabove|, |:lockmarks|, |:noswapfile| |:rightbelow|,
|:silent|, |:tab|, |:topleft|, |:verbose|, and |:vertical|.
Note that these are not yet supported: |:noautocmd|,
|:sandbox| and |:unsilent|.
Examples: >
Expand Down
25 changes: 25 additions & 0 deletions runtime/doc/windows.txt
Expand Up @@ -279,6 +279,31 @@ occupy the full height. Example: >
Opens a vertically split, full-height window on the "tags" file at the far
left of the Vim window.

*:cur* *:curwin*
:[count]cur[win][!] {cmd}
Execute {cmd}. If it contains a command that splits a window,
use the current window instead of opening a new one.
Doesn't work for |:all|, |:execute| and |:normal|.
This fails when changes have been made to the original buffer
and 'autowrite' or 'hidden' are not set. Use [!] to forcefully
discard any changes to the original buffer. If [count] is
given the command will pick the window specified by [count]
instead of the current window.

Examples: >
:curwin help " opens help in the current window
:.curwin help " as above
:+curwin help " opens help in the window after the
" current one
:-curwin help " opens help in the window before the
" current one
:1curwin help " opens help in the top left window
:$curwin help " opens help in the bottom right window
:+curwin copen " opens quickfix in the next window
:3curwin! split " opens current buffer in the 3rd window
" and abandon that window's original
" buffer if needed


Closing a window
----------------
Expand Down
2 changes: 1 addition & 1 deletion runtime/syntax/vim.vim
Expand Up @@ -19,7 +19,7 @@ syn keyword vimTodo contained COMBAK FIXME TODO XXX
syn cluster vimCommentGroup contains=vimTodo,@Spell

" regular vim commands {{{2
syn keyword vimCommand contained a arga[dd] argu[ment] bad[d] bn[ext] breakd[el] bw[ipeout] cadde[xpr] cc cf[ile] changes cla[st] cnf[ile] comp[iler] cq[uit] cw[indow] delep dell diffg[et] dig[raphs] doau ea el[se] endt[ry] f[ile] fina[lly] foldd[oopen] go[to] ha[rdcopy] hid[e] ij[ump] isp[lit] keepa l[ist] lat lcl[ose] lex[pr] lgete[xpr] lla[st] lnf[ile] lol[der] lt[ag] lw[indow] menut[ranslate] mkv[imrc] nb[key] noa nos[wapfile] on[ly] packl[oadall] po[p] pro ps[earch] ptl[ast] pu[t] pydo pyxdo r[ead] redraws[tatus] rew[ind] rubyd[o] sIc sIp san[dbox] sbf[irst] sbr[ewind] sci scs setl[ocal] sgc sgp sie sin sm[agic] sn[ext] sor[t] spellr[epall] srI srl star[tinsert] sts[elect] sv[iew] syncbind tab tabf[ind] tabnew tags ter[minal] tm[enu] to[pleft] tu[nmenu] undol[ist] up[date] vi[sual] vmapc[lear] wa[ll] winp[os] ws[verb] xmapc[lear] xprop
syn keyword vimCommand contained a arga[dd] argu[ment] bad[d] bn[ext] breakd[el] bw[ipeout] cadde[xpr] cc cf[ile] changes cla[st] cnf[ile] comp[iler] cq[uit] cur[win] cw[indow] delep dell diffg[et] dig[raphs] doau ea el[se] endt[ry] f[ile] fina[lly] foldd[oopen] go[to] ha[rdcopy] hid[e] ij[ump] isp[lit] keepa l[ist] lat lcl[ose] lex[pr] lgete[xpr] lla[st] lnf[ile] lol[der] lt[ag] lw[indow] menut[ranslate] mkv[imrc] nb[key] noa nos[wapfile] on[ly] packl[oadall] po[p] pro ps[earch] ptl[ast] pu[t] pydo pyxdo r[ead] redraws[tatus] rew[ind] rubyd[o] sIc sIp san[dbox] sbf[irst] sbr[ewind] sci scs setl[ocal] sgc sgp sie sin sm[agic] sn[ext] sor[t] spellr[epall] srI srl star[tinsert] sts[elect] sv[iew] syncbind tab tabf[ind] tabnew tags ter[minal] tm[enu] to[pleft] tu[nmenu] undol[ist] up[date] vi[sual] vmapc[lear] wa[ll] winp[os] ws[verb] xmapc[lear] xprop
syn keyword vimCommand contained ab argd[elete] as[cii] bd[elete] bo[tright] breakl[ist] cN[ext] caddf[ile] ccl[ose] cfdo chd[ir] cle[arjumps] co[py] con[tinue] cr[ewind] d[elete] deletel delm[arks] diffo[ff] dir dp earlier elsei[f] endw[hile] files fini[sh] folddoc[losed] gr[ep] helpc[lose] his[tory] il[ist] iuna[bbrev] keepalt la[st] later lcs lf[ile] lgr[ep] lli[st] lo[adview] lop[en] lua m[ove] mes mkvie[w] nbc[lose] noautocmd nu[mber] opt[ions] pc[lose] popu[p] prof[ile] ptN[ext] ptn[ext] pw[d] pyf[ile] pyxfile rec[over] reg[isters] ri[ght] rubyf[ile] sIe sIr sav[eas] sbl[ast] sc scl scscope sf[ind] sge sgr sig sip sm[ap] sno[magic] sp[lit] spellu[ndo] src srn startg[replace] sun[hide] sw[apname] syntime tabN[ext] tabfir[st] tabo[nly] tc[l] tf[irst] tma[p] tp[revious] tunma[p] unh[ide] v vie[w] vne[w] wh[ile] wn[ext] wundo xme xunme
syn keyword vimCommand contained abc[lear] argdo au bel[owright] bp[revious] bro[wse] cNf[ile] cal[l] cd cfir[st] che[ckpath] clo[se] col[der] conf[irm] cs debug deletep delp diffp[atch] dj[ump] dr[op] ec em[enu] ene[w] filet fir[st] foldo[pen] grepa[dd] helpf[ind] i imapc[lear] j[oin] keepj[umps] lad[dexpr] lb[uffer] lcscope lfdo lgrepa[dd] lmak[e] loadk lp[revious] luado ma[rk] messages mod[e] nbs[tart] noh[lsearch] o[pen] ownsyntax pe[rl] pp[op] profd[el] pta[g] ptp[revious] py3 python3 q[uit] red[o] res[ize] rightb[elow] rundo sIg sN[ext] sbN[ext] sbm[odified] scI scp se[t] sfir[st] sgi sh[ell] sign sir sme snoreme spe[llgood] spellw[rong] sre[wind] srp startr[eplace] sunme sy t tabc[lose] tabl[ast] tabp[revious] tcld[o] th[row] tmapc[lear] tr[ewind] u[ndo] unl ve[rsion] vim[grep] vs[plit] win[size] wp[revious] wv[iminfo] xmenu xunmenu
syn keyword vimCommand contained abo[veleft] arge[dit] bN[ext] bf[irst] br[ewind] bufdo c[hange] cat[ch] cdo cg[etfile] checkt[ime] cmapc[lear] colo[rscheme] cope[n] cscope debugg[reedy] deletl dep diffpu[t] dl ds[earch] echoe[rr] en[dif] ex filetype fix[del] for gui helpg[rep] ia in ju[mps] keepp[atterns] laddb[uffer] lbo[ttom] ld[o] lfir[st] lh[elpgrep] lmapc[lear] loadkeymap lpf[ile] luafile mak[e] mk[exrc] mz[scheme] new nor ol[dfiles] p[rint] ped[it] pre[serve] promptf[ind] ptf[irst] ptr[ewind] py3do pythonx qa[ll] redi[r] ret[ab] ru[ntime] rv[iminfo] sIl sa[rgument] sb[uffer] sbn[ext] sce scr[iptnames] setf[iletype] sg sgl si sil[ent] sl[eep] smenu snoremenu spelld[ump] spr[evious] srg st[op] stj[ump] sunmenu syn tN[ext] tabd[o] tabm[ove] tabr[ewind] tclf[ile] tj[ump] tn[ext] try una[bbreviate] unlo[ckvar] verb[ose] vimgrepa[dd] wN[ext] winc[md] wq x[it] xnoreme xwininfo
Expand Down
4 changes: 4 additions & 0 deletions src/buffer.c
Expand Up @@ -4947,6 +4947,10 @@ do_arg_all(
need_mouse_correct = TRUE;
# endif

/* don't use a current window, since the whole point of this command is to
* open multiple splits */
cmdmod.curwin = 0;

/*
* Try closing all windows that are not in the argument list.
* Also close windows that are not full width;
Expand Down
50 changes: 25 additions & 25 deletions src/ex_cmdidxs.h
Expand Up @@ -8,29 +8,29 @@ static const unsigned short cmdidxs1[26] =
/* a */ 0,
/* b */ 19,
/* c */ 42,
/* d */ 108,
/* e */ 130,
/* f */ 150,
/* g */ 166,
/* h */ 172,
/* i */ 181,
/* j */ 199,
/* k */ 201,
/* l */ 206,
/* m */ 268,
/* n */ 286,
/* o */ 306,
/* p */ 318,
/* q */ 357,
/* r */ 360,
/* s */ 380,
/* t */ 448,
/* u */ 493,
/* v */ 504,
/* w */ 522,
/* x */ 536,
/* y */ 546,
/* z */ 547
/* d */ 109,
/* e */ 131,
/* f */ 151,
/* g */ 167,
/* h */ 173,
/* i */ 182,
/* j */ 200,
/* k */ 202,
/* l */ 207,
/* m */ 269,
/* n */ 287,
/* o */ 307,
/* p */ 319,
/* q */ 358,
/* r */ 361,
/* s */ 381,
/* t */ 449,
/* u */ 494,
/* v */ 505,
/* w */ 523,
/* x */ 537,
/* y */ 547,
/* z */ 548
};

/*
Expand All @@ -43,7 +43,7 @@ static const unsigned char cmdidxs2[26][26] =
{ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
/* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0 },
/* b */ { 2, 0, 0, 4, 5, 7, 0, 0, 0, 0, 0, 8, 9, 10, 11, 12, 0, 13, 0, 0, 0, 0, 22, 0, 0, 0 },
/* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 37, 40, 46, 56, 58, 59, 60, 0, 62, 0, 65, 0, 0, 0 },
/* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 37, 40, 46, 56, 58, 59, 60, 0, 62, 0, 66, 0, 0, 0 },
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 0, 16, 0, 0, 17, 0, 0, 19, 20, 0, 0, 0, 0, 0, 0, 0 },
/* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0 },
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0 },
Expand All @@ -69,4 +69,4 @@ static const unsigned char cmdidxs2[26][26] =
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};

static const int command_count = 560;
static const int command_count = 561;
15 changes: 12 additions & 3 deletions src/ex_cmds.c
Expand Up @@ -6327,6 +6327,7 @@ ex_help(exarg_T *eap)
#ifdef FEAT_FOLDING
int old_KeyTyped = KeyTyped;
#endif
int ecmd_flags = ECMD_HIDE;

if (eap != NULL)
{
Expand Down Expand Up @@ -6448,8 +6449,16 @@ ex_help(exarg_T *eap)
if (win_split(0, n) == FAIL)
goto erret;

if (curwin->w_height < p_hh)
win_setheight((int)p_hh);
if (cmdmod.curwin == 0)
{
if (curwin->w_height < p_hh)
win_setheight((int)p_hh);
}
else
{
if (cmdmod.curwin_force)
ecmd_flags = ECMD_FORCEIT;
}

/*
* Open help file (do_ecmd() will set b_help flag, readfile() will
Expand All @@ -6458,7 +6467,7 @@ ex_help(exarg_T *eap)
*/
alt_fnum = curbuf->b_fnum;
(void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL,
ECMD_HIDE + ECMD_SET_HELP,
ecmd_flags + ECMD_SET_HELP,
NULL); /* buffer is still open, don't store info */
if (!cmdmod.keepalt)
curwin->w_alt_fnum = alt_fnum;
Expand Down
3 changes: 3 additions & 0 deletions src/ex_cmds.h
Expand Up @@ -434,6 +434,9 @@ EX(CMD_cunabbrev, "cunabbrev", ex_abbreviate,
EX(CMD_cunmenu, "cunmenu", ex_menu,
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,
ADDR_NONE),
EX(CMD_curwin, "curwin", ex_wrongmodifier,
NEEDARG|EXTRA|NOTRLCOM,
ADDR_NONE),
EX(CMD_cwindow, "cwindow", ex_cwindow,
RANGE|COUNT|TRLBAR,
ADDR_OTHER),
Expand Down
44 changes: 38 additions & 6 deletions src/ex_docmd.c
Expand Up @@ -2377,6 +2377,7 @@ do_one_cmd(
case CMD_browse:
case CMD_call:
case CMD_confirm:
case CMD_curwin:
case CMD_delfunction:
case CMD_djump:
case CMD_dlist:
Expand Down Expand Up @@ -2669,11 +2670,38 @@ parse_command_modifiers(exarg_T *eap, char **errormsg, int skip_only)
cmdmod.split |= WSP_BOT;
continue;

case 'c': if (!checkforcmd(&eap->cmd, "confirm", 4))
break;
case 'c': if (checkforcmd(&eap->cmd, "confirm", 4))
{
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
cmdmod.confirm = TRUE;
cmdmod.confirm = TRUE;
#endif
continue;
}
if (!checkforcmd(&p, "curwin", 3))
break;

{
long winnr = get_address(eap, &eap->cmd, ADDR_WINDOWS,
eap->skip, skip_only,
FALSE, 1);
if (winnr == MAXLNUM)
cmdmod.curwin = CURRENT_WIN_NR;
else
{
if (winnr <= 0 || winnr > LAST_WIN_NR)
{
*errormsg = (e_invrange);
return FAIL;
}
cmdmod.curwin = winnr;
}
if (*p == '!')
{
cmdmod.curwin_force = TRUE;
p = skipwhite(p + 1);
}
eap->cmd = p;
}
continue;

case 'k': if (checkforcmd(&eap->cmd, "keepmarks", 3))
Expand Down Expand Up @@ -3253,6 +3281,7 @@ static struct cmdmod
{"botright", 2, FALSE},
{"browse", 3, FALSE},
{"confirm", 4, FALSE},
{"curwin", 3, TRUE},
{"filter", 4, FALSE},
{"hide", 3, FALSE},
{"keepalt", 5, FALSE},
Expand Down Expand Up @@ -3753,6 +3782,7 @@ set_one_cmd_context(
case CMD_cdo:
case CMD_cfdo:
case CMD_confirm:
case CMD_curwin:
case CMD_debug:
case CMD_folddoclosed:
case CMD_folddoopen:
Expand Down Expand Up @@ -6868,7 +6898,8 @@ ex_splitview(exarg_T *eap)
RESET_BINDING(curwin);
else
do_check_scrollbind(FALSE);
do_exedit(eap, old_curwin);

do_exedit(eap, (old_curwin == curwin) ? NULL : old_curwin);
}

# ifdef FEAT_BROWSE
Expand Down Expand Up @@ -7208,7 +7239,8 @@ do_exedit(
}
}

if ((eap->cmdidx == CMD_new
if (!cmdmod.curwin
&& (eap->cmdidx == CMD_new
|| eap->cmdidx == CMD_tabnew
|| eap->cmdidx == CMD_tabedit
|| eap->cmdidx == CMD_vnew) && *eap->arg == NUL)
Expand Down Expand Up @@ -7245,7 +7277,7 @@ do_exedit(
&& vim_strchr(p_cpo, CPO_GOTO1) != NULL)
? ECMD_ONE : eap->do_ecmd_lnum,
(buf_hide(curbuf) ? ECMD_HIDE : 0)
+ (eap->forceit ? ECMD_FORCEIT : 0)
+ (eap->forceit || (cmdmod.curwin && cmdmod.curwin_force) ? ECMD_FORCEIT : 0)
/* after a split we can use an existing buffer */
+ (old_curwin != NULL ? ECMD_OLDBUF : 0)
+ (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 )
Expand Down
25 changes: 16 additions & 9 deletions src/quickfix.c
Expand Up @@ -4089,6 +4089,7 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
tabpage_T *prevtab = curtab;
int flags = 0;
win_T *win;
int ecmd_flags = ECMD_HIDE;

qf_buf = qf_find_buf(qi);

Expand All @@ -4115,18 +4116,21 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
qi->qf_refcount++;
}

if (cmdmod.curwin && cmdmod.curwin_force)
ecmd_flags = ECMD_FORCEIT;

if (oldwin != curwin)
oldwin = NULL; // don't store info when in another window
if (qf_buf != NULL)
{
// Use the existing quickfix buffer
(void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
ECMD_HIDE + ECMD_OLDBUF, oldwin);
ecmd_flags + ECMD_OLDBUF, oldwin);
}
else
{
// Create a new quickfix buffer
(void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
(void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ecmd_flags, oldwin);

// save the number of the new buffer
qi->qf_bufnr = curbuf->b_fnum;
Expand All @@ -4138,13 +4142,16 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
if (!bt_quickfix(curbuf))
qf_set_cwindow_options();

// Only set the height when still in the same tab page and there is no
// window to the side.
if (curtab == prevtab && curwin->w_width == Columns)
win_setheight(height);
curwin->w_p_wfh = TRUE; // set 'winfixheight'
if (win_valid(win))
prevwin = win;
if (cmdmod.curwin == 0)
{
// Only set the height when still in the same tab page and there is no
// window to the side.
if (curtab == prevtab && curwin->w_width == Columns)
win_setheight(height);
curwin->w_p_wfh = TRUE; // set 'winfixheight'
if (win_valid(win))
prevwin = win;
}

return OK;
}
Expand Down
2 changes: 2 additions & 0 deletions src/structs.h
Expand Up @@ -588,6 +588,8 @@ typedef struct
# ifdef FEAT_BROWSE_CMD
int browse; // TRUE to invoke file dialog
# endif
int curwin; // > 0 when ":curwin" was used
int curwin_force; // set for :curwin!
int split; // flags for win_split()
int tab; // > 0 when ":tab" was used
# if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
Expand Down