Getting Started with Text Editors on OpenBSD

Updated on November 21, 2023
Getting Started with Text Editors on OpenBSD header image

A terminal-based text editor is an essential kit for server management, it makes code editing, configuration file editing, creating and saving files easy. By default, most Unix systems including OpenBSD are preinstalled with vi as the default text editor, but with the advancement in code stacks, newer text editors such as Vim, Nano, Emacs, offer better features, editing, and support for multiple file types.

In this article, you will learn how to install and use common text editors on OpenBSD.

Prerequisites

Nano

Nano is a popular, beginner-friendly, and easy to use text editor, it uses a control +standard where you must press a corresponding key to perform a specific function.

  • ^G Get Help
  • ^O WriteOut
  • ^R Read File
  • ^Y Prev Page
  • ^K Cut Text
  • ^C Cur Pos
  • ^X Exit
  • ^J Justify
  • ^W Where Is
  • ^V Next Page
  • ^U UnCut Text
  • ^T To Spell

Install Nano.

# pkg_add nano

Use Nano

Start Nano.

# nano

Enter some text in the editor.

Then, press Control + O (Write Out), enter a filename to save the file, and press Enter.

File Name to Write:

To exit Nano, press Control + X.

^X Exit

To open an existing file for editing, run nano and the file path. For example, the following command opens the OpenBSD Packet Filter configuration file.

# nano /etc/httpd.conf

Perform a search by pressing Control + W, and enter the string to search.

^W Where Is

For further information on how to use the Nano text editor, simply press Control + G (Get Help).

^G Get Help

Vim

Vim is a straightforward, highly configurable, extendable, and efficient text editor. It is the improved version of the default vi text editor with advanced features and commands.

Install VIM

# pkg_add vim

Use VIM

VIM offers multiple usage modes, normal, insert, visual and command modes. By default, Vim starts in normal mode. Start it with the following command:

# vim

Enter insert mode by pressing i on your keyboard.

Enter some text in the editor. Then, press escape esc on your keyboard to switch back to normal mode.

esc 

Now, enter a colon : to switch to command mode. Then, add w to save your file.

:w

Exit Vim by entering q in command mode.

:q

For more information on how to use Vim, enter help in command mode.

:help

Emacs

GNU Emacs is one of the most versatile text editors, supports multiple file types, code syntax highlighting, and highly extensible with a large collection of available modules. However, it’s an advanced editor, and not beginner-friendly.

Install Emacs

#pkg_add emacs

Select option 3 (no_x11) to install the terminal version.

Ambiguous: choose package for emacs
a   0: <None>
    1: emacs-27.2p3-gtk2
    2: emacs-27.2p3-gtk3
    3: emacs-27.2p3-no_x11
Your choice:

To start emacs, use the following command.

# emacs 

For more information on how to use emacs, refer to the official documentation.

NeoVIM

NeoVim is a fork of Vim that adds more extensibility, and uses the same modes, commands as Vim. To install NeoVIM, use the following command:

# pkg_add neovim

Start NeoVIM

# nvim

Enter insert mode i to create a simple file, and save with wq in command mode.

:wq

To migrate Vim configurations to NeoVim, simply create a symlink between the two configuration file directories.

For further information on how to use NeoVim, refer to the official documentation.

Micro

Micro is a text editor that is designed to be easy and offers standard key bindings using the Control (Ctrl) key. It offers syntax highlighting, multiple cursors in a file, and highly extensible with plugins.

To install Micro, use the following command:

# pkg_add micro

Start Micro

# micro 

Enter text in the editor, and save your file with Control + S. To undo changes to the file, press Control + Z on the keyboard, and press Control + q to exit the editor.

  • Ctrl + S: Save
  • Ctrl + Z: Undo last action
  • Ctrl + q: Quit the editor

Conclusion

There is no limitation on the number of text editors you can run on your OpenBSD server. However, depending on your experience with any of the text editors listed in this article, you can create, edit and modify files through your server terminal.

To open files with any of the text editors, simply start the editor with the file path as an argument, for example:

  • micro /etc/httpd.conf
  • nvim /etc/httpd.conf
  • emacs /etc/httpd.conf
  • nano /etc/httpd.conf
  • vim /etc/httpd.conf