Vim Tips Wiki
No edit summary
 
(Adjust previous/next navigation)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1120
 
|id=1120
  +
|previous=1119
|title=Syntax highlighting when starting a string: fix annoyance
 
  +
|next=1126
|created=February 4, 2006 17:49
+
|created=February 4, 2006
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=AK
 
|author=AK
 
|version=5.7
 
|version=5.7
 
|rating=1/10
 
|rating=1/10
  +
|category1=Python
|text=
 
  +
|category2=
Did you ever notice how syntax highlight of the whole screen below current line changes when you start a string line (at least, in .py python files)? Vim thinks the rest of the screen is inside a string and highlights it as such. I find this extremely annoying and I found a very neat fix: you have to edit the syntax file for python (or some other language), and add 'oneline' to the relevant line:
 
 
}}
 
Did you ever notice how syntax highlight of the whole screen below current line changes when you start a string line (at least, in .py Python files)? Vim thinks the rest of the screen is inside a string and highlights it as such. I find this extremely annoying and I found a very neat fix: you have to edit the syntax file for Python (or some other language), and add 'oneline' to the relevant line:
   
  +
<pre>
 
syn region pythonString matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\'+ contains=pythonEscape oneline
 
syn region pythonString matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape oneline
  +
</pre>
   
 
This way, only the current line will change, from cursor to the end of line. Usually you're entering the string at the end of line, so you'll have no changes in syntax at all.
   
 
==Comments==
syn region pythonString matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\'+ contains=pythonEscape oneline
 
 
But then you lose the ability to see when you've forgotten to close a quote, etc.
   
syn region pythonString matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape oneline
 
 
 
 
This way only current line will change, from cursor to the end of line. Usually you're entering the string at the end of line, so you'll have no changes in syntax at all.
 
}}
 
 
== Comments ==
 
... but then you loose the ability to *see* when you've forgotten to close a quote, etc...
 
 
'''Anonymous'''
 
, February 5, 2006 0:47
 
 
----
 
----
Just map the sting delimiter key to produce a pair of them and position you between them.
+
Just map the sting delimiter key to produce a pair of them and position you between them.
  +
<pre>
inoremap " ""&lt;Esc&gt;i
+
inoremap " ""<Esc>i
That way you do not forget to close the string and you do not have the syntax coloring problem.
 
  +
</pre>
 
   
 
That way you do not forget to close the string and you do not have the syntax coloring problem.
   
'''Anonymous'''
 
, February 5, 2006 15:28
 
 
----
 
----
<!-- parsed by vimtips.py in 0.550079 seconds-->
 

Latest revision as of 02:51, 20 July 2009

Tip 1120 Printable Monobook Previous Next

created February 4, 2006 · complexity intermediate · author AK · version 5.7


Did you ever notice how syntax highlight of the whole screen below current line changes when you start a string line (at least, in .py Python files)? Vim thinks the rest of the screen is inside a string and highlights it as such. I find this extremely annoying and I found a very neat fix: you have to edit the syntax file for Python (or some other language), and add 'oneline' to the relevant line:

syn region pythonString matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\'+ contains=pythonEscape oneline
syn region pythonString matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape oneline

This way, only the current line will change, from cursor to the end of line. Usually you're entering the string at the end of line, so you'll have no changes in syntax at all.

Comments[]

But then you lose the ability to see when you've forgotten to close a quote, etc.


Just map the sting delimiter key to produce a pair of them and position you between them.

inoremap " ""<Esc>i

That way you do not forget to close the string and you do not have the syntax coloring problem.