LinuxShellSite

General commands (platform-independent)

CommandDescription
vim filenameOpens a file in the Vim editor
Nano File NameOpens a file in the Nano Editor
VI File NameOpens a file in the Vi editor (often an alias for Vim)
vimtutorStarts the Vim tutorial
vim -R filenameOpens a file in Vim in read-only mode
vim +line number filenameOpens a file in the Vim at a specific line
vimdiff file1 file2Compares two files side by side in Vim
export EDITOR=vimSets Vim as the default editor for the current session
export EDITOR=nanoSets Nano as the default editor for the current session

Ubuntu/Debian

Installation and removal

CommandDescription
sudo apt updateUpdates the package lists
sudo apt install vimInstalls the Vim editor
sudo apt install nanoInstall the Nano Editor
sudo apt remove vimUninstalls the Vim editor
sudo apt remove nanoUninstalls Nano Editor
sudo apt install vim-gtk3Installs Vim with GTK3 support (graphic)
sudo apt install vim-athenaInstall the Athena version of Vim
  

Configuration

CommandDescription
sudo update-alternatives –config editorSets the default editor system-wide
sudo vim /etc/vim/vimrcEdits the global Vim configuration file
sudo nano /etc/nanorcEdits the global nano configuration file

RHEL/CentOS

Installation and removal

CommandDescription
sudo yum install vimInstalls the Vim editor
sudo yum install nanoInstall the Nano Editor
sudo yum remove vimUninstalls the Vim editor
sudo yum remove nanoUninstalls Nano Editor
sudo yum install vim-enhancedInstalls the advanced version of Vim

Configuration

CommandDescription
sudo alternatives –config editorSets the default editor system-wide
sudo vim /etc/vimrcEdits the global Vim configuration file
sudo nano /etc/nanorcEdits the global nano configuration file

Fedora

Installation and removal

CommandDescription
sudo dnf install vimInstalls the Vim editor
sudo dnf install nanoInstall the Nano Editor
sudo dnf remove vimUninstalls the Vim editor
sudo dnf remove nanoUninstalls Nano Editor
sudo dnf install vim-X11Installs Vim with GUI support

Configuration

CommandDescription
sudo update-alternatives –config editorSets the default editor system-wide
sudo vim /etc/vimrcEdits the global Vim configuration file
sudo nano /etc/nanorcEdits the global nano configuration file

Important configuration files

FileDescription
~/.vimrcCustom Vim Configuration
/etc/vim/vimrcGlobal Vim configuration file (Ubuntu/Debian)
/etc/vimrcGlobal Vim configuration file (RHEL/CentOS/Fedora)
~/.nanorcCustom Nano Configuration
/etc/nanorcGlobal Nano Configuration File

Useful Vim commands (within the editor)

CommandDescription
:wSaves the current file
:qQuit the editor
:wq or 😡Saves the file and exits the editor
:q!Quits the editor without saving
/suchbegriffSearches for a term in the file
:set numberEnables line numbering
:syntax onEnables syntax highlighting

Useful Nano commands (inside the editor)

Keyboard shortcutDescription
Ctrl + OSaves the current file
Ctrl + XQuit the editor
Ctrl + WSearches for a term in the file
Ctrl + KCuts out the current line
Ctrl + UPastes the last cut line
Alt + AStarts the markup (text selection)
Ctrl + GDisplays the help page

Set editor as default

System-wide

  • Ubuntu/Debian
    sudo update-alternatives –config editor
  • RHEL/CentOS
    sudo alternatives –config editor

For the current user

  • Add one of the following lines to ~/. rc:
    export EDITOR=vim
    # or
    export EDITOR=nano

Tips and tricks

  • Vim as a replacement for Vi
    On many systems, vi is a symbolic link to vim. To make sure Vim is always used, you can set an alias:
    alias vi=’vim’

    This can be done in the ~/. rc to make the alias permanent.
  • Installing plugins for Vim
    Vim supports plugins to extend functionality. A popular plugin manager is Vundle:
    git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

    Then configure the plugins in the ~/.vimrc.
  • Nano with syntax highlighting
    By default, syntax highlighting is disabled in Nano. To enable it, remove the comment characters in /etc/nanorc or ~/.nanorc before the corresponding include lines.
  • Example:
    include “/usr/share/nano/*.nanorc”

Troubleshooting

  • Problem: vim or nano is not found.
    Solution: Make sure Notepad is installed and check the path:
    which vim
    which nano
  • Problem: Changes in the configuration file are not applied.
    Solution: Make sure that the configuration file has been edited correctly and does not contain any syntax errors.