Skip to content
Browse files


  • Loading branch information...
1 parent 2de4679 commit d424784c5976ca79d1f4514b2507030b03a6db3b @sjl sjl committed Nov 16, 2011
Showing with 60 additions and 0 deletions.
  1. +6 −0 chapters/46.markdown
  2. +54 −0 chapters/47.markdown
6 chapters/46.markdown
@@ -129,3 +129,9 @@ a conscious decision about whether to make `:` an operator. If you decide to do
so, add it to the syntax file.
Do the same for `.` and `/`.
+Add a syntax group `potionNumber` that highlights numbers. Link it to the
+highlight group `Number`. Remember that Potion supports numbers like `2`,
+`0xffaf`, `123.23`, `1e-2`, and `1.9956e+2`. Remember to balance the time it
+takes to handle edge cases with the amount of time those edge cases will
+actually be used.
54 chapters/47.markdown
@@ -0,0 +1,54 @@
+Even More Advanced Syntax Highlighting
+Syntax highlighting in Vim is a topic that could easily fill a book of its own.
+We're going to cover one last important part of it here and then move on to
+other things. If you want to learn more you can read the Vim documentation with
+`:help syntax` and look at syntax files other people have made.
+Highlighting Strings
+Potion, like most programming languages, supports string literals like `"Hello,
+world!"`. We should highlight these as strings. To do this we'll use the
+`syntax region` command. Add the following to your Potion syntax file:
+ syntax region potionString start=/\v"/ skip=/\v\\./ end=/\v"/
+ highlight link potionString String
+Close and reopen your `` file and you'll see that the string at the
+end of the file is highlighted!
+The last line here should be familiar. Reread the previous two chapters if you
+don't understand what it does.
+The first line adds to a syntax group using a "region". Regions have a "start"
+pattern and an "end" pattern that specify where they start and end. In this
+case, a Potion string starts when we see a double quote and ends when we see the
+next double quote.
+The "skip" argument to `syntax region` allows us to handle string escapes like
+`"She said: \"Vimscript is tricky, but useful\"!"`.
+If we didn't use the `skip` argument Vim would end the string at the `"` before
+`Vimscript`, which is not what we want!
+In a nutshell, the `skip` argument to `syntax region` tells Vim: "once you start
+matching this region, I want you to ignore anything that matches `skip`, even if
+it would normally be considered the end of the region".
+Take a few minutes and think through this. What happens with something like
+`"foo \\" bar"`? Is that the correct behavior? Will that *always* be the
+correct behavior? Close this book, take a few minutes and really *think* about
+Add syntax highlighting for single quoted strings.
+Read `:help syn-region`.
+Reading that should take longer than reading this chapter. Pour yourself
+a drink, you've earned it!

0 comments on commit d424784

Please sign in to comment.
Something went wrong with that request. Please try again.