Working with files

Most of the file operations are accessible from the File menu. Using this menu, a new file can be created, existing files opened, and opened files saved or renamed.

It is also possible to insert a file into another one, and to revert a modified file to its previously saved state.

Figure 3.12. Bluefish File Menu

A screen shot of the Bluefish File Menu

Creating files

Apart from using File->New (Ctrl-N) or the New icon to create a new file, you may also use File->New Window (Shift-Ctrl-N).

Both methods create an untitled file of type text with the default character encoding defined in the Files tab in the Edit->Preferences menu option.

Opening files

Through File->Open... (Ctrl-O), one or more files can be opened. When creating new files, you may want to open the files in a new window. In this case, use File->New Window to first open the new window and then open the desired files as usual.

Figure 3.13. Bluefish Open File Dialog

A screen shot of the Open File Dialog
Note

The most recently opened directories appear in the upper part of the left side panel, while the lower part contains user-defined locations. To add a new directory to the list, click on Add. You can also filter the file list by file type using the pop menu located on the right side. The list of file types in the filter menu is provided through the Filetypes tab found in Bluefish's Edit->Preferences menu option.

Recently opened files can be opened by selecting them from the list within File->Open recent. The number of files in this menu can be set in the preferences under Files.

The file browser in the side panel can also be used to open files. It supports filtering files, by right clicking the contextual menu in the file browser.

Figure 3.14. Filtering Files with the Bluefish File Browser

A screen shot showing how to filter files with the Bluefish file browser

The available filters may be modified in Preferences. For more information, see the section called “Modifying the files filters”.

If you right click a directory, you can make this directory the base directory for the file browser using the Set as basedir option. Then you can access it directly from the pop up menu in the upper part of the file browser.

By default the file browser follows the document focus. If you change to a different document, the file browser will show the contents of the directory where this document is located. This behaviour can be changed on the bottom of the file browser.

Information about currently opened files can be seen if you move the mouse over the document tab (by default on the bottom of the screen). A so called tool tip will be shown with information about the full path, size, permissions, file type and encoding of the file.

Figure 3.15. Info on open file with the Bluefish File Browser

A screen shot showing Info on open file with the Bluefish file browser

An interesting feature of Bluefish is the ability to open files by selecting the text of a currently opened file. For example, if a filename is shown in say a terminal application, you can select the filename, and use File->Open from Selection to open that file. The file, if it exists, will be opened in another tab within Bluefish.

Finally, files can be opened via the command line by feeding filenames to Bluefish as arguments. This can even be done while Bluefish is running and the resulting file will then show up in its own tab.

Files can also be opened by clicking on the Open... icon in the main tool bar.

Note

If you have installed gnome-vfs or gnome-vfs2 before installing Bluefish, you will be able to open files on remote desktop.

Be aware that if the file is huge it may take a very long time to get the rendering if syntax highlighting is enabled. The GTK editing widget used in Bluefish, furthermore, is not very good at handling files with very long lines, and that could also slow down Bluefish considerably.

Saving files

If a document is modified, the filename is shown in red in the document tabs, and also if you right click on the tabs, the full path is shown in red in the list that will pop up.

Figure 3.16. Tool Tip for Modified File

A screen shot showing the tool tip for modified file

To save a document, you can use the File menu, the Save icon in the tool bar, or press the shortcut key combination Ctrl-S. By default a backup is made during save. The original file is copied to the same filename with a tilde ~ appended. This suffix and the backup behaviour can be changed in the preferences under Files.

Before saving the file, Bluefish will check if the original file was changed on disk, using the last modified time and the file size. On some filesystems the last modified time is sometimes not very precise (most notably on samba mounts). This makes Bluefish think the file is modified when it is not. This check can be changed in the preferences under Files.

You can also save a document under a different name, using the Save As... (Shift-Ctrl-S) menu entry, or the Save As... icon in the main tool bar. The original file will still exist.

Figure 3.17. Saving a File under a new Name

A screen shot showing how to save a file under a new name

To save all modified files, you can use the File->Save All menu entry. This will save all documents that have been modified and present you with a save dialog if some files are new files.

Renaming files

It is also possible to move or rename a document, using the File->Rename... (F2) menu item, or right-clicking the file name in the side panel and choosing the Rename item.

Figure 3.18. Moving a file to another location

A screen shot showing how to move a file to another location

Closing files

When you want to close a file quickly, click on the close icon in the document tab. You may also use the Close icon in the main tool bar, or the File->Close (Ctrl-W) menu item.

Figure 3.19. Closing a file with the document tab icon

A screen shot of the close icon in the document tab

If the file is unchanged, it is merely closed. If the file has been modified, you will be presented with a save dialog.

Figure 3.20. Closing a modified file

A screen shot showing how to close a modified file
Tip

Use it to save and close a file in one step.

When dealing with multiple files, you may want to use the File->Close All (Shift-Ctrl-W) menu item.

For each modified file, you will be presented with a save dialog, where you can choose to save the changes, close the file (i.e. discarding any change), or cancel the operation.

Figure 3.21. Closing all files

A screen shot showing how to close all files
Tip

Say you have a number of open files, and only a few of them have been changed. To quickly close the unchanged files, and remain with the modified ones, use it answering cancel for the latter ones.

Note that the File->Close Window menu item offers the same behaviour.

Inserting files

You can insert any file into the current document with the File->Insert... menu item. The file will be inserted at the cursor location.

For more in-depth information about dealing with files, see the section called “More on files”.

Editing

Undo and Redo

The undo and redo functionalities are available from the Edit menu, the main tool bar, and the keyboard shortcuts.

  • Undo (Ctrl-Z)

  • Redo (Shift-Ctrl-Z)

The functions Undo All and Redo All in the Edit menu will undo or redo all of the stored changes. The maximum number of changes can be configured in the preferences, by default Bluefish will remember the last 100 changes per document. It is possible to clear the changes after the document is saved, an option in the preferences which is disabled by default.

Cut, Copy, and Paste

The functions Cut, Copy, and Paste are available from the Edit menu, the main tool bar, and the keyboard shortcuts.

  • Cut (Ctrl-X)

  • Copy (Ctrl-C)

  • Paste (Ctrl-V)

On X Windows Systems, you can also paste the current selected text using the middle mouse button. First select some text (in Bluefish or in any other X application), then press the middle mouse button where you want to paste the selected text.

Cut or copy and then paste can also be done by selecting some text and dragging it to the destination. If the text is dragged to another document (or another application), it is copied. If the text is dragged within one document it is moved. Dragging highlighted text from one application to another may or may not work. However, most GNOME and GTK programs support this feature.

Input methods

Bluefish handles a number of input methods, available from the contextual menu within a given document.

Figure 3.22. The Input Methods Contextual menu

A screen shot showing the input methods contextual menu
  • The default mode switches all input methods off.

  • The Amharic mode is used for the most popular Ethiopian language.

  • The Cedilla mode is used for languages such as French, which uses the cedilla.

  • The Cyrillic mode is used to enter Russian with Roman letters. The transliteration occurs immediately.

  • The Inukitut mode works the same as Cyrillic mode.

  • The IPA mode is used for International phonetic alphabet.

  • Other modes are used for Erythrean, Ethiopian, Thai and Vietnamese languages.

The X Input method relies on a client-server input system, and an input server.

For Japanese, Chinese, and Korean documents, you may have to install and launch the correct input system, such as canna, and the appropriate input server, such as kinput2.

Here is how to write a Japanese document on a non-Japanese system.

Procedure 3.1. Writing in Japanese with Bluefish on a non-Japanese system

  1. Launch the canna server if it is not running already

  2. Set the encoding to Japanese, for example: export LANG=ja_JP.UTF-8

  3. Set the Xinput method with export XMODIFIERS="@im=kinput2"

  4. Launch kinput2 as a background process with kinput2 &

  5. Launch bluefish as a background process with bluefish &

  6. To activate the Xinput method within bluefish, use Shift-Space. A small window with a Japanese glyph will appear at one of the corner of the Bluefish window. Once the desired glyph has been composed, press Space, and hit enter to validate it.

Here, you can see the small Xinput method window, at the bottom left corner of the window and the first Japanese word not already validated in the Bluefish window launched on a French system.

Figure 3.23. Writing in Japanese with Bluefish

A screen shot showing how to write in Japanese with Bluefish

For an in-depth discussion on that subject, see Inputting from the keyboard.

Basic Find and Replace

Bluefish offers a wide range of find and replace methods in the Edit menu, also available through the contextual menu within a document. Here we will explore the most basic ones. For advanced find and replace methods, see the section called “Find and Replace”.

Searching for a word within a whole document

Choose the Edit->Find... (Ctrl-F) menu item. A Find dialog will be displayed. Enter the word to search for in the Search for: field. Then click OK.

Figure 3.24. Finding a word in a document, from start to end

A screen shot showing how to search a string within a document, from start to end.

If the word does not exist in the document, a small window pops up.

Figure 3.25. Unsuccessful search window

A screen shot showing the unsuccessful search window.

If the search is successful, the document window scrolls up to the first occurrence of the string in the document and highlights it.

Below is an example of a search applied to a shell script.

Figure 3.26. Highlighted search result in the document window

A screen shot showing the search result highlighted in the document window.

To find a subsequent occurrence of the string, use the Edit->Find again (Ctrl-G) menu item. If no further occurrence is found, a dialog will be displayed notifying you that no match was found.

Setting limits to the search scope

You may want to search for a string from the cursor location till the end of the document. Here is an example to search all name == occurrences within a python script from a given location.

Procedure 3.2. Searching from selection

  1. Put the cursor where you want to start the search from in the document window

    Figure 3.27. Setting the cursor location

    A screen shot showing how to set the cursor location for a limited search.
  2. Open the Find... dialog

  3. Enter your search string in the Search for: field

  4. Choose Current position till end from the Starts at: pop up menu

    Figure 3.28. Choosing a limited search method

    A screen shot showing how to search from the cursor's location.
  5. Click OK.

Here is the result:

Figure 3.29. Limited search result

A screen shot showing the result of a limited search.

Notice that the search does not take into account the occurrence of the same string at line 50, since it is outside the search scope.

You can also limit the search scope to a selection range. In that case, highlight the selection before the search, and choose Beginning of selection till end of selection from the Starts at: pop up menu in the Find dialog.

Case sensitive search

By default, the search process is case insensitive. If you want to make it case sensitive, just check the Match case box in the Find dialog.

Figure 3.30. Making the search case sensitive

A screen shot showing how to make the search case sensitive

Here is the result applied to a ruby script:

Figure 3.31. Case sensitive search result

A screen shot showing a case sensitive search

Notice again that the result does not catch the XML string at line 45, since the search string was xml and case sensitive search was requested.

Overlapping searches

It may occur that the document contains some kind of palindrome you want to search for. The "normal" find process does not retrieve all occurrences of that kind of string.

In this case, you have to check the Overlap searches box in the Find dialog to retrieve all occurences of the string.

Figure 3.32. Finding overlapping strings

A screen shot showing how to find overlapping strings

Applied to a shell script, the second search (with Ctrl-F, then Ctrl-G) will give the following result:

Figure 3.33. An overlapping string retrieved with the Find dialog

A screen shot showing an overlapping string retrieved by the Find process

Retrieving previous search strings

Notice that the pop up menu to the right of the Search for field in the Find dialog allows you to retrieve previous search strings. They are listed in reverse order by search history, providing quicker access to the most recent searches.

Figure 3.34. Retrieving recent searches

A screen shot showing the search for pop up menu to retrieve recent search string

More on find

For an explanation of the Bookmark results box of the Find dialog, see the section called “Generating several bookmarks at once”.

You will find details on Find Again and Find from Selection in the section called “Find and Replace”.

For a quick way of switching from HTML entities to other types of encoding and changing letter cases, see the section called “Special find an replace features”.

Replacing features

The Edit->Replace... (Ctrl-H) menu item works the same way and has all the features, the Edit->Find... (Ctrl-F) menu item offers.

The Replace dialog is also accessible through the contextual menu within a document.

For the features common to the Find dialog, see the section called “Searching for a word within a whole document”.

Here we will explain the features unique to the Replace dialog.

Figure 3.35. The Replace dialog

A screen shot showing the replace dialog

Retrieving previous replace strings

As for the Search for field's pop up menu, the Replace with field's pop up menu allows you to retrieve previous strings used for replace, the most recent ones being at the top of the list.

Changing letter case when replacing

If you want to change letter case when replacing, use the Replace type pop up menu.

The default choice is Normal, that is the case is not changed.

With the Uppercase replace type, the search string will be replaced with its uppercase translation.

Likewise, with the Lowercase replace type, the search string will be replaced with its lowercase translation.

Figure 3.36. Changing letter case when replacing

A screen shot showing how to change letter case when replacing

Notice that in this case, the Replace with field is deactivated, thus not taken into account even if you have entered some string in it.

Choosing strings to replace

It may occur that you do not want to replace all search strings retrieved by the search process, but only some of them. In this case, check the Prompt before replace box. A Confirm replace dialog will appear for each retrieved string where you can choose to Skip this string, i.e. leave it as it is, Replace it, Replace all strings within the search scope, or Close the dialog, i.e. cancel the process.

Figure 3.37. The Replace confirm dialog

A screen shot showing the replace confirm dialog

If you want to replace only the first occurrence of a search string, check the Replace once box instead.

More on replace

For further explanation on replace features within Bluefish, see the section called “Find and Replace”.

File types

Different file types can change the behaviour of Bluefish. File types are recognized by their extension, or by the beginning of the file's contents. The current document type is shown in the far right of the status bar. If the type of a file is not properly detected, you can change the type using the Document->Document Type menu. See the section called “Customising Bluefish” to change these extensions.

Syntax highlighting

Syntax highlighting is the coloring of words that have special meaning for a language. The patterns can vary: for example, "<title>" means "start of title" in HTML, "function" means "start of function" in PHP.

While editing, Bluefish will only update the highlighting patterns in the block of text around the cursor. The number of lines (the size) of this block can be adjusted in the preferences under Editor. The syntax highlighting for the total document can be refreshed using the Document->Update Highlighting (F5) menu. It can be disabled in the preferences under Editor. For more information about adding or modifying syntax highlighting for existent or new languages, see here.

More on files

Remote files

Assuming a working Internet connection, files can also be opened from the web using File->Open URL. This feature depends on your gnome_vfs setup. If it is installed and working, http://, sftp://, smb:// and possibly more types of remote services should be supported by Bluefish. Depending on your gnome_vfs version, some of these protocols are not yet fully stable, which can crash Bluefish!

Figure 3.38. Opening an URL from the web

A screen shot showing how to open an URL from the web

Here you can see the style sheet of an Apache web site, nicely highlighted after its opening via the Bluefish File->Open URL menu.

Figure 3.39. A style sheet opened via the Open URL menu

A screen shot of a style sheet opened via the Open URL menu

Character encoding

There are many different standards for character encoding of text files. Most well known is the ASCII standard, which describes only 127 characters, and is supported by every text editor in the world. The most common standard nowadays is UTF-8, which describes thousands of characters, and is backwards compatible with ASCII.

Internally, Bluefish will always work with UTF-8. When opening a file, Bluefish has to detect the correct encoding for the file. For HTML files, the encoding should be present in a <meta name="encoding"> tag. Bluefish will always use this tag if it is available in the file. If this tag has an encoding that is not present in the Bluefish config file, this encoding is automatically added to the Bluefish config file.

The locale also defines a default encoding. If you are using a locale (a local setting, defining language, time format, currency format, number formatting etc.), Bluefish will try to load the file using the encoding defined in the locale.

Bluefish itself also has a setting for a default encoding. This is the next encoding Bluefish will try. This is also the encoding Bluefish will use for files created by Bluefish (UTF-8 by default).

If these steps fail, Bluefish will simply try every encoding defined in the Bluefish config file.

Filenames on disk can also contain non ASCII characters. All GNOME and GTK programs (including Bluefish) assume that filenames are in UTF-8 encoding. If you have filenames in the encoding of your locale on your disk, you have to set G_BROKEN_FILENAMES=1 in the environment to make GNOME and GTK programs detect this encoding.

For information about writing documents in 16-bits encoded languages, such as Japanese, see the section called “Input methods”.

Open advanced

You can open multiple files at once with the File->Open Advanced... (Shift-Ctrl-O) menu item from a directory based on their extension or their contents. The same functionality is available from the file browser in the side panel by right-clicking a directory. This feature is available only when the find and grep utilities are installed on your system.

To open all files by extension, enter the extension in the dialog, and leave the search pattern empty. Check the recursive option if you want to include all subdirectories in the search. To open files by content, leave the extension at *, and enter a search pattern in the dialog. You can use regular expression patterns if you check the Is regex option.

You may also combine both methods. Here we open recursively all Chinese XML files in a given tree, whose contents contain the word packaging.

Figure 3.40. Using the Open Advanced dialog

A screen shot showing the usage of the Open Advanced dialog