How to copy and paste code without rich text formatting? [closed] - editor

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I used to often find myself coping a piece of code from a website/Word document etc only to discover that when doing Paste I would end up with the desired code plus some extra HTML tags/text, basically extra formatting information.
To get rid of that extra ballast I would paste the text to the Notepad and then copy it again and then paste to the desired destination.
Pretty recently I discovered a simple and free tool for Windows called PureText that allows me to cut the Notepad step. It basically adds an extra keyboard shortcut e.g WinKey + V that will do the Paste action without formatting; just pure text.
I find it very handy.
I was wondering what approach would you use yourselves? Are they any better/easier to use tools around?

Just to summarize the available options:
Tools
PureText - free tool for Windows
Use AutoHotkey and write your own macro
as suggested by Dean
Browsers
To copy plain text from a browser: Copy As Plain Text or CopyPlainText (suggested by cori) - Firefox extensions
To paste without formatting to a browser (Firefox/Chrome at least): CTRL+⇧ Shift+V on Windows/Linux, see below for Mac OS X.
Other
Under Mac OS X, you can ⇧ Shift+⌥ Alt+⌘ Command+V to paste with the "current" format (Edit -> Paste and Match Style); or ⌘ Command+⇧ Shift+V to paste without formatting (by Kamafeather)
Paste to Notepad (or other text editor), and then copy from Notepad and paste again
For single-line text: paste to any non-rich text field (browser URL, textarea, search/find inputs, etc.)
Please feel free to edit/add new items

Just for reference, under Mac OS X, you can use ⌘ Command+⇧ Shift+V to paste without formatting or with the "current" format.
Note: in some apps it's ⌘ Command+⇧ Shift+⌥ Alt+V (see "Edit" Menu → "Paste and Match Style")

I'm a big fan of Autohotkey.
I defined a 'paste plain text' macro that works in any application. It runs when I press Ctrl+Shift+V and pastes a plain version of whatever is on the clipboard. The nice thing about Autohotkey: you can code things to work the way you want them to work across all applications.
^+v::
; Convert any copied files, HTML, or other formatted text to plain text
Clipboard = %Clipboard%
; Paste by pressing Ctrl+V
SendInput, ^v
return

From websites, using Firefox, I use the CopyPlainText extension.

If you're pasting into Word you can use the Paste Special command.

I have Far.exe as the first item in the start menu.
Richtext in the clipboard ->
ctrl-escape,arrdown,enter,shift-f4,$,enter
shift-insert,ctrl-insert,alt-backspace,
f10,enter
-> plaintext in the clipboard
Pros: no mouse, just blind typing, ends exactly where i was before
Cons: ANSI encoding - international symbols are lost
Luckily, I do not have to do that too often :)

Nice find with your PureText. I had build, before I change keyboard, a key that was running a macro that was copying-pasting-copying in notepad for this task! I'll give a try to your software since I do not have any macro key now :(

I wrote an unpublished java app to monitor the clipboard, replacing items that offered text along with other richer formats, with items only offering the plain text format.

Look for a little clipboard icon that pops up at the end of the material you pasted. Click on this and choose "keep text only".

I use OpenOffice.org and that offers a paste special option, where you can omit the formatting altogether. If you are not bound to MS Word, it's IMO worth a try and it's free :-)

Whenever these plugins and options aren't available I just use my good ol friend notepad. Paste content into notepad where it won't accept the extra formatting and then copy it right back out. Sort of hacky but oh well. It works!

I usually work with Notepad2, all the text I copy from the web are pasted there and then reused, that allows me to clean it (from format and make modifications).
You can download Notepad2 here

If you are using MS Word then try ALT+E, S, U, Enter (Uses the Paste Special)

Related

Text wrapping in SPSS-22 syntax editor

I use SPSS-22 on a Linux machine.
I would like to know, if I can somehow tell the editor to automatically introduce line breaks, once the edge of the window is reached, as I would like to insert some longer comments in the syntax without having to press return all the time.
The syntax editor will turn overly long lines red, but it will not wrap the lines for you. 251 characters is the maximum legal length, but you would probably not want lines that long in your output for readability, so wrapping them yourself is probably warranted.
You might be interested in the TEXT extension command for writing long comments that will appear in separate text blocks in the output rather than being buried in log blocks. TEXT supports html and rtf markup as well.
TEXT requires the (free) Python Essentials for Statistics. Details are on the SPSS Community website (www.ibm.com/developerworks/spssdevcentral), but the Essentials are automatically installed (unless you decline) with Statistics 22. I think TEXT is included in the Essentials, but if not, you can get it via the Download and Install Extension Bundles feature under Utilities.

Normalize tab spaces

I have a project that has code that was contributed by many people without a proper policy on tab space (I know, huge mistake.)
What's the best way to normalize all tabs to spaces? Optimally some kind of a script that can do this to all files via the command line at once.
I know of Ruby Beautifier, but I didn't have any luck with ERB files (it also doesn't run on 1.9).
Thanks in advance
EDIT:
Forgot to say that we use Mac OS X
There's a command line utility bundled with OS X called tab2space that you might find useful. It's probably available on other platforms too.
I'd say open all files in Notepad++ and replace "\t" with " " (or 4 spaces) with the usual replace dialog. You'll have to choose 'Extended' in the lower left corner and press "Replace in all opened documents".

