Boosting Development Efficiency — Linux Development Environment Setup Guide

In modern software development, having an efficient and convenient development environment can significantly improve productivity. This article provides a detailed guide on setting up a complete development environment on Linux, including configuration and usage of the tmux terminal multiplexer, vim code editor, enhanced zsh shell, and git version control.

Prerequisites

Before you begin, make sure your system meets the following minimum requirements:

  • tmux: version >= 2.1
  • vim: version >= 7.3
  • zsh: oh-my-zsh recommended
  • git: latest version

1. TMUX Terminal Multiplexer Configuration

TMUX is an excellent terminal multiplexer that allows you to create multiple sessions and windows within a single terminal window, making it ideal for developers who need to handle multiple tasks simultaneously.

Installation and Configuration

First, clone the recommended tmux configuration:

bash
1
2
3
4
$ cd ~
$ git clone https://github.com/gpakosz/.tmux.git
$ ln -s -f .tmux/.tmux.conf
$ cp .tmux/.tmux.conf.local .

On Ubuntu systems, you also need to install xclip for cross-file copy and paste support:

bash
1
$ sudo apt-get install xclip

Configuration File Modifications

Open the .tmux.conf file and find the following configuration to modify:

Original configuration:

bash
1
bind -t vi-copy y copy-selection

Change to:

bash
1
bind -t vi-copy y copy-pipe "xclip -sel clip -i"

If your tmux version is < 1.8, modify the configuration as follows:

bash
1
2
3
# copy & paste between tmux and x clipboard
bind C-p run-shell "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
bind C-y run-shell "tmux show-buffer | xclip -sel clip -i"

In the .tmux.conf.local file, uncomment the following configuration:

bash
1
2
#set -g status-keys vi
#set -g mode-keys vi

Common TMUX Operations

Session management:

  • tmux new -s session_name: Create a new session
  • tmux ls: List all sessions
  • tmux attach -t session_name: Attach to a specific session
  • tmux kill-session -t session_name: Kill a session

Window management:

  • Ctrl+d: Close current window
  • Ctrl+b then c: Create new window
  • Ctrl+b then w: Select window
  • Ctrl+b then 0-9: Quick switch between windows

Pane management:

  • Ctrl+b then ": Split pane horizontally
  • Ctrl+b then %: Split pane vertically
  • Ctrl+b then arrow keys: Switch between panes
  • Ctrl+b then x: Close current pane

2. GIT Version Control Configuration

GIT is one of the most important version control tools in modern software development. Below we introduce how to use git submodules to manage multiple related projects.

Managing Multiple Projects with Git Submodules

In daily development, we often need to manage multiple related git repositories simultaneously, including team projects and personal projects. Using git submodules makes it very convenient to manage these projects.

Creating a project with submodules:

bash
1
2
3
4
5
6
7
$ mkdir cmworkspace
$ git init
$ git remote add origin https://github.com/username/cmworkspace.git
$ git submodule add https://github.com/username/cmexapp.git micmexapp
$ git add -A
$ git commit -m "add submodule micmexapp"
$ git push --set-upstream origin master

Updating all submodules:

When you need to update all submodules simultaneously, use the following command:

bash
1
$ git submodule foreach git pull

Cloning a project with submodules:

bash
1
2
3
4
5
6
$ git clone https://github.com/username/cmworkspace.git
$ cd cmworkspace
$ git submodule init
$ git submodule sync
$ git submodule update
$ git submodule foreach git pull origin master

Git Alias Configuration

To make git more convenient to use, you can add the following aliases to your .gitconfig file:

bash
1
2
3
4
5
6
7
8
9
[alias]
    st = status
    co = checkout
    br = branch
    lg = log --oneline --graph --all
    df = diff
    ci = commit
    pl = pull
    ps = push

3. ZSH Enhanced Shell Configuration

ZSH is an enhanced version of the traditional bash shell. When paired with oh-my-zsh, it provides richer functionality and a better user experience.

Installing Oh My ZSH

bash
1
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Common Plugin Configuration

Edit the ~/.zshrc file and enable the following plugins:

bash
1
2
3
4
5
6
7
8
9
plugins=(
    git
    zsh-autosuggestions
    zsh-syntax-highlighting
    autojump
    extract
    docker
    npm
)

Recommended plugin descriptions:

  • zsh-autosuggestions: Automatic command suggestions
  • zsh-syntax-highlighting: Syntax highlighting
  • autojump: Smart directory jumping
  • extract: Smart extraction
  • docker: Docker command completion
  • npm: Node.js package management completion

Theme Configuration

Choose a theme you like, for example:

bash
1
ZSH_THEME="agnoster"

Custom Environment Variables

Add common environment variables in ~/.zshrc:

bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Encoding settings
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8

# Editor settings
export EDITOR=vim

# History settings
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTCONTROL=ignorespace

# Color settings
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

4. VIM Code Editor Configuration

VIM is a powerful code editor that, with proper configuration, can provide a development experience comparable to an IDE.

Installing VIM

bash
1
2
3
4
5
# Ubuntu/Debian
$ sudo apt-get install vim

# CentOS/RHEL
$ sudo yum install vim

VIM Configuration File

Create a ~/.vimrc configuration file:

vim
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
" Basic settings
set nocompatible               " Use Vim's improved mode instead of Vi compatible mode
filetype plugin indent on       " Enable file type detection
syntax on                      " Syntax highlighting

" Display settings
set number                      " Show line numbers
set relativenumber              " Show relative line numbers
set cursorline                  " Highlight current line
set showmatch                   " Highlight matching brackets
set showmode                    " Show current mode

" Indentation settings
set autoindent                  " Auto indent
set smartindent                 " Smart indent
set expandtab                   " Use spaces instead of tabs
set tabstop=4                   " Tab width of 4
set shiftwidth=4                " Indent width of 4

" Search settings
set ignorecase                  " Ignore case when searching
set smartcase                   " Be case-sensitive when search contains uppercase
set hlsearch                    " Highlight search results
set incsearch                   " Incremental search

" Encoding settings
set encoding=utf-8
set fileencoding=utf-8

" Backup settings
set nobackup
set noswapfile

" Key mappings
let mapleader = ","
nnoremap <Leader>w :w<CR>
nnoremap <Leader>q :q<CR>
nnoremap <Leader>wq :wq<CR>
nnoremap <Leader>q! :q!<CR>

" Plugin management
call plug#begin('~/.vim/plugged')

" Code completion
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround'

" File browsing
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

" Status bar
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" Theme
Plug 'morhetz/gruvbox'

" Git related
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'

" Code formatting
Plug 'prettier/vim-prettier', {
  \ 'do': 'npm install',
  \ 'branch': 'release/0.23.0',
  \ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'markdown'],
  \ }

" Code snippets
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'

call plug#end()

Basic VIM Operations

Basic movement:

  • h, j, k, l: left, down, up, right
  • gg: Jump to beginning of file
  • G: Jump to end of file
  • w: Jump to beginning of next word
  • b: Jump to beginning of previous word

Editing operations:

  • i: Insert mode
  • Esc: Return to normal mode
  • dd: Delete current line
  • yy: Copy current line
  • p: Paste
  • u: Undo
  • Ctrl+r: Redo

Search and replace:

  • /pattern: Search forward
  • ?pattern: Search backward
  • n: Next search result
  • N: Previous search result
  • :s/pattern/replacement/g: Global replacement

Multi-window operations:

  • :split: Split window horizontally
  • :vsplit: Split window vertically
  • Ctrl+w then arrow keys: Switch between windows
  • Ctrl+w then c: Close current window

5. Integrated Configuration

Creating a Startup Script

Create a startup script ~/dev-setup to quickly configure all tools:

bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Development environment quick start script

echo "=== Development Environment Setup Script ==="
echo "1. Configure Git aliases"
echo "2. Configure TMUX session"
echo "3. Start VIM"
echo "4. Exit"
echo

read -p "Please select an option (1-4): " choice

case $choice in
    1)
        echo "Configuring Git aliases..."
        git config --global alias.st status
        git config --global alias.co checkout
        git config --global alias.br branch
        git config --global alias.lg "log --oneline --graph --all"
        git config --global alias.df diff
        git config --global alias.ci commit
        git config --global alias.pl pull
        git config --global alias.ps push
        echo "Git aliases configured successfully"
        ;;
    2)
        echo "Starting TMUX session..."
        tmux new -s dev
        ;;
    3)
        echo "Starting VIM..."
        vim
        ;;
    4)
        echo "Exiting script"
        exit 0
        ;;
    *)
        echo "Invalid option"
        ;;
esac

Add execute permission to the script:

bash
1
$ chmod +x ~/dev-setup

Environment Variable Configuration

Add common environment variables in ~/.zshrc:

bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Development tool paths
export PATH="$HOME/.local/bin:$PATH"

# Python virtual environment
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_HOOK_DIR=$WORKON_HOME

# Go path
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

# Node.js path
export NODE_PATH=/usr/local/lib/node_modules
export PATH=$PATH:/usr/local/bin

# Rust path
export PATH="$HOME/.cargo/bin:$PATH"

# Custom functions
mkcd() {
    mkdir -p "$1" && cd "$1"
}

extract() {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)   tar xvjf $1    ;;
            *.tar.gz)    tar xvzf $1    ;;
            *.tar.xz)    tar xvJf $1    ;;
            *.bz2)       bunzip2 $1     ;;
            *.rar)       unrar x $1     ;;
            *.gz)        gunzip $1      ;;
            *.tar)       tar xvf $1     ;;
            *.tbz2)      tar xvjf $1    ;;
            *.tgz)       tar xvzf $1    ;;
            *.zip)       unzip $1       ;;
            *.Z)         uncompress $1  ;;
            *.7z)        7z x $1        ;;
            *)           echo "Unrecognized file type: $1" ;;
        esac
    else
        echo "File does not exist: $1"
    fi
}

6. Tips and Best Practices

TMUX Tips

  1. Session persistence: Even if the SSH connection drops, tmux sessions remain running
  2. Session sharing: You can share tmux sessions with other team members
  3. Shortcut memorization: Remember Ctrl+b as the tmux prefix key
  4. Custom configuration: Modify .tmux.conf.local according to your usage habits

VIM Tips

  1. Visual mode: Press v to enter character selection mode, press V to enter line selection mode
  2. Block selection: Press Ctrl+v to enter block selection mode
  3. Macro recording: Press qa to start recording a macro, press q to stop, press @a to execute
  4. Folding: Press zc to fold, press zo to unfold

ZSH Tips

  1. Auto-completion: Press Tab after typing a command to complete it
  2. History search: Use Ctrl+r to search command history
  3. Directory jumping: Use the j command to jump to frequently used directories
  4. Plugin management: Use antigen or zgen to manage zsh plugins

GIT Tips

  1. Branch management: Use git branch to manage branches
  2. Merge strategies: Choose appropriate merge strategies based on project needs
  3. Tag management: Use git tag to manage version tags
  4. Remote repositories: Use git remote to manage remote repositories

7. Troubleshooting

Common Issues

TMUX copy and paste not working:

bash
1
2
3
4
5
# Install xclip
sudo apt-get install xclip

# Check tmux version
tmux -V

VIM plugins cannot be installed:

bash
1
2
3
4
5
# Install curl
sudo apt-get install curl

# Install git
sudo apt-get install git

ZSH plugins cannot be loaded:

bash
1
2
3
4
5
# Ensure .zshrc file exists
ls -la ~/.zshrc

# Reload configuration
source ~/.zshrc

GIT submodule issues:

bash
1
2
3
4
5
6
7
8
# Initialize submodules
git submodule init

# Update submodules
git submodule update

# Sync submodules
git submodule sync

8. Summary

With the above configuration, you now have a complete Linux development environment, including:

  • TMUX: A powerful terminal multiplexer supporting session management and window splitting
  • VIM: An efficient code editor supporting rich plugins and custom configuration
  • ZSH: An enhanced shell providing auto-completion and syntax highlighting
  • GIT: A powerful version control tool supporting submodule management

This environment setup will help you significantly improve development efficiency, reduce unnecessary repetitive work, and make the development process smoother and more enjoyable. We recommend further personalizing each tool based on your actual needs and usage habits.

Remember, tools are only aids — the most important thing is to master the correct usage methods and develop good development habits. As you continue to use and explore, you will gradually discover more powerful features of each tool, making them truly become capable assistants in your development work.