Data Structures | Macros | Functions | Variables
ops.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/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/macros.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/screen.h"
#include "nvim/search.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  block_def


#define OPF_LINES   1
#define OPF_CHANGE   2
#define MSG_NO_CLIP


int get_op_type (int char1, int char2)
int op_on_lines (int op)
int op_is_change (int op)
int get_op_char (int optype)
int get_extra_op_char (int optype)
void op_shift (oparg_T *oap, int curs_top, int amount)
void shift_line (int left, int round, int amount, int call_changed_bytes)
void op_reindent (oparg_T *oap, Indenter how)
int get_expr_register (void)
void set_expr_line (char_u *new_line)
char_uget_expr_line (void)
char_uget_expr_line_src (void)
bool valid_yank_reg (int regname, bool writing)
yankreg_Tget_yank_register (int regname, int mode)
yankreg_Tcopy_register (int name) FUNC_ATTR_NONNULL_RET
bool yank_register_mline (int regname)
 check if the current yank register has kMTLineWise register type More...
int do_record (int c)
int do_execreg (int regname, int colon, int addcr, int silent)
int insert_reg (int regname, bool literally_arg)
bool get_spec_reg (int regname, char_u **argp, bool *allocated, bool errmsg)
bool cmdline_paste_reg (int regname, bool literally_arg, bool remcr)
int op_delete (oparg_T *oap)
void op_tilde (oparg_T *oap)
bool swapchar (int op_type, pos_T *pos) FUNC_ATTR_NONNULL_ARG(2)
void op_insert (oparg_T *oap, long count1)
int op_change (oparg_T *oap)
void init_yank (void)
void free_register (yankreg_T *reg) FUNC_ATTR_NONNULL_ALL
bool op_yank (oparg_T *oap, bool message, int deleting) FUNC_ATTR_NONNULL_ALL
void do_put (int regname, yankreg_T *reg, int dir, long count, int flags)
void adjust_cursor_eol (void)
int preprocs_left (void)
int get_register_name (int num)
int get_unname_register (void)
void ex_display (exarg_T *eap)
char_uskip_comment (char_u *line, bool process, bool include_space, bool *is_comment)
int do_join (size_t count, int insert_space, int save_undo, int use_formatoptions, bool setmark)
int fex_format (linenr_T lnum, long count, int c)
void format_lines (linenr_T line_count, int avoid_fex)
int paragraph_start (linenr_T lnum)
void op_addsub (oparg_T *oap, linenr_T Prenum1, bool g_cmd)
int do_addsub (int op_type, pos_T *pos, int length, linenr_T Prenum1)
MotionType get_reg_type (int regname, colnr_T *reg_width)
void format_reg_type (MotionType reg_type, colnr_T reg_width, char *buf, size_t buf_len) FUNC_ATTR_NONNULL_ALL
voidget_reg_contents (int regname, int flags)
void write_reg_contents (int name, const char_u *str, ssize_t len, int must_append)
void write_reg_contents_lst (int name, char_u **strings, bool must_append, MotionType yank_type, colnr_T block_len)
void write_reg_contents_ex (int name, const char_u *str, ssize_t len, bool must_append, MotionType yank_type, colnr_T block_len)
void clear_oparg (oparg_T *oap)
void cursor_pos_info (dict_T *dict)
void do_pending_operator (cmdarg_T *cap, int old_col, bool gui_yank)
int get_default_register_name (void)
bool prepare_yankreg_from_object (yankreg_T *reg, String regtype, size_t lines)
void finish_yankreg_from_object (yankreg_T *reg, bool clipboard_adjust)
void start_batch_changes (void)
 Avoid slow things (clipboard) during batch operations (while/for-loops). More...
void end_batch_changes (void)
 Counterpart to start_batch_changes(). More...
