Sublime Forum

How to highlight block of code

#1

http://bit.ly/YNmlAI

Do anybody know how to highlight blocks of text as with the image above?

Here is the link again should the other image doesnt work. Thanks all.

0 Likes

#2

Push Ctrl+` to load the console to test the following command. It will highlight the current selection with the coloring for scope “string” as defined in your color scheme. You can make it into a plugin command and then assign a key binding to that plugin command.

view.add_regions("highlightkeytest", view.sel(), "string")

sublimetext.com/docs/2/api_reference.html
add_regions(key, [regions], scope, , )
The scope is used to source a color to draw the regions in, it should be the name of a scope, such as “comment” or “string”. If the scope is empty, the regions won’t be drawn.

0 Likes

#3

Thanks for replying Robert.

I dont get it yet, I have tried to put the following code into the console.view.add_regions("highlightkeytest", view.sel(), "string") I just get the following error.[code]Boost.Python.ArgumentError: Python argument types in
View.add_regions(View, str, RegionSet, str)
did not match C++ signature:
add_regions(SP, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, boost::python::list, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >)
add_regions(SP, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, boost::python::list, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, int)
add_regions(SP, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, boost::python::list, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >)
add_regions(SP, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, boost::python::list, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, int)

add_regions(“highlightkeytest”, view.sel(), “string”)
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘add_regions’ is not defined[/code]

Im not experienced using this sort of coding language at all, but i think that highlighting certain areas with code they way it shows in the screenshot above could be very handy.

Will you explain the steps for the highlight feature please.

Thanks.

0 Likes

#4

Change your statement to

view.add_regions("highlightkeytest", list(view.sel()), "string")

What are you trying to do?

0 Likes