[unbuntu 配置]:~/.bashrc 和/etc/vim/vimrc常用配置

本文介绍如何在~/.bashrc中配置终端提示符显示Git分支名,并提供了一种美观的PS1配置方案。此外,还展示了如何设置路径、代理及nvm,以及一些常用的alias命令。最后,给出了vimrc的常用配置,包括改变tab为4个空格、自动缩进等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

~/.bashrc的常用配置

终端提示符显示git branch名

在 ~/.bashrc里面添加终端提示符显示git branch名

PS1='\[\e[32;1m\]${debian_chroot:+($debian_chroot)}\u@\A:\[\e[1;33m\]\w$(__git_ps1 " \[\e[1;35m\](%s)")\[\e[32;1m\]\$ \[\e[m\]'

Mac 如下更改

function git_branch {
  branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
  if [ "${branch}" != "" ];then
      if [ "${branch}" = "(no branch)" ];then
          branch="(`git rev-parse --short HEAD`...)"
      fi
      echo " ($branch)"
  fi
}

export PS1='\[\e[32;1m\]${debian_chroot:+($debian_chroot)}\u@\A:\[\e[1;33m\]\w\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ \[\e[m\]'

好看的PS1配置

parse_git_branch() {
git branch 2> /dev/null | sed -e ‘/[]/d’ -e ‘s/ (.*)/ (\1)/’
}
PS1="[\033[0;32m]\u@\h [\033[0;33m]\w [\033[0;36m]$(parse_git_branch)[\033[0m]\n$ "
在这里插入图片描述

设置 path

# config path
export PATH=/home/changpzh/.nvm/versions/node/v6.11.4/bin:/usr/share/:$PATH

设置 proxy

export http_proxy=http://10.144.1.10:8080
export https_proxy=http://10.144.1.10:8080

nvm 配置

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

配置 alias

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

alias ..="cd .."
alias ..2="cd ../../"
alias ..3="cd ../../../"
alias ..4="cd ../../../../"
alias ..5="cd ../../../../../"

vimrc 常用配置

vimrc在 /etc/vim/ 下面

"change tapsapce to 4 spaces"
set tabstop=4				" 设置tab长度为4
set softtabstop=4   		" 使得按退格键时可以一次删掉 4 个空格
set shiftwidth=4    		" 设置<<< 和 >>>移动时宽度为4
set noexpandtab
set expandtab
set autoindent  			" 自动缩进
set showmatch 				" 显示匹配的括号

set hlsearch				" 高亮search 匹配字样
set backspace=2				" 可以随时用退格删除字符
set background=dark					" 显示不同的底色色调
set nu						" 显示每一行的行号
syntax on 					" 自动语法高亮

"Hightlight cursor line"
:set cursorline
:set cursorcolumn

"change Hight light color"
highlight CursorLine   cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE


==============================================================================
set showmatch                   " automatically show matching brackets. works like it does in bbedit.
set vb                          " turn on the "visual bell" - which is much quieter than the "audio blink"
set ruler                       " show the cursor position all the time
set laststatus=2                " make the last line where the status is two lines deep so you can see status always
set backspace=indent,eol,start  " make that backspace key work the way it should
set nocompatible                " vi compatible is LAME
set background=dark             " Use colours that work well on a dark background (Console is usually black)
set showmode                    " show the current mode
set clipboard=unnamed           " set clipboard to unnamed to access the system clipboard under windows
syntax on                       " turn syntax highlighting on by default

" Show EOL type and last modified timestamp, right after the filename
set statusline=%<%F%h%m%r\ [%{&ff}]\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})%=%l,%c%V\ %P

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木瓜~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值