Mercurial > vim
annotate runtime/doc/usr_05.txt @ 9900:daecffbd0322 v7.4.2224
commit https://github.com/vim/vim/commit/af9c4c9b5761c4c074237d87e2c95713bf721eab
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 17 21:51:56 2016 +0200
patch 7.4.2224
Problem: Compiler warnings with older compiler and 64 bit numbers.
Solution: Add "LL" to large values. (Mike Williams)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 17 Aug 2016 22:00:07 +0200 |
parents | aba2d0a01290 |
children | 9f48eab77d62 |
rev | line source |
---|---|
8795
aba2d0a01290
commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
1 *usr_05.txt* For Vim version 7.4. Last change: 2016 Mar 28 |
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 | |
14 |05.3| Simple mappings | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
15 |05.4| Adding a package |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
16 |05.5| Adding a plugin |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
17 |05.6| Adding a help file |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
18 |05.7| The option window |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
19 |05.8| Often used options |
7 | 20 |
21 Next chapter: |usr_06.txt| Using syntax highlighting | |
22 Previous chapter: |usr_04.txt| Making small changes | |
23 Table of contents: |usr_toc.txt| | |
24 | |
25 ============================================================================== | |
26 *05.1* The vimrc file *vimrc-intro* | |
27 | |
28 You probably got tired of typing commands that you use very often. To start | |
819 | 29 Vim with all your favorite option settings and mappings, you write them in |
30 what is called the vimrc file. Vim executes the commands in this file when it | |
31 starts up. | |
7 | 32 |
819 | 33 If you already have a vimrc file (e.g., when your sysadmin has one setup for |
34 you), you can edit it this way: > | |
7 | 35 |
819 | 36 :edit $MYVIMRC |
37 | |
38 If you don't have a vimrc file yet, see |vimrc| to find out where you can | |
7 | 39 create a vimrc file. Also, the ":version" command mentions the name of the |
40 "user vimrc file" Vim looks for. | |
41 | |
819 | 42 For Unix and Macintosh this file is always used and is recommended: |
7 | 43 |
819 | 44 ~/.vimrc ~ |
7 | 45 |
819 | 46 For MS-DOS and MS-Windows you can use one of these: |
7 | 47 |
819 | 48 $HOME/_vimrc ~ |
49 $VIM/_vimrc ~ | |
7 | 50 |
51 The vimrc file can contain all the commands that you type after a colon. The | |
52 most simple ones are for setting options. For example, if you want Vim to | |
3967 | 53 always start with the 'incsearch' option on, add this line your vimrc file: > |
7 | 54 |
55 set incsearch | |
56 | |
57 For this new line to take effect you need to exit Vim and start it again. | |
58 Later you will learn how to do this without exiting Vim. | |
59 | |
60 This chapter only explains the most basic items. For more information on how | |
61 to write a Vim script file: |usr_41.txt|. | |
62 | |
63 ============================================================================== | |
64 *05.2* The example vimrc file explained *vimrc_example.vim* | |
65 | |
66 In the first chapter was explained how the example vimrc (included in the | |
67 Vim distribution) file can be used to make Vim startup in not-compatible mode | |
68 (see |not-compatible|). The file can be found here: | |
69 | |
70 $VIMRUNTIME/vimrc_example.vim ~ | |
71 | |
72 In this section we will explain the various commands used in this file. This | |
73 will give you hints about how to set up your own preferences. Not everything | |
74 will be explained though. Use the ":help" command to find out more. | |
75 | |
76 > | |
77 set nocompatible | |
78 | |
79 As mentioned in the first chapter, these manuals explain Vim working in an | |
80 improved way, thus not completely Vi compatible. Setting the 'compatible' | |
81 option off, thus 'nocompatible' takes care of this. | |
82 | |
83 > | |
84 set backspace=indent,eol,start | |
85 | |
86 This specifies where in Insert mode the <BS> is allowed to delete the | |
87 character in front of the cursor. The three items, separated by commas, tell | |
88 Vim to delete the white space at the start of the line, a line break and the | |
89 character before where Insert mode started. | |
90 > | |
91 | |
92 set autoindent | |
93 | |
94 This makes Vim use the indent of the previous line for a newly created line. | |
95 Thus there is the same amount of white space before the new line. For example | |
96 when pressing <Enter> in Insert mode, and when using the "o" command to open a | |
97 new line. | |
98 > | |
99 | |
100 if has("vms") | |
101 set nobackup | |
102 else | |
103 set backup | |
104 endif | |
105 | |
106 This tells Vim to keep a backup copy of a file when overwriting it. But not | |
107 on the VMS system, since it keeps old versions of files already. The backup | |
108 file will have the same name as the original file with "~" added. See |07.4| | |
109 > | |
110 | |
111 set history=50 | |
112 | |
113 Keep 50 commands and 50 search patterns in the history. Use another number if | |
114 you want to remember fewer or more lines. | |
115 > | |
116 | |
117 set ruler | |
118 | |
119 Always display the current cursor position in the lower right corner of the | |
120 Vim window. | |
121 | |
122 > | |
123 set showcmd | |
124 | |
125 Display an incomplete command in the lower right corner of the Vim window, | |
126 left of the ruler. For example, when you type "2f", Vim is waiting for you to | |
127 type the character to find and "2f" is displayed. When you press "w" next, | |
128 the "2fw" command is executed and the displayed "2f" is removed. | |
129 | |
130 +-------------------------------------------------+ | |
131 |text in the Vim window | | |
132 |~ | | |
133 |~ | | |
134 |-- VISUAL -- 2f 43,8 17% | | |
135 +-------------------------------------------------+ | |
136 ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^ | |
137 'showmode' 'showcmd' 'ruler' | |
138 | |
139 > | |
140 set incsearch | |
141 | |
142 Display the match for a search pattern when halfway typing it. | |
143 | |
144 > | |
145 map Q gq | |
146 | |
147 This defines a key mapping. More about that in the next section. This | |
148 defines the "Q" command to do formatting with the "gq" operator. This is how | |
149 it worked before Vim 5.0. Otherwise the "Q" command starts Ex mode, but you | |
150 will not need it. | |
151 | |
152 > | |
43 | 153 vnoremap _g y:exe "grep /" . escape(@", '\\/') . "/ *.c *.h"<CR> |
7 | 154 |
43 | 155 This mapping yanks the visually selected text and searches for it in C files. |
156 This is a complicated mapping. You can see that mappings can be used to do | |
157 quite complicated things. Still, it is just a sequence of commands that are | |
7 | 158 executed like you typed them. |
159 | |
160 > | |
161 if &t_Co > 2 || has("gui_running") | |
162 syntax on | |
163 set hlsearch | |
164 endif | |
165 | |
166 This switches on syntax highlighting, but only if colors are available. And | |
167 the 'hlsearch' option tells Vim to highlight matches with the last used search | |
168 pattern. The "if" command is very useful to set options only when some | |
169 condition is met. More about that in |usr_41.txt|. | |
170 | |
171 *vimrc-filetype* > | |
172 filetype plugin indent on | |
173 | |
174 This switches on three very clever mechanisms: | |
175 1. Filetype detection. | |
176 Whenever you start editing a file, Vim will try to figure out what kind of | |
177 file this is. When you edit "main.c", Vim will see the ".c" extension and | |
178 recognize this as a "c" filetype. When you edit a file that starts with | |
179 "#!/bin/sh", Vim will recognize it as a "sh" filetype. | |
180 The filetype detection is used for syntax highlighting and the other two | |
181 items below. | |
182 See |filetypes|. | |
183 | |
184 2. Using filetype plugin files | |
185 Many different filetypes are edited with different options. For example, | |
186 when you edit a "c" file, it's very useful to set the 'cindent' option to | |
187 automatically indent the lines. These commonly useful option settings are | |
188 included with Vim in filetype plugins. You can also add your own, see | |
189 |write-filetype-plugin|. | |
190 | |
191 3. Using indent files | |
192 When editing programs, the indent of a line can often be computed | |
193 automatically. Vim comes with these indent rules for a number of | |
194 filetypes. See |:filetype-indent-on| and 'indentexpr'. | |
195 | |
196 > | |
197 autocmd FileType text setlocal textwidth=78 | |
198 | |
199 This makes Vim break text to avoid lines getting longer than 78 characters. | |
200 But only for files that have been detected to be plain text. There are | |
201 actually two parts here. "autocmd FileType text" is an autocommand. This | |
202 defines that when the file type is set to "text" the following command is | |
203 automatically executed. "setlocal textwidth=78" sets the 'textwidth' option | |
204 to 78, but only locally in one file. | |
205 | |
1125 | 206 *restore-cursor* > |
7 | 207 autocmd BufReadPost * |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
208 \ if line("'\"") > 1 && line("'\"") <= line("$") | |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
209 \ exe "normal! g`\"" | |
7 | 210 \ endif |
211 | |
212 Another autocommand. This time it is used after reading any file. The | |
213 complicated stuff after it checks if the '" mark is defined, and jumps to it | |
214 if so. The backslash at the start of a line is used to continue the command | |
215 from the previous line. That avoids a line getting very long. | |
216 See |line-continuation|. This only works in a Vim script file, not when | |
217 typing commands at the command-line. | |
218 | |
219 ============================================================================== | |
220 *05.3* Simple mappings | |
221 | |
222 A mapping enables you to bind a set of Vim commands to a single key. Suppose, | |
223 for example, that you need to surround certain words with curly braces. In | |
224 other words, you need to change a word such as "amount" into "{amount}". With | |
225 the :map command, you can tell Vim that the F5 key does this job. The command | |
226 is as follows: > | |
227 | |
228 :map <F5> i{<Esc>ea}<Esc> | |
229 < | |
230 Note: | |
231 When entering this command, you must enter <F5> by typing four | |
232 characters. Similarly, <Esc> is not entered by pressing the <Esc> | |
233 key, but by typing five characters. Watch out for this difference | |
234 when reading the manual! | |
235 | |
236 Let's break this down: | |
237 <F5> The F5 function key. This is the trigger key that causes the | |
238 command to be executed as the key is pressed. | |
239 | |
240 i{<Esc> Insert the { character. The <Esc> key ends Insert mode. | |
241 | |
242 e Move to the end of the word. | |
243 | |
244 a}<Esc> Append the } to the word. | |
245 | |
246 After you execute the ":map" command, all you have to do to put {} around a | |
247 word is to put the cursor on the first character and press F5. | |
248 | |
249 In this example, the trigger is a single key; it can be any string. But when | |
250 you use an existing Vim command, that command will no longer be available. | |
251 You better avoid that. | |
252 One key that can be used with mappings is the backslash. Since you | |
253 probably want to define more than one mapping, add another character. You | |
164 | 254 could map "\p" to add parentheses around a word, and "\c" to add curly braces, |
255 for example: > | |
7 | 256 |
257 :map \p i(<Esc>ea)<Esc> | |
258 :map \c i{<Esc>ea}<Esc> | |
259 | |
260 You need to type the \ and the p quickly after another, so that Vim knows they | |
261 belong together. | |
262 | |
263 The ":map" command (with no arguments) lists your current mappings. At | |
264 least the ones for Normal mode. More about mappings in section |40.1|. | |
265 | |
266 ============================================================================== | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
267 *05.4* Adding a package *add-package* *matchit-install* |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
268 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
269 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
|
270 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
|
271 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 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
|
276 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
277 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
|
278 packadd! matchit |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
279 |
8748
b1a19a2f73f0
commit https://github.com/vim/vim/commit/4f3f668c8486444e53163c29d2fc79bf47eb3c82
Christian Brabandt <cb@256bit.org>
parents:
8720
diff
changeset
|
280 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
|
281 :help matchit |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
282 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
283 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
|
284 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
|
285 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
286 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
|
287 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
|
288 1. create the package directory: > |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
289 mkdir -p ~/.vim/pack/fancy |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
290 < "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
|
291 package. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
292 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
|
293 directory in the archive is "start": > |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
294 cd ~/.vim/pack/fancy |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
295 unzip /tmp/fancy.zip |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
296 < 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
|
297 path like this: |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
298 ~/.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
|
299 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
|
300 else. |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
301 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
302 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
|
303 |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
304 ============================================================================== |
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
305 *05.5* Adding a plugin *add-plugin* *plugin* |
7 | 306 |
307 Vim's functionality can be extended by adding plugins. A plugin is nothing | |
308 more than a Vim script file that is loaded automatically when Vim starts. You | |
309 can add a plugin very easily by dropping it in your plugin directory. | |
310 {not available when Vim was compiled without the |+eval| feature} | |
311 | |
312 There are two types of plugins: | |
313 | |
314 global plugin: Used for all kinds of files | |
315 filetype plugin: Only used for a specific type of file | |
316 | |
317 The global plugins will be discussed first, then the filetype ones | |
318 |add-filetype-plugin|. | |
319 | |
320 | |
321 GLOBAL PLUGINS *standard-plugin* | |
322 | |
323 When you start Vim, it will automatically load a number of global plugins. | |
324 You don't have to do anything for this. They add functionality that most | |
325 people will want to use, but which was implemented as a Vim script instead of | |
326 being compiled into Vim. You can find them listed in the help index | |
327 |standard-plugin-list|. Also see |load-plugins|. | |
328 | |
329 *add-global-plugin* | |
330 You can add a global plugin to add functionality that will always be present | |
331 when you use Vim. There are only two steps for adding a global plugin: | |
332 1. Get a copy of the plugin. | |
333 2. Drop it in the right directory. | |
334 | |
335 | |
336 GETTING A GLOBAL PLUGIN | |
337 | |
338 Where can you find plugins? | |
339 - Some come with Vim. You can find them in the directory $VIMRUNTIME/macros | |
340 and its sub-directories. | |
800 | 341 - Download from the net. There is a large collection on http://www.vim.org. |
7 | 342 - They are sometimes posted in a Vim |maillist|. |
343 - You could write one yourself, see |write-plugin|. | |
344 | |
800 | 345 Some plugins come as a vimball archive, see |vimball|. |
346 Some plugins can be updated automatically, see |getscript|. | |
347 | |
7 | 348 |
349 USING A GLOBAL PLUGIN | |
350 | |
351 First read the text in the plugin itself to check for any special conditions. | |
352 Then copy the file to your plugin directory: | |
353 | |
354 system plugin directory ~ | |
355 Unix ~/.vim/plugin/ | |
356 PC and OS/2 $HOME/vimfiles/plugin or $VIM/vimfiles/plugin | |
357 Amiga s:vimfiles/plugin | |
358 Macintosh $VIM:vimfiles:plugin | |
359 Mac OS X ~/.vim/plugin/ | |
360 RISC-OS Choices:vimfiles.plugin | |
361 | |
362 Example for Unix (assuming you didn't have a plugin directory yet): > | |
363 | |
364 mkdir ~/.vim | |
365 mkdir ~/.vim/plugin | |
8795
aba2d0a01290
commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
366 cp /tmp/yourplugin.vim ~/.vim/plugin |
7 | 367 |
8795
aba2d0a01290
commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
368 That's all! Now you can use the commands defined in this plugin. |
7 | 369 |
548 | 370 Instead of putting plugins directly into the plugin/ directory, you may |
371 better organize them by putting them into subdirectories under plugin/. | |
372 As an example, consider using "~/.vim/plugin/perl/*.vim" for all your Perl | |
373 plugins. | |
541 | 374 |
7 | 375 |
376 FILETYPE PLUGINS *add-filetype-plugin* *ftplugins* | |
377 | |
378 The Vim distribution comes with a set of plugins for different filetypes that | |
379 you can start using with this command: > | |
380 | |
381 :filetype plugin on | |
382 | |
383 That's all! See |vimrc-filetype|. | |
384 | |
385 If you are missing a plugin for a filetype you are using, or you found a | |
386 better one, you can add it. There are two steps for adding a filetype plugin: | |
387 1. Get a copy of the plugin. | |
388 2. Drop it in the right directory. | |
389 | |
390 | |
391 GETTING A FILETYPE PLUGIN | |
392 | |
393 You can find them in the same places as the global plugins. Watch out if the | |
394 type of file is mentioned, then you know if the plugin is a global or a | |
395 filetype one. The scripts in $VIMRUNTIME/macros are global ones, the filetype | |
396 plugins are in $VIMRUNTIME/ftplugin. | |
397 | |
398 | |
399 USING A FILETYPE PLUGIN *ftplugin-name* | |
400 | |
401 You can add a filetype plugin by dropping it in the right directory. The | |
402 name of this directory is in the same directory mentioned above for global | |
403 plugins, but the last part is "ftplugin". Suppose you have found a plugin for | |
404 the "stuff" filetype, and you are on Unix. Then you can move this file to the | |
405 ftplugin directory: > | |
406 | |
407 mv thefile ~/.vim/ftplugin/stuff.vim | |
408 | |
409 If that file already exists you already have a plugin for "stuff". You might | |
410 want to check if the existing plugin doesn't conflict with the one you are | |
411 adding. If it's OK, you can give the new one another name: > | |
412 | |
413 mv thefile ~/.vim/ftplugin/stuff_too.vim | |
414 | |
415 The underscore is used to separate the name of the filetype from the rest, | |
10 | 416 which can be anything. If you use "otherstuff.vim" it wouldn't work, it would |
417 be loaded for the "otherstuff" filetype. | |
7 | 418 |
419 On MS-DOS you cannot use long filenames. You would run into trouble if you | |
420 add a second plugin and the filetype has more than six characters. You can | |
421 use an extra directory to get around this: > | |
422 | |
423 mkdir $VIM/vimfiles/ftplugin/fortran | |
424 copy thefile $VIM/vimfiles/ftplugin/fortran/too.vim | |
425 | |
426 The generic names for the filetype plugins are: > | |
427 | |
428 ftplugin/<filetype>.vim | |
429 ftplugin/<filetype>_<name>.vim | |
430 ftplugin/<filetype>/<name>.vim | |
431 | |
432 Here "<name>" can be any name that you prefer. | |
433 Examples for the "stuff" filetype on Unix: > | |
434 | |
435 ~/.vim/ftplugin/stuff.vim | |
436 ~/.vim/ftplugin/stuff_def.vim | |
437 ~/.vim/ftplugin/stuff/header.vim | |
438 | |
439 The <filetype> part is the name of the filetype the plugin is to be used for. | |
440 Only files of this filetype will use the settings from the plugin. The <name> | |
441 part of the plugin file doesn't matter, you can use it to have several plugins | |
442 for the same filetype. Note that it must end in ".vim". | |
443 | |
444 | |
445 Further reading: | |
446 |filetype-plugins| Documentation for the filetype plugins and information | |
447 about how to avoid that mappings cause problems. | |
448 |load-plugins| When the global plugins are loaded during startup. | |
449 |ftplugin-overrule| Overruling the settings from a global plugin. | |
450 |write-plugin| How to write a plugin script. | |
451 |plugin-details| For more information about using plugins or when your | |
452 plugin doesn't work. | |
453 |new-filetype| How to detect a new file type. | |
454 | |
455 ============================================================================== | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
456 *05.6* Adding a help file *add-local-help* |
7 | 457 |
458 If you are lucky, the plugin you installed also comes with a help file. We | |
459 will explain how to install the help file, so that you can easily find help | |
460 for your new plugin. | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
461 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
|
462 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
|
463 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
|
464 the "mkdir" commands if you already have the directory.) > |
7 | 465 |
466 :!mkdir ~/.vim | |
467 :!mkdir ~/.vim/plugin | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
468 :!cp /tmp/doit.vim ~/.vim/plugin |
7 | 469 |
22 | 470 The "cp" command is for Unix, on MS-DOS you can use "copy". |
471 | |
7 | 472 Now create a "doc" directory in one of the directories in 'runtimepath'. > |
473 | |
474 :!mkdir ~/.vim/doc | |
475 | |
476 Copy the help file to the "doc" directory. > | |
477 | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
478 :!cp /tmp/doit.txt ~/.vim/doc |
7 | 479 |
480 Now comes the trick, which allows you to jump to the subjects in the new help | |
481 file: Generate the local tags file with the |:helptags| command. > | |
482 | |
483 :helptags ~/.vim/doc | |
484 | |
485 Now you can use the > | |
486 | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
487 :help doit |
7 | 488 |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
489 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
|
490 an entry for the local help file when you do: > |
7 | 491 |
492 :help local-additions | |
493 | |
494 The title lines from the local help files are automagically added to this | |
495 section. There you can see which local help files have been added and jump to | |
496 them through the tag. | |
497 | |
498 For writing a local help file, see |write-local-help|. | |
499 | |
500 ============================================================================== | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
501 *05.7* The option window |
7 | 502 |
503 If you are looking for an option that does what you want, you can search in | |
504 the help files here: |options|. Another way is by using this command: > | |
505 | |
506 :options | |
507 | |
508 This opens a new window, with a list of options with a one-line explanation. | |
509 The options are grouped by subject. Move the cursor to a subject and press | |
510 <Enter> to jump there. Press <Enter> again to jump back. Or use CTRL-O. | |
511 | |
512 You can change the value of an option. For example, move to the "displaying | |
513 text" subject. Then move the cursor down to this line: | |
514 | |
515 set wrap nowrap ~ | |
516 | |
517 When you hit <Enter>, the line will change to: | |
518 | |
519 set nowrap wrap ~ | |
520 | |
521 The option has now been switched off. | |
522 | |
523 Just above this line is a short description of the 'wrap' option. Move the | |
524 cursor one line up to place it in this line. Now hit <Enter> and you jump to | |
525 the full help on the 'wrap' option. | |
526 | |
527 For options that take a number or string argument you can edit the value. | |
528 Then press <Enter> to apply the new value. For example, move the cursor a few | |
529 lines up to this line: | |
530 | |
531 set so=0 ~ | |
532 | |
533 Position the cursor on the zero with "$". Change it into a five with "r5". | |
534 Then press <Enter> to apply the new value. When you now move the cursor | |
535 around you will notice that the text starts scrolling before you reach the | |
536 border. This is what the 'scrolloff' option does, it specifies an offset | |
537 from the window border where scrolling starts. | |
538 | |
539 ============================================================================== | |
8720
9380c37723f8
commit https://github.com/vim/vim/commit/aedfcbe1e6c7df6edcd6756d7601bfdec7dd2087
Christian Brabandt <cb@256bit.org>
parents:
5294
diff
changeset
|
540 *05.8* Often used options |
7 | 541 |
542 There are an awful lot of options. Most of them you will hardly ever use. | |
543 Some of the more useful ones will be mentioned here. Don't forget you can | |
544 find more help on these options with the ":help" command, with single quotes | |
545 before and after the option name. For example: > | |
546 | |
547 :help 'wrap' | |
548 | |
549 In case you have messed up an option value, you can set it back to the | |
10 | 550 default by putting an ampersand (&) after the option name. Example: > |
7 | 551 |
552 :set iskeyword& | |
553 | |
554 | |
555 NOT WRAPPING LINES | |
556 | |
557 Vim normally wraps long lines, so that you can see all of the text. Sometimes | |
558 it's better to let the text continue right of the window. Then you need to | |
10 | 559 scroll the text left-right to see all of a long line. Switch wrapping off |
560 with this command: > | |
7 | 561 |
562 :set nowrap | |
563 | |
564 Vim will automatically scroll the text when you move to text that is not | |
565 displayed. To see a context of ten characters, do this: > | |
566 | |
567 :set sidescroll=10 | |
568 | |
569 This doesn't change the text in the file, only the way it is displayed. | |
570 | |
571 | |
572 WRAPPING MOVEMENT COMMANDS | |
573 | |
574 Most commands for moving around will stop moving at the start and end of a | |
575 line. You can change that with the 'whichwrap' option. This sets it to the | |
576 default value: > | |
577 | |
578 :set whichwrap=b,s | |
579 | |
580 This allows the <BS> key, when used in the first position of a line, to move | |
581 the cursor to the end of the previous line. And the <Space> key moves from | |
582 the end of a line to the start of the next one. | |
583 | |
584 To allow the cursor keys <Left> and <Right> to also wrap, use this command: > | |
585 | |
586 :set whichwrap=b,s,<,> | |
587 | |
588 This is still only for Normal mode. To let <Left> and <Right> do this in | |
589 Insert mode as well: > | |
590 | |
591 :set whichwrap=b,s,<,>,[,] | |
592 | |
593 There are a few other flags that can be added, see 'whichwrap'. | |
594 | |
595 | |
596 VIEWING TABS | |
597 | |
598 When there are tabs in a file, you cannot see where they are. To make them | |
599 visible: > | |
600 | |
601 :set list | |
602 | |
1278 | 603 Now every tab is displayed as ^I. And a $ is displayed at the end of each |
7 | 604 line, so that you can spot trailing spaces that would otherwise go unnoticed. |
605 A disadvantage is that this looks ugly when there are many Tabs in a file. | |
606 If you have a color terminal, or are using the GUI, Vim can show the spaces | |
607 and tabs as highlighted characters. Use the 'listchars' option: > | |
608 | |
609 :set listchars=tab:>-,trail:- | |
610 | |
611 Now every tab will be displayed as ">---" (with more or less "-") and trailing | |
612 white space as "-". Looks a lot better, doesn't it? | |
613 | |
614 | |
615 KEYWORDS | |
616 | |
617 The 'iskeyword' option specifies which characters can appear in a word: > | |
618 | |
619 :set iskeyword | |
620 < iskeyword=@,48-57,_,192-255 ~ | |
621 | |
622 The "@" stands for all alphabetic letters. "48-57" stands for ASCII | |
623 characters 48 to 57, which are the numbers 0 to 9. "192-255" are the | |
624 printable latin characters. | |
625 Sometimes you will want to include a dash in keywords, so that commands | |
626 like "w" consider "upper-case" to be one word. You can do it like this: > | |
627 | |
628 :set iskeyword+=- | |
629 :set iskeyword | |
630 < iskeyword=@,48-57,_,192-255,- ~ | |
631 | |
632 If you look at the new value, you will see that Vim has added a comma for you. | |
633 To remove a character use "-=". For example, to remove the underscore: > | |
634 | |
635 :set iskeyword-=_ | |
636 :set iskeyword | |
637 < iskeyword=@,48-57,192-255,- ~ | |
638 | |
639 This time a comma is automatically deleted. | |
640 | |
641 | |
642 ROOM FOR MESSAGES | |
643 | |
644 When Vim starts there is one line at the bottom that is used for messages. | |
645 When a message is long, it is either truncated, thus you can only see part of | |
646 it, or the text scrolls and you have to press <Enter> to continue. | |
647 You can set the 'cmdheight' option to the number of lines used for | |
648 messages. Example: > | |
649 | |
650 :set cmdheight=3 | |
651 | |
652 This does mean there is less room to edit text, thus it's a compromise. | |
653 | |
654 ============================================================================== | |
655 | |
656 Next chapter: |usr_06.txt| Using syntax highlighting | |
657 | |
658 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: |