Fundamentals 14 min read

Master tmux & Vim: Essential Commands and Config for Terminal Workflows

This guide introduces tmux, a terminal multiplexer, covering installation on Ubuntu, configuration tweaks, session/window/pane hierarchy, and common key bindings, then shifts to Vim, detailing its modes, basic navigation, editing commands, and a sample .vimrc configuration to enhance productivity.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master tmux & Vim: Essential Commands and Config for Terminal Workflows

tmux

tmux (Terminal Multiplexer) is a terminal multiplexer that allows you to run and manage multiple terminal sessions within a single window. It is useful for remote work, handling multiple tasks, and long‑running processes.

1. Install tmux

On Ubuntu:

Update package list sudo apt update Install tmux sudo apt install tmux Configure tmux Edit ~/.tmux.conf to change settings, e.g., enable mouse support and change the default prefix key.

Step 1: Edit ~/.tmux.conf

nano ~/.tmux.conf

Step 2: Modify content

Change the prefix from Ctrl‑b to Ctrl‑a and enable mouse:

# Set new prefix to Ctrl‑a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Enable mouse support
set -g mouse on

Step 3: Reload configuration

tmux source-file ~/.tmux.conf

2. tmux structure

tmux consists of three components:

Session

Definition: The top‑level container representing an independent terminal environment that can contain multiple windows.

Each session is independent; you can switch between sessions, each with its own windows and panes.

Sessions can run in the background and be reattached later.

Window

Definition: A virtual terminal inside a session, similar to a tab.

A session can have multiple windows, each displaying a separate terminal.

Windows can be switched quickly.

Pane

Definition: A sub‑region of a window that can be split horizontally or vertically.

Each pane runs an independent program or command.

Splitting and resizing panes improves screen utilization.

Relationship

Session contains windows

Window contains panes

Hierarchy: Session → Window → Pane

Summary

Session is the top‑level structure containing multiple windows.

Window is an independent work area within a session, which can be split into panes.

Pane is a sub‑region of a window that allows parallel terminal sessions.

+---------------------------------------------------------+
|                           Session                      |
|                           (会话)                        |
|                                                         |
|  +---------------------+  +---------------------+      |
|  |       Window 1      |  |       Window 2      |      |
|  |       (窗口 1)       |  |       (窗口 2)       |     |
|  |                     |  |                     |      |
|  |  +-------------+    |  |  +-------------+    |      |
|  |  |   Pane 1    |    |  |  |   Pane 3    |    |      |
|  |  |  (窗格 1)   |    |  |  |  (窗格 3)   |    |       |
|  |  +-------------+    |  |  +-------------+    |      |
|  |  +-------------+    |  |  +-------------+    |      |
|  |  |   Pane 2    |    |  |  |   Pane 4    |    |      |
|  |  |  (窗格 2)   |    |  |  |  (窗格 4)   |    |       |
|  |  +-------------+    |  |  +-------------+    |      |
|  +---------------------+  +---------------------+      |
|                                                         |
+---------------------------------------------------------+

2. Common tmux commands

Start tmux

Run tmux to start a new session (creates a session, a window, and a pane).

Pane management

Split vertically: Ctrl‑a " Split horizontally: Ctrl‑a % Switch panes: Ctrl‑a Arrow Close pane: Ctrl‑d Copy mode: Ctrl‑a [, select text, then Enter to copy.

Paste: Ctrl‑a ] Toggle fullscreen:

Ctrl‑a z

Session management

Detach: Ctrl‑a d List sessions: tmux ls Attach to a session: tmux a or tmux attach-session -t sessionname Kill a session: tmux kill-session -t sessionname Kill all sessions:

tmux kill-service

vim

Vim (Vi IMproved) is a powerful text editor based on the classic vi editor, with many enhancements.

1. Basic concepts

Modes :

Normal mode : default mode for navigation and commands.

Insert mode : enter with i, I, a, A to edit text.

Command‑line mode : enter with :, ?, \ to execute commands.

Mode switching

Normal → Insert: press i, I, a, or A.

Normal → Command‑line: press :, /, or ?.

Insert → Normal: press Esc.

Command‑line → Normal: press Enter to execute or Esc to cancel.

2. Basic operations

2.1 Cursor movement

In normal mode:

h j k l   # left down up right
↑ ↓ ← →   # arrow keys
n<space>  # move n positions forward
0 or Home   # beginning of line
$ or End    # end of line
gg          # first line
g          # last line
nG          # go to line n

2.2 Text manipulation

v          # start visual selection
d          # delete selection (yanks to clipboard)
dd         # delete current line
gg d G    # delete all content
y          # yank (copy) selection
yy         # yank current line
p          # paste after cursor
u          # undo
Ctrl‑r     # redo
Shift‑>    # indent right
Shift‑<    # indent left
:w         # save
:q         # quit
:wq        # save and quit
:wq!       # force quit

2.3 Other commands

:set nu          # show line numbers
:set nonu        # hide line numbers
gg = G           # format whole file
==               # format current line
:set hlsearch    # highlight search
:noh             # clear highlight
:set paste       # enable paste mode
:set nopaste     # disable paste mode

3. Configuration file

Create ~/.vimrc and add the following settings to improve the editing experience:

" Show line numbers
set number

" Highlight current line
set cursorline

" Show ruler (line and column)
set ruler

" Enable syntax highlighting
syntax on

" Filetype detection and auto‑indent
filetype plugin indent on

" Use spaces instead of tabs
set expandtab
set shiftwidth=4
set tabstop=4
set autoindent
set smartindent

" Show matching brackets
set showmatch

" Search settings
set hlsearch
set incsearch
set ignorecase
set smartcase
set showcmd

" Split window preferences
set splitbelow
set splitright

" Better undo
set undofile
set undodir=~/.vim/undodir

" Wrap long lines
set wrap

" Code folding
set foldmethod=syntax
set foldlevelstart=99

" Colorscheme
colorscheme desert

" Status line
set laststatus=2

" Backspace behavior
set backspace=indent,eol,start

" Auto‑write
set autowrite

" List characters
set list
set listchars=tab:>-,trail:.,eol:$

" Show break
set showbreak=+++

" Highlight cursor line
hi CursorLine cterm=NONE ctermbg=darkgray

" History size
set history=1000

" Format options
set formatoptions+=cro
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

productivityVimterminaltmux
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.