├── .vim ├── ftdetect │ ├── json.vim │ └── gofiletype.vim ├── syntax │ ├── cpp.vim │ ├── godoc.vim │ └── go.vim ├── ftplugin │ └── go │ │ ├── fmt.vim │ │ ├── test.sh │ │ └── import.vim ├── indent │ ├── go.vim │ └── python.vim ├── autoload │ └── go │ │ └── complete.vim ├── readme.txt └── plugin │ └── godoc.vim ├── linux ├── .inputrc ├── .gitignore ├── init_tmux.sh ├── .screenrc ├── install_ruby2.sh ├── .aliases ├── init_rc.sh ├── apt_install.sh ├── .tmux.conf ├── json.vim ├── .bashrc └── .zshrc ├── .gitconfig ├── nvim ├── init.sh └── init.lua ├── .vimrc └── mac └── .zshrc /.vim/ftdetect/json.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.json set filetype=json 2 | -------------------------------------------------------------------------------- /.vim/syntax/cpp.vim: -------------------------------------------------------------------------------- 1 | "highlight Functions 2 | syn match cFuntions display "[a-zA-Z_]\{-1,}\s\{-0,}(\{1}"ms=s,me=e-1 3 | hi def link cFuntions Title 4 | -------------------------------------------------------------------------------- /linux/.inputrc: -------------------------------------------------------------------------------- 1 | "\e[A": history-search-backward 2 | "\e[B": history-search-forward 3 | set show-all-if-ambiguous on 4 | set completion-ignore-case on 5 | set bell-style none 6 | -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | *.demo 3 | *swp 4 | *.out 5 | *.o 6 | *.d 7 | *.ut 8 | log 9 | main 10 | lib*.a 11 | *_demo 12 | segdict* 13 | tmp 14 | t.* 15 | *.pid 16 | tags 17 | build 18 | node_modules 19 | .vim/bundle 20 | -------------------------------------------------------------------------------- /linux/init_tmux.sh: -------------------------------------------------------------------------------- 1 | test -d ~/.tmux || mkdir ~/.tmux 2 | cd ~/.tmux 3 | test -d tmux-resurrect || git clone https://github.com/tmux-plugins/tmux-resurrect.git 4 | test -d tmux-continuum || git clone https://github.com/tmux-plugins/tmux-continuum.git 5 | -------------------------------------------------------------------------------- /.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = yanyiwu 3 | email = wuyanyi09@foxmail.com 4 | [alias] 5 | st = status 6 | ci = commit 7 | co = checkout 8 | pr = pull --rebase 9 | [color] 10 | ui = true 11 | [push] 12 | default = simple 13 | [submodule] 14 | recurse = true 15 | -------------------------------------------------------------------------------- /nvim/init.sh: -------------------------------------------------------------------------------- 1 | ln -fs ~/etc/nvim/init.lua ~/.config/nvim/init.lua 2 | 3 | git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim 4 | git clone https://github.com/github/copilot.vim.git ~/.config/nvim/pack/github/start/copilot.vim 5 | -------------------------------------------------------------------------------- /linux/.screenrc: -------------------------------------------------------------------------------- 1 | hardstatus alwayslastline 2 | hardstatus string "%{.bW}%-w%{.rY}%n %t%{-}%+w %=%{..G} %c:%s " 3 | startup_message off 4 | vbell off 5 | bind ' ' title 6 | bindkey -k k; title 7 | bindkey -k F1 prev 8 | bindkey -k F2 next 9 | #defencoding GBK 10 | #encoding GBK UTF-8 11 | 12 | bindkey "^[j" prev 13 | bindkey "^[k" next 14 | -------------------------------------------------------------------------------- /linux/install_ruby2.sh: -------------------------------------------------------------------------------- 1 | sudo apt-get -y update 2 | sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev 3 | cd /tmp 4 | wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz 5 | tar -xvzf ruby-2.0.0-p481.tar.gz 6 | cd ruby-2.0.0-p481/ 7 | ./configure --prefix=/usr/local 8 | make 9 | sudo make install 10 | -------------------------------------------------------------------------------- /.vim/syntax/godoc.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2011 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | 5 | if exists("b:current_syntax") 6 | finish 7 | endif 8 | 9 | syn case match 10 | syn match godocTitle "^\([A-Z]*\)$" 11 | 12 | command -nargs=+ HiLink hi def link 13 | 14 | HiLink godocTitle Title 15 | 16 | delcommand HiLink 17 | 18 | let b:current_syntax = "godoc" 19 | 20 | " vim:ts=4 sts=2 sw=2: 21 | -------------------------------------------------------------------------------- /linux/.aliases: -------------------------------------------------------------------------------- 1 | alias ls='ls --color=auto' 2 | alias grep='grep --color=auto' 3 | alias fgrep='fgrep --color=auto' 4 | alias egrep='egrep --color=auto' 5 | alias rm='rm -i' 6 | alias ll='ls -alF' 7 | alias la='ls -A' 8 | alias l='ls -CF' 9 | 10 | alias rrm='/bin/rm -rf' 11 | alias rm='mv --target-directory ~/.trash' 12 | alias mv='mv -i' 13 | alias cp='cp -i' 14 | export CLASSPATH=$CLASSPATH:.:build/lucene-core-3.0.3-dev.jar:build/lucene-demos-3.0.3-dev.jar 15 | alias vi='vim -O' 16 | alias dropbox='~/etc/linux/dropbox_uploader.sh' 17 | alias pyconv='~/etc/pytools/pyconv.py' 18 | 19 | alias gitpush='git push origin HEAD' 20 | -------------------------------------------------------------------------------- /linux/init_rc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | test -d ~/.trash || mkdir ~/.trash 3 | #cp -r .gitconfig .inputrc .bashrc .vim .vimrc .screenrc .zshrc .tmux.conf ~ 4 | ln -fs ~/etc/linux/.vim ~ 5 | test -d ~/.vim/bundle/Vundle.vim || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim 6 | ln -fs ~/etc/linux/.vimrc ~ 7 | ln -fs ~/etc/linux/.gitconfig ~ 8 | ln -fs ~/etc/linux/.inputrc ~ 9 | ln -fs ~/etc/linux/.bashrc ~ 10 | ln -fs ~/etc/linux/.screenrc ~ 11 | ln -fs ~/etc/linux/.zshrc ~ 12 | ln -fs ~/etc/linux/.tmux.conf ~ 13 | #git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle 14 | test -d ~/.oh-my-zsh || git clone git@github.com:yanyiwu/oh-my-zsh.git ~/.oh-my-zsh 15 | -------------------------------------------------------------------------------- /linux/apt_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | INSTALL="apt-get install -y" 3 | UPDATE="apt-get update" 4 | 5 | $UPDATE 6 | 7 | $INSTALL vim; 8 | $INSTALL git git-core git-completion; 9 | $INSTALL ssh screen tmux; 10 | $INSTALL curl; 11 | $INSTALL make; 12 | $INSTALL cmake; 13 | $INSTALL clang; 14 | $INSTALL npm; 15 | $INSTALL zsh; 16 | 17 | #chrome 18 | #$INSTALL chromium-browser; 19 | 20 | #cpp 21 | $INSTALL g++; 22 | 23 | #python 24 | $INSTALL python-setuptools python-mysqldb pylint 25 | 26 | 27 | #ice communication 28 | #$INSTALL ice34-services ice34-slice ice34-translators; 29 | 30 | 31 | #java 32 | #$INSTALL openjdk-7-jdk; 33 | 34 | #mysql:need user to set mysql root password 35 | #$INSTALL mysql-server mysql-server-core mysql-client-core 36 | 37 | $INSTALL ruby1.9.1-dev 38 | gem install jekyll 39 | -------------------------------------------------------------------------------- /.vim/ftdetect/gofiletype.vim: -------------------------------------------------------------------------------- 1 | " We take care to preserve the user's fileencodings and fileformats, 2 | " because those settings are global (not buffer local), yet we want 3 | " to override them for loading Go files, which are defined to be UTF-8. 4 | let s:current_fileformats = '' 5 | let s:current_fileencodings = '' 6 | 7 | " define fileencodings to open as utf-8 encoding even if it's ascii. 8 | function! s:gofiletype_pre() 9 | let s:current_fileformats = &g:fileformats 10 | let s:current_fileencodings = &g:fileencodings 11 | set fileencodings=utf-8 fileformats=unix 12 | setlocal filetype=go 13 | endfunction 14 | 15 | " restore fileencodings as others 16 | function! s:gofiletype_post() 17 | let &g:fileformats = s:current_fileformats 18 | let &g:fileencodings = s:current_fileencodings 19 | endfunction 20 | 21 | au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix 22 | au BufRead *.go call s:gofiletype_pre() 23 | au BufReadPost *.go call s:gofiletype_post() 24 | -------------------------------------------------------------------------------- /linux/.tmux.conf: -------------------------------------------------------------------------------- 1 | set -g prefix ^a 2 | unbind ^b 3 | bind a send-prefix 4 | 5 | #set -g status-right "#[fg=green]#(uptime.pl)#[default] . #[fg=green]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default]" 6 | set -g status-right '%H:%M:%S %d-%b-%y' 7 | 8 | set -g status-bg blue 9 | set -g status-fg yellow 10 | 11 | #set-window-option -g window-status-current-fg white 12 | #set-window-option -g window-status-current-bg red 13 | #set-window-option -g window-status-current-attr bright 14 | set-window-option -g window-status-current-style "bg=red,fg=white,bright" 15 | 16 | # -n means no prefix 17 | bind-key -n F7 command-prompt 'rename-session %%' 18 | bind-key -n F10 command-prompt 'rename-window %%' 19 | bind-key -n F11 previous-window 20 | bind-key -n F12 next-window 21 | 22 | bind-key -n S-Left swap-window -t -1 23 | bind-key -n S-Right swap-window -t +1 24 | 25 | run-shell ~/.tmux/tmux-resurrect/resurrect.tmux 26 | run-shell ~/.tmux/tmux-continuum/continuum.tmux 27 | set -g @continuum-save-interval '60' 28 | -------------------------------------------------------------------------------- /nvim/init.lua: -------------------------------------------------------------------------------- 1 | vim.o.number = true 2 | vim.o.tabstop = 4 3 | vim.o.shiftwidth = 4 4 | vim.o.expandtab = true 5 | vim.o.autoindent = true 6 | vim.cmd("syntax on") 7 | vim.cmd("filetype plugin indent on") 8 | vim.cmd("set clipboard=unnamedplus") 9 | 10 | vim.cmd("command Q : q") 11 | vim.cmd("command W : w") 12 | vim.cmd("command Wq : wq") 13 | vim.cmd("command WQ : wq") 14 | 15 | -- Auto jump to the last cursor position 16 | vim.api.nvim_create_autocmd("BufReadPost", { 17 | pattern = "*", 18 | callback = function() 19 | local mark = vim.api.nvim_buf_get_mark(0, '"') 20 | local lcount = vim.api.nvim_buf_line_count(0) 21 | if mark[1] > 0 and mark[1] <= lcount then 22 | vim.api.nvim_win_set_cursor(0, mark) 23 | end 24 | end, 25 | }) 26 | 27 | 28 | if vim.fn.has('wsl') == 1 then 29 | vim.g.clipboard = { 30 | name = 'WslClipboard', 31 | copy = { 32 | ['+'] = 'clip.exe', 33 | ['*'] = 'clip.exe', 34 | }, 35 | paste = { 36 | ['+'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', 37 | ['*'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', 38 | }, 39 | cache_enabled = 0, 40 | } 41 | end 42 | 43 | require('packer').startup(function() 44 | use 'nvim-treesitter/nvim-treesitter' 45 | run = ':TSUpdate' 46 | end) 47 | 48 | require'nvim-treesitter.configs'.setup { 49 | ensure_installed = {"python"}, -- Install Python support 50 | highlight = { 51 | enable = true, 52 | }, 53 | } 54 | -------------------------------------------------------------------------------- /.vim/ftplugin/go/fmt.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2011 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | " 5 | " fmt.vim: Vim command to format Go files with gofmt. 6 | " 7 | " This filetype plugin add a new commands for go buffers: 8 | " 9 | " :Fmt 10 | " 11 | " Filter the current Go buffer through gofmt. 12 | " It tries to preserve cursor position and avoids 13 | " replacing the buffer with stderr output. 14 | " 15 | if exists("b:did_ftplugin_go_fmt") 16 | finish 17 | endif 18 | 19 | command! -buffer Fmt call s:GoFormat() 20 | 21 | function! s:GoFormat() 22 | let view = winsaveview() 23 | silent %!gofmt 24 | if v:shell_error 25 | let errors = [] 26 | for line in getline(1, line('$')) 27 | let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)') 28 | if !empty(tokens) 29 | call add(errors, {"filename": @%, 30 | \"lnum": tokens[2], 31 | \"col": tokens[3], 32 | \"text": tokens[4]}) 33 | endif 34 | endfor 35 | if empty(errors) 36 | % | " Couldn't detect gofmt error format, output errors 37 | endif 38 | undo 39 | if !empty(errors) 40 | call setloclist(0, errors, 'r') 41 | endif 42 | echohl Error | echomsg "Gofmt returned error" | echohl None 43 | endif 44 | call winrestview(view) 45 | endfunction 46 | 47 | let b:did_ftplugin_go_fmt = 1 48 | 49 | " vim:ts=4:sw=4:et 50 | -------------------------------------------------------------------------------- /.vim/indent/go.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2011 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | " 5 | " indent/go.vim: Vim indent file for Go. 6 | " 7 | " TODO: 8 | " - function invocations split across lines 9 | " - general line splits (line ends in an operator) 10 | 11 | if exists("b:did_indent") 12 | finish 13 | endif 14 | let b:did_indent = 1 15 | 16 | " C indentation is too far off useful, mainly due to Go's := operator. 17 | " Let's just define our own. 18 | setlocal nolisp 19 | setlocal autoindent 20 | setlocal indentexpr=GoIndent(v:lnum) 21 | setlocal indentkeys+=<:>,0=},0=) 22 | 23 | if exists("*GoIndent") 24 | finish 25 | endif 26 | 27 | function! GoIndent(lnum) 28 | let prevlnum = prevnonblank(a:lnum-1) 29 | if prevlnum == 0 30 | " top of file 31 | return 0 32 | endif 33 | 34 | " grab the previous and current line, stripping comments. 35 | let prevl = substitute(getline(prevlnum), '//.*$', '', '') 36 | let thisl = substitute(getline(a:lnum), '//.*$', '', '') 37 | let previ = indent(prevlnum) 38 | 39 | let ind = previ 40 | 41 | if prevl =~ '[({]\s*$' 42 | " previous line opened a block 43 | let ind += &sw 44 | endif 45 | if prevl =~# '^\s*\(case .*\|default\):$' 46 | " previous line is part of a switch statement 47 | let ind += &sw 48 | endif 49 | " TODO: handle if the previous line is a label. 50 | 51 | if thisl =~ '^\s*[)}]' 52 | " this line closed a block 53 | let ind -= &sw 54 | endif 55 | 56 | " Colons are tricky. 57 | " We want to outdent if it's part of a switch ("case foo:" or "default:"). 58 | " We ignore trying to deal with jump labels because (a) they're rare, and 59 | " (b) they're hard to disambiguate from a composite literal key. 60 | if thisl =~# '^\s*\(case .*\|default\):$' 61 | let ind -= &sw 62 | endif 63 | 64 | return ind 65 | endfunction 66 | -------------------------------------------------------------------------------- /.vim/autoload/go/complete.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2011 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | " 5 | " This file provides a utility function that performs auto-completion of 6 | " package names, for use by other commands. 7 | 8 | let s:goos = $GOOS 9 | let s:goarch = $GOARCH 10 | 11 | if len(s:goos) == 0 12 | if exists('g:golang_goos') 13 | let s:goos = g:golang_goos 14 | elseif has('win32') || has('win64') 15 | let s:goos = 'windows' 16 | elseif has('macunix') 17 | let s:goos = 'darwin' 18 | else 19 | let s:goos = '*' 20 | endif 21 | endif 22 | 23 | if len(s:goarch) == 0 24 | if exists('g:golang_goarch') 25 | let s:goarch = g:golang_goarch 26 | else 27 | let s:goarch = '*' 28 | endif 29 | endif 30 | 31 | function! go#complete#Package(ArgLead, CmdLine, CursorPos) 32 | let dirs = [] 33 | 34 | if executable('go') 35 | let goroot = substitute(system('go env GOROOT'), '\n', '', 'g') 36 | if v:shell_error 37 | echo '\'go env GOROOT\' failed' 38 | endif 39 | else 40 | let goroot = $GOROOT 41 | endif 42 | 43 | if len(goroot) != 0 && isdirectory(goroot) 44 | let dirs += [ goroot ] 45 | endif 46 | 47 | let workspaces = split($GOPATH, ':') 48 | if workspaces != [] 49 | let dirs += workspaces 50 | endif 51 | 52 | if len(dirs) == 0 53 | " should not happen 54 | return [] 55 | endif 56 | 57 | let ret = {} 58 | for dir in dirs 59 | let root = expand(dir . '/pkg/' . s:goos . '_' . s:goarch) 60 | for i in split(globpath(root, a:ArgLead.'*'), "\n") 61 | if isdirectory(i) 62 | let i .= '/' 63 | elseif i !~ '\.a$' 64 | continue 65 | endif 66 | let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g') 67 | let ret[i] = i 68 | endfor 69 | endfor 70 | return sort(keys(ret)) 71 | endfunction 72 | -------------------------------------------------------------------------------- /.vim/ftplugin/go/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # Copyright 2012 The Go Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE file. 6 | # 7 | # Tests for import.vim. 8 | 9 | cd $(dirname $0) 10 | 11 | cat > base.go <&1 -n "$1: " 29 | vim -e -s -u /dev/null -U /dev/null --noplugin -c "source import.vim" \ 30 | -c "$1" -c 'wq! test.go' base.go 31 | # ensure blank lines are treated correctly 32 | if ! gofmt test.go | cmp test.go; then 33 | echo 2>&1 "gofmt conflict" 34 | gofmt test.go | diff -u test.go - | sed "s/^/ /" 2>&1 35 | fail=1 36 | return 37 | fi 38 | if ! grep -P -q "(?s)$2" test.go; then 39 | echo 2>&1 "$2 did not match" 40 | cat test.go | sed "s/^/ /" 2>&1 41 | fail=1 42 | return 43 | fi 44 | echo 2>&1 "ok" 45 | } 46 | 47 | # Tests for Import 48 | 49 | test_one "Import baz" '"baz".*"bytes"' 50 | test_one "Import io/ioutil" '"io".*"io/ioutil".*"net"' 51 | test_one "Import myc" '"io".*"myc".*"net"' # prefix of a site prefix 52 | test_one "Import nat" '"io".*"nat".*"net"' 53 | test_one "Import net/http" '"net".*"net/http".*"mycorp/foo"' 54 | test_one "Import zoo" '"net".*"zoo".*"mycorp/foo"' 55 | test_one "Import mycorp/bar" '"net".*"mycorp/bar".*"mycorp/foo"' 56 | test_one "Import mycorp/goo" '"net".*"mycorp/foo".*"mycorp/goo"' 57 | 58 | # Tests for Drop 59 | 60 | cat > base.go <&1 "FAIL" 76 | exit 1 77 | fi 78 | echo 2>&1 "PASS" 79 | -------------------------------------------------------------------------------- /linux/json.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: JSON 3 | " Maintainer: Jeroen Ruigrok van der Werven 4 | " Last Change: 2009-06-16 5 | " Version: 0.4 6 | " {{{1 7 | 8 | " Syntax setup {{{2 9 | " For version 5.x: Clear all syntax items 10 | " For version 6.x: Quit when a syntax file was already loaded 11 | 12 | if !exists("main_syntax") 13 | if version < 600 14 | syntax clear 15 | elseif exists("b:current_syntax") 16 | finish 17 | endif 18 | let main_syntax = 'json' 19 | endif 20 | 21 | " Syntax: Strings {{{2 22 | syn region jsonString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsonEscape 23 | " Syntax: JSON does not allow strings with single quotes, unlike JavaScript. 24 | syn region jsonStringSQ start=+'+ skip=+\\\\\|\\"+ end=+'+ 25 | 26 | " Syntax: Escape sequences {{{3 27 | syn match jsonEscape "\\["\\/bfnrt]" contained 28 | syn match jsonEscape "\\u\x\{4}" contained 29 | 30 | " Syntax: Strings should always be enclosed with quotes. 31 | syn match jsonNoQuotes "\<\a\+\>" 32 | 33 | " Syntax: Numbers {{{2 34 | syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" 35 | 36 | " Syntax: An integer part of 0 followed by other digits is not allowed. 37 | syn match jsonNumError "-\=\<0\d\.\d*\>" 38 | 39 | " Syntax: Boolean {{{2 40 | syn keyword jsonBoolean true false 41 | 42 | " Syntax: Null {{{2 43 | syn keyword jsonNull null 44 | 45 | " Syntax: Braces {{{2 46 | syn match jsonBraces "[{}\[\]]" 47 | 48 | " Define the default highlighting. {{{1 49 | " For version 5.7 and earlier: only when not done already 50 | " For version 5.8 and later: only when an item doesn't have highlighting yet 51 | if version >= 508 || !exists("did_json_syn_inits") 52 | if version < 508 53 | let did_json_syn_inits = 1 54 | command -nargs=+ HiLink hi link 55 | else 56 | command -nargs=+ HiLink hi def link 57 | endif 58 | HiLink jsonString String 59 | HiLink jsonEscape Special 60 | HiLink jsonNumber Number 61 | HiLink jsonBraces Operator 62 | HiLink jsonNull Function 63 | HiLink jsonBoolean Boolean 64 | 65 | HiLink jsonNumError Error 66 | HiLink jsonStringSQ Error 67 | HiLink jsonNoQuotes Error 68 | delcommand HiLink 69 | endif 70 | 71 | let b:current_syntax = "json" 72 | if main_syntax == 'json' 73 | unlet main_syntax 74 | endif 75 | 76 | " Vim settings {{{2 77 | " vim: ts=8 fdm=marker 78 | -------------------------------------------------------------------------------- /.vim/readme.txt: -------------------------------------------------------------------------------- 1 | Vim plugins for Go (http://golang.org) 2 | ====================================== 3 | 4 | To use all the Vim plugins, add these lines to your $HOME/.vimrc. 5 | 6 | " Some Linux distributions set filetype in /etc/vimrc. 7 | " Clear filetype flags before changing runtimepath to force Vim to reload them. 8 | filetype off 9 | filetype plugin indent off 10 | set runtimepath+=$GOROOT/misc/vim 11 | filetype plugin indent on 12 | syntax on 13 | 14 | If you want to select fewer plugins, use the instructions in the rest of 15 | this file. 16 | 17 | Vim syntax highlighting 18 | ----------------------- 19 | 20 | To install automatic syntax highlighting for GO programs: 21 | 22 | 1. Copy or link the filetype detection script to the ftdetect directory 23 | underneath your vim runtime directory (normally $HOME/.vim/ftdetect) 24 | 2. Copy or link syntax/go.vim to the syntax directory underneath your vim 25 | runtime directory (normally $HOME/.vim/syntax). Linking this file rather 26 | than just copying it will ensure any changes are automatically reflected 27 | in your syntax highlighting. 28 | 3. Add the following line to your .vimrc file (normally $HOME/.vimrc): 29 | 30 | syntax on 31 | 32 | In a typical unix environment you might accomplish this using the following 33 | commands: 34 | 35 | mkdir -p $HOME/.vim/ftdetect 36 | mkdir -p $HOME/.vim/syntax 37 | mkdir -p $HOME/.vim/autoload/go 38 | ln -s $GOROOT/misc/vim/ftdetect/gofiletype.vim $HOME/.vim/ftdetect/ 39 | ln -s $GOROOT/misc/vim/syntax/go.vim $HOME/.vim/syntax 40 | ln -s $GOROOT/misc/vim/autoload/go/complete.vim $HOME/.vim/autoload/go 41 | echo "syntax on" >> $HOME/.vimrc 42 | 43 | 44 | Vim filetype plugins 45 | -------------------- 46 | 47 | To install one of the available filetype plugins: 48 | 49 | 1. Same as 1 above. 50 | 2. Copy or link one or more plugins from ftplugin/go/*.vim to the 51 | Go-specific ftplugin directory underneath your vim runtime directory 52 | (normally $HOME/.vim/ftplugin/go/*.vim). 53 | 3. Add the following line to your .vimrc file (normally $HOME/.vimrc): 54 | 55 | filetype plugin on 56 | 57 | 58 | Vim indentation plugin 59 | ---------------------- 60 | 61 | To install automatic indentation: 62 | 63 | 1. Same as 1 above. 64 | 2. Copy or link indent/go.vim to the indent directory underneath your vim 65 | runtime directory (normally $HOME/.vim/indent). 66 | 3. Add the following line to your .vimrc file (normally $HOME/.vimrc): 67 | 68 | filetype indent on 69 | 70 | 71 | Godoc plugin 72 | ------------ 73 | 74 | To install godoc plugin: 75 | 76 | 1. Same as 1 above. 77 | 2. Copy or link plugin/godoc.vim to $HOME/.vim/plugin/godoc, 78 | syntax/godoc.vim to $HOME/.vim/syntax/godoc.vim, 79 | and autoload/go/complete.vim to $HOME/.vim/autoload/go/complete.vim. 80 | -------------------------------------------------------------------------------- /.vim/plugin/godoc.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2011 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | " 5 | " godoc.vim: Vim command to see godoc. 6 | 7 | if exists("g:loaded_godoc") 8 | finish 9 | endif 10 | let g:loaded_godoc = 1 11 | 12 | let s:buf_nr = -1 13 | let s:last_word = '' 14 | 15 | function! s:GodocView() 16 | if !bufexists(s:buf_nr) 17 | leftabove new 18 | file `="[Godoc]"` 19 | let s:buf_nr = bufnr('%') 20 | elseif bufwinnr(s:buf_nr) == -1 21 | leftabove split 22 | execute s:buf_nr . 'buffer' 23 | delete _ 24 | elseif bufwinnr(s:buf_nr) != bufwinnr('%') 25 | execute bufwinnr(s:buf_nr) . 'wincmd w' 26 | endif 27 | 28 | setlocal filetype=godoc 29 | setlocal bufhidden=delete 30 | setlocal buftype=nofile 31 | setlocal noswapfile 32 | setlocal nobuflisted 33 | setlocal modifiable 34 | setlocal nocursorline 35 | setlocal nocursorcolumn 36 | setlocal iskeyword+=: 37 | setlocal iskeyword-=- 38 | 39 | nnoremap K :Godoc 40 | 41 | au BufHidden call let buf_nr = -1 42 | endfunction 43 | 44 | function! s:GodocWord(word) 45 | let word = a:word 46 | silent! let content = system('godoc ' . word) 47 | if v:shell_error || !len(content) 48 | if len(s:last_word) 49 | silent! let content = system('godoc ' . s:last_word.'/'.word) 50 | if v:shell_error || !len(content) 51 | echo 'No documentation found for "' . word . '".' 52 | return 53 | endif 54 | let word = s:last_word.'/'.word 55 | else 56 | echo 'No documentation found for "' . word . '".' 57 | return 58 | endif 59 | endif 60 | let s:last_word = word 61 | silent! call s:GodocView() 62 | setlocal modifiable 63 | silent! %d _ 64 | silent! put! =content 65 | silent! normal gg 66 | setlocal nomodifiable 67 | setfiletype godoc 68 | endfunction 69 | 70 | function! s:Godoc(...) 71 | let word = join(a:000, ' ') 72 | if !len(word) 73 | let oldiskeyword = &iskeyword 74 | setlocal iskeyword+=. 75 | let word = expand('') 76 | let &iskeyword = oldiskeyword 77 | endif 78 | let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') 79 | let words = split(word, '\.') 80 | if !len(words) 81 | return 82 | endif 83 | call s:GodocWord(words[0]) 84 | if len(words) > 1 85 | if search('^\%(const\|var\|type\|\s\+\) ' . words[1] . '\s\+=\s') 86 | return 87 | endif 88 | if search('^func ' . words[1] . '(') 89 | return 90 | endif 91 | echo 'No documentation found for "' . word . '".' 92 | endif 93 | endfunction 94 | 95 | command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc() 96 | nnoremap (godoc-keyword) :call Godoc('') 97 | 98 | " vim:ts=4:sw=4:et 99 | -------------------------------------------------------------------------------- /linux/.bashrc: -------------------------------------------------------------------------------- 1 | # ~/.bashrc: executed by bash(1) for non-login shells. 2 | # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) 3 | # for examples 4 | 5 | # If not running interactively, don't do anything 6 | [ -z "$PS1" ] && return 7 | 8 | # don't put duplicate lines in the history. See bash(1) for more options 9 | # ... or force ignoredups and ignorespace 10 | HISTCONTROL=ignoredups:ignorespace 11 | 12 | # append to the history file, don't overwrite it 13 | shopt -s histappend 14 | 15 | # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) 16 | HISTSIZE=1000 17 | HISTFILESIZE=2000 18 | 19 | # check the window size after each command and, if necessary, 20 | # update the values of LINES and COLUMNS. 21 | shopt -s checkwinsize 22 | 23 | # make less more friendly for non-text input files, see lesspipe(1) 24 | [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" 25 | 26 | # set variable identifying the chroot you work in (used in the prompt below) 27 | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then 28 | debian_chroot=$(cat /etc/debian_chroot) 29 | fi 30 | 31 | # set a fancy prompt (non-color, unless we know we "want" color) 32 | case "$TERM" in 33 | xterm-color) color_prompt=yes;; 34 | esac 35 | 36 | # uncomment for a colored prompt, if the terminal has the capability; turned 37 | # off by default to not distract the user: the focus in a terminal window 38 | # should be on the output of commands, not on the prompt 39 | #force_color_prompt=yes 40 | 41 | if [ -n "$force_color_prompt" ]; then 42 | if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then 43 | # We have color support; assume it's compliant with Ecma-48 44 | # (ISO/IEC-6429). (Lack of such support is extremely rare, and such 45 | # a case would tend to support setf rather than setaf.) 46 | color_prompt=yes 47 | else 48 | color_prompt= 49 | fi 50 | fi 51 | 52 | if [ "$color_prompt" = yes ]; then 53 | PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 54 | else 55 | PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' 56 | fi 57 | unset color_prompt force_color_prompt 58 | 59 | # If this is an xterm set the title to user@host:dir 60 | case "$TERM" in 61 | xterm*|rxvt*) 62 | PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" 63 | ;; 64 | *) 65 | ;; 66 | esac 67 | 68 | # enable color support of ls and also add handy aliases 69 | if [ -x /usr/bin/dircolors ]; then 70 | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" 71 | alias ls='ls --color=auto' 72 | 73 | alias grep='grep --color=auto' 74 | alias fgrep='fgrep --color=auto' 75 | alias egrep='egrep --color=auto' 76 | 77 | alias rm='rm -i' 78 | fi 79 | 80 | # some more ls aliases 81 | alias ll='ls -alF' 82 | alias la='ls -A' 83 | alias l='ls -CF' 84 | 85 | alias rrm='/bin/rm -rf' 86 | alias rm='mv --target-directory ~/.trash' 87 | alias mv='mv -i' 88 | alias cp='cp -i' 89 | export CLASSPATH=$CLASSPATH:.:build/lucene-core-3.0.3-dev.jar:build/lucene-demos-3.0.3-dev.jar 90 | alias vi='vim -O' 91 | alias dropbox='~/etc/linux/dropbox_uploader.sh' 92 | alias pyconv='~/etc/pytools/pyconv.py' 93 | 94 | alias gitpush='git push origin HEAD' 95 | 96 | 97 | 98 | #Alias definitions. 99 | # You may want to put all your additions into a separate file like 100 | # ~/.bash_aliases, instead of adding them here directly. 101 | # See /usr/share/doc/bash-doc/examples in the bash-doc package. 102 | 103 | if [ -f ~/.bash_aliases ]; then 104 | . ~/.bash_aliases 105 | fi 106 | 107 | # enable programmable completion features (you don't need to enable 108 | # this, if it's already enabled in /etc/bash.bashrc and /etc/profile 109 | # sources /etc/bash.bashrc). 110 | if [ -f /etc/bash_completion ] && ! shopt -oq posix; then 111 | . /etc/bash_completion 112 | fi 113 | 114 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | syntax on 2 | set tabstop=4 3 | "set softtabstop=4 4 | set shiftwidth=4 5 | set autoindent 6 | set cindent 7 | set history=4000 8 | set mouse=v 9 | set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s 10 | set number 11 | set smarttab 12 | set expandtab 13 | set backspace=indent,eol,start 14 | set path+=/usr/include 15 | au FileType cpp set tabstop=2 16 | au FileType cpp set shiftwidth=2 17 | au FileType c set tabstop=2 18 | au FileType c set shiftwidth=2 19 | 20 | command Q : q 21 | command W : w 22 | command Wq : wq 23 | command WQ : wq 24 | 25 | 26 | " show the percentage of the content 27 | set ru 28 | 29 | " keep matching while you enter any character of searching keywords 30 | "set is 31 | 32 | "set whichwrap=b,s,<,>,[,] 33 | 34 | if &term=="xterm" 35 | set t_Co=8 36 | set t_Sb=^[[4%dm 37 | set t_Sf=^[[3%dm 38 | endif 39 | 40 | filetype off 41 | filetype plugin on 42 | filetype indent on 43 | set enc=utf8 44 | set fencs=utf8,gbk 45 | 46 | " highlight search 47 | set hlsearch 48 | " open file and go to the line last time you out 49 | au BufReadPost * 50 | \ if line("'\"") > 1 && line("'\"") <= line("$") | 51 | \ exe "normal! g'\"" | 52 | \ endif 53 | 54 | 55 | 56 | 57 | 58 | " bundle 59 | 60 | 61 | 62 | set nocompatible " be iMproved 63 | filetype off " required! 64 | 65 | "set rtp+=~/.vim/bundle/vundle/ 66 | set rtp+=~/.vim/bundle/Vundle.vim 67 | "call vundle#rc() 68 | call vundle#begin() 69 | Plugin 'honza/vim-snippets' 70 | 71 | " let Vundle manage Vundle 72 | " required! 73 | Bundle 'kien/ctrlp.vim' 74 | Bundle 'fatih/vim-go' 75 | Bundle 'octol/vim-cpp-enhanced-highlight' 76 | Bundle 'scrooloose/nerdcommenter' 77 | Bundle 'pangloss/vim-javascript' 78 | Bundle 'ervandew/supertab' 79 | Bundle 'Raimondi/delimitMate' 80 | Bundle 'tpope/vim-surround' 81 | Bundle 'vim-scripts/a.vim' 82 | Bundle 'derekwyatt/vim-scala' 83 | Bundle 'altercation/vim-colors-solarized' 84 | Bundle 'rust-lang/rust.vim' 85 | Bundle 'davidhalter/jedi-vim' 86 | 87 | call vundle#end() 88 | 89 | "" My bundles here: 90 | "" 91 | "" original repos on GitHub 92 | "Bundle 'tpope/vim-fugitive' 93 | "Bundle 'Lokaltog/vim-easymotion' 94 | "Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} 95 | "Bundle 'tpope/vim-rails.git' 96 | "" vim-scripts repos 97 | "Bundle 'L9' 98 | "Bundle 'FuzzyFinder' 99 | "" non-GitHub repos 100 | "Bundle 'git://git.wincent.com/command-t.git' 101 | "" Git repos on your local machine (i.e. when working on your own plugin) 102 | ""Bundle 'file:///Users/gmarik/path/to/plugin' 103 | "" better color 104 | "Bundle 'tomasr/molokai' 105 | " 106 | 107 | let g:html_indent_inctags = "html,body,head,tbody" 108 | let g:html_indent_script1 = "inc" 109 | let g:html_indent_style1 = "inc" 110 | 111 | " GoInstallBineries, GoImports will be called when :w 112 | let g:go_fmt_command = "goimports" 113 | 114 | "nmap gd:GoDef 115 | 116 | 117 | filetype plugin indent on " required! 118 | " 119 | " Brief help 120 | " :BundleList - list configured bundles 121 | " :BundleInstall(!) - install (update) bundles 122 | " :BundleSearch(!) foo - search (or refresh cache first) for foo 123 | " :BundleClean(!) - confirm (or auto-approve) removal of unused bundles 124 | " 125 | " see :h vundle for more details or wiki for FAQ 126 | " NOTE: comments after Bundle commands are not allowed. 127 | 128 | "nmap j 129 | "nmap l 130 | "nmap i 131 | "nmap k 132 | "nmap h 133 | 134 | let g:tagbar_type_go = { 135 | \ 'ctagstype' : 'go', 136 | \ 'kinds' : [ 137 | \ 'p:package', 138 | \ 'i:imports:1', 139 | \ 'c:constants', 140 | \ 'v:variables', 141 | \ 't:types', 142 | \ 'n:interfaces', 143 | \ 'w:fields', 144 | \ 'e:embedded', 145 | \ 'm:methods', 146 | \ 'r:constructor', 147 | \ 'f:functions' 148 | \ ], 149 | \ 'sro' : '.', 150 | \ 'kind2scope' : { 151 | \ 't' : 'ctype', 152 | \ 'n' : 'ntype' 153 | \ }, 154 | \ 'scope2kind' : { 155 | \ 'ctype' : 't', 156 | \ 'ntype' : 'n' 157 | \ }, 158 | \ 'ctagsbin' : 'gotags', 159 | \ 'ctagsargs' : '-sort -silent' 160 | \ } 161 | 162 | " vimdiff colors 163 | "syntax enable 164 | "set background=dark 165 | "colorscheme solarized 166 | 167 | if &diff 168 | syntax off 169 | endif 170 | 171 | -------------------------------------------------------------------------------- /linux/.zshrc: -------------------------------------------------------------------------------- 1 | # Path to your oh-my-zsh installation. 2 | export ZSH=$HOME/.oh-my-zsh 3 | 4 | # Set name of the theme to load. 5 | # Look in ~/.oh-my-zsh/themes/ 6 | # Optionally, if you set this to "random", it'll load a random theme each 7 | # time that oh-my-zsh is loaded. 8 | ZSH_THEME="robbyrussell" 9 | 10 | # Uncomment the following line to use case-sensitive completion. 11 | # CASE_SENSITIVE="true" 12 | 13 | # Uncomment the following line to disable bi-weekly auto-update checks. 14 | # DISABLE_AUTO_UPDATE="true" 15 | 16 | # Uncomment the following line to change how often to auto-update (in days). 17 | # export UPDATE_ZSH_DAYS=13 18 | 19 | # Uncomment the following line to disable colors in ls. 20 | # DISABLE_LS_COLORS="true" 21 | 22 | # Uncomment the following line to disable auto-setting terminal title. 23 | # DISABLE_AUTO_TITLE="true" 24 | 25 | # Uncomment the following line to enable command auto-correction. 26 | # ENABLE_CORRECTION="true" 27 | 28 | # Uncomment the following line to display red dots whilst waiting for completion. 29 | # COMPLETION_WAITING_DOTS="true" 30 | 31 | # Uncomment the following line if you want to disable marking untracked files 32 | # under VCS as dirty. This makes repository status check for large repositories 33 | # much, much faster. 34 | # DISABLE_UNTRACKED_FILES_DIRTY="true" 35 | 36 | # Uncomment the following line if you want to change the command execution time 37 | # stamp shown in the history command output. 38 | # The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" 39 | # HIST_STAMPS="mm/dd/yyyy" 40 | 41 | # Would you like to use another custom folder than $ZSH/custom? 42 | # ZSH_CUSTOM=/path/to/new-custom-folder 43 | 44 | # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) 45 | # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 46 | # Example format: plugins=(rails git textmate ruby lighthouse) 47 | # Add wisely, as too many plugins slow down shell startup. 48 | plugins=(git autojump) 49 | 50 | source $ZSH/oh-my-zsh.sh 51 | 52 | # User configuration 53 | 54 | export PATH="$HOME/local/go/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" 55 | # export MANPATH="/usr/local/man:$MANPATH" 56 | 57 | # You may need to manually set your language environment 58 | # export LANG=en_US.UTF-8 59 | 60 | # Preferred editor for local and remote sessions 61 | # if [[ -n $SSH_CONNECTION ]]; then 62 | # export EDITOR='vim' 63 | # else 64 | # export EDITOR='mvim' 65 | # fi 66 | 67 | # Compilation flags 68 | # export ARCHFLAGS="-arch x86_64" 69 | 70 | # ssh 71 | # export SSH_KEY_PATH="~/.ssh/dsa_id" 72 | 73 | # Set personal aliases, overriding those provided by oh-my-zsh libs, 74 | # plugins, and themes. Aliases can be placed here, though oh-my-zsh 75 | # users are encouraged to define aliases within the ZSH_CUSTOM folder. 76 | # For a full list of active aliases, run `alias`. 77 | # 78 | # Example aliases 79 | # alias zshconfig="mate ~/.zshrc" 80 | # alias ohmyzsh="mate ~/.oh-my-zsh" 81 | export EDITOR='vim' 82 | alias vi="vim -O" 83 | export GOPATH=~/golang 84 | export GOROOT=~/local/go 85 | export PATH=$GOPATH/bin/:$PATH 86 | DISABLE_AUTO_TITLE=true 87 | function rmfunc() { 88 | mv $@ ~/.trash/ 89 | } 90 | alias rm=rmfunc 91 | alias rrm='/bin/rm -rf' 92 | function gotaghere() { 93 | rm -f tags 94 | gotags -R=true -f=tags * 95 | } 96 | 97 | function astylegoogle() { 98 | astyle -C --style=google --indent=spaces=2 $@ 99 | } 100 | 101 | function extract () { 102 | if [ -f $1 ] ; then 103 | case $1 in 104 | *.tar.bz2) tar xjf $1 ;; 105 | *.tar.gz) tar xzf $1 ;; 106 | *.bz2) bunzip2 $1 ;; 107 | *.rar) unrar e $1 ;; 108 | *.gz) gunzip $1 ;; 109 | *.tar) tar xf $1 ;; 110 | *.tbz2) tar xjf $1 ;; 111 | *.tgz) tar xzf $1 ;; 112 | *.zip) unzip $1 ;; 113 | *.Z) uncompress $1 ;; 114 | *.7z) 7z x $1 ;; 115 | *) echo "'$1' cannot be extracted via extract()" ;; 116 | esac 117 | else 118 | echo "'$1' is not a valid file" 119 | fi 120 | } 121 | 122 | alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''' 123 | 124 | alias gl="git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" 125 | 126 | alias tm='ps -ef | grep' 127 | ft() { 128 | find . -name "$2" -exec grep -il "$1" {} \; 129 | } 130 | 131 | export EDITOR='vim' 132 | 133 | alias cleantrash="rrm ~/.trash/*" 134 | export LD_LIBRARY_PATH=/usr/local/lib 135 | 136 | eval "$(fasd --init auto)" 137 | alias j='fasd_cd -d' 138 | -------------------------------------------------------------------------------- /mac/.zshrc: -------------------------------------------------------------------------------- 1 | # Path to your oh-my-zsh installation. 2 | export ZSH=$HOME/.oh-my-zsh 3 | 4 | # Set name of the theme to load. 5 | # Look in ~/.oh-my-zsh/themes/ 6 | # Optionally, if you set this to "random", it'll load a random theme each 7 | # time that oh-my-zsh is loaded. 8 | ZSH_THEME="josh" 9 | 10 | # Uncomment the following line to use case-sensitive completion. 11 | # CASE_SENSITIVE="true" 12 | 13 | # Uncomment the following line to disable bi-weekly auto-update checks. 14 | # DISABLE_AUTO_UPDATE="true" 15 | 16 | # Uncomment the following line to change how often to auto-update (in days). 17 | # export UPDATE_ZSH_DAYS=13 18 | 19 | # Uncomment the following line to disable colors in ls. 20 | # DISABLE_LS_COLORS="true" 21 | 22 | # Uncomment the following line to disable auto-setting terminal title. 23 | # DISABLE_AUTO_TITLE="true" 24 | 25 | # Uncomment the following line to enable command auto-correction. 26 | # ENABLE_CORRECTION="true" 27 | 28 | # Uncomment the following line to display red dots whilst waiting for completion. 29 | # COMPLETION_WAITING_DOTS="true" 30 | 31 | # Uncomment the following line if you want to disable marking untracked files 32 | # under VCS as dirty. This makes repository status check for large repositories 33 | # much, much faster. 34 | # DISABLE_UNTRACKED_FILES_DIRTY="true" 35 | 36 | # Uncomment the following line if you want to change the command execution time 37 | # stamp shown in the history command output. 38 | # The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" 39 | # HIST_STAMPS="mm/dd/yyyy" 40 | 41 | # Would you like to use another custom folder than $ZSH/custom? 42 | # ZSH_CUSTOM=/path/to/new-custom-folder 43 | 44 | # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) 45 | # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 46 | # Example format: plugins=(rails git textmate ruby lighthouse) 47 | # Add wisely, as too many plugins slow down shell startup. 48 | plugins=(git autojump colored-man sudo zsh-syntax-highlighting brew-cask brew) 49 | 50 | source $ZSH/oh-my-zsh.sh 51 | 52 | # User configuration 53 | 54 | export PATH="$HOME/local/go/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" 55 | # export MANPATH="/usr/local/man:$MANPATH" 56 | 57 | # You may need to manually set your language environment 58 | # export LANG=en_US.UTF-8 59 | 60 | # Preferred editor for local and remote sessions 61 | # if [[ -n $SSH_CONNECTION ]]; then 62 | # export EDITOR='vim' 63 | # else 64 | # export EDITOR='mvim' 65 | # fi 66 | 67 | # Compilation flags 68 | # export ARCHFLAGS="-arch x86_64" 69 | 70 | # ssh 71 | # export SSH_KEY_PATH="~/.ssh/dsa_id" 72 | 73 | # Set personal aliases, overriding those provided by oh-my-zsh libs, 74 | # plugins, and themes. Aliases can be placed here, though oh-my-zsh 75 | # users are encouraged to define aliases within the ZSH_CUSTOM folder. 76 | # For a full list of active aliases, run `alias`. 77 | # 78 | # Example aliases 79 | # alias zshconfig="mate ~/.zshrc" 80 | # alias ohmyzsh="mate ~/.oh-my-zsh" 81 | alias vi="vim -O" 82 | export GOPATH=~/golang/ 83 | export PATH=$GOPATH/bin/:$PATH 84 | DISABLE_AUTO_TITLE=true 85 | 86 | function extract () { 87 | if [ -f $1 ] ; then 88 | case $1 in 89 | *.tar.bz2) tar xjf $1 ;; 90 | *.tar.gz) tar xzf $1 ;; 91 | *.bz2) bunzip2 $1 ;; 92 | *.rar) unrar e $1 ;; 93 | *.gz) gunzip $1 ;; 94 | *.tar) tar xf $1 ;; 95 | *.tbz2) tar xjf $1 ;; 96 | *.tgz) tar xzf $1 ;; 97 | *.zip) unzip $1 ;; 98 | *.Z) uncompress $1 ;; 99 | *.7z) 7z x $1 ;; 100 | *) echo "'$1' cannot be extracted via extract()" ;; 101 | esac 102 | else 103 | echo "'$1' is not a valid file" 104 | fi 105 | } 106 | 107 | 108 | alias rrm='/bin/rm -rf' 109 | function rmfunc() { 110 | mv $@ ~/.trash/ 111 | } 112 | alias rm=rmfunc 113 | 114 | function gotaghere() { 115 | rm -f tags 116 | gotags -R=true -f=tags * 117 | } 118 | 119 | function astylegoogle() { 120 | astyle -C --style=google --indent=spaces=2 $@ 121 | } 122 | 123 | alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''' 124 | 125 | alias gl="git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" 126 | 127 | alias tm='ps -ef | grep' 128 | ft() { 129 | find . -name "$2" -exec grep -il "$1" {} \; 130 | } 131 | 132 | 133 | 134 | export DOCKER_CERT_PATH=/Users/yanyiwu/.boot2docker/certs/boot2docker-vm 135 | export DOCKER_TLS_VERIFY=1 136 | export DOCKER_HOST=tcp://192.168.59.103:2376 137 | 138 | export JAVA_HOME=`/usr/libexec/java_home` 139 | export PATH=${JAVA_HOME}/bin:$PATH 140 | #export NVM_IOJS_ORG_MIRROR="https://npm.taobao.org/mirrors/iojs/" 141 | #export NVM_DIR=$(brew --prefix)/var/nvm 142 | #source $(brew --prefix nvm)/nvm.sh 143 | 144 | 145 | function ports() { lsof -Pni4 | grep LISTEN } 146 | 147 | alias cnpm="npm --registry=https://registry.npm.taobao.org \ 148 | --cache=$HOME/.npm/.cache/cnpm \ 149 | --disturl=https://npm.taobao.org/dist \ 150 | --userconfig=$HOME/.cnpmrc" 151 | export PATH="/usr/local/bin:$PATH" 152 | export PATH="/usr/local/sbin:$PATH" 153 | 154 | eval "$(fasd --init auto)" 155 | alias j='fasd_cd -d' 156 | -------------------------------------------------------------------------------- /.vim/indent/python.vim: -------------------------------------------------------------------------------- 1 | " Python indent file 2 | " Language: Python 3 | " Maintainer: Eric Mc Sween 4 | " Original Author: David Bustos 5 | " Last Change: 2004 Jun 07 6 | 7 | " Only load this indent file when no other was loaded. 8 | if exists("b:did_indent") 9 | finish 10 | endif 11 | let b:did_indent = 1 12 | 13 | setlocal expandtab 14 | setlocal nolisp 15 | setlocal autoindent 16 | setlocal indentexpr=GetPythonIndent(v:lnum) 17 | setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except,0 18 | 19 | let s:maxoff = 50 20 | 21 | " Find backwards the closest open parenthesis/bracket/brace. 22 | function! s:SearchParensPair() 23 | let line = line('.') 24 | let col = col('.') 25 | 26 | " Skip strings and comments and don't look too far 27 | let skip = "line('.') < " . (line - s:maxoff) . " ? dummy :" . 28 | \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? ' . 29 | \ '"string\\|comment"' 30 | 31 | " Search for parentheses 32 | call cursor(line, col) 33 | let parlnum = searchpair('(', '', ')', 'bW', skip) 34 | let parcol = col('.') 35 | 36 | " Search for brackets 37 | call cursor(line, col) 38 | let par2lnum = searchpair('\[', '', '\]', 'bW', skip) 39 | let par2col = col('.') 40 | 41 | " Search for braces 42 | call cursor(line, col) 43 | let par3lnum = searchpair('{', '', '}', 'bW', skip) 44 | let par3col = col('.') 45 | 46 | " Get the closest match 47 | if par2lnum > parlnum || (par2lnum == parlnum && par2col > parcol) 48 | let parlnum = par2lnum 49 | let parcol = par2col 50 | endif 51 | if par3lnum > parlnum || (par3lnum == parlnum && par3col > parcol) 52 | let parlnum = par3lnum 53 | let parcol = par3col 54 | endif 55 | 56 | " Put the cursor on the match 57 | if parlnum > 0 58 | call cursor(parlnum, parcol) 59 | endif 60 | return parlnum 61 | endfunction 62 | 63 | " Find the start of a multi-line statement 64 | function! s:StatementStart(lnum) 65 | let lnum = a:lnum 66 | while 1 67 | if getline(lnum - 1) =~ '\\$' 68 | let lnum = lnum - 1 69 | else 70 | call cursor(lnum, 1) 71 | let maybe_lnum = s:SearchParensPair() 72 | if maybe_lnum < 1 73 | return lnum 74 | else 75 | let lnum = maybe_lnum 76 | endif 77 | endif 78 | endwhile 79 | endfunction 80 | 81 | " Find the block starter that matches the current line 82 | function! s:BlockStarter(lnum, block_start_re) 83 | let lnum = a:lnum 84 | let maxindent = 10000 " whatever 85 | while lnum > 1 86 | let lnum = prevnonblank(lnum - 1) 87 | if indent(lnum) < maxindent 88 | if getline(lnum) =~ a:block_start_re 89 | return lnum 90 | else 91 | let maxindent = indent(lnum) 92 | " It's not worth going further if we reached the top level 93 | if maxindent == 0 94 | return -1 95 | endif 96 | endif 97 | endif 98 | endwhile 99 | return -1 100 | endfunction 101 | 102 | function! GetPythonIndent(lnum) 103 | 104 | " First line has indent 0 105 | if a:lnum == 1 106 | return 0 107 | endif 108 | 109 | " If we can find an open parenthesis/bracket/brace, line up with it. 110 | call cursor(a:lnum, 1) 111 | let parlnum = s:SearchParensPair() 112 | if parlnum > 0 113 | let parcol = col('.') 114 | let closing_paren = match(getline(a:lnum), '^\s*[])}]') != -1 115 | if match(getline(parlnum), '[([{]\s*$', parcol - 1) != -1 116 | if closing_paren 117 | return indent(parlnum) 118 | else 119 | return indent(parlnum) + &shiftwidth 120 | endif 121 | else 122 | if closing_paren 123 | return parcol - 1 124 | else 125 | return parcol 126 | endif 127 | endif 128 | endif 129 | 130 | " Examine this line 131 | let thisline = getline(a:lnum) 132 | let thisindent = indent(a:lnum) 133 | 134 | " If the line starts with 'elif' or 'else', line up with 'if' or 'elif' 135 | if thisline =~ '^\s*\(elif\|else\)\>' 136 | let bslnum = s:BlockStarter(a:lnum, '^\s*\(if\|elif\)\>') 137 | if bslnum > 0 138 | return indent(bslnum) 139 | else 140 | return -1 141 | endif 142 | endif 143 | 144 | " If the line starts with 'except' or 'finally', line up with 'try' 145 | " or 'except' 146 | if thisline =~ '^\s*\(except\|finally\)\>' 147 | let bslnum = s:BlockStarter(a:lnum, '^\s*\(try\|except\)\>') 148 | if bslnum > 0 149 | return indent(bslnum) 150 | else 151 | return -1 152 | endif 153 | endif 154 | 155 | " Examine previous line 156 | let plnum = a:lnum - 1 157 | let pline = getline(plnum) 158 | let sslnum = s:StatementStart(plnum) 159 | 160 | " If the previous line is blank, keep the same indentation 161 | if pline =~ '^\s*$' 162 | return -1 163 | endif 164 | 165 | " If this line is explicitly joined, try to find an indentation that looks 166 | " good. 167 | if pline =~ '\\$' 168 | let compound_statement = '^\s*\(if\|while\|for\s.*\sin\|except\)\s*' 169 | let maybe_indent = matchend(getline(sslnum), compound_statement) 170 | if maybe_indent != -1 171 | return maybe_indent 172 | else 173 | return indent(sslnum) + &sw * 2 174 | endif 175 | endif 176 | 177 | " If the previous line ended with a colon, indent relative to 178 | " statement start. 179 | if pline =~ ':\s*$' 180 | return indent(sslnum) + &sw 181 | endif 182 | 183 | " If the previous line was a stop-execution statement or a pass 184 | if getline(sslnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>' 185 | " See if the user has already dedented 186 | if indent(a:lnum) > indent(sslnum) - &sw 187 | " If not, recommend one dedent 188 | return indent(sslnum) - &sw 189 | endif 190 | " Otherwise, trust the user 191 | return -1 192 | endif 193 | 194 | " In all other cases, line up with the start of the previous statement. 195 | return indent(sslnum) 196 | endfunction 197 | -------------------------------------------------------------------------------- /.vim/syntax/go.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2009 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | " 5 | " go.vim: Vim syntax file for Go. 6 | " 7 | " Options: 8 | " There are some options for customizing the highlighting; the recommended 9 | " settings are the default values, but you can write: 10 | " let OPTION_NAME = 0 11 | " in your ~/.vimrc file to disable particular options. You can also write: 12 | " let OPTION_NAME = 1 13 | " to enable particular options. At present, all options default to on. 14 | " 15 | " - go_highlight_array_whitespace_error 16 | " Highlights white space after "[]". 17 | " - go_highlight_chan_whitespace_error 18 | " Highlights white space around the communications operator that don't follow 19 | " the standard style. 20 | " - go_highlight_extra_types 21 | " Highlights commonly used library types (io.Reader, etc.). 22 | " - go_highlight_space_tab_error 23 | " Highlights instances of tabs following spaces. 24 | " - go_highlight_trailing_whitespace_error 25 | " Highlights trailing white space. 26 | 27 | " Quit when a (custom) syntax file was already loaded 28 | if exists("b:current_syntax") 29 | finish 30 | endif 31 | 32 | if !exists("go_highlight_array_whitespace_error") 33 | let go_highlight_array_whitespace_error = 1 34 | endif 35 | if !exists("go_highlight_chan_whitespace_error") 36 | let go_highlight_chan_whitespace_error = 1 37 | endif 38 | if !exists("go_highlight_extra_types") 39 | let go_highlight_extra_types = 1 40 | endif 41 | if !exists("go_highlight_space_tab_error") 42 | let go_highlight_space_tab_error = 1 43 | endif 44 | if !exists("go_highlight_trailing_whitespace_error") 45 | let go_highlight_trailing_whitespace_error = 1 46 | endif 47 | 48 | syn case match 49 | 50 | syn keyword goDirective package import 51 | syn keyword goDeclaration var const type 52 | syn keyword goDeclType struct interface 53 | 54 | hi def link goDirective Statement 55 | hi def link goDeclaration Keyword 56 | hi def link goDeclType Keyword 57 | 58 | " Keywords within functions 59 | syn keyword goStatement defer go goto return break continue fallthrough 60 | syn keyword goConditional if else switch select 61 | syn keyword goLabel case default 62 | syn keyword goRepeat for range 63 | 64 | hi def link goStatement Statement 65 | hi def link goConditional Conditional 66 | hi def link goLabel Label 67 | hi def link goRepeat Repeat 68 | 69 | " Predefined types 70 | syn keyword goType chan map bool string error 71 | syn keyword goSignedInts int int8 int16 int32 int64 rune 72 | syn keyword goUnsignedInts byte uint uint8 uint16 uint32 uint64 uintptr 73 | syn keyword goFloats float32 float64 74 | syn keyword goComplexes complex64 complex128 75 | 76 | hi def link goType Type 77 | hi def link goSignedInts Type 78 | hi def link goUnsignedInts Type 79 | hi def link goFloats Type 80 | hi def link goComplexes Type 81 | 82 | " Treat func specially: it's a declaration at the start of a line, but a type 83 | " elsewhere. Order matters here. 84 | syn match goType /\/ 85 | syn match goDeclaration /^func\>/ 86 | 87 | " Predefined functions and values 88 | syn keyword goBuiltins append cap close complex copy delete imag len 89 | syn keyword goBuiltins make new panic print println real recover 90 | syn keyword goConstants iota true false nil 91 | 92 | hi def link goBuiltins Keyword 93 | hi def link goConstants Keyword 94 | 95 | " Comments; their contents 96 | syn keyword goTodo contained TODO FIXME XXX BUG 97 | syn cluster goCommentGroup contains=goTodo 98 | syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell 99 | syn region goComment start="//" end="$" contains=@goCommentGroup,@Spell 100 | 101 | hi def link goComment Comment 102 | hi def link goTodo Todo 103 | 104 | " Go escapes 105 | syn match goEscapeOctal display contained "\\[0-7]\{3}" 106 | syn match goEscapeC display contained +\\[abfnrtv\\'"]+ 107 | syn match goEscapeX display contained "\\x\x\{2}" 108 | syn match goEscapeU display contained "\\u\x\{4}" 109 | syn match goEscapeBigU display contained "\\U\x\{8}" 110 | syn match goEscapeError display contained +\\[^0-7xuUabfnrtv\\'"]+ 111 | 112 | hi def link goEscapeOctal goSpecialString 113 | hi def link goEscapeC goSpecialString 114 | hi def link goEscapeX goSpecialString 115 | hi def link goEscapeU goSpecialString 116 | hi def link goEscapeBigU goSpecialString 117 | hi def link goSpecialString Special 118 | hi def link goEscapeError Error 119 | 120 | " Strings and their contents 121 | syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError 122 | syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup 123 | syn region goRawString start=+`+ end=+`+ 124 | 125 | hi def link goString String 126 | hi def link goRawString String 127 | 128 | " Characters; their contents 129 | syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU 130 | syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup 131 | 132 | hi def link goCharacter Character 133 | 134 | " Regions 135 | syn region goBlock start="{" end="}" transparent fold 136 | syn region goParen start='(' end=')' transparent 137 | 138 | " Integers 139 | syn match goDecimalInt "\<\d\+\([Ee]\d\+\)\?\>" 140 | syn match goHexadecimalInt "\<0x\x\+\>" 141 | syn match goOctalInt "\<0\o\+\>" 142 | syn match goOctalError "\<0\o*[89]\d*\>" 143 | 144 | hi def link goDecimalInt Integer 145 | hi def link goHexadecimalInt Integer 146 | hi def link goOctalInt Integer 147 | hi def link Integer Number 148 | 149 | " Floating point 150 | syn match goFloat "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>" 151 | syn match goFloat "\<\.\d\+\([Ee][-+]\d\+\)\?\>" 152 | syn match goFloat "\<\d\+[Ee][-+]\d\+\>" 153 | 154 | hi def link goFloat Float 155 | 156 | " Imaginary literals 157 | syn match goImaginary "\<\d\+i\>" 158 | syn match goImaginary "\<\d\+\.\d*\([Ee][-+]\d\+\)\?i\>" 159 | syn match goImaginary "\<\.\d\+\([Ee][-+]\d\+\)\?i\>" 160 | syn match goImaginary "\<\d\+[Ee][-+]\d\+i\>" 161 | 162 | hi def link goImaginary Number 163 | 164 | " Spaces after "[]" 165 | if go_highlight_array_whitespace_error != 0 166 | syn match goSpaceError display "\(\[\]\)\@<=\s\+" 167 | endif 168 | 169 | " Spacing errors around the 'chan' keyword 170 | if go_highlight_chan_whitespace_error != 0 171 | " receive-only annotation on chan type 172 | syn match goSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@=" 173 | " send-only annotation on chan type 174 | syn match goSpaceError display "\(\/ 182 | syn match goExtraType /\/ 183 | syn match goExtraType /\/ 184 | syn match goExtraType /\/ 185 | endif 186 | 187 | " Space-tab error 188 | if go_highlight_space_tab_error != 0 189 | syn match goSpaceError display " \+\t"me=e-1 190 | endif 191 | 192 | " Trailing white space error 193 | if go_highlight_trailing_whitespace_error != 0 194 | syn match goSpaceError display excludenl "\s\+$" 195 | endif 196 | 197 | hi def link goExtraType Type 198 | hi def link goSpaceError Error 199 | 200 | " Search backwards for a global declaration to start processing the syntax. 201 | "syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/ 202 | 203 | " There's a bug in the implementation of grouphere. For now, use the 204 | " following as a more expensive/less precise workaround. 205 | syn sync minlines=500 206 | 207 | let b:current_syntax = "go" 208 | -------------------------------------------------------------------------------- /.vim/ftplugin/go/import.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2011 The Go Authors. All rights reserved. 2 | " Use of this source code is governed by a BSD-style 3 | " license that can be found in the LICENSE file. 4 | " 5 | " import.vim: Vim commands to import/drop Go packages. 6 | " 7 | " This filetype plugin adds three new commands for go buffers: 8 | " 9 | " :Import {path} 10 | " 11 | " Import ensures that the provided package {path} is imported 12 | " in the current Go buffer, using proper style and ordering. 13 | " If {path} is already being imported, an error will be 14 | " displayed and the buffer will be untouched. 15 | " 16 | " :ImportAs {localname} {path} 17 | " 18 | " Same as Import, but uses a custom local name for the package. 19 | " 20 | " :Drop {path} 21 | " 22 | " Remove the import line for the provided package {path}, if 23 | " present in the current Go buffer. If {path} is not being 24 | " imported, an error will be displayed and the buffer will be 25 | " untouched. 26 | " 27 | " In addition to these commands, there are also two shortcuts mapped: 28 | " 29 | " \f - Runs :Import fmt 30 | " \F - Runs :Drop fmt 31 | " 32 | " The backslash is the default maplocalleader, so it is possible that 33 | " your vim is set to use a different character (:help maplocalleader). 34 | " 35 | if exists("b:did_ftplugin_go_import") 36 | finish 37 | endif 38 | 39 | command! -buffer -nargs=? -complete=customlist,go#complete#Package Drop call s:SwitchImport(0, '', ) 40 | command! -buffer -nargs=1 -complete=customlist,go#complete#Package Import call s:SwitchImport(1, '', ) 41 | command! -buffer -nargs=* -complete=customlist,go#complete#Package ImportAs call s:SwitchImport(1, ) 42 | map f :Import fmt 43 | map F :Drop fmt 44 | 45 | function! s:SwitchImport(enabled, localname, path) 46 | let view = winsaveview() 47 | let path = a:path 48 | 49 | " Quotes are not necessary, so remove them if provided. 50 | if path[0] == '"' 51 | let path = strpart(path, 1) 52 | endif 53 | if path[len(path)-1] == '"' 54 | let path = strpart(path, 0, len(path) - 1) 55 | endif 56 | if path == '' 57 | call s:Error('Import path not provided') 58 | return 59 | endif 60 | 61 | " Extract any site prefix (e.g. github.com/). 62 | " If other imports with the same prefix are grouped separately, 63 | " we will add this new import with them. 64 | " Only up to and including the first slash is used. 65 | let siteprefix = matchstr(path, "^[^/]*/") 66 | 67 | let qpath = '"' . path . '"' 68 | if a:localname != '' 69 | let qlocalpath = a:localname . ' ' . qpath 70 | else 71 | let qlocalpath = qpath 72 | endif 73 | let indentstr = 0 74 | let packageline = -1 " Position of package name statement 75 | let appendline = -1 " Position to introduce new import 76 | let deleteline = -1 " Position of line with existing import 77 | let linesdelta = 0 " Lines added/removed 78 | 79 | " Find proper place to add/remove import. 80 | let line = 0 81 | while line <= line('$') 82 | let linestr = getline(line) 83 | 84 | if linestr =~# '^package\s' 85 | let packageline = line 86 | let appendline = line 87 | 88 | elseif linestr =~# '^import\s\+(' 89 | let appendstr = qlocalpath 90 | let indentstr = 1 91 | let appendline = line 92 | let firstblank = -1 93 | let lastprefix = "" 94 | while line <= line("$") 95 | let line = line + 1 96 | let linestr = getline(line) 97 | let m = matchlist(getline(line), '^\()\|\(\s\+\)\(\S*\s*\)"\(.\+\)"\)') 98 | if empty(m) 99 | if siteprefix == "" && a:enabled 100 | " must be in the first group 101 | break 102 | endif 103 | " record this position, but keep looking 104 | if firstblank < 0 105 | let firstblank = line 106 | endif 107 | continue 108 | endif 109 | if m[1] == ')' 110 | " if there's no match, add it to the first group 111 | if appendline < 0 && firstblank >= 0 112 | let appendline = firstblank 113 | endif 114 | break 115 | endif 116 | let lastprefix = matchstr(m[4], "^[^/]*/") 117 | if a:localname != '' && m[3] != '' 118 | let qlocalpath = printf('%-' . (len(m[3])-1) . 's %s', a:localname, qpath) 119 | endif 120 | let appendstr = m[2] . qlocalpath 121 | let indentstr = 0 122 | if m[4] == path 123 | let appendline = -1 124 | let deleteline = line 125 | break 126 | elseif m[4] < path 127 | " don't set candidate position if we have a site prefix, 128 | " we've passed a blank line, and this doesn't share the same 129 | " site prefix. 130 | if siteprefix == "" || firstblank < 0 || match(m[4], "^" . siteprefix) >= 0 131 | let appendline = line 132 | endif 133 | elseif siteprefix != "" && match(m[4], "^" . siteprefix) >= 0 134 | " first entry of site group 135 | let appendline = line - 1 136 | break 137 | endif 138 | endwhile 139 | break 140 | 141 | elseif linestr =~# '^import ' 142 | if appendline == packageline 143 | let appendstr = 'import ' . qlocalpath 144 | let appendline = line - 1 145 | endif 146 | let m = matchlist(linestr, '^import\(\s\+\)\(\S*\s*\)"\(.\+\)"') 147 | if !empty(m) 148 | if m[3] == path 149 | let appendline = -1 150 | let deleteline = line 151 | break 152 | endif 153 | if m[3] < path 154 | let appendline = line 155 | endif 156 | if a:localname != '' && m[2] != '' 157 | let qlocalpath = printf("%s %" . len(m[2])-1 . "s", a:localname, qpath) 158 | endif 159 | let appendstr = 'import' . m[1] . qlocalpath 160 | endif 161 | 162 | elseif linestr =~# '^\(var\|const\|type\|func\)\>' 163 | break 164 | 165 | endif 166 | let line = line + 1 167 | endwhile 168 | 169 | " Append or remove the package import, as requested. 170 | if a:enabled 171 | if deleteline != -1 172 | call s:Error(qpath . ' already being imported') 173 | elseif appendline == -1 174 | call s:Error('No package line found') 175 | else 176 | if appendline == packageline 177 | call append(appendline + 0, '') 178 | call append(appendline + 1, 'import (') 179 | call append(appendline + 2, ')') 180 | let appendline += 2 181 | let linesdelta += 3 182 | let appendstr = qlocalpath 183 | let indentstr = 1 184 | endif 185 | call append(appendline, appendstr) 186 | execute appendline + 1 187 | if indentstr 188 | execute 'normal >>' 189 | endif 190 | let linesdelta += 1 191 | endif 192 | else 193 | if deleteline == -1 194 | call s:Error(qpath . ' not being imported') 195 | else 196 | execute deleteline . 'd' 197 | let linesdelta -= 1 198 | 199 | if getline(deleteline-1) =~# '^import\s\+(' && getline(deleteline) =~# '^)' 200 | " Delete empty import block 201 | let deleteline -= 1 202 | execute deleteline . "d" 203 | execute deleteline . "d" 204 | let linesdelta -= 2 205 | endif 206 | 207 | if getline(deleteline) == '' && getline(deleteline - 1) == '' 208 | " Delete spacing for removed line too. 209 | execute deleteline . "d" 210 | let linesdelta -= 1 211 | endif 212 | endif 213 | endif 214 | 215 | " Adjust view for any changes. 216 | let view.lnum += linesdelta 217 | let view.topline += linesdelta 218 | if view.topline < 0 219 | let view.topline = 0 220 | endif 221 | 222 | " Put buffer back where it was. 223 | call winrestview(view) 224 | 225 | endfunction 226 | 227 | function! s:Error(s) 228 | echohl Error | echo a:s | echohl None 229 | endfunction 230 | 231 | let b:did_ftplugin_go_import = 1 232 | 233 | " vim:ts=4:sw=4:et 234 | --------------------------------------------------------------------------------