首页 > 其他分享 >Mac终端美化(iterm2+oh-my-zsh+vim)

Mac终端美化(iterm2+oh-my-zsh+vim)

时间:2024-07-19 23:18:39浏览次数:18  
标签:git oh my iterm2 vim set zsh

vim + oh-my-zsh + git配置开发环境

vim配置

安装vundle

使用vundle作为插件管理器,使用前先安装vundle

mkdir -p ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

 

配置 .vimrc

编辑~/.vimrc文件,写入以下内容

set nocompatible
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'

" code complete
Plugin 'davidhalter/jedi-vim'
Plugin 'ervandew/supertab'

" syntastic check
Plugin 'nvie/vim-flake8'
Plugin 'scrooloose/syntastic'

" colorscheme
Plugin 'altercation/vim-colors-solarized'
Plugin 'luochen1990/rainbow' , {'for': 'python'}
Plugin 'morhetz/gruvbox'

" code format
Plugin 'mindriot101/vim-yapf'

" file search
Plugin 'ctrlpvim/ctrlp.vim'

call vundle#end()
filetype plugin indent on

colorscheme gruvbox

" for code complete
let g:jedi#auto_initialization = 1
let g:jedi#completions_enabled = 0
let g:jedi#show_call_signatures = 1


" for <leader>
let mapleader = ","
let g:mapleader = ","

" goto definition
let g:jedi#goto_definitions_command = ""
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_command = "<leader>d"

" file search
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
" serach file in MRU
nmap <Leader>f :CtrlPMRUFiles<CR>
" search file in BUffer
nmap <Leader>b :CtrlPBuffer<CR>


set number
set cursorline
set fileencoding=utf-8
set fencs=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set history=500
let python_highlight_all=1
set background=dark
set t_Co=256
set laststatus=2
set viminfo+=!
set showmatch
set matchtime=5
set ignorecase
set hlsearch
set autoindent
set cindent
set tabstop=4
set expandtab
set softtabstop=4
set shiftwidth=4
set autochdir
set autoread

highlight OverLength ctermbg=red ctermfg=white guibg=#592929
autocmd! FileType python match OverLength /\%89v.\+/

 

保存后打开vim,在normal模式下输入

:PluginInstall

vundle会自动安装配置的插件,之后就可以愉快地使用啦~

使用

配置后的效果如图

使用比较简单,主要是flake8和jedi的使用

flake8用于检查代码,编辑完后按快捷键F7进行检查

jedi用于代码补全和跳转,在函数名或者类名处按下, + d会跳转到定义处

ctrp用于文件搜索和跳转,按下, + f 调出搜索框,输入文件名进行搜索,按下, + b调出缓冲区文件,此快捷键配合

, + d可以在定义处和调用处来回跳转,非常好用

zsh配置

zsh是区别于bash的一种shell,比bash更好用

安装zsh

oh-my-zsh是基于zsh的一个主题,可以在其官网下载,地址:

以下两种方式任选一种安装

# 选择其一即可
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

 

配置.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="/root/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will 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 automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

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

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# 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.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# 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?
# Standard 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.
plugins=(
    git
    history
    zsh-syntax-highlighting
    zsh-completions
    extract
    )

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
bindkey ',' autosuggest-accept
source $ZSH/oh-my-zsh.sh
unsetopt share_history

# 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"

# 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"

export TERM=xterm-256color
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=247'


# for autojump
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh

 

安装插件

上面我们自己配置了一些插件,需要手动下载

安装zsh-autosuggestions

git clone git clone https://gitclone.com/github.com/zsh-users/zsh-autosuggestions.git /Users/username/.zsh/zsh-autosuggestions/

 

安装zsh-syntax-highlighting和zsh-completions

cd ~/.oh-my-zsh/plugins
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
git clone https://github.com/zsh-users/zsh-completions.git

刷新.zshrc文件

source ~/.zshrc

 使用

上面步骤完成后,就可以愉快地使用啦,效果如下图

提示符会显示当前的仓库和分支名,命令行也会自动补全,非常好用


git配置

原始的git没有颜色区分,看着不舒服,在~/.gitconfig里可以配置颜色,这样git statusgit diff就能很容易地看出修改来了

[user]
    email = [email protected]
    name = handsome

[alias]
    br = branch
    
[color]
    branch = auto
    diff = auto
    status = auto

[color "branch"]
    current = green
    local = white
    remote = green
    
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold

[color "status"]
    added = green
    changed = red
    untracked = red

git的使用效果留给大家自己去体验

这就是我自己的配置,如果大家有更好的配置可以告知我~

 

 

