📄 eval.txt
字号:
Escape the characters in {chars} that occur in {string} with a backslash. Example:> :echo escape('c:\program files\vim', ' \') results in:> c:\\program\ files\\vim *exists()*exists({expr}) The result is a Number, which is 1 if {var} is defined, zero otherwise. The {expr} argument is a string, which contains one of these: &option-name Vim option $ENVNAME environment variable (could also be done by comparing with an empty string) *funcname built-in function (see |functions|) or user defined function (see |user-functions|). varname internal variable (see |internal-variables|). Examples:> exists("&shortname")> exists("$HOSTNAME")> exists("*strftime")> exists("bufcount") There must be no space between the symbol &/$/* and the name. Note that the argument must be a string, not the name of the variable itself! This example doesn't check for existence of the "bufcount" variable, but gets the contents of "bufcount", and checks if that exists: exists(bufcount) *expand()*expand({expr} [, {flag}]) Expand wildcards and the following special keywords in {expr}. The result is a String. When there are several matches, they are separated by <NL> characters. [Note: in version 5.0 a space was used, which caused problems when a file name contains a space] If the expansion fails, the result is an empty string. A name for a non-existing file is not included. When {expr} starts with '%', '#' or '<', the expansion is done like for the |cmdline-special| variables with their associated modifiers. Here is a short overview: % current file name # alternate file name #n alternate file name n <cfile> file name under the cursor <afile> autocmd file name <abuf> autocmd buffer number <sfile> sourced script file name <cword> word under the cursor <cWORD> WORD under the cursor Modifiers: :p expand to full path :h head (last path component removed) :t tail (last path component only) :r root (one extension removed) :e extension only Example:> :let &tags = expand("%:p:h") . "/tags" Note that when expanding a string that starts with '%', '#' or '<', any following text is ignored. This does NOT work:> :let doesntwork = expand("%:h.bak") Use this:> :let doeswork = expand("%:h") . ".bak" Also note that expanding "<cfile>" and others only returns the referenced file name without further expansion. If "<cfile>" is "~/.cshrc", you need to do another expand() to have the "~/" expanded into the path of the home directory:> :echo expand(expand("<cfile>")) There cannot be white space between the variables and the following modifier. The |fnamemodify()| function can be used to modify normal file names. When using '%' or '#', and the current or alternate file name is not defined, an empty string is used. Using "%:p" in a buffer with no name, results in the current directory, with a '/' added. When {expr} does not start with '%', '#' or '<', it is expanded like a file name is expanded on the command line. 'suffixes' and 'wildignore' are used, unless the optional {flag} argument is given and it is non-zero. Expand() can also be used to expand variables and environment variables that are only known in a shell. But this can be slow, because a shell must be started. See |expr-env-expand|. See |glob()| for finding existing files. See |system()| for getting the raw output of an external command. *filereadable()*filereadable({file}) The result is a Number, which is TRUE when a file with the name {file} exists, and can be read. If {file} doesn't exist, or is a directory, the result is FALSE. {file} is any expression, which is used as a String. *file_readable()* Obsolete name: file_readable(). *fnamemodify()*fnamemodify({fname}, {mods}) Modify file name {fname} according to {mods}. {mods} is a string of characters like it is used for file names on the command line. See |filename-modifiers|. Example:> :echo fnamemodify("main.c", ":p:h") results in:> /home/mool/vim/vim/src/ *getcwd()*getcwd() The result is a String, which is the name of the current working directory. *getftime()*getftime({fname}) The result is a Number, which is the last modification time of the given file {fname}. The value is measured as seconds since 1st Jan 1970, and may be passed to strftime(). See also |localtime()| and |strftime()|. If the file {fname} can't be found -1 is returned. *getline()*getline({lnum}) The result is a String, which is line {lnum} from the current buffer. Example:> getline(1) When {lnum} is a String that doesn't start with a digit, line() is called to translate the String into a Number. To get the line under the cursor:> getline(".") When {lnum} is smaller than 1 or bigger than the number of lines in the buffer, an empty string is returned. *getwinposx()*getwinposx() The result is a Number, which is the X coordinate in pixels of the left hand side of the GUI vim window. The result will be -1 if the information is not available. *getwinposy()*getwinposy() The result is a Number, which is the Y coordinate in pixels of the top of the GUI vim window. The result will be -1 if the information is not available. *glob()*glob({expr}) Expand the file wildcards in {expr}. The result is a String. When there are several matches, they are separated by <NL> characters. If the expansion fails, the result is an empty string. A name for a non-existing file is not included. For most systems backticks can be used to get files names from any external command. Example:> :let tagfiles = glob("`find . -name tags -print`")> :let &tags = substitute(tagfiles, "\n", ",", "g") The result of the program inside the backticks should be one item per line. Spaces inside an item are allowed. See |expand()| for expanding special Vim variables. See |system()| for getting the raw output of an external command. *has()*has({feature}) The result is a Number, which is 1 if the feature {feature} is supported, zero otherwise. The {feature} argument is a string. See |feature-list| below. *histadd()*histadd({history}, {item}) Add the String {item} to the history {history} which can be one of: *hist-names* "cmd" or ":" command line history "search" or "/" search pattern history "expr" or "=" typed expression history "input" or "@" input line history If {item} does already exist in the history, it will be shifted to become the newest entry. The result is a Number: 1 if the operation was successful, otherwise 0 is returned. Example:> :call histadd("input", strftime("%Y %b %d"))> :let date=input("Enter date: ") *histdel()*histdel({history} [, {item}]) Clear {history}, ie. delete all its entries. See |hist-names| for the possible values of {history}. If the parameter {item} is given as String, this is seen as regular expression. All entries matching that expression will be removed from the history (if there are any). If {item} is a Number, it will be interpreted as index, see |:history-indexing|. The respective entry will be removed if it exists. The result is a Number: 1 for a successful operation, otherwise 0 is returned. Examples: Clear expression register history:> :call histdel("expr") Remove all entries starting with "*" from the search history:> :call histdel("/", '^\*') The following three are equivalent:> :call histdel("search", histnr("search"))> :call histdel("search", -1)> :call histdel("search", '^'.histget("search", -1).'$') To delete the last search pattern and use the last-but-one for the "n" command and 'hlsearch':> :call histdel("search", -1)> :let @/ = histget("search", -1) *histget()*histget({history} [, {index}]) The result is a String, the entry with Number {index} from {history}. See |hist-names| for the possible values of {history}, and |:history-indexing| for {index}. If there is no such entry, an empty String is returned. When {index} is omitted, the most recent item from the history is used. Examples: Redo the second last search from history.> :execute '/' . histget("search", -2) Define an Ex command ":H {num}" that supports re-execution of the {num}th entry from the output of |:history|.> :command -nargs=1 H execute histget("cmd",0+<args>) *histnr()*histnr({history}) The result is the Number of the current entry in {history}. See |hist-names| for the possible values of {history}. If an error occurred, -1 is returned. Example:> :let inp_index = histnr("expr") *hlexists()*hlexists({name}) The result is a Number, which is non-zero if a highlight group called {name} exists. This is when the group has been defined in some way. Not necessarily when highlighting has been defined for it, it may also have been used for a syntax item. *highlight_exists()* Obsolete name: highlight_exists(). *hlID()*hlID({name}) The result is a Number, which is the ID of the highlight group with name {name}. When the highlight group doesn't exist, zero is returned. This can be used to retrieve information about the highlight group. For example, to get the background color of the "Comment" group:> :echo synIDattr(synIDtrans(hlID("Comment")), "bg") *highlightID()* Obsolete name: highlightID(). *hostname()*hostname() The result is a String, which is the name of the machine on which Vim is currently running. Machine names greater than 256 characters long are truncated.input({prompt}) *input()* The result is a String, which is whatever the user typed on the command-line. The parameter is either a prompt string, or a blank string (for no prompt). A '\n' can be used in the prompt to start a new line. The highlighting set with |:echohl| is used for the prompt. The input is entered just like a command-line, with the same editing commands and mappings. There is a separate history for lines typed for input(). NOTE: This must not be used in a startup file, for the versions that only run in GUI mode (e.g., the Win32 GUI). Example:> :if input("Coffee or beer? ") == "beer"> : echo "Cheers!"> :endif *isdirectory()*isdirectory({directory}) The result is a Number, which is TRUE when a directory with the name {directory} exists. If {directory} doesn't exist, or isn't a directory, the result is FALSE. {directory} is any expression, which is used as a String. *libcall()*libcall({libname}, {funcname}, {argument}) Call function {funcname} in the run-time library {libname} with argument {argument}. The result is the String returned. If {argument} is a number, it is passed to the function as an int; if {param} is a string, it is passed as a null-terminated string. If the function returns NULL, this will appear as an empty string "" to Vim. libcall() allows you to write your own 'plug-in' extensions to Vim without having to recompile the program. It is NOT a means to call system functions! If you try to do so Vim will very probably crash. For Win32, the functions you write must be placed in a DLL and use the normal C calling convention (NOT Pascal which is used in Windows System DLLs). The function must take exactly one parameter, either a character pointer or a long integer, and must return a character pointer or NULL. The character pointer returned must point to memory that will remain valid after the function has returned (e.g. in static data in the DLL). If it points to allocated memory, that memory will leak away. Using a static buffer in the function should work, it's then freed when the DLL is unloaded. WARNING: If the function returns a non-valid pointer, Vim will crash! This also happens if the function returns a number, because Vim thinks it's a pointer. For Win32 systems, {libname} should be the filename of the DLL without the ".DLL" suffix. A full path is only required if the DLL is not in the usual places. {only in Win32 versions} *line()*line({expr}) The result is a Number, which is the line number of the file position given with {expr}. The accepted positions are: . the cursor position $ the last line in the current buffer 'x position of mark x (if the mark is not set, 0 is returned) Note that only marks in the current file can be used. Examples:> line(".") line number of the cursor> line("'t") line number of mark t> line("'" . marker) line number of mark marker *last-position-jump* This autocommand jumps to the last known position in a file just after opening it, if the '" mark is set:> :au BufReadPost * if line("'\"") | exe "normal '\"" | endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -