Last active
February 18, 2020 04:05
-
-
Save yangvipguang/844357a6bf72ee3017529c7d27d8bce0 to your computer and use it in GitHub Desktop.
Vimrc
This file contains 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
" Specify a directory for plugins | |
" - For Neovim: stdpath('data') . '/plugged' | |
" - Avoid using standard Vim directory names like 'plugin' | |
call plug#begin('~/.vim/plugged') | |
" Make sure you use single quotes | |
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align | |
Plug 'junegunn/vim-easy-align' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
" 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' | |
" On-demand loading | |
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } | |
Plug 'tpope/vim-fireplace', { 'for': 'clojure' } | |
" Using a non-master branch | |
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } | |
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above) | |
Plug 'fatih/vim-go', { 'tag': '*' } | |
" Plugin options | |
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' } | |
" Plugin outside ~/.vim/plugged with post-update hook | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
" Unmanaged plugin (manually installed and updated) | |
Plug '~/my-prototype-plugin' | |
" Initialize plugin system | |
call plug#end() | |
" allow plugins by file type (required for plugins!) | |
filetype plugin on | |
filetype indent on | |
" tabs and spaces handling | |
set expandtab | |
set tabstop=4 | |
set softtabstop=4 | |
set shiftwidth=4 | |
" highlight cursor line and column | |
set cursorline | |
set cursorcolumn | |
" hidden startup messages | |
set shortmess=atI | |
" auto read and write | |
set autowrite | |
set autoread | |
" when deal with unsaved files ask what to do | |
set confirm | |
" no backup files | |
set nobackup | |
" other settings | |
set langmenu=zh_CN.UTF-8 | |
set mouse=a | |
set whichwrap+=<,>,h,l,[,] | |
set background=dark | |
set encoding=utf-8 | |
set backspace=2 " make backspace work like most other apps | |
set backspace=indent,eol,start | |
" tab length exceptions on some file types | |
autocmd FileType html setlocal shiftwidth=2 tabstop=2 softtabstop=2 | |
autocmd FileType htmldjango setlocal shiftwidth=2 tabstop=2 softtabstop=2 | |
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2 softtabstop=2 | |
" always show status bar | |
set laststatus=2 | |
" incremental search | |
set incsearch | |
" highlighted search results | |
set hlsearch | |
" search ignore case | |
set ignorecase | |
" muting search highlighting | |
nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l> | |
" syntax highlight on | |
syntax on | |
" show line numbers | |
set nu | |
" tab navigation mappings | |
map tn :tabn<CR> | |
map tp :tabp<CR> | |
map tm :tabm | |
map tt :tabnew | |
map ts :tab split<CR> | |
map <C-S-Right> :tabn<CR> | |
imap <C-S-Right> <ESC>:tabn<CR> | |
map <C-S-Left> :tabp<CR> | |
imap <C-S-Left> <ESC>:tabp<CR> | |
" old autocomplete keyboard shortcut | |
imap <C-J> <C-X><C-O> | |
" Comment this line to enable autocompletion preview window | |
" (displays documentation related to the selected completion option) | |
" Disabled by default because preview makes the window flicker | |
set completeopt-=preview | |
" save as sudo | |
ca w!! w !sudo tee "%" | |
" simple recursive grep | |
" both recursive grep commands with internal or external (fast) grep | |
command! -nargs=1 RecurGrep lvimgrep /<args>/gj ./**/*.* | lopen | set nowrap | |
command! -nargs=1 RecurGrepFast silent exec 'lgrep! <q-args> ./**/*.*' | lopen | |
" mappings to call them | |
nmap ,R :RecurGrep | |
nmap ,r :RecurGrepFast | |
" mappings to call them with the default word as search text | |
nmap ,wR :RecurGrep <cword><CR> | |
nmap ,wr :RecurGrepFast <cword><CR> | |
" when scrolling, keep cursor 3 lines away from screen border | |
set scrolloff=3 | |
" autocompletion of files and commands behaves like zsh | |
" (autocomplete menu) | |
set wildmenu | |
set wildmode=full | |
" better backup, swap and undos storage | |
set directory=~/.vim/dirs/tmp " directory to place swap files in | |
set backup " make backup files | |
set backupdir=~/.vim/dirs/backups " where to put backup files | |
set undofile " persistent undos - undo after you re-open the file | |
set undodir=~/.vim/dirs/undos | |
set viminfo+=n~/.vim/dirs/viminfo | |
" store yankring history file there too | |
let g:yankring_history_dir = '~/.vim/dirs/' | |
" create needed directories if they don't exist | |
if !isdirectory(&backupdir) | |
call mkdir(&backupdir, "p") | |
endif | |
if !isdirectory(&directory) | |
call mkdir(&directory, "p") | |
endif | |
if !isdirectory(&undodir) | |
call mkdir(&undodir, "p") | |
endif | |
" ============================================================================ | |
" Plugins settings and mappings | |
" Edit them as you wish. | |
" Tagbar ----------------------------- | |
" toggle tagbar display | |
map <F4> :TagbarToggle<CR> | |
" autofocus on tagbar open | |
let g:tagbar_autofocus = 1 | |
" NERDTree ----------------------------- | |
" toggle nerdtree display | |
map <F3> :NERDTreeToggle<CR> | |
" open nerdtree with the current file selected | |
nmap ,t :NERDTreeFind<CR> | |
" don;t show these file types | |
let NERDTreeIgnore = ['\.pyc$', '\.pyo$'] | |
" Tasklist ------------------------------ | |
" show pending tasks list | |
map <F2> :TaskList<CR> | |
" CtrlP ------------------------------ | |
" file finder mapping | |
let g:ctrlp_map = ',e' | |
" hidden some types files | |
let g:ctrlp_show_hidden = 1 | |
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.png,*.jpg,*.gif "Linux | |
" tags (symbols) in current file finder mapping | |
nmap ,g :CtrlPBufTag<CR> | |
" tags (symbols) in all files finder mapping | |
nmap ,G :CtrlPBufTagAll<CR> | |
" general code finder in all files mapping | |
nmap ,f :CtrlPLine<CR> | |
" recent files finder mapping | |
nmap ,m :CtrlPMRUFiles<CR> | |
" commands finder mapping | |
nmap ,c :CtrlPCmdPalette<CR> | |
" to be able to call CtrlP with default search text | |
function! CtrlPWithSearchText(search_text, ctrlp_command_end) | |
execute ':CtrlP' . a:ctrlp_command_end | |
call feedkeys(a:search_text) | |
endfunction | |
" same as previous mappings, but calling with current word as default text | |
nmap ,wg :call CtrlPWithSearchText(expand('<cword>'), 'BufTag')<CR> | |
nmap ,wG :call CtrlPWithSearchText(expand('<cword>'), 'BufTagAll')<CR> | |
nmap ,wf :call CtrlPWithSearchText(expand('<cword>'), 'Line')<CR> | |
nmap ,we :call CtrlPWithSearchText(expand('<cword>'), '')<CR> | |
nmap ,pe :call CtrlPWithSearchText(expand('<cfile>'), '')<CR> | |
nmap ,wm :call CtrlPWithSearchText(expand('<cword>'), 'MRUFiles')<CR> | |
nmap ,wc :call CtrlPWithSearchText(expand('<cword>'), 'CmdPalette')<CR> | |
" don't change working directory | |
let g:ctrlp_working_path_mode = 0 | |
" ignore these files and folders on file finder | |
let g:ctrlp_custom_ignore = { | |
\ 'dir': '\v[\/](\.git|\.hg|\.svn)$', | |
\ 'file': '\.pyc$\|\.pyo$', | |
\ } | |
" Syntastic ------------------------------ | |
" show list of errors and warnings on the current file | |
nmap <leader>e :Errors<CR> | |
" turn to next or previous errors, after open errors list | |
nmap <leader>n :lnext<CR> | |
nmap <leader>p :lprevious<CR> | |
" check also when just opened the file | |
let g:syntastic_check_on_open = 1 | |
" syntastic checker for javascript. | |
" eslint is the only tool support JSX. | |
" If you don't need write JSX, you can use jshint. | |
" And eslint is slow, but not a hindrance | |
" let g:syntastic_javascript_checkers = ['jshint'] | |
let g:syntastic_javascript_checkers = ['eslint'] | |
" don't put icons on the sign column (it hides the vcs status icons of signify) | |
let g:syntastic_enable_signs = 0 | |
" custom icons (enable them if you use a patched font, and enable the previous | |
" setting) | |
let g:syntastic_error_symbol = '?' | |
let g:syntastic_warning_symbol = '?' | |
let g:syntastic_style_error_symbol = '?' | |
let g:syntastic_style_warning_symbol = '?' | |
" mappings to toggle display, and to focus on it | |
let g:tabman_toggle = 'tl' | |
let g:tabman_focus = 'tf' | |
" Autoclose ------------------------------ | |
" Fix to let ESC work as espected with Autoclose plugin | |
let g:AutoClosePumvisible = {"ENTER": "\<C-Y>", "ESC": "\<ESC>"} | |
" DragVisuals ------------------------------ | |
" mappings to move blocks in 4 directions | |
vmap <expr> <S-M-LEFT> DVB_Drag('left') | |
vmap <expr> <S-M-RIGHT> DVB_Drag('right') | |
vmap <expr> <S-M-DOWN> DVB_Drag('down') | |
vmap <expr> <S-M-UP> DVB_Drag('up') | |
" mapping to duplicate block | |
vmap <expr> D DVB_Duplicate() | |
" Signify ------------------------------ | |
" this first setting decides in which order try to guess your current vcs | |
" UPDATE it to reflect your preferences, it will speed up opening files | |
let g:signify_vcs_list = [ 'git', 'hg' ] | |
" mappings to jump to changed blocks | |
nmap <leader>sn <plug>(signify-next-hunk) | |
nmap <leader>sp <plug>(signify-prev-hunk) | |
" nicer colors | |
highlight DiffAdd cterm=bold ctermbg=none ctermfg=119 | |
highlight DiffDelete cterm=bold ctermbg=none ctermfg=167 | |
highlight DiffChange cterm=bold ctermbg=none ctermfg=227 | |
highlight SignifySignAdd cterm=bold ctermbg=237 ctermfg=119 | |
highlight SignifySignDelete cterm=bold ctermbg=237 ctermfg=167 | |
highlight SignifySignChange cterm=bold ctermbg=237 ctermfg=227 | |
function! AccentDemo() | |
let keys = ['a','b','c','d','e','f','g','h'] | |
for k in keys | |
call airline#parts#define_text(k, k) | |
endfor | |
call airline#parts#define_accent('a', 'red') | |
call airline#parts#define_accent('b', 'green') | |
call airline#parts#define_accent('c', 'blue') | |
call airline#parts#define_accent('d', 'yellow') | |
call airline#parts#define_accent('e', 'orange') | |
call airline#parts#define_accent('f', 'purple') | |
call airline#parts#define_accent('g', 'bold') | |
call airline#parts#define_accent('h', 'italic') | |
let g:airline_section_a = airline#section#create(keys) | |
endfunction | |
autocmd VimEnter * call AccentDemo() | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#left_sep = ' ' | |
let g:airline#extensions#tabline#left_alt_sep = '|' | |
let g:airline#extensions#tabline#formatter = 'default' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment