3. Working with files and folders

3.1. Creating files
3.2. Managing directories
3.3. Opening files
3.4. Saving files
3.5. Renaming files
3.6. Deleting files
3.7. Closing files
3.8. Inserting files
3.9. Editing
3.9.1. Undo and Redo
3.9.2. Cut, Copy, and Paste
3.9.3. Input methods
3.10. Basic Find and Replace
3.10.1. Searching for a word within a whole document
3.10.2. Setting limits to the search scope
3.10.3. Case sensitive search
3.10.4. Overlapping searches
3.10.5. Retrieving previous search strings
3.10.6. More on find
3.10.7. Replacing features
3.10.8. Retrieving previous replace strings
3.10.9. Changing letter case when replacing
3.10.10. Choosing strings to replace
3.10.11. More on replace
3.11. File types
3.11.1. Syntax highlighting
3.12. More on files
3.12.1. Remote files
3.12.2. Character encoding
3.12.3. Open advanced

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.

You may also insert a file into another one, and revert a modified file to its previously saved state.

Figure III.12. Bluefish File Menu

A screen shot of the Bluefish File Menu

You may also add directories, delete files, and refresh the file browser in the side panel using its contextual menu.

Figure III.13. The file browser contextual menu

A screen shot showing the file browser contextual menu

3.1. Creating files

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

Those methods create an untitled file of type text with default permissions and the default character encoding defined in the Files tab in the EditPreferences menu option. You will further have to save it under the desired name.

To spare yourself the bother of saving, right click on the desired directory in the directory list of the file browser in the side panel and select New File. You will be presented with a File name dialog, where you will enter the desired name:

Figure III.14. The File name dialog

A screen shot showing the File name dialog

3.2. Managing directories

To create a new directory, right click on the desired parent directory in the directory list of the file browser in the side panel and select New Directory.

Then enter the desired name in the Directory name dialog. Bluefish will create the named directory with the default permissions.

Note that you cannot delete directories within Bluefish, but you can refresh the view with the Refresh contextual menu item of the file browser. This is especially useful when you add files and directories or delete files.

3.3. Opening files

Through FileOpen... (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 FileNew Window to first open the new window and then open the desired files as usual.

Figure III.15. 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 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 EditPreferences menu option.

Recently opened files can be opened by selecting them from the list within FileOpen 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 III.16. 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 Section 6.11, “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 III.17. 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 FileOpen 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.

3.4. 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 III.18. 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 file systems 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 III.19. 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 FileSave 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.

3.5. Renaming files

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

Figure III.20. Moving a file to another location

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

3.6. Deleting files

To delete a file, right click on it in the file browser within the side panel. You will be asked either to confirm the deletion or to cancel the process, if you have the right permissions for it.

[Warning]

Be cautious with this feature, there is no easy way to recover the deleted file.

3.7. 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 FileClose (Ctrl-W) menu item.

Figure III.21. 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 III.22. 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 FileClose 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 III.23. 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 FileClose Window menu item offers the same behaviour.

3.8. Inserting files

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

For more in-depth information about dealing with files, see Section 3.12, “More on files”.

3.9. Editing

3.9.1. 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.

3.9.2. 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.

3.9.3. Input methods

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

Figure III.24. 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 III.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 III.25. 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.

3.10. 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 Section 4.5, “Find and Replace”.

3.10.1. Searching for a word within a whole document

Choose the EditFind... (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 III.26. 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 III.27. 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 III.28. 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 EditFind again (Ctrl-G) menu item. If no further occurrence is found, a dialog will be displayed notifying you that no match was found.

3.10.2. 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 III.2. Searching from selection

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

    Figure III.29. 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 III.30. 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 III.31. 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.

3.10.3. 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 III.32. 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 III.33. 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.

3.10.4. 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 III.34. 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 III.35. An overlapping string retrieved with the Find dialog

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

3.10.5. 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 III.36. Retrieving recent searches

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

3.10.6. More on find

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

You will find details on Find Again and Find from Selection in Section 4.5, “Find and Replace”.

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

3.10.7. Replacing features

The EditReplace... (Ctrl-H) menu item works the same way and has all the features, the EditFind... (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 Section 3.10.1, “Searching for a word within a whole document”.

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

Figure III.37. The Replace dialog

A screen shot showing the replace dialog

3.10.8. 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.

3.10.9. 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 III.38. 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.

3.10.10. 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 III.39. 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.

3.10.11. More on replace

For further explanation on replace features within Bluefish, see Section 4.5, “Find and Replace”.

3.11. 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 DocumentDocument Type menu. See Section 6, “Customising Bluefish” to change these extensions.

3.11.1. 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 DocumentUpdate 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.

3.12. More on files

3.12.1. Remote files

Assuming a working Internet connection, files can also be opened from the web using FileOpen 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 III.40. 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 FileOpen URL menu.

Figure III.41. A style sheet opened via the Open URL menu

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

3.12.2. 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 Section 3.9.3, “Input methods”.

3.12.3. Open advanced

You can open multiple files at once with the FileOpen 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 III.42. Using the Open Advanced dialog

A screen shot showing the usage of the Open Advanced dialog