this page is updated for Manual 2. It needs to be verified! once you have verified this page (and corrected if necessary) please modify the status to v (verified), i.e. st=v (see Guidelines for Writing this Manual)
The snippets plugin allows you to record reusable pieces of code. There are two categories of snippets:
- insert strings
- search and replace patterns
Snippets are organized in branches.
- Bluefish 1.3 users
- you can copy your old snippets to Bluefish 2
$ cp ~/.bluefish-unstable/snippets ~/.bluefish/
- Bluefish 1.0 users
- to import your Bluefish 1 Custom menu in snippets you can use Olivier's python script convert_custom_menu_to_snippets.py.
- put convert_custom_menu_to_snippets.py in ~/.bluefish/ directory
- make the script executable: $ chmod a+x convert_custom_menu_to_snippets.py
- run the script: $ ./convert_custom_menu_to_snippets.py > mysnippets.xml
- import mysnippets.xml in your snippets plugin.
- You also can find useful snippets in Snippets repository
- or h ave a look at Tutorial: Creating a Custom Command using a Bluefish Snippet.
The first time you open Bluefish 2 you have default snippets. You can create new snippets, or import a set of snippets. Right click in the snippets area open the snippets menu.
There are two kinds of snippets, insert snippets and replace snippets.
Snippets are organized in branches (chapters) and possibly sub-branches. In mediawiki branch there is a sub-branche called man bf where are usefull snippets to edit Bluefish manual. The title of the snippet gives an idea of what it does. By moving the mouse over the title of the snippet appears a tooltip giving details.
By double-clicking a snippet item the code is inserted at the cursor position in the edit area.
We place the cursor in edit area under the line === Snippets usage === to insert a framed image
This snippet use 2 parameters, double-clicking opens a dialog box.
Here is the result:
The before text is inserted before the cursor in edit area, the cursor is now after the text inserted by the snippet.
Some snippets make replace in a selected text. Select text before use them!
- you can export:
- a branch
- a single snippet
- to export your entire snippets file just copy ~/.bluefish/snippets to mysnippets.xml
- to export a selection of branches, you have to create a new branch, move wanted branches into it and export the new branch.
All snippets should be placed in a branch. If your snippets file is empty, the first thing to create is the first branch.
To insert a snippet, choose a branch, right click on its name to open the snippets menu. In this example we add a snippet in mediawiki(en) branch:
Here we use two variables, one for the name of the image, the other for the text under the image.
Please use %% if you need literal % in your string! eg: use style="width:20%%"<tt> to have style="width:20%"
Is File path
The new snippet take place at the end of its branch. You can move it using drag and drop. You can also re-edit it or delete it.
In this other example we use a snippet that use both before and after text.
first we select text in edit area, then we double click on the includeonly snippet.
The before text is inserted before the cursor or the selection. The after text is inserted after the cursor or the selection.
Search and replace snippets
Search and replace snippets are very powerfull. See Basic Find and Replace and Find and Replace Using Regular Expressions for general infos about Bluefish find and replace. Here will be considered only on the specific substitutions in the snippets.
Right click on an item open the snippets menu, Edit snippet. If the item is a branch use also Edit snippet to change its name.
If the item is a snippet we can re-edit it, firt name and description, and in second step before and after text and parameter(s) name(s).
Use drag and drop to reorder snippets. You can reorder single snippet or branches. To create a new top level branch you have to right-click on the empty part at the end of the snippets pannel. (actually bug: if you have too many snippets for the height of the window, there is no empty line at the end of the snippets list.)
When a mouse is over the snippet pannel typing a letter select the first entry (from the top) witch name begin with this letter.
e.g. if you have to entries, bbcode and bash, typing b select bbcode, typing ba select bash. This works only with item that are visibles not for items that are in collapsed branches.
Set snippet accelerator
Select a snippet item, right click to open the menu, choose Set snippet accelerator.
For example if you type Ctrl + f for framed image, you can now open the frame image snippet dialog by typing Ctrl + f when mouse is over the snippet pannel, even if the mediawiki branch is collapsed.
You can delete a snippet and also a branch with all its sub-branches and snippets in one click. Be aware that there is no undo method.
You can have snippets as a top bar. Be aware that if you have to many top level entries in snippets for the width of your window, the last top level entries are not displayed in snippets top bar.
see Snippets syntax