usr_05.txt 26 KB

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