linux or mac 的zsh配置, 以及vim 和tmux常用配置

linux or mac 的zsh配置, 以及vim 和tmux常用配置

以linux为例来展示zsh的安装及设置

  • 首先查看自己的shell
  1. 查看当前用的shell echo $SHELL

  2. 查看支持哪些shell cat /etc/shells

  • zsh 安装
  1. linux下直接sudo apt-get install -y zsh

  2. 再检查一下 cat /etc/shells,会发现多了一个/bin/zsh

  3. 使用比较方便的oh-my-zsh

  4. 安装 oh-my-zsh

wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh - 0 - | sh

如果安装出现问题,比如一个pam 认证失败 的错误, 就

sudo chsh -s /bin/bash 把shell 设置为bash,然后再chsh -s /bin/zsh换成zsh.

  1. ~/.zshrc中的配置

我的配置如下

#if you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
  export ZSH=/home/pengkun/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# zhs的主题
ZSH_THEME="ys"
# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of
# looking in ~/.oh-my-zsh/themes/
# An empty array have no effect
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.

# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.

# z命令快速跳转目录     x命令解压一切文件         命令行可以直接google  
plugins=(
  git z zsh-autosuggestions extract web-search zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
#
#自动补全插件
#source ~/.oh-my-zsh/plugins/incr/incr*.zsh
# 自动更新的时间间隔,单位是天,这里设置 30 天更新一次
export UPDATE_ZSH_DAYS=30

关于自动补全的 可以到git 上下载zsh-autosuggestions 放到~/.oh-my-zsh/plugins下面.

然后在~/.zshrc中的

下载的命令是

git clone https://github.com/zsh-users/zsh-autosuggestions 
source zsh-autosuggestions.zsh
# 语法高亮的
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

# 注意上面两个要放在~/.oh-my-zsh/plugins 下面去,不是zsh下面

加了语法高亮之后,在终端再打cd, ls,python这些命令的时候会发现,变亮了。

plugins=(
  git z zsh-autosuggestions extract web-search zsh-syntax-highlighting
)

加入zsh-autosuggestions我的上面已经加入了,而且是有其他的,如果上面的高亮设置的出错了,就也到git上面下载然后放到plugins下面,

上面的设置好之后还可以查看google, firefox等

比如firefox NBA就会直接打开NBA.

tmux 里面的,使得进入tmux 之后就是 zsh

我的常用配置如下

set -g default-shell /bin/zsh
set -g default-command /bin/zsh
set -g mouse on
bind '"' split-window -c '#{pane_current_path}'
bind '%' split-window -h -c '#{pane_current_path}'

在安vim 的一些插件时有时也会出

YCMD的错: YCMd,..restart。。。 这时候需要编译


cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

这个要根据自己的python, 如果上面报

error python headers are missing in /usr/include/python2.7

可以尝试

sudo apt install python2.7-dev

也可以直接用python3

python3 install.py --clang-completer

后面的这个是加上c语言的自动补全.

我常用的tmux配置

set -g default-shell /bin/zsh
set -g default-command /bin/zsh
set -g mouse on

bind '"' split-window -c '#{pane_current_path}'
bind '%' split-window -h -c '#{pane_current_path}'

set -g pane-border-style fg=green,bg=black
set -g pane-active-border-style fg=green,bg=black

我的vim 常用配置

先下载vundle git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim~/.vimrc中加入

syntax on
set cursorline
set encoding=utf8
set ts=4
set sts=4
set expandtab
set shiftwidth=4
set nu
set hlsearch
set showmatch

filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Lokaltog/vim-powerline'
Plugin 'Valloric/YouCompleteMe'
call vundle#end()
filetype plugin indent on
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

然后再vim :PluginInstall

其它

修改默认的shell为zsh

可以试试

sudo usermod -s /bin/zsh username

或者

chsh -s /bin/zsh

再zsh里面加入时间

只需要在主题文件中 ` .oh-my-zsh/themes/你的主题文件` 加入


function preexec() {
  timer=${timer:-$SECONDS}
}

function precmd() {
  if [ $timer ]; then
    timer_show=$(($SECONDS - $timer))
    if [[ $timer_show -ge $min_show_time ]]; then
      RPROMPT='%{$fg_bold[red]%}(${timer_show}s)%f%{$fg_bold[white]%}[%*]%f'
    else
      RPROMPT='%{$fg_bold[white]%}[%*]%f'
    fi
    unset timer
  fi
}

autoload -Uz add-zsh-hook
add-zsh-hook preexec preexec
add-zsh-hook precmd precmd


打赏,谢谢~~

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,多谢支持~

打开微信扫一扫,即可进行扫码打赏哦