Data Structures | Macros | Typedefs | Functions | Variables
normal.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
#include "nvim/eval/userfunc.h"
#include "nvim/event/loop.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/grid_defs.h"
#include "nvim/indent.h"
#include "nvim/keycodes.h"
#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/mapping.h"
#include "nvim/mark.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/ops.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/plines.h"
#include "nvim/quickfix.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/spellfile.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  normal_state
struct  nv_cmd


#define NV_NCH   0x01
#define NV_NCH_NOP   (0x02|NV_NCH)
#define NV_NCH_ALW   (0x04|NV_NCH)
#define NV_LANG   0x08
#define NV_SS   0x10
#define NV_SSS   0x20
#define NV_STS   0x40
#define NV_RL   0x80
#define NV_KEEPREG   0x100
#define NV_NCW   0x200
#define NV_CMDS_SIZE   ARRAY_SIZE(nv_cmds)
#define SHOWCMD_BUFLEN   (SHOWCMD_COLS + 1 + 30)


typedef struct normal_state NormalState
typedef void(* nv_func_T) (cmdarg_T *cap)


void init_normal_cmds (void)
 Initialize the nv_cmd_idx[] table. More...
void normal_enter (bool cmdwin, bool noexmode)
bool do_mouse (oparg_T *oap, int c, int dir, long count, bool fixindent)
void end_visual_mode (void)
void reset_VIsual_and_resel (void)
 Reset VIsual_active and VIsual_reselect. More...
void reset_VIsual (void)
 Reset VIsual_active and VIsual_reselect if it's set. More...
void restore_visual_mode (void)
size_t find_ident_under_cursor (char_u **text, int find_type) FUNC_ATTR_NONNULL_ARG(1)
size_t find_ident_at_pos (win_T *wp, linenr_T lnum, colnr_T startcol, char_u **text, int *textcol, int find_type) FUNC_ATTR_NONNULL_ARG(1
 for (i=(find_type &FIND_IDENT) ? 0 :1;i< 2;i++)
 if (ptr[col]==NUL||(i==0 &&this_class !=2))
 if (textcol !=NULL)
 while (ptr[col] !=NUL &&((i==0 ? mb_get_class(ptr+col)==this_class :mb_get_class(ptr+col) !=0)||((find_type &FIND_EVAL) &&col<=(int) startcol &&find_is_eval_item(ptr+col, &col, &bn, FORWARD))))
 assert (col >=0)
 return (size_t)
 Prepare for redo of a normal command. More...
void prep_redo (int regname, long num, int cmd1, int cmd2, int cmd3, int cmd4, int cmd5)
void clearop (oparg_T *oap)
void clearopbeep (oparg_T *oap)
void may_clear_cmdline (void)
void clear_showcmd (void)
bool add_to_showcmd (int c)
void add_to_showcmd_c (int c)
void push_showcmd (void)
void pop_showcmd (void)
void do_check_scrollbind (bool check)
void check_scrollbind (linenr_T topline_diff, long leftcol_diff)
bool find_decl (char_u *ptr, size_t len, bool locally, bool thisblock, int flags_arg)
void scroll_redraw (int up, long count)
 Scroll "count" lines up or down, and redraw. More...
void do_nv_ident (int c1, int c2)
 Call nv_ident() as if "c1" was used, with "c2" as next character. More...
bool get_visual_text (cmdarg_T *cap, char_u **pp, size_t *lenp)
void start_selection (void)
 Start selection for Shift-movement keys. More...
void may_start_select (int c)
bool unadjust_for_sel (void)
void set_cursor_for_append_to_line (void)
 Move the cursor for the "A" command. More...
void normal_cmd (oparg_T *oap, bool toplevel)


size_t int i
int this_class = 0
int prev_class
int prevcol
int bn = 0
char_uptr = ml_get_buf(wp->w_buffer, lnum, false)
text = ptr
 startcol = col
 col = 0

Macro Definition Documentation


#define NV_CMDS_SIZE   ARRAY_SIZE(nv_cmds)


#define NV_KEEPREG   0x100


#define NV_LANG   0x08


#define NV_NCH   0x01


#define NV_NCH_ALW   (0x04|NV_NCH)


#define NV_NCH_NOP   (0x02|NV_NCH)


#define NV_NCW   0x200


#define NV_RL   0x80


#define NV_SS   0x10


#define NV_SSS   0x20


#define NV_STS   0x40


#define SHOWCMD_BUFLEN   (SHOWCMD_COLS + 1 + 30)

Typedef Documentation

◆ NormalState

typedef struct normal_state NormalState

◆ nv_func_T

typedef void(* nv_func_T) (cmdarg_T *cap)

Function to be called for a Normal or Visual mode command. The argument is a cmdarg_T.

Function Documentation

◆ add_to_showcmd()

bool add_to_showcmd ( int  c)

Add 'c' to string of shown command chars.

true if output has been written (and setcursor() has been called).

◆ add_to_showcmd_c()

void add_to_showcmd_c ( int  c)

◆ assert()

assert ( col >=  0)

◆ check_scrollbind()

void check_scrollbind ( linenr_T  topline_diff,
long  leftcol_diff 

Synchronize any windows that have "scrollbind" set, based on the number of rows by which the current window has changed (1998-11-02 16:21:01 R. Edward Ralston erals[email protected][email protected][email protected]compu[email protected]ter.[email protected]org)

◆ clear_showcmd()

void clear_showcmd ( void  )

◆ clearop()

void clearop ( oparg_T oap)

◆ clearopbeep()

void clearopbeep ( oparg_T oap)

◆ do_check_scrollbind()

void do_check_scrollbind ( bool  check)

When "check" is false, prepare for commands that scroll the window. When "check" is true, take care of scroll-binding after the window has scrolled. Called from normal_cmd() and edit().

◆ do_mouse()

bool do_mouse ( oparg_T oap,
int  c,
int  dir,
long  count,
bool  fixindent 

Do the appropriate action for the current mouse click in the current mode. Not used for Command-line mode.

Normal Mode: event modi- position visual change action fier cursor window left press - yes end yes left press C yes end yes "^]" (2) left press S yes end yes "*" (2) left drag - yes start if moved no left relse - yes start if moved no middle press - yes if not active no put register middle press - yes if active no yank and put right press - yes start or extend yes right press S yes no change yes "#" (2) right drag - yes extend no right relse - yes extend no

Insert or Replace Mode: event modi- position visual change action fier cursor window left press - yes (cannot be active) yes left press C yes (cannot be active) yes "CTRL-O^]" (2) left press S yes (cannot be active) yes "CTRL-O*" (2) left drag - yes start or extend (1) no CTRL-O (1) left relse - yes start or extend (1) no CTRL-O (1) middle press - no (cannot be active) no put register right press - yes start or extend yes CTRL-O right press S yes (cannot be active) yes "CTRL-O#" (2)

(1) only if mouse pointer moved since press (2) only if click is in same buffer

oapoperator argument, can be NULL
dirDirection to 'put' if necessary
fixindentPUT_FIXINDENT if fixing indent necessary
true if start_arrow() should be called for edit mode.

◆ do_nv_ident()

void do_nv_ident ( int  c1,
int  c2 

Call nv_ident() as if "c1" was used, with "c2" as next character.

◆ end_visual_mode()

void end_visual_mode ( void  )

End Visual mode. This function should ALWAYS be called to end Visual mode, except from do_pending_operator().

◆ find_decl()

bool find_decl ( char_u ptr,
size_t  len,
bool  locally,
bool  thisblock,
int  flags_arg 

Search for variable declaration of "ptr[len]". When "locally" is true in the current function ("gd"), otherwise in the current file ("gD").

thisblockwhen true check the {} block scope.
flags_argflags passed to searchit()
fail when not found.

◆ find_ident_at_pos()

size_t find_ident_at_pos ( win_T wp,
linenr_T  lnum,
colnr_T  startcol,
char_u **  text,
int *  textcol,
int  find_type 

Like find_ident_under_cursor(), but for any window and any position. However: Uses 'iskeyword' from the current window!.

textcolcolumn where "text" starts, can be NULL

◆ find_ident_under_cursor()

size_t find_ident_under_cursor ( char_u **  text,
int  find_type 

Find the identifier under or to the right of the cursor. "find_type" can have one of three values: FIND_IDENT: find an identifier (keyword) FIND_STRING: find any non-white text FIND_IDENT + FIND_STRING: find any non-white text, identifier preferred. FIND_EVAL: find text useful for C program debugging

There are three steps:

  1. Search forward for the start of an identifier/text. Doesn't move if already on one.
  2. Search backward for the start of this identifier/text. This doesn't match the real Vi but I like it a little better and it shouldn't bother anyone.
  3. Search forward to the end of this identifier/text. When FIND_IDENT isn't defined, we backup until a blank.
the length of the text, or zero if no text is found.

If text is found, a pointer to the text is put in "*text". This points into the current buffer line and is not always NUL terminated.

◆ for()

for ( )

◆ get_visual_text()

bool get_visual_text ( cmdarg_T cap,
char_u **  pp,
size_t *  lenp 

Get visually selected text, within one line only.

ppreturn: start of selected text
lenpreturn: length of selected text
false if more than one line selected.

◆ if() [1/2]

if ( ptr  [col] = NUL || (i == 0 && this_class != 2))

◆ if() [2/2]

if ( textcol !  = NULL)

◆ init_normal_cmds()

void init_normal_cmds ( void  )

Initialize the nv_cmd_idx[] table.

◆ may_clear_cmdline()

void may_clear_cmdline ( void  )

If the mode is currently displayed clear the command line or update the command displayed.

◆ may_start_select()

void may_start_select ( int  c)

Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. When "c" is 'o' (checking for "mouse") then also when mapped.

◆ normal_cmd()

void normal_cmd ( oparg_T oap,
bool  toplevel 

◆ normal_enter()

void normal_enter ( bool  cmdwin,
bool  noexmode 

Normal state entry point. This is called on:

  • Startup, In this case the function never returns.
  • The command-line window is opened(q:). Returns when cmdwin_result != 0.
  • The :visual command is called from :global in ex mode, :global/PAT/visual for example. Returns when re-entering ex mode(because ex mode recursion is not allowed)

This used to be called main_loop on main.c

◆ pop_showcmd()

void pop_showcmd ( void  )

◆ prep_redo()

void prep_redo ( int  regname,
long  num,
int  cmd1,
int  cmd2,
int  cmd3,
int  cmd4,
int  cmd5 

Prepare for redo of any command. Note that only the last argument can be a multi-byte char.

◆ push_showcmd()

void push_showcmd ( void  )

push_showcmd() and pop_showcmd() are used when waiting for the user to type something and there is a partial mapping.

◆ reset_VIsual()

void reset_VIsual ( void  )

Reset VIsual_active and VIsual_reselect if it's set.

◆ reset_VIsual_and_resel()

void reset_VIsual_and_resel ( void  )

Reset VIsual_active and VIsual_reselect.

◆ restore_visual_mode()

void restore_visual_mode ( void  )

◆ return()

return ( size_t  )

Prepare for redo of a normal command.

◆ scroll_redraw()

void scroll_redraw ( int  up,
long  count 

Scroll "count" lines up or down, and redraw.

◆ set_cursor_for_append_to_line()

void set_cursor_for_append_to_line ( void  )

Move the cursor for the "A" command.

◆ start_selection()

void start_selection ( void  )

Start selection for Shift-movement keys.

◆ unadjust_for_sel()

bool unadjust_for_sel ( void  )

Exclude last character at end of Visual area for 'selection' == "exclusive". Should check VIsual_mode before calling this.

true when backed up to the previous line.

◆ while()

while ( ptr [col] = NUL && ((i == 0              ? mb_get_class(ptr + col) == this_class              : mb_get_class(ptr + col) != 0)             || ((find_type & FIND_EVAL)                 && col <= (int)startcol                 && find_is_eval_item(ptr + col, &col, &bnFORWARD))))

Variable Documentation

◆ bn

bn = 0

◆ col

col = 0

◆ i

size_t int i
Initial value:
int col = 0

◆ prev_class

int prev_class

◆ prevcol

int prevcol

◆ ptr

ptr = ml_get_buf(wp->w_buffer, lnum, false)

◆ startcol

startcol = col

◆ text

* text = ptr

◆ this_class

this_class = 0
Definition: normal.c:2426