# Vimhelp -- User Manual -- Chapter 12 -- Clever tricks # Copyright (C) 2006 Bram Moolenaar. # Florian 'eix' Rehnisch , 2008. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: vimhelp 7.0.122\n" "POT-Creation-Date: 2008-03-22 22:10+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: German \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf8\n" "Content-Transfer-Encoding: 8bit" # type: Plain text #: usr_12.txt:2 #, no-wrap msgid "*usr_12.txt*\tFor Vim version 7.0. Last change: 2006 Apr 24\n" msgstr "" # type: Plain text #: usr_12.txt:4 #, no-wrap msgid "\t\t VIM USER MANUAL - by Bram Moolenaar\n" msgstr "" # type: Plain text #: usr_12.txt:6 #, no-wrap msgid "\t\t\t\tClever tricks\n" msgstr "" # type: Plain text #: usr_12.txt:11 msgid "" "By combining several commands you can make Vim do nearly everything. In " "this chapter a number of useful combinations will be presented. This uses " "the commands introduced in the previous chapters and a few more." msgstr "" # type: Plain text #: usr_12.txt:20 msgid "" "|12.1|\tReplace a word |12.2|\tChange \"Last, First\" to \"First Last\" " "|12.3|\tSort a list |12.4|\tReverse line order |12.5|\tCount words " "|12.6|\tFind a man page |12.7|\tTrim blanks |12.8|\tFind where a word is " "used" msgstr "" # type: Plain text #: usr_12.txt:24 #, no-wrap msgid "" " Next chapter: |usr_20.txt| Typing command-line commands quickly\n" " Previous chapter: |usr_11.txt| Recovering from a crash\n" "Table of contents: |usr_toc.txt|\n" msgstr "" # type: Plain text #: usr_12.txt:25 usr_12.txt:90 usr_12.txt:131 usr_12.txt:177 usr_12.txt:202 usr_12.txt:231 usr_12.txt:281 usr_12.txt:309 usr_12.txt:354 #, no-wrap msgid "==============================================================================\n" msgstr "" # type: Plain text #: usr_12.txt:27 #, no-wrap msgid "*12.1*\tReplace a word\n" msgstr "" # type: Plain text #: usr_12.txt:30 msgid "" "The substitute command can be used to replace all occurrences of a word with " "another word: >" msgstr "" # type: Plain text #: usr_12.txt:32 #, no-wrap msgid "\t:%s/four/4/g\n" msgstr "" # type: Plain text #: usr_12.txt:38 #, no-wrap msgid "" "The \"%\" range means to replace in all lines. The \"g\" flag at the end " "causes\n" "all words in a line to be replaced.\n" " This will not do the right thing if your file also contains " "\"thirtyfour\".\n" "It would be replaced with \"thirty4\". To avoid this, use the \"\\<\" item " "to\n" "match the start of a word: >\n" msgstr "" # type: Plain text #: usr_12.txt:40 #, no-wrap msgid "\t:%s/\\\" to match the " "end of a word: >" msgstr "" # type: Plain text #: usr_12.txt:45 #, no-wrap msgid "\t:%s/\\/4/g\n" msgstr "" # type: Plain text #: usr_12.txt:49 msgid "" "If you are programming, you might want to replace \"four\" in comments, but " "not in the code. Since this is difficult to specify, add the \"c\" flag to " "have the substitute command prompt you for each replacement: >" msgstr "" # type: Plain text #: usr_12.txt:52 #, no-wrap msgid "\t:%s/\\/4/gc\n" msgstr "" # type: Plain text #: usr_12.txt:55 msgid "REPLACING IN SEVERAL FILES" msgstr "" # type: Plain text #: usr_12.txt:61 #, no-wrap msgid "" "Suppose you want to replace a word in more than one file. You could edit " "each\n" "file and type the command manually. It's a lot faster to use record and\n" "playback.\n" " Let's assume you have a directory with C++ files, all ending in " "\".cpp\".\n" "There is a function called \"GetResp\" that you want to rename to " "\"GetAnswer\".\n" msgstr "" # type: Plain text #: usr_12.txt:74 #, no-wrap msgid "" "\tvim *.cpp\t\tStart Vim, defining the argument list to\n" "\t\t\t\tcontain all the C++ files. You are now in the\n" "\t\t\t\tfirst file.\n" "\tqq\t\t\tStart recording into the q register\n" "\t:%s/\\/GetAnswer/g\n" "\t\t\t\tDo the replacements in the first file.\n" "\t:wnext\t\t\tWrite this file and move to the next one.\n" "\tq\t\t\tStop recording.\n" "\t@q\t\t\tExecute the q register. This will replay the\n" "\t\t\t\tsubstitution and \":wnext\". You can verify\n" "\t\t\t\tthat this doesn't produce an error message.\n" "\t999@q\t\t\tExecute the q register on the remaining files.\n" msgstr "" # type: Plain text #: usr_12.txt:77 msgid "" "At the last file you will get an error message, because \":wnext\" cannot " "move to the next file. This stops the execution, and everything is done." msgstr "" # type: Plain text #: usr_12.txt:81 #, no-wrap msgid "" "\tNote:\n" "\tWhen playing back a recorded sequence, an error stops the execution.\n" "\tTherefore, make sure you don't get an error message when recording.\n" msgstr "" # type: Plain text #: usr_12.txt:85 msgid "" "There is one catch: If one of the .cpp files does not contain the word " "\"GetResp\", you will get an error and replacing will stop. To avoid this, " "add the \"e\" flag to the substitute command: >" msgstr "" # type: Plain text #: usr_12.txt:87 #, no-wrap msgid "\t:%s/\\/GetAnswer/ge\n" msgstr "" # type: Plain text #: usr_12.txt:89 msgid "" "The \"e\" flag tells \":substitute\" that not finding a match is not an " "error." msgstr "" # type: Plain text #: usr_12.txt:92 #, no-wrap msgid "*12.2*\tChange \"Last, First\" to \"First Last\"\n" msgstr "" # type: Plain text #: usr_12.txt:94 msgid "You have a list of names in this form:" msgstr "" # type: Plain text #: usr_12.txt:97 #, no-wrap msgid "" "\tDoe, John ~\n" "\tSmith, Peter ~\n" msgstr "" # type: Plain text #: usr_12.txt:99 msgid "You want to change that to:" msgstr "" # type: Plain text #: usr_12.txt:102 #, no-wrap msgid "" "\tJohn Doe ~\n" "\tPeter Smith ~\n" msgstr "" # type: Plain text #: usr_12.txt:104 msgid "This can be done with just one command: >" msgstr "" # type: Plain text #: usr_12.txt:106 #, no-wrap msgid "\t:%s/\\([^,]*\\), \\(.*\\)/\\2 \\1/\n" msgstr "" # type: Plain text #: usr_12.txt:114 #, no-wrap msgid "" "Let's break this down in parts. Obviously it starts with a substitute\n" "command. The \"%\" is the line range, which stands for the whole file. " "Thus\n" "the substitution is done in every line in the file.\n" " The arguments for the substitute command are \"/from/to/\". The " "slashes\n" "separate the \"from\" pattern and the \"to\" string. This is what the " "\"from\"\n" "pattern contains:\n" "\t\t\t\t\t\t\t\\([^,]*\\), \\(.*\\) ~\n" msgstr "" # type: Plain text #: usr_12.txt:122 #, no-wrap msgid "" "\tThe first part between \\( \\) matches \"Last\"\t\\( \\)\n" "\t match anything but a comma\t\t\t [^,]\n" "\t any number of times\t\t\t\t *\n" "\tmatches \", \" literally\t\t\t\t\t ,\n" "\tThe second part between \\( \\) matches \"First\"\t\t \\( \\)\n" "\t any character\t\t\t\t\t .\n" "\t any number of times\t\t\t\t\t *\n" msgstr "" # type: Plain text #: usr_12.txt:130 #, no-wrap msgid "" "In the \"to\" part we have \"\\2\" and \"\\1\". These are called " "backreferences.\n" "They refer to the text matched by the \"\\( \\)\" parts in the pattern. " "\"\\2\"\n" "refers to the text matched by the second \"\\( \\)\", which is the \"First\" " "name.\n" "\"\\1\" refers to the first \"\\( \\)\", which is the \"Last\" name.\n" " You can use up to nine backreferences in the \"to\" part of a " "substitute\n" "command. \"\\0\" stands for the whole matched pattern. There are a few " "more\n" "special items in a substitute command, see |sub-replace-special|.\n" msgstr "" # type: Plain text #: usr_12.txt:133 #, no-wrap msgid "*12.3*\tSort a list\n" msgstr "" # type: Plain text #: usr_12.txt:135 msgid "In a Makefile you often have a list of files. For example:" msgstr "" # type: Plain text #: usr_12.txt:145 #, no-wrap msgid "" "\tOBJS = \\ ~\n" "\t\tversion.o \\ ~\n" "\t\tpch.o \\ ~\n" "\t\tgetopt.o \\ ~\n" "\t\tutil.o \\ ~\n" "\t\tgetopt1.o \\ ~\n" "\t\tinp.o \\ ~\n" "\t\tpatch.o \\ ~\n" "\t\tbackup.o ~\n" msgstr "" # type: Plain text #: usr_12.txt:147 msgid "To sort this list, filter the text through the external sort command: >" msgstr "" # type: Plain text #: usr_12.txt:151 #, no-wrap msgid "" "\t/^OBJS\n" "\tj\n" "\t:.,/^$/-1!sort\n" msgstr "" # type: Plain text #: usr_12.txt:157 #, no-wrap msgid "" "This goes to the first line, where \"OBJS\" is the first thing in the " "line.\n" "Then it goes one line down and filters the lines until the next empty " "line.\n" "You could also select the lines in Visual mode and then use \"!sort\". " "That's\n" "easier to type, but more work when there are many lines.\n" " The result is this:\n" msgstr "" # type: Plain text #: usr_12.txt:167 #, no-wrap msgid "" "\tOBJS = \\ ~\n" "\t\tbackup.o ~\n" "\t\tgetopt.o \\ ~\n" "\t\tgetopt1.o \\ ~\n" "\t\tinp.o \\ ~\n" "\t\tpatch.o \\ ~\n" "\t\tpch.o \\ ~\n" "\t\tutil.o \\ ~\n" "\t\tversion.o \\ ~\n" msgstr "" # type: Plain text #: usr_12.txt:176 #, no-wrap msgid "" "Notice that a backslash at the end of each line is used to indicate the " "line\n" "continues. After sorting, this is wrong! The \"backup.o\" line that was " "at\n" "the end didn't have a backslash. Now that it sorts to another place, it\n" "must have a backslash.\n" " The simplest solution is to add the backslash with \"A \\\". You " "can\n" "keep the backslash in the last line, if you make sure an empty line comes\n" "after it. That way you don't have this problem again.\n" msgstr "" # type: Plain text #: usr_12.txt:179 #, no-wrap msgid "*12.4*\tReverse line order\n" msgstr "" # type: Plain text #: usr_12.txt:182 msgid "" "The |:global| command can be combined with the |:move| command to move all " "the lines before the first line, resulting in a reversed file. The command " "is: >" msgstr "" # type: Plain text #: usr_12.txt:184 #, no-wrap msgid "\t:global/^/m 0\n" msgstr "" # type: Plain text #: usr_12.txt:186 msgid "Abbreviated: >" msgstr "" # type: Plain text #: usr_12.txt:188 #, no-wrap msgid "\t:g/^/m 0\n" msgstr "" # type: Plain text #: usr_12.txt:195 msgid "" "The \"^\" regular expression matches the beginning of the line (even if the " "line is blank). The |:move| command moves the matching line to after the " "mythical zeroth line, so the current matching line becomes the first line of " "the file. As the |:global| command is not confused by the changing line " "numbering, |:global| proceeds to match all remaining lines of the file and " "puts each as the first." msgstr "" # type: Plain text #: usr_12.txt:199 msgid "" "This also works on a range of lines. First move to above the first line and " "mark it with \"mt\". Then move the cursor to the last line in the range and " "type: >" msgstr "" # type: Plain text #: usr_12.txt:201 #, no-wrap msgid "\t:'t+1,.g/^/m 't\n" msgstr "" # type: Plain text #: usr_12.txt:204 #, no-wrap msgid "*12.5*\tCount words\n" msgstr "" # type: Plain text #: usr_12.txt:209 #, no-wrap msgid "" "Sometimes you have to write a text with a maximum number of words. Vim " "can\n" "count the words for you.\n" " When the whole file is what you want to count the words in, use this\n" "command: >\n" msgstr "" # type: Plain text #: usr_12.txt:211 #, no-wrap msgid "\tg CTRL-G\n" msgstr "" # type: Plain text #: usr_12.txt:215 #, no-wrap msgid "" "Do not type a space after the g, this is just used here to make the " "command\n" "easy to read.\n" " The output looks like this:\n" msgstr "" # type: Plain text #: usr_12.txt:217 #, no-wrap msgid "\tCol 1 of 0; Line 141 of 157; Word 748 of 774; Byte 4489 of 4976 ~\n" msgstr "" # type: Plain text #: usr_12.txt:220 msgid "" "You can see on which word you are (748), and the total number of words in " "the file (774)." msgstr "" # type: Plain text #: usr_12.txt:226 msgid "" "When the text is only part of a file, you could move to the start of the " "text, type \"g CTRL-G\", move to the end of the text, type \"g CTRL-G\" " "again, and then use your brain to compute the difference in the word " "position. That's a good exercise, but there is an easier way. With Visual " "mode, select the text you want to count words in. Then type g CTRL-G. The " "result:" msgstr "" # type: Plain text #: usr_12.txt:228 #, no-wrap msgid "\tSelected 5 of 293 Lines; 70 of 1884 Words; 359 of 10928 Bytes ~\n" msgstr "" # type: Plain text #: usr_12.txt:230 msgid "For other ways to count words, lines and other items, see |count-items|." msgstr "" # type: Plain text #: usr_12.txt:233 #, no-wrap msgid "*12.6*\tFind a man page\t\t\t\t\t*find-manpage*\n" msgstr "" # type: Plain text #: usr_12.txt:237 msgid "" "While editing a shell script or C program, you are using a command or " "function that you want to find the man page for (this is on Unix). Let's " "first use a simple way: Move the cursor to the word you want to find help on " "and press >" msgstr "" # type: Plain text #: usr_12.txt:239 #, no-wrap msgid "\tK\n" msgstr "" # type: Plain text #: usr_12.txt:244 msgid "" "Vim will run the external \"man\" program on the word. If the man page is " "found, it is displayed. This uses the normal pager to scroll through the " "text (mostly the \"more\" program). When you get to the end pressing " " will get you back into Vim." msgstr "" # type: Plain text #: usr_12.txt:248 msgid "" "A disadvantage is that you can't see the man page and the text you are " "working on at the same time. There is a trick to make the man page appear " "in a Vim window. First, load the man filetype plugin: >" msgstr "" # type: Plain text #: usr_12.txt:250 #, no-wrap msgid "\t:runtime! ftplugin/man.vim\n" msgstr "" # type: Plain text #: usr_12.txt:253 msgid "" "Put this command in your vimrc file if you intend to do this often. Now you " "can use the \":Man\" command to open a window on a man page: >" msgstr "" # type: Plain text #: usr_12.txt:255 #, no-wrap msgid "\t:Man csh\n" msgstr "" # type: Plain text #: usr_12.txt:261 #, no-wrap msgid "" "You can scroll around and the text is highlighted. This allows you to " "find\n" "the help you were looking for. Use CTRL-W w to jump to the window with " "the\n" "text you were working on.\n" " To find a man page in a specific section, put the section number first.\n" "For example, to look in section 3 for \"echo\": >\n" msgstr "" # type: Plain text #: usr_12.txt:263 #, no-wrap msgid "\t:Man 3 echo\n" msgstr "" # type: Plain text #: usr_12.txt:267 msgid "" "To jump to another man page, which is in the text with the typical form " "\"word(1)\", press CTRL-] on it. Further \":Man\" commands will use the " "same window." msgstr "" # type: Plain text #: usr_12.txt:269 msgid "To display a man page for the word under the cursor, use this: >" msgstr "" # type: Plain text #: usr_12.txt:271 #, no-wrap msgid "\t\\K\n" msgstr "" # type: Plain text #: usr_12.txt:275 msgid "" "(If you redefined the , use it instead of the backslash). For " "example, you want to know the return value of \"strstr()\" while editing " "this line:" msgstr "" # type: Plain text #: usr_12.txt:277 #, no-wrap msgid "\tif ( strstr (input, \"aap\") == ) ~\n" msgstr "" # type: Plain text #: usr_12.txt:280 msgid "" "Move the cursor to somewhere on \"strstr\" and type \"\\K\". A window will " "open to display the man page for strstr()." msgstr "" # type: Plain text #: usr_12.txt:283 #, no-wrap msgid "*12.7*\tTrim blanks\n" msgstr "" # type: Plain text #: usr_12.txt:287 msgid "" "Some people find spaces and tabs at the end of a line useless, wasteful, and " "ugly. To remove whitespace at the end of every line, execute the following " "command: >" msgstr "" # type: Plain text #: usr_12.txt:289 #, no-wrap msgid "\t:%s/\\s\\+$//\n" msgstr "" # type: Plain text #: usr_12.txt:296 #, no-wrap msgid "" "The line range \"%\" is used, thus this works on the whole file. The " "pattern\n" "that the \":substitute\" command matches with is \"\\s\\+$\". This finds " "white\n" "space characters (\\s), 1 or more of them (\\+), before the end-of-line " "($).\n" "Later will be explained how you write patterns like this |usr_27.txt|.\n" " The \"to\" part of the substitute command is empty: \"//\". Thus it " "replaces\n" "with nothing, effectively deleting the matched white space.\n" msgstr "" # type: Plain text #: usr_12.txt:300 msgid "" "Another wasteful use of spaces is placing them before a Tab. Often these " "can be deleted without changing the amount of white space. But not always! " "Therefore, you can best do this manually. Use this search command: >" msgstr "" # type: Plain text #: usr_12.txt:302 #, no-wrap msgid "\t/ \t\n" msgstr "" # type: Plain text #: usr_12.txt:308 #, no-wrap msgid "" "You cannot see it, but there is a space before a tab in this command. " "Thus\n" "it's \"/\". Now use \"x\" to delete the space and check that " "the\n" "amount of white space doesn't change. You might have to insert a Tab if " "it\n" "does change. Type \"n\" to find the next match. Repeat this until no " "more\n" "matches can be found.\n" msgstr "" # type: Plain text #: usr_12.txt:311 #, no-wrap msgid "*12.8*\tFind where a word is used\n" msgstr "" # type: Plain text #: usr_12.txt:318 #, no-wrap msgid "" "If you are a UNIX user, you can use a combination of Vim and the grep " "command\n" "to edit all the files that contain a given word. This is extremely useful " "if\n" "you are working on a program and want to view or edit all the files that\n" "contain a specific variable.\n" " For example, suppose you want to edit all the C program files that " "contain\n" "the word \"frame_counter\". To do this you use the command: >\n" msgstr "" # type: Plain text #: usr_12.txt:320 #, no-wrap msgid "\tvim `grep -l frame_counter *.c`\n" msgstr "" # type: Plain text #: usr_12.txt:333 #, no-wrap msgid "" "Let's look at this command in detail. The grep command searches through a " "set\n" "of files for a given word. Because the -l argument is specified, the " "command\n" "will only list the files containing the word and not print the matching " "lines.\n" "The word it is searching for is \"frame_counter\". Actually, this can be " "any\n" "regular expression. (Note: What grep uses for regular expressions is not\n" "exactly the same as what Vim uses.)\n" " The entire command is enclosed in backticks (`). This tells the UNIX " "shell\n" "to run this command and pretend that the results were typed on the command\n" "line. So what happens is that the grep command is run and produces a list " "of\n" "files, these files are put on the Vim command line. This results in Vim\n" "editing the file list that is the output of grep. You can then use " "commands\n" "like \":next\" and \":first\" to browse through the files.\n" msgstr "" # type: Plain text #: usr_12.txt:336 msgid "FINDING EACH LINE" msgstr "" # type: Plain text #: usr_12.txt:342 #, no-wrap msgid "" "The above command only finds the files in which the word is found. You " "still\n" "have to find the word within the files.\n" " Vim has a built-in command that you can use to search a set of files for " "a\n" "given string. If you want to find all occurrences of \"error_string\" in " "all C\n" "program files, for example, enter the following command: >\n" msgstr "" # type: Plain text #: usr_12.txt:344 #, no-wrap msgid "\t:grep error_string *.c\n" msgstr "" # type: Plain text #: usr_12.txt:353 #, no-wrap msgid "" "This causes Vim to search for the string \"error_string\" in all the " "specified\n" "files (*.c). The editor will now open the first file where a match is " "found\n" "and position the cursor on the first matching line. To go to the next\n" "matching line (no matter in what file it is), use the \":cnext\" command. " "To go\n" "to the previous match, use the \":cprev\" command. Use \":clist\" to see " "all the\n" "matches and where they are.\n" " The \":grep\" command uses the external commands grep (on Unix) or " "findstr\n" "(on Windows). You can change this by setting the option 'grepprg'.\n" msgstr "" # type: Plain text #: usr_12.txt:357 msgid "Next chapter: |usr_20.txt| Typing command-line commands quickly" msgstr "" # type: Plain text #: usr_12.txt:358 msgid "Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl:" msgstr ""