usr_06.txt (6880B)
1 *usr_06.txt* Nvim 2 3 4 VIM USER MANUAL by Bram Moolenaar 5 6 7 Using syntax highlighting 8 9 10 Black and white text is boring. With colors your file comes to life. This 11 not only looks nice, it also speeds up your work. Change the colors used for 12 the different sorts of text. Print your text, with the colors you see on the 13 screen. 14 15 |06.1| Switching it on 16 |06.2| No or wrong colors? 17 |06.3| Different colors 18 |06.4| With colors or without colors 19 |06.5| Further reading 20 21 Next chapter: |usr_07.txt| Editing more than one file 22 Previous chapter: |usr_05.txt| Set your settings 23 Table of contents: |usr_toc.txt| 24 25 ============================================================================== 26 *06.1* Switching it on 27 28 Syntax highlighting is enabled by default. Nvim will automagically detect the 29 type of file and load the right syntax highlighting. 30 31 ============================================================================== 32 *06.2* No or wrong colors? 33 34 There can be a number of reasons why you don't see colors: 35 36 - Your terminal does not support colors. 37 Vim will use bold, italic and underlined text, but this doesn't look 38 very nice. You probably will want to try to get a terminal with 39 colors. 40 41 - Your terminal does support colors, but Vim doesn't know this. 42 Make sure your $TERM setting is correct. For example, when using an 43 xterm that supports colors: > 44 45 setenv TERM xterm-color 46 < 47 or (depending on your shell): > 48 49 TERM=xterm-color; export TERM 50 51 < The terminal name must match the terminal you are using. 52 53 - The file type is not recognized. 54 Vim doesn't know all file types, and sometimes it's near to impossible 55 to tell what language a file uses. Try this command: > 56 57 :set filetype 58 < 59 If the result is "filetype=" then the problem is indeed that Vim 60 doesn't know what type of file this is. You can set the type 61 manually: > 62 63 :set filetype=fortran 64 65 < To see which types are available, look in the directory 66 $VIMRUNTIME/syntax. For the GUI you can use the Syntax menu. 67 Setting the filetype can also be done with a |modeline|, so that the 68 file will be highlighted each time you edit it. For example, this 69 line can be used in a Makefile (put it near the start or end of the 70 file): > 71 72 # vim: syntax=make 73 74 < You might know how to detect the file type yourself. Often the file 75 name extension (after the dot) can be used. 76 See |new-filetype| for how to tell Vim to detect that file type. 77 78 - There is no highlighting for your file type. 79 You could try using a similar file type by manually setting it as 80 mentioned above. If that isn't good enough, you can write your own 81 syntax file, see |mysyntaxfile|. 82 83 84 Or the colors could be wrong: 85 86 - The colored text is very hard to read. 87 Vim guesses the background color that you are using. If it is black 88 (or another dark color) it will use light colors for text. If it is 89 white (or another light color) it will use dark colors for text. If 90 Vim guessed wrong the text will be hard to read. To solve this, set 91 the 'background' option. For a dark background: > 92 93 :set background=dark 94 95 < And for a light background: > 96 97 :set background=light 98 99 < Make sure you put this _before_ the ":syntax enable" command, 100 otherwise the colors will already have been set. You could do 101 ":syntax reset" after setting 'background' to make Vim set the default 102 colors again. 103 104 - The colors are wrong when scrolling bottom to top. 105 Vim doesn't read the whole file to parse the text. It starts parsing 106 wherever you are viewing the file. That saves a lot of time, but 107 sometimes the colors are wrong. A simple fix is hitting CTRL-L. Or 108 scroll back a bit and then forward again. 109 For a real fix, see |:syn-sync|. Some syntax files have a way to make 110 it look further back, see the help for the specific syntax file. For 111 example, |ft-tex-syntax| for the TeX syntax. 112 113 ============================================================================== 114 *06.3* Different colors *:syn-default-override* 115 116 If you don't like the default colors, you can select another color scheme. In 117 the GUI use the Edit/Color Scheme menu. You can also type the command: > 118 119 :colorscheme evening 120 121 "evening" is the name of the color scheme. There are several others you might 122 want to try out. Look in the directory $VIMRUNTIME/colors. 123 124 When you found the color scheme that you like, add the ":colorscheme" command 125 to your |init.vim| file. 126 127 You could also write your own color scheme. This is how you do it: 128 129 1. Select a color scheme that comes close. Copy this file to your own Vim 130 directory. For Unix, this should work: > 131 132 !mkdir -p ~/.config/nvim/colors 133 !cp $VIMRUNTIME/colors/morning.vim ~/.config/nvim/colors/mine.vim 134 < 135 This is done from Vim, because it knows the value of $VIMRUNTIME. 136 137 2. Edit the color scheme file. These entries are useful: 138 139 cterm attributes in a color terminal 140 ctermfg foreground color in a color terminal 141 ctermbg background color in a color terminal 142 gui attributes in the GUI 143 guifg foreground color in the GUI 144 guibg background color in the GUI 145 146 For example, to make comments green: > 147 148 :highlight Comment ctermfg=green guifg=green 149 < 150 Attributes you can use for "cterm" and "gui" are "bold" and "underline". 151 If you want both, use "bold,underline". For details see the |:highlight| 152 command. 153 154 3. Tell Vim to always use your color scheme. Put this line in your |vimrc|: > 155 156 colorscheme mine 157 158 If you want to see what the most often used color combinations look like, use 159 this command: > 160 161 :runtime syntax/colortest.vim 162 163 You will see text in various color combinations. You can check which ones are 164 readable and look nice. 165 166 ============================================================================== 167 *06.4* With colors or without colors 168 169 Displaying text in color takes a lot of effort. If you find the displaying 170 too slow, you might want to disable syntax highlighting for a moment: > 171 172 :syntax clear 173 174 When editing another file (or the same one) the colors will come back. 175 176 If you want to stop highlighting completely use: > 177 178 :syntax off 179 180 This will completely disable syntax highlighting and remove it immediately for 181 all buffers. See |:syntax-off| for more details. 182 183 *:syn-manual* 184 If you want syntax highlighting only for specific files, use this: > 185 186 :syntax manual 187 188 This will enable the syntax highlighting, but not switch it on automatically 189 when starting to edit a buffer. To switch highlighting on for the current 190 buffer, set the 'syntax' option: > 191 192 :set syntax=ON 193 < 194 ============================================================================== 195 *06.5* Further reading 196 197 |usr_44.txt| Your own syntax highlighted. 198 |syntax| All the details. 199 200 ============================================================================== 201 202 Next chapter: |usr_07.txt| Editing more than one file 203 204 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: