Movatterモバイル変換


[0]ホーム

URL:


Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq
Go to keyword (shortcut:k)
Site search (shortcut:s)
usr_06.txt  ForVim version 9.1.  Last change: 2024 Oct 05     VIM USER MANUAL- byBramMoolenaar  Usingsyntax highlightingBlack and white textis boring.  With colors your file comes to life.  Thisnot only looks nice,it also speeds up your work.  Change the colors used forthe different sorts of text.  Print your text, with the colors you see on thescreen.06.1  Switchingit on06.2  No or wrong colors?06.3  Different colors06.4  With colors or without colors06.5  Printing with colors06.6  Further reading     Next chapter:usr_07.txt  Editing more than one file Previous chapter:usr_05.txt  Set your settingsTable of contents:usr_toc.txt==============================================================================06.1  Switchingit onIt all starts with one simple command::syntax enableThat should work in most situations to get color in your files.  Vim willautomagically detect the type of file and load the rightsyntax highlighting.Suddenly comments are blue, keywords brown and strings red.  This makesiteasy to overview the file.  Aftera while you will find that black&white textslows you down!If you always want to usesyntax highlighting,put the ":syntax enable"command in yourvimrc file.If you wantsyntax highlighting only when theterminal supports colors, youcanput this in yourvimrc file:if &t_Co > 1   syntax enableendifIf you wantsyntax highlighting only in theGUI version,put the ":syntaxenable" command in yourgvimrc file.==============================================================================06.2  No or wrong colors?There can bea number of reasons why you don't see colors:- Yourterminal does not support colors.Vim will use bold,italic and underlined text, but this doesn't lookvery nice.  You probably will want to try to getaterminal withcolors.  For Unix,I recommend the xterm from the XFree86 project:xfree-xterm.- Yourterminal does support colors, but Vim doesn't know this.Make sure your $TERM settingis correct.  For example, when using anxterm that supports colors:setenv TERM xterm-coloror (depending on your shell):TERM=xterm-color; export TERMTheterminal namemust match theterminal you are using.  Ifitstill doesn't work, havea lookatxterm-color, which showsa fewways to make Vim display colors (not only for an xterm).- The file typeis not recognized.Vim doesn't know all file types, and sometimes it's near to impossibleto tell what languagea file uses.  Try this command::set filetypeIf the resultis "filetype=" then the problemis indeed that Vimdoesn't know what type of file this is.  You can set the typemanually::set filetype=fortranTo see which types are available, look in the directory$VIMRUNTIME/syntax.  For theGUI you can use theSyntax menu.Setting thefiletype can also be done withamodeline, so that thefile will be highlighted each time you edit it.  For example, thisline can be used ina Makefile (putit near the start orend of thefile):# vim: syntax=makeYou might know how to detect the file type yourself.  Often the filename extension (after the dot) can be used.Seenew-filetype for how to tell Vim to detect that file type.- Thereis no highlighting for your file type.You could try usinga similar file type by manually settingitasmentioned above.  If that isn't good enough, you can write your ownsyntax file, seemysyntaxfile.Or the colors could be wrong:- The colored textis very hard to read.Vim guesses the background color that you are using.  Ifitis black(or another dark color)it will use light colors for text.  Ifitiswhite (or another light color)it will use dark colors for text.  IfVim guessed wrong the text will be hard to read.  To solve this, setthe'background' option.  Fora dark background::set background=darkAnd fora light background::set background=lightMake sure youput this _before_ the ":syntax enable" command,otherwise the colors will already have been set.  You coulddo":syntax reset" after setting'background' to make Vim set the defaultcolors again.- The colors are wrong whenscrolling bottom to top.Vim doesn't read the whole file to parse the text.  It starts parsingwherever you are viewing the file.  That savesa lot of time, butsometimes the colors are wrong.A simple fixis hittingCTRL-L.  Orscroll backa bit and then forward again.Fora real fix, see:syn-sync.  Somesyntax files havea way to makeit look further back, see thehelp for the specificsyntax file.  Forexample,tex.vim for the TeX syntax.==============================================================================06.3  Different colors:syn-default-overrideIf you don't like the default colors, you can select another color scheme.  IntheGUI use the Edit/Color Scheme menu.  You can also type the command::colorscheme evening"evening"is the name of the color scheme.  There are several others you mightwant to try out.  Look in the directory $VIMRUNTIME/colors.When you found the color scheme that you like, add the ":colorscheme" commandto yourvimrc file.You could also write your own color scheme.  Thisis how youdo it:1.Selecta color scheme that comes close.  Copy this file to your own Vim   directory.  For Unix, this should work:!mkdir ~/.vim/colors!cp $VIMRUNTIME/colors/morning.vim ~/.vim/colors/mine.vim   Thisis done from Vim, becauseit knows the value of $VIMRUNTIME.2. Edit the color scheme file.  These entries are useful:termattributes ina B&Wterminalctermattributes ina colorterminalctermfgforeground color ina colorterminalctermbgbackground color ina colorterminalguiattributes in theGUIguifgforeground color in theGUIguibgbackground color in theGUI   For example, to make comments green::highlight Comment ctermfg=green guifg=green   Attributes you can use for "cterm" and "gui" are "bold" and "underline".   If you want both, use "bold,underline".  For details see the:highlight   command.3. Tell Vim to always use your color scheme.  Put this line in yourvimrc:colorscheme mineIf you want to see what the most often used color combinations look like, usethis command::runtime syntax/colortest.vimYou will see text invarious color combinations.  You can check which ones arereadable and look nice.  These aren't the only colors available to you though.You can specify #rrggbb hex colors and you can define new names for hexcolors inv:colornames like so:let v:colornames['mine_red'] = '#aa0000'If you are authoringa color scheme for others to use,itis importantto define these colors only when theydo not exist:call extend(v:colornames, {'mine_red': '#aa0000'}, 'keep')This allows users of the color scheme to override the precise definition ofthat color prior to loading your color scheme.  For example, ina.vimrcfile:runtime colors/lists/css_colors.vimlet v:colornames['your_red'] = v:colornames['css_red']colorscheme yourschemeAsa color scheme author, you should be able to rely on some color names forGUI colors.  These are defined incolors/lists/default.vim.  All such filesfound on the'runtimepath' are loaded each time the colorscheme commandisrun.A canonicallistis provided by the vim distribution, which shouldinclude allX11 colors (previously defined in rgb.txt).==============================================================================06.4  With colors or without colorsDisplaying text in color takesa lot of effort.  If you find the displayingtoo slow, you might want to disablesyntax highlighting fora moment::syntax clearWhen editing another file (or the same one) the colors will come back.If you want to stop highlighting completely use::syntax offThis will completely disablesyntax highlighting and removeit immediately forall buffers.  See:syntax-off for more details.:syn-manualIf you wantsyntax highlighting only for specific files, use this::syntax manualThis will enable thesyntax highlighting, but not switchit on automaticallywhenstarting to edita buffer.  To switch highlighting on for the currentbuffer, set the'syntax' option::set syntax=ON==============================================================================06.5  Printing with colorssyntax-printingIn theMS-Windows version you can print the current file with this command::hardcopyYou will get the usual printer dialog, where you can select the printer andafew settings.  If you havea color printer, the paper output should look thesameas what you see inside Vim.  But when you usea dark background thecolors will be adjusted to look good on white paper.There are severaloptions that change the way Vim prints:'printdevice''printheader''printfont''printoptions'To print onlya range of lines,  useVisual mode to select the lines and thentype the command:v100j:hardcopy"v" startsVisual mode.  "100j" movesa hundred lines down, they will behighlighted.  Then ":hardcopy" will print those lines.  You can use othercommands to move inVisual mode, of course.This also works on Unix, if you havea PostScript printer.  Otherwise, youwill have todoa bit more work.  You need to convert the text to HTML first,and then printit froma web browser.Convert the current file to HTML with this command::TOhtmlIncase that doesn't work::source $VIMRUNTIME/syntax/2html.vimYou will seeit crunching away, this can take quitea while fora large file.Some time later anotherwindow shows the HTML code.  Now write this somewhere(doesn't matter where, you throwit away later)::write main.c.htmlOpen this file in your favorite browser and printit from there.  If all goeswell, the output should look exactlyasit does in Vim.  See2html.vim fordetails.  Don't forget to delete the HTML file when you are done with it.Instead of printing, you could alsoput the HTML file ona web server, and letothers lookat the colored text.==============================================================================06.6  Further readingusr_44.txt  Your ownsyntax highlighted.syntax      All the details.==============================================================================Next chapter:usr_07.txt  Editing more than one fileCopyright: seemanual-copyright  vim:tw=78:ts=8:noet:ft=help:norl:

Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq


[8]ページ先頭

©2009-2025 Movatter.jp