Movatterモバイル変換


[0]ホーム

URL:


Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq
Go to keyword (shortcut:k)
Site search (shortcut:s)
usr_20.txt  ForVim version 9.2.  Last change: 2026 Feb 14     VIM USER MANUALbyBramMoolenaar     Typing command-line commands quicklyVim hasa few generic features that makesit easier to enter commands.  Coloncommands can be abbreviated, edited and repeated.  Completionis available fornearly everything.20.1  Command line editing20.2  Command lineabbreviations20.3  Command line completion20.4  Command linehistory20.5  Command linewindow     Next chapter:usr_21.txt  Go away and come back Previous chapter:usr_12.txt  Clever tricksTable of contents:usr_toc.txt==============================================================================20.1  Command line editingWhen you usea colon (:) command or search forastring with/ or ?, Vim putsthe cursor on the bottom of the screen.  There you type the command or searchpattern.  Thisis called the Command line.  Also when it's used for enteringasearch command.The most obvious way to edit the command you typeis by pressing the<BS> key.This erases the character before the cursor.  To erase another character,typed earlier, first move the cursor with the cursor keys.   For example, you have typed this::s/col/pig/Before you hit<Enter>, you notice that "col" should be "cow".  To correctthis, you type<Left> five times.  The cursoris now just after "col".  Type<BS> and "w" to correct::s/cow/pig/Now you can press<Enter> directly.  You don't have to move the cursor to theend of the line before executing the command.The most often used keys to move around in the command line:<Left>one character left<Right>one character right<S-Left> or<C-Left>oneword left<S-Right> or<C-Right>oneword rightCTRL-B or<Home>to begin of command lineCTRL-E or<End>toend of command lineNote:<S-Left> (cursor left key with Shift key pressed) and<C-Left> (cursorleft key with Control pressed) will not work on all keyboards.  Samefor the other Shift and Control combinations.You can also use the mouse to move the cursor.DELETINGAs mentioned,<BS> deletes the character before the cursor.  To deletea wholeword useCTRL-W./the fine pigCTRL-W/the fineCTRL-U removes all text, thus allows you to start all over again.OVERSTRIKEThe<Insert> key toggles betweeninserting characters andreplacing theexisting ones.  Start with this text:/the fine pigMove the cursor to the start of "fine" with<S-Left> twice (or<Left> eighttimes, if<S-Left> doesn't work).  Now press<Insert> to switch to overstrikeand type "great":/the greatpigOops, we lost the space.  Now, don't use<BS>, becauseit would delete the"t" (thisis different fromReplace mode).  Instead, press<Insert> to switchfrom overstrike to inserting, and type the space:/the great pigCANCELLINGYou thought of executinga: or/ command, but changed your mind.  To get ridof what you already typed, without executing it, pressCTRL-C or<Esc>.Note:<Esc>is the universal "get out" key.  Unfortunately, in the good oldVi pressing<Esc> ina command line executed the command!  Since thatmight be considered to bea bug, Vim uses<Esc> to cancel the command.But with the'cpoptions' optionit can be madeVi compatible.  Andwhen usingamapping (which might be written for Vi)<Esc> also worksVi compatible.  Therefore, usingCTRL-Cisamethod that always works.If you areat the start of the command line, pressing<BS> will cancel thecommand.  It's likedeleting the ":" or "/" that the line starts with.==============================================================================20.2  Command lineabbreviationsSome of the ":" commands are really long.  We already mentioned that":substitute" can be abbreviated to ":s".  Thisisa generic mechanism, all":" commands can be abbreviated.How short cana command get?  There are 26 letters, and many more commands.For example, ":set" also starts with ":s", but ":s" doesn't starta ":set"command.  Instead ":set" can be abbreviated to ":se".   When the shorter form ofa command could be used for two commands,itstands for only one of them.  Thereis no logic behind which one, you have tolearn them.  In thehelp files the shortest form that worksis mentioned.  Forexample::s[ubstitute]This means that the shortest form of ":substitute"is ":s".  The followingcharacters are optional.  Thus ":su" and ":sub" also work.In the user manual we will either use the full name of command, ora shortversion thatis still readable.  For example, ":function" can be abbreviatedto ":fu".  But since most people don't understand what that stands for, wewill use ":fun".  (Vim doesn't havea ":funny" command, otherwise ":fun" wouldbe confusing too.)Itis recommended that in Vim scripts you write the full command name.  Thatmakesit easier to read back when you make later changes.  Except for someoften used commands like ":w"(":write") and ":r"(":read").A particularly confusing oneis ":end", which could stand for ":endif",":endwhile" or ":endfunction".  Therefore, always use the full name.SHORT OPTION NAMESIn the user manual the long version of the option namesis used.  Manyoptionsalso havea short name.  Unlike ":" commands, thereis only one short namethat works.  For example, the short name of'autoindent'is'ai'.  Thus thesetwo commandsdo the same thing::set autoindent:set aiYou can find the fulllist of long and short names here:option-list.==============================================================================20.3  Command line completionThisis one of those Vim features that, by itself,isa reason to switch fromVi to Vim.  Once you have used this, you can'tdo without.Suppose you havea directory that contains these files:info.txtintro.txtbodyofthepaper.txtTo edit the last one, you use the command::edit bodyofthepaper.txtIt'seasy to type this wrong.A much quicker way is::edit b<Tab>Which will result in the same command.  What happened?  The<Tab> key doescompletion of theword before the cursor.  In thiscase "b".  Vim looks in thedirectory and finds only one file that starts witha "b".  Thatmust be theone you are looking for, thus Vim completes the file name for you.Now type::edit i<Tab>Vim will beep, and give you::edit info.txtThebeep means that Vim has found more than one match.  It then uses the firstmatchit found (alphabetically).  If you press<Tab> again, you get::edit intro.txtThus, if the first<Tab> doesn't give you the file you were looking for, pressit again.  If there are more matches, you will see them all, oneata time.   If you press<Tab> on the last matching entry, you willgo back to what youfirst typed::edit iThenit starts all over again.  Thus Vim cycles through thelist of matches.UseCTRL-P togo through thelist in the other direction:      <-------------------<Tab> -------------------------+  |<Tab> --><Tab> -->:editi:edit info.txt:editintro.txt  <--CTRL-P       <--CTRL-P   |   +----------------------CTRL-P ------------------------>CONTEXTWhen you type ":seti" instead of ":editi" and press<Tab> you get::set iconHey, why didn't you get ":set info.txt"?  That's because Vim has contextsensitive completion.  The kind of words Vim will look for depends on thecommand before it.  Vim knows that you cannot usea file name just aftera":set" command, but you can use an option name.   Again, if you repeat typing the<Tab>, Vim will cycle through all matches.There are quitea few, it's better to type more characters first::set isk<Tab>Gives::set iskeywordNow type "=" and press<Tab>::set iskeyword=@,48-57,_,192-255What happens hereis that Vim inserts the old value of the option.  Now youcan edit it.   Whatis completed with<Tab>is what Vim expects in that place.  Just tryit out to see howit works.  In some situations you will not get what youwant.  That's either because Vim doesn't know what you want, or becausecompletion was not implemented for that situation.  In thatcase you will geta<Tab> inserted (displayedas ^I).LIST MATCHESWhen there are many matches, you would like to see an overview.  Do this bypressingCTRL-D.  For example, pressingCTRL-D after::set isresults in::set isincsearch  isfname    isident    iskeyword  isprint:set isVim lists the matches and then comes back with the text you typed.  You cannow check thelist for the item you wanted.  Ifit isn't there, you can use<BS> to correct the word.  If there are many matches, typea few morecharacters before pressing<Tab> to complete the rest.   If you have watched carefully, you will have noticed that "incsearch"doesn't start with "is".  In thiscase "is" stands for the short name of"incsearch".  (Manyoptions havea short anda long name.)  Vimis cleverenough to know that you might have wanted to expand the short name of theoption into the long name.THERE IS MORETheCTRL-L command completes theword to the longest unambiguous string.  Ifyou type ":editi" and there are files "info.txt" and "info_backup.txt" youwill get ":edit info".The'wildmode' option can be used to change the way completion works.The'wildmenu' option can be used to geta menu-likelist of matches.Use the'suffixes' option to specify files that areless important and appearat theend of thelist of files.The'wildignore' optionspecifies files that are not listedat all.More about all of this here:cmdline-completion==============================================================================20.4  Command linehistoryIn chapter 3 we briefly mentioned the history.  The basics are that you canuse the<Up> key to recall an older command line.<Down> then takes you backto newer commands.There are actually five histories.  The ones we will mention here are for ":"commands and for "/" and "?" search commands.  The "/" and "?" commands sharethe same history, because they are both search commands.  The three otherhistories are for expressions, debug mode commands and input lines for theinput() function.cmdline-historySuppose you have donea ":set" command, typed ten more colon commands and thenwant to repeat that ":set" command again.  You could press ":" and then tentimes<Up>.  Thereisa quicker way::se<Up>Vim will nowgo back to the previous command that started with "se".  You havea good chance that thisis the ":set" command you were looking for.  At leastyou should not have to press<Up> very often (unless ":set" commandsis allyou have done).The<Up> key will use the text typed so far and compareit with the lines inthe history.  Only matching lines will be used.   If youdo not find the line you were looking for, use<Down> togo back towhat you typed and correct that.  Or useCTRL-U to start all over again.To see all the lines in the history::historyThat's thehistory of ":" commands.  The searchhistoryis displayed with thiscommand::history /CTRL-P will work like<Up>, except thatit doesn't matter what you alreadytyped.  Similarly forCTRL-N and<Down>.CTRL-P stands for previous,CTRL-Nfor next.==============================================================================20.5  Command linewindowTyping the text in the command line works differently from typing text inInsert mode.  It doesn't allow many commands to change the text.  For mostcommands that's OK, but sometimes you have to typea complicated command.That's where the command linewindowis useful.Open the command linewindow with this command:q:Vim now opensa (small)windowat the bottom.  It contains the command linehistory, and an empty lineat the end:+-------------------------------------+|otherwindow      ||~      |file.txt=============================|:ec      ||:e config.h.in      ||:set path=.,/usr/include,,      ||:set iskeyword=@,48-57,_,192-255     ||:setis      ||:q      ||:      |command-line=========================|      |+-------------------------------------+You are now inNormal mode.  You can use the "hjkl" keys to move around.  Forexample, move up with "5k" to the ":e config.h.in" line.  Type "$h" togo tothe "i" of "in" and type "cwout".  Now you have changed the line to::e config.h.outNow press<Enter> and this command will be executed.  The command linewindowwill close.   The<Enter> command will execute the line under the cursor.  It doesn'tmatter whether Vimis inInsert mode or inNormal mode.   Changes in the command linewindow are lost.  Theydo not result in thehistory to be changed.  Except that the command you execute will be added totheend of the history, like with all executed commands.The command linewindowis very useful when you want to have overview of thehistory, lookupa similar command, changeita bit and execute it.A searchcommand can be used to find something.   In the previous example the "?config" search command could have been usedto find the previous command that contains "config".  It'sa bit strange,because you are usinga command line to search in the command line window.While typing that search command you can't open another command line window,there can be only one.==============================================================================Next chapter:usr_21.txt  Go away and come backCopyright: seemanual-copyright  vim:tw=78:ts=8:noet:ft=help:norl:

Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq


[8]ページ先頭

©2009-2026 Movatter.jp