Data Structures | Macros | Enumerations | Functions
ex_cmds.c File Reference
#include <assert.h>
#include <float.h>
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "nvim/api/buffer.h"
#include "nvim/api/extmark.h"
#include "nvim/api/private/defs.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/decoration.h"
#include "nvim/diff.h"
#include "nvim/digraph.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/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/highlight.h"
#include "nvim/indent.h"
#include "nvim/log.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/misc1.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/os.h"
#include "nvim/os/shell.h"
#include "nvim/os/time.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/spell.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  subflags_T
 Flags kept between calls to :substitute. More...
 
struct  SubResult
 
struct  PreviewLines
 
struct  sorti_T
 Struct to store info to be sorted. More...
 

Macros

#define SPACE_FOR_DESC   (1 + 1 + 1 + MB_MAXBYTES + 16 + 4 + 3 + 3 + 1)
 
#define ADJUST_SUB_FIRSTLNUM()
 
#define PUSH_PREVIEW_LINES()
 

Enumerations

enum  SubIgnoreType { kSubHonorOptions = 0, kSubIgnoreCase, kSubMatchCase }
 Case matching style to use for :substitute. More...
 

Functions

void do_ascii (const exarg_T *const eap)
 ":ascii" and "ga" implementation More...
 
void ex_align (exarg_T *eap)
 
void ex_sort (exarg_T *eap)
 
void ex_retab (exarg_T *eap)
 
int do_move (linenr_T line1, linenr_T line2, linenr_T dest)
 
void ex_copy (linenr_T line1, linenr_T line2, linenr_T n)
 
void do_bang (int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out) FUNC_ATTR_NONNULL_ALL
 
void do_shell (char_u *cmd, int flags)
 
char_umake_filter_cmd (char_u *cmd, char_u *itmp, char_u *otmp)
 
void append_redir (char *const buf, const size_t buflen, const char *const opt, const char *const fname)
 
void print_line_no_prefix (linenr_T lnum, int use_number, int list)
 
void print_line (linenr_T lnum, int use_number, int list)
 
int rename_buffer (char_u *new_fname)
 
void ex_file (exarg_T *eap)
 
void ex_update (exarg_T *eap)
 
void ex_write (exarg_T *eap)
 
int do_write (exarg_T *eap)
 
int check_overwrite (exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int other)
 
void ex_wnext (exarg_T *eap)
 
void do_wqall (exarg_T *eap)
 
int not_writing (void)
 
int getfile (int fnum, char_u *ffname_arg, char_u *sfname_arg, int setpm, linenr_T lnum, int forceit)
 
int do_ecmd (int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T newlnum, int flags, win_T *oldwin)
 
void ex_append (exarg_T *eap)
 
void ex_change (exarg_T *eap)
 
void ex_z (exarg_T *eap)
 
int check_secure (void)
 
void sub_get_replacement (SubReplacementString *const ret_sub) FUNC_ATTR_NONNULL_ALL
 
void sub_set_replacement (SubReplacementString sub)
 
bool do_sub_msg (bool count_only)
 
void ex_global (exarg_T *eap)
 
void global_exe (char_u *cmd)
 Execute cmd on lines marked with ml_setmarked(). More...
 
bool prepare_tagpreview (bool undo_sync)
 
void ex_help (exarg_T *eap)
 
char_ucheck_help_lang (char_u *arg)
 
int help_heuristic (char_u *matched_string, int offset, int wrong_case)
 
int find_help_tags (const char_u *arg, int *num_matches, char_u ***matches, bool keep_lang)
 
void fix_help_buffer (void)
 
void ex_exusage (exarg_T *eap)
 
void ex_viusage (exarg_T *eap)
 
void ex_helptags (exarg_T *eap)
 
void ex_helpclose (exarg_T *eap)
 
int sub_preview_win (buf_T *preview_buf)
 
void close_preview_windows (void)
 Closes any open windows for inccommand preview buffer. More...
 
void ex_substitute (exarg_T *eap)
 
char_uskip_vimgrep_pat (char_u *p, char_u **s, int *flags)
 
void ex_oldfiles (exarg_T *eap)
 List v:oldfiles in a nice way. More...
 

Macro Definition Documentation

◆ ADJUST_SUB_FIRSTLNUM

#define ADJUST_SUB_FIRSTLNUM ( )
Value:
do { \
/* For a multi-line match, make a copy of the last matched */ \
/* line and continue in that one. */ \
if (nmatch > 1) { \
sub_firstlnum += nmatch - 1; \
xfree(sub_firstline); \
sub_firstline = vim_strsave(ml_get(sub_firstlnum)); \
/* When going beyond the last line, stop substituting. */ \
if (sub_firstlnum <= line2) { \
do_again = true; \
} else { \
subflags.do_all = false; \
} \
} \
if (skip_match) { \
/* Already hit end of the buffer, sub_firstlnum is one */ \
/* less than what it ought to be. */ \
xfree(sub_firstline); \
sub_firstline = vim_strsave((char_u *)""); \
copycol = 0; \
} \
} while (0)

◆ PUSH_PREVIEW_LINES

#define PUSH_PREVIEW_LINES ( )
Value:
do { \
linenr_T match_lines = current_match.end.lnum \
- current_match.start.lnum +1; \
if (preview_lines.subresults.size > 0) { \
linenr_T last = kv_last(preview_lines.subresults).end.lnum; \
if (last == current_match.start.lnum) { \
preview_lines.lines_needed += match_lines - 1; \
} \
} else { \
preview_lines.lines_needed += match_lines; \
} \
kv_push(preview_lines.subresults, current_match); \
} while (0)

◆ SPACE_FOR_DESC

#define SPACE_FOR_DESC   (1 + 1 + 1 + MB_MAXBYTES + 16 + 4 + 3 + 3 + 1)

Enumeration Type Documentation

◆ SubIgnoreType

Case matching style to use for :substitute.

Enumerator
kSubHonorOptions 

Honor the user's 'ignorecase'/'smartcase' options.

kSubIgnoreCase 

Ignore case of the search.

kSubMatchCase 

Match case of the search.

Function Documentation

◆ append_redir()

void append_redir ( char *const  buf,
const size_t  buflen,
const char *const  opt,
const char *const  fname 
)

Append output redirection for the given file to the end of the buffer

Parameters
[out]bufBuffer to append to.
[in]buflenBuffer length.
[in]optSeparator or format string to append: will append ‘printf(’ ' . opt, fname)ifsis found inoptor a space, opt, a space and then fname ifs` is not found there.
[in]fnameFile name to append.

◆ check_help_lang()

char_u* check_help_lang ( char_u arg)

◆ check_overwrite()

int check_overwrite ( exarg_T eap,
buf_T buf,
char_u fname,
char_u ffname,
int  other 
)

Check if it is allowed to overwrite a file. If b_flags has BF_NOTEDITED, BF_NEW or BF_READERR, check for overwriting current file. May set eap->forceit if a dialog says it's OK to overwrite.

Parameters
fnamefile name to be used (can differ from buf->ffname)
ffnamefull path version of fname
otherwriting under other name
Returns
OK if it's OK, FAIL if it is not.

◆ check_secure()

int check_secure ( void  )

◆ close_preview_windows()

void close_preview_windows ( void  )

Closes any open windows for inccommand preview buffer.

◆ do_ascii()

void do_ascii ( const exarg_T *const  eap)

":ascii" and "ga" implementation

◆ do_bang()

void do_bang ( int  addr_count,
exarg_T eap,
bool  forceit,
bool  do_in,
bool  do_out 
)

◆ do_ecmd()

int do_ecmd ( int  fnum,
char_u ffname,
char_u sfname,
exarg_T eap,
linenr_T  newlnum,
int  flags,
win_T oldwin 
)

start editing a new file

Parameters
fnumfile number; if zero use ffname/sfname
ffnamethe file name
  • full path if sfname used,
  • any file name if sfname is NULL
  • empty string to re-edit with the same file name (but may be in a different directory)
  • NULL to start an empty buffer
sfnamethe short file name (or NULL)
eapcontains the command to be executed after loading the file and forced 'ff' and 'fenc'. Can be NULL!
newlnumif > 0: put cursor on this line number (if possible) ECMD_LASTL: use last position in loaded file ECMD_LAST: use last position in all files ECMD_ONE: use first line
flagsECMD_HIDE: if TRUE don't free the current buffer ECMD_SET_HELP: set b_help flag of (new) buffer before opening file ECMD_OLDBUF: use existing buffer if it exists ECMD_FORCEIT: ! used for Ex command ECMD_ADDBUF: don't edit, just add to buffer list ECMD_ALTBUF: like ECMD_ADDBUF and also set the alternate file ECMD_NOWINENTER: Do not trigger BufWinEnter
oldwinShould be "curwin" when editing a new buffer in the current window, NULL when splitting the window first. When not NULL info of the previous buffer for "oldwin" is stored.
Returns
FAIL for failure, OK otherwise

◆ do_move()

int do_move ( linenr_T  line1,
linenr_T  line2,
linenr_T  dest 
)

◆ do_shell()

void do_shell ( char_u cmd,
int  flags 
)

Call a shell to execute a command. When "cmd" is NULL start an interactive shell.

Parameters
flagsmay be SHELL_DOOUT when output is redirected

◆ do_sub_msg()

bool do_sub_msg ( bool  count_only)

Give message for number of substitutions. Can also be used after a ":global" command.

Parameters
count_onlyused 'n' flag for ":s"
Returns
true if a message was given.

◆ do_wqall()

void do_wqall ( exarg_T eap)

◆ do_write()

int do_write ( exarg_T eap)

◆ ex_align()

void ex_align ( exarg_T eap)

◆ ex_append()

void ex_append ( exarg_T eap)

◆ ex_change()

void ex_change ( exarg_T eap)

◆ ex_copy()

void ex_copy ( linenr_T  line1,
linenr_T  line2,
linenr_T  n 
)

◆ ex_exusage()

void ex_exusage ( exarg_T eap)

◆ ex_file()

void ex_file ( exarg_T eap)

◆ ex_global()

void ex_global ( exarg_T eap)

◆ ex_help()

void ex_help ( exarg_T eap)

◆ ex_helpclose()

void ex_helpclose ( exarg_T eap)

◆ ex_helptags()

void ex_helptags ( exarg_T eap)

◆ ex_oldfiles()

void ex_oldfiles ( exarg_T eap)

List v:oldfiles in a nice way.

◆ ex_retab()

void ex_retab ( exarg_T eap)

◆ ex_sort()

void ex_sort ( exarg_T eap)

◆ ex_substitute()

void ex_substitute ( exarg_T eap)

:substitute command

If 'inccommand' is empty: calls do_sub(). If 'inccommand' is set: shows a "live" preview then removes the changes. from undo history.

◆ ex_update()

void ex_update ( exarg_T eap)

◆ ex_viusage()

void ex_viusage ( exarg_T eap)

◆ ex_wnext()

void ex_wnext ( exarg_T eap)

◆ ex_write()

void ex_write ( exarg_T eap)

◆ ex_z()

void ex_z ( exarg_T eap)

◆ find_help_tags()

int find_help_tags ( const char_u arg,
int *  num_matches,
char_u ***  matches,
bool  keep_lang 
)

◆ fix_help_buffer()

void fix_help_buffer ( void  )

◆ getfile()

int getfile ( int  fnum,
char_u ffname_arg,
char_u sfname_arg,
int  setpm,
linenr_T  lnum,
int  forceit 
)

◆ global_exe()

void global_exe ( char_u cmd)

Execute cmd on lines marked with ml_setmarked().

◆ help_heuristic()

int help_heuristic ( char_u matched_string,
int  offset,
int  wrong_case 
)

Return a heuristic indicating how well the given string matches. The smaller the number, the better the match. This is the order of priorities, from best match to worst match:

  • Match with least alphanumeric characters is better.
  • Match with least total characters is better.
  • Match towards the start is better.
  • Match starting with "+" is worse (feature instead of command) Assumption is made that the matched_string passed has already been found to match some string for which help is requested. webb.
Parameters
offsetoffset for match
wrong_caseno matching case
Returns
a heuristic indicating how well the given string matches.

◆ make_filter_cmd()

char_u* make_filter_cmd ( char_u cmd,
char_u itmp,
char_u otmp 
)

Create a shell command from a command string, input redirection file and output redirection file.

Parameters
cmdCommand to execute.
itmpNULL or the input file.
otmpNULL or the output file.
Returns
an allocated string with the shell command.

◆ not_writing()

int not_writing ( void  )

◆ prepare_tagpreview()

bool prepare_tagpreview ( bool  undo_sync)

Set up for a tagpreview.

Parameters
undo_syncsync undo when leaving the window
Returns
true when it was created.

◆ print_line()

void print_line ( linenr_T  lnum,
int  use_number,
int  list 
)

◆ print_line_no_prefix()

void print_line_no_prefix ( linenr_T  lnum,
int  use_number,
int  list 
)

◆ rename_buffer()

int rename_buffer ( char_u new_fname)

◆ skip_vimgrep_pat()

char_u* skip_vimgrep_pat ( char_u p,
char_u **  s,
int *  flags 
)

Skip over the pattern argument of ":vimgrep /pat/[g][j]". Put the start of the pattern in "*s", unless "s" is NULL. If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP. If "s" is not NULL terminate the pattern with a NUL. Return a pointer to the char just past the pattern plus flags.

◆ sub_get_replacement()

void sub_get_replacement ( SubReplacementString *const  ret_sub)

Get old substitute replacement string

Parameters
[out]ret_subLocation where old string will be saved.

◆ sub_preview_win()

int sub_preview_win ( buf_T preview_buf)

Tries to enter to an existing window of given buffer. If no existing buffer is found, creates a new split.

Returns OK/FAIL.

◆ sub_set_replacement()

void sub_set_replacement ( SubReplacementString  sub)

Set substitute string and timestamp

Warning
sub must be in allocated memory. It is not copied.
Parameters
[in]subNew replacement string.
ml_get
char_u * ml_get(linenr_T lnum)
Definition: memline.c:1830
vim_strsave
char_u * vim_strsave(const char_u *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
Copy "string" into newly allocated memory.
Definition: strings.c:54
kv_last
#define kv_last(v)
Definition: kvec.h:71
char_u
unsigned char char_u
Definition: types.h:12