oh-my-zsh隐藏用户名或者主机名(主题去掉git目录多级显示)

oh-my-zsh隐藏用户名或者主机名

修改vim ~/.zshrc文件,在文件底部增加

隐藏用户名和主机名

prompt_context() {}

只保留用户名,隐藏主机名

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}

只保留主机名,隐藏用户名

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$HOST"
  fi
}

修改后执行 source ~/.zshrc才能生效,注:可以去掉$HOST避免重复显示路径

标签:git,oh,my,iterm2,vim,set,zsh
From: https://www.cnblogs.com/orzs/p/18312539

相关文章

  • python ssl报错 aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot
    报错信息原代码:asyncwithsession.post(url,headers=headers,data=payload)asresponse:print(f"{id}签到结果:",awaitresponse.text())原因:在使用aiohttp进行HTTPS请求时,如果没有设置正确的SSL证书验证,就可能会出现以上问题解决办法忽略SSL......
  • AutoHotKey自动热键(五)添加WINDOWS秘笈指令-输入瞬间启动功能
    在AUTOHOTKEY的使用中,不仅仅可以监听组合热键,还可以监听正常文本击键录入,这是另一种监听方式,比如依次击键jsq之后直接弹出<计算器>工具,或者依次击键sj之后直接输出135****5564的手机号码,等等,这就是autohotkey的录入击键监听,以双冒号为开头::因这种录入监听像极了......
  • debian12安装zsh及ohmyzsh
    1.安装基本工具sudoaptupdate&&sudoaptupgrade-ysudoaptinstallzshgitcurl-y2.设置默认终端chsh-s/bin/zsh3.安装zsh通过下列任一方式安装:MethodCommandcurlsh-c"$(curl-fsSLhttps://install.ohmyz.sh/)"wgetsh-c"$(wget-O-https......
  • nohup命令:Linux保持进程运行的利器
    在Linux系统中,nohup命令是一种非常有用的工具,用于在用户退出登录或关闭终端时保持进程的运行。本文将深入讲解nohup命令的作用、使用方法以及相关注意事项,帮助读者充分利用这个强大的命令。nohup命令的作用​nohup​是"nohangup"的缩写,它的主要作用是在后台运行一个命令或进......
  • centos系统构建安装john导致的编译问题error: size of array element is not a multip
    blake2.h:112:5:error:sizeofarrayelementisnotamultipleofitsalignment112|blake2b_stateS[4][1];|^~~~~~~~~~~~~blake2.h:113:5:error:sizeofarrayelementisnotamultipleofitsalignment113|blake2b_stateR[1];......
  • COOIS/COHV增强
    1、文档说明本文档介绍COOIS/COHV事务码中常用的选择屏幕增强和ALV增强2、选择屏幕增强COOIS生产订单抬头选择屏幕添加筛选条件,并将自定义数据添加到报表 选择屏幕新增筛选字段函数模块中,将选择屏幕筛选条件抛到内存。此处可以优化,将不属于自定义删选条件去掉,只抛自定义筛......
  • Johnson-Lindenstrauss Lemma 随即投影
    michael 作者忘忧草不是大佬。我感觉我说的挺具体的了,一共就两行代码,一行构建随机矩阵,一行做矩阵乘法。你会python的话可以这么写:g_matrix=numpy.random.normal(size=(n,m))output=numpy.matmul(input,g_matrix)2021-12-08​回复​1mic......
  • Johnson法则
    2条的流水作业调度问题的贪心做法。题目:有n个作业要在两台机器M1和M2组成的流水线上完成加工。每个作业i都必须先花时间ai在Mi上加工,然后花时间bi在M2上加工确定n个作业的加工顺序,使得从作业1在机器M1上加工开始到作业n在机器M2上加工为止所用的总时间最短做法:(1)把所有......
  • 13、爬虫-协程-asyncio和异步操作-aiohttp
    概念:当程序sleep或者input、output等待的时候、cpu是处于堵塞状态的、cpu此时是不再为我们的代码服务的、所以协程就是当遇到了前面这种情况的时候可以选择性的切换到其他任务上 同步协程:asyncio当程序在睡眠的时候注意加上:awaitasyncio.sleep(2)"""多任务协程asyncio......
  • 14、爬虫-异步协程爬取西游记小说-aiohttp-aiofiles
     注意:有关所有的IO操作都要加上:await挂起 """https://dushu.baidu.com/pc/detail?gid=4306063500#小说网站https://dushu.baidu.com/api/pc/getCatalog?data={%22book_id%22:%224306063500%22}#可以拿到每个章节的bookid、cid(每个章节的id)、这里%22相当于"号htt......