syntax-highlighting interview questions
Top syntax-highlighting frequently asked interview questions
I have a textmate color theme I really like this,
But I am a hardcore vim user. Is there an easy (painless) way for me to use this color scheme with vim?
Source: (StackOverflow)
How can I highlight XML from stdin (e.g. piped from xmllint --format
) to stdout?
I know how to get highlighting working in nano
and view
, but is there something that just outputs to stdout and exits?
What I'd link to do is just type something like
xmllint --format xmlfile.xml | some-highlighter
or maybe, for big files
xmllint --format xmlfile.xml | some-highlighter | less
and get pretty output.
Source: (StackOverflow)
For example, if I open a text file, notepad++ would open it in 'default' theme. But if I open a php file for instance, it would open it in 'custom_theme1'. I know notepad++ is highly extensible, so I wasn't sure if anybody had ever run across a plugin that could do it. Or could a plugin even be written to do this?
Source: (StackOverflow)
Meld 1.5.1 uses gtksourceview (via pygtksourceview) for its syntax-highlighting, however I'm unable to figure out how to configure it to use a specific style (color scheme/theme) from the ones available to gtksourceview.
Maybe the solution is outside of meld - eg, settings the default style used for gtksourceview in general, or something similar.
Source: (StackOverflow)
I like the code coloring in Github so that keywords gets highlighted when view source code.
But in Bitbucket i see very light color and almost no diff between codes , keywords etc.
very bad color coding for all languages
Is there any way to chnage that or its default for all
Source: (StackOverflow)
How do I make vim automatically apply c++ syntax highlight on Arduino files (.ino/.pde)?
Or how does vim syntax highlight know what is a c++ file? And how can I tell him that files that is called .ino and .pde is also c++ files.
Source: (StackOverflow)
How do I easily write and syntax-highlighted PHP code (or any others programming language) in a Word 2009 document?
Source: (StackOverflow)
I've run into some kind of O(n^2) or worse behavior when viewing very large (e.g. 128MB) files in Emacs and jumping to the end of the file. I think it may have to do with my coloring algorithm to color the text contextually. If I type control-g (keyboard-quit), the operation is not affected. I'd like some way to recover my emacs session without just killing it. I tried sending a SIGINT, but emacs just exited. Are there any signals I can send, or some other way (perhaps in a debugger) to force the whatever action is running to give up and return control to me?
Source: (StackOverflow)
This question already has an answer here:
I have an XML snippet in Notepad++ that I would like to share with a co-worker via email. In Notepad++ the syntax highlighting nicely shows off the elements and attributes. Here is a sample picture:

When I copy/paste this in Outlook only the text comes over. The Outlook email is set to HTML. I have also verified in Word only the text is pasted.
There are separate Copy to Clipboard
menu items but they look focused on filenames. Is there an option or extension that will copy the formatting as well as the text?
Source: (StackOverflow)
I am editing some xml right now and I have been leaving myself some comments of things to come back to. Like this
<!-- Question: bla bla -->
I am editing with vim right now and I would like vim to highlight Question right now so that I can easily look through my code and find all the places I need to look at. I know I need to add something in my vimrc but I think that I might be searching for the wrong thing.
Update
I tried putting this in my .vimrc
but it had no effect:
syn keyword JakeAnnotation Question
hi JakeAnnotation gui=bold term=bold cterm=bold
Update 2
Actually I can see that what I did before had some effect because when I do this:
:hi
It shows me all of the things that it is highlighting and one of the entries is:
JakeAnnotation xxx term=bold cterm=bold ctermbg=6
(and the xxx is formatted correctly)
This leads me to beleave that I am just not defining Question properly. Does Question need to be on a line by itself?
Update 3
Ok so to user 22303's post I have this working:
highlight MyQuestion cterm=bold term=bold ctermbg=blue ctermfg=black
match MyQuestion /Question/
However I suspect that you are only allowed to have one match per file. Because when I do this:
highlight MyQuestion cterm=bold term=bold ctermbg=blue ctermfg=black
match MyQuestion /Question/
highlight MyRelook cterm=bold term=bold ctermbg=blue ctermfg=black
match MyRelook /Another look/
The first one stops working. (But the second one works).
Source: (StackOverflow)
Customizing what files you can preview is cool, but is there a way to create a custom preview extension to add syntax highlighting? I have many .h, .c, .cpp, .cs and .java files on my windows machine and it would be nice to have the syntax highlighting available via explorer's new preview pane.
Source: (StackOverflow)
I'm working on reorganizing my .bashrc
. I moved my aliases to .bash_aliases
(which is sourced by .bashrc
, but I can't figure out how to enable syntax highlighting for this file. vim
seems unable to figure out what language the file is in. It works fine for .bashrc
. Any ideas?
Source: (StackOverflow)
How do you take notes on code snippets and or command line sequences in Evernote (Mac or PC)? Is there a way to have code blocks like the 'Code Sample' buttons here:
example
Any way to have colored syntax highlighting?
Source: (StackOverflow)
I have defined a file time jak.vim
to offer custom highlighting when I take notes, however it is being applied to some files that do not have the .jak
extension. Specifically a file named progress.jlog
. Just to test if the problem was specific to that extension I renamed progress.jlog
to progress
(no extension) but experienced the same problem.
What I did:
- I created
jak.vim
in the directory ~/.vim/ftdetect
- I added this line: "au BufRead, BufNewFile *.jak set filetype=jak" to the top as described in the vim reference
- I restarted vim (:x, and then reopened)
This is what my ~/.vim/ftdetect/jak.vim
looks like:
~/.vim/ftdetect][505]% cat jak.vim
au BufRead, BufNewFile *.jak set filetype=jak
syn region JakeSubtitle start=+==+ end=+==+
highlight JakeSubtitle ctermbg=black ctermfg=DarkMagenta
syn region JakeTitle start=+===+ end=+===+
highlight JakeTitle ctermbg=black ctermfg=yellow
syn region JakeMasterTitle start=+====+ end=+====+
highlight JakeMasterTitle cterm=bold term=bold ctermbg=black ctermfg=LightBlue
syn region emphasis start=+<em>+ end=+</em>+
highlight emphasis ctermbg=black ctermfg=yellow
" makes all of the numbered items bold."
" (this works I just don't like the effect. Decided to change to just highlight the "number)
"syn region numberedItem start=+^\t*\d*)+ end=+\n+"
syn match numberedItem +^\t*\d*)+
highlight numberedItem cterm=bold
And just incase you need to know this is what my .vimrc
looks like:
~/.vim/ftdetect][508]% cat ../../.vimrc
"on will override defaults set. Enable will allow you to set defaults."
" also turns on filetype"
"syntax on"
syntax enable
set nocompatible
" ???"
set backspace=2
"Auto indent"
set ai
"Map jj to Esc so that you do not have to reach for the Esc button"
imap jj <Esc>
"do not allow the search to wrap around the screen, must stop at the bottom."
set nowrapscan
"when doing a search highlight all occurances"
":set hlsearch"
"stop text from wrapping on the screen"
set nowrap
"turn the mouse on while in insert mode"
set mouse=i
"attempting to highlight specific keywords so it is easy to see in code."
"see help e410 for more info."
"see this post I created: http://superuser.com/questions/110054/custom-vim-highlighting"
"Legal colors: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta,"
"Brown, DarkYellow, LightGray, LightGrey, Gray, Grey, DarkGray, DarkGrey,"
"Blue, LightBlue, Green, LightGreen, Cyan, LightCyan, Red, LightRed, Magenta,"
"LightMagenta, Yellow, LightYellow, White"
syn keyword JakeKeywords Question TODO Answer JAKEHTTPS PossibleProblem
highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=Blue
"for case-insensitve searches"
set ignorecase
"Override the 'ignorecase' option if the search pattern contains upper"
"case characters. Only used when the search pattern is typed and"
"'ignorecase' option is on."
set smartcase
"use indents as the folding method"
set foldmethod=indent
"make vim save and load the folding of the document each time it loads"
"also places the cursor in the last place that it was left."
au BufWinLeave * mkview
au BufWinEnter * silent loadview
Note: I completed all the quotes (comments) to make it easier to read
Update
I found nsharish's post to be very helpfull. They suggested that I add this to my vimrc:
au BufRead,BufNewFile *.jak set filetype=jak
and add my jak.vim
file to ~/.vim/syntax
Unfortunately that code conflicts with these two lines (in my vimrc)
au BufWinLeave *.c mkview
au BufWinEnter *.c silent loadview
I use these two to save my folds, cursor location, etc when loading vim (see :help lo
). If I comment out those two lines nsharish's suggestion works like a charm. With those two lines there is no highlighting in any of my files.
Conclusion
I marked nsharish's answer as the best answer (because it as most helpful to me). However this is how I solved the problem:
Nsharish was right I needed this line in my .vimrc
:
syntax enable
au BufRead,BufNewFile *.jak set filetype=jak
And I needed to move my jak.vim
file to ~/.vim/syntax
.
However as noted above there was a conflict with these lines:
au BufWinLeave * mkview
au BufWinEnter * silent loadview
When these lines were commented the highlighting worked.
What I needed to do was to change the ...set filetype...
to this:
au BufWinEnter,BufRead,BufNewFile *.jak set filetype=jak
I think that the BufWinEnter is called after the BufRead/BufNew file so the highlighting was being overwritten by the formatting saved from last time.
Thank again to nsharish for helping me to come up with this solution.
Source: (StackOverflow)
Background
Batch convert various syntax-highlighted source files (C, SQL, Java, PHP, batch, bash) into high-resolution images (600dpi), suitable for an eBook and printed book.
Failed Solutions
A number of attempts so far:
- OpenOffice or LibreOffice - Have to re-import source code into the document every time the source file changes. (That is, the solution cannot be easily automated for hundreds or thousands of source files.)
- enscript. Cannot easily change colours, imperfectly renders output, not comprehensive.
- LyX / LaTeX. Imperfectly renders output.
- gvim to HTML — HTMLDOC to PostScript — GhostScript to PNG. HTMLDOC ignores
font
tags.
- gvim to HTML — html2ps — GhostScript to PNG. RGB colours are not recognized by
html2ps
.
- Firefox to PostScript — GhostScript to PNG. Obnoxiously circuitous.
- gvim to HTML — OmniFormat to anything. Free version unsuitable for batch processing; lots of advertising pop-ups.
- pygments. Cannot easily change image resolution; does not have gvim's range of colour schemes.
Closest Solution
The solution that almost works is:
- gvim to HTML — wkhtmltopdf to PDF. Will require post-processing with ImageMagick (wkhtmltoimage cannot set image resolution, only page width).
Requirements
- Windows and Linux, but either is acceptable.
- Free or OSS
- Command line only (suitable for batch processing)
- Easily change colour scheme
- Support: PHP, batch, bash, Java, JavaScript, R, C, and SQL
Question
Any other ways to convert syntax-highlighted source code to a high-resolution (600dpi) image?
Thank you!
Source: (StackOverflow)