![]() |
VOOZH | about |
This document is a step by step guide to edit a configuration file.
All the time.
Configuration files are the default method to configure most software. Use a text editor to edit them. The default text editor in Gentoo is nano.
Different text editors may be used on the command line to edit configuration files. Nano will be installed by default on a new Gentoo installation, but it is ultimately up to the user what editor to install and use. See the text editor article for details on selecting and installing a text editor.
Nano will probably be the most accessible editor for beginners, because it behaves a little like many GUI editors, and provides a help bar at the bottom of the screen by default.
The sudo command may be needed to edit system configuration files owned by root.
user $cp <filename> <filename>.bak-$(date +%FT%T)Start Emacs by typing emacs in the terminal, followed by file path and name:
user $emacs <filename>Move around with the arrow keys, insert text freely. To save a file, type (+ followed by +).
To close Emacs, type (+ followed by +).
For "quick-start" documentation directly in Emacs, type: (+ followed by ). For further help on how to use Emacs, type (+ followed by ).
For more information online:
Start Nano by typing nano in the terminal, followed by file path and name:
user $nano <filename>-w option. Without this option, long lines are wrapped by inserting newlines - this will often break configuration files.Nano now shows the content of the text file. Navigate through the text with the arrow keys and make edits as desired.
At the bottom, Nano shows shortcuts for common actions (save, exit, etc.). The shortcut to save a file is shown as "^O". Users must prefix the shortcut with the key, so to save a file press +. Nano will create the file upon saving, if no file with the given path exists yet.
To exit press +.
sed can be used for more complex edits and scripted changes. As an example, the following command would remove all lines containing the string foobar from /etc/portage/package.accept_keywords:
root #sed -e '/foobar/d' -i /etc/portage/package.accept_keywordsStart Vim by typing vim in the terminal, followed by file path and name (using the vi command should also be possible):
user $vim <filename>Vim will create the file upon saving, if no such file exists yet.
Vim is a modal editor, it will start in command mode, and can be switched between this and insert mode. Use , , , (by default) to move the cursor in command mode. Enter insert mode, to enter text, by pressing , and return to command mode by pressing . Save by opening the Vim command line, by pressing , then , . Quit with , , . Add after to quit without saving changes.
See Vim/Guide for more instructions on using Vim. See vi about vi-like editors. Of course, check out the Vim article.