Created
September 3, 2017 14:14
-
-
Save liujingyu/49b663e031cf9ce35557945896129be0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if empty(glob('~/.vim/autoload/plug.vim')) | |
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs | |
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | |
autocmd VimEnter * | |
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) | |
\| PlugInstall --sync | q | |
\| endif | |
endif | |
" With a map leader it's possible to do extra key combinations | |
" like <leader>w saves the current file | |
let mapleader = "\<Space>" | |
let g:mapleader = "\<Space>" | |
" ============================================================================ | |
" VIM-PLUG BLOCK {{{ | |
" ============================================================================ | |
" Plugins will be downloaded under the specified directory. | |
call plug#begin('~/.vim/plugged') | |
" Declare the list of plugins. | |
Plug 'tpope/vim-sensible' | |
Plug 'junegunn/seoul256.vim' | |
" NERD tree will be loaded on the first invocation of NERDTreeToggle command | |
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } | |
augroup nerd_loader | |
autocmd! | |
autocmd VimEnter * silent! autocmd! FileExplorer | |
autocmd BufEnter,BufNew * | |
\ if isdirectory(expand('<amatch>')) | |
\| call plug#load('nerdtree') | |
\| execute 'autocmd! nerd_loader' | |
\| endif | |
augroup END | |
" Multiple commands | |
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] } | |
" Code to execute when the plugin is lazily loaded on demand | |
Plug 'junegunn/goyo.vim', { 'for': 'markdown' } | |
autocmd! User goyo.vim echom 'Goyo is now loaded!' | |
Plug 'easymotion/vim-easymotion' | |
Plug 'terryma/vim-multiple-cursors' | |
Plug 'tpope/vim-fugitive' | |
Plug 'liujingyu/vimrc' | |
Plug 'mattn/webapi-vim' | |
Plug 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'} | |
Plug 'altercation/vim-colors-solarized' | |
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align | |
Plug 'junegunn/vim-easy-align' | |
" Any valid git URL is allowed | |
Plug 'https://github.com/junegunn/vim-github-dashboard.git' | |
" Multiple Plug commands can be written in a single line using | separators | |
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
Plug 'w0rp/ale' | |
Plug 'gregsexton/gitv', {'on': ['Gitv']} | |
Plug 'anyakichi/vim-surround' | |
Plug 'tpope/vim-repeat' | |
Plug 'vim-airline/vim-airline-themes' | Plug 'bling/vim-airline' | |
Plug 'scrooloose/nerdcommenter' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'kshenoy/vim-signature' | |
Plug 'terryma/vim-expand-region' | |
Plug 'mileszs/ack.vim' | |
Plug 'posva/vim-vue' | |
Plug 'jaxbot/semantic-highlight.vim' | |
Plug 'junegunn/vim-xmark', { 'do': 'make' } | |
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' } | |
Plug 'AndrewRadev/splitjoin.vim' | |
Plug 'junegunn/gv.vim' | |
Plug 'mattn/emmet-vim' | |
Plug 'Raimondi/delimitMate' | |
Plug 'lvht/phpcd.vim', { 'for': 'php', 'do': 'composer install' } | |
let g:phpcd_php_cli_executable = 'php7.0' | |
" List ends here. Plugins become visible to Vim after this call. | |
call plug#end() | |
" }}} | |
" ---------------------------------------------------------------------------- | |
" vim-plug extension | |
" ---------------------------------------------------------------------------- | |
function! s:plug_doc() | |
let name = matchstr(getline('.'), '^- \zs\S\+\ze:') | |
if has_key(g:plugs, name) | |
for doc in split(globpath(g:plugs[name].dir, 'doc/*.txt'), '\n') | |
execute 'tabe' doc | |
endfor | |
endif | |
endfunction | |
augroup PlugHelp | |
autocmd! | |
autocmd FileType vim-plug nnoremap <buffer> <silent> H :call <sid>plug_doc()<cr> | |
augroup END | |
function! s:plug_gx() | |
let line = getline('.') | |
let sha = matchstr(line, '^ \X*\zs\x\{7,9}\ze ') | |
let name = empty(sha) ? matchstr(line, '^[-x+] \zs[^:]\+\ze:') | |
\ : getline(search('^- .*:$', 'bn'))[2:-2] | |
let uri = get(get(g:plugs, name, {}), 'uri', '') | |
if uri !~ 'github.com' | |
return | |
endif | |
let repo = matchstr(uri, '[^:/]*/'.name) | |
let url = empty(sha) ? 'https://github.com/'.repo | |
\ : printf('https://github.com/%s/commit/%s', repo, sha) | |
call netrw#BrowseX(url, 0) | |
endfunction | |
augroup PlugGx | |
autocmd! | |
autocmd FileType vim-plug nnoremap <buffer> <silent> gx :call <sid>plug_gx()<cr> | |
augroup END | |
function! s:scroll_preview(down) | |
silent! wincmd P | |
if &previewwindow | |
execute 'normal!' a:down ? "\<c-e>" : "\<c-y>" | |
wincmd p | |
endif | |
endfunction | |
function! s:setup_extra_keys() | |
nnoremap <silent> <buffer> J :call <sid>scroll_preview(1)<cr> | |
nnoremap <silent> <buffer> K :call <sid>scroll_preview(0)<cr> | |
nnoremap <silent> <buffer> <c-n> :call search('^ \X*\zs\x')<cr> | |
nnoremap <silent> <buffer> <c-p> :call search('^ \X*\zs\x', 'b')<cr> | |
nmap <silent> <buffer> <c-j> <c-n>o | |
nmap <silent> <buffer> <c-k> <c-p>o | |
endfunction | |
augroup PlugDiffExtra | |
autocmd! | |
autocmd FileType vim-plug call s:setup_extra_keys() | |
augroup END | |
" ---------------------------------------------------------------------------- | |
" 用FZF 查找文件 | |
" 设置查找时排除的目录 | |
" ---------------------------------------------------------------------------- | |
let $FZF_DEFAULT_COMMAND = 'find . -type f ! -path "./node_modules/*" ! -path "./bower_components/*" ! -path "./.git/*" ! -path "*.swp"' | |
map <C-P> :tabnew<CR>:FZF<CR> | |
map!<C-P> <ESc>:w<CR> :tabnew<CR>:FZF<CR> | |
" ---------------------------------------------------------------------------- | |
" Plug 'altercation/vim-colors-solarized' | |
" ---------------------------------------------------------------------------- | |
if has('gui_running') | |
set background=light | |
else | |
set background=dark | |
endif | |
colorscheme solarized | |
let g:solarized_termcolors=256 | |
if exists('$TMUX') | |
set term=screen-256color | |
endif | |
"============================================= | |
" Basic | |
"============================================= | |
" airline-themes | |
let g:airline_theme='solarized' | |
" 粘贴模式 | |
nnoremap <F5> :set invpaste paste?<CR> | |
set pastetoggle=<F5> | |
set showmode | |
nmap <F4> :TagbarToggle<CR> | |
" ---------------------------------------------------------------------------- | |
" vimawesome.com | |
" ---------------------------------------------------------------------------- | |
function! VimAwesomeComplete() abort | |
let prefix = matchstr(strpart(getline('.'), 0, col('.') - 1), '[.a-zA-Z0-9_/-]*$') | |
echohl WarningMsg | |
echo 'Downloading plugin list from VimAwesome' | |
echohl None | |
ruby << EOF | |
require 'json' | |
require 'open-uri' | |
query = VIM::evaluate('prefix').gsub('/', '%20') | |
items = 1.upto(max_pages = 3).map do |page| | |
Thread.new do | |
url = "http://vimawesome.com/api/plugins?page=#{page}&query=#{query}" | |
data = open(url).read | |
json = JSON.parse(data, symbolize_names: true) | |
json[:plugins].map do |info| | |
pair = info.values_at :github_owner, :github_repo_name | |
next if pair.any? { |e| e.nil? || e.empty? } | |
{word: pair.join('/'), | |
menu: info[:category].to_s, | |
info: info.values_at(:short_desc, :author).compact.join($/)} | |
end.compact | |
end | |
end.each(&:join).map(&:value).inject(:+) | |
VIM::command("let cands = #{JSON.dump items}") | |
EOF | |
if !empty(cands) | |
inoremap <buffer> <c-v> <c-n> | |
augroup _VimAwesomeComplete | |
autocmd! | |
autocmd CursorMovedI,InsertLeave * iunmap <buffer> <c-v> | |
\| autocmd! _VimAwesomeComplete | |
augroup END | |
call complete(col('.') - strchars(prefix), cands) | |
endif | |
return '' | |
endfunction | |
augroup VimAwesomeComplete | |
autocmd! | |
autocmd FileType vim inoremap <c-x><c-v> <c-r>=VimAwesomeComplete()<cr> | |
augroup END | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment