Skip to main content
Module

x/ddc_vim/deps.ts>fn.search

Dark deno-powered completion framework for neovim/Vim8
Go to Latest
function fn.search
import { fn } from "https://deno.land/x/ddc_vim@v2.3.0/deps.ts";
const { search } = fn;

Search for regexp pattern {pattern}. The search starts at the cursor position (you can use |cursor()| to set it). When a match has been found its line number is returned. If there is no match a 0 is returned and the cursor doesn't move. No error message is given. {flags} is a String, which can contain these character flags: 'b' search Backward instead of forward 'c' accept a match at the Cursor position 'e' move to the End of the match 'n' do Not move the cursor 'p' return number of matching sub-Pattern (see below) 's' Set the ' mark at the previous location of the cursor 'w' Wrap around the end of the file 'W' don't Wrap around the end of the file 'z' start searching at the cursor column instead of zero If neither 'w' or 'W' is given, the 'wrapscan' option applies. If the 's' flag is supplied, the ' mark is set, only if the cursor is moved. The 's' flag cannot be combined with the 'n' flag. 'ignorecase', 'smartcase' and 'magic' are used. When the 'z' flag is not given, forward searching always starts in column zero and then matches before the cursor are skipped. When the 'c' flag is present in 'cpo' the next search starts after the match. Without the 'c' flag the next search starts one column further. This matters for overlapping matches. When searching backwards and the 'z' flag is given then the search starts in column zero, thus no match in the current line will be found (unless wrapping around the end of the file). When the {stopline} argument is given then the search stops after searching this line. This is useful to restrict the search to a range of lines. Examples: let match = search('(', 'b', line("w0")) let end = search('END', '', line("w$")) When {stopline} is used and it is not zero this also implies that the search does not wrap around the end of the file. A zero value is equal to not giving the argument. When the {timeout} argument is given the search stops when more than this many milliseconds have passed. Thus when {timeout} is 500 the search stops after half a second. The value must not be negative. A zero value is like not giving the argument. {only available when compiled with the |+reltime| feature} If the {skip} expression is given it is evaluated with the cursor positioned on the start of a match. If it evaluates to non-zero this match is skipped. This can be used, for example, to skip a match in a comment or a string. {skip} can be a string, which is evaluated as an expression, a function reference or a lambda. When {skip} is omitted or empty, every match is accepted. When evaluating {skip} causes an error the search is aborted and -1 returned. With the 'p' flag the returned value is one more than the first sub-match in (). One if none of them matched but the whole pattern did match. To get the column number too use |searchpos()|. The cursor will be positioned at the match, unless the 'n' flag is used. Example (goes over all files in the argument list): :let n = 1 :while n <= argc() " loop over all files in arglist : exe "argument " . n : " start at the last char in the file and wrap for the : " first search to find match at start of file : normal G$ : let flags = "w" : while search("foo", flags) > 0 : s/foo/bar/g : let flags = "W" : endwhile : update " write the file if modified : let n = n + 1 :endwhile Example for using some flags: :echo search('<if|(else)|(endif)', 'ncpe') This will search for the keywords "if", "else", and "endif" under or after the cursor. Because of the 'p' flag, it returns 1, 2, or 3 depending on which keyword is found, or 0 if the search fails. With the cursor on the first word of the line: if (foo == 0) | let foo = foo + 1 | endif ~ the function returns 1. Without the 'c' flag, the function finds the "endif" and returns 3. The same thing happens without the 'e' flag if the cursor is on the "f" of "if". The 'n' flag tells the function not to move the cursor. Can also be used as a |method|: GetPattern()->search()

Parameters

denops: Denops
pattern: unknown
optional
flags: unknown
optional
stopline: unknown
optional
timeout: unknown
optional
skip: unknown

Returns

Promise<unknown>