Vim context highlighting - vim

I think standard highlighting is useful -- to some extent. When programming with callbacks and nested structures, this does not help. Keywords and strings, they appear everywhere, and it helps when they are shown in a distinct color, but these colors gives no clue about in which scope I am, where I am in a lexical standpoint.
I have heard of context highlighting, in a talk of Douglas Crockford, which I can't remember a url to. The idea is, to highlight lexical levels of scope. Toplevel definitions are colored in color0, inner level block statements are colored in color1, and this repeats recursively every time a new level of scope is introduced. Below is an example for this, using some imaginary node libraries. (Now added a (ish (or scheme lisp)) example)
This is not necessarily for node or javascript. I wonder if there is an editor/vim plugin implementing this kind of feature. I don't know if context highlighting is the word for this, but I can't just find one. Googling for context highlighting brings up results for generic token based highlighting and ConTeXt (which I don't have a clue about).
Does this exists? Is there an editor implements this? And more importantly, can I have this in vim?
Another question which is identical to mine, with no real answer: Is Crockford style Context Coloring implemented in any code editor?

I also couldn't find anything similar, so I wrote one:
rainbow_levels.vim: A different approach to code highlighting.
Of course it is a very simplistic implementation, only considering indentation levels instead of real context, but it gets the job done ;D

Not exactly what you are requesting, but code folding is a powerful feature to let you focus on specific levels of your code. Vim supports folding http://vim.wikia.com/wiki/Folding
Indention guides are very handy also, for focusing in on specific parts of code. The sublime text editor has this (http://sublimetext.userecho.com/topic/98136-indent-guide-highlighting-changed/)
I saw this plugin for vim (https://github.com/nathanaelkane/vim-indent-guides) that appears to do the same thing.
You could possibly create a syntax highlighter that uses the indentation logic of this plugin to change the color scheme. What you describe is more involved where it needs to work not just off the indention, but like a language parser.

There is now a plugin for this in VIM called vim-js-context-coloring. I've only just played with it a little and am not super impressed yet, but it looks promising!
Note: you need to install npm and then run npm install in the directory where the plugin is installed. I regretfully, forgot to read the instructions when I installed it.

Related

Sublime, altering behavior of highlighting definions upon mouse-hover

I have a project with several classes which partly share functions while at other times the functions are different in code, but use the same name.
When hovering over a function name, Sublime highlights every file and line where that definition is found.
In my opinion it would be better if it actually included which class the different highlights belong to.
Is it possible to edit this in some way ?
Assume systems.js contains 4 different classes (1 base, 3 children). I would like to append or prepend the shown strings by the class definition (fetchable via prototype).
The hover popup mentioned in your question is powered by Sublime's internal symbol index, which is created in combination with the syntax definition that's used to syntax highlight files that you're editing. The Sublime syntax system is fairly context free; it parses the structure of the code but it doesn't contain any real structural information about it.
So for example it can determine that getShots is a function or method because of the syntax that was used to define it, but it doesn't know what class it came from.
The code for the hover popup is available in Default/symbol.py (you can use PackageResourceViewer to examine it) and associates symbols under the cursor with other places that it's seen symbols with that name in other files in the project; it literally only knows the information that you see in the popup; places where things by that name are defined and places where things of that name are referenced.
So in one sense, the answer to your question is No; core sublime can't do that because it doesn't have enough code intelligence to be able to figure that sort of thing out; this is exacerbated by dynamic languages like JavaScript where things can theoretically change at runtime as well.
The primary reason for that is because Sublime is extensible enough to support literally every programming language instead of just focusing on one or two (as e.g. PhpStorm does), so it doesn't have the core code to determine the information required.
All that said, since Sublime is indeed extremely extensible, it's possible that external code that does specialize on a language could be leveraged by a package in order to provide the appropriate information.
Two examples of that are SublimeCodeIntel and LSP for example. I don't use either of them myself, so I don't know for sure how good a fit they might be in your workflow.
I highly recommend you shift to Visual Studio Code majorly because sublime is an editor whereas vs code is an IDE. Also, it has very great extension support for all languages. I would recommend you to use jshint which the most popular plugin for js code available for almost all popular editors and IDEs. But still if you want to go with Sublime I suggest you following plugins:
https://www.sitepoint.com/essential-sublime-text-javascript-plugins/

Using Sublime 2 for Haskell Development?

What is the current status of Sublime 2 integration for Haskell? I see two possible packages so far. A plugin for code highlighting and a REPL plugin.
Is there an intelli-sense plugin for Haskell?
Maybe integration with Hackage as well?
Thanks.
SublimeHaskell plugin is the modern choice for Haskell development with SublimeText. It is well maintained and has plenty of useful features.
Other quite useful plugins:
Shell Turtlestein, which allows you to quickly type in shell commands under a single keystroke from inside the editor.
SublimeREPL, which allows you to run GHCi from inside the editor. Though without support for cabal repl yet.
SideBarEnhancements, which I primarily use to rename/move files without touching the mouse. With it you can hit Ctrl/Cmd + P and type "rename" or "move" to enter the dialogue.
I use Sublime exclusively at the moment and while it's not all that special out of the box, installing sublime-text-haskell as Cubic suggested makes it a little better (it will compile and highlight errors when you save a file and apparently enhances the auto-completion).
I've experimented with writing my own plugins but the reality is that a lot of really cool possibilities are made difficult to implement because the API is actually kind of restricting (there's no way to add extra information like type signatures to auto-complete options for example).
It seems that the dev(s) are working on adding some requested API features, but until then, sublime-text-haskell is probably the best Haskell plugin.

Code-oriented editor : Must-have features?

I hope this question doesn't fall into the "subjective question" case, but here's what :
I've been coding for almost 18 years, and having migrated to Macs for the last year or so, it was inevitable to start thinking about writing a code editor from scratch - probably, just to try this thing out, or to make something that perfectly suits my needs. And I was wondering :
What are the absolute MUST-HAVEs of a good code editor*? (by order of priority, if possible)
If we're talking about a not-so-conventional feature, could you give me an example of actual implementation of that particular feature? ("xxxxx" like in Notepad++ on Windows).
Looking forward to see your answers...
*Well, there is sometimes a thin line between what could be considered as an "Editor" and an "IDE", but let's just not exclude more... IDE-oriented ones...
Syntax highlighting with error checking.
"Go to Definition"/"Go to Declaration". Other types of quick "Go To"s.
As many kinds of autocompletion as you can possibly imagine.
Vim mode or being a Vim clone (command/edit mode dichotomy).
There's a lot of other nice-to-have features like automatic refactoring but the above I believe are definitive traits of a source code editor.

How to write a VIM color scheme?

I have been looking around for VIM color schemes and found some great ones out there (esp. by using http://code.google.com/p/vimcolorschemetest/), but I always want to change a few aspects of each one I find. So I've decided now that what I really want to do is make my own, or be able to customize the ones I find on the fly. Basically, what I want to know is:
1) How do I write a vim color scheme -- are there any good (quick) tutorials?
2) How do I add language-specific customizations? Like say for Python, I might be interested in having different colors for classes and methods (is this even possible? What level of customization is possible?). Anything you can tell me about how to customize for specific languages would be fantastic! (esp. python, but also others like C, Java, Ruby would be great)
3) Are there are good, complete (ideally well-commented) templates that I could start from which contain all aspects of a color scheme, like background, text, language specific stuff, and the like?
Vivify lets you interactively create vim colorschemes with color pickers and previews your scheme using several code samples.
I didn't watch the "Creating colorschemes for Vim" episode of VIMcasts, but the others are really good.
colorschemes are actually vim scripts. You use the hi command for coloring, which works like
hi TextType guifg=#hexforegroundcolor guibg=#hexbgcolor gui=bold/italic/underlined/undercurled (assumed you use gvim). If you type :hionly, you get a complete list of text types with their current highlighting
see also http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme
May be you can find this colorscheme template useful: http://www.vim.org/scripts/script.php?script_id=106
The original description is
"The philosophy here is to provide a ready-to-uncomment list of highlight commands for all the important groups. Then you can deviate from the default until you come up with one you like."
Launch vim, say ":help syntax", it has quick start etc.
For the complete templates look at your installation:
colorschemes are in /usr/share/vim/vimcurrent/colors/
languages syntax in /usr/share/vim/vimcurrent/syntax/

Vim: How to set up an efficient autocomplete configuration?

I've been using Vim for a while now and love it, but one thing I've noticed when I use other editors is that I've never really got autocomplete working with much efficiency. I have supertab & snipmate working, I have tags for whatever language I'm using set up, but somehow it seems a little too cumbersome to use all that much, and apart from long method names I typically just avoid autocomplete.
Does anyone have fast, comprehensive autocomplete funcitonality set up in vim? Specifically:
At the moment, I hit "tab" to autocomplete class/method/variable names & generate snippets, but Ctrl+X+O for inbuilt langauge commands. I'd rather press tab for everything.
The ordering doesn't seem to be too intelligent. Very common stuff is often hidden in the middle of a bunch of rarely-used commands.
I've set up autocomplpop to show potential autocompletes as I'm typing, but I have to hit tab twice to accept the first entry. One much rather single-tab it.
So, any tips on setting up an efficient, comprehensive autocomplete configuration in vim? I know this question is a little vague - but if anyone has an overview of how they autocomplete well, and/or a link to a guide, it would be much appreciated.
Just thought I'd come back and mention that I finally found something I like: A customised version of NeoComplCache. Nice auto popup, everything integrated pleasantly into 'tab', and with a bit of customisation plays nice with snippets.
http://www.vim.org/scripts/script.php?script_id=2620
This is very dependant on your working domain. Vim is a text editor with the ability to interface with intelligent text-aware mechanisms.
If you are using java there is eclim, which is the eclipse backend together with a vim plugin for the frontend.
For C or C++ there is the plugin OmniCppComplete
It works by scanning the headers in the paths you have set up in vim (see :h path), and works very well imo.
If you have to press Ctrl-X_Ctrl-O for omnicompleteion, then your supertab config seems a bit broken. It should try omni or filename completion first, and then fall back to word completion.
YouCompleteMe plugin by Valloric is a very decent plugins for autocomplete and suggestion.
It contains support for all the major languages and you can extend the feature with setting up different engine .
it also comes with syntax checker so u don't have to use Syntastic separately
For setup details visit this link
https://github.com/Valloric/YouCompleteMe

Resources