robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1*usr_20.txt* Nvim 2 3 4 VIM USER MANUAL by Bram Moolenaar 5 6 7 Typing command-line commands quickly 8 9 10Vim has a few generic features that makes it easier to enter commands. Colon 11commands can be abbreviated, edited and repeated. Completion is available for 12nearly everything. 13 14|20.1| Command line editing 15|20.2| Command line abbreviations 16|20.3| Command line completion 17|20.4| Command line history 18|20.5| Command line window 19 20 Next chapter: |usr_21.txt| Go away and come back 21 Previous chapter: |usr_12.txt| Clever tricks 22Table of contents: |usr_toc.txt| 23 24============================================================================== 25*20.1* Command line editing 26 27When you use a colon (:) command or search for a string with / or ?, Vim puts 28the cursor on the bottom of the screen. There you type the command or search 29pattern. This is called the Command line. Also when it's used for entering a 30search command. 31 32The most obvious way to edit the command you type is by pressing the <BS> key. 33This erases the character before the cursor. To erase another character, 34typed earlier, first move the cursor with the cursor keys. 35 For example, you have typed this: > 36 37 :s/col/pig/ 38 39Before you hit <Enter>, you notice that "col" should be "cow". To correct 40this, you type <Left> five times. The cursor is now just after "col". Type 41<BS> and "w" to correct: > 42 43 :s/cow/pig/ 44 45Now you can press <Enter> directly. You don't have to move the cursor to the 46end of the line before executing the command. 47 48The most often used keys to move around in the command line: 49 50 <Left> one character left 51 <Right> one character right 52 <S-Left> or <C-Left> one word left 53 <S-Right> or <C-Right> one word right 54 CTRL-B or <Home> to begin of command line 55 CTRL-E or <End> to end of command line 56 57 Note: 58 <S-Left> (cursor left key with Shift key pressed) and <C-Left> (cursor 59 left key with Control pressed) will not work on all keyboards. Same 60 for the other Shift and Control combinations. 61 62You can also use the mouse to move the cursor. 63 64 65DELETING 66 67As mentioned, <BS> deletes the character before the cursor. To delete a whole 68word use CTRL-W. 69 70 /the fine pig ~ 71 72 CTRL-W 73 74 /the fine ~ 75 76CTRL-U removes all text, thus allows you to start all over again. 77 78 79OVERSTRIKE 80 81The <Insert> key toggles between inserting characters and replacing the 82existing ones. Start with this text: 83 84 /the fine pig ~ 85 86Move the cursor to the start of "fine" with <S-Left> twice (or <Left> eight 87times, if <S-Left> doesn't work). Now press <Insert> to switch to overstrike 88and type "great": 89 90 /the greatpig ~ 91 92Oops, we lost the space. Now, don't use <BS>, because it would delete the 93"t" (this is different from Replace mode). Instead, press <Insert> to switch 94from overstrike to inserting, and type the space: 95 96 /the great pig ~ 97 98 99CANCELLING 100 101You thought of executing a : or / command, but changed your mind. To get rid 102of what you already typed, without executing it, press CTRL-C or <Esc>. 103 104 Note: 105 <Esc> is the universal "get out" key. Unfortunately, in the good old 106 Vi pressing <Esc> in a command line executed the command! Since that 107 might be considered to be a bug, Vim uses <Esc> to cancel the command. 108 But with the 'cpoptions' option it can be made Vi compatible. And 109 when using a mapping (which might be written for Vi) <Esc> also works 110 Vi compatible. Therefore, using CTRL-C is a method that always works. 111 112If you are at the start of the command line, pressing <BS> will cancel the 113command. It's like deleting the ":" or "/" that the line starts with. 114 115============================================================================== 116*20.2* Command line abbreviations 117 118Some of the ":" commands are really long. We already mentioned that 119":substitute" can be abbreviated to ":s". This is a generic mechanism, all 120":" commands can be abbreviated. 121 122The builtin function |fullcommand()| can be used to return an abbreviated 123command's full name. For example, the following commands echo "edit", "echo", 124and "echomsg": 125>vim 126 :echo fullcommand('e') 127 :echo fullcommand('ec') 128 :echo fullcommand('echom') 129< 130How short can a command get? There are 26 letters, and many more commands. 131For example, ":set" also starts with ":s", but ":s" doesn't start a ":set" 132command. Instead ":set" can be abbreviated to ":se". 133 When the shorter form of a command could be used for two commands, it 134stands for only one of them. There is no logic behind which one, you have to 135learn them. In the help files the shortest form that works is mentioned. For 136example: > 137 138 :s[ubstitute] 139 140This means that the shortest form of ":substitute" is ":s". The following 141characters are optional. Thus ":su" and ":sub" also work. 142 143In the user manual we will either use the full name of command, or a short 144version that is still readable. For example, ":function" can be abbreviated 145to ":fu". But since most people don't understand what that stands for, we 146will use ":fun". (Vim doesn't have a ":funny" command, otherwise ":fun" would 147be confusing too.) 148 149It is recommended that in Vim scripts you write the full command name. That 150makes it easier to read back when you make later changes. Except for some 151often used commands like ":w" (":write") and ":r" (":read"). 152 A particularly confusing one is ":end", which could stand for ":endif", 153":endwhile" or ":endfunction". Therefore, always use the full name. 154 155 156SHORT OPTION NAMES 157 158In the user manual the long version of the option names is used. Many options 159also have a short name. Unlike ":" commands, there is only one short name 160that works. For example, the short name of 'autoindent' is 'ai'. Thus these 161two commands do the same thing: > 162 163 :set autoindent 164 :set ai 165 166You can find the full list of long and short names here: |option-list|. 167 168============================================================================== 169*20.3* Command line completion 170 171This is one of those Vim features that, by itself, is a reason to switch from 172Vi to Vim. Once you have used this, you can't do without. 173 174Suppose you have a directory that contains these files: 175 176 info.txt 177 intro.txt 178 bodyofthepaper.txt 179 180To edit the last one, you use the command: > 181 182 :edit bodyofthepaper.txt 183 184It's easy to type this wrong. A much quicker way is: > 185 186 :edit b<Tab> 187 188Which will result in the same command. What happened? The <Tab> key does 189completion of the word before the cursor. In this case "b". Vim looks in the 190directory and finds only one file that starts with a "b". That must be the 191one you are looking for, thus Vim completes the file name for you. 192 193Now type: > 194 195 :edit i<Tab> 196 197Vim will beep, and give you: > 198 199 :edit info.txt 200 201The beep means that Vim has found more than one match. It then uses the first 202match it found (alphabetically). If you press <Tab> again, you get: > 203 204 :edit intro.txt 205 206Thus, if the first <Tab> doesn't give you the file you were looking for, press 207it again. If there are more matches, you will see them all, one at a time. 208 If you press <Tab> on the last matching entry, you will go back to what you 209first typed: > 210 211 :edit i 212 213Then it starts all over again. Thus Vim cycles through the list of matches. 214Use CTRL-P to go through the list in the other direction: 215 216 <------------------- <Tab> -------------------------+ 217 | 218 <Tab> --> <Tab> --> 219 :edit i :edit info.txt :edit intro.txt 220 <-- CTRL-P <-- CTRL-P 221 | 222 +---------------------- CTRL-P ------------------------> 223 224 225CONTEXT 226 227When you type ":set i" instead of ":edit i" and press <Tab> you get: > 228 229 :set icon 230 231Hey, why didn't you get ":set info.txt"? That's because Vim has context 232sensitive completion. The kind of words Vim will look for depends on the 233command before it. Vim knows that you cannot use a file name just after a 234":set" command, but you can use an option name. 235 Again, if you repeat typing the <Tab>, Vim will cycle through all matches. 236There are quite a few, it's better to type more characters first: > 237 238 :set isk<Tab> 239 240Gives: > 241 242 :set iskeyword 243 244Now type "=" and press <Tab>: > 245 246 :set iskeyword=@,48-57,_,192-255 247 248What happens here is that Vim inserts the old value of the option. Now you 249can edit it. 250 What is completed with <Tab> is what Vim expects in that place. Just try 251it out to see how it works. In some situations you will not get what you 252want. That's either because Vim doesn't know what you want, or because 253completion was not implemented for that situation. In that case you will get 254a <Tab> inserted (displayed as ^I). 255 256 257LIST MATCHES 258 259When there are many matches, you would like to see an overview. Do this by 260pressing CTRL-D. For example, pressing CTRL-D after: > 261 262 :set is 263 264results in: > 265 266 :set is 267 incsearch isfname isident iskeyword 268 :set is 269 270Vim lists the matches and then comes back with the text you typed. You can 271now check the list for the item you wanted. If it isn't there, you can use 272<BS> to correct the word. If there are many matches, type a few more 273characters before pressing <Tab> to complete the rest. 274 If you have watched carefully, you will have noticed that "incsearch" 275doesn't start with "is". In this case "is" stands for the short name of 276"incsearch". (Many options have a short and a long name.) Vim is clever 277enough to know that you might have wanted to expand the short name of the 278option into the long name. 279 280 281THERE IS MORE 282 283The CTRL-L command completes the word to the longest unambiguous string. If 284you type ":edit i" and there are files "info.txt" and "info_backup.txt" you 285will get ":edit info". 286 287The 'wildmode' option can be used to change the way completion works. 288The 'wildmenu' option can be used to get a menu-like list of matches. 289Use the 'suffixes' option to specify files that are less important and appear 290at the end of the list of files. 291The 'wildignore' option specifies files that are not listed at all. 292 293More about all of this here: |cmdline-completion| 294 295============================================================================== 296*20.4* Command line history 297 298In chapter 3 we briefly mentioned the history. The basics are that you can 299use the <Up> key to recall an older command line. <Down> then takes you back 300to newer commands. 301 302There are actually five histories. The ones we will mention here are for ":" 303commands and for "/" and "?" search commands. The "/" and "?" commands share 304the same history, because they are both search commands. The three other 305histories are for expressions, debug mode commands and input lines for the 306input() function. |cmdline-history| 307 308Suppose you have done a ":set" command, typed ten more colon commands and then 309want to repeat that ":set" command again. You could press ":" and then ten 310times <Up>. There is a quicker way: > 311 312 :se<Up> 313 314Vim will now go back to the previous command that started with "se". You have 315a good chance that this is the ":set" command you were looking for. At least 316you should not have to press <Up> very often (unless ":set" commands is all 317you have done). 318 319The <Up> key will use the text typed so far and compare it with the lines in 320the history. Only matching lines will be used. 321 If you do not find the line you were looking for, use <Down> to go back to 322what you typed and correct that. Or use CTRL-U to start all over again. 323 324To see all the lines in the history: > 325 326 :history 327 328That's the history of ":" commands. The search history is displayed with this 329command: > 330 331 :history / 332 333CTRL-P will work like <Up>, except that it doesn't matter what you already 334typed. Similarly for CTRL-N and <Down>. CTRL-P stands for previous, CTRL-N 335for next. 336 337============================================================================== 338*20.5* Command line window 339 340Typing the text in the command line works differently from typing text in 341Insert mode. It doesn't allow many commands to change the text. For most 342commands that's OK, but sometimes you have to type a complicated command. 343That's where the command line window is useful. 344 345Open the command line window with this command: > 346 347 q: 348 349Vim now opens a (small) window at the bottom. It contains the command line 350history, and an empty line at the end: 351> 352 +-------------------------------------+ 353 |other window | 354 |~ | 355 |file.txt=============================| 356 |:e c | 357 |:e config.h.in | 358 |:set path=.,/usr/include,, | 359 |:set iskeyword=@,48-57,_,192-255 | 360 |:set is | 361 |:q | 362 |: | 363 |command-line=========================| 364 | | 365 +-------------------------------------+ 366< 367You are now in Normal mode. You can use the "hjkl" keys to move around. For 368example, move up with "5k" to the ":e config.h.in" line. Type "$h" to go to 369the "i" of "in" and type "cwout". Now you have changed the line to: 370 371 :e config.h.out ~ 372 373Now press <Enter> and this command will be executed. The command line window 374will close. 375 The <Enter> command will execute the line under the cursor. It doesn't 376matter whether Vim is in Insert mode or in Normal mode. 377 Changes in the command line window are lost. They do not result in the 378history to be changed. Except that the command you execute will be added to 379the end of the history, like with all executed commands. 380 381The command line window is very useful when you want to have overview of the 382history, lookup a similar command, change it a bit and execute it. A search 383command can be used to find something. 384 In the previous example the "?config" search command could have been used 385to find the previous command that contains "config". It's a bit strange, 386because you are using a command line to search in the command line window. 387While typing that search command you can't open another command line window, 388there can be only one. 389 390============================================================================== 391 392Next chapter: |usr_21.txt| Go away and come back 393 394Copyright: see |manual-copyright| 395 396vim:tw=78:ts=8:noet:ft=help:norl: