Text Editors
Here we will introduce the basics of 2 text editors, nano and vi, both are already installed on the HPC.
What is a Text Editor and why do I need to use it?
Most configurations of Linux systems and the programs within are done by editing text files. Whether it is a file that configures your bash profile or a script you use that runs a program, being proficient with a text editor will greatly benefit your workflow on the HPC.
nano
Known as one of the most user friendly because of its similarity to none linux text editors. While it is not as powerful as vim (which we will introduce later), it contains the useful functionalities needed in basic editing of text files such as search/replace, copy/paste and so on.
Files can be opened by nano using the command “nano {filename}”. Especially helpful to new users, there is always a list of shortcuts displayed at the bottom of the program viewing window. The “^” is used to designate the “ctrl” key. Most of the commands for nano use “ctrl” or “alt” plus a letter.
Some common ones that you should get familiar with right off the bat are:
ctrl+V Page down
ctrl+Y Page up
alt+\ First page
alt+/ Last page
ctrl+X Exit (Will be prompted to save document and rename it if needed)
ctrl+O Save document
Cheatsheet for GNU nano (nano-editor.org)
Vim
Vim, also known as vi, is a common and powerful text-editor that is a bit less user friendly than nano. Below we will go over some of the most common commands, but if you’d like to go through a Vim tutorial, freeCodeCamp has a free one which you can try.
How to open a file:
vi name_of_file.txt
Common commands:
Command | Explanation |
---|---|
i | insert mode; enables you to edit the document |
<esc> | pressing the <esc> key allows you to exit insert mode (or any other mode) to use other keyboard commands |
gg | navigate to top of the document |
<shift> + G | navigate to bottom of the document |
Y | “yank,” copies an entire line to your clipboard |
P | capital P; pastes that line to where your cursor is |
p | lowercase p; paste on next line below your cursor |
u | undo |
<ctrl> + r | redo |
:q | exit the document, type |
:wq | save and then exit the document, type |
:q! | exit the document without saving, type |
More Advanced Commands
Command | Explanation |
---|---|
<ctrl> + v | visual block mode; enables you to add, edit, copy, paste, and delete columns of text in the document very powerful, and worth a Google search |
:%s/old/new/gc | search and replace; also very powerful and worth a Google search |
A Great Vim Cheat Sheet (vimsheet.com)