Macros | Enumerations | Functions
window.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/hashtab.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/match.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/plines.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"


#define NOWIN   ((win_T *)-1)
#define ROWS_AVAIL   (Rows - p_ch - tabline_height() - global_stl_height())
#define FRACTION_MULT   16384L


enum  wee_flags_T {
 flags for win_enter_ext() More...


win_Tprevwin_curwin (void)
void do_window (int nchar, long Prenum, int xchar)
void win_set_buf (Window window, Buffer buffer, bool noautocmd, Error *err)
win_Twin_new_float (win_T *wp, bool last, FloatConfig fconfig, Error *err)
void win_set_minimal_style (win_T *wp)
void win_config_float (win_T *wp, FloatConfig fconfig)
void win_check_anchored_floats (win_T *win)
int win_fdccol_count (win_T *wp)
 Return the number of fold columns to display. More...
void ui_ext_win_position (win_T *wp)
void ui_ext_win_viewport (win_T *wp)
int win_split (int size, int flags)
int win_split_ins (int size, int flags, win_T *new_wp, int dir)
bool win_valid_floating (const win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool win_valid (const win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
win_Twin_find_by_handle (handle_T handle) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool win_valid_any_tab (win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int win_count (void)
int make_windows (int count, bool vertical)
void win_move_after (win_T *win1, win_T *win2)
void win_equal (win_T *next_curwin, bool current, int dir)
void entering_window (win_T *const win) FUNC_ATTR_NONNULL_ALL
void win_init_empty (win_T *wp)
void curwin_init (void)
void close_windows (buf_T *buf, bool keep_curwin)
bool one_window (win_T *counted_float) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool one_nonfloat (void)
 Like ONE_WINDOW but only considers non-floating windows. More...
bool last_nonfloat (win_T *wp) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int win_close (win_T *win, bool free_buf, bool force)
void win_close_othertab (win_T *win, int free_buf, tabpage_T *tp)
win_Twinframe_remove (win_T *win, int *dirp, tabpage_T *tp)
win_Tframe2win (frame_T *frp)
void frame_new_height (frame_T *topfrp, int height, bool topfirst, bool wfh) FUNC_ATTR_NONNULL_ALL
void close_others (int message, int forceit)
int win_alloc_first (void)
void win_alloc_aucmd_win (void)
void win_init_size (void)
void free_tabpage (tabpage_T *tp)
int win_new_tabpage (int after, char_u *filename)
int may_open_tabpage (void)
int make_tabpages (int maxcount)
bool valid_tabpage (tabpage_T *tpc) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int valid_tabpage_win (tabpage_T *tpc)
 Returns true when tpc is valid and at least one window is valid. More...
void close_tabpage (tabpage_T *tab)
tabpage_Tfind_tabpage (int n)
int tabpage_index (tabpage_T *ftp)
void goto_tabpage (int n)
void goto_tabpage_tp (tabpage_T *tp, bool trigger_enter_autocmds, bool trigger_leave_autocmds)
bool goto_tabpage_lastused (void)
void goto_tabpage_win (tabpage_T *tp, win_T *wp)
void tabpage_move (int nr)
void win_goto (win_T *wp)
tabpage_Twin_find_tabpage (win_T *win)
win_Twin_vert_neighbor (tabpage_T *tp, win_T *wp, bool up, long count)
win_Twin_horz_neighbor (tabpage_T *tp, win_T *wp, bool left, long count)
void win_enter (win_T *wp, bool undo_sync)
void fix_current_dir (void)
 Used after making another window the current one: change directory if needed. More...
win_Tbuf_jump_open_win (buf_T *buf)
win_Tbuf_jump_open_tab (buf_T *buf)
void free_wininfo (wininfo_T *wip, buf_T *bp)
void win_free_grid (win_T *wp, bool reinit)
void win_append (win_T *after, win_T *wp)
void win_remove (win_T *wp, tabpage_T *tp)
void shell_new_rows (void)
void shell_new_columns (void)
void may_trigger_winscrolled (void)
 Trigger WinScrolled for "curwin" if needed. More...
void win_size_save (garray_T *gap)
void win_size_restore (garray_T *gap) FUNC_ATTR_NONNULL_ALL
int win_comp_pos (void)
void win_reconfig_floats (void)
void win_setheight (int height)
void win_setheight_win (int height, win_T *win)
void win_setwidth (int width)
void win_setwidth_win (int width, win_T *wp)
void win_setminheight (void)
void win_setminwidth (void)
void win_drag_status_line (win_T *dragwin, int offset)
 Status line of dragwin is dragged "offset" lines down (negative is up). More...
void win_drag_vsep_line (win_T *dragwin, int offset)
void set_fraction (win_T *wp)
void win_new_height (win_T *wp, int height)
void scroll_to_fraction (win_T *wp, int prev_height)
void win_set_inner_size (win_T *wp)
void win_new_width (win_T *wp, int width)
 Set the width of a window. More...
void win_comp_scroll (win_T *wp)
void command_height (void)
char_ugrab_file_name (long count, linenr_T *file_lnum)
char_ufile_name_at_cursor (int options, long count, linenr_T *file_lnum)
char_ufile_name_in_line (char_u *line, int col, int options, long count, char_u *rel_fname, linenr_T *file_lnum)
void last_status (bool morewin)
int tabline_height (void)
 Return the number of lines used by the tab page line. More...
int global_stl_height (void)
 Return the number of lines used by the global statusline. More...
int min_rows (void)
bool only_one_window (void)
void check_lnums (bool do_curwin)
void reset_lnums (void)
void make_snapshot (int idx)
void restore_snapshot (int idx, int close_curwin)
int switch_win (switchwin_T *switchwin, win_T *win, tabpage_T *tp, bool no_display)
int switch_win_noblock (switchwin_T *switchwin, win_T *win, tabpage_T *tp, bool no_display)
void restore_win (switchwin_T *switchwin, bool no_display)
void restore_win_noblock (switchwin_T *switchwin, bool no_display)
void switch_buffer (bufref_T *save_curbuf, buf_T *buf)
void restore_buffer (bufref_T *save_curbuf)
 Restore the current buffer after using switch_buffer(). More...
int win_getid (typval_T *argvars)
int win_gotoid (typval_T *argvars)
void win_get_tabwin (handle_T id, int *tabnr, int *winnr)
void win_id2tabwin (typval_T *const argvars, typval_T *const rettv)
win_Twin_id2wp (int id)
win_Twin_id2wp_tp (int id, tabpage_T **tpp)
int win_id2win (typval_T *argvars)
void win_findbuf (typval_T *argvars, list_T *list)
void get_framelayout (const frame_T *fr, list_T *l, bool outer)
void win_ui_flush (void)
win_Tlastwin_nofloating (void)

Macro Definition Documentation


do { \
if (cmdwin_type != 0) { \
emsg(_(e_cmdwin)); \
return; \
} \
} while (0)


#define FRACTION_MULT   16384L


#define NOWIN   ((win_T *)-1)


#define ROWS_AVAIL   (Rows - p_ch - tabline_height() - global_stl_height())

Enumeration Type Documentation

◆ wee_flags_T

flags for win_enter_ext()


Function Documentation

◆ buf_jump_open_tab()

win_T* buf_jump_open_tab ( buf_T buf)

Jump to the first open window in any tab page that contains buffer "buf", if one exists.

the found window, or NULL.

◆ buf_jump_open_win()

win_T* buf_jump_open_win ( buf_T buf)

Jump to the first open window that contains buffer "buf", if one exists. Returns a pointer to the window found, otherwise NULL.

◆ check_lnums()

void check_lnums ( bool  do_curwin)

Correct the cursor line number in other windows. Used after changing the current buffer, and before applying autocommands.

do_curwinwhen true, also check current window.

◆ close_others()

void close_others ( int  message,
int  forceit 

Try to close all windows except current one. Buffers in the other windows become hidden if 'hidden' is set, or '!' is used and the buffer was modified.

Used by ":bdel" and ":only".

forceitalways hide all other windows

◆ close_tabpage()

void close_tabpage ( tabpage_T tab)

Close tabpage tab, assuming it has no windows in it. There must be another tabpage or this will crash.

◆ close_windows()

void close_windows ( buf_T buf,
bool  keep_curwin 

Closes all windows for buffer buf unless there is only one non-floating window.

keep_curwindon't close curwin

◆ command_height()

void command_height ( void  )

◆ curwin_init()

void curwin_init ( void  )

Init the current window "curwin". Called when a new file is being edited.

◆ do_window()

void do_window ( int  nchar,
long  Prenum,
int  xchar 

all CTRL-W window commands are handled here, called from normal_cmd().

xcharextra char from ":wincmd gx" or NUL

◆ entering_window()

void entering_window ( win_T *const  win)

◆ file_name_at_cursor()

char_u* file_name_at_cursor ( int  options,
long  count,
linenr_T file_lnum 

◆ file_name_in_line()

char_u* file_name_in_line ( char_u line,
int  col,
int  options,
long  count,
char_u rel_fname,
linenr_T file_lnum 
rel_fnamefile we are searching relative to
file_lnumline number after the file name
the name of the file under or after ptr[col]. Otherwise like file_name_at_cursor().

◆ find_tabpage()

tabpage_T* find_tabpage ( int  n)

◆ fix_current_dir()

void fix_current_dir ( void  )

Used after making another window the current one: change directory if needed.

◆ frame2win()

win_T* frame2win ( frame_T frp)

◆ frame_new_height()

void frame_new_height ( frame_T topfrp,
int  height,
bool  topfirst,
bool  wfh 

Set a new height for a frame. Recursively sets the height for contained frames and windows. Caller must take care of positions.

topfirstresize topmost contained frame first.
wfhobey 'winfixheight' when there is a choice; may cause the height not to be set.

◆ free_tabpage()

void free_tabpage ( tabpage_T tp)

◆ free_wininfo()

void free_wininfo ( wininfo_T wip,
buf_T bp 

◆ get_framelayout()

void get_framelayout ( const frame_T fr,
list_T l,
bool  outer 

◆ global_stl_height()

int global_stl_height ( void  )

Return the number of lines used by the global statusline.

◆ goto_tabpage()

void goto_tabpage ( int  n)

◆ goto_tabpage_lastused()

bool goto_tabpage_lastused ( void  )

Go to the last accessed tab page, if there is one.

true if the tab page is valid, false otherwise.

◆ goto_tabpage_tp()

void goto_tabpage_tp ( tabpage_T tp,
bool  trigger_enter_autocmds,
bool  trigger_leave_autocmds 

Go to tabpage "tp". Note: doesn't update the GUI tab.

trigger_enter_autocmdswhen true trigger *Enter autocommands.
trigger_leave_autocmdswhen true trigger *Leave autocommands.

◆ goto_tabpage_win()

void goto_tabpage_win ( tabpage_T tp,
win_T wp 

◆ grab_file_name()

char_u* grab_file_name ( long  count,
linenr_T file_lnum 

◆ last_nonfloat()

bool last_nonfloat ( win_T wp)

if wp is the last non-floating window

always false for a floating window

◆ last_status()

void last_status ( bool  morewin)

Add or remove a status line from window(s), according to the value of 'laststatus'.

morewinpretend there are two or more windows if true.

◆ last_window()

bool last_window ( win_T win)

Check that the specified window is the last one.

wincounted even if floating
true if the specified window is the only window that exists, false if there is another, possibly in another tab page.

◆ lastwin_nofloating()

win_T* lastwin_nofloating ( void  )

◆ make_snapshot()

void make_snapshot ( int  idx)

◆ make_tabpages()

int make_tabpages ( int  maxcount)

◆ make_windows()

int make_windows ( int  count,
bool  vertical 

Make "count" windows on the screen. Must be called when there is just one window, filling the whole screen (excluding the command line).

verticalsplit windows vertically if true
actual number of windows on the screen.

◆ may_open_tabpage()

int may_open_tabpage ( void  )

◆ may_trigger_winscrolled()

void may_trigger_winscrolled ( void  )

Trigger WinScrolled for "curwin" if needed.

◆ min_rows()

int min_rows ( void  )

Return the minimal number of rows that is needed on the screen to display the current number of windows.

◆ one_nonfloat()

bool one_nonfloat ( void  )

Like ONE_WINDOW but only considers non-floating windows.

◆ one_window()

bool one_window ( win_T counted_float)

Check that current tab page contains no more then one window other than aucmd_win.

counted_floatcounted even if floating, but not if it is aucmd_win

◆ only_one_window()

bool only_one_window ( void  )

Check that there is only one window (and only one tab page), not counting a help or preview window, unless it is the current window. Does not count "aucmd_win". Does not count floats unless it is current.

◆ prevwin_curwin()

win_T* prevwin_curwin ( void  )
the current window, unless in the cmdline window and "prevwin" is set, then return "prevwin".

◆ reset_lnums()

void reset_lnums ( void  )

Reset cursor and topline to its stored values from check_lnums(). check_lnums() must have been called first!

◆ restore_buffer()

void restore_buffer ( bufref_T save_curbuf)

Restore the current buffer after using switch_buffer().

◆ restore_snapshot()

void restore_snapshot ( int  idx,
int  close_curwin 

Restore a previously created snapshot, if there is any. This is only done if the screen size didn't change and the window layout is still the same.

close_curwinclosing current window

◆ restore_win()

void restore_win ( switchwin_T switchwin,
bool  no_display 

◆ restore_win_noblock()

void restore_win_noblock ( switchwin_T switchwin,
bool  no_display 

◆ scroll_to_fraction()

void scroll_to_fraction ( win_T wp,
int  prev_height 

◆ set_fraction()

void set_fraction ( win_T wp)

◆ shell_new_columns()

void shell_new_columns ( void  )

◆ shell_new_rows()

void shell_new_rows ( void  )

◆ switch_buffer()

void switch_buffer ( bufref_T save_curbuf,
buf_T buf 

Make "buf" the current buffer.

restore_buffer() MUST be called to undo. No autocommands will be executed. Use aucmd_prepbuf() if there are any.

◆ switch_win()

int switch_win ( switchwin_T switchwin,
win_T win,
tabpage_T tp,
bool  no_display 

Set "win" to be the curwin and "tp" to be the current tab page. restore_win() MUST be called to undo, also when FAIL is returned. No autocommands will be executed until restore_win() is called.

no_displayif true the display won't be affected, no redraw is triggered, another tabpage access is limited.
FAIL if switching to "win" failed.

◆ switch_win_noblock()

int switch_win_noblock ( switchwin_T switchwin,
win_T win,
tabpage_T tp,
bool  no_display 

◆ tabline_height()

int tabline_height ( void  )

Return the number of lines used by the tab page line.

◆ tabpage_index()

int tabpage_index ( tabpage_T ftp)

◆ tabpage_move()

void tabpage_move ( int  nr)

◆ ui_ext_win_position()

void ui_ext_win_position ( win_T wp)

◆ ui_ext_win_viewport()

void ui_ext_win_viewport ( win_T wp)

◆ valid_tabpage()

bool valid_tabpage ( tabpage_T tpc)

Check that tpc points to a valid tab page.

[in]tpcTabpage to check.

◆ valid_tabpage_win()

int valid_tabpage_win ( tabpage_T tpc)

Returns true when tpc is valid and at least one window is valid.

◆ win_alloc_aucmd_win()

void win_alloc_aucmd_win ( void  )

◆ win_alloc_first()

int win_alloc_first ( void  )

◆ win_append()

void win_append ( win_T after,
win_T wp 

◆ win_check_anchored_floats()

void win_check_anchored_floats ( win_T win)

◆ win_close()

int win_close ( win_T win,
bool  free_buf,
bool  force 

◆ win_close_othertab()

void win_close_othertab ( win_T win,
int  free_buf,
tabpage_T tp 

◆ win_comp_pos()

int win_comp_pos ( void  )

◆ win_comp_scroll()

void win_comp_scroll ( win_T wp)

◆ win_config_float()

void win_config_float ( win_T wp,
FloatConfig  fconfig 

◆ win_count()

int win_count ( void  )

◆ win_drag_status_line()

void win_drag_status_line ( win_T dragwin,
int  offset 

Status line of dragwin is dragged "offset" lines down (negative is up).

◆ win_drag_vsep_line()

void win_drag_vsep_line ( win_T dragwin,
int  offset 

◆ win_enter()

void win_enter ( win_T wp,
bool  undo_sync 

Make window wp the current window.

Autocmds may close the window immediately, so caller must check win_valid(wp).

◆ win_equal()

void win_equal ( win_T next_curwin,
bool  current,
int  dir 

Make all windows the same height. 'next_curwin' will soon be the current window, make sure it has enough rows.

next_curwinpointer to current window to be or NULL
currentdo only frame with current window
dir'v' for vertically, 'h' for horizontally, 'b' for both, 0 for using p_ead

◆ win_fdccol_count()

int win_fdccol_count ( win_T wp)

Return the number of fold columns to display.

◆ win_find_by_handle()

win_T* win_find_by_handle ( handle_T  handle)

◆ win_find_tabpage()

tabpage_T* win_find_tabpage ( win_T win)

◆ win_findbuf()

void win_findbuf ( typval_T argvars,
list_T list 

◆ win_free_grid()

void win_free_grid ( win_T wp,
bool  reinit 

◆ win_get_tabwin()

void win_get_tabwin ( handle_T  id,
int *  tabnr,
int *  winnr 

◆ win_getid()

int win_getid ( typval_T argvars)

◆ win_goto()

void win_goto ( win_T wp)

◆ win_gotoid()

int win_gotoid ( typval_T argvars)

◆ win_horz_neighbor()

win_T* win_horz_neighbor ( tabpage_T tp,
win_T wp,
bool  left,
long  count 

Get the left or right neighbor window of the specified window.

Returns the specified window if the neighbor is not found. Returns the previous window if the specifiecied window is a floating window.

lefttrue for the left neighbor
countnth neighbor window
found window

◆ win_id2tabwin()

void win_id2tabwin ( typval_T *const  argvars,
typval_T *const  rettv 

◆ win_id2win()

int win_id2win ( typval_T argvars)

◆ win_id2wp()

win_T* win_id2wp ( int  id)

◆ win_id2wp_tp()

win_T* win_id2wp_tp ( int  id,
tabpage_T **  tpp 

◆ win_init_empty()

void win_init_empty ( win_T wp)

◆ win_init_size()

void win_init_size ( void  )

◆ win_move_after()

void win_move_after ( win_T win1,
win_T win2 

◆ win_new_float()

win_T* win_new_float ( win_T wp,
bool  last,
FloatConfig  fconfig,
Error err 

Create a new float.

wpif NULL, allocate a new window, otherwise turn existing window into a float. It must then already belong to the current tabpage!
lastmake the window the last one in the window list. Only used when allocating the autocommand window.
configmust already have been validated!

◆ win_new_height()

void win_new_height ( win_T wp,
int  height 

◆ win_new_tabpage()

int win_new_tabpage ( int  after,
char_u filename 

Create a new tabpage with one window.

It will edit the current buffer, like after :split.

afterPut new tabpage after tabpage "after", or after the current tabpage in case of 0.
filenameWill be passed to apply_autocmds().
Was the new tabpage created successfully? FAIL or OK.

◆ win_new_width()

void win_new_width ( win_T wp,
int  width 

Set the width of a window.

◆ win_reconfig_floats()

void win_reconfig_floats ( void  )

◆ win_remove()

void win_remove ( win_T wp,
tabpage_T tp 

Remove a window from the window list.

tptab page "win" is in, NULL for current

◆ win_set_buf()

void win_set_buf ( Window  window,
Buffer  buffer,
bool  noautocmd,
Error err 

◆ win_set_inner_size()

void win_set_inner_size ( win_T wp)

◆ win_set_minimal_style()

void win_set_minimal_style ( win_T wp)

◆ win_setheight()

void win_setheight ( int  height)

◆ win_setheight_win()

void win_setheight_win ( int  height,
win_T win 

◆ win_setminheight()

void win_setminheight ( void  )

◆ win_setminwidth()

void win_setminwidth ( void  )

◆ win_setwidth()

void win_setwidth ( int  width)

◆ win_setwidth_win()

void win_setwidth_win ( int  width,
win_T wp 

◆ win_size_restore()

void win_size_restore ( garray_T gap)

◆ win_size_save()

void win_size_save ( garray_T gap)

◆ win_split()

int win_split ( int  size,
int  flags 

◆ win_split_ins()

int win_split_ins ( int  size,
int  flags,
win_T new_wp,
int  dir 

◆ win_ui_flush()

void win_ui_flush ( void  )

◆ win_valid()

bool win_valid ( const win_T win)

Check if "win" is a pointer to an existing window in the current tabpage.

winwindow to check

◆ win_valid_any_tab()

bool win_valid_any_tab ( win_T win)

Check if "win" is a pointer to an existing window in any tabpage.

winwindow to check

◆ win_valid_floating()

bool win_valid_floating ( const win_T win)

Return true if "win" is floating window in the current tab page.

winwindow to check

◆ win_vert_neighbor()

win_T* win_vert_neighbor ( tabpage_T tp,
win_T wp,
bool  up,
long  count 

Get the above or below neighbor window of the specified window.

Returns the specified window if the neighbor is not found. Returns the previous window if the specifiecied window is a floating window.

uptrue for the above neighbor
countnth neighbor window
found window

◆ winframe_remove()

win_T* winframe_remove ( win_T win,
int *  dirp,
tabpage_T tp 

Remove a window and its frame from the tree of frames.

dirpset to 'v' or 'h' for direction if 'ea'
tptab page "win" is in, NULL for current
a pointer to the window that got the freed up space.
#define _(x)
Definition: gettext.h:20