Christian Brabandt | 0b0f7d6 | 2024-05-19 09:11:09 +0200 | [diff] [blame] | 1 | *usr_21.txt* For Vim version 9.1. Last change: 2024 May 17 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | |
| 3 | VIM USER MANUAL - by Bram Moolenaar |
| 4 | |
| 5 | Go away and come back |
| 6 | |
| 7 | |
| 8 | This chapter goes into mixing the use of other programs with Vim. Either by |
| 9 | executing program from inside Vim or by leaving Vim and coming back later. |
| 10 | Furthermore, this is about the ways to remember the state of Vim and restore |
| 11 | it later. |
| 12 | |
| 13 | |21.1| Suspend and resume |
| 14 | |21.2| Executing shell commands |
| 15 | |21.3| Remembering information; viminfo |
| 16 | |21.4| Sessions |
| 17 | |21.5| Views |
| 18 | |21.6| Modelines |
| 19 | |
| 20 | Next chapter: |usr_22.txt| Finding the file to edit |
| 21 | Previous chapter: |usr_20.txt| Typing command-line commands quickly |
| 22 | Table of contents: |usr_toc.txt| |
| 23 | |
| 24 | ============================================================================== |
| 25 | *21.1* Suspend and resume |
| 26 | |
| 27 | Like most Unix programs Vim can be suspended by pressing CTRL-Z. This stops |
| 28 | Vim and takes you back to the shell it was started in. You can then do any |
| 29 | other commands until you are bored with them. Then bring back Vim with the |
| 30 | "fg" command. > |
| 31 | |
| 32 | CTRL-Z |
| 33 | {any sequence of shell commands} |
| 34 | fg |
| 35 | |
| 36 | You are right back where you left Vim, nothing has changed. |
| 37 | In case pressing CTRL-Z doesn't work, you can also use ":suspend". |
| 38 | Don't forget to bring Vim back to the foreground, you would lose any changes |
| 39 | that you made! |
| 40 | |
| 41 | Only Unix has support for this. On other systems Vim will start a shell for |
| 42 | you. This also has the functionality of being able to execute shell commands. |
| 43 | But it's a new shell, not the one that you started Vim from. |
| 44 | When you are running the GUI you can't go back to the shell where Vim was |
| 45 | started. CTRL-Z will minimize the Vim window instead. |
| 46 | |
| 47 | ============================================================================== |
| 48 | *21.2* Executing shell commands |
| 49 | |
| 50 | To execute a single shell command from Vim use ":!{command}". For example, to |
| 51 | see a directory listing: > |
| 52 | |
| 53 | :!ls |
| 54 | :!dir |
| 55 | |
| 56 | The first one is for Unix, the second one for MS-Windows. |
| 57 | Vim will execute the program. When it ends you will get a prompt to hit |
| 58 | <Enter>. This allows you to have a look at the output from the command before |
| 59 | returning to the text you were editing. |
| 60 | The "!" is also used in other places where a program is run. Let's take |
| 61 | a look at an overview: |
| 62 | |
| 63 | :!{program} execute {program} |
| 64 | :r !{program} execute {program} and read its output |
| 65 | :w !{program} execute {program} and send text to its input |
| 66 | :[range]!{program} filter text through {program} |
| 67 | |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 68 | Notice that the presence of a range before "!{program}" makes a big |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 69 | difference. Without it executes the program normally, with the range a number |
| 70 | of text lines is filtered through the program. |
| 71 | |
| 72 | Executing a whole row of programs this way is possible. But a shell is much |
| 73 | better at it. You can start a new shell this way: > |
| 74 | |
| 75 | :shell |
| 76 | |
| 77 | This is similar to using CTRL-Z to suspend Vim. The difference is that a new |
| 78 | shell is started. |
| 79 | |
| 80 | When using the GUI the shell will be using the Vim window for its input and |
| 81 | output. Since Vim is not a terminal emulator, this will not work perfectly. |
| 82 | If you have trouble, try toggling the 'guipty' option. If this still doesn't |
| 83 | work well enough, start a new terminal to run the shell in. For example with: |
| 84 | > |
| 85 | :!xterm& |
| 86 | |
| 87 | ============================================================================== |
| 88 | *21.3* Remembering information; viminfo |
| 89 | |
| 90 | After editing for a while you will have text in registers, marks in various |
| 91 | files, a command line history filled with carefully crafted commands. When |
| 92 | you exit Vim all of this is lost. But you can get it back! |
| 93 | |
| 94 | The viminfo file is designed to store status information: |
| 95 | |
| 96 | Command-line and Search pattern history |
| 97 | Text in registers |
| 98 | Marks for various files |
| 99 | The buffer list |
| 100 | Global variables |
| 101 | |
| 102 | Each time you exit Vim it will store this information in a file, the viminfo |
| 103 | file. When Vim starts again, the viminfo file is read and the information |
| 104 | restored. |
| 105 | |
| 106 | The 'viminfo' option is set by default to restore a limited number of items. |
| 107 | You might want to set it to remember more information. This is done through |
| 108 | the following command: > |
| 109 | |
| 110 | :set viminfo=string |
| 111 | |
| 112 | The string specifies what to save. The syntax of this string is an option |
| 113 | character followed by an argument. The option/argument pairs are separated by |
| 114 | commas. |
| 115 | Take a look at how you can build up your own viminfo string. First, the ' |
| 116 | option is used to specify how many files for which you save marks (a-z). Pick |
| 117 | a nice even number for this option (1000, for instance). Your command now |
| 118 | looks like this: > |
| 119 | |
| 120 | :set viminfo='1000 |
| 121 | |
| 122 | The f option controls whether global marks (A-Z and 0-9) are stored. If this |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 123 | option is 0, none are stored. If it is 1 or you do not specify an f option, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 124 | the marks are stored. You want this feature, so now you have this: > |
| 125 | |
| 126 | :set viminfo='1000,f1 |
| 127 | |
| 128 | The < option controls how many lines are saved for each of the registers. By |
| 129 | default, all the lines are saved. If 0, nothing is saved. To avoid adding |
| 130 | thousands of lines to your viminfo file (which might never get used and makes |
| 131 | starting Vim slower) you use a maximum of 500 lines: > |
| 132 | |
| 133 | :set viminfo='1000,f1,<500 |
| 134 | < |
| 135 | Other options you might want to use: |
| 136 | : number of lines to save from the command line history |
| 137 | @ number of lines to save from the input line history |
| 138 | / number of lines to save from the search history |
| 139 | r removable media, for which no marks will be stored (can be |
| 140 | used several times) |
| 141 | ! global variables that start with an uppercase letter and |
| 142 | don't contain lowercase letters |
| 143 | h disable 'hlsearch' highlighting when starting |
| 144 | % the buffer list (only restored when starting Vim without file |
| 145 | arguments) |
| 146 | c convert the text using 'encoding' |
| 147 | n name used for the viminfo file (must be the last option) |
| 148 | |
| 149 | See the 'viminfo' option and |viminfo-file| for more information. |
| 150 | |
| 151 | When you run Vim multiple times, the last one exiting will store its |
| 152 | information. This may cause information that previously exiting Vims stored |
| 153 | to be lost. Each item can be remembered only once. |
| 154 | |
| 155 | |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 156 | GETTING BACK TO WHERE YOU STOPPED VIM |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 157 | |
| 158 | You are halfway editing a file and it's time to leave for holidays. You exit |
| 159 | Vim and go enjoy yourselves, forgetting all about your work. After a couple |
| 160 | of weeks you start Vim, and type: |
| 161 | > |
| 162 | '0 |
| 163 | |
| 164 | And you are right back where you left Vim. So you can get on with your work. |
| 165 | Vim creates a mark each time you exit Vim. The last one is '0. The |
| 166 | position that '0 pointed to is made '1. And '1 is made to '2, and so forth. |
| 167 | Mark '9 is lost. |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 168 | The |:marks| command is useful to find out where '0 to '9 will take you. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 169 | |
| 170 | |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 171 | GETTING BACK TO SOME FILE |
| 172 | |
| 173 | If you want to go back to a file that you edited recently, but not when |
| 174 | exiting Vim, there is a slightly more complicated way. You can see a list of |
| 175 | files by typing the command: > |
| 176 | |
| 177 | :oldfiles |
| 178 | < 1: ~/.viminfo ~ |
| 179 | 2: ~/text/resume.txt ~ |
| 180 | 3: /tmp/draft ~ |
| 181 | |
| 182 | Now you would like to edit the second file, which is in the list preceded by |
| 183 | "2:". You type: > |
| 184 | |
| 185 | :e #<2 |
| 186 | |
| 187 | Instead of ":e" you can use any command that has a file name argument, the |
| 188 | "#<2" item works in the same place as "%" (current file name) and "#" |
| 189 | (alternate file name). So you can also split the window to edit the third |
| 190 | file: > |
| 191 | |
| 192 | :split #<3 |
| 193 | |
| 194 | That #<123 thing is a bit complicated when you just want to edit a file. |
| 195 | Fortunately there is a simpler way: > |
| 196 | |
| 197 | :browse oldfiles |
| 198 | < 1: ~/.viminfo ~ |
| 199 | 2: ~/text/resume.txt ~ |
| 200 | 3: /tmp/draft ~ |
| 201 | -- More -- |
| 202 | |
| 203 | You get the same list of files as with |:oldfiles|. If you want to edit |
| 204 | "resume.txt" first press "q" to stop the listing. You will get a prompt: |
| 205 | |
| 206 | Type number and <Enter> (empty cancels): ~ |
| 207 | |
| 208 | Type "2" and press <Enter> to edit the second file. |
| 209 | |
Christian Brabandt | 0b0f7d6 | 2024-05-19 09:11:09 +0200 | [diff] [blame] | 210 | If you know that the filename contains a pattern, you can also |:filter| the |
| 211 | list of files: > |
| 212 | |
| 213 | :filter /resume/ :browse oldfiles |
| 214 | < |
| 215 | Since there is only one single matching filename, Vim will directly edit that |
| 216 | file without prompting. If the filter matches several files, you'll get |
| 217 | prompted for the list of matching files instead: > |
| 218 | |
| 219 | :filter! /resume/ browse oldfiles |
| 220 | < 1: ~/.viminfo ~ |
| 221 | 3: /tmp/draft ~ |
| 222 | Type number and <Enter> (q or empty cancels): ~ |
| 223 | |
| 224 | Note: this time we filtered out all files NOT matching resume. |
| 225 | |
| 226 | |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 227 | More info at |:oldfiles|, |v:oldfiles| and |c_#<|. |
| 228 | |
| 229 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 230 | MOVE INFO FROM ONE VIM TO ANOTHER |
| 231 | |
| 232 | You can use the ":wviminfo" and ":rviminfo" commands to save and restore the |
| 233 | information while still running Vim. This is useful for exchanging register |
| 234 | contents between two instances of Vim, for example. In the first Vim do: > |
| 235 | |
| 236 | :wviminfo! ~/tmp/viminfo |
| 237 | |
| 238 | And in the second Vim do: > |
| 239 | |
| 240 | :rviminfo! ~/tmp/viminfo |
| 241 | |
| 242 | Obviously, the "w" stands for "write" and the "r" for "read". |
| 243 | The ! character is used by ":wviminfo" to forcefully overwrite an existing |
| 244 | file. When it is omitted, and the file exists, the information is merged into |
| 245 | the file. |
| 246 | The ! character used for ":rviminfo" means that all the information is |
| 247 | used, this may overwrite existing information. Without the ! only information |
| 248 | that wasn't set is used. |
| 249 | These commands can also be used to store info and use it again later. You |
| 250 | could make a directory full of viminfo files, each containing info for a |
| 251 | different purpose. |
| 252 | |
| 253 | ============================================================================== |
| 254 | *21.4* Sessions |
| 255 | |
| 256 | Suppose you are editing along, and it is the end of the day. You want to quit |
| 257 | work and pick up where you left off the next day. You can do this by saving |
| 258 | your editing session and restoring it the next day. |
| 259 | A Vim session contains all the information about what you are editing. |
| 260 | This includes things such as the file list, window layout, global variables, |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 261 | options and other information. (Exactly what is remembered is controlled by |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 262 | the 'sessionoptions' option, described below.) |
| 263 | The following command creates a session file: > |
| 264 | |
| 265 | :mksession vimbook.vim |
| 266 | |
| 267 | Later if you want to restore this session, you can use this command: > |
| 268 | |
| 269 | :source vimbook.vim |
| 270 | |
| 271 | If you want to start Vim and restore a specific session, you can use the |
| 272 | following command: > |
| 273 | |
| 274 | vim -S vimbook.vim |
| 275 | |
| 276 | This tells Vim to read a specific file on startup. The 'S' stands for |
| 277 | session (actually, you can source any Vim script with -S, thus it might as |
| 278 | well stand for "source"). |
| 279 | |
| 280 | The windows that were open are restored, with the same position and size as |
| 281 | before. Mappings and option values are like before. |
| 282 | What exactly is restored depends on the 'sessionoptions' option. The |
Bram Moolenaar | 25c9c68 | 2019-05-05 18:13:34 +0200 | [diff] [blame] | 283 | default value is: |
| 284 | "blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 285 | |
| 286 | blank keep empty windows |
| 287 | buffers all buffers, not only the ones in a window |
| 288 | curdir the current directory |
| 289 | folds folds, also manually created ones |
| 290 | help the help window |
| 291 | options all options and mappings |
Bram Moolenaar | 25c9c68 | 2019-05-05 18:13:34 +0200 | [diff] [blame] | 292 | tabpages all tab pages |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 293 | winsize window sizes |
Bram Moolenaar | 25c9c68 | 2019-05-05 18:13:34 +0200 | [diff] [blame] | 294 | terminal include terminal windows |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 295 | |
| 296 | Change this to your liking. To also restore the size of the Vim window, for |
| 297 | example, use: > |
| 298 | |
| 299 | :set sessionoptions+=resize |
| 300 | |
| 301 | |
| 302 | SESSION HERE, SESSION THERE |
| 303 | |
| 304 | The obvious way to use sessions is when working on different projects. |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 305 | Suppose you store your session files in the directory "~/.vim". You are |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 306 | currently working on the "secret" project and have to switch to the "boring" |
| 307 | project: > |
| 308 | |
| 309 | :wall |
| 310 | :mksession! ~/.vim/secret.vim |
| 311 | :source ~/.vim/boring.vim |
| 312 | |
| 313 | This first uses ":wall" to write all modified files. Then the current session |
| 314 | is saved, using ":mksession!". This overwrites the previous session. The |
| 315 | next time you load the secret session you can continue where you were at this |
| 316 | point. And finally you load the new "boring" session. |
| 317 | |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 318 | If you open help windows, split and close various windows, and generally mess |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 319 | up the window layout, you can go back to the last saved session: > |
| 320 | |
| 321 | :source ~/.vim/boring.vim |
| 322 | |
| 323 | Thus you have complete control over whether you want to continue next time |
| 324 | where you are now, by saving the current setup in a session, or keep the |
| 325 | session file as a starting point. |
| 326 | Another way of using sessions is to create a window layout that you like to |
| 327 | use, and save this in a session. Then you can go back to this layout whenever |
| 328 | you want. |
| 329 | For example, this is a nice layout to use: |
| 330 | |
| 331 | +----------------------------------------+ |
| 332 | | VIM - main help file | |
| 333 | | | |
| 334 | |Move around: Use the cursor keys, or "h| |
| 335 | |help.txt================================| |
| 336 | |explorer | | |
| 337 | |dir |~ | |
| 338 | |dir |~ | |
| 339 | |file |~ | |
| 340 | |file |~ | |
| 341 | |file |~ | |
| 342 | |file |~ | |
| 343 | |~/=========|[No File]===================| |
| 344 | | | |
| 345 | +----------------------------------------+ |
| 346 | |
| 347 | This has a help window at the top, so that you can read this text. The narrow |
| 348 | vertical window on the left contains a file explorer. This is a Vim plugin |
| 349 | that lists the contents of a directory. You can select files to edit there. |
| 350 | More about this in the next chapter. |
| 351 | Create this from a just started Vim with: > |
| 352 | |
| 353 | :help |
| 354 | CTRL-W w |
| 355 | :vertical split ~/ |
| 356 | |
| 357 | You can resize the windows a bit to your liking. Then save the session with: |
| 358 | > |
| 359 | :mksession ~/.vim/mine.vim |
| 360 | |
| 361 | Now you can start Vim with this layout: > |
| 362 | |
| 363 | vim -S ~/.vim/mine.vim |
| 364 | |
| 365 | Hint: To open a file you see listed in the explorer window in the empty |
| 366 | window, move the cursor to the filename and press "O". Double clicking with |
| 367 | the mouse will also do this. |
| 368 | |
| 369 | |
| 370 | UNIX AND MS-WINDOWS |
| 371 | |
| 372 | Some people have to do work on MS-Windows systems one day and on Unix another |
| 373 | day. If you are one of them, consider adding "slash" and "unix" to |
| 374 | 'sessionoptions'. The session files will then be written in a format that can |
| 375 | be used on both systems. This is the command to put in your vimrc file: > |
| 376 | |
| 377 | :set sessionoptions+=unix,slash |
| 378 | |
| 379 | Vim will use the Unix format then, because the MS-Windows Vim can read and |
| 380 | write Unix files, but Unix Vim can't read MS-Windows format session files. |
| 381 | Similarly, MS-Windows Vim understands file names with / to separate names, but |
| 382 | Unix Vim doesn't understand \. |
| 383 | |
| 384 | |
| 385 | SESSIONS AND VIMINFO |
| 386 | |
| 387 | Sessions store many things, but not the position of marks, contents of |
| 388 | registers and the command line history. You need to use the viminfo feature |
| 389 | for these things. |
| 390 | In most situations you will want to use sessions separately from viminfo. |
| 391 | This can be used to switch to another session, but keep the command line |
| 392 | history. And yank text into registers in one session, and paste it back in |
| 393 | another session. |
| 394 | You might prefer to keep the info with the session. You will have to do |
| 395 | this yourself then. Example: > |
| 396 | |
| 397 | :mksession! ~/.vim/secret.vim |
| 398 | :wviminfo! ~/.vim/secret.viminfo |
| 399 | |
| 400 | And to restore this again: > |
| 401 | |
| 402 | :source ~/.vim/secret.vim |
| 403 | :rviminfo! ~/.vim/secret.viminfo |
| 404 | |
| 405 | ============================================================================== |
| 406 | *21.5* Views |
| 407 | |
| 408 | A session stores the looks of the whole of Vim. When you want to store the |
| 409 | properties for one window only, use a view. |
| 410 | The use of a view is for when you want to edit a file in a specific way. |
| 411 | For example, you have line numbers enabled with the 'number' option and |
| 412 | defined a few folds. Just like with sessions, you can remember this view on |
| 413 | the file and restore it later. Actually, when you store a session, it stores |
| 414 | the view of each window. |
| 415 | There are two basic ways to use views. The first is to let Vim pick a name |
| 416 | for the view file. You can restore the view when you later edit the same |
| 417 | file. To store the view for the current window: > |
| 418 | |
| 419 | :mkview |
| 420 | |
| 421 | Vim will decide where to store the view. When you later edit the same file |
| 422 | you get the view back with this command: > |
| 423 | |
| 424 | :loadview |
| 425 | |
| 426 | That's easy, isn't it? |
| 427 | Now you want to view the file without the 'number' option on, or with all |
| 428 | folds open, you can set the options to make the window look that way. Then |
| 429 | store this view with: > |
| 430 | |
| 431 | :mkview 1 |
| 432 | |
| 433 | Obviously, you can get this back with: > |
| 434 | |
| 435 | :loadview 1 |
| 436 | |
| 437 | Now you can switch between the two views on the file by using ":loadview" with |
| 438 | and without the "1" argument. |
| 439 | You can store up to ten views for the same file this way, one unnumbered |
| 440 | and nine numbered 1 to 9. |
| 441 | |
| 442 | |
| 443 | A VIEW WITH A NAME |
| 444 | |
| 445 | The second basic way to use views is by storing the view in a file with a name |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 446 | you choose. This view can be loaded while editing another file. Vim will |
| 447 | then switch to editing the file specified in the view. Thus you can use this |
| 448 | to quickly switch to editing another file, with all its options set as you |
| 449 | saved them. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 450 | For example, to save the view of the current file: > |
| 451 | |
| 452 | :mkview ~/.vim/main.vim |
| 453 | |
| 454 | You can restore it with: > |
| 455 | |
| 456 | :source ~/.vim/main.vim |
| 457 | |
| 458 | ============================================================================== |
| 459 | *21.6* Modelines |
| 460 | |
| 461 | When editing a specific file, you might set options specifically for that |
| 462 | file. Typing these commands each time is boring. Using a session or view for |
| 463 | editing a file doesn't work when sharing the file between several people. |
| 464 | The solution for this situation is adding a modeline to the file. This is |
| 465 | a line of text that tells Vim the values of options, to be used in this file |
| 466 | only. |
| 467 | A typical example is a C program where you make indents by a multiple of 4 |
| 468 | spaces. This requires setting the 'shiftwidth' option to 4. This modeline |
| 469 | will do that: |
| 470 | |
| 471 | /* vim:set shiftwidth=4: */ ~ |
| 472 | |
| 473 | Put this line as one of the first or last five lines in the file. When |
| 474 | editing the file, you will notice that 'shiftwidth' will have been set to |
| 475 | four. When editing another file, it's set back to the default value of eight. |
| 476 | For some files the modeline fits well in the header, thus it can be put at |
| 477 | the top of the file. For text files and other files where the modeline gets |
| 478 | in the way of the normal contents, put it at the end of the file. |
| 479 | |
| 480 | The 'modelines' option specifies how many lines at the start and end of the |
| 481 | file are inspected for containing a modeline. To inspect ten lines: > |
| 482 | |
| 483 | :set modelines=10 |
| 484 | |
| 485 | The 'modeline' option can be used to switch this off. Do this when you are |
Bram Moolenaar | 313b723 | 2007-05-05 17:56:55 +0000 | [diff] [blame] | 486 | working as root on Unix or Administrator on MS-Windows, or when you don't |
| 487 | trust the files you are editing: > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 488 | |
| 489 | :set nomodeline |
| 490 | |
| 491 | Use this format for the modeline: |
| 492 | |
| 493 | any-text vim:set {option}={value} ... : any-text ~ |
| 494 | |
| 495 | The "any-text" indicates that you can put any text before and after the part |
| 496 | that Vim will use. This allows making it look like a comment, like what was |
| 497 | done above with /* and */. |
Bram Moolenaar | 313b723 | 2007-05-05 17:56:55 +0000 | [diff] [blame] | 498 | The " vim:" part is what makes Vim recognize this line. There must be |
| 499 | white space before "vim", or "vim" must be at the start of the line. Thus |
| 500 | using something like "gvim:" will not work. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 501 | The part between the colons is a ":set" command. It works the same way as |
| 502 | typing the ":set" command, except that you need to insert a backslash before a |
| 503 | colon (otherwise it would be seen as the end of the modeline). |
| 504 | |
| 505 | Another example: |
| 506 | |
| 507 | // vim:set textwidth=72 dir=c\:\tmp: use c:\tmp here ~ |
| 508 | |
| 509 | There is an extra backslash before the first colon, so that it's included in |
| 510 | the ":set" command. The text after the second colon is ignored, thus a remark |
| 511 | can be placed there. |
| 512 | |
| 513 | For more details see |modeline|. |
| 514 | |
| 515 | ============================================================================== |
| 516 | |
| 517 | Next chapter: |usr_22.txt| Finding the file to edit |
| 518 | |
Bram Moolenaar | d473c8c | 2018-08-11 18:00:22 +0200 | [diff] [blame] | 519 | Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: |