codekingpro/portable-devtools
114k
1*usr_05.txt* For Vim version 9.2. Last change: 2026 Feb 142 3 4 VIM USER MANUAL by Bram Moolenaar5 6 7 Set your settings8 9 10Vim can be tuned to work like you want it to. This chapter shows you how to11make Vim start with options set to different values. Add plugins to extend12Vim's capabilities. Or define your own macros.13 14|05.1| The vimrc file15|05.2| The example vimrc file explained16|05.3| The defaults.vim file explained17|05.4| Simple mappings18|05.5| Adding a package19|05.6| Adding a plugin20|05.7| Adding a help file21|05.8| The option window22|05.9| Often used options23 24 Next chapter: |usr_06.txt| Using syntax highlighting25 Previous chapter: |usr_04.txt| Making small changes26Table of contents: |usr_toc.txt|27 28==============================================================================29*05.1* The vimrc file *vimrc-intro*30 31You probably got tired of typing commands that you use very often. To start32Vim with all your favorite option settings and mappings, you write them in33what is called the vimrc file. Vim executes the commands in this file when it34starts up.35 36If you already have a vimrc file (e.g., when your sysadmin has one setup for37you), you can edit it this way: >38 39 :edit $MYVIMRC40 41If you don't have a vimrc file yet, see |vimrc| to find out where you can42create a vimrc file. Also, the ":version" command mentions the name of the43"user vimrc file" Vim looks for.44 45For Unix and Macintosh this file is always used and is recommended:46 47 ~/.vimrc ~48 49For MS-Windows you can use one of these:50 51 $HOME/_vimrc ~52 $VIM/_vimrc ~53 54If you are creating the vimrc file for the first time, it is recommended to55put this line at the top: >56 57 source $VIMRUNTIME/defaults.vim58 59This initializes Vim for new users (as opposed to traditional Vi users). See60|defaults.vim| for the details.61 62The vimrc file can contain all the commands that you type after a colon. The63simplest ones are for setting options. For example, if you want Vim to always64start with the 'incsearch' option on, add this line your vimrc file: >65 66 set incsearch67 68For this new line to take effect you need to exit Vim and start it again.69Later you will learn how to do this without exiting Vim.70 71This chapter only explains the most basic items. For more information on how72to write a Vim script file: |usr_41.txt|.73 74==============================================================================75*05.2* The example vimrc file explained *vimrc_example.vim*76 77In the first chapter was explained how the example vimrc (included in the78Vim distribution) file can be used to make Vim startup in not-compatible mode79(see |not-compatible|). The file can be found here:80 81 $VIMRUNTIME/vimrc_example.vim ~82 83In this section we will explain the various commands used in this file. This84will give you hints about how to set up your own preferences. Not everything85will be explained though. Use the ":help" command to find out more.86 87>88 " Get the defaults that most users want.89 source $VIMRUNTIME/defaults.vim90 91This loads the "defaults.vim" file in the $VIMRUNTIME directory. This sets up92Vim for how most users like it. If you are one of the few that don't, then93comment out this line. The commands are explained below:94|defaults.vim-explained|95 96>97 if has("vms")98 set nobackup99 else100 set backup101 if has('persistent_undo')102 set undofile103 endif104 endif105 106This tells Vim to keep a backup copy of a file when overwriting it. But not107on the VMS system, since it keeps old versions of files already. The backup108file will have the same name as the original file with "~" added. See |07.4|109 110This also sets the 'undofile' option, if available. This will store the111multi-level undo information in a file. The result is that when you change a112file, exit Vim, and then edit the file again, you can undo the changes made113previously. It's a very powerful and useful feature, at the cost of storing a114file. For more information see |undo-persistence|.115 116The "if" command is very useful to set options117only when some condition is met. More about that in |usr_41.txt|.118 119>120 if &t_Co > 2 || has("gui_running")121 set hlsearch122 endif123 124This switches on the 'hlsearch' option, telling Vim to highlight matches with125the last used search pattern.126 127>128 augroup vimrcEx129 au!130 autocmd FileType text setlocal textwidth=78131 augroup END132 133This makes Vim break text to avoid lines getting longer than 78 characters.134But only for files that have been detected to be plain text. There are135actually two parts here. "autocmd FileType text" is an autocommand. This136defines that when the file type is set to "text" the following command is137automatically executed. "setlocal textwidth=78" sets the 'textwidth' option138to 78, but only locally in one file.139 140The wrapper with "augroup vimrcEx" and "augroup END" makes it possible to141delete the autocommand with the "au!" command. See |:augroup|.142 143>144 if has('syntax') && has('eval')145 packadd! matchit146 endif147 148This loads the "matchit" plugin if the required features are available.149It makes the |%| command more powerful. This is explained at150|matchit-install|.151 152 153==============================================================================154*05.3* The defaults.vim file explained *defaults.vim-explained*155 156The |defaults.vim| file is loaded when the user has no vimrc file. When you157create a new vimrc file, add this line near the top to keep using it: >158 159 source $VIMRUNTIME/defaults.vim160 161Or use the vimrc_example.vim file, as explained above.162 163The following explains what defaults.vim is doing.164 165>166 if exists('skip_defaults_vim')167 finish168 endif169 170Loading defaults.vim can be disabled with this command: >171 let skip_defaults_vim = 1172This has to be done in the system vimrc file. See |system-vimrc|. If you173have a user vimrc this is not needed, since defaults.vim will not be loaded174automatically.175 176>177 set nocompatible178 179As mentioned in the first chapter, these manuals explain Vim working in an180improved way, thus not completely Vi compatible. Setting the 'compatible'181option off, thus 'nocompatible' takes care of this.182 183>184 set backspace=indent,eol,start185 186This specifies where in Insert mode the <BS> is allowed to delete the187character in front of the cursor. The three items, separated by commas, tell188Vim to delete the white space at the start of the line, a line break and the189character before where Insert mode started. See 'backspace'.190 191>192 set history=200193 194Keep 200 commands and 200 search patterns in the history. Use another number195if you want to remember fewer or more lines. See 'history'.196 197>198 set ruler199 200Always display the current cursor position in the lower right corner of the201Vim window. See 'ruler'.202 203>204 set showcmd205 206Display an incomplete command in the lower right corner of the Vim window,207left of the ruler. For example, when you type "2f", Vim is waiting for you to208type the character to find and "2f" is displayed. When you press "w" next,209the "2fw" command is executed and the displayed "2f" is removed.210 211 +-------------------------------------------------+212 |text in the Vim window |213 |~ |214 |~ |215 |-- VISUAL -- 2f 43,8 17% |216 +-------------------------------------------------+217 ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^218 'showmode' 'showcmd' 'ruler'219 220 221>222 set wildmenu223 224Display completion matches in a status line. That is when you type <Tab> and225there is more than one match. See 'wildmenu'.226 227>228 set ttimeout229 set ttimeoutlen=100230 231This makes typing Esc take effect more quickly. Normally Vim waits a second232to see if the Esc is the start of an escape sequence. If you have a very slow233remote connection, increase the number. See 'ttimeout'.234 235>236 set display=truncate237 238Show @@@ in the last line if it is truncated, instead of hiding the whole239line. See 'display'.240 241>242 set incsearch243 244Display the match for a search pattern when halfway typing it. See245'incsearch'.246 247>248 set nrformats-=octal249 250Do not recognize numbers starting with a zero as octal. See 'nrformats'.251 252>253 map Q gq254 255This defines a key mapping. More about that in the next section. This256defines the "Q" command to do formatting with the "gq" operator. This is how257it worked before Vim 5.0. Otherwise the "Q" command starts Ex mode, but you258will not need it.259 260>261 inoremap <C-U> <C-G>u<C-U>262 263CTRL-U in insert mode deletes all entered text in the current line. Use264CTRL-G u to first break undo, so that you can undo CTRL-U after inserting a265line break. Revert with ":iunmap <C-U>".266 267>268 if has('mouse')269 set mouse=a270 endif271 272Enable using the mouse if available. See 'mouse'.273 274>275 vnoremap _g y:exe "grep /" .. escape(@", '\\/') .. "/ *.c *.h"<CR>276 277This mapping yanks the visually selected text and searches for it in C files.278You can see that a mapping can be used to do quite complicated things. Still,279it is just a sequence of commands that are executed like you typed them.280 281>282 syntax on283 284Enable highlighting files in color. See |syntax|.285 286 *vimrc-filetype* >287 filetype plugin indent on288 289This switches on three very clever mechanisms:2901. Filetype detection.291 Whenever you start editing a file, Vim will try to figure out what kind of292 file this is. When you edit "main.c", Vim will see the ".c" extension and293 recognize this as a "c" filetype. When you edit a file that starts with294 "#!/bin/sh", Vim will recognize it as a "sh" filetype.295 The filetype detection is used for syntax highlighting and the other two296 items below.297 See |filetypes|.298 2992. Using filetype plugin files300 Many different filetypes are edited with different options. For example,301 when you edit a "c" file, it's very useful to set the 'cindent' option to302 automatically indent the lines. These commonly useful option settings are303 included with Vim in filetype plugins. You can also add your own, see304 |write-filetype-plugin|.305 3063. Using indent files307 When editing programs, the indent of a line can often be computed308 automatically. Vim comes with these indent rules for a number of309 filetypes. See |:filetype-indent-on| and 'indentexpr'.310 311 312 *restore-cursor* *last-position-jump* >vim313 314 augroup RestoreCursor315 autocmd!316 autocmd BufReadPost *317 \ let line = line("'\"")318 \ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'319 \ && index(['xxd', 'gitrebase'], &filetype) == -1320 \ && !&diff321 \ | execute "normal! g`\""322 \ | endif323 augroup END324 325Another autocommand. This time it is used after reading any file. The326complicated stuff after it checks if the '" mark is defined, and jumps to it327if so. It doesn't do that when:328 - editing a commit or rebase message, which are likely a different one than329 last time,330 - using xxd(1) to filter and edit binary files, which transforms input files331 back and forth, causing them to have dual nature, so to speak (see also332 |using-xxd|) and333 - Vim is in diff mode334 335The backslash at the start of a line is used to continue the command from the336previous line. That avoids a line getting very long. See |line-continuation|.337This only works in a Vim script file, not when typing commands at the338command line.339 340>341 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_342 \ | diffthis | wincmd p | diffthis343 344This adds the ":DiffOrig" command. Use this in a modified buffer to see the345differences with the file it was loaded from. See |diff| and |:DiffOrig|.346 347>348 set nolangremap349 350Prevent that the langmap option applies to characters that result from a351mapping. If set (default), this may break plugins (but it's backward352compatible). See 'langremap'.353 354==============================================================================355*05.4* Simple mappings356 357A mapping enables you to bind a set of Vim commands to a single key. Suppose,358for example, that you need to surround certain words with curly braces. In359other words, you need to change a word such as "amount" into "{amount}". With360the :map command, you can tell Vim that the F5 key does this job. The command361is as follows: >362 363 :map <F5> i{<Esc>ea}<Esc>364<365 Note:366 When entering this command, you must enter <F5> by typing four367 characters. Similarly, <Esc> is not entered by pressing the <Esc>368 key, but by typing five characters. Watch out for this difference369 when reading the manual!370 371Let's break this down:372 <F5> The F5 function key. This is the trigger key that causes the373 command to be executed as the key is pressed.374 375 i{<Esc> Insert the { character. The <Esc> key ends Insert mode.376 377 e Move to the end of the word.378 379 a}<Esc> Append the } to the word.380 381After you execute the ":map" command, all you have to do to put {} around a382word is to put the cursor on the first character and press F5.383 384In this example, the trigger is a single key; it can be any string. But when385you use an existing Vim command, that command will no longer be available.386You better avoid that.387 One key that can be used with mappings is the backslash. Since you388probably want to define more than one mapping, add another character. You389could map "\p" to add parentheses around a word, and "\c" to add curly braces,390for example: >391 392 :map \p i(<Esc>ea)<Esc>393 :map \c i{<Esc>ea}<Esc>394 395You need to type the \ and the p quickly after another, so that Vim knows they396belong together.397 398The ":map" command (with no arguments) lists your current mappings. At399least the ones for Normal mode. More about mappings in section |40.1|.400 401==============================================================================402*05.5* Adding a package *add-package*403 404A package is a set of files that you can add to Vim. There are two kinds of405packages: optional and automatically loaded on startup.406 407The Vim distribution comes with a few packages that you can optionally use.408 409------------------------------------------------------------------------------410Adding the matchit package *matchit-install* *package-matchit*411------------------------------------------------------------------------------412For example, the matchit package This plugin makes the "%" command jump to413matching HTML tags, if/else/endif in Vim scripts, etc. Very useful, although414it's not backwards compatible (that's why it is not enabled by default).415 416To start using the matchit plugin, add one line to your vimrc file: >417 packadd! matchit418 419That's all! After restarting Vim you can find help about this plugin: >420 :help matchit421 422This works, because when `:packadd` loaded the plugin it also added the423package directory in 'runtimepath', so that the help file can be found.424 425You can find packages on the Internet in various places. It usually comes as426an archive or as a repository. For an archive you can follow these steps:427 1. create the package directory: >428 mkdir -p ~/.vim/pack/fancy429< "fancy" can be any name of your liking. Use one that describes the430 package.431 2. unpack the archive in that directory. This assumes the top432 directory in the archive is "start": >433 cd ~/.vim/pack/fancy434 unzip /tmp/fancy.zip435< If the archive layout is different make sure that you end up with a436 path like this:437 ~/.vim/pack/fancy/start/fancytext/plugin/fancy.vim ~438 Here "fancytext" is the name of the package, it can be anything439 else.440 441------------------------------------------------------------------------------442Adding the editorconfig package *editorconfig-install* *package-editorconfig*443------------------------------------------------------------------------------444 445Similar to the matchit package, to load the distributed editorconfig plugin446when Vim starts, add the following line to your vimrc file: >447 packadd! editorconfig448 449After restarting your Vim, the plugin is active and you can read about it at: >450 :h editorconfig.txt451 452 453------------------------------------------------------------------------------454Adding the comment package *comment-install* *package-comment*455------------------------------------------------------------------------------456 457Load the plugin with this command: >458 packadd comment459<460This way you can use the plugin with the default key bindings `gc` and similar461for commenting (which is a well-established mapping in the Vim community).462 463If you add this line to your vimrc file, then you need to restart Vim to have464the package loaded. Once the package is loaded, read about it at: >465 :h comment.txt466 467 468------------------------------------------------------------------------------469Adding the nohlsearch package *nohlsearch-install* *package-nohlsearch*470------------------------------------------------------------------------------471 472Load the plugin with this command: >473 packadd nohlsearch474<475Automatically execute |:nohlsearch| after 'updatetime' or getting into476|Insert| mode.477Thus assuming default updatetime, hlsearch would be suspended/turned off after4784 seconds of idle time.479 480To disable the effect of the plugin after it has been loaded: >481 au! nohlsearch482<483 484------------------------------------------------------------------------------485Adding the highlight-yank package *hlyank-install* *package-hlyank*486------------------------------------------------------------------------------487 488Load the plugin with this command: >489 packadd hlyank490<491This package briefly highlights the affected region of the last |yank|492command. See |52.6| for a simplified implementation using the493|getregionpos()| function.494 495The plugin understands the following configuration variables (the settings496show the default values).497 498To specify a different highlighting group, use: >499 :let g:hlyank_hlgroup = 'IncSearch'500<501To use a different highlighting duration, use: >502 :let g:hlyank_duration = 300503The unit is milliseconds, and the upper limit is 3000 ms. If you set a value504higher than this, the highlighting duration will be 3000 ms.505 506To highlight in visual mode, use: >507 :let g:hlyank_invisual = v:true508 509To disable the effect of the plugin after it has been loaded: >510 au! hlyank511 512------------------------------------------------------------------------------513Adding the osc52 package *osc52-install* *package-osc52*514------------------------------------------------------------------------------515 516Load the plugin with this command: >517 packadd osc52518<519The osc52.vim package provides support for the OSC 52 terminal command, which520allows an application to access the clipboard by communicating directly with521your terminal.522 523Once the package is loaded, read about it at: >524 :h osc52.txt525 526More information about packages can be found here: |packages|.527 528==============================================================================529*05.6* Adding a plugin *add-plugin* *plugin*530 531Vim's functionality can be extended by adding plugins. A plugin is nothing532more than a Vim script file that is loaded automatically when Vim starts. You533can add a plugin very easily by dropping it in your plugin directory.534{not available when Vim was compiled without the |+eval| feature}535 536There are two types of plugins:537 538 global plugin: Used for all kinds of files539 filetype plugin: Only used for a specific type of file540 541The global plugins will be discussed first, then the filetype ones542|add-filetype-plugin|.543 544 545GLOBAL PLUGINS *standard-plugin* *distributed-plugins*546 547When you start Vim, it will automatically load a number of global plugins.548You don't have to do anything for this. They add functionality that most549people will want to use, but which was implemented as a Vim script instead of550being compiled into Vim. You can find them listed in the help index551|standard-plugin-list|.552 553For locally installed plugins and packages (which come with a separated help554file) a similar list can be found in the help section |local-additions|.555 556Also see |load-plugins|.557 558 *add-global-plugin*559You can add a global plugin to add functionality that will always be present560when you use Vim. There are only two steps for adding a global plugin:5611. Get a copy of the plugin.5622. Drop it in the right directory.563 564 565GETTING A GLOBAL PLUGIN566 567Where can you find plugins?568- Some are always loaded, you can see them in the directory569 $VIMRUNTIME/plugin.570- Some come with Vim. You can find them in the directory $VIMRUNTIME/macros571 and its sub-directories and under $VIM/vimfiles/pack/dist/opt/.572- Download from the net. There is a large collection on http://www.vim.org.573- They are sometimes posted in a Vim |maillist|.574- You could write one yourself, see |write-plugin|.575 576Some plugins come as a vimball archive, see |vimball|.577Some plugins can be updated automatically, see |getscript|.578 579 580USING A GLOBAL PLUGIN581 582First read the text in the plugin itself to check for any special conditions.583Then copy the file to your plugin directory:584 585 system plugin directory ~586 Unix ~/.vim/plugin/587 PC $HOME/vimfiles/plugin or $VIM/vimfiles/plugin588 Amiga s:vimfiles/plugin589 Macintosh $VIM:vimfiles:plugin590 Mac OS X ~/.vim/plugin/591 592Example for Unix (assuming you didn't have a plugin directory yet): >593 594 mkdir ~/.vim595 mkdir ~/.vim/plugin596 cp /tmp/yourplugin.vim ~/.vim/plugin597 598That's all! Now you can use the commands defined in this plugin.599 600Instead of putting plugins directly into the plugin/ directory, you may601better organize them by putting them into subdirectories under plugin/.602As an example, consider using "~/.vim/plugin/perl/*.vim" for all your Perl603plugins.604 605 606FILETYPE PLUGINS *add-filetype-plugin* *ftplugins*607 608The Vim distribution comes with a set of plugins for different filetypes that609you can start using with this command: >610 611 :filetype plugin on612 613That's all! See |vimrc-filetype|.614 615If you are missing a plugin for a filetype you are using, or you found a616better one, you can add it. There are two steps for adding a filetype plugin:6171. Get a copy of the plugin.6182. Drop it in the right directory.619 620 621GETTING A FILETYPE PLUGIN622 623You can find them in the same places as the global plugins. Watch out if the624type of file is mentioned, then you know if the plugin is a global or a625filetype one. The scripts in $VIMRUNTIME/macros are global ones, the filetype626plugins are in $VIMRUNTIME/ftplugin.627 628 629USING A FILETYPE PLUGIN *ftplugin-name*630 631You can add a filetype plugin by dropping it in the right directory. The632name of this directory is in the same directory mentioned above for global633plugins, but the last part is "ftplugin". Suppose you have found a plugin for634the "stuff" filetype, and you are on Unix. Then you can move this file to the635ftplugin directory: >636 637 mv thefile ~/.vim/ftplugin/stuff.vim638 639If that file already exists you already have a plugin for "stuff". You might640want to check if the existing plugin doesn't conflict with the one you are641adding. If it's OK, you can give the new one another name: >642 643 mv thefile ~/.vim/ftplugin/stuff_too.vim644 645The underscore is used to separate the name of the filetype from the rest,646which can be anything. If you use "otherstuff.vim" it wouldn't work, it would647be loaded for the "otherstuff" filetype.648 649On MS-DOS like filesystems you cannot use long filenames. You would run into650trouble if you add a second plugin and the filetype has more than six651characters. You can use an extra directory to get around this: >652 653 mkdir $VIM/vimfiles/ftplugin/fortran654 copy thefile $VIM/vimfiles/ftplugin/fortran/too.vim655 656The generic names for the filetype plugins are: >657 658 ftplugin/<filetype>.vim659 ftplugin/<filetype>_<name>.vim660 ftplugin/<filetype>/<name>.vim661 662Here "<name>" can be any name that you prefer.663Examples for the "stuff" filetype on Unix: >664 665 ~/.vim/ftplugin/stuff.vim666 ~/.vim/ftplugin/stuff_def.vim667 ~/.vim/ftplugin/stuff/header.vim668 669The <filetype> part is the name of the filetype the plugin is to be used for.670Only files of this filetype will use the settings from the plugin. The <name>671part of the plugin file doesn't matter, you can use it to have several plugins672for the same filetype. Note that it must end in ".vim".673 674 675Further reading:676|filetype-plugins| Documentation for the filetype plugins and information677 about how to avoid that mappings cause problems.678|load-plugins| When the global plugins are loaded during startup.679|ftplugin-overrule| Overruling the settings from a global plugin.680|write-plugin| How to write a plugin script.681|plugin-details| For more information about using plugins or when your682 plugin doesn't work.683|new-filetype| How to detect a new file type.684 685==============================================================================686*05.7* Adding a help file *add-local-help*687 688If you are lucky, the plugin you installed also comes with a help file. We689will explain how to install the help file, so that you can easily find help690for your new plugin.691 Let us use the "doit.vim" plugin as an example. This plugin comes with692documentation: "doit.txt". Let's first copy the plugin to the right693directory. This time we will do it from inside Vim. (You may skip some of694the "mkdir" commands if you already have the directory.) >695 696 :!mkdir ~/.vim697 :!mkdir ~/.vim/plugin698 :!cp /tmp/doit.vim ~/.vim/plugin699 700The "cp" command is for Unix, on MS-Windows you can use "copy".701 702Now create a "doc" directory in one of the directories in 'runtimepath'. >703 704 :!mkdir ~/.vim/doc705 706Copy the help file to the "doc" directory. >707 708 :!cp /tmp/doit.txt ~/.vim/doc709 710Now comes the trick, which allows you to jump to the subjects in the new help711file: Generate the local tags file with the |:helptags| command. >712 713 :helptags ~/.vim/doc714 715Now you can use the >716 717 :help doit718 719command to find help for "doit" in the help file you just added. You can see720an entry for the local help file when you do: >721 722 :help local-additions723 724The title lines from the local help files are automagically added to this725section. There you can see which local help files have been added and jump to726them through the tag.727 728For writing a local help file, see |write-local-help|.729 730==============================================================================731*05.8* The option window732 733If you are looking for an option that does what you want, you can search in734the help files here: |options|. Another way is by using this command: >735 736 :options737 738This opens a new window, with a list of options with a one-line explanation.739The options are grouped by subject. Move the cursor to a subject and press740<Enter> to jump there. Press <Enter> again to jump back. Or use CTRL-O.741 742You can change the value of an option. For example, move to the "displaying743text" subject. Then move the cursor down to this line:744 745 set wrap nowrap ~746 747When you hit <Enter>, the line will change to:748 749 set nowrap wrap ~750 751The option has now been switched off.752 753Just above this line is a short description of the 'wrap' option. Move the754cursor one line up to place it in this line. Now hit <Enter> and you jump to755the full help on the 'wrap' option.756 757For options that take a number or string argument you can edit the value.758Then press <Enter> to apply the new value. For example, move the cursor a few759lines up to this line:760 761 set so=0 ~762 763Position the cursor on the zero with "$". Change it into a five with "r5".764Then press <Enter> to apply the new value. When you now move the cursor765around you will notice that the text starts scrolling before you reach the766border. This is what the 'scrolloff' option does, it specifies an offset767from the window border where scrolling starts.768 769==============================================================================770*05.9* Often used options771 772There are an awful lot of options. Most of them you will hardly ever use.773Some of the more useful ones will be mentioned here. Don't forget you can774find more help on these options with the ":help" command, with single quotes775before and after the option name. For example: >776 777 :help 'wrap'778 779In case you have messed up an option value, you can set it back to the780default by putting an ampersand (&) after the option name. Example: >781 782 :set iskeyword&783 784 785NOT WRAPPING LINES786 787Vim normally wraps long lines, so that you can see all of the text. Sometimes788it's better to let the text continue right of the window. Then you need to789scroll the text left-right to see all of a long line. Switch wrapping off790with this command: >791 792 :set nowrap793 794Vim will automatically scroll the text when you move to text that is not795displayed. To see a context of ten characters, do this: >796 797 :set sidescroll=10798 799This doesn't change the text in the file, only the way it is displayed.800 801 802WRAPPING MOVEMENT COMMANDS803 804Most commands for moving around will stop moving at the start and end of a805line. You can change that with the 'whichwrap' option. This sets it to the806default value: >807 808 :set whichwrap=b,s809 810This allows the <BS> key, when used in the first position of a line, to move811the cursor to the end of the previous line. And the <Space> key moves from812the end of a line to the start of the next one.813 814To allow the cursor keys <Left> and <Right> to also wrap, use this command: >815 816 :set whichwrap=b,s,<,>817 818This is still only for Normal mode. To let <Left> and <Right> do this in819Insert mode as well: >820 821 :set whichwrap=b,s,<,>,[,]822 823There are a few other flags that can be added, see 'whichwrap'.824 825 826VIEWING TABS827 828When there are tabs in a file, you cannot see where they are. To make them829visible: >830 831 :set list832 833Now every tab is displayed as ^I. And a $ is displayed at the end of each834line, so that you can spot trailing spaces that would otherwise go unnoticed.835 A disadvantage is that this looks ugly when there are many Tabs in a file.836If you have a color terminal, or are using the GUI, Vim can show the spaces837and tabs as highlighted characters. Use the 'listchars' option: >838 839 :set listchars=tab:>-,trail:-840 841Now every tab will be displayed as ">---" (with more or less "-") and trailing842white space as "-". Looks a lot better, doesn't it?843 844 845KEYWORDS846 847The 'iskeyword' option specifies which characters can appear in a word: >848 849 :set iskeyword850< iskeyword=@,48-57,_,192-255 ~851 852The "@" stands for all alphabetic letters. "48-57" stands for ASCII853characters 48 to 57, which are the numbers 0 to 9. "192-255" are the854printable latin characters.855 Sometimes you will want to include a dash in keywords, so that commands856like "w" consider "upper-case" to be one word. You can do it like this: >857 858 :set iskeyword+=-859 :set iskeyword860< iskeyword=@,48-57,_,192-255,- ~861 862If you look at the new value, you will see that Vim has added a comma for you.863 To remove a character use "-=". For example, to remove the underscore: >864 865 :set iskeyword-=_866 :set iskeyword867< iskeyword=@,48-57,192-255,- ~868 869This time a comma is automatically deleted.870 871 872ROOM FOR MESSAGES873 874When Vim starts there is one line at the bottom that is used for messages.875When a message is long, it is either truncated, thus you can only see part of876it, or the text scrolls and you have to press <Enter> to continue.877 You can set the 'cmdheight' option to the number of lines used for878messages. Example: >879 880 :set cmdheight=3881 882This does mean there is less room to edit text, thus it's a compromise.883 884==============================================================================885 886Next chapter: |usr_06.txt| Using syntax highlighting887 888Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl:889 