Data Structures | Typedefs | Functions
search.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/indent.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/option.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  SearchedFile
 

Typedefs

typedef struct SearchedFile SearchedFile
 

Functions

int search_regcomp (char_u *pat, int pat_save, int pat_use, int options, regmmatch_T *regmatch)
 
char_uget_search_pat (void)
 
char_ureverse_text (char_u *s) FUNC_ATTR_NONNULL_RET
 
void save_re_pat (int idx, char_u *pat, int magic)
 
void save_search_patterns (void)
 
void restore_search_patterns (void)
 
void save_last_search_pattern (void)
 
void restore_last_search_pattern (void)
 
char_ulast_search_pattern (void)
 
int ignorecase (char_u *pat)
 
int ignorecase_opt (char_u *pat, int ic_in, int scs)
 As ignorecase() put pass the "ic" and "scs" flags. More...
 
bool pat_has_uppercase (char_u *pat) FUNC_ATTR_NONNULL_ALL
 Returns true if pattern pat has an uppercase character. More...
 
const char * last_csearch (void)
 
int last_csearch_forward (void)
 
int last_csearch_until (void)
 
void set_last_csearch (int c, char_u *s, int len)
 
void set_csearch_direction (Direction cdir)
 
void set_csearch_until (int t_cmd)
 
char_ulast_search_pat (void)
 
void reset_search_dir (void)
 
void set_last_search_pat (const char_u *s, int idx, int magic, int setlast)
 
void last_pat_prog (regmmatch_T *regmatch)
 
int searchit (win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, char_u *pat, long count, int options, int pat_use, searchit_arg_T *extra_arg)
 
void set_search_direction (int cdir)
 
int do_search (oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, int options, searchit_arg_T *sia)
 
int search_for_exact_line (buf_T *buf, pos_T *pos, Direction dir, char_u *pat)
 
int searchc (cmdarg_T *cap, int t_cmd) FUNC_ATTR_NONNULL_ALL
 
pos_Tfindmatch (oparg_T *oap, int initc)
 
pos_Tfindmatchlimit (oparg_T *oap, int initc, int flags, int64_t maxtravel)
 
void showmatch (int c)
 
int findsent (Direction dir, long count)
 
bool findpar (bool *pincl, int dir, long count, int what, int both)
 
int startPS (linenr_T lnum, int para, int both)
 
int fwd_word (long count, int bigword, int eol)
 
int bck_word (long count, int bigword, int stop)
 
int end_word (long count, int bigword, int stop, int empty)
 
int bckend_word (long count, int bigword, bool eol)
 
int current_word (oparg_T *oap, long count, int include, int bigword)
 
int current_sent (oparg_T *oap, long count, int include)
 
int current_block (oparg_T *oap, long count, int include, int what, int other)
 
int current_tagblock (oparg_T *oap, long count_arg, bool include)
 
int current_par (oparg_T *oap, long count, int include, int type)
 
bool current_quote (oparg_T *oap, long count, bool include, int quotechar) FUNC_ATTR_NONNULL_ALL
 
int current_search (long count, bool forward)
 
int linewhite (linenr_T lnum)
 
void f_searchcount (typval_T *argvars, typval_T *rettv, FunPtr fptr)
 
void find_pattern_in_path (char_u *ptr, Direction dir, size_t len, bool whole, bool skip_comments, int type, long count, int action, linenr_T start_lnum, linenr_T end_lnum)
 
static void if (did_show)
 
else if (!msg_silent)
 
 if (got_int)
 
 for (;;)
 
void get_search_pattern (SearchPattern *const pat)
 Get last search pattern. More...
 
void get_substitute_pattern (SearchPattern *const pat)
 Get last substitute pattern. More...
 
void set_search_pattern (const SearchPattern pat)
 Set last search pattern. More...
 
void set_substitute_pattern (const SearchPattern pat)
 Set last substitute pattern. More...
 
void set_last_used_pattern (const bool is_substitute_pattern)
 
bool search_was_last_used (void)
 Returns true if search pattern was the last used one. More...
 

Typedef Documentation

◆ SearchedFile

typedef struct SearchedFile SearchedFile

Function Documentation

◆ bck_word()

int bck_word ( long  count,
int  bigword,
int  stop 
)

◆ bckend_word()

int bckend_word ( long  count,
int  bigword,
bool  eol 
)

Move back to the end of the word.

Parameters
bigwordTRUE for "B"
eolif true, then stop at end of line.
Returns
FAIL if start of the file was reached.

◆ current_block()

int current_block ( oparg_T oap,
long  count,
int  include,
int  what,
int  other 
)

Find block under the cursor, cursor at end. "what" and "other" are two matching parenthesis/brace/etc.

Parameters
includeTRUE == include white space
what'(', '{', etc.
other')', '}', etc.

◆ current_par()

int current_par ( oparg_T oap,
long  count,
int  include,
int  type 
)
Parameters
includeTRUE == include white space
type'p' for paragraph, 'S' for section

◆ current_quote()

bool current_quote ( oparg_T oap,
long  count,
bool  include,
int  quotechar 
)

