当前位置: 首页 > 工具软件 > .tmux > 使用案例 >

Linux 中的 bashrc、vimrc 及 tmux.conf 配置

空慈
2023-12-01

概述

趁手的工具能大大提高生产力。而对于整天与 Linux 字符终端打交道的程序员来说,终端工具、shell 工具以及文本编辑工具,一定要用好、用趁手。这里 3 个工具我选择的分别是 tmux、bash、Vim。当然,*NIX(UNIX、Linux)环境下还有很大其他很好的选择,如 screen、zsh、Emacs 等等,关键还是自己用趁手。没有最好,只有最合适自己的。不要盲目站队、打口水仗。一切以提高生产力为目标。

这里记录我这 3 个工具的配置。为了方便统一管理和在多个 Linux 系统中配置,我把配置文件放到了 Gitee 仓库中,在各个 Linux 系统中 clone 下来,然后直接引用。

bashrc

在 .bashrc 中加入以下代码,确保每次 bash 启动后加载指定的配置,这里主要是配置了一些 aliases,大大简化命令的输入。

if [ -f /home/jack/git/linux-dev-env/bash_aliases ]; then
    . /home/jack/git/linux-dev-env/bash_aliases
fi

bash_aliases 文件的内容如下:

# You can copy the following to ~/.bashrc and source it
# OR
# copy this file to ~/.bash_aliases and call it in ~/.bashrc, like:
# if [ -f ~/.bash_aliases ]; then
#     . ~/.bash_aliases
# fi

# Base
alias srb="source ~/.bashrc"
alias ax="chmod a+x"
alias dx="chmod a-x"
alias lspwd='ls | sed "s:^:`pwd`/:"'
alias ping='ping -c 3'
alias tmux0='tmux a -t 0'

# cd
alias cd..='cd ..'
alias ..="cd .."
alias ...="cd ..; cd .."
alias jt='cd /home/jack/linux-a-io/hardware-test'
alias gotot='cd /mnt/d/tmp'

# vim
alias vi=vim

# make
alias mc="make clean"

# Git
alias gs="git status"
alias gc="git commit ."
alias gcd="git checkout develop"
alias gcm="git checkout master"
alias gpm="git push origin master"
alias gpd="git push origin develop"
alias gfo="git fetch origin"
alias gmm="git merge origin/master"
alias gmd="git merge origin/develop"
alias gtm='foo(){ git archive master --prefix="$1/" | gzip > $1.tar.gz; }; foo '
alias groot="while [ ! -d .git ]; do cd ..; done"   # Go to the root of a git repo.

# SSH
alias cp2='foo(){ scp -r $1 root@192.168.$2:~; }; foo '
alias cpfrom='foo(){ scp -r jack@192.168.$1:$2 .; }; foo '
alias ss125='ssh jack@192.168.1.125'
alias ss60='ssh jack@192.168.1.60'

vimrc

~/.vimrc 文件只有一行,加载自己另外管理的配置文件。

source /home/jack/git/linux-dev-env/vimrc

vimrc 的配置:

" Add one line to ~/.vimrc:
"   source /home/jack/git/linux-dev-env/vimrc

" Colors
syntax enable       " enable syntax highlight


" Leader Shortcuts
let mapleader=","
" jk is escape, type fast.
inoremap jk <esc>


" UI
set number          " show line numbers
set wildmenu        " visual autocomplete for command menu
set showmatch       " highlight matching [{()}]
set lazyredraw      " redraw only when we need to

filetype indent on  " load filetype-specific indent files

set cursorline      " Hightlight the current line.
:highlight CursorLine   cterm=NONE ctermbg=black guibg=black
:highlight CursorColumn cterm=NONE ctermbg=black guibg=black
:nnoremap <Leader>c :set cursorline! cursorcolumn!<CR>


" Space and tab
set tabstop=4       " number of visual spaces per TAB
set softtabstop=4   " number of spaces in tab when editing
set shiftwidth=4    " affects  >>, << or == and automatic indentation
set expandtab       " tabs are spaces


" Search
set incsearch       " search as characters are entered
set hlsearch        " highlight matches
set ignorecase      " Case insensitive
" turn off search highlight
nnoremap <leader><space> :nohlsearch<CR>


" Folding
set foldenable          " enable folding
set foldlevelstart=2    " open most folds by default
set foldminlines=3      " 10 nested fold max
set foldmethod=indent   " fold based on indent level
" use space to open/closes folds
nnoremap <space> za


" Movement
" move vertically by visual line
nnoremap j gj
nnoremap k gk
" highlight last inserted text
nnoremap gV `[v`]

tmux.conf

创建 ~/.tmux.conf 配置文件,加入以下一行。每次 tmux 启动就会加载自己专门的配置。

source-file /home/jack/git/linux-dev-env/tmux.conf

tmux.conf 独立维护管理的配置文件,通过 Gitee 仓库在多个 Linux 系统之间共享。

# Create ~/.tmux.conf and add one line in it to source this file:
# source-file /home/jack/git/linux-dev-env/tmux.conf

# Set prefix to Ctrl + a
set -g prefix C-a
unbind C-b

# Window number start from 1
set-option -g base-index 1
set-window-option -g pane-base-index 1

# Easy to swich window, like byobu
bind-key -n F2 new-window
bind-key -n F3 previous-window
bind-key -n F4 next-window

参考

https://gitee.com/liaojieliang/linux-dev-env

https://github.com/coolshellx/articles/blob/master/00-How.To.Set.Up.An.High.Efficiency.Work.Enviornment.md

2019年9月30日

 类似资料: