iterm2+zsh+vim配色

一个好的终端环境能让写代码的心情变好。

先上效果:

iterm2配色:https://blog.biezhi.me/2018/11/build-a-beautiful-mac-terminal-environment.html

zsh插件:https://juejin.im/entry/5ae00e54f265da0b8635ea5c

安装oh my zsh

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

iterm2配色

先检查下终端颜色配置为 xterm-256color,位置在 iTerm2 -> Preferences -> Profiles -> Terminal

下载配色文件:

1
2
mkdir ~/.iterm2 && cd ~/.iterm2
git clone https://github.com/mbadolato/iTerm2-Color-Schemes

finder前往.iterm2文件夹,可以固定在侧边栏:

import iTerm2-Color-Schemes/schemes内所有的文件之后选择Tomorrow Night:

iterm2字体

先安装homebrew:

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1
2
brew tap homebrew/cask-fonts
brew cask install font-hack-nerd-font

zsh主题

1
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

.zshrc里面修改ZSH_THEME:

1
2
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE="nerdfont-complete" # 使用nerdfont字体

每次修改.zshrc都需要source生效:

1
source ~/.zshrc

zsh插件

extract

只需要在plugins里添加即可

使用:

1
x input.tar.gz

sublime

sublime打开文件/文件夹:

只需要在plugins里添加即可

使用:

1
2
3
4
5
st	打开 sublime
st + 文件夹 打开该文件夹
st + 文件 打开该文件
stt 打开当前的文件夹,相当于 st .
sst 管理员权限 相当于 sudo st

autojump

记住你进过的文件夹,下次直接进最深层:

1
brew install autojump

使用:

第一次进入:

1
cd limengting/limengting-test/src/main/java

第二次进入直接:

1
j java

zsh-syntax-highlighting

高亮命令

1
2
brew install zsh-syntax-highlighting(貌似不用)
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

zsh-autosuggestions

记住你曾经输入过的命令,当你再次输入前几个命令的时候帮你自动匹配,让你工作更高效。

1
2
brew install zsh-autosuggestions(貌似不用)
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

,不要覆盖tab来做autosuggestion,在.zshrc中写入:

1
bindkey ',' autosuggest-accept

之前的插件统一增加到.zshrc的plugins里:

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

colorls

不需要再plugins里面添加colorls

colorls官网:https://github.com/athityakumar/colorls

ruby没权限的解决方法:https://blog.argcv.com/articles/4429.c

1
brew install ruby

.zshrc中增加一句:

1
export PATH="/usr/local/opt/ruby/bin:$PATH"  # /usr/local/opt/ruby/bin在前面

执行:

1
which gem

which gem验证后结果是/usr/local/opt/ruby/bin/gem

如果不是则:

1
2
/usr/local/opt/ruby/bin/gem install colorls
source $(dirname $(/usr/local/opt/ruby/bin/gem which colorls))/tab_complete.sh

https://github.com/athityakumar/colorls/issues/264

.zshrc中增加:

1
2
3
export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH=$PATH:$(ruby -e 'puts Gem.bindir') # 这句要在上一句后面,确保用的是local环境的ruby
alias ls='colorls --sd'

如果要显示隐藏文件/文件夹:

1
ls -A

vim配色

.vimrc中写入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
set nocompatible  "关闭与VI的兼容
set number "显示行号
filetype on
set history=1000
set background=dark "设置背景为灰色
syntax on "打开语法高亮显示
set autoindent "自动对齐,使用上一行的对齐方式
set smartindent "智能对齐方式
set tabstop=4
set shiftwidth=4
set showmatch "设置匹配模式,类似当输入一个左括号时匹配上相应的那个右括号
set guioptions-=T
set vb t_vb=
set ruler "在编辑过程中,在右下角显示光标位置的状态行
set nohls
set incsearch "搜索自动定位
if has("vms")
set nobackup
else
set backup
endif

cat高亮

1
2
brew install python
pip3 install Pygments

安装报错:

1
2
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pygments'
Consider using the `--user` option or check the permissions.

https://github.com/sindresorhus/weechat-notification-center/issues/1

执行:

1
sudo chown -R $USER /Library/Python/2.7

重新安装成功后.zshrc中添加:

1
alias cat='pygmentize -P style=monokai -P tabsize=4 -f terminal256 -g'

重新加载.zshrc

1
source ~/.zshrc

centos虚拟机shell配色修改

主要指的是自己的vps或者公司的开发机,由于有连接外网的限制,不适合弄很多花哨的配色,只需要能够简单的高亮即可。

在.bashrc中添加:

1
2
3
4
5
6
7
alias ls='ls --color=auto'
alias la='ls -a --color=auto'
alias vi='vim'
alias dir='ls --color=auto'
alias tail0='tail -f -n0'
alias git-push='git push origin HEAD:refs/for/master'
export PS1="[\e[33m\u\e[37m@\e[35m\H\e[37m:\e[36m\$PWD\e[0m]\$ "
1
source .bashrc

如果登录shell没有自动加载.bashrc,在/etc/profile中添加:

1
2
3
if [ -s ~/.bashrc ]; then
source ~/.bashrc;
fi

IDE字体更改

新电脑其他更改

更换homebrew源

1
2
3
4
5
6
7
8
# 进入brew主目录
$ cd `brew --repo`

# 更换镜像
$ git remote set-url origin https://git.coding.net/homebrew/homebrew.git

# 测试效果
$ brew update

git在新电脑配置

生成公私钥

1
ssh-keygen -t rsa

如果要指定文件名

1
ssh-keygen -t rsa -f id_rsa.limengting01

生成的~/.ssh/id_rsa是私钥,~/.ssh/id_rsa.pub是公钥

配置名字

1
2
git config --global user.email "Sunnie.alexandratou@outlook.com"
git config --global user.name "limengting"

hexo在新电脑配置

本地

1
2
brew install node
npm install -g hexo-cli

远程

增加新电脑公钥到authorized_keys给新电脑增加权限:

先用有登陆权限的机器登上vps 或者在腾讯云上登陆:

输入账号root,和密码(如果密码忘了可以点击更多重置密码)

再把本地的~/.ssh/id_rsa.pub粘贴到vps上的~/.ssh/authorized_keys里面

1
2
root@VM-0-12-ubuntu:~# cd .ssh
root@VM-0-12-ubuntu:~/.ssh# vim authorized_keys

新电脑iterm2配置

拉代码创建文件夹显示错误

1
fatal: could not create leading directories of 'xxx': Permission denied

设置iterm2完全访问:

增加权限:

1
sudo chmod -R 755 .

.ssh报错:

1
2
3
4
Permissions 0755 for '/Users/limengting01/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/limengting01/.ssh/id_rsa": bad permissions

减少.ssh/id_rsa权限:

1
chmod 600 ~/.ssh/id_rsa

在所有者是root的文件夹下依然无法创建文件,cd 到该文件夹下增加权限

1
2
cd ~/baidu
sudo chmod -R 777 .

新电脑.zshrc配置

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
export ZSH="/Users/limengting01/.oh-my-zsh"

alias vps='ssh root@123.207.143.168'

ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE="nerdfont-complete" # 使用nerdfont字体

export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH=$PATH:$(ruby -e 'puts Gem.bindir') # 这句要在上一句后面,确保用的是local环境的ruby
alias ls='colorls --sd'

alias cat='pygmentize -P style=monokai -P tabsize=4 -f terminal256 -g'
alias relay='xxx' # 登陆公司堡垒机

plugins=(
git
extract
zsh-syntax-highlighting
zsh-autosuggestions
autojump
sublime
)
source $ZSH/oh-my-zsh.sh

bindkey ',' autosuggest-accept
谢谢小天使请我吃糖果
0%