Find quote under the cursor, cursor at end.

Parameters
includetrue == include quote char
quotecharQuote character
Returns
true if found, else false.

◆ current_search()

int current_search ( long  count,
bool  forward 
)

Find next search match under cursor, cursor at end. Used while an operator is pending, and in Visual mode.

Parameters
forwardtrue for forward, false for backward

◆ current_sent()

int current_sent ( oparg_T oap,
long  count,
int  include 
)

◆ current_tagblock()

int current_tagblock ( oparg_T oap,
long  count_arg,
bool  include 
)

Find tag block under the cursor, cursor at end.

Parameters
includetrue == include white space

◆ current_word()

int current_word ( oparg_T oap,
long  count,
int  include,
int  bigword 
)

Find word under cursor, cursor at end. Used while an operator is pending, and in Visual mode.

Parameters
includeTRUE: include word and white space
bigwordFALSE == word, TRUE == WORD

◆ do_search()

int do_search ( oparg_T oap,
int  dirc,
int  search_delim,
char_u pat,
long  count,
int  options,
searchit_arg_T sia 
)

Highest level string search function. Search for the 'count'th occurrence of pattern 'pat' in direction 'dirc'

Careful: If spats[0].off.line == TRUE and spats[0].off.off == 0 this makes the movement linewise without moving the match position.

Parameters
dircif 0: use previous dir.
patNULL or empty : use previous string.
optionsif TRUE and SEARCH_REV == TRUE : go in reverse of previous dir. SEARCH_ECHO == TRUE : echo the search command and handle options SEARCH_MSG == TRUE : may give error message SEARCH_OPT == TRUE : interpret optional flags SEARCH_HIS == TRUE : put search pattern in history SEARCH_NOOF == TRUE : don't add offset to position SEARCH_MARK == TRUE : set previous context mark SEARCH_KEEP == TRUE : keep previous search pattern SEARCH_START == TRUE : accept match at curpos itself SEARCH_PEEK == TRUE : check for typed char, cancel search
oapcan be NULL
dirc'/' or '?'
search_delimdelimiter for search, e.g. '' in sregexreplacement
siaoptional arguments or NULL
Returns
0 for failure, 1 for found, 2 for found and line offset added.

◆ end_word()

int end_word ( long  count,
int  bigword,
int  stop,
int  empty 
)

◆ f_searchcount()

void f_searchcount ( typval_T argvars,
typval_T rettv,
FunPtr  fptr 
)

◆ find_pattern_in_path()

void find_pattern_in_path ( char_u ptr,
Direction  dir,
size_t  len,
bool  whole,
bool  skip_comments,
int  type,
long  count,
int  action,
linenr_T  start_lnum,
linenr_T  end_lnum 
)

Find identifiers or defines in included files. If p_ic && (compl_cont_status & CONT_SOL) then ptr must be in lowercase.

Parameters
ptrpointer to search pattern
dirdirection of expansion
lenlength of search pattern
wholematch whole words only
skip_commentsdon't match inside comments
typeType of search; are we looking for a type? a macro?
actionWhat to do when we find it
start_lnumfirst line to start searching
end_lnumlast line for searching

◆ findmatch()

pos_T* findmatch ( oparg_T oap,
int  initc 
)

◆ findmatchlimit()

pos_T* findmatchlimit ( oparg_T oap,
int  initc,
int  flags,
int64_t  maxtravel 
)

◆ findpar()

bool findpar ( bool pincl,
int  dir,
long  count,
int  what,
int  both 
)

Find the next paragraph or section in direction 'dir'. Paragraphs are currently supposed to be separated by empty lines. If 'what' is NUL we go to the next paragraph. If 'what' is '{' or '}' we go to the next section. If 'both' is TRUE also stop at '}'.

Parameters
pinclReturn: true if last char is to be included
Returns
TRUE if the next paragraph or section was found.

◆ findsent()

int findsent ( Direction  dir,
long  count 
)

◆ for()

for ( ;;  )

◆ fwd_word()

int fwd_word ( long  count,
int  bigword,
int  eol 
)

fwd_word(count, type, eol) - move forward one word

Returns
FAIL if the cursor was already at the end of the file. If eol is TRUE, last word stops at end of line (for operators).
Parameters
bigword"W", "E" or "B"

◆ get_search_pat()

char_u* get_search_pat ( void  )

◆ get_search_pattern()

void get_search_pattern ( SearchPattern *const  pat)

Get last search pattern.

◆ get_substitute_pattern()

void get_substitute_pattern ( SearchPattern *const  pat)

Get last substitute pattern.

◆ if() [1/3]

else if ( msg_silent)

◆ if() [2/3]

static void if ( did_show  )

◆ if() [3/3]

if ( got_int  )

◆ ignorecase()

int ignorecase ( char_u pat)

◆ ignorecase_opt()

int ignorecase_opt ( char_u pat,
int  ic_in,
int  scs 
)

As ignorecase() put pass the "ic" and "scs" flags.

◆ last_csearch()

const char* last_csearch ( void  )

◆ last_csearch_forward()

