常用配置

Last Edited Time
Aug 24, 2022 08:48 AM
date
Jan 3, 2018
slug
common-config
status
Published
tags
Bash
ZSH
VIM
Notebook
summary
Mac 常用命令 + ZSH 配置 + Vim 配置
type
Post

CentOS 初始化安装

dnf install -y git zsh
dnf copr enable atim/zoxide
dnf install -y zoxide
curl -sS https://webinstall.dev/zoxide | bash
sh -c "$(curl -sL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" --unattended
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
echo """
plugins=(zsh-syntax-highlighting zsh-autosuggestions)
source \$ZSH/oh-my-zsh.sh
eval \"\$(zoxide init zsh)\"
alias j='z'
""" >> ~/.zshrc

Common Used Settings

ZSH

plugins=(fzf-tab zsh-syntax-highlighting zsh-autosuggestions fzf)
source $ZSH/oh-my-zsh.sh

# Custom
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"                                       # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
source $(brew --prefix nvm)/nvm.sh

## fzf, key bindings (CTRL-T / CTRL-R / ALT-C) and fuzzy auto-completion is not enabled by default
export FZF_DEFAULT_OPTS="
--border
--layout=reverse
--info=inline
--height=80%
--multi
--preview-window=:hidden
--preview='([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--color='bg:-1,bg+:-1,preview-bg:-1,border:#66D9EF,pointer:#A6E22E,marker:#A6E22E'
--bind '?:toggle-preview'
--bind 'space:toggle'
"
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_ALT_C_COMMAND="fd --type d --hidden --follow --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# fzf autocompletion, for more info see fzf/shell/completion.zsh
_fzf_compgen_path() {
    fd --type f --hidden --follow --exclude .git . "$1"
}
_fzf_compgen_dir() {
    fd --type d --hidden --follow --exclude .git . "$1"
}
bindkey "ç" fzf-cd-widget

## fuck
eval $(thefuck --alias)

## zoxide
eval "$(zoxide init zsh)"

## alias
alias wtf='fuck'
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
alias rm='trash -F'
alias j='z'
alias flutter='fvm flutter'
alias miniflare='node ~/Code/personal/@faas/miniflare/packages/miniflare/bootstrap.js'

# Java
export PATH="/usr/local/opt/openjdk/bin:$PATH"
# Mysql Client
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
# Android Studio
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
# Flutter
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/jiyu/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2>/dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/jiyu/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/jiyu/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/jiyu/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

VIM Settings On Mac

install Vundle.vim first

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" file explorer
Plugin 'https://github.com/scrooloose/nerdtree.git'

" share NERDTree between tabs
Plugin 'jistr/vim-nerdtree-tabs'

" vim airline enhance
Plugin 'vim-airline/vim-airline'

" ctrlp finder
Plugin 'ctrlpvim/ctrlp.vim'

" editor config
Plugin 'editorconfig/editorconfig-vim'

" prettier
Plugin 'prettier/vim-prettier'

" smooth scroll
Plugin 'yuttie/comfortable-motion.vim'

" monokai color theme
Plugin 'tomasr/molokai'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

" enable syntax and use theme
syntax enable
colorscheme molokai

" set transparent background
highlight Normal ctermbg=none
highlight NonText ctermbg=none

set showcmd     " Show (partial) command in status line.
set mouse=n    " Enable mouse usage (normal mode)
set number      " Enable line number

" Buffer config
map <Tab> :bprevious<CR>
map <S-Tab> :bnext<CR>
map <C-w> :bw<CR>

" NERDTree config
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " auto close last NERDTree
let NERDTreeAutoCenter = 1 " auto center when name is too long
let NERDTreeQuitOnOpen = 1 " automatically close NerdTree when you open a file
let NERDTreeShowHidden = 1 " show hidden files
let g:airline#extensions#tabline#enabled = 1 " vim airline show all buffers when only have one tab
map <C-b> :NERDTreeTabsToggle<CR>

" Ctrl-P Config
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] " support .gitignore

" comfortable motion config
let g:comfortable_motion_no_default_key_mappings = 1 " <C-b> conflict, map the key manually
nnoremap <silent> <C-d> :call comfortable_motion#flick(100)<CR>
nnoremap <silent> <C-u> :call comfortable_motion#flick(-100)<CR>