Vim & tmux & zsh ——打造IDE之vim 发表于 2018-01-18 关键词:Vim 我在我的github也维护了一份关于Vim的文档,编辑器之神,话不多说,直接上配置 zsh直接用homebrew安装即可,不做过多介绍。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565" https://lierhua.top" https://yeyuqiudeng.top" ===============================================================================" Info" leader: default is `\`, detailed with `:help <leader>``" ===============================================================================" ===============================================================================" General Configuration" ===============================================================================set nocompatible " Use the vim's keyboard setting, not viif filereadable(expand("~/.vim/vimrc.vundle")) source ~/.vim/vimrc.vundleendifset nu " Set the line numbersyntax on " Syntax highlighting"set autochdir " Set the current dir as thr work dirfiletype on " File type detectionfiletype plugin on " Loading the plugin files for specific file typesfiletype indent on " Loading the indent file for specific file types with" Tab and Indentset tabstop=4set softtabstop=4set shiftwidth=4set smarttab"set expandtab " Use the space to instead of tabset autoindent " Copy indent from current line when starting a new lineset smartindentset cindent" Seach and Matchset hlsearch " Highlight the search resultset incsearch " Real-time searchset ignorecaseset smartcaseset showmatch " When a bracket is inserted, briefly jump to the matching one" Displayset showmode " Show the current modeset t_Co=256 " If under tty, use 256" Display tab and trail spaceset listset listchars=tab:>-,trail:." Not display above listnmap <leader>l :set list!<CR>" Otherset nobackupset fileencodings=utf-8,gb18030,cp936,big5 " Set the encode" set pastetoggle=<F10> " Bind `F10` to `:set paste`set pastetoggle=<leader>pset backspace=2 " same as ":set backspace=indent,eol,start" in vim7.4" Press `shift` while selecting with the mouse can disable into visual mode" In mac os, hold `alt/option` is easier" ref: http://stackoverflow.com/questions/4608161/copy-text-out-of-vim-with-set-mouse-a-enabledset mouse=a " Enable mouseset foldmethod=indent " The kind of folding used for the current windowset foldlevel=99" -------------------------------------------------------------------------------" Enhanced" -------------------------------------------------------------------------------au BufRead,BufNewFile *.md set filetype=markdown " .md default is modula2" Execute python file being edited with <Shift> + e:map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>" Auto add head info" .py file auto add headerfunction HeaderPython() call setline(1, "#!/usr/bin/env python") call append(1, "# -*- coding: utf-8 -*-") call append(2, "# fupeng.li @ " . strftime('%Y-%m-%d', localtime())) normal G normal oendfautocmd bufnewfile *.py call HeaderPython()" .sh file auto add headerfunction HeaderBash() call setline(1, "#!/bin/bash") call append(1, "# fupeng.li @ " . strftime('%Y-%m-%d', localtime())) normal G normal oendfautocmd bufnewfile *.sh call HeaderBash()" ref: http://stackoverflow.com/questions/158968/changing-vim-indentation-behavior-by-file-typeautocmd FileType html set shiftwidth=2|set expandtabautocmd FileType htmljinja setlocal shiftwidth=2 tabstop=2 softtabstop=2 expandtabautocmd FileType css setlocal shiftwidth=2 tabstop=2 softtabstop=2 expandtabautocmd Filetype javascript setlocal ts=2 sts=2 sw=2 expandtabautocmd FileType sh setlocal shiftwidth=4 tabstop=4 softtabstop=4 expandtabautocmd FileType python setlocal shiftwidth=4 tabstop=4 softtabstop=4 expandtabautocmd FileType vim setlocal shiftwidth=2 tabstop=2 softtabstop=2 expandtab" enable quick jump between keyword, such as if/endifruntime macros/matchit.vim" quick expand current active file's directory (not work directory)" use `%%' to auto expand instead of `%:h<Tab>'cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'" -------------------------------------------------------------------------------" Bind Keys" -------------------------------------------------------------------------------" <C-l>: quick temp disable hlsearchnnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>" ===============================================================================" Vundle Configuration" ===============================================================================set nocompatible " be iMproved, requiredfiletype off " required!" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, required!Plugin 'gmarik/Vundle.vim'" My Vundles here:" Display"Plugin 'Lokaltog/vim-powerline' " newer powerline is https://github.com/powerline/powerlinePlugin 'vim-airline/vim-airline'Plugin 'vim-airline/vim-airline-themes'Plugin 'chriskempson/tomorrow-theme'Plugin 'jnurmine/Zenburn'Plugin 'kien/rainbow_parentheses.vim'"Plugin 'Yggdroot/indentLine'" Note vim-colorschemes will cause vim-powerline not work if :tabnew" Plugin 'flazz/vim-colorschemes' " themes collectionPlugin 'Color-Scheme-Explorer'" PythonPlugin 'davidhalter/jedi-vim'Plugin 'nvie/vim-flake8'Plugin 'mitsuhiko/vim-jinja'"Plugin 'kevinw/pyflakes-vim'"Plugin 'fs111/pydoc.vim'"Plugin 'Pydiction'"Plugin 'pep8'" HTML & CSS"Plugin 'mattn/emmet-vim'"Plugin 'hail2u/vim-css3-syntax'" JavaScript"Plugin 'pangloss/vim-javascript' " improved indentation"Plugin 'ternjs/tern_for_vim' " js autocompletion"Plugin 'Shutnik/jshint2.vim'" Go"Plugin 'fatih/vim-go'" LaTeXPlugin 'lervag/vimtex'"---tex config---let g:vimtex_compiler_latexmk = {'callback' : 0}set nocompatiblelet &rtp = '~/.vim/bundle/vimtex,' . &rtplet &rtp .= ',~/.vim/bundle/vimtex/after'filetype plugin indent onsyntax enable" MarkdownPlugin 'sjl/badwolf'" EnhancedPlugin 'scrooloose/nerdtree'Plugin 'jistr/vim-nerdtree-tabs'Plugin 'airblade/vim-gitgutter'Plugin 'ervandew/supertab'Plugin 'Shougo/neocomplete.vim' " neocomplete need vim --with-luaPlugin 'SirVer/ultisnips'Plugin 'honza/vim-snippets' " needed with SirVer/ultisnipsPlugin 'AndrewRadev/splitjoin.vim' " transition between multiline and single-line codePlugin 'Tagbar' " Tagbar is more powerful than 'taglist.vim'Plugin 'Auto-Pairs' " Auto-Pairs is more useful than AutoClose"Plugin 'godlygeek/tabular'Plugin 'hotoo/pangu.vim'Plugin 'easymotion/vim-easymotion'if has('mac') || has('macunix') Plugin 'rizzatti/dash.vim'endifcall vundle#end() " required!filetype plugin indent on " required!" To ignore plugin indent changes, instead use:"filetype plugin on""" Brief help" :PluginList - lists configured plugins" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate" :PluginSearch foo - searches for foo; append `!` to refresh local cache" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal"" see :h vundle for more details or wiki for FAQ" Put your non-Plugin stuff after this line" -------------------------------------------------------------------------------" Lokaltog/vim-powerline" -------------------------------------------------------------------------------let g:Powerline_symbols = 'unicode' " compatible/unicode/fancyset laststatus=2 " Always show the statuslineset encoding=utf-8 " Necessary to show Unicode glyphsset t_Co=256 " Explicitly tell Vim that the terminal supports 256 colors" -------------------------------------------------------------------------------" vim-airline/vim-airline" -------------------------------------------------------------------------------" Keep vim-powerline configuration opened" In Mac with iTerm2, need to select patched font for non-ascii font, in" Profiles -> Textlet g:airline_powerline_fonts = 1let g:airline_theme='molokai'" -------------------------------------------------------------------------------" kien/rainbow_parentheses.vim" -------------------------------------------------------------------------------" always onau VimEnter *.py,*.js,*.html,*.css,*.sls RainbowParenthesesToggleau Syntax *.py,*.js,*.html,*.css,*.sls RainbowParenthesesLoadRoundau Syntax *.py,*.js,*.html,*.css,*.sls RainbowParenthesesLoadSquareau Syntax *.py,*.js,*.html,*.css,*.sls RainbowParenthesesLoadBraces" the outer layer is the last pair" remove black for dark terminallet g:rbpt_colorpairs = [ \ ['brown', 'RoyalBlue3'], \ ['darkblue', 'SeaGreen3'], \ ['darkgray', 'DarkOrchid3'], \ ['darkgreen', 'firebrick3'], \ ['darkcyan', 'RoyalBlue3'], \ ['darkred', 'SeaGreen3'], \ ['darkmagenta', 'DarkOrchid3'], \ ['brown', 'firebrick3'], \ ['gray', 'RoyalBlue3'], \ ['darkred', 'DarkOrchid3'], \ ['darkmagenta', 'DarkOrchid3'], \ ['darkblue', 'firebrick3'], \ ['darkgreen', 'RoyalBlue3'], \ ['darkcyan', 'SeaGreen3'], \ ['red', 'firebrick3'], \ ]let g:rbpt_max = 15" -------------------------------------------------------------------------------" Yggdroot/indentLine" -------------------------------------------------------------------------------" https://github.com/Yggdroot/indentLine" let g:indentLine_char='┆'" let g:indentLine_enabled = 1" -------------------------------------------------------------------------------" davidhalter/jedi-vim" -------------------------------------------------------------------------------" Goto assignments <leader>g (typical goto function)" Goto definitions <leader>d (follow identifier as far as possible, includes" imports and statements)" Show Documentation/Pydoc K (shows a popup with assignments)" Renaming <leader>r" Usages <leader>n (shows all the usages of a name)" Open module, e.g. :Pyimport os (opens the os module)autocmd FileType python setlocal completeopt-=preview " disable docstring"let g:jedi#completions_command = "<C-N>"" -------------------------------------------------------------------------------" nvie/vim-flake8" -------------------------------------------------------------------------------autocmd FileType python map <buffer> <F3> :call Flake8()<CR>let g:flake8_quickfix_height=5let g:flake8_show_in_gutter=1highlight link Flake8_Error Errorhighlight link Flake8_Warning WarningMsghighlight link Flake8_Complexity WarningMsghighlight link Flake8_Naming WarningMsghighlight link Flake8_PyFlake WarningMsgautocmd BufWritePost *.py call Flake8()" ----------------------------------------------------------------------------" mattn/emmet-vim" ----------------------------------------------------------------------------" trigger key: <c-y>, " note with comma" html:5" <c-y>n: next edit point" <c-y>N: previous edit point" <c-y>d: select whole label" <c-y>D: select whole label content" <c-y>k: delete current label" ----------------------------------------------------------------------------" hail2u/vim-css3-syntax" ----------------------------------------------------------------------------augroup VimCSS3Syntax autocmd! autocmd FileType css setlocal iskeyword+=-augroup END" ----------------------------------------------------------------------------" ternjs/tern_for_vim" ----------------------------------------------------------------------------let tern_show_signature_in_pum = 1let tern_show_argument_hints = 'on_hold'autocmd FileType javascript nnoremap <leader>d :TernDef<CR>autocmd FileType javascript setlocal omnifunc=tern#Complete"" ----------------------------------------------------------------------------" Shutnik/jshint2.vim" ----------------------------------------------------------------------------let jshint2_save = 1" jshint validationnnoremap <leader>j :JSHint<CR>" ----------------------------------------------------------------------------" scrooloose/nerdtree and jistr/vim-nerdtree-tabs" ----------------------------------------------------------------------------"nmap <leader>ne :NERDTreeToggle<CR>nmap <leader>ne :NERDTreeTabsToggle<CR>"Ctrl+N 打开/关闭map <C-n> :NERDTreeToggle<CR>" 当不带参数打开Vim时自动加载项目树autocmd StdinReadPre * let s:std_in=1autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif" 当所有文件关闭时关闭项目树窗格autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif" 不显示这些文件let NERDTreeIgnore=['\.pyc$', '\~$', 'node_modules'] "ignore files in NERDTree" 不显示项目树上额外的信息,例如帮助、提示什么的let NERDTreeMinimalUI=1" ----------------------------------------------------------------------------" ervandew/supertab" ----------------------------------------------------------------------------set completeopt=longest,menu,previewlet g:SuperTabDefaultCompletionType = "<c-x><c-o>" " use omni completion instead of defaultlet g:SuperTabCrMapping = 1 " disable <enter> with newline, https://github.com/ervandew/supertab/issues/142" ----------------------------------------------------------------------------" Shougo/neocomplete.vim" ----------------------------------------------------------------------------" Disable AutoComplPop.let g:acp_enableAtStartup = 0" Use neocomplete.let g:neocomplete#enable_at_startup = 1" Use smartcase.let g:neocomplete#enable_smart_case = 1" Set minimum syntax keyword length.let g:neocomplete#sources#syntax#min_keyword_length = 3let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'" Define dictionary.let g:neocomplete#sources#dictionary#dictionaries = { \ 'default' : '', \ 'vimshell' : $HOME.'/.vimshell_hist', \ 'scheme' : $HOME.'/.gosh_completions' \ }" Define keyword.if !exists('g:neocomplete#keyword_patterns') let g:neocomplete#keyword_patterns = {}endiflet g:neocomplete#keyword_patterns['default'] = '\h\w*'" Plugin key-mappings.inoremap <expr><C-g> neocomplete#undo_completion()inoremap <expr><C-l> neocomplete#complete_common_string()" Recommended key-mappings." <TAB>: completion.inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"" <C-h>, <BS>: close popup and delete backword char.inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"" Close popup by <Space>."inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"" AutoComplPop like behavior.let g:neocomplete#enable_auto_select = 1" Enable omni completion.autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSSautocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTagsautocmd FileType javascript setlocal omnifunc=tern#Complete " for ternjsautocmd FileType python setlocal omnifunc=jedi#completions " for jediautocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags" Enable heavy omni completion.if !exists('g:neocomplete#sources#omni#input_patterns') let g:neocomplete#sources#omni#input_patterns = {}endif" ----------------------------------------------------------------------------" SirVer/ultisnips" ----------------------------------------------------------------------------" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.let g:UltiSnipsExpandTrigger="<tab>"let g:UltiSnipsJumpForwardTrigger="<c-b>"let g:UltiSnipsJumpBackwardTrigger="<c-z>"" If you want :UltiSnipsEdit to split your window.let g:UltiSnipsEditSplit="vertical"" ----------------------------------------------------------------------------" Tagbar" ----------------------------------------------------------------------------nmap <F8> :TagbarToggle<CR>map <leader>tb :TagbarToggle<CR>let g:tagbar_sort = 0"let g:tagbar_type_markdown = {" \ 'ctagstype': 'markdown'," \ 'ctagsbin' : '/Users/fupeng.li/.dotfiles/markdown2ctags.py'," \ 'ctagsargs' : '-f - --sort=yes'," \ 'kinds' : [" \ 's:sections'," \ 'i:images'" \ ]," \ 'sro' : '|'," \ 'kind2scope' : {" \ 's' : 'section'," \ }," \ 'sort': 0,"\ }" ----------------------------------------------------------------------------" airblade/vim-gitgutter" ----------------------------------------------------------------------------let g:gitgutter_max_signs = 500"let g:gitgutter_highlight_lines = 1highlight clear SignColumn" ----------------------------------------------------------------------------" SirVer/ultisnips" ----------------------------------------------------------------------------" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe."let g:UltiSnipsExpandTrigger="<tab>""let g:UltiSnipsJumpForwardTrigger="<c-b>""let g:UltiSnipsJumpBackwardTrigger="<c-z>"" ----------------------------------------------------------------------------" rizzatti/dash.vim" ----------------------------------------------------------------------------" https://raw.githubusercontent.com/rizzatti/dash.vim/master/doc/dash.txtlet g:dash_map = { \ 'python' : ['py', 'python2', 'py3', 'python3'] \ }nmap <silent> <leader>da <Plug>DashSearch" ----------------------------------------------------------------------------" godlygeek/tabular" ----------------------------------------------------------------------------" use `Tab /|` to auto align '|'" ----------------------------------------------------------------------------" hotoo/pangu.vim" https://github.com/hotoo/pangu.vim" ----------------------------------------------------------------------------autocmd BufWritePre *.markdown,*.md call PanGuSpacing()" ----------------------------------------------------------------------------" easymotion/vim-easymotion" https://github.com/easymotion/vim-easymotion" ----------------------------------------------------------------------------" <Leader>f{char} to move to {char}map <Leader>f <Plug>(easymotion-bd-f)nmap <Leader>f <Plug>(easymotion-overwin-f)" s{char}{char} to move to {char}{char}nmap s <Plug>(easymotion-overwin-f2)" Move to linemap <Leader>L <Plug>(easymotion-bd-jk)nmap <Leader>L <Plug>(easymotion-overwin-line)" Move to wordmap <Leader>w <Plug>(easymotion-bd-w)nmap <Leader>w <Plug>(easymotion-overwin-w)" ===============================================================================" Color Settings" ===============================================================================" test color with run `:runtime syntax/colortest.vim`set t_Co=256if exists('+colorcolumn') " cc is only exist >= `Vim7.3` set cc=100 " Short for colorcolumnelse au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)endifhi ColorColumn ctermbg=lightgrey guibg=lightgrey " Highlighter cctry set background=dark colorscheme Tomorrow-Night-Bright " Below syntax will affect vim-airline statusbar; write colorscheme " directly is ok " autocmd BufEnter * colorscheme Tomorrow-Night-Bright autocmd BufEnter *.md,*.mkd,*.markdown colorscheme badwolfcatch /^Vim\%((\a\+)\)\=:E185/ colorscheme desertendtry" for gui, such as macvimif has("gui_running") "set guifont=Monaco:h12 set guifont=Source\ Code\ Pro\ for\ Powerline:h12 " for vim-airline set gcr=a:blinkon0 "Disable cursor blink set lines=60 set columns=150else colorscheme Zenburnendif" Highlight TODO/FIXME/XXXhighlight myTODO cterm=bold term=bold ctermbg=yellow ctermfg=blackmatch myTODO /\(TODO\|XXX\|FIXME\)/" this options can be setted with colors, and must be put after colorschemeset cursorline " Highlighter the current lineset cursorcolumn " Highlighter the vertical line"hi search cterm=underline ctermfg=whitehighlight PmenuSel cterm=underline,bold ctermfg=blue"设置光标样式为竖线vertical bar"" Change cursor shape between insert and normal mode in iTerm2.appif $TERM_PROGRAM =~ "iTerm" let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal modeendif" 设置在tmux下光标样式为vertical barif exists('$TMUX') let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\" let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"else let &t_SI = "\<Esc>]50;CursorShape=1\x7" let &t_EI = "\<Esc>]50;CursorShape=0\x7"endif 打赏 微信支付 支付宝