int last_csearch_forward ( void  )

◆ last_csearch_until()

int last_csearch_until ( void  )

◆ last_pat_prog()

void last_pat_prog ( regmmatch_T regmatch)

◆ last_search_pat()

char_u* last_search_pat ( void  )

◆ last_search_pattern()

char_u* last_search_pattern ( void  )

◆ linewhite()

int linewhite ( linenr_T  lnum)

◆ pat_has_uppercase()

bool pat_has_uppercase ( char_u pat)

Returns true if pattern pat has an uppercase character.

◆ reset_search_dir()

void reset_search_dir ( void  )

◆ restore_last_search_pattern()

void restore_last_search_pattern ( void  )

◆ restore_search_patterns()

void restore_search_patterns ( void  )

◆ reverse_text()

char_u* reverse_text ( char_u s)

◆ save_last_search_pattern()

void save_last_search_pattern ( void  )

Save and restore the search pattern for incremental highlight search feature.

It's similar to but different from save_search_patterns() and restore_search_patterns(), because the search pattern must be restored when cancelling incremental searching even if it's called inside user functions.

◆ save_re_pat()

void save_re_pat ( int  idx,
char_u pat,
int  magic 
)

◆ save_search_patterns()

void save_search_patterns ( void  )

◆ search_for_exact_line()

int search_for_exact_line ( buf_T buf,
pos_T pos,
Direction  dir,
char_u pat 
)

◆ search_regcomp()

int search_regcomp ( char_u pat,
int  pat_save,
int  pat_use,
int  options,
regmmatch_T regmatch 
)

translate search pattern for vim_regcomp()

pat_save == RE_SEARCH: save pat in spats[RE_SEARCH].pat (normal search cmd) pat_save == RE_SUBST: save pat in spats[RE_SUBST].pat (:substitute command) pat_save == RE_BOTH: save pat in both patterns (:global command) pat_use == RE_SEARCH: use previous search pattern if "pat" is NULL pat_use == RE_SUBST: use previous substitute pattern if "pat" is NULL pat_use == RE_LAST: use last used pattern if "pat" is NULL options & SEARCH_HIS: put search string in history options & SEARCH_KEEP: keep previous search pattern

Parameters
regmatchreturn: pattern and ignore-case flag
Returns
FAIL if failed, OK otherwise.

◆ search_was_last_used()

bool search_was_last_used ( void  )

Returns true if search pattern was the last used one.

◆ searchc()

int searchc ( cmdarg_T cap,
int  t_cmd 
)

◆ searchit()

int searchit ( win_T win,
buf_T buf,
pos_T pos,
pos_T end_pos,
Direction  dir,
char_u pat,
long  count,
int  options,
int  pat_use,
searchit_arg_T extra_arg 
)

lowest level search function. Search for 'count'th occurrence of pattern "pat" in direction "dir". Start at position "pos" and return the found position in "pos".

if (options & SEARCH_MSG) == 0 don't give any messages if (options & SEARCH_MSG) == SEARCH_NFMSG don't give 'notfound' messages if (options & SEARCH_MSG) == SEARCH_MSG give all messages if (options & SEARCH_HIS) put search pattern in history if (options & SEARCH_END) return position at end of match if (options & SEARCH_START) accept match at pos itself if (options & SEARCH_KEEP) keep previous search pattern if (options & SEARCH_FOLD) match only once in a closed fold if (options & SEARCH_PEEK) check for typed char, cancel search if (options & SEARCH_COL) start at pos->col instead of zero

Parameters
winwindow to search in; can be NULL for a buffer without a window!
end_posset to end of the match, unless NULL
pat_usewhich pattern to use when "pat" is empty
extra_argoptional extra arguments, can be NULL
Returns
FAIL (zero) for failure, non-zero for success. the index of the first matching subpattern plus one; one if there was none.

◆ set_csearch_direction()

void set_csearch_direction ( Direction  cdir)

◆ set_csearch_until()

void set_csearch_until ( int  t_cmd)

◆ set_last_csearch()

void set_last_csearch ( int  c,
char_u s,
int  len 
)

◆ set_last_search_pat()

void set_last_search_pat ( const char_u s,
int  idx,
int  magic,
int  setlast 
)

◆ set_last_used_pattern()

void set_last_used_pattern ( const bool  is_substitute_pattern)

Set last used search pattern

Parameters
[in]is_substitute_patternIf true set substitute pattern as last used. Otherwise sets search pattern.

◆ set_search_direction()

void set_search_direction ( int  cdir)

◆ set_search_pattern()

void set_search_pattern ( const SearchPattern  pat)

Set last search pattern.

◆ set_substitute_pattern()

void set_substitute_pattern ( const SearchPattern  pat)

Set last substitute pattern.

◆ showmatch()

void showmatch ( int  c)

Move cursor briefly to character matching the one under the cursor. Used for Insert mode and "r" command. Show the match only if it is visible on the screen. If there isn't a match, then beep.

Parameters
cchar to show match for

◆ startPS()

int startPS ( linenr_T  lnum,
int  para,
int  both 
)