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