Mercurial > vim
annotate runtime/doc/usr_05.txt @ 17233:e7a4d1ac0d0d v8.1.1616
patch 8.1.1616: build failure with gcc on Amiga
commit https://github.com/vim/vim/commit/8531dc66e8da1cb4d944d5b447f6f05e8c91401f
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jul 1 22:28:20 2019 +0200
patch 8.1.1616: build failure with gcc on Amiga
Problem: Build failure with gcc on Amiga.
Solution: Add missing header includes. (Ola S?der, closes https://github.com/vim/vim/issues/4603)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 01 Jul 2019 22:30:05 +0200 |
parents | c002c4899529 |
children | af69c9335223 |
rev | line source |
---|---|
16808 | 1 *usr_05.txt* For Vim version 8.1. Last change: 2019 May 23 |
7 | 2 |
3 VIM USER MANUAL - by Bram Moolenaar | |
4 | |
5 Set your settings | |
6 | |
7 | |
8 Vim can be tuned to work like you want it to. This chapter shows you how to | |
9 make Vim start with options set to different values. Add plugins to extend | |
164 | 10 Vim's capabilities. Or define your own macros. |
7 | 11 |
12 |05.1| The vimrc file | |
13 |05.2| The example vimrc file explained | |
15729 | 14 |05.3| The defaults.vim file explained |
15 |05.4| Simple mappings | |
16 |05.5| Adding a package | |
17 |05.6| Adding a plugin | |
18 |05.7| Adding a help file | |
19 |05.8| The option window | |
20 |05.9| Often used options | |
7 | 21 |
22 Next chapter: |usr_06.txt| Using syntax highlighting | |
23 Previous chapter: |usr_04.txt| Making small changes | |
24 Table of contents: |usr_toc.txt| | |
25 | |
26 ============================================================================== | |
27 *05.1* The vimrc file *vimrc-intro* | |
28 | |
29 You probably got tired of typing commands that you use very often. To start | |
819 | 30 Vim with all your favorite option settings and mappings, you write them in |
31 what is called the vimrc file. Vim executes the commands in this file when it | |
32 starts up. | |
7 | 33 |
819 | 34 If you already have a vimrc file (e.g., when your sysadmin has one setup for |
35 you), you can edit it this way: > | |
7 | 36 |
819 | 37 :edit $MYVIMRC |
38 | |
39 If you don't have a vimrc file yet, see |vimrc| to find out where you can | |
7 | 40 create a vimrc file. Also, the ":version" command mentions the name of the |
41 "user vimrc file" Vim looks for. | |
42 | |
819 | 43 For Unix and Macintosh this file is always used and is recommended: |
7 | 44 |
819 | 45 ~/.vimrc ~ |
7 | 46 |
819 | 47 For MS-DOS and MS-Windows you can use one of these: |
7 | 48 |
819 | 49 $HOME/_vimrc ~ |
50 $VIM/_vimrc ~ | |
7 | 51 |
13341
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
52 If you are creating the vimrc file for the first time, it is recommended to |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
53 put this line at the top: > |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
54 |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
55 source $VIMRUNTIME/defaults.vim |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
56 |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
57 This initializes Vim for new users (as opposed to traditional Vi users). See |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
58 |defaults.vim| for the details. |
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
59 |
7 | 60 The vimrc file can contain all the commands that you type after a colon. The |
61 most simple ones are for setting options. For example, if you want Vim to | |
3967 | 62 always start with the 'incsearch' option on, add this line your vimrc file: > |
7 | 63 |
64 set incsearch | |
65 | |
66 For this new line to take effect you need to exit Vim and start it again. | |
67 Later you will learn how to do this without exiting Vim. | |
68 | |
69 This chapter only explains the most basic items. For more information on how | |
70 to write a Vim script file: |usr_41.txt|. | |
71 | |
72 ============================================================================== | |
73 *05.2* The example vimrc file explained *vimrc_example.vim* | |
74 | |
75 In the first chapter was explained how the example vimrc (included in the | |
76 Vim distribution) file can be used to make Vim startup in not-compatible mode | |
77 (see |not-compatible|). The file can be found here: | |
78 | |
79 $VIMRUNTIME/vimrc_example.vim ~ | |
80 | |
81 In this section we will explain the various commands used in this file. This | |
82 will give you hints about how to set up your own preferences. Not everything | |
83 will be explained though. Use the ":help" command to find out more. | |
84 | |
85 > | |
15729 | 86 " Get the defaults that most users want. |
87 source $VIMRUNTIME/defaults.vim | |
16023 | 88 |
15729 | 89 This loads the "defaults.vim" file in the $VIMRUNTIME directory. This sets up |
90 Vim for how most users like it. If you are one of the few that don't, then | |
91 comment out this line. The commands are explained below: | |
92 |defaults.vim-explained| | |
93 | |
94 > | |
95 if has("vms") | |
96 set nobackup | |
97 else | |
98 set backup | |
99 if has('persistent_undo') | |
100 set undofile | |
101 endif | |
102 endif | |
103 | |
104 This tells Vim to keep a backup copy of a file when overwriting it. But not | |
105 on the VMS system, since it keeps old versions of files already. The backup | |
106 file will have the same name as the original file with "~" added. See |07.4| | |
107 | |
108 This also sets the 'undofile' option, if available. This will store the | |
109 multi-level undo information in a file. The result is that when you change a | |
110 file, exit Vim, and then edit the file again, you can undo the changes made | |
111 previously. It's a very powerful and useful feature, at the cost of storing a | |
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 | |
16023 | 167 |
15729 | 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. | |
16023 | 173 |
15729 | 174 > |
7 | 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 | |
15729 | 187 character before where Insert mode started. See 'backspace'. |
7 | 188 |
15729 | 189 > |
190 set history=200 | |
7 | 191 |
15729 | 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'. | |
16023 | 194 |
7 | 195 > |
196 set ruler | |
197 | |
198 Always display the current cursor position in the lower right corner of the | |
15729 | 199 Vim window. See 'ruler'. |
7 | 200 |
201 > | |
202 set showcmd | |
203 | |
204 Display an incomplete command in the lower right corner of the Vim window, | |
205 left of the ruler. For example, when you type "2f", Vim is waiting for you to | |
206 type the character to find and "2f" is displayed. When you press "w" next, | |
207 the "2fw" command is executed and the displayed "2f" is removed. | |
208 | |
209 +-------------------------------------------------+ | |
210 |text in the Vim window | | |
211 |~ | | |
212 |~ | | |
213 |-- VISUAL -- 2f 43,8 17% | | |
214 +-------------------------------------------------+ | |
215 ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^ | |
216 'showmode' 'showcmd' 'ruler' | |
217 | |
15729 | 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 | |
16808 | 237 line. See 'display'. |
15729 | 238 |
7 | 239 > |
240 set incsearch | |
241 | |
15729 | 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'. | |
7 | 249 |
250 > | |
251 map Q gq | |
252 | |
253 This defines a key mapping. More about that in the next section. This | |
254 defines the "Q" command to do formatting with the "gq" operator. This is how | |
255 it worked before Vim 5.0. Otherwise the "Q" command starts Ex mode, but you | |
256 will not need it. | |
257 | |
258 > | |
15729 | 259 inoremap <C-U> <C-G>u<C-U> |
16023 | 260 |
15729 | 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 > | |
43 | 273 vnoremap _g y:exe "grep /" . escape(@", '\\/') . "/ *.c *.h"<CR> |
7 | 274 |
43 | 275 This mapping yanks the visually selected text and searches for it in C files. |
15729 | 276 You can see that a mapping can be used to do quite complicated things. Still, |
277 it is just a sequence of commands that are executed like you typed them. | |
7 | 278 |
279 > | |
15729 | 280 syntax on |
7 | 281 |
15729 | 282 Enable highlighting files in color. See |syntax|. |
7 | 283 |
284 *vimrc-filetype* > | |
285 filetype plugin indent on | |
286 | |
287 This switches on three very clever mechanisms: | |
288 1. Filetype detection. | |
289 Whenever you start editing a file, Vim will try to figure out what kind of | |
290 file this is. When you edit "main.c", Vim will see the ".c" extension and | |
291 recognize this as a "c" filetype. When you edit a file that starts with | |
292 "#!/bin/sh", Vim will recognize it as a "sh" filetype. | |
293 The filetype detection is used for syntax highlighting and the other two | |
294 items below. | |
295 See |filetypes|. | |
296 | |
297 2. Using filetype plugin files | |
298 Many different filetypes are edited with different options. For example, | |
299 when you edit a "c" file, it's very useful to set the 'cindent' option to | |
300 automatically indent the lines. These commonly useful option settings are | |
301 included with Vim in filetype plugins. You can also add your own, see | |
302 |write-filetype-plugin|. | |
303 | |
304 3. Using indent files | |
305 When editing programs, the indent of a line can often be computed | |
306 automatically. Vim comes with these indent rules for a number of | |
307 filetypes. See |:filetype-indent-on| and 'indentexpr'. | |
308 | |
309 | |
15729 | 310 *restore-cursor* *last-position-jump* > |
311 autocmd BufReadPost * | |
312 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' | |
313 \ | exe "normal! g`\"" | |
314 \ | endif | |
7 | 315 |
316 Another autocommand. This time it is used after reading any file. The | |
317 complicated stuff after it checks if the '" mark is defined, and jumps to it | |
318 if so. The backslash at the start of a line is used to continue the command | |
319 from the previous line. That avoids a line getting very long. | |
320 See |line-continuation|. This only works in a Vim script file, not when | |
321 typing commands at the command-line. | |
322 | |
15729 | 323 > |
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 | |
16023 | 328 differences with the file it was loaded from. See |diff| and |:DiffOrig|. |
15729 | 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 | |
7 | 337 ============================================================================== |
15729 | 338 *05.4* Simple mappings |
7 | 339 |
340 A mapping enables you to bind a set of Vim commands to a single key. Suppose, | |
341 for example, that you need to surround certain words with curly braces. In | |
342 other words, you need to change a word such as "amount" into "{amount}". With | |
343 the :map command, you can tell Vim that the F5 key does this job. The command | |
344 is as follows: > | |
345 | |
346 :map <F5> i{<Esc>ea}<Esc> | |
347 < | |
348 Note: | |
349 When entering this command, you must enter <F5> by typing four | |
350 characters. Similarly, <Esc> is not entered by pressing the <Esc> | |
351 key, but by typing five characters. Watch out for this difference | |
352 when reading the manual! | |
353 | |
354 Let's break this down: | |
355 <F5> The F5 function key. This is the trigger key that causes the | |
356 command to be executed as the key is pressed. | |
357 | |
358 i{<Esc> Insert the { character. The <Esc> key ends Insert mode. | |
359 | |
360 e Move to the end of the word. | |
361 | |
362 a}<Esc> Append the } to the word. | |
363 | |
364 After you execute the ":map" command, all you have to do to put {} around a | |
365 word is to put the cursor on the first character and press F5. | |
366 | |
367 In this example, the trigger is a single key; it can be any string. But when | |
368 you use an existing Vim command, that command will no longer be available. | |
369 You better avoid that. | |
370 One key that can be used with mappings is the backslash. Since you | |
371 probably want to define more than one mapping, add another character. You | |
164 | 372 could map "\p" to add parentheses around a word, and "\c" to add curly braces, |
373 for example: > | |
7 | 374 |
375 :map \p i(<Esc>ea)<Esc> | |
376 :map \c i{<Esc>ea}<Esc> | |
377 | |
378 You need to type the \ and the p quickly after another, so that Vim knows they | |
379 belong together. | |
380 | |
381 The ":map" command (with no arguments) lists your current mappings. At | |
382 least the ones for Normal mode. More about mappings in section |40.1|. | |
383 | |
384 ============================================================================== | |
15729 | 385 *05.5* Adding a package *add-package* *matchit-install* |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
386 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
387 A package is a set of files that you can add to Vim. There are two kinds of |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
388 packages: optional and automatically loaded on startup. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
389 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
390 The Vim distribution comes with a few packages that you can optionally use. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
391 For example, the matchit plugin. This plugin makes the "%" command jump to |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
392 matching HTML tags, if/else/endif in Vim scripts, etc. Very useful, although |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
393 it's not backwards compatible (that's why it is not enabled by default). |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
394 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
395 To start using the matchit plugin, add one line to your vimrc file: > |
8748
b1a19a2f73f0
commit https://github.com/vim/vim/commit/4f3f668c8486444e53163c29d2fc79bf47eb3c82
Christian Brabandt <cb@256bit.org>
parents:
8720
diff
changeset
|
396 packadd! matchit |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
397 |
8748
b1a19a2f73f0
commit https://github.com/vim/vim/commit/4f3f668c8486444e53163c29d2fc79bf47eb3c82
Christian Brabandt <cb@256bit.org>
parents:
8720
diff
changeset
|
398 That's all! After restarting Vim you can find help about this plugin: > |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
399 :help matchit |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
400 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
401 This works, because when `:packadd` loaded the plugin it also added the |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
402 package directory in 'runtimepath', so that the help file can be found. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
403 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
404 You can find packages on the Internet in various places. It usually comes as |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
405 an archive or as a repository. For an archive you can follow these steps: |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
406 1. create the package directory: > |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
407 mkdir -p ~/.vim/pack/fancy |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
408 < "fancy" can be any name of your liking. Use one that describes the |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
409 package. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
410 2. unpack the archive in that directory. This assumes the top |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
411 directory in the archive is "start": > |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
412 cd ~/.vim/pack/fancy |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
413 unzip /tmp/fancy.zip |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
414 < If the archive layout is different make sure that you end up with a |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
415 path like this: |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
416 ~/.vim/pack/fancy/start/fancytext/plugin/fancy.vim ~ |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
417 Here "fancytext" is the name of the package, it can be anything |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
418 else. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
419 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
420 More information about packages can be found here: |packages|. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
421 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
422 ============================================================================== |
15729 | 423 *05.6* Adding a plugin *add-plugin* *plugin* |
7 | 424 |
425 Vim's functionality can be extended by adding plugins. A plugin is nothing | |
426 more than a Vim script file that is loaded automatically when Vim starts. You | |
427 can add a plugin very easily by dropping it in your plugin directory. | |
428 {not available when Vim was compiled without the |+eval| feature} | |
429 | |
430 There are two types of plugins: | |
431 | |
432 global plugin: Used for all kinds of files | |
433 filetype plugin: Only used for a specific type of file | |
434 | |
435 The global plugins will be discussed first, then the filetype ones | |
436 |add-filetype-plugin|. | |
437 | |
438 | |
439 GLOBAL PLUGINS *standard-plugin* | |
440 | |
441 When you start Vim, it will automatically load a number of global plugins. | |
442 You don't have to do anything for this. They add functionality that most | |
443 people will want to use, but which was implemented as a Vim script instead of | |
444 being compiled into Vim. You can find them listed in the help index | |
445 |standard-plugin-list|. Also see |load-plugins|. | |
446 | |
447 *add-global-plugin* | |
448 You can add a global plugin to add functionality that will always be present | |
449 when you use Vim. There are only two steps for adding a global plugin: | |
450 1. Get a copy of the plugin. | |
451 2. Drop it in the right directory. | |
452 | |
453 | |
454 GETTING A GLOBAL PLUGIN | |
455 | |
456 Where can you find plugins? | |
14372 | 457 - Some are always loaded, you can see them in the directory $VIMRUNTIME/plugin. |
7 | 458 - Some come with Vim. You can find them in the directory $VIMRUNTIME/macros |
14372 | 459 and its sub-directories and under $VIM/vimfiles/pack/dist/opt/. |
800 | 460 - Download from the net. There is a large collection on http://www.vim.org. |
7 | 461 - They are sometimes posted in a Vim |maillist|. |
462 - You could write one yourself, see |write-plugin|. | |
463 | |
800 | 464 Some plugins come as a vimball archive, see |vimball|. |
465 Some plugins can be updated automatically, see |getscript|. | |
466 | |
7 | 467 |
468 USING A GLOBAL PLUGIN | |
469 | |
470 First read the text in the plugin itself to check for any special conditions. | |
471 Then copy the file to your plugin directory: | |
472 | |
473 system plugin directory ~ | |
474 Unix ~/.vim/plugin/ | |
475 PC and OS/2 $HOME/vimfiles/plugin or $VIM/vimfiles/plugin | |
476 Amiga s:vimfiles/plugin | |
477 Macintosh $VIM:vimfiles:plugin | |
478 Mac OS X ~/.vim/plugin/ | |
479 RISC-OS Choices:vimfiles.plugin | |
480 | |
481 Example for Unix (assuming you didn't have a plugin directory yet): > | |
482 | |
483 mkdir ~/.vim | |
484 mkdir ~/.vim/plugin | |
8795
aba2d0a01290
commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
485 cp /tmp/yourplugin.vim ~/.vim/plugin |
7 | 486 |
8795
aba2d0a01290
commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
487 That's all! Now you can use the commands defined in this plugin. |
7 | 488 |
548 | 489 Instead of putting plugins directly into the plugin/ directory, you may |
490 better organize them by putting them into subdirectories under plugin/. | |
491 As an example, consider using "~/.vim/plugin/perl/*.vim" for all your Perl | |
492 plugins. | |
541 | 493 |
7 | 494 |
495 FILETYPE PLUGINS *add-filetype-plugin* *ftplugins* | |
496 | |
497 The Vim distribution comes with a set of plugins for different filetypes that | |
498 you can start using with this command: > | |
499 | |
500 :filetype plugin on | |
501 | |
502 That's all! See |vimrc-filetype|. | |
503 | |
504 If you are missing a plugin for a filetype you are using, or you found a | |
505 better one, you can add it. There are two steps for adding a filetype plugin: | |
506 1. Get a copy of the plugin. | |
507 2. Drop it in the right directory. | |
508 | |
509 | |
510 GETTING A FILETYPE PLUGIN | |
511 | |
512 You can find them in the same places as the global plugins. Watch out if the | |
513 type of file is mentioned, then you know if the plugin is a global or a | |
514 filetype one. The scripts in $VIMRUNTIME/macros are global ones, the filetype | |
515 plugins are in $VIMRUNTIME/ftplugin. | |
516 | |
517 | |
518 USING A FILETYPE PLUGIN *ftplugin-name* | |
519 | |
520 You can add a filetype plugin by dropping it in the right directory. The | |
521 name of this directory is in the same directory mentioned above for global | |
522 plugins, but the last part is "ftplugin". Suppose you have found a plugin for | |
523 the "stuff" filetype, and you are on Unix. Then you can move this file to the | |
524 ftplugin directory: > | |
525 | |
526 mv thefile ~/.vim/ftplugin/stuff.vim | |
527 | |
528 If that file already exists you already have a plugin for "stuff". You might | |
529 want to check if the existing plugin doesn't conflict with the one you are | |
530 adding. If it's OK, you can give the new one another name: > | |
531 | |
532 mv thefile ~/.vim/ftplugin/stuff_too.vim | |
533 | |
534 The underscore is used to separate the name of the filetype from the rest, | |
10 | 535 which can be anything. If you use "otherstuff.vim" it wouldn't work, it would |
536 be loaded for the "otherstuff" filetype. | |
7 | 537 |
538 On MS-DOS you cannot use long filenames. You would run into trouble if you | |
539 add a second plugin and the filetype has more than six characters. You can | |
540 use an extra directory to get around this: > | |
541 | |
542 mkdir $VIM/vimfiles/ftplugin/fortran | |
543 copy thefile $VIM/vimfiles/ftplugin/fortran/too.vim | |
544 | |
545 The generic names for the filetype plugins are: > | |
546 | |
547 ftplugin/<filetype>.vim | |
548 ftplugin/<filetype>_<name>.vim | |
549 ftplugin/<filetype>/<name>.vim | |
550 | |
551 Here "<name>" can be any name that you prefer. | |
552 Examples for the "stuff" filetype on Unix: > | |
553 | |
554 ~/.vim/ftplugin/stuff.vim | |
555 ~/.vim/ftplugin/stuff_def.vim | |
556 ~/.vim/ftplugin/stuff/header.vim | |
557 | |
558 The <filetype> part is the name of the filetype the plugin is to be used for. | |
559 Only files of this filetype will use the settings from the plugin. The <name> | |
560 part of the plugin file doesn't matter, you can use it to have several plugins | |
561 for the same filetype. Note that it must end in ".vim". | |
562 | |
563 | |
564 Further reading: | |
565 |filetype-plugins| Documentation for the filetype plugins and information | |
566 about how to avoid that mappings cause problems. | |
567 |load-plugins| When the global plugins are loaded during startup. | |
568 |ftplugin-overrule| Overruling the settings from a global plugin. | |
569 |write-plugin| How to write a plugin script. | |
570 |plugin-details| For more information about using plugins or when your | |
571 plugin doesn't work. | |
572 |new-filetype| How to detect a new file type. | |
573 | |
574 ============================================================================== | |
15729 | 575 *05.7* Adding a help file *add-local-help* |
7 | 576 |
577 If you are lucky, the plugin you installed also comes with a help file. We | |
578 will explain how to install the help file, so that you can easily find help | |
579 for your new plugin. | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
580 Let us use the "doit.vim" plugin as an example. This plugin comes with |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
581 documentation: "doit.txt". Let's first copy the plugin to the right |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
582 directory. This time we will do it from inside Vim. (You may skip some of |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
583 the "mkdir" commands if you already have the directory.) > |
7 | 584 |
585 :!mkdir ~/.vim | |
586 :!mkdir ~/.vim/plugin | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
587 :!cp /tmp/doit.vim ~/.vim/plugin |
7 | 588 |
22 | 589 The "cp" command is for Unix, on MS-DOS you can use "copy". |
590 | |
7 | 591 Now create a "doc" directory in one of the directories in 'runtimepath'. > |
592 | |
593 :!mkdir ~/.vim/doc | |
594 | |
595 Copy the help file to the "doc" directory. > | |
596 | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
597 :!cp /tmp/doit.txt ~/.vim/doc |
7 | 598 |
599 Now comes the trick, which allows you to jump to the subjects in the new help | |
600 file: Generate the local tags file with the |:helptags| command. > | |
601 | |
602 :helptags ~/.vim/doc | |
603 | |
604 Now you can use the > | |
605 | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
606 :help doit |
7 | 607 |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
608 command to find help for "doit" in the help file you just added. You can see |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
609 an entry for the local help file when you do: > |
7 | 610 |
611 :help local-additions | |
612 | |
613 The title lines from the local help files are automagically added to this | |
614 section. There you can see which local help files have been added and jump to | |
615 them through the tag. | |
616 | |
617 For writing a local help file, see |write-local-help|. | |
618 | |
619 ============================================================================== | |
15729 | 620 *05.8* The option window |
7 | 621 |
622 If you are looking for an option that does what you want, you can search in | |
623 the help files here: |options|. Another way is by using this command: > | |
624 | |
625 :options | |
626 | |
627 This opens a new window, with a list of options with a one-line explanation. | |
628 The options are grouped by subject. Move the cursor to a subject and press | |
629 <Enter> to jump there. Press <Enter> again to jump back. Or use CTRL-O. | |
630 | |
631 You can change the value of an option. For example, move to the "displaying | |
632 text" subject. Then move the cursor down to this line: | |
633 | |
634 set wrap nowrap ~ | |
635 | |
636 When you hit <Enter>, the line will change to: | |
637 | |
638 set nowrap wrap ~ | |
639 | |
640 The option has now been switched off. | |
641 | |
642 Just above this line is a short description of the 'wrap' option. Move the | |
643 cursor one line up to place it in this line. Now hit <Enter> and you jump to | |
644 the full help on the 'wrap' option. | |
645 | |
646 For options that take a number or string argument you can edit the value. | |
647 Then press <Enter> to apply the new value. For example, move the cursor a few | |
648 lines up to this line: | |
649 | |
650 set so=0 ~ | |
651 | |
652 Position the cursor on the zero with "$". Change it into a five with "r5". | |
653 Then press <Enter> to apply the new value. When you now move the cursor | |
654 around you will notice that the text starts scrolling before you reach the | |
655 border. This is what the 'scrolloff' option does, it specifies an offset | |
656 from the window border where scrolling starts. | |
657 | |
658 ============================================================================== | |
15729 | 659 *05.9* Often used options |
7 | 660 |
661 There are an awful lot of options. Most of them you will hardly ever use. | |
662 Some of the more useful ones will be mentioned here. Don't forget you can | |
663 find more help on these options with the ":help" command, with single quotes | |
664 before and after the option name. For example: > | |
665 | |
666 :help 'wrap' | |
667 | |
668 In case you have messed up an option value, you can set it back to the | |
10 | 669 default by putting an ampersand (&) after the option name. Example: > |
7 | 670 |
671 :set iskeyword& | |
672 | |
673 | |
674 NOT WRAPPING LINES | |
675 | |
676 Vim normally wraps long lines, so that you can see all of the text. Sometimes | |
677 it's better to let the text continue right of the window. Then you need to | |
10 | 678 scroll the text left-right to see all of a long line. Switch wrapping off |
679 with this command: > | |
7 | 680 |
681 :set nowrap | |
682 | |
683 Vim will automatically scroll the text when you move to text that is not | |
684 displayed. To see a context of ten characters, do this: > | |
685 | |
686 :set sidescroll=10 | |
687 | |
688 This doesn't change the text in the file, only the way it is displayed. | |
689 | |
690 | |
691 WRAPPING MOVEMENT COMMANDS | |
692 | |
693 Most commands for moving around will stop moving at the start and end of a | |
694 line. You can change that with the 'whichwrap' option. This sets it to the | |
695 default value: > | |
696 | |
697 :set whichwrap=b,s | |
698 | |
699 This allows the <BS> key, when used in the first position of a line, to move | |
700 the cursor to the end of the previous line. And the <Space> key moves from | |
701 the end of a line to the start of the next one. | |
702 | |
703 To allow the cursor keys <Left> and <Right> to also wrap, use this command: > | |
704 | |
705 :set whichwrap=b,s,<,> | |
706 | |
707 This is still only for Normal mode. To let <Left> and <Right> do this in | |
708 Insert mode as well: > | |
709 | |
710 :set whichwrap=b,s,<,>,[,] | |
711 | |
712 There are a few other flags that can be added, see 'whichwrap'. | |
713 | |
714 | |
715 VIEWING TABS | |
716 | |
717 When there are tabs in a file, you cannot see where they are. To make them | |
718 visible: > | |
719 | |
720 :set list | |
721 | |
1278 | 722 Now every tab is displayed as ^I. And a $ is displayed at the end of each |
7 | 723 line, so that you can spot trailing spaces that would otherwise go unnoticed. |
724 A disadvantage is that this looks ugly when there are many Tabs in a file. | |
725 If you have a color terminal, or are using the GUI, Vim can show the spaces | |
726 and tabs as highlighted characters. Use the 'listchars' option: > | |
727 | |
728 :set listchars=tab:>-,trail:- | |
729 | |
730 Now every tab will be displayed as ">---" (with more or less "-") and trailing | |
731 white space as "-". Looks a lot better, doesn't it? | |
732 | |
733 | |
734 KEYWORDS | |
735 | |
736 The 'iskeyword' option specifies which characters can appear in a word: > | |
737 | |
738 :set iskeyword | |
739 < iskeyword=@,48-57,_,192-255 ~ | |
740 | |
741 The "@" stands for all alphabetic letters. "48-57" stands for ASCII | |
742 characters 48 to 57, which are the numbers 0 to 9. "192-255" are the | |
743 printable latin characters. | |
744 Sometimes you will want to include a dash in keywords, so that commands | |
745 like "w" consider "upper-case" to be one word. You can do it like this: > | |
746 | |
747 :set iskeyword+=- | |
748 :set iskeyword | |
749 < iskeyword=@,48-57,_,192-255,- ~ | |
750 | |
751 If you look at the new value, you will see that Vim has added a comma for you. | |
752 To remove a character use "-=". For example, to remove the underscore: > | |
753 | |
754 :set iskeyword-=_ | |
755 :set iskeyword | |
756 < iskeyword=@,48-57,192-255,- ~ | |
757 | |
758 This time a comma is automatically deleted. | |
759 | |
760 | |
761 ROOM FOR MESSAGES | |
762 | |
763 When Vim starts there is one line at the bottom that is used for messages. | |
764 When a message is long, it is either truncated, thus you can only see part of | |
765 it, or the text scrolls and you have to press <Enter> to continue. | |
766 You can set the 'cmdheight' option to the number of lines used for | |
767 messages. Example: > | |
768 | |
769 :set cmdheight=3 | |
770 | |
771 This does mean there is less room to edit text, thus it's a compromise. | |
772 | |
773 ============================================================================== | |
774 | |
775 Next chapter: |usr_06.txt| Using syntax highlighting | |
776 | |
14519 | 777 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: |