comparison runtime/doc/usr_05.txt @ 15729:fe57e4f0eac1

Update runtime files. commit https://github.com/vim/vim/commit/314dd79cac2adc10304212d1980d23ecf6782cfc Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 3 15:27:20 2019 +0100 Update runtime files.
author Bram Moolenaar <Bram@vim.org>
date Sun, 03 Feb 2019 15:30:09 +0100
parents 5c5908e81e93
children dc766e1b0c95
comparison
equal deleted inserted replaced
15728:479381bd1728 15729:fe57e4f0eac1
1 *usr_05.txt* For Vim version 8.1. Last change: 2018 Feb 20 1 *usr_05.txt* For Vim version 8.1. Last change: 2019 Jan 26
2 2
3 VIM USER MANUAL - by Bram Moolenaar 3 VIM USER MANUAL - by Bram Moolenaar
4 4
5 Set your settings 5 Set your settings
6 6
9 make Vim start with options set to different values. Add plugins to extend 9 make Vim start with options set to different values. Add plugins to extend
10 Vim's capabilities. Or define your own macros. 10 Vim's capabilities. Or define your own macros.
11 11
12 |05.1| The vimrc file 12 |05.1| The vimrc file
13 |05.2| The example vimrc file explained 13 |05.2| The example vimrc file explained
14 |05.3| Simple mappings 14 |05.3| The defaults.vim file explained
15 |05.4| Adding a package 15 |05.4| Simple mappings
16 |05.5| Adding a plugin 16 |05.5| Adding a package
17 |05.6| Adding a help file 17 |05.6| Adding a plugin
18 |05.7| The option window 18 |05.7| Adding a help file
19 |05.8| Often used options 19 |05.8| The option window
20 |05.9| Often used options
20 21
21 Next chapter: |usr_06.txt| Using syntax highlighting 22 Next chapter: |usr_06.txt| Using syntax highlighting
22 Previous chapter: |usr_04.txt| Making small changes 23 Previous chapter: |usr_04.txt| Making small changes
23 Table of contents: |usr_toc.txt| 24 Table of contents: |usr_toc.txt|
24 25
80 In this section we will explain the various commands used in this file. This 81 In this section we will explain the various commands used in this file. This
81 will give you hints about how to set up your own preferences. Not everything 82 will give you hints about how to set up your own preferences. Not everything
82 will be explained though. Use the ":help" command to find out more. 83 will be explained though. Use the ":help" command to find out more.
83 84
84 > 85 >
85 set nocompatible 86 " Get the defaults that most users want.
86 87 source $VIMRUNTIME/defaults.vim
87 As mentioned in the first chapter, these manuals explain Vim working in an 88 >
88 improved way, thus not completely Vi compatible. Setting the 'compatible' 89 This loads the "defaults.vim" file in the $VIMRUNTIME directory. This sets up
89 option off, thus 'nocompatible' takes care of this. 90 Vim for how most users like it. If you are one of the few that don't, then
90 91 comment out this line. The commands are explained below:
91 > 92 |defaults.vim-explained|
92 set backspace=indent,eol,start 93
93 94 >
94 This specifies where in Insert mode the <BS> is allowed to delete the
95 character in front of the cursor. The three items, separated by commas, tell
96 Vim to delete the white space at the start of the line, a line break and the
97 character before where Insert mode started.
98 >
99
100 set autoindent
101
102 This makes Vim use the indent of the previous line for a newly created line.
103 Thus there is the same amount of white space before the new line. For example
104 when pressing <Enter> in Insert mode, and when using the "o" command to open a
105 new line.
106 >
107
108 if has("vms") 95 if has("vms")
109 set nobackup 96 set nobackup
110 else 97 else
111 set backup 98 set backup
99 if has('persistent_undo')
100 set undofile
101 endif
112 endif 102 endif
113 103
114 This tells Vim to keep a backup copy of a file when overwriting it. But not 104 This tells Vim to keep a backup copy of a file when overwriting it. But not
115 on the VMS system, since it keeps old versions of files already. The backup 105 on the VMS system, since it keeps old versions of files already. The backup
116 file will have the same name as the original file with "~" added. See |07.4| 106 file will have the same name as the original file with "~" added. See |07.4|
117 > 107
118 108 This also sets the 'undofile' option, if available. This will store the
119 set history=50 109 multi-level undo information in a file. The result is that when you change a
120 110 file, exit Vim, and then edit the file again, you can undo the changes made
121 Keep 50 commands and 50 search patterns in the history. Use another number if 111 previously. It's a very powerful and useful feature, at the cost of storing a
122 you want to remember fewer or more lines. 112 file. For more information see |undo-persistence|.
113
114 The "if" command is very useful to set options
115 only when some condition is met. More about that in |usr_41.txt|.
116
117 >
118 if &t_Co > 2 || has("gui_running")
119 set hlsearch
120 endif
121
122 This switches on the 'hlsearch' option, telling Vim to highlight matches with
123 the last used search pattern.
124
125 >
126 augroup vimrcEx
127 au!
128 autocmd FileType text setlocal textwidth=78
129 augroup END
130
131 This makes Vim break text to avoid lines getting longer than 78 characters.
132 But only for files that have been detected to be plain text. There are
133 actually two parts here. "autocmd FileType text" is an autocommand. This
134 defines that when the file type is set to "text" the following command is
135 automatically executed. "setlocal textwidth=78" sets the 'textwidth' option
136 to 78, but only locally in one file.
137
138 The wrapper with "augroup vimrcEx" and "augroup END" makes it possible to
139 delete the autocommand with the "au!" command. See |:augroup|.
140
141 >
142 if has('syntax') && has('eval')
143 packadd! matchit
144 endif
145
146 This loads the "matchit" plugin if the required features are available.
147 It makes the |%| command more powerful. This is explained at
148 |matchit-install|.
149
150
151 ==============================================================================
152 *05.3* The defaults.vim file explained *defaults.vim-explained*
153
154 The |defaults.vim| file is loaded when the user has no vimrc file. When you
155 create a new vimrc file, add this line near the top to keep using it: >
156
157 source $VIMRUNTIME/defaults.vim
158
159 Or use the vimrc_example.vim file, as explained above.
160
161 The following explains what defaults.vim is doing.
162
163 >
164 if exists('skip_defaults_vim')
165 finish
166 endif
167 >
168 Loading defaults.vim can be disabled with this command: >
169 let skip_defaults_vim = 1
170 This has to be done in the system vimrc file. See |system-vimrc|. If you
171 have a user vimrc this is not needed, since defaults.vim will not be loaded
172 automatically.
173 >
174 >
175 set nocompatible
176
177 As mentioned in the first chapter, these manuals explain Vim working in an
178 improved way, thus not completely Vi compatible. Setting the 'compatible'
179 option off, thus 'nocompatible' takes care of this.
180
181 >
182 set backspace=indent,eol,start
183
184 This specifies where in Insert mode the <BS> is allowed to delete the
185 character in front of the cursor. The three items, separated by commas, tell
186 Vim to delete the white space at the start of the line, a line break and the
187 character before where Insert mode started. See 'backspace'.
188
189 >
190 set history=200
191
192 Keep 200 commands and 200 search patterns in the history. Use another number
193 if you want to remember fewer or more lines. See 'history'.
123 > 194 >
124 195
125 set ruler 196 set ruler
126 197
127 Always display the current cursor position in the lower right corner of the 198 Always display the current cursor position in the lower right corner of the
128 Vim window. 199 Vim window. See 'ruler'.
129 200
130 > 201 >
131 set showcmd 202 set showcmd
132 203
133 Display an incomplete command in the lower right corner of the Vim window, 204 Display an incomplete command in the lower right corner of the Vim window,
142 |-- VISUAL -- 2f 43,8 17% | 213 |-- VISUAL -- 2f 43,8 17% |
143 +-------------------------------------------------+ 214 +-------------------------------------------------+
144 ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^ 215 ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^
145 'showmode' 'showcmd' 'ruler' 216 'showmode' 'showcmd' 'ruler'
146 217
218
219 >
220 set wildmenu
221
222 Display completion matches in a status line. That is when you type <Tab> and
223 there is more than one match. See 'wildmenu'.
224
225 >
226 set ttimeout
227 set ttimeoutlen=100
228
229 This makes typing Esc take effect more quickly. Normally Vim waits a second
230 to see if the Esc is the start of an escape sequence. If you have a very slow
231 remote connection, increase the number. See 'ttimeout'.
232
233 >
234 set display=truncate
235
236 Show @@@ in the last line if it is truncated, instead of hiding the whole
237 like. See 'display'.
238
147 > 239 >
148 set incsearch 240 set incsearch
149 241
150 Display the match for a search pattern when halfway typing it. 242 Display the match for a search pattern when halfway typing it. See
243 'incsearch'.
244
245 >
246 set nrformats-=octal
247
248 Do not recognize numbers starting with a zero as octal. See 'nrformats'.
151 249
152 > 250 >
153 map Q gq 251 map Q gq
154 252
155 This defines a key mapping. More about that in the next section. This 253 This defines a key mapping. More about that in the next section. This
156 defines the "Q" command to do formatting with the "gq" operator. This is how 254 defines the "Q" command to do formatting with the "gq" operator. This is how
157 it worked before Vim 5.0. Otherwise the "Q" command starts Ex mode, but you 255 it worked before Vim 5.0. Otherwise the "Q" command starts Ex mode, but you
158 will not need it. 256 will not need it.
159 257
160 > 258 >
259 inoremap <C-U> <C-G>u<C-U>
260 >
261 CTRL-U in insert mode deletes all entered text in the current line. Use
262 CTRL-G u to first break undo, so that you can undo CTRL-U after inserting a
263 line break. Revert with ":iunmap <C-U>".
264
265 >
266 if has('mouse')
267 set mouse=a
268 endif
269
270 Enable using the mouse if available. See 'mouse'.
271
272 >
161 vnoremap _g y:exe "grep /" . escape(@", '\\/') . "/ *.c *.h"<CR> 273 vnoremap _g y:exe "grep /" . escape(@", '\\/') . "/ *.c *.h"<CR>
162 274
163 This mapping yanks the visually selected text and searches for it in C files. 275 This mapping yanks the visually selected text and searches for it in C files.
164 This is a complicated mapping. You can see that mappings can be used to do 276 You can see that a mapping can be used to do quite complicated things. Still,
165 quite complicated things. Still, it is just a sequence of commands that are 277 it is just a sequence of commands that are executed like you typed them.
166 executed like you typed them. 278
167 279 >
168 > 280 syntax on
169 if &t_Co > 2 || has("gui_running") 281
170 syntax on 282 Enable highlighting files in color. See |syntax|.
171 set hlsearch
172 endif
173
174 This switches on syntax highlighting, but only if colors are available. And
175 the 'hlsearch' option tells Vim to highlight matches with the last used search
176 pattern. The "if" command is very useful to set options only when some
177 condition is met. More about that in |usr_41.txt|.
178 283
179 *vimrc-filetype* > 284 *vimrc-filetype* >
180 filetype plugin indent on 285 filetype plugin indent on
181 286
182 This switches on three very clever mechanisms: 287 This switches on three very clever mechanisms:
199 3. Using indent files 304 3. Using indent files
200 When editing programs, the indent of a line can often be computed 305 When editing programs, the indent of a line can often be computed
201 automatically. Vim comes with these indent rules for a number of 306 automatically. Vim comes with these indent rules for a number of
202 filetypes. See |:filetype-indent-on| and 'indentexpr'. 307 filetypes. See |:filetype-indent-on| and 'indentexpr'.
203 308
204 > 309
205 autocmd FileType text setlocal textwidth=78 310 *restore-cursor* *last-position-jump* >
206 311 autocmd BufReadPost *
207 This makes Vim break text to avoid lines getting longer than 78 characters. 312 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
208 But only for files that have been detected to be plain text. There are 313 \ | exe "normal! g`\""
209 actually two parts here. "autocmd FileType text" is an autocommand. This 314 \ | endif
210 defines that when the file type is set to "text" the following command is
211 automatically executed. "setlocal textwidth=78" sets the 'textwidth' option
212 to 78, but only locally in one file.
213
214 *restore-cursor* >
215 autocmd BufReadPost *
216 \ if line("'\"") > 1 && line("'\"") <= line("$") |
217 \ exe "normal! g`\"" |
218 \ endif
219 315
220 Another autocommand. This time it is used after reading any file. The 316 Another autocommand. This time it is used after reading any file. The
221 complicated stuff after it checks if the '" mark is defined, and jumps to it 317 complicated stuff after it checks if the '" mark is defined, and jumps to it
222 if so. The backslash at the start of a line is used to continue the command 318 if so. The backslash at the start of a line is used to continue the command
223 from the previous line. That avoids a line getting very long. 319 from the previous line. That avoids a line getting very long.
224 See |line-continuation|. This only works in a Vim script file, not when 320 See |line-continuation|. This only works in a Vim script file, not when
225 typing commands at the command-line. 321 typing commands at the command-line.
226 322
227 ============================================================================== 323 >
228 *05.3* Simple mappings 324 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
325 \ | wincmd p | diffthis
326
327 This adds the ":DiffOrig" command. Use this in a modified buffer to see the
328 differences with the file it was loaded from. See |diff|.
329
330 >
331 set nolangremap
332
333 Prevent that the langmap option applies to characters that result from a
334 mapping. If set (default), this may break plugins (but it's backward
335 compatible). See 'langremap'.
336
337 ==============================================================================
338 *05.4* Simple mappings
229 339
230 A mapping enables you to bind a set of Vim commands to a single key. Suppose, 340 A mapping enables you to bind a set of Vim commands to a single key. Suppose,
231 for example, that you need to surround certain words with curly braces. In 341 for example, that you need to surround certain words with curly braces. In
232 other words, you need to change a word such as "amount" into "{amount}". With 342 other words, you need to change a word such as "amount" into "{amount}". With
233 the :map command, you can tell Vim that the F5 key does this job. The command 343 the :map command, you can tell Vim that the F5 key does this job. The command
270 380
271 The ":map" command (with no arguments) lists your current mappings. At 381 The ":map" command (with no arguments) lists your current mappings. At
272 least the ones for Normal mode. More about mappings in section |40.1|. 382 least the ones for Normal mode. More about mappings in section |40.1|.
273 383
274 ============================================================================== 384 ==============================================================================
275 *05.4* Adding a package *add-package* *matchit-install* 385 *05.5* Adding a package *add-package* *matchit-install*
276 386
277 A package is a set of files that you can add to Vim. There are two kinds of 387 A package is a set of files that you can add to Vim. There are two kinds of
278 packages: optional and automatically loaded on startup. 388 packages: optional and automatically loaded on startup.
279 389
280 The Vim distribution comes with a few packages that you can optionally use. 390 The Vim distribution comes with a few packages that you can optionally use.
308 else. 418 else.
309 419
310 More information about packages can be found here: |packages|. 420 More information about packages can be found here: |packages|.
311 421
312 ============================================================================== 422 ==============================================================================
313 *05.5* Adding a plugin *add-plugin* *plugin* 423 *05.6* Adding a plugin *add-plugin* *plugin*
314 424
315 Vim's functionality can be extended by adding plugins. A plugin is nothing 425 Vim's functionality can be extended by adding plugins. A plugin is nothing
316 more than a Vim script file that is loaded automatically when Vim starts. You 426 more than a Vim script file that is loaded automatically when Vim starts. You
317 can add a plugin very easily by dropping it in your plugin directory. 427 can add a plugin very easily by dropping it in your plugin directory.
318 {not available when Vim was compiled without the |+eval| feature} 428 {not available when Vim was compiled without the |+eval| feature}
460 |plugin-details| For more information about using plugins or when your 570 |plugin-details| For more information about using plugins or when your
461 plugin doesn't work. 571 plugin doesn't work.
462 |new-filetype| How to detect a new file type. 572 |new-filetype| How to detect a new file type.
463 573
464 ============================================================================== 574 ==============================================================================
465 *05.6* Adding a help file *add-local-help* 575 *05.7* Adding a help file *add-local-help*
466 576
467 If you are lucky, the plugin you installed also comes with a help file. We 577 If you are lucky, the plugin you installed also comes with a help file. We
468 will explain how to install the help file, so that you can easily find help 578 will explain how to install the help file, so that you can easily find help
469 for your new plugin. 579 for your new plugin.
470 Let us use the "doit.vim" plugin as an example. This plugin comes with 580 Let us use the "doit.vim" plugin as an example. This plugin comes with
505 them through the tag. 615 them through the tag.
506 616
507 For writing a local help file, see |write-local-help|. 617 For writing a local help file, see |write-local-help|.
508 618
509 ============================================================================== 619 ==============================================================================
510 *05.7* The option window 620 *05.8* The option window
511 621
512 If you are looking for an option that does what you want, you can search in 622 If you are looking for an option that does what you want, you can search in
513 the help files here: |options|. Another way is by using this command: > 623 the help files here: |options|. Another way is by using this command: >
514 624
515 :options 625 :options
544 around you will notice that the text starts scrolling before you reach the 654 around you will notice that the text starts scrolling before you reach the
545 border. This is what the 'scrolloff' option does, it specifies an offset 655 border. This is what the 'scrolloff' option does, it specifies an offset
546 from the window border where scrolling starts. 656 from the window border where scrolling starts.
547 657
548 ============================================================================== 658 ==============================================================================
549 *05.8* Often used options 659 *05.9* Often used options
550 660
551 There are an awful lot of options. Most of them you will hardly ever use. 661 There are an awful lot of options. Most of them you will hardly ever use.
552 Some of the more useful ones will be mentioned here. Don't forget you can 662 Some of the more useful ones will be mentioned here. Don't forget you can
553 find more help on these options with the ":help" command, with single quotes 663 find more help on these options with the ":help" command, with single quotes
554 before and after the option name. For example: > 664 before and after the option name. For example: >