[TOC]
安裝
官方網(wǎng)站
http://www.cygwin.com/
下載安裝
http://www.cygwin.com/setup-x86_64.exe
cygwin安裝目錄是C:\cygwin64\

cygwin程序依賴(lài)目錄是

建議選則國(guó)內(nèi)源,速度塊,且可以不斷更新

建議選則國(guó)內(nèi)源,速度塊
- 清華源 https://mirrors.tuna.tsinghua.edu.cn/cygwin/
清華源幫助 tsinghua help - 163源 http://mirrors.163.com/cygwin/
- 東軟源 http://mirrors.neusoft.edu.com/
- 搜狐源 http://mirrors.sohu.com/cygwin/
必用插件
在search中輸入 vim 等待片刻就會(huì)搜索出 vim 相關(guān)的模塊

圖中keep表示已經(jīng)安裝完成,未安裝的點(diǎn)擊 成 install
常用安裝
vim - 默認(rèn)沒(méi)有安裝,請(qǐng)自行勾選后安裝
dos2unix 轉(zhuǎn)換 win 的腳本讓 unix 可用
curl(Net)
wget(Web)
time (GUN time commond)
推薦一定安裝
dos2unix用于修復(fù) windows 換行符導(dǎo)致的腳本報(bào)錯(cuò)^m無(wú)法運(yùn)行的錯(cuò)誤
配置
加入右鍵菜單
如果安裝目錄修改過(guò),請(qǐng)自行替換腳本或者配置的對(duì)應(yīng)目錄
新建文件 cygwinRegDirShell.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin]
""="CygWin Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin]
"Icon"="C:\\cygwin64\\Cygwin.ico"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin]
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin\command]
""="C:\\cygwin64\\Cygwin.bat %V"
運(yùn)行這個(gè)腳本即可寫(xiě)入注冊(cè)表
或者Win+R 輸入 regedit
進(jìn)入節(jié)點(diǎn) HKEY_CLASSES_ROOT\Directory\Background\shell
鼠標(biāo)右鍵,選擇新建->項(xiàng)填寫(xiě)cygwin 在右側(cè)窗口填入值

右側(cè)數(shù)值添加 鼠標(biāo)右鍵 新建->字符串值
| 名稱(chēng) | 類(lèi)型 | 數(shù)據(jù) |
|---|---|---|
| 默認(rèn) | REG_SZ | CygWin Here |
| Icon | REG_SZ | C:\cygwin64\Cygwin.ico |
| NoWorkingDirectory | REG_SZ |

然后鼠標(biāo)右鍵剛創(chuàng)建的 cygwin,選擇新建->項(xiàng),填寫(xiě)command
在右側(cè)填入
| 名稱(chēng) | 類(lèi)型 | 數(shù)據(jù) |
|---|---|---|
| 默認(rèn) | REG_SZ | C:\cygwin64\Cygwin.bat %V |

- 然后進(jìn)入cygwin 安裝目錄修改
Cygwin.bat文件
@echo off
setlocal enableextensions
set TERM=
set _T=%*
C:
chdir C:\cygwin64\bin
bash --login -i
修改.bash_profile文件,在C:\ctgwin64\home\[用戶名]\下, 在文件的最后增加
# Set CygWin Right Click open with folder
export _T=${_T//\\//} # replace backslash to fowardslash
if [[ $_T == "" ]]; then
export _T="c:/Users/${USER}"
fi
cd "$_T"
如果沒(méi)用找到.bash_profile文件,運(yùn)行一次 cygwin 將生成用戶文件基礎(chǔ)配置文件
換行符風(fēng)格
因?yàn)?win 的換行符不能在其他系統(tǒng)上使用,安裝 dos2unix 工具,再需要轉(zhuǎn)換的文本處執(zhí)行
dos2unix [filePath]
cygwin中文亂碼
這里是針對(duì)GBK亂碼,如果沒(méi)有亂碼就不需要修改
進(jìn)入用戶目錄, 打開(kāi)目錄下 .bash_profile 文件
cd ~
vim .bash_profile
將如下內(nèi)容添加到文件的末尾
## for windows GBK
export LC_CTYPE=zh_CN.GBK
export LANG=zh_CN.GBK
export OUTPUT_CHARSET=GBK
export XMODIFIERS=@im=Chinput3
stty cs8 -istrip
stty pass8
export LESSCHARSET=latin1
然后打開(kāi)用戶根目錄的 .inputrc 文件,解開(kāi)注釋
# Allow 8-bit input/output
增加bash 對(duì)8 字節(jié)字符處理
加載配置生效
source ~/.bash_profile
文件作色
修改~/.bashrc 在最末尾增加內(nèi)容
alias ls='ls -F -N --color=auto'
然后執(zhí)行 source ~/.bashrc
用戶環(huán)境變量
- 用戶環(huán)境變量,在
~/.bash_profile的Set CygWin 前添加,以后的設(shè)置也這樣
alias ls='ls -hG'
alias ll='ls -l'
alias la='ls -a'
alias l='ls -CF'
alias gs='git status'
然后執(zhí)行 source ~/.bash_profile
vim基礎(chǔ)配置
在用戶的跟新建文件 vim ~/.vimrc 內(nèi)容有
" windows backspace can delete
set backspace=indent,eol,start
" open syntax
syntax on
" close compatible like annotate
:set nocompatible
" set not show line number can change by :set nu
:set nonu
" show cmd
:set showcmd
" set show line number when in edit
:set ruler
" set tab button stop
" default tabstop=8
:set tabstop=4
:set softtabstop=4
:set shiftwidth=4
:set expandtab
" use keyboard F11 to change paste mode
:set pastetoggle=<F11>
" normal is :set nolist | show hide is :set invlist
:set nolist
如果想使用 vi 類(lèi)似 vim 需要修改成這樣
" windows backspace can delete
set backspace=indent,eol,start
" open syntax
syntax on
" close compatible like annotate
set nocompatible
" set not show line number can change by :set nu
:set nonu
" show cmd
set showcmd
" set show line number when in edit
:set ruler
" set tab button stop
" default tabstop=8
:set tabstop=4
:set softtabstop=4
:set shiftwidth=4
:set expandtab
" use keyboard F11 to change paste mode
:set pastetoggle=<F11>
" normal is :set nolist | show hide is :set invlist
:set nolist
set wildmenu
set fo=cqrt
set laststatus=2
set textwidth=78
set ww=<,>,h,l
set autoindent
" set no error bells
set noeb visualbell
let mapleader = ","
syn on
filetype on
filetype plugin on
filetype indent on
shell老是提示\r錯(cuò)誤
檢查shell 內(nèi)容錯(cuò)誤cat -v
解決方法是對(duì)文件進(jìn)行換行風(fēng)格處理
sed 's/..$//g' srcfile > destfile
ssh / git-ssh配置
win+r 運(yùn)行 cygwin
cd ~
mkdir .ssh
cd .ssh
sshkey-gen -t rsa -C "your@mail.com"
輸入文件別名的生成 some-git.pub 和 some-git
然后配置本地ssh設(shè)置
vim config
# 輸入內(nèi)容為
Host gitlab.yougit.com
HostName gitlab.yougit.com
IdentityFile ~/.ssh/some-git
如果是ssh遠(yuǎn)程到服務(wù)器,可以添加
- User 來(lái)設(shè)置用戶
Host youserver.host.com
HostName 192.168.1.101
User mine
IdentityFile ~/.ssh/my_server
配置服務(wù)端
cat some-git.pub
把輸出的內(nèi)容配置到服務(wù)端