📄 editing.txt
字号:
*:w_f* *:write_f*:[range]w[rite] {file} Write the specified lines to {file}, unless it already exists and the 'writeany' option is off. *:w!*:[range]w[rite]! {file} Write the specified lines to {file}. Overwrite an existing file. *:w_a* *:write_a*:[range]w[rite][!] >> Append the specified lines to the current file.:[range]w[rite][!] >> {file} Append the specified lines to {file}. '!' forces the write even if file does not exist. *:w_c* *:write_c*:[range]w[rite] !{cmd} Execute {cmd} with [range] lines as standard input (note the space in front of the '!'). {cmd} is executed like with ":!{cmd}", any '!' is replaced with the previous command |:!|.The default [range] for the ":w" command is the whole buffer (1,$).If a file name is given with ":w" it becomes the alternate file. This can beused, for example, when the write fails and you want to try again later with":w #". This can be switched off by removing the 'A' flag from the'cpoptions' option. *:up* *:update*:[range]up[date][!] [>>] [file] Like ":write", but only write when the buffer has been modified. {not in Vi} *:q* *:quit*:q[uit] Quit Vim. This fails when changes have been made and Vim refuses to |abandon| the current buffer, and when not editing the last file in the argument list.:conf[irm] q[uit] Quit, but give prompt when changes have been made, or not editing the last file in the argument list. See |:confirm| and 'confirm'. {not in Vi}:q[uit]! Quit without writing, also when visible buffers have changes. Does not exit when there are changed hidden buffers. Use ":qall!" to exit always.:cq[uit] Quit always, without writing, and return an error code. See |:cq|. Used for Manx's QuickFix mode (see |quickfix|). {not in Vi} *:wq*:wq Write the current file and exit (unless editing the last file in the argument list or the file is read-only).:wq! Write the current file and exit.:wq {file} Write to {file}. Exit if not editing the last file in the argument list.:wq! {file} Write to {file} and exit.:[range]wq[!] [file] Same as above, but only write the lines in [range]. *:x* *:xit*:[range]x[it][!] [file] Like ":wq", but write only when changes have been made. When 'hidden' is set and there are more windows, the current buffer becomes hidden, after writing the file. *:exi* *:exit*:[range]exi[t][!] [file] Same as :xit. *ZZ*ZZ Write current file, if modified, and exit (same as ":x"). (Note: If there are several windows for the current file, the file is written if it was modified and the window is closed). *ZQ*ZQ Quit current file and exit (same as ":q!"). (Note: If there are several windows for the current file, only the window is closed). *timestamp*Vim remembers the modification timestamp of a file when you begin editing it.Before writing a file the timestamp is checked. If it has changed, Vim willask if you really want to overwrite the file: WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)?If you hit 'y' Vim will continue writing the file. If you hit 'n' the write isaborted. If you used ":wq" or "ZZ" Vim will not exit, you will get anotherchance to write the file.Alternatively, after a shell command is run (|:!cmd| |suspend| |:read!| |K|)ALL timestamps are compared. Vim will run any associated |FileChangedShell|autocommands or display the above WARNING for any files that have changed.The message would normally mean that somebody has written to the file afterthe edit session started. This could be another person, in which case youprobably want to check if your changes to the file and the changes from theother person should be merged. Write the file under another name and check fordifferences (the "diff" program can be used for this).It is also possible that you modified the file yourself, from another editsession or with another command (e.g., a filter command). Then you will knowwhich version of the file you want to keep. *backup*If you write to an existing file (but do not append) while the 'backup','writebackup' or 'patchmode' option is on, a backup of the original file ismade. On Unix systems the file is copied, on other systems the file isrenamed. After the file has been successfully written and when the'writebackup' option is on and the 'backup' option is off, the backup file isdeleted. When the 'patchmode' option is on the backup file may be renamed. *backup-table*'backup' 'writebackup' action ~ off off no backup made off on backup current file, deleted afterwards (default) on off delete old backup, backup current file on on delete old backup, backup current fileWhen the 'backup' option is on, an old backup file (with the same name as thenew backup file) will be deleted. If 'backup' is not set, but 'writebackup' isset, an existing backup file will not be deleted. The backup file that is madewhile the file is being written will have a different name.The directories given with the 'backupdir' option is used to put the backupfile in. (default: same directory as the written file).On Unix systems:When you write to an existing file, that file is truncated and then filledwith the new text. This means that protection bits, owner and symbolic linksare unmodified. The backup file however, is a new file, owned by the user whoedited the file. The group of the backup is set to the group of the originalfile. If this fails, the protection bits for the group are made the same asfor others.If the creation of a backup file fails, the write is not done. If you wantto write anyway add a '!' to the command. *write-readonly*When the 'cpoptions' option contains 'W', Vim will refuse to overwrite areadonly file. When 'W' is not present, ":w!" will overwrite a readonly file,if the system allows it (the directory must be writable). *write-fail*If the writing of the new file fails, you have to be careful not to loseyour changes AND the original file. If there is no backup file and writingthe new file failed, you have already lost the original file! DON'T EXIT VIMUNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in placeof the original file (if possible). If you exit Vim, and lose the changesyou made, the original file will mostly still be there. If putting back theoriginal file fails, there will be an error message telling you that youlost the original file. *DOS-format-write*If the 'fileformat' is "dos", <CR> <NL> is used for <EOL>. This is defaultfor MS-DOS, Win32 and OS/2. On other systems the message "[dos format]" isshown to remind you that an unusual <EOL> was used. *Unix-format-write*If the 'fileformat' is "unix", <NL> is used for <EOL>. On MS-DOS, Win32 andOS/2 the message "[unix format]" is shown. *Mac-format-write*If the 'fileformat' is "mac", <CR> is used for <EOL>. On non-Mac systems themessage "[mac format]" is shown.See also |file-formats| and the 'fileformat' and 'fileformats' options.==============================================================================6. Editing binary files *edit-binary*Although Vim was made to edit text files, it is possible to edit binaryfiles. The "-b" Vim argument (b for binary) makes Vim do file I/O in binarymode, and sets some options for editing binary files ('binary' on, 'textwidth'to 0, 'modeline' off, 'expandtab' off). Setting the 'binary' option has thesame effect. Don't forget to do this before reading the file.There are a few things to remember when editing binary files:- When editing executable files the number of characters must not change. Use only the "R" or "r" command to change text. Do not delete characters with "x" or by backspacing.- Set the 'textwidth' option to 0. Otherwise lines will unexpectedly be split in two.- When there are not many <EOL>s, the lines will become very long. If you want to edit a line that does not fit on the screen reset the 'wrap' option. Horizontal scrolling is used then. If a line becomes too long (more than about 32767 characters on the Amiga, much more on 32-bit systems, see |limits|) you cannot edit that line. The line will be split when reading the file. It is also possible that you get an "out of memory" error when reading the file.- Make sure the 'binary' option is set BEFORE loading the file. Otherwise both <CR> <NL> and <NL> are considered to end a line and when the file is written the <NL> will be replaced with <CR> <NL>.- <Nul> characters are shown on the screen as ^@. You can enter them with "CTRL-V CTRL-@" or "CTRL-V 000" {Vi cannot handle <Nul> characters in the file}- To insert a <NL> character in the file split up a line. When writing the buffer to a file a <NL> will be written for the <EOL>.- Vim normally appends an <EOL> at the end of the file if there is none. Setting the 'binary' option prevents this. If you want to add the final <EOL>, set the 'endofline' option. You can also read the value of this option to see if there was an <EOL> for the last line (you cannot see this in the text).==============================================================================7. Encryption *encryption*Vim is able to write files encrypted, and read them back. The encrypted textcannot be read without the right key.Note: The swapfile and text in memory are not encrypted. A systemadministrator will be able to see your text while you are editing it.WARNING: If you make a typo when entering the key and then write the file andexit, the text will be lost!The normal way to work with encryption, is to use the ":X" command, which willask you to enter a key. A following write command will use that key toencrypt the file. If you later edit the same file, Vim will ask you to entera key. If you type the same key as that was used for writing, the text willbe readable again. If you use a wrong key, it will be a mess. *:X*:X Prompt for an encryption key. The typing is done without showing the actual text, so that someone looking at the display won't see it. The typed key is stored in the 'key' option, which is used to encrypt the file when it is written. See also |-x|.The value of the 'key' options is used when text is written. When the optionis not empty, the written file will be encrypted, using the value as theencryption key. A magic number is prepended, so that Vim can recognize thatthe file is encrypted.To disable the encryption, reset the 'key' option to an empty value:> :set key=When reading a file that has been encrypted and this option is not empty, itwill be used for decryption. If the value is empty, you will be prompted toenter the key. If you don't enter a key, the file is edited without beingdecrypted.If want to start reading a file that uses a different key, set the 'key'option to an empty string, so that Vim will prompt for a new one. Don't usethe ":set" command to enter the value, other people can read the command overyour shoulder.Since the value of the 'key' option is supposed to be a secret, its value cannever be viewed. You should not set this option in a vimrc file.An encrypted file can be recognized by the "file" command, if you add thisline to "/etc/magic", "/usr/share/misc/magic" or wherever your system has the"magic" file:> 0 string VimCrypt~ Vim encrypted fileNotes:- Text you copy or delete goes to the numbered registers. The registers can be saved in the .viminfo file, where they could be read. Change your 'viminfo' option to be safe.- Someone can type commands in Vim when you walk away for a moment, he should not be able to get the key.- If you make a typing mistake when entering the key, you might not be able to get your text back!- If you type the key with a ":set key=value" command, it can be kept in the history, showing the 'key' value in a viminfo file.- There is never 100% safety. The encryption in Vim has not been tested for robustness.- The algorithm used is breakable. A 4 character key in about one hour, a 6 character key in one day (on a Pentium 133 PC). This requires that you know some text that must appear in the file. An expert can break it for any key.- Pkzip uses the same encryption, and US Govt has no objection to its export. Pkzip's public file APPNOTE.TXT describes this algorithm in detail.- Vim originates from the Netherlands. That is where the sources come from. Thus the encryption code is not exported from the USA. vim:tw=78:ts=8:sw=8:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -