Data Structures | Macros | Typedefs | Functions | Variables
edit.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/event/loop.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/highlight_group.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/keycodes.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.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/path.h"
#include "nvim/plines.h"
#include "nvim/popupmnu.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  compl_S
struct  insert_state


#define CTRL_X_WANT_IDENT   0x100
#define CTRL_X_NORMAL   0
 CTRL-N CTRL-P completion, default. More...
#define CTRL_X_SCROLL   2
#define CTRL_X_WHOLE_LINE   3
#define CTRL_X_FILES   4
#define CTRL_X_FINISHED   8
#define CTRL_X_CMDLINE   11
#define CTRL_X_FUNCTION   12
#define CTRL_X_OMNI   13
#define CTRL_X_SPELL   14
#define CTRL_X_LOCAL_MSG   15
 only used in "ctrl_x_msgs" More...
#define CTRL_X_EVAL   16
 for builtin function complete() More...
#define CTRL_X_CMDLINE_CTRL_X   17
 CTRL-X typed in CTRL_X_CMDLINE. More...
#define CTRL_X_MSG(i)   ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
#define CTRL_X_MODE_LINE_OR_EVAL(m)   ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)
#define BACKSPACE_CHAR   1
#define BACKSPACE_WORD   2
#define BACKSPACE_LINE   4
#define PC_STATUS_UNSET   0
#define PC_STATUS_RIGHT   1
#define PC_STATUS_LEFT   2
#define PC_STATUS_SET   3
#define FREE_CPTEXT(cptext, cptext_allocated)
#define DICT_FIRST   (1)
#define DICT_EXACT   (2)
#define CI_WHAT_MODE   0x01
#define CI_WHAT_PUM_VISIBLE   0x02
#define CI_WHAT_ITEMS   0x04
#define CI_WHAT_SELECTED   0x08
#define CI_WHAT_INSERTED   0x10
#define CI_WHAT_ALL   0xff
#define MIN_SPACE   75
#define ISSPECIAL(c)   ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
#define WHITECHAR(cc)
#define INPUT_BUFLEN   100


typedef struct compl_S compl_T
typedef struct insert_state InsertState


bool goto_im (void)
bool edit (int cmdchar, bool startln, long count)
void edit_putchar (int c, bool highlight)
char_ubuf_prompt_text (const buf_T *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
 Return the effective prompt for the specified buffer. More...
char_uprompt_text (void)
bool prompt_curpos_editable (void)
void edit_unputchar (void)
void display_dollar (colnr_T col)
void change_indent (int type, int amount, int round, int replaced, int call_changed_bytes)
void truncate_spaces (char_u *line)
void backspace_until_column (int col)
bool ctrl_x_mode_not_default (void)
bool ctrl_x_mode_not_defined_yet (void)
bool vim_is_ctrl_x_key (int c) FUNC_ATTR_WARN_UNUSED_RESULT
int ins_compl_add_infercase (char_u *str_arg, int len, bool icase, char_u *fname, Direction dir, bool cont_s_ipos) FUNC_ATTR_NONNULL_ARG(1)
void completeopt_was_set (void)
void set_completion (colnr_T startcol, list_T *list)
void ins_compl_show_pum (void)
 for (i=0;i< count &&!got_int &&!compl_interrupted;i++)
char_ufind_word_start (char_u *ptr) FUNC_ATTR_PURE
char_ufind_word_end (char_u *ptr) FUNC_ATTR_PURE
bool ins_compl_active (void)
 Check that Insert completion is active. More...
void get_complete_info (list_T *what_list, dict_T *retdict)
int ins_compl_add_tv (typval_T *const tv, const Direction dir, bool fast) FUNC_ATTR_NONNULL_ALL
void pum_ext_select_item (int item, bool insert, bool finish)
void ins_compl_check_keys (int frequency, int in_compl_func)
int get_literal (bool no_simplify)
void insertchar (int c, int flags, int second_indent)
void auto_format (bool trailblank, bool prev_line)
int comp_textwidth (bool ff)
int stop_arrow (void)
void set_last_insert (int c)
char_uadd_char2buf (int c, char_u *s) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
void beginline (int flags)
int oneright (void)
int oneleft (void)
int cursor_up (long n, int upd_topline)
 @oaram upd_topline When TRUE: update topline More...
int cursor_down (long n, int upd_topline)
int stuff_inserted (int c, long count, int no_esc)
char_uget_last_insert (void)
char_uget_last_insert_save (void)
void replace_push (int c)
int replace_push_mb (char_u *p)
void fixthisline (IndentGetter get_the_indent)
void fix_indent (void)
bool in_cinkeys (int keytyped, int when, bool line_is_empty)
int hkmap (int c) FUNC_ATTR_PURE
int ins_copychar (linenr_T lnum)
colnr_T get_nolist_virtcol (void)


struct {
   bool   active
   int   item
   bool   insert
   bool   finish
 state for pum_ext_select_item. More...
static void int i
FILE * fp
int add_r

Macro Definition Documentation


#define BACKSPACE_CHAR   1


#define BACKSPACE_LINE   4


#define BACKSPACE_WORD   2




#define CI_WHAT_ALL   0xff


#define CI_WHAT_INSERTED   0x10


#define CI_WHAT_ITEMS   0x04


#define CI_WHAT_MODE   0x01


#define CI_WHAT_PUM_VISIBLE   0x02


#define CI_WHAT_SELECTED   0x08


#define CTRL_X_CMDLINE   11


#define CTRL_X_CMDLINE_CTRL_X   17





#define CTRL_X_EVAL   16

for builtin function complete()


#define CTRL_X_FILES   4


#define CTRL_X_FINISHED   8


#define CTRL_X_FUNCTION   12


#define CTRL_X_LOCAL_MSG   15

only used in "ctrl_x_msgs"


#define CTRL_X_MODE_LINE_OR_EVAL (   m)    ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)


#define CTRL_X_MSG (   i)    ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]


#define CTRL_X_NORMAL   0

CTRL-N CTRL-P completion, default.




#define CTRL_X_OMNI   13






#define CTRL_X_SCROLL   2


#define CTRL_X_SPELL   14






#define CTRL_X_WANT_IDENT   0x100


#define CTRL_X_WHOLE_LINE   3


#define DICT_EXACT   (2)


#define DICT_FIRST   (1)


#define FREE_CPTEXT (   cptext,
do { \
if (cptext != NULL && cptext_allocated) { \
for (size_t i = 0; i < CPT_COUNT; i++) { \
xfree(cptext[i]); \
} \
} \
} while (0)


#define INPUT_BUFLEN   100


#define ISSPECIAL (   c)    ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')


#define MIN_SPACE   75


#define PC_STATUS_LEFT   2


#define PC_STATUS_RIGHT   1


#define PC_STATUS_SET   3


#define PC_STATUS_UNSET   0


#define WHITECHAR (   cc)
(ascii_iswhite(cc) \

Typedef Documentation

◆ compl_T

typedef struct compl_S compl_T

◆ InsertState

typedef struct insert_state InsertState

Function Documentation

◆ add_char2buf()

char_u* add_char2buf ( int  c,
char_u s 

Add character "c" to buffer "s"

Escapes the special meaning of K_SPECIAL, handles multi-byte characters.

[in]cCharacter to add.
[out]sBuffer to add to. Must have at least MB_MAXBYTES + 1 bytes.
Pointer to after the added bytes.

◆ auto_format()

void auto_format ( bool  trailblank,
bool  prev_line 

Called after inserting or deleting text: When 'formatoptions' includes the 'a' flag format from the current line until the end of the paragraph. Keep the cursor at the same position relative to the text. The caller must have saved the cursor line for undo, following ones will be saved here.

trailblankwhen true also format with trailing blank
prev_linemay start in previous line

◆ backspace_until_column()

void backspace_until_column ( int  col)

Backspace the cursor until the given column. Handles MODE_REPLACE and MODE_VREPLACE modes correctly. May also be used when not in insert mode at all. Will attempt not to go before "col" even when there is a composing character.

◆ beginline()

void beginline ( int  flags)

◆ buf_prompt_text()

char_u* buf_prompt_text ( const buf_T *const  buf)

Return the effective prompt for the specified buffer.

◆ change_indent()

void change_indent ( int  type,
int  amount,
int  round,
int  replaced,
int  call_changed_bytes 

Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D). Keep the cursor on the same character. type == INDENT_INC increase indent (for CTRL-T or <Tab>) type == INDENT_DEC decrease indent (for CTRL-D) type == INDENT_SET set indent to "amount"

roundif TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
replacedreplaced character, put on replace stack
call_changed_bytescall changed_bytes()

◆ comp_textwidth()

int comp_textwidth ( bool  ff)

Find out textwidth to be used for formatting: if 'textwidth' option is set, use it else if 'wrapmargin' option is set, use curwin->w_width_inner-'wrapmargin' if invalid value, use 0. Set default to window width (maximum 79) for "gq" operator.

ffforce formatting (for "gq" command)

◆ completeopt_was_set()

void completeopt_was_set ( void  )

◆ ctrl_x_mode_not_default()

bool ctrl_x_mode_not_default ( void  )

◆ ctrl_x_mode_not_defined_yet()

bool ctrl_x_mode_not_defined_yet ( void  )

◆ cursor_down()

int cursor_down ( long  n,
int  upd_topline 

Cursor down a number of logical lines.

upd_toplineWhen TRUE: update topline

◆ cursor_up()

int cursor_up ( long  n,
int  upd_topline 

@oaram upd_topline When TRUE: update topline

◆ display_dollar()

void display_dollar ( colnr_T  col)

◆ edit()

bool edit ( int  cmdchar,
bool  startln,
long  count 

edit(): Start inserting text.

"cmdchar" can be: 'i' normal insert command 'a' normal append command 'R' replace command 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo, but still only one <CR> is inserted. <Esc> is not used for redo. 'g' "gI" command. 'V' "gR" command for Virtual Replace mode. 'v' "gr" command for single character Virtual Replace mode.

This function is not called recursively. For CTRL-O commands, it returns and lets the caller handle the Normal-mode command.

cmdcharcommand that started the insert
startlnif true, insert at start of line
countrepeat count for the command
true if a CTRL-O command caused the return (insert mode pending).

◆ edit_putchar()

void edit_putchar ( int  c,
bool  highlight 

◆ edit_unputchar()

void edit_unputchar ( void  )

◆ find_word_end()

char_u* find_word_end ( char_u ptr)

◆ find_word_start()

char_u* find_word_start ( char_u ptr)

◆ fix_indent()

void fix_indent ( void  )

◆ fixthisline()

void fixthisline ( IndentGetter  get_the_indent)

◆ for()

for ( )

◆ get_complete_info()

void get_complete_info ( list_T what_list,
dict_T retdict 

◆ get_last_insert()

char_u* get_last_insert ( void  )

◆ get_last_insert_save()

char_u* get_last_insert_save ( void  )

◆ get_literal()

int get_literal ( bool  no_simplify)

Next character is interpreted literally. A one, two or three digit decimal number is interpreted as its byte value. If one or two digits are entered, the next character is given to vungetc(). For Unicode a character > 255 may be returned.

no_simplifydo not include modifiers into the key

◆ get_nolist_virtcol()

colnr_T get_nolist_virtcol ( void  )

◆ goto_im()

bool goto_im ( void  )

Return true when need to go to Insert mode because of 'insertmode'.

Don't do this when still processing a command or a mapping. Don't do this when inside a ":normal" command.

◆ hkmap()

int hkmap ( int  c)

◆ in_cinkeys()

bool in_cinkeys ( int  keytyped,
int  when,
bool  line_is_empty 

Check that "cinkeys" contains the key "keytyped", when == '*': Only if key is preceded with '*' (indent before insert) when == '!': Only if key is preceded with '!' (don't insert) when == ' ': Only if key is not preceded with '*' (indent afterwards)

"keytyped" can have a few special values: KEY_OPEN_FORW : KEY_OPEN_BACK : KEY_COMPLETE : Just finished completion.

keytypedkey that was typed
whencondition on when to perform the check
line_is_emptywhen true, accept keys with '0' before them.

◆ ins_compl_active()

bool ins_compl_active ( void  )

Check that Insert completion is active.

◆ ins_compl_add_infercase()

int ins_compl_add_infercase ( char_u str_arg,
int  len,
bool  icase,
char_u fname,
Direction  dir,
bool  cont_s_ipos 

This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the case of the originally typed text is used, and the case of the completed text is inferred, ie this tries to work out what case you probably wanted the rest of the word to be in – webb

[in]cont_s_iposnext ^X<> will set initial_pos

◆ ins_compl_add_tv()

int ins_compl_add_tv ( typval_T *const  tv,
const Direction  dir,
bool  fast 

Add a match to the list of matches from VimL object

[in]tvObject to get matches from.
[in]dirCompletion direction.
[in]fastuse fast_breakcheck() instead of os_breakcheck().
NOTDONE if the given string is already in the list of completions, otherwise it is added to the list and OK is returned. FAIL will be returned in case of error.

◆ ins_compl_check_keys()

void ins_compl_check_keys ( int  frequency,
int  in_compl_func 

◆ ins_compl_show_pum()

void ins_compl_show_pum ( void  )

Show the popup menu for the list of matches. Also adjusts "compl_shown_match" to an entry that is actually displayed.

◆ ins_copychar()

int ins_copychar ( linenr_T  lnum)

◆ insertchar()

void insertchar ( int  c,
int  flags,
int  second_indent 

"flags": INSCHAR_FORMAT - force formatting INSCHAR_CTRLV - char typed just after CTRL-V INSCHAR_NO_FEX - don't use 'formatexpr'

NOTE: passes the flags value straight through to internal_format() which, beside INSCHAR_FORMAT (above), is also looking for these: INSCHAR_DO_COM - format comments INSCHAR_COM_LIST - format comments with num list or 2nd line indent

ccharacter to insert or NUL
second_indentindent for second line if >= 0

◆ oneleft()

int oneleft ( void  )

◆ oneright()

int oneright ( void  )

◆ prompt_curpos_editable()

bool prompt_curpos_editable ( void  )
true if the cursor is in the editable position of the prompt line.

◆ prompt_text()

char_u* prompt_text ( void  )

◆ pum_ext_select_item()

void pum_ext_select_item ( int  item,
bool  insert,
bool  finish 

◆ replace_push()

void replace_push ( int  c)

Push character that is replaced onto the the replace stack.

replace_offset is normally 0, in which case replace_push will add a new character at the end of the stack. If replace_offset is not 0, that many characters will be left on the stack above the newly inserted character.

ccharacter that is replaced (NUL is none)

◆ replace_push_mb()

int replace_push_mb ( char_u p)

◆ set_completion()

void set_completion ( colnr_T  startcol,
list_T list 

◆ set_last_insert()

void set_last_insert ( int  c)

◆ stop_arrow()

int stop_arrow ( void  )

◆ stuff_inserted()

int stuff_inserted ( int  c,
long  count,
int  no_esc 

Stuff the last inserted text in the read buffer. Last_insert actually is a copy of the redo buffer, so we first have to remove the command.

cCommand character to be inserted
countRepeat this many times
no_escDon't add an ESC at the end

◆ truncate_spaces()

void truncate_spaces ( char_u line)

Truncate the space at the end of a line. This is to be used only in an insert mode. It handles fixing the replace stack for MODE_REPLACE and MODE_VREPLACE modes.

◆ vim_is_ctrl_x_key()

bool vim_is_ctrl_x_key ( int  c)

Check that the character "c" a valid key to go to or keep us in CTRL-X mode? This depends on the current mode.

ccharacter to check

Variable Documentation

◆ active

bool active

◆ add_r

int add_r

◆ finish

bool finish

◆ fp

FILE* fp

◆ i

void int i
Initial value:

◆ insert

bool insert

◆ item

int item

◆ pum_want

struct { ... } pum_want

state for pum_ext_select_item.

char_u * get_cursor_pos_ptr(void)
Definition: cursor.c:498
char_u * ptr
Definition: normal.c:2330
static void int i
Definition: edit.c:3047
bool utf_iscomposing(int c)
Definition: mbyte.c:1053
#define CPT_COUNT
Definition: edit.h:13
int utf_ptr2char(const char *const p_in) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
Definition: mbyte.c:605
unsigned char char_u
Definition: types.h:12
return NULL
Definition: eval.c:9968