Master tmux and vim: Installation, Configuration, and Essential Commands
This guide walks you through installing tmux on Ubuntu, customizing its configuration, understanding its session‑window‑pane hierarchy, and using common tmux commands, then introduces vim’s modes, key bindings, basic editing operations, and a practical .vimrc configuration for a smoother editing experience.
tmux Overview
tmux (Terminal Multiplexer) allows multiple terminal sessions to be created, accessed and controlled inside a single window. It is useful for remote work, multitasking and keeping long‑running jobs alive after disconnection.
Installation on Ubuntu
Update the package index: sudo apt update Install tmux:
sudo apt install tmuxBasic Configuration
Edit the file ~/.tmux.conf and add the following lines to change the default prefix to Ctrl‑a and enable mouse support:
# Set new prefix to Ctrl‑a (default is Ctrl‑b)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Enable mouse support
set -g mouse onReload the configuration without leaving the session:
tmux source-file ~/.tmux.conftmux Hierarchy
Session : top‑level container that can hold multiple windows. Sessions can be detached and later re‑attached.
Window : a virtual terminal inside a session; a session may contain many windows.
Pane : a sub‑region of a window created by splitting the window horizontally or vertically.
Common tmux Commands
Starting tmux
Start a new session with a default window and pane:
tmuxPane Management (prefix is Ctrl‑a )
Split vertically: Ctrl‑a " Split horizontally: Ctrl‑a % Switch panes: Ctrl‑a <arrow> Close pane: Ctrl‑d Enter copy mode: Ctrl‑a [ → move cursor, press Enter to copy, paste with Ctrl‑a ] Toggle fullscreen for the current pane:
Ctrl‑a zSession Management
Detach from the current session: Ctrl‑a d List all sessions: tmux ls Attach to a session: tmux attach-session -t <session‑name> Create a new session (named mysession): tmux new-session -s mysession Create a new detached session: tmux new-session -s mysession -d Kill a specific session: tmux kill-session -t <session‑name> Kill all sessions:
tmux kill-servervim Overview
vim (Vi IMproved) is a powerful, extensible text editor that builds on the classic vi interface. It provides several operating modes and a rich set of commands for efficient editing.
Basic Concepts
Normal mode : default mode for navigation and issuing commands.
Insert mode : entered with i, I, a or A to edit text.
Command‑line mode : entered with :, / or ? to execute Ex commands or searches.
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 run the command or Esc to cancel.
Cursor Movement (Normal mode)
h j k l– left, down, up, right.
Arrow keys – same directions. 0 or Home – start of line. $ or End – end of line. gg – first line; G – last line. nG – go to line n .
Text Editing (Normal mode)
v– start visual selection; move cursor to select text. d – delete selection (also yanks to the unnamed register). dd – delete the current line. yy – yank (copy) the current line. p – paste after the cursor. u – undo; Ctrl‑r – redo. Shift‑> / Shift‑< – indent/outdent selected lines.
Save/quit: :w, :q, :wq, :wq!.
Search and Highlight
Forward search: /word then Enter.
Backward search: ?word then Enter.
Next match: n; previous match: N.
Toggle highlight: :set hlsearch / :noh.
Sample vim Configuration (.vimrc)
Create or edit ~/.vimrc and add the following settings to improve usability:
" 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, 4‑space indent
set expandtab
set shiftwidth=4
set tabstop=4
" Enable smart indent
set smartindent
" Show matching brackets
set showmatch
" Enable search highlighting and incremental search
set hlsearch
set incsearch
" Use system clipboard
set clipboard=unnamedplus
" Case‑insensitive search, but respect case when uppercase used
set ignorecase
set smartcase
" Show command as you type
set showcmd
" Split windows below and to the right
set splitbelow
set splitright
" Persistent undo
set undofile
set undodir=~/.vim/undodir
" Wrap long lines
set wrap
" Enable folding based on syntax
set foldmethod=syntax
set foldlevelstart=99
" Color scheme (choose any you like)
colorscheme desert
" Always show status line
set laststatus=2
" Better backspace behavior in insert mode
set backspace=indent,eol,start
" Auto‑write on buffer change
set autowrite
" Show invisible characters
set list
set listchars=tab:>-,trail:.,eol:$
" Highlight current line with custom colors
hi CursorLine cterm=NONE ctermbg=darkgray
" Increase command history size
set history=1000
" Enable automatic formatting options
set formatoptions+=croSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
