[Mac] iTerm2 + Powerline + Vim 設定
[Mac] iTerm2 + Powerline + Vim 設定
Update: 2020/08/22
Env
OS Version: macOS High Sierra 10.13.4 ---> 10.14.4 ---> 10.15.6 (Catalina)
iTerm2 Version: 3.1.6 ---> 3.2.8 ---> 3.3.12
Bash Verison: 3.2.57(1)
Zsh Version: 5.7.1 (macOS default) ---> 5.8 (from brew because of the powerlevel10k's theme asked for)
Python Version: 3.6 ---> 3.7 ---> 3.7.2_2 ---> 3.8.2
Pip Version: 10.0.1 ---> 18.0 ---> 19.0.3 ---> 20.2.2
Powerline Version: 2.6 ---> 2.7
Vim Version: stable 8.1
因為mac有點怪怪的所以後來整個重灌,這次因為直接用Catalina的ISO檔來安裝,所以算是原生的64 bit環境,不像之前那樣是慢慢升級上來的情況,滿多東西有了不少改變。
另外,Cataline Terminal預設就是zsh而非bash,所以之前安裝Powerline的方式就變了很多,以前因本人不用zsh,所以都不會去安裝oh-my-zsh,但是這次就必須安裝了.......為了zsh的主題。
## 1. 先安裝brew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" ## 2. 安裝之後會用到的字型 brew tap homebrew/cask-fonts brew cask install font-hack-nerd-font or brew cask install font-fira-code ## 3. 不用oh-my-zsh直接用brew安裝的方式 brew install romkatv/powerlevel10k/powerlevel10k echo 'source /usr/local/opt/powerlevel10k/powerlevel10k.zsh-theme' >>! ~/.zshrc ## 3. 安裝oh-my-zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" vim ~/.zshrc ZSH_DISABLE_COMPFIX=true ## 3.1 安裝oh-my-zsh plugins # zsh-completions: git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions vim ~/.zshrc plugins=(git zsh-completions) # zsh-syntax-highlighting: git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting vim ~/.zshrc plugins=(git zsh-completions zsh-syntax-highlighting) ## 4. 安裝powerline pip install --user powerline-status pip show powerline-status ## 4.1 Get PATH /Users/fiona/Library/Python/3.8/lib/python/site-packages ## 5. Config vim ~/.zprofile PATH=${PATH}:/Users/fiona/Library/Python/3.8/bin ## 6. 安裝Powerlevel10k for oh-my-zsh git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k vim ~/.zshrc ZSH_THEME="powerlevel10k/powerlevel10k" ## 7. Restart your iTerm2 and begin the powerlevel10k's installation. ## 8. Vim config git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim vim ~/.vimrc " vundle config filetype off set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' Plugin 'Lokaltog/vim-powerline' call vundle#end() set encoding=utf-8 set laststatus=2 set t_Co=256 # Open vim vim test :PluginInstall (Preview) :PluginInstall (Install)
2019 Update Info
這個月突然想到brew很久沒更新了,想說更新一下,結果沒想到brew的vim版本一更新完,
我的Powerline又壞掉了QAQ
查了一下都說是Vim 8.1.1050版本預設改用python3,但是因為用brew安裝python的時候會連python2一起裝,
變成系統會是python代表python2.7.16,python3才是python3.7.2_2,結果會出現下面的錯誤,
所以只好先移除Vim,然後修改bash_profile內的別名(Alias),讓brew執行python的時候先去跑python3,再來安裝Vim之後就可以正常安裝了,
brew uninstall vim
vim ~/.bash_profile
alias python="python3"
source ~/.bash_profile
brew install vim
這樣安裝完之後Powerline就可以繼續正常使用囉,記得在把別名(Alias)改回原來的樣子就好!
我有看到另一種解法,直接brew uninstall python@2
後再安裝Vim
就好了,這個就太猛了XD
2018 Update Info
Python3.6更新到Python3.7之後,我的Powerline就壞掉(Crashed)了QAQ
原因是Mac版的Python3.6升級到3.7後,之前pip install的套件都不見了==|||
所以只好重新安裝,重新安裝並且修改PATH路徑後就正常了。
Pre-install
這邊紀錄在macOS上面設定Powerline的過程,當然要設定前有些基本條件要做,像是用Homebrew安裝python、vim,字型檔(Fronts)的安裝等等,
安裝開者版本(目前在我的環境macOS High Seirra下會失敗,所以不建議)
pip3 install --user git+git://github.com/powerline/powerline
pip3 show powerline-status
# Path
/Users/fiona/Library/Python/3.6/lib/python/site-packages
安裝穩定版本
pip3 install powerline-status
pip3 show powerline-status
# Path
/usr/local/lib/python3.6/site-packages
Bash Shell配置方法
vim ~/.bash_profile
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/local/lib/python3.6/site-packages/powerline/bindings/bash/powerline.sh
如果畫面顯示文件、檔案都是單一顏色(Single Color),而不是彩色(Colors)的話,可以在檔案中加上以下設定,
export CLICOLOR=1
export TERM=xterm-256color
Vim配置方法
brew install vim --with-python --with-ruby --with-perl
上面這個要先做,不然下面的設定都會出現錯誤(Error)
set encoding=utf-8
source /usr/local/lib/python3.6/site-packages/powerline/bindings/vim/plugin/powerline.vim
set laststatus=2
set t_Co=256
or
set encoding=utf-8
set rtp+=/usr/local/lib/python3.6/site-packages/powerline/bindings/vim
set laststatus=2
set t_Co=256
Reference
https://powerline.readthedocs.io/en/latest/installation.html#repository-root
https://blog.csdn.net/leiyu231/article/details/73800064
https://coderwall.com/p/yiot4q/setup-vim-powerline-and-iterm2-on-mac-os-x
http://cenalulu.github.io/linux/mac-powerline/
https://blog.codefront.net/2013/10/27/installing-powerline-on-os-x-homebrew/
https://superuser.com/questions/399594/color-scheme-not-applied-in-iterm2
https://apple.stackexchange.com/questions/33677/how-can-i-configure-mac-terminal-to-have-color-ls-output
https://ltaoo.github.io/2018/10/22/更新%20macOS%20Mojave%20后%20vim%20打不开/