🐧
Linux
  • Introduction
  • 🖇️general
    • essentials
    • other commands
    • Superuser-do (sudo)
    • SUID, SGID, sticky bit
    • /dev/null
    • environment variables
    • special variables
    • shebang
  • spool
  • 🔧bash
    • overview
    • redirection
    • loop
    • .bashrc
  • text processing
    • grep
    • sed
    • awk
  • xxd/hexdump
  • text editors
    • nano
    • vi/vim
  • 📂filesystem & directories
    • Filesystem Hierachy Standard (FHS)
      • /etc
        • hosts, hosts.allow, hosts.deny
        • /cron.d
        • /httpd
        • /samba.d
        • hostname
        • crontab
        • shadow
        • passwd
        • profile
        • services
      • /dev
      • /proc
        • version
      • /mnt
      • /opt
      • /sbin
      • /lib
      • /usr
      • /tmp
      • /var
      • /bin
      • /run
    • chroot
  • find
  • locate
  • ⌚processes & jobs
    • cronjob
    • daemon
  • ⛓️system
    • systemctl
    • hostname
    • systemd
  • 🗃️media
    • ffmpeg
    • pdftk
  • 🔒Security
    • ufw
  • firejail
  • apparmor
  • 📦Package management
    • dpkg
    • apt/apt-get
  • Storage
    • lsblk
    • mount/umount
  • df/du
  • user management
    • chsh
  • Networking
    • Introduction
    • routing table/interface management
    • /etc/hosts, /etc/hosts.allow, /etc/hosts.deny
Powered by GitBook
On this page
  • Normal mode (navigation)
  • Insert mode (typing & editing)
  • Command mode (executing commands)
  1. text editors

vi/vim

There are a few modes: insert, normal and command mode.

Normal mode (navigation)

Press the esc button from any other mode. This is the default mode.

Insert mode (typing & editing)

Press i from the normal mode. This mode allows us to directly insert and edit text — just like a normal text editor.

Command mode (executing commands)

Press : from the normal mode. This mode allows us to run several commands without leaving the editor. One feature I really appreciate is the ability to run shell commands — see below for more details.

Useful commands

  1. Save (write) file

:w  
  1. Quit

:q
  1. Combine write + quit

:wq
  1. Quit without saving

:q!
  1. Execute shell commands

:!
:! ls

Note: The symbol % represents the current filename without any extensions

Examples

Eg. Compile and execute a C program file test.c (that is currently opened)

:! gcc test.c -o test && ./test
:! gcc %.c -o % && ./%

Eg. Execute a Python program file test.py (that is currently opened)

:! python3 test.py
:! python3 %.py

Eg. Change permissions and execute a .sh (shell) script test.sh

:! ls -l
:! chmod +x test.sh
:! ./%

PreviousnanoNextFilesystem Hierachy Standard (FHS)

Last updated 2 months ago