How To Edit Text Files Using gEdit

The gEdit Text Editor
The gEdit Text Editor.

Introduction

gEdit is a Linux text editor commonly deployed as part of the GNOME desktop environment.

Most Linux guides and tutorials will get you to use the nano editor or vi to edit text files and configuration files and the reason for this is that nano and vi are almost guaranteed to be installed as part of the Linux operating system.

The gEdit editor is much easier to use than nano and vi however and works in much the same way as the Microsoft Windows Notepad.

How To Start gEdit

If you are running a distribution with the GNOME desktop environment press the super key (key with the Windows logo on it, next to the ALT key).

Type "Edit" into the search bar and an icon for "Text Editor" will appear. Click on this icon.

You can also open files within gEdit in the following way:

  • Open the Nautilus file manager
  • Navigate to the folder with the file you wish to open
  • Right click on the file.
  • If there is an option to "open with text editor" click on this link otherwise click "open with other application" and choose the "text editor" option.

Finally you can also edit files in gEdit from the command line. Simply open a terminal and type the following command:

gedit

To open a specific file you can specify the filename after the gedit command as follows:

gedit /path/to/file

It is better to run the gedit command as a background command so that the cursor returns to the terminal after you have executed the command to open it.

In order to run a program in the background you add the ampersand symbol as follows:

gedit &

The gEdit User Interface

The gEdit user interface contains a single toolbar at the top with a panel for entering text below it.

The toolbar contains the following items:

  • Open
  • Add a tab
  • Save
  • Options
  • Minimise
  • Maximise
  • Close

    Clicking on the "open" menu icon pulls up a window with a search bar for searching for documents, a list of recently accessed documents and a button called "other documents".

    When you click on the "other documents" button a file dialog will appear where you can search through the directory structure for the file you wish to open.

    There is a plus symbol (+) next to the "open" menu. When you click on this symbol a new tab is added. This means you can edit multiple documents at the same time.

    The "save" icon displays the file dialog and you can choose where in the file system to save the file. You can also choose the character encoding and the file type.

    There is a "options" icon denoted by three vertical dots. When clicked this brings up a new menu with the following options:

    • Refresh
    • Print
    • Full screen
    • Save As
    • Save All
    • Find
    • Find and Replace
    • Clear Highlight
    • Go to line
    • View -> Side Panel
    • View -> Highlight Mode
    • Tools -> Check spelling
    • Tools -> Set Language
    • Tools -> Highlight misspelled words
    • Tools -> Insert date and time
    • Tools -> Statistics
    • Preferences
    • Help
    • About
    • Close All
    • Close
    • Quit

    The other three icons let you minimise, maximise or close the editor.

    Refresh The Document

    The "refresh" icon can be found on the "options" menu.

     

    It will not be enabled unless the document you are editing has changed since you first loaded it.

    If a file changes after you have loaded it a message will appear on the screen asking you whether you wish to reload it.

    Print A Document

    The "print" icon on the "options" menu brings up the print settings screen and you can choose to print the document to a file or printer.

    Display A Document Full Screen

    The "full screen" icon on the "options" menu displays the gEdit window as a full screen window and hides the toolbar.

    You can turn off full screen mode by hovering your mouse over the top of the window and clicking the full screen icon again on the menu.

    Save Documents

    The "save as" menu item on the "options" menu shows the file save dialog and you can choose where to save the file.

    The "Save All" menu item saves all the files open on all the tabs.

    Searching For Text

    The "find" menu item can be found on the "options" menu. 

    Clicking the "find" menu item brings up a search bar. You can enter the text to search for and choose the direction to search (up or down the page).

    The "find and replace" menu item brings up a window where you can search for the text to search for and enter the text you wish to replace it with. You can also match by case, search backwards, match entire word only, wrap around and use regular expressions. The options on this screen let you find, replace or replace all matched entries.

    Clear Highlighted Text

    The "clear highlight" menu item can be found on the "options" menu. This clears selected text which has been highlighted using the "find" option.

    Go To A Specific Line

    To go to a specific line click on the "Go To Line" menu item on the "options" menu.

    A small window opens which lets you enter the line number you wish to go to.

    In the event that the line number you enter is longer than the file, the cursor will be moved to the bottom of the document.

    Display A Side Panel

    Under the "options" menu there is a sub menu called "view" and under that there is an option to display or hide the side panel.

    The side panel shows a list of open documents. You can view each document simply by clicking on it.

    Highlight Text

    It is possible to highlight text depending on the type of document you are creating.

    From the "options" menu click on the "view" menu and then "Highlight Mode".

    A list of possible modes appear. For example you will see options for many programming languages including Perl, Python, Java, C, VBScript, Actionscript and many more.

    The text is highlighted using the keywords for the language chosen.

    For example if you chose SQL as the highlight mode then a script might look something like this:

    select * from tablename where x = 1

    Set The Language

    To set the language of the document click on the "options" menu and then from the "tools" sub-menu click on "Set Language".

    You can choose from a number of different languages.

    Check The Spelling

    To spell check a document click on the "options" menu and then from the "tools" menu choose "check spelling".

    When a word has an incorrect spelling a list of suggestions will be displayed. You can choose to ignore, ignore all, change or change all occurrences of the incorrect word.

    There is another option on the "tools" menu called "highlight misspelled words". When checked any incorrectly spelt words will be highlighted.

    Insert The Date And Time

    You can insert the date and time into a document by clicking the "options" menu, followed by the "tools" menu and then by clicking "Insert date and time".

    A window will appear from which you can choose the format for the date and time.

    Get Statistics For Your Document

    Under the "options" menu and then the "tools" sub-menu there is an option called "statistics".

    This shows a new window with the following statistics:

    • Number of lines
    • Number of words
    • Number of characters (with spaces)
    • Number of characters (without spaces)
    • Bytes

    Preferences

    To pull up the preferences click on the "options" menu and then "preferences".

    A window appears with 4 tabs:

    • View
    • Editor
    • Fonts And Colours
    • Plugins

    The view tab lets you choose whether to display line numbers,  a right margin, a status bar, an overview map and/or a grid pattern.

    You can also determine whether word wrap is turned on or off and whether a single word splits over multiple lines.

    There are also options for how highlighting works.

    The editor tab lets you determine how many spaces make up a tab and whether to insert spaces instead of tabs.

    You can also determine how often a file is auto-saved.

    The fonts and colours tab lets you choose the theme used by gEdit as well as the default font family and size.

    Plugins

    There are a number of plugins available for gEdit. 

    On the preferences screen click on the "plugins" tab.

    Some of them are already highlighted but enable others by placing a check in the box. 

    The plugins available are as follows:

    • Document statistics
    • External tools
    • File browser panel
    • Insert date/time
    • Modelines
    • Python console
    • Quick open
    • Snippets
    • Sort
    • Spell Checker