# vimhelp: user manual: ch40:Make new commands # Copyright (C) 1988-2006 Bram Moolenaar. # This file is distributed under the same license as the vim documentation. # Florian 'eix' Rehnisch , 2009. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: vimhelp 7.0\n" "POT-Creation-Date: 2009-09-24 16:06+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf8\n" "Content-Transfer-Encoding: 8bit" # type: Plain text #: usr_40.txt:2 #, no-wrap msgid "*usr_40.txt*\tFor Vim version 7.0. Last change: 2006 Apr 24\n" msgstr "" # type: Plain text #: usr_40.txt:4 #, no-wrap msgid "\t\t VIM USER MANUAL - by Bram Moolenaar\n" msgstr "" # type: Plain text #: usr_40.txt:6 #, no-wrap msgid "\t\t\t Make new commands\n" msgstr "" # type: Plain text #: usr_40.txt:11 msgid "" "Vim is an extensible editor. You can take a sequence of commands you use " "often and turn it into a new command. Or redefine an existing command. " "Autocommands make it possible to execute commands automatically." msgstr "" # type: Plain text #: usr_40.txt:15 msgid "" "|40.1|\tKey mapping |40.2|\tDefining command-line commands " "|40.3|\tAutocommands" msgstr "" # type: Plain text #: usr_40.txt:19 #, no-wrap msgid "" " Next chapter: |usr_41.txt| Write a Vim script\n" " Previous chapter: |usr_32.txt| The undo tree\n" "Table of contents: |usr_toc.txt|\n" msgstr "" # type: Plain text #: usr_40.txt:20 usr_40.txt:279 usr_40.txt:424 usr_40.txt:652 #, no-wrap msgid "" "==============================================================================\n" msgstr "" # type: Plain text #: usr_40.txt:22 #, no-wrap msgid "*40.1*\tKey mapping\n" msgstr "" # type: Plain text #: usr_40.txt:29 #, no-wrap msgid "" "A simple mapping was explained in section |05.3|. The principle is that " "one\n" "sequence of key strokes is translated into another sequence of key " "strokes.\n" "This is a simple, yet powerful mechanism.\n" " The simplest form is that one key is mapped to a sequence of keys. " "Since\n" "the function keys, except , have no predefined meaning in Vim, these " "are " "a\n" "good choice to map. Example: >\n" msgstr "" # type: Plain text #: usr_40.txt:31 #, no-wrap msgid "\t:map GoDate: :read !datekJ\n" msgstr "" # type: Plain text #: usr_40.txt:43 #, no-wrap msgid "" "This shows how three modes are used. After going to the last line with " "\"G\",\n" "the \"o\" command opens a new line and starts Insert mode. The text " "\"Date: " "\" is\n" "inserted and takes you out of insert mode.\n" " Notice the use of special keys inside <>. This is called angle bracket\n" "notation. You type these as separate characters, not by pressing the key\n" "itself. This makes the mappings better readable and you can copy and " "paste\n" "the text without problems.\n" " The \":\" character takes Vim to the command line. The \":read !date\" " "command\n" "reads the output from the \"date\" command and appends it below the " "current\n" "line. The is required to execute the \":read\" command.\n" " At this point of execution the text looks like this:\n" msgstr "" # type: Plain text #: usr_40.txt:46 #, no-wrap msgid "" "\tDate: ~\n" "\tFri Jun 15 12:54:34 CEST 2001 ~\n" msgstr "" # type: Plain text #: usr_40.txt:49 #, no-wrap msgid "" "Now \"kJ\" moves the cursor up and joins the lines together.\n" " To decide which key or keys you use for mapping, see |map-which-keys|.\n" msgstr "" # type: Plain text #: usr_40.txt:52 msgid "MAPPING AND MODES" msgstr "" # type: Plain text #: usr_40.txt:56 msgid "" "The \":map\" command defines remapping for keys in Normal mode. You can " "also define mappings for other modes. For example, \":imap\" applies to " "Insert mode. You can use it to insert a date below the cursor: >" msgstr "" # type: Plain text #: usr_40.txt:58 #, no-wrap msgid "\t:imap Date: :read !datekJ\n" msgstr "" # type: Plain text #: usr_40.txt:65 #, no-wrap msgid "" "It looks a lot like the mapping for in Normal mode, only the start is\n" "different. The mapping for Normal mode is still there. Thus you can " "map\n" "the same key differently for each mode.\n" " Notice that, although this mapping starts in Insert mode, it ends in " "Normal\n" "mode. If you want it to continue in Insert mode, append an \"a\" to the\n" "mapping.\n" msgstr "" # type: Plain text #: usr_40.txt:67 msgid "Here is an overview of map commands and in which mode they work:" msgstr "" # type: Plain text #: usr_40.txt:75 #, no-wrap msgid "" "\t:map\t\tNormal, Visual and Operator-pending\n" "\t:vmap\t\tVisual\n" "\t:nmap\t\tNormal\n" "\t:omap\t\tOperator-pending\n" "\t:map!\t\tInsert and Command-line\n" "\t:imap\t\tInsert\n" "\t:cmap\t\tCommand-line\n" msgstr "" # type: Plain text #: usr_40.txt:79 msgid "" "Operator-pending mode is when you typed an operator character, such as " "\"d\" " "or \"y\", and you are expected to type the motion command or a text object. " " " "Thus when you type \"dw\", the \"w\" is entered in operator-pending mode." msgstr "" # type: Plain text #: usr_40.txt:85 msgid "" "Suppose that you want to define so that the command d deletes a C " "program block (text enclosed in curly braces, {}). Similarly y would " "yank the program block into the unnamed register. Therefore, what you need " "to do is to define to select the current program block. You can do " "this with the following command: >" msgstr "" # type: Plain text #: usr_40.txt:87 #, no-wrap msgid "\t:omap a{\n" msgstr "" # type: Plain text #: usr_40.txt:91 msgid "" "This causes to perform a select block \"a{\" in operator-pending mode, " "just like you typed it. This mapping is useful if typing a { on your " "keyboard is a bit difficult." msgstr "" # type: Plain text #: usr_40.txt:94 msgid "LISTING MAPPINGS" msgstr "" # type: Plain text #: usr_40.txt:98 msgid "" "To see the currently defined mappings, use \":map\" without arguments. Or " "one of the variants that include the mode in which they work. The output " "could look like this:" msgstr "" # type: Plain text #: usr_40.txt:104 #, no-wrap msgid "" "\t _g\t\t :call MyGrep(1) ~\n" "\tv \t\t :s/^/> /:noh`` ~\n" "\tn \t\t :.,$s/^/> /:noh`` ~\n" "\t \t \n" "\t \t \n" msgstr "" # type: Plain text #: usr_40.txt:113 #, no-wrap msgid "" "The first column of the list shows in which mode the mapping is effective.\n" "This is \"n\" for Normal mode, \"i\" for Insert mode, etc. A blank is used " "for a\n" "mapping defined with \":map\", thus effective in both Normal and Visual " "mode.\n" " One useful purpose of listing the mapping is to check if special keys in " "<>\n" "form have been recognized (this only works when color is supported). For\n" "example, when is displayed in color, it stands for the escape " "character.\n" "When it has the same color as the other text, it is five characters.\n" msgstr "" # type: Plain text #: usr_40.txt:116 msgid "REMAPPING" msgstr "" # type: Plain text #: usr_40.txt:119 msgid "" "The result of a mapping is inspected for other mappings in it. For " "example, " "the mappings for above could be shortened to: >" msgstr "" # type: Plain text #: usr_40.txt:123 #, no-wrap msgid "" "\t:map G\n" "\t:imap \n" "\t:map oDate: :read !datekJ\n" msgstr "" # type: Plain text #: usr_40.txt:127 msgid "" "For Normal mode is mapped to go to the last line, and then behave like " " was pressed. In Insert mode stops Insert mode with and " "then " "also uses . Then is mapped to do the actual work." msgstr "" # type: Plain text #: usr_40.txt:130 msgid "" "Suppose you hardly ever use Ex mode, and want to use the \"Q\" command to " "format text (this was so in old versions of Vim). This mapping will do it: " ">" msgstr "" # type: Plain text #: usr_40.txt:132 #, no-wrap msgid "\t:map Q gq\n" msgstr "" # type: Plain text #: usr_40.txt:135 msgid "" "But, in rare cases you need to use Ex mode anyway. Let's map \"gQ\" to Q, " "so that you can still go to Ex mode: >" msgstr "" # type: Plain text #: usr_40.txt:137 #, no-wrap msgid "\t:map gQ Q\n" msgstr "" # type: Plain text #: usr_40.txt:142 #, no-wrap msgid "" "What happens now is that when you type \"gQ\" it is mapped to \"Q\". So " "far " "so\n" "good. But then \"Q\" is mapped to \"gq\", thus typing \"gQ\" results in " "\"gq\", and\n" "you don't get to Ex mode at all.\n" " To avoid keys to be mapped again, use the \":noremap\" command: >\n" msgstr "" # type: Plain text #: usr_40.txt:144 #, no-wrap msgid "\t:noremap gQ Q\n" msgstr "" # type: Plain text #: usr_40.txt:147 msgid "" "Now Vim knows that the \"Q\" is not to be inspected for mappings that apply " "to it. There is a similar command for every mode:" msgstr "" # type: Plain text #: usr_40.txt:155 #, no-wrap msgid "" "\t:noremap\tNormal, Visual and Operator-pending\n" "\t:vnoremap\tVisual\n" "\t:nnoremap\tNormal\n" "\t:onoremap\tOperator-pending\n" "\t:noremap!\tInsert and Command-line\n" "\t:inoremap\tInsert\n" "\t:cnoremap\tCommand-line\n" msgstr "" # type: Plain text #: usr_40.txt:158 msgid "RECURSIVE MAPPING" msgstr "" # type: Plain text #: usr_40.txt:164 #, no-wrap msgid "" "When a mapping triggers itself, it will run forever. This can be used to\n" "repeat an action an unlimited number of times.\n" " For example, you have a list of files that contain a version number in " "the\n" "first line. You edit these files with \"vim *.txt\". You are now editing " "the\n" "first file. Define this mapping: >\n" msgstr "" # type: Plain text #: usr_40.txt:166 #, no-wrap msgid "\t:map ,, :s/5.1/5.2/:wnext,,\n" msgstr "" # type: Plain text #: usr_40.txt:177 #, no-wrap msgid "" "Now you type \",,\". This triggers the mapping. It replaces \"5.1\" with " "\"5.2\"\n" "in the first line. Then it does a \":wnext\" to write the file and edit " "the\n" "next one. The mapping ends in \",,\". This triggers the same mapping " "again,\n" "thus doing the substitution, etc.\n" " This continues until there is an error. In this case it could be a " "file\n" "where the substitute command doesn't find a match for \"5.1\". You can " "then\n" "make a change to insert \"5.1\" and continue by typing \",,\" again. Or " "the\n" "\":wnext\" fails, because you are in the last file in the list.\n" " When a mapping runs into an error halfway, the rest of the mapping is\n" "discarded. CTRL-C interrupts the mapping (CTRL-Break on MS-Windows).\n" msgstr "" # type: Plain text #: usr_40.txt:180 msgid "DELETE A MAPPING" msgstr "" # type: Plain text #: usr_40.txt:183 msgid "" "To remove a mapping use the \":unmap\" command. Again, the mode the " "unmapping applies to depends on the command used:" msgstr "" # type: Plain text #: usr_40.txt:191 #, no-wrap msgid "" "\t:unmap\t\tNormal, Visual and Operator-pending\n" "\t:vunmap\t\tVisual\n" "\t:nunmap\t\tNormal\n" "\t:ounmap\t\tOperator-pending\n" "\t:unmap!\t\tInsert and Command-line\n" "\t:iunmap\t\tInsert\n" "\t:cunmap\t\tCommand-line\n" msgstr "" # type: Plain text #: usr_40.txt:195 msgid "" "There is a trick to define a mapping that works in Normal and " "Operator-pending mode, but not in Visual mode. First define it for all " "three modes, then delete it for Visual mode: >" msgstr "" # type: Plain text #: usr_40.txt:198 #, no-wrap msgid "" "\t:map /--->\n" "\t:vunmap \n" msgstr "" # type: Plain text #: usr_40.txt:200 msgid "" "Notice that the five characters \"\" stand for the single key CTRL-A." msgstr "" # type: Plain text #: usr_40.txt:204 msgid "" "To remove all mappings use the |:mapclear| command. You can guess the " "variations for different modes by now. Be careful with this command, it " "can't be undone." msgstr "" # type: Plain text #: usr_40.txt:207 msgid "SPECIAL CHARACTERS" msgstr "" # type: Plain text #: usr_40.txt:213 #, no-wrap msgid "" "The \":map\" command can be followed by another command. A | character\n" "separates the two commands. This also means that a | character can't be " "used\n" "inside a map command. To include one, use (five characters). " "Example:\n" ">\n" "\t:map :write !checkin %\n" msgstr "" # type: Plain text #: usr_40.txt:219 #, no-wrap msgid "" "The same problem applies to the \":unmap\" command, with the addition that " "you\n" "have to watch out for trailing white space. These two commands are " "different:\n" ">\n" "\t:unmap a | unmap b\n" "\t:unmap a| unmap b\n" msgstr "" # type: Plain text #: usr_40.txt:221 msgid "The first command tries to unmap \"a \", with a trailing space." msgstr "" # type: Plain text #: usr_40.txt:223 msgid "When using a space inside a mapping, use (seven characters): >" msgstr "" # type: Plain text #: usr_40.txt:225 #, no-wrap msgid "\t:map W\n" msgstr "" # type: Plain text #: usr_40.txt:227 msgid "This makes the spacebar move a blank-separated word forward." msgstr "" # type: Plain text #: usr_40.txt:231 msgid "" "It is not possible to put a comment directly after a mapping, because the " "\" " "character is considered to be part of the mapping. You can use |\", this " "starts a new, empty command with a comment. Example: >" msgstr "" # type: Plain text #: usr_40.txt:233 #, no-wrap msgid "\t:map W| \" Use spacebar to move forward a word\n" msgstr "" # type: Plain text #: usr_40.txt:236 msgid "MAPPINGS AND ABBREVIATIONS" msgstr "" # type: Plain text #: usr_40.txt:249 #, no-wrap msgid "" "Abbreviations are a lot like Insert mode mappings. The arguments are " "handled\n" "in the same way. The main difference is the way they are triggered. An\n" "abbreviation is triggered by typing a non-word character after the word. " "A\n" "mapping is triggered when typing the last character.\n" " Another difference is that the characters you type for an abbreviation " "are\n" "inserted in the text while you type them. When the abbreviation is " "triggered\n" "these characters are deleted and replaced by what the abbreviation " "produces.\n" "When typing the characters for a mapping, nothing is inserted until you " "type\n" "the last character that triggers it. If the 'showcmd' option is set, the\n" "typed characters are displayed in the last line of the Vim window.\n" " An exception is when a mapping is ambiguous. Suppose you have done two\n" "mappings: >\n" msgstr "" # type: Plain text #: usr_40.txt:252 #, no-wrap msgid "" "\t:imap aa foo\n" "\t:imap aaa bar\n" msgstr "" # type: Plain text #: usr_40.txt:258 msgid "" "Now, when you type \"aa\", Vim doesn't know if it should apply the first or " "the second mapping. It waits for another character to be typed. If it is " "an \"a\", the second mapping is applied and results in \"bar\". If it is a " "space, for example, the first mapping is applied, resulting in \"foo\", and " "then the space is inserted." msgstr "" # type: Plain text #: usr_40.txt:261 msgid "ADDITIONALLY..." msgstr "" # type: Plain text #: usr_40.txt:264 msgid "" "The