int save_batch_count (void)
void restore_batch_count (int save_count)
const voidop_global_reg_iter (const void *const iter, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(2
const voidop_reg_iter (const void *const iter, const yankreg_T *const regs, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(3
 while (iter_reg - &(regs[0])< NUM_SAVED_REGISTERS &&reg_empty(iter_reg))
 if (iter_reg - &(regs[0])==NUM_SAVED_REGISTERS||reg_empty(iter_reg))
size_t op_reg_amount (void)
 Get a number of non-empty registers. More...
bool op_reg_set (const char name, const yankreg_T reg, bool is_unnamed)
const yankreg_Top_reg_get (const char name)
bool op_reg_set_previous (const char name) FUNC_ATTR_WARN_UNUSED_RESULT
bcount_t get_region_bytecount (buf_T *buf, linenr_T start_lnum, linenr_T end_lnum, colnr_T start_col, colnr_T end_col)


const yankreg_Titer_reg
int iter_off = (int)(iter_reg - &(regs[0]))
name = (char)get_register_name(iter_off)
reg = *iter_reg
is_unnamed = (iter_reg == y_previous)
return NULL

Macro Definition Documentation


#define MSG_NO_CLIP
"clipboard: No provider. " \
"Try \":checkhealth\" or \":h clipboard\"."


#define OPF_CHANGE   2


#define OPF_LINES   1

Function Documentation

◆ adjust_cursor_eol()

void adjust_cursor_eol ( void  )

◆ clear_oparg()

void clear_oparg ( oparg_T oap)

◆ cmdline_paste_reg()

bool cmdline_paste_reg ( int  regname,
bool  literally_arg,
bool  remcr 

Paste a yank register into the command line. Only for non-special registers. Used by CTRL-R in command-line mode. insert_reg() can't be used here, because special characters from the register contents will be interpreted as commands.

regnameRegister name.
literally_argInsert text literally instead of "as typed".
remcrWhen true, don't add CR characters.
FAIL for failure, OK otherwise

◆ copy_register()

yankreg_T* copy_register ( int  name)

Returns a copy of contents in register name for use in do_put. Should be freed by caller.

◆ cursor_pos_info()

void cursor_pos_info ( dict_T dict)

Give some info about the position of the cursor (for "g CTRL-G"). In Visual mode, give some info about the selected region. (In this case, the *_count_cursor variables store running totals for the selection.) When "dict" is not NULL store the info there instead of showing it.

◆ do_addsub()

int do_addsub ( int  op_type,
pos_T pos,
int  length,
linenr_T  Prenum1 

Add or subtract from a number in a line.

op_typeOP_NR_ADD or OP_NR_SUB.
posCursor position.
lengthTarget number length.
Prenum1Amount of addition or subtraction.
true if some character was changed.

◆ do_execreg()

int do_execreg ( int  regname,
int  colon,
int  addcr,
int  silent 

Execute a yank register: copy it into the stuff buffer

coloninsert ':' before each line
addcralways add '
' to end of line
silentset "silent" flag in typeahead buffer
FAIL for failure, OK otherwise

◆ do_join()

int do_join ( size_t  count,
int  insert_space,
int  save_undo,
int  use_formatoptions,
bool  setmark 

◆ do_pending_operator()

void do_pending_operator ( cmdarg_T cap,
int  old_col,
bool  gui_yank 

◆ do_put()

void do_put ( int  regname,
yankreg_T reg,
int  dir,
long  count,
int  flags 

◆ do_record()

int do_record ( int  c)

◆ end_batch_changes()

void end_batch_changes ( void  )

Counterpart to start_batch_changes().

◆ ex_display()

void ex_display ( exarg_T eap)

◆ fex_format()

int fex_format ( linenr_T  lnum,
long  count,
int  c 
ccharacter to be inserted

◆ finish_yankreg_from_object()

void finish_yankreg_from_object ( yankreg_T reg,
bool  clipboard_adjust 

◆ format_lines()

void format_lines ( linenr_T  line_count,
int  avoid_fex 

Format "line_count" lines, starting at the cursor position. When "line_count" is negative, format until the end of the paragraph. Lines after the cursor line are saved for undo, caller must have saved the first line.

avoid_fexdon't use 'formatexpr'

◆ format_reg_type()

void format_reg_type ( MotionType  reg_type,
colnr_T  reg_width,
char *  buf,
size_t  buf_len 

Format the register type as a string.

reg_typeThe register type.
reg_widthThe width, only used if "reg_type" is kMTBlockWise.
[out]bufBuffer to store formatted string. The allocated size should be at least NUMBUFLEN+2 to always fit the value.
buf_lenThe allocated size of the buffer.

◆ free_register()

void free_register ( yankreg_T reg)

Free contents of yankreg reg. Called for normal freeing and in case of error. reg must not be NULL (but reg->y_array might be)

◆ get_default_register_name()

int get_default_register_name ( void  )

Check if the default register (used in an unnamed paste) should be a clipboard register. This happens when clipboard=unnamed[plus] is set and a provider is available.

the name of of a clipboard register that should be used, or NUL if none.

◆ get_expr_line()

char_u* get_expr_line ( void  )

◆ get_expr_line_src()

char_u* get_expr_line_src ( void  )

◆ get_expr_register()

int get_expr_register ( void  )

◆ get_extra_op_char()

int get_extra_op_char ( int  optype)

◆ get_op_char()

int get_op_char ( int  optype)

◆ get_op_type()

int get_op_type ( int  char1,
int  char2 

◆ get_reg_contents()

void* get_reg_contents ( int  regname,
int  flags 

Gets the contents of a register.

Used for @r in expressions and for getreg().
regnameThe register.
flagssee GRegFlags
The contents of the register as an allocated string.
A linked list when flags contains kGRegList.
NULL for error.

◆ get_reg_type()

MotionType get_reg_type ( int  regname,
colnr_T reg_width 

◆ get_region_bytecount()

bcount_t get_region_bytecount ( buf_T buf,
linenr_T  start_lnum,
linenr_T  end_lnum,
colnr_T  start_col,
colnr_T  end_col 

Get the byte count of buffer region. End-exclusive.

number of bytes

◆ get_register_name()

int get_register_name ( int  num)

◆ get_spec_reg()

bool get_spec_reg ( int  regname,
char_u **  argp,
bool allocated,
bool  errmsg 

If "regname" is a special register, return true and store a pointer to its value in "argp".

allocatedreturn: true when value was allocated
errmsggive error message when failing
true if "regname" is a special register,

◆ get_unname_register()

int get_unname_register ( void  )
the index of the register "" points to.

◆ get_yank_register()

yankreg_T* get_yank_register ( int  regname,
int  mode 

Return yankreg_T to use, according to the value of regname. Cannot handle the '_' (black hole) register. Must only be called with a valid register name!

regnameThe name of the register used or 0 for the unnamed register
modeOne of the following three flags:

YREG_PASTE: Prepare for pasting the register regname. With no regname specified, read from last written register, or from unnamed clipboard (depending on the clipboard=unnamed option). Queries the clipboard provider if necessary.

YREG_YANK: Preparare for yanking into regname. With no regname specified, yank into "0 register. Update y_previous for next unnamed paste.

YREG_PUT: Obtain the location that would be read when pasting regname.

◆ if()

if ( iter_reg - &  regs[0] = NUM_SAVED_REGISTERS || reg_empty(iter_reg))

◆ init_yank()

void init_yank ( void  )

◆ insert_reg()

int insert_reg ( int  regname,
bool  literally_arg 

Insert a yank register: copy it into the Read buffer. Used by CTRL-R command and middle mouse button in insert mode.

literally_arginsert literally, not as if typed
FAIL for failure, OK otherwise

◆ op_addsub()

void op_addsub ( oparg_T oap,
linenr_T  Prenum1,
bool  g_cmd 

Handle the add/subtract operator.

[in]oapArguments of operator.
[in]Prenum1Amount of addition or subtraction.
[in]g_cmdPrefixed with g.

◆ op_change()

int op_change ( oparg_T oap)

◆ op_delete()

int op_delete ( oparg_T oap)

◆ op_global_reg_iter()

const void* op_global_reg_iter ( const void *const  iter,
char *const  name,
yankreg_T *const  reg,
bool is_unnamed 

Iterate over global registers.

See also

◆ op_insert()

void op_insert ( oparg_T oap,
long  count1 

◆ op_is_change()

int op_is_change ( int  op)

◆ op_on_lines()

int op_on_lines ( int  op)

◆ op_reg_amount()

size_t op_reg_amount ( void  )

Get a number of non-empty registers.

◆ op_reg_get()

const yankreg_T* op_reg_get ( const char  name)

Get register with the given name

[in]nameRegister name.
Pointer to the register contents or NULL.

◆ op_reg_iter()

const void* op_reg_iter ( const void *const  iter,
const yankreg_T *const  regs,
char *const  name,
yankreg_T *const  reg,
bool is_unnamed 

Iterate over registers regs.

[in]iterIterator. Pass NULL to start iteration.
[in]regsRegisters list to be iterated.
[out]nameRegister name.
[out]regRegister contents.
Pointer that must be passed to next op_register_iter call or NULL if iteration is over.

◆ op_reg_set()

bool op_reg_set ( const char  name,
const yankreg_T  reg,
bool  is_unnamed 

Set register to a given value

[in]nameRegister name.
[in]regRegister value.
[in]is_unnamedWhether to set the unnamed regiseter to reg
true on success, false on failure.

◆ op_reg_set_previous()

bool op_reg_set_previous ( const char  name)

Set the previous yank register

[in]nameRegister name.
true on success, false on failure.

◆ op_reindent()

void op_reindent ( oparg_T oap,
Indenter  how 

◆ op_shift()

void op_shift ( oparg_T oap,
int  curs_top,
int  amount 

◆ op_tilde()

void op_tilde ( oparg_T oap)

◆ op_yank()

bool op_yank ( oparg_T oap,
bool  message,
int  deleting 

Yanks the text between "oap->start" and "oap->end" into a yank register. If we are to append (uppercase register), we first yank into a new yank register and then concatenate the old and the new one.

oapoperator arguments
messageshow message when more than &report lines are yanked.
deletingwhether the function was called from a delete operation.
whether the operation register was writable.

◆ paragraph_start()

int paragraph_start ( linenr_T  lnum)

◆ prepare_yankreg_from_object()

bool prepare_yankreg_from_object ( yankreg_T reg,
String  regtype,
size_t  lines 
[out]regExpected to be empty

◆ preprocs_left()

int preprocs_left ( void  )

◆ restore_batch_count()

void restore_batch_count ( int  save_count)

◆ save_batch_count()

int save_batch_count ( void  )

◆ set_expr_line()

void set_expr_line ( char_u new_line)

◆ shift_line()

void shift_line ( int  left,
int  round,
int  amount,
int  call_changed_bytes 

Shift the current line one shiftwidth left (if left != 0) or right leaves cursor on first blank in the line.

call_changed_bytescall changed_bytes()

◆ skip_comment()

char_u* skip_comment ( char_u line,
bool  process,
bool  include_space,
bool is_comment 

If "process" is true and the line begins with a comment leader (possibly after some white space), return a pointer to the text after it. Put a boolean value indicating whether the line ends with an unclosed comment in "is_comment".

line- line to be processed
process- if false, will only check whether the line ends with an unclosed comment,
include_space- whether to skip space following the comment leader
[out]is_comment- whether the current line ends with an unclosed comment.

◆ start_batch_changes()

void start_batch_changes ( void  )

Avoid slow things (clipboard) during batch operations (while/for-loops).

◆ swapchar()

bool swapchar ( int  op_type,
pos_T pos 

◆ valid_yank_reg()

bool valid_yank_reg ( int  regname,
bool  writing 

Returns whether regname is a valid name of a yank register. Note: There is no check for 0 (default register), caller should do this. The black hole register '_' is regarded as valid.

regnamename of register
writingallow only writable registers

◆ while()

while ( )

◆ write_reg_contents()

void write_reg_contents ( int  name,
const char_u str,
ssize_t  len,
int  must_append 

write_reg_contents - store str in register name

See also

◆ write_reg_contents_ex()

void write_reg_contents_ex ( int  name,
const char_u str,
ssize_t  len,
bool  must_append,
MotionType  yank_type,
colnr_T  block_len 

write_reg_contents_ex - store str in register name

If str ends in '
' or '\r', use linewise, otherwise use charwise.

when name is '/', len and must_append are ignored. This means that str MUST be NUL-terminated.
nameThe name of the register
strThe contents to write
lenIf >= 0, write len bytes of str. Otherwise, write strlen(str) bytes. If len is larger than the allocated size of src, the behaviour is undefined.
must_appendIf true, append the contents of str to the current contents of the register. Note that regardless of must_append, this function will append when name is an uppercase letter.
yank_typeThe motion type (kMTUnknown to auto detect)
block_lenwidth of visual block

◆ write_reg_contents_lst()

void write_reg_contents_lst ( int  name,
char_u **  strings,
bool  must_append,
MotionType  yank_type,
colnr_T  block_len 

◆ yank_register_mline()

bool yank_register_mline ( int  regname)

check if the current yank register has kMTLineWise register type

Variable Documentation


Initial value:
return op_reg_iter(iter, y_regs, name, reg, is_unnamed)

◆ is_unnamed

* is_unnamed = (iter_reg == y_previous)

◆ iter_off

int iter_off = (int)(iter_reg - &(regs[0]))

◆ iter_reg

const yankreg_T* iter_reg
Initial value:
= (iter == NULL
? &(regs[0])
: (const yankreg_T *const)iter)

◆ name

* name = (char)get_register_name(iter_off)


return NULL

◆ reg

* reg = *iter_reg
Definition of one register.
Definition: ops.h:84
* is_unnamed
Definition: ops.c:7158
return NULL
Definition: ops.c:7164
* name
Definition: ops.c:7156
const void * op_reg_iter(const void *const iter, const yankreg_T *const regs, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(3
* reg
Definition: ops.c:7157