?? starting.txt
字號(hào):
If the expression evaluates to zero, these commands are skipped.The |:echo| command prints its argument, which is also an expression.Many constructions can be used in an expression. In the example we see this: &term The value of the 'term' option. A name prepended with '&' is the value of the option by that name. == "equal", compares the strings or numbers on each side, and evaluates to true when they are equal. "xterm" A literal string.For more information about expressions, see |expression|.You can also use "else":> if &tabstop != 8> echo "tabstop is " . &tabstop> else> echo "tabstop is OK"> endifNote that a dot is used in the first echo command, to concatenate the literalstring with the value of the 'tabstop' option. It is automatically convertedfrom a number to a string, so that it can be concatenated.WHILE - ENDWHILE ~To repeat a sequence of commands the |:while| command can be used:> let i = 1> while i < 10> echo i> let i = i + 1> endwhileThis uses the internal variable "i". An internal variable is used just likein many programming languages. The |:let| command is used to assign a valueto a variable. The variable need not be declared and can hold a number or astring.The statements between the "while" and the "endwhile" are executed nine times.Note that the variable "i" is incremented with the "let i = i + 1" command.If you would forget this, the loop would run forever! Fortunately you caninterrupt it with a CTRL-C (CTRL-Break on DOS).BUILTIN FUNCTIONS ~Vim has builtin functions that you can use. Example:> echo exists("did_my_inits")This will print a one when the variable "did_my_inits" exists, and a zero ifit doesn't exist.> if has("gui_running")> syntax on> endifThis will switch on syntax highlighting if the GUI is started. The has()function can be used to check if a certain feature is supported.> call append(0, hostname() . " - " . strftime("%Y %b %d"))This inserts a line with the name of the computer and the current date at thestart of the current buffer.There are many more functions, which can be used to accomplish most things youwould want to do in Vim, which are too complicated to do with normal commands.See |functions|.USER DEFINED FUNCTIONS ~You will often have a number of commands that you use in several places. Youcan define a function for these, and call it where you want. Example:> function My_Func(name)> if a:name ==? "john"> let s = "Hello "> else> let s = "I don't know "> endif> echo s . a:name . "."> endfunExplanation:The function "My_Func" is defined with one argument. "a:name" is used torefer to that argument. The "==?" operator is used to compare the argumentwith "john" while ignoring case. You could call it like this:> call My_Func("John")> Hello John.> call My_Func("James")> I don't know James.Note that the name of a user function always starts with a capital letter.There can be any number of arguments. See |:function|.PACKAGING ~To avoid your function names to interfere with functions that you get fromothers, use this scheme:- Prepend a unique string before each function name. I often use an abbreviation. For example, "OW_" is used for the option window functions.- Put the definition of your functions together in a file. Set a global variable to indicate that the functions have been loaded. When sourcing the file again, first unload the functions.Example:> " This is the XXX package>> if exists("XXX_loaded")> delfun XXX_one> delfun XXX_two> endif>> function XXX_one(a)> ... body of function ...> endfun>> function XXX_two(b)> ... body of function ...> endfun>> let XXX_loaded = 1AUTOCOMMANDS ~You might want to set options or define mappings when editing a certain kindof file. Fortunatly, Vim already recognizes a lot of file types. This isused for syntax highlighting, but you can use it for other things too. Youneed to have syntax enabled |:syn-on|, or use this command:> filetype onFor example, this autocommand sets the 'cindent' option in a C program file:> au FileType c set cindentThis autocommand consists of three parts: FileType the name of the event which is used c the name of the file type detected set cindent the command executed when the event happens and the file type is "c"See |:autocmd| for more information.This works fine for the 'cindent' option, which is local to a buffer. Whenthis is used for defining a mapping, this will not work properly when thereare two windows. For example, if you are editing foo.txt in one window andfoo.c in another, a mapping defined for foo.c will also be used in foo.txt.To make the mapping only work in the foo.c file, it needs to be removed assoon as the foo.c file is no longer the current buffer. That can be done inthis way:> au BufEnter * if &ft == "c" | call CM_map() | endif> au BufLeave * if &ft == "c" | call CM_unmap() | endif> fun CM_map()> set cindent> imap { {<CR> <BS><CR>}<Up><End>> endfun> fun CM_unmap()> iunmap {> endfunOne function is used here to define the mapping and another to remove it.This makes it possible to add more mappings, without changing theautocommands.The use of functions makes it possible to keep the autocommands short. Withthe '|' character commands are separated.In the ":imap" command the <> codes are used to avoid the need for controlcharacters. This is easy to type and to read back. The " <BS> is used toavoid that the indent is removed when <CR> is typed.==============================================================================7. The viminfo file *viminfo-file*If you exit Vim and later start it again, you would normally lose a lot ofinformation. The viminfo file can be used to remember that information, whichenables you to continue where you left off.The viminfo file is used to store:- The command line history.- The search string history.- The input-line history.- Contents of registers.- Marks for several files.- File marks, pointing to locations in files.- Last search/substitute pattern (for 'n' and '&').- The buffer list.- Global variables.The viminfo file is not supported when the |+viminfo| feature has beendisabled at compile time.You could also use a session file. The difference is that the viminfo filedoes not depend on what you are working on. There normally is only oneviminfo file. Session files are used to save the state of a specific editingsession. You could have several session files, one for each project you areworking on. Viminfo and session files together can be used to effectivelyenter Vim and directly start working in your desired setup. |session-file| *viminfo-read*When Vim is started and the 'viminfo' option is non-empty, the contents ofthe viminfo file are read and the info can be used in the appropriate places.The marks are not read in at startup (but file marks are). See|initialization| for how to set the 'viminfo' option upon startup. *viminfo-write*When Vim exits and 'viminfo' is non-empty, the info is stored in the viminfofile (it's actually merged with the existing one, if one exists). The'viminfo' option is a string containing information about what info should bestored, and contains limits on how much should be stored (see 'viminfo').Notes for Unix:- The file protection for the viminfo file will be set to prevent other users from being able to read it, because it may contain any text or commands that you have worked with.- If you want to share the viminfo file with other users (e.g. when you "su" to another user), you can make the file writable for the group or everybody. Vim will preserve this when writing new viminfo files. Be careful, don't allow just anybody to read and write your viminfo file!- Vim will not overwrite a viminfo file that is not writable by the current "real" user. This helps for when you did "su" to become root, but your $HOME is still set to a normal user's home directory. Otherwise Vim would create a viminfo file owned by root that nobody else can read.Marks are stored for each file separately. When a file is read and 'viminfo'is non-empty, the marks for that file are read from the viminfo file. NOTE:The marks are only written when exiting Vim, which is fine because marks areremembered for all the files you have opened in the current editing session,unless ":bdel" is used. If you want to save the marks for a file that you areabout to abandon with ":bdel", use ":wv". The '[' and ']' marks are notstored, but the '"' mark is. The '"' mark is very useful for jumping to thecursor position when the file was last exited. No marks are saved for filesthat start with any string given with the "r" flag in 'viminfo'. This can beused to avoid saving marks for files on removable media (for MS-DOS you woulduse "ra:,rb:", for Amiga "rdf0:,rdf1:,rdf2:"). *viminfo-file-marks*Uppercase marks ('A to 'Z) are stored when writing the viminfo file. Thenumbered marks ('0 to '9) are a bit special. When the viminfo file is written(when exiting or with the ":wviminfo" command), '0 is set to the current cursorposition and file. The old '0 is moved to '1, '1 to '2, etc. Thisresembles what happens with the "1 to "9 delete registers. If the currentcursor position is already present in '0 to '9, it is moved to '0, to avoidhaving the same position twice. The result is that with "'0", you can jumpback to the file and line where you exited Vim. To do that right away, tryusing this command:> vim -c "normal '0"In (c)sh, you could make an alias for it:> alias lvim vim -c '"'normal "'"0'"'Viminfo file name: *viminfo-file-name*- The default name of the viminfo file is "$HOME/.viminfo" for Unix and OS/2, "s:.viminfo" for Amiga, "$HOME\_viminfo" for MS-DOS and Win32. For the last two, when $HOME is not set, "$VIM\_viminfo" is used. When $VIM is also not set, "c:\_viminfo" is used. For OS/2 "$VIM/.viminfo" is used when $HOME is not set and $VIM is set.- The 'n' flag in the 'viminfo' option can be used to specify another viminfo file name |'viminfo'|.- The "-i" Vim argument can be used to set another file name, |-i|. When the file name given is "NONE" (all uppercase), no viminfo file is ever read or written. Also not for the commands below!- For the commands below, another file name can be given, overriding the default and the name given with 'viminfo' or "-i" (unless it's NONE).Two commands can be used to read and write the viminfo file manually. Thiscan be used to exchange registers between two running Vim programs: Firsttype ":wv" in one and then ":rv" in the other. Note that if the registeralready contained something, then ":rv!" would be required. Also notehowever that this means everything will be overwritten with information fromthe first Vim, including the command line history, etc.The viminfo file itself can be edited by hand too, although we suggest youstart with an existing one to get the format right. It is reasonablyself-explanatory once you're in there. This can be useful in order tocreate a second file, say "~/.my_viminfo" which could contain certainsettings that you always want when you first start Vim. For example, youcan preload registers with particular data, or put certain commands in thecommand line history. A line in your .vimrc file like> rviminfo! ~/.my_viminfocan be used to load this information. You could even have different viminfosfor different types of files (e.g., C code) and load them based on the filename, using the ":autocmd" command (see |:autocmd|). *viminfo-errors*When Vim detects an error while reading a viminfo file, it will not overwritethat file. If there are more than 10 errors, Vim stops reading the viminfofile. This was done to avoid accidentally destroying a file when the filename of the viminfo file is wrong. This could happen when accidentally typing"vim -i file" when you wanted "vim -R file" (yes, somebody accidentally didthat!). If you want to overwrite a viminfo file with an error in it, you willeither have to fix the error, or delete the file (while Vim is running, somost of the information will be restored). *:rv* *:rviminfo*:rv[iminfo][!] [file] Read from viminfo file [file] (default: see above). If [!] is given, then any information that is already set (registers, marks, etc.) will be overwritten. {not in Vi} *:wv* *:wviminfo*:wv[iminfo][!] [file] Write to viminfo file [file] (default: see above). The information in the file is first read in to make a merge between old and new info. When [!] is used, the old information is not read first, only the internal info is written. If 'viminfo' is empty, marks for up to 100 files will be written. {not in Vi} vim:tw=78:ts=8:sw=8:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -