Using php code in Scrivener

Hi

I decided to create files and folders in Scrivener with my various WordPress tutorial projects which I will gradually add to my web site.
I copy php code from a web page and paste it into a WordPress functions file and test it out. It works fine.
I copy the php code into a new file in Scrivener and then copy it from Scrivener into the WordPress functions file and it does not work.

How do I add clean formated code into Scrivener and still have it clean formated inside Scrivener?
(As code is one part of the tutorials that I write.)

Thank you!

Paal Joachim

I can’t say for sure if this is the problem, since your literal description of events wouldn’t cause this to happen, but do be aware that since Scrivener is out of the box set up for regular writing, it will use typographic punctuation, which is of course invalid syntax, in a context such as the following:

$this = “Nope!”;

That problem always gets me in OmniFocus, where I like to paste code snippets and invariably edit them in its notes fields. Fortunately with Scrivener you can switch that capability off in the Corrections preference pane, though. Highly recommended if you use Scrivener to store code.

Hey Amber

Thank you for your tips!

I turned off Preferences -> Corrections
Use smart quotes and everything else in the Substitutions area.

I also noticed I had to right click in Scrivener and paste and match style using the existing style of the document I pasted the code into. Then I could take the code and use it elsewhere and it then worked. If I just did a copy and paste of the code into the document then the code would not work. Kinda tricky…

Perhaps there could be a smart paste feature taking the raw copy and pasting it raw into the document. Pasting it using existing style it would then use the style that is already in the document.

I can’t think of why that would happen. Rulers and fonts and highlights have no bearing at all on the bytes of the text itself when pasted into a plain-text window. Perhaps the target window is not strictly speaking a plain-text area? I would examine the before/after text in a coding editor with invisible characters enabled, to see precisely what is going on.

The Edit/Paste and Match Style menu command already has a standard keyboard shortcut (the same used by nearly all Mac software that supports rich text). But if you prefer Paste act otherwise all of the time, you can change the PaMS shortcut to Cmd-V and put regular paste on the Shift-Opt-Cmd-V shortcut. (In case you need it: custom shortcuts.)

Thank you for the feedback!

Sometimes I will paste something in and the style is then included. It would be nice to easily remove/adjust and have some more control over it.

Right, when I accidentally paste formatting like that I just hit Cmd-Z to Undo the paste and then follow up with the Paste and Match Style shortcut. But you should also be aware of a feature that will strip all formatting from the current text editor and reset it to whatever your default settings are. You can read more about that in this article.