How to have "Find in Files" results automatically expanded

Simple question, (Easy points!)
In Delphi 2010 (with updates 4 and 5) "Find in Files" shows the results with the tree closed for each file. I have to click on a plus-sign to open each file's results.
I know there's a way to configure the IDE to automatically show the results with all the trees open, but for some reason (fatigue on my part?) I'm unable to find where to set that option.
Tom
Edit on year later: I re-asked this question here: Auto-expanding the results of "Find in Files" int the Messages windows and got a good answer:
"[Use the] Group results by file" checkbox on the Find In Files dialog.
Somehow I'd overlooked that! I'm posting this edit so that other readers in the future find it here.
I couldn't find anything like what you are asking about, in the Options. Perhaps you confused that with something else, but maybe I overlooked the option (too).
Anyway, there's a keyboard shortcut, Ctrl+Shift+Numpad +, to automatically expand all the tree items in the Message box tree view (when it is focused). Similarly, Ctrl+Shift+Numpad - collapses them all.
Not directly answering your question; but I was often frustrated by this, until I found the excellent Grep Search that is included with GExperts
It includes an option to 'Expand all matches after searching'. It also fixes many other shortcomings with the Delphi 'Find in Files'. I highly recommend it.

simple search engine

I am trying to write program its like a simple search engine, in this program the user is supposed to enter a search keyword into an edit box and then he can click the search button, and the program is supposed to open a specific text file from the directory and find a matching word to that keyword in this text file. I am using Delphi 2007. thank you
Basically you need to find a string in another string. Take a look at this algorithm: http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm
If you are on a unix system, send a call to grep. If you are on a windows system, install grep for windows.
You might want to look at the source code for the open source project GExperts. It contains a text search engine (grep) that works very well.
I have written something similar in C# - Searcharoo.net - you can download the source code from there.
What might be more useful, though, are the articles that I wrote describing how it works... This description of how Version 1 might be of some use - although I'm probably biased since I wrote it (back in 2004).
Your question is pretty open so I'm not sure if this will help - particularly since I don't know Delphi and how different it is to C# - but hope it helps...

Printing code with syntax highlighting? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 months ago.
Improve this question
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?
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.
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.
New Answer:
Use TextMate. It prints colored code automatically. There's no setup. Just print. In case previous or newer versions can't do this I'm using TextMate version 2.0.23
Old Answer, and the answer for people who don't have Macs:
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
http://pygments.org/ is one option. It supports a ton of languages, and since it's written as a python library, you can script the conversion process however you want.
Visual Studio will, and allows you have a completely separate configuration for printing.
I recently compared the 2 solutions already mentioned : vim & pygments. They both give great results, but there is how you can practically use them quickly:
pygments does not provide direct export to PDF. Hence, the simplest solution I found was to export to HTML and then use wkhtmltopdf. You can combine both operations using the following bash script:
src2pdf () {
local noext="${1%.*}"
pygmentize -O full -o "$noext.html" "$1"
# enabling line wrapping in <pre> blocks
perl -i -wpe '/<style.*>$/&&($_.="pre{white-space:pre-wrap;}\n")' "$noext.html"
wkhtmltopdf "$noext.html" "$noext.pdf"
rm "$noext.html"
}
for vim, it's as simple as this: TERM=xterm-256color vim '+hardcopy >out.ps' +q code.src
I found out that the $TERM environment variable can affect the output colors, so I prefer to set it explicitly.
And finally, you may need to tweak your .vimrc a little:
set printfont=:h9
set printoptions=number:y,left:5pc
The tool called enscript is very much the tool for doing this. It is very powerful, is not tied to an editor nor a language and you can create PDF's with syntax highlighting.
The documentation pretty much says it all.
enscript man page
Under unix you might want to try a2ps. It is flexible and produces nice results.
I while ago I created a household python script that wraps pygments into a small console utility. It works with any language supported by pygments.
Also if you happen to use eclipse, you could simply copy the selected text in the editor and then paste it in a RTF-aware editor like MS Word - it will preserve all the colors, fonts and formatting.
If you have problems with Visual Studio 2012 concerning the highlighted printing an handeling the described problem:
Download and install this Power Tool which implements the color
printing, besides some other features and bug fixes. Works for me!
Solution For Bash Shell
Add this line to ~/.bashrc if you are using UBUNTU
or, to ~/.bash_profile if you are using MAC
If that file does not exists, create it.
alias lprc='vim -me -c ":syntax on" -c ":hardcopy" -c ":q"'
source ~/.bashrc or source ~/.bash_profile
To print colored hello.py just do this:
lprc hello.py instead of lpr hello.py
Use ConTEXT programming editor (which is free). I am using it for both generating .pdf-s with syntax highlighted source code and printing to paper.
There are many ConTEXT syntax highlihting definitions to download and you can make your own highligher file which will BTW be highlighted using the ConTEXT Highlighter Files highlighter definition.
I do it downloading js and css files from
https://prismjs.com/
There are so many 5-7 options to select the theme and language highlighter. Once you select a theme and download the tiny js/css files the next thing you need to do is rename the code file to html, and call the css/js files. Open the html in a browser and print it. Done!
You can also use this in case you've to print with bnw syntax highlighting https://github.com/SGI-CAPP-AT2/code-highlight-n-print

Resources