📄 eval.txt
字号:
internal variable *expr-variable*----------------- variable internal variableSee below |internal-variables|.function call *expr-function*------------- function(expr1, ...) function callSee below |functions|.==============================================================================3. Internal variable *internal-variables*An internal variable name can be made up of letters, digits and '_'. But itcannot start with a digit.An internal variable is created with the ":let" command |:let|.An internal variable is destroyed with the ":unlet" command |:unlet|.Using a name that isn't an internal variable, or an internal variable that hasbeen destroyed, results in an error.A variable name that is preceded with "b:" is local to the current buffer.Thus you can have several "b:foo" variables, one for each buffer.This kind of variable is deleted when the buffer is unloaded. If you want tokeep it, avoid that the buffer is unloaded by setting the 'hidden' option.A variable name that is preceded with "w:" is local to the current window. Itis deleted when the window is closed.Inside functions global variables are accessed with "g:".Predefined Vim variables: *v:count* *count-variable*v:count The count given for the last Normal mode command. Can be used to get the count before a mapping. Read-only. Example:> :map _x :<C-U>echo "the count is " . count<CR> Note: The <C-U> is required to remove the line range that you get when typing ':' after a count. "count" also works, for backwards compatibility. *v:count1* *count1-variable*v:count1 Just like "v:count", but defaults to one when no count is used. *v:errmsg* *errmsg-variable*v:errmsg Last given error message. It's allowed to set this variable. Example:> :let errmsg = ""> :next> :if errmsg != ""> : ... "errmsg" also works, for backwards compatibility. *v:warningmsg* *warningmsg-variable*v:warningmsg Last given warning message. It's allowed to set this variable. *v:statusmsg* *statusmsg-variable*v:statusmsg Last given status message. It's allowed to set this variable. *v:shell_error* *shell_error-variable*v:shell_error Result of the last shell command. When non-zero, the last shell command had an error. When zero, there was no problem. This only works when the shell returns the error code to Vim. The value -1 is often used when the command could not be executed. Read-only. Example:> :!mv foo bar> :if v:shell_error> : echo 'could not rename "foo" to "bar"!'> :endif "shell_error" also works, for backwards compatibility. *v:this_session* *this_session-variable*v:this_session Full filename of the last loaded or saved session file. See |:mksession|. It is allowed to set this variable. When no session file has been saved, this variable is empty. "this_session" also works, for backwards compatibility. *v:version* *version-variable*v:version Version number of Vim: Major version number times 100 plus minor version number. Version 5.0 is 500. Version 5.1 (5.01) is 501. Read-only. "version" also works, for backwards compatibility.==============================================================================4. Builtin Functions *functions*(Use CTRL-] on the function name to jump to the full explanation)USAGE RESULT DESCRIPTION ~append( {lnum}, {string}) Number append {string} below line {lnum}argc() Number number of files in the argument listargv( {nr}) String {nr} entry of the argument listbrowse( {save}, {title}, {initdir}, {default}) String put up a file requesterbufexists( {expr}) Number TRUE if buffer {expr} existsbufloaded( {expr}) Number TRUE if buffer {expr} is loadedbufname( {expr}) String Name of the buffer {expr}bufnr( {expr}) Number Number of the buffer {expr}bufwinnr( {nr}) Number window number of buffer {nr}byte2line( {byte}) Number line number at byte count {byte}char2nr( {expr}) Number ASCII value of first char in {expr}col( {expr}) Number column nr of cursor or markconfirm( {msg}, {choices} [, {default} [, {type}]]) Number number of choice picked by userdelete( {fname}) Number delete file {fname}did_filetype() Number TRUE if FileType autocommand event usedescape( {string}, {chars}) String escape {chars} in {string} with '\'exists( {var}) Number TRUE if {var} existsexpand( {expr}) String expand special keywords in {expr}filereadable( {file}) Number TRUE if {file} is a readable filefnamemodify( {fname}, {mods}) String modify file namegetcwd() String the current working directorygetftime( {fname}) Number last modification time of filegetline( {lnum}) String line {lnum} from current buffergetwinposx() Number X coord in pixels of GUI vim windowgetwinposy() Number Y coord in pixels of GUI vim windowglob( {expr} [, {flag}]) String expand file wildcards in {expr}has( {feature}) Number TRUE if feature {feature} supportedhistadd( {history},{item}) String add an item to a historyhistdel( {history} [, {item}]) String remove an item from a historyhistget( {history} [, {index}]) String get the item {index} from a historyhistnr( {history}) Number highest index of a historyhlexists( {name}) Number TRUE if highlight group {name} existshlID( {name}) Number syntax ID of highlight group {name}hostname() String name of the machine vim is running oninput( {prompt}) String get input from the userisdirectory( {directory}) Number TRUE if {directory} is a directorylibcall( {lib}, {func}, {arg} String call {func} in library {lib}line( {expr}) Number line nr of cursor, last line or markline2byte( {lnum}) Number byte count of line {lnum}localtime() Number current timemaparg( {name}[, {mode}]) String rhs of mapping {name} in mode {mode}mapcheck( {name}[, {mode}]) String check for mappings matching {name}match( {expr}, {pat}) Number position where {pat} matches in {expr}matchend( {expr}, {pat}) Number position where {pat} ends in {expr}matchstr( {expr}, {pat}) String match of {pat} in {expr}nr2char( {expr}) String single char with ASCII value {expr}rename({from}, {to}) Number rename (move) file from {from} to {to}setline( {lnum}, {line}) Number set line {lnum} to {line}strftime( {format}[, {time}]) String time in specified formatstrlen( {expr}) Number length of the String {expr}strpart( {src}, {start}, {len}) String {len} characters of {src} at {start}strtrans( {expr}) String translate sting to make it printablesubstitute( {expr}, {pat}, {sub}, {flags}) String all {pat} in {expr} replaced with {sub}synID( {line}, {col}, {trans}) Number syntax ID at {line} and {col}synIDattr( {synID}, {what} [, {mode}]) String attribute {what} of syntax ID {synID}synIDtrans( {synID}) Number translated syntax ID of {synID}system( {expr}) String output of shell command {expr}tempname() String name for a temporary filevirtcol( {expr}) Number screen column of cursor or markvisualmode() String last visual mode usedwinbufnr( {nr}) Number buffer number of window {nr}winheight( {nr}) Number height of window {nr}winnr() Number number of current windowappend({lnum}, {string} *append()* Append the text {string} after line {lnum} in the current buffer. {lnum} can be zero, to insert a line before the first one. Returns 1 for failure ({lnum} out of range) or 0 for success. *argc()*argc() The result is the number of files in the argument list. See |arglist|. *argv()*argv({nr}) The result is the {nr}th file in the argument list. See |arglist|. "argv(0)" is the first one. Example:> let i = 0> while i < argc()> let f = substitute(argv(i), '\([. ]\)', '\\&', 'g')> exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'> let i = i + 1> endwhile *browse()*browse({save}, {title}, {initdir}, {default}) Put up a file requester. This only works when "has("browse")" returns non-zero (only in some GUI versions). The input fields are: {save} when non-zero, select file to write {title} title for the requester {initdir} directory to start browsing in {default} default file name When the "Cancel" button is hit, something went wrong, or browsing is not possible, an empty string is returned. *bufexists()*bufexists({expr}) The result is a Number, which is non-zero if a buffer called {expr} exists. If the {expr} argument is a string it must match a buffer name exactly. If the {expr} argument is a number buffer numbers are used. Use "bufexists(0)" to test for the existence of an alternate file name. *buffer_exists()* Obsolete name: buffer_exists(). *bufloaded()*bufloaded({expr}) The result is a Number, which is non-zero if a buffer called {expr} exists and is loaded (shown in a window or hidden). The {expr} argument is used like with bufexists(). *bufname()*bufname({expr}) The result is the name of a buffer, as it is displayed by the ":ls" command. If {expr} is a Number, that buffer number's name is given. Number zero is the alternate buffer for the current window. If {expr} is a String, it is used as a regexp pattern to match with the buffer names. This is always done like 'magic' is set and 'cpoptions' is empty. When there is more than one match an empty string is returned. "" or "%" can be used for the current buffer, "#" for the alternate buffer. If the {expr} is a String, but you want to use it as a buffer number, force it to be a Number by adding zero to it:> echo bufname("3" + 0) If the buffer doesn't exist, or doesn't have a name, an empty string is returned.> bufname("#") alternate buffer name> bufname(3) name of buffer 3> bufname("%") name of current buffer> bufname("file2") name of buffer where "file2" matches. *buffer_name()* Obsolete name: buffer_name(). *bufnr()*bufnr({expr}) The result is the number of a buffer, as it is displayed by the ":ls" command. For the use of {expr}, see bufname() above. If the buffer doesn't exist, -1 is returned. bufnr("$") is the last buffer:> :let last_buffer = bufnr("$") The result is a Number, which is the highest buffer number of existing buffers. Note that not all buffers with a smaller number necessarily exist, because ":bdel" may have removed them. Use bufexists() to test for the existence of a buffer. *buffer_number()* Obsolete name: buffer_number(). *last_buffer_nr()* Obsolete name for bufnr("$"): last_buffer_nr(). *bufwinnr()*bufwinnr({expr}) The result is a Number, which is the number of the first window associated with buffer {expr}. For the use of {expr}, see bufname() above. If buffer {expr} doesn't exist or there is no such window, -1 is returned. Example:> echo "A window containing buffer 1 is " . (bufwinnr(1)) *byte2line()*byte2line({byte}) Return the line number that contains the character at byte count {byte} in the current buffer. This includes the end-of-line character, depending on the 'fileformat' option for the current buffer. The first character has byte count one. Also see |line2byte()|, |go| and |:goto|. {not available when compiled without the |+byte_offset| feature} *char2nr()*char2nr({expr}) Return ASCII value of the first char in {expr}. Examples:> char2nr(" ") returns 32> char2nr("ABC") returns 65 *col()*col({expr}) The result is a Number, which is the column of the file position given with {expr}. The accepted positions are: . the cursor position '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:> col(".") column of cursor> col("'t") column of mark t> col("'" . markname) column of mark markname The first column is 1. 0 is returned for an error. *confirm()*confirm({msg}, {choices} [, {default} [, {type}]]) Confirm() offers the user a dialog, from which a choice can be made. It returns the number of the choice. For the first choice this is 1. Note: confirm() is only supported when compiled with dialog support, see |+dialog_con| and |+dialog_gui|. {msg} is displayed in a |dialog| with {choices} as the alternatives. {msg} is a String, use '\n' to include a newline. Only on some systems the string is wrapped when it doesn't fit. {choices} is a String, with the individual choices separated by '\n', e.g.> confirm("Save changes?", "&Yes\n&No\n&Cancel") The letter after the '&' is the shortcut key for that choice. Thus you can type 'c' to select "Cancel". The shorcut does not need to be the first letter:> confirm("file has been modified", "&Save\nSave &All") For the console, the first letter of each choice is used as the default shortcut key. The optional {default} argument is the number of the choice that is made if the user hits <CR>. Use 1 to make the first choice the default one. Use 0 to not set a default. If {default} is omitted, 0 is used. The optional {type} argument gives the type of dialog. This is only used for the icon of the Win32 GUI. It can be one of these values: "Error", "Question", "Info", "Warning" or "Generic". Only the first character is relevant. When {type} is omitted, "Generic" is used. If the user aborts the dialog by pressing <Esc>, CTRL-C, or another valid interrupt key, confirm() returns 0. An example:> :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)> :if choice == 0> : echo "make up your mind!"> :elseif choice == 3> : echo "tasteful"> :else> : echo "I prefer bananas myself."> :endif In a GUI dialog, buttons are used. The layout of the buttons depends on the 'v' flag in 'guioptions'. If it is included, the buttons are always put vertically. Otherwise, confirm() tries to put the buttons in one horizontal line. If they don't fit, a vertical layout is used anyway. For some systems the horizontal layout is always used. *delete()*delete({fname}) Deletes the file by the name {fname}. The result is a Number, which is 0 if the file was deleted successfully, and non-zero when the deletion failed. *did_filetype()*did_filetype() Returns non-zero when autocommands are being executed and the FileType event has been triggered at least once. Can be used to avoid triggering the FileType event again in the scripts that detect the file type. |FileType|escape({string}, {chars}) *escape()*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -