Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing code with syntax highlighting?

I have occasion to need to print code (Horrors!!! ;) ), and i was wondering what editor or tool would i use to print that code out with proper formatting and syntax highlighting? If it's important, it will be c# code but ideally the tool will work for as many languages as possible. Can Notepad++ or something handle this?

like image 691
RCIX Avatar asked Nov 01 '09 11:11

RCIX


People also ask

How do I print codes with syntax highlighting?

Simply open the file on command line with vim <filename> , type :syntax on<ENTER> , then :hardcopy<ENTER> to print it.

Does VS code have syntax highlighting?

Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords like if or for in JavaScript differently than strings and comments and variable names.


3 Answers

You can use Vim! It's probably installed already if you're on modern Linux/MacOS and an easy install if not.

:syntax will turn syntax highlighting on and :hardcopy will print it. There's syntax highlighting definitions for many languages out there. The default look is usually optimised for screen display, but you can fix that.

Simply open the file on command line with vim <filename>, type :syntax on<ENTER>, then :hardcopy<ENTER> to print it. Quit Vim with :q!<ENTER>.

There's also the :TOhtml command which will open the current selection as HTML in a new Vim window. Capture the entire document with :%y<ENTER> followed by :TOhtml<ENTER> to open it.

like image 148
mahemoff Avatar answered Sep 17 '22 23:09

mahemoff


Yes, Notepad++ can certainly print code with syntax highlighting.

Colour printing would obviously be preferable, but on the occasions when I've printed in black and white, the subtle differences in colour [rendered as shades of grey, of course] can be difficult to distinguish.

However, I think a little customisation of the colour schemes should make this less of a problem.

like image 41
pavium Avatar answered Sep 16 '22 23:09

pavium


Use vim. Its the easiest method to do it in my experience by far, that is, once you know how.

Vim comes pre-installed on Macs, btw. And I know how you special people like colors, so I'm going to make this impatientbusinessman-proof for the benefit of all.

1.) open file

vim filename.m

2.) enable syntax coloration (mine did not have enabled by default)

:syntax on

3.) print

:hardcopy

Vim will choose your system's default printer without asking you so make sure you set that up first.

4.) exit the program (this is actually not a given)

:q

OR

Use Aptana. Aptana is pretty sweet, its free and it has great ftp functionality.

like image 39
boulder_ruby Avatar answered Sep 17 '22 23:09

boulder_ruby