Win7 安装cygwin以及设置

安装

  1. 先去官网下载安装文件。cygwin_com/install_html(把下划线换为.)32位的选setup-x86.exe64位的选setup-x86_64.exe。下载完毕后,一定要通过邮件菜单 以管理员的身份运行 。
  2. 运行之后在选择镜像文件地址的时候,一般在国内都是选择mirrors.163.com/cygwin/ 毕竟速度快些。出错的原因是后来出现X86和X86_64两个文件夹,所以找不到对应的setup.ini文件了。应对的方法就是 添加具体的地址。
    如果是 32位的就添加 http://mirrors.163.com/cygwin/x86/
    如果是 64位的就添加 http://mirrors.163.com/cygwin/x86_64。
  3. 包选择 autoconf2. ,automake1.1 ,binutil ,gcc-cor ,gcc-g ,gd ,pcre ,pcre-devel ,make ,vim ,git,python

第一次启动时会生成Home目录,在${cygwin}/home/${YOUR_USER_NAME}。${cygwin}表示你的cygwin安装目录。

显示设置

  1. 调整${HOME}/.bashrc文件,把注释掉别名打开:

    alias df='df -h'
    alias du='du -h'
    
    alias whence='type -a'                        # where, of a sort
    alias grep='grep --color'                     # show differences in colour
    alias egrep='egrep --color=auto'              # show differences in colour
    alias fgrep='fgrep --color=auto'              # show differences in colour
    
    alias ls='ls -h --color=tty'                 # classify files in colour
    alias dir='ls --color=auto --format=vertical'
    alias vdir='ls --color=auto --format=long'
    alias ll='ls -l'                              # long list
    alias la='ls -A'                              # all but . and ..
    alias l='ls -CF'                              #
    alias wch='which -a'
    

    这样调整后,可以ls、grep、dir输出彩色显示。另外加上命令的-h选项,这样文件大小以K、M、G显示,方便人阅读。

  2. git输出(比如log、status)彩色显示,使用下面的命令配置:

    git config --global color.ui auto
    
  3. vi配置
    在${HOME}/.vimrc文件中加上: # 没有.vimrc文件就新建。

    set number
    set hlsearch
    set fileencoding=utf-8
    set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
    
    set nocompatible
    set backspace=indent,eol,start
    
    syntax enable
    

    说明:

    1. syntax enable:打开语法高亮。cygwin的vi缺省没有打开。
    2. set nocompatible和set backspace:配置backspace键,缺省backspace不起作用。
    3. set fileencoding和set fileencodings:缺省文件编码和自动识别文件编码顺序
    4. set number:显示行号
    5. set hlsearch:搜索到内容高亮
  4. 配置盘符的链接
    到D盘,要/cygdrive/d,可以新建符号链接/d,这样可以减少录入(MSYS的做法)

    ln -s /cygdrive/c /c
    ln -s /cygdrive/d /d
    ln -s /cygdrive/e /e
    
  5. 自动补全不区分大小写

    1. ~/.bashrc文件中添加:
      shopt -s nocaseglob
      
    2. ~/.inputrc文件中添加:
      set completion-ignore-case on
      
  6. 配置按单词移动/删除

    1. .inputrc文件中添加:
      # Ctrl+Left/Right to move by whole words
      "\e[1;5C": forward-word
      "\e[1;5D": backward-word
      # Ctrl+Backspace/Delete to delete whole words
      "\e[3;5~": kill-word
      "\C-_": backward-kill-word
      
  7. Windows命令的乱码

    1. 在用户目录(cd ~)里的.bash_profile文件末尾添加如下代码
      export LC_ALL=zh_CN.GBK
      export LC_CTYPE=zh_CN.GBK
      export LANG=zh_CN.GBK
      export XMODIFIERS=@im=Chinput3
      stty cs8 -istrip
      stty pass8
      export LESSCHARSET=latin1
      
    2. 同样是~目录,去掉.inputrc文件中一下代码的注释(前面的#号)
      set meta-flag on
      set convert-meta off
      set input-meta on
      set output-meta on 
      
    3. 还是~目录,.bashrc文件中添加代码
      alias ls='ls --color --show-control-chars'
      
    4. Cygwin的options设置Texts:
      • locale = zh_CN
      • Character set = GBK
    5. 重启Cygwin。
posted @ 2017-10-11 16:24  SPPan  阅读(1071)  评论(0)    收藏  举报