V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
china521
V2EX  ›  分享发现

突然想让大家把 Vim 配置跟撸码的时候的截图发一下, 看谁的更好玩.

  •  
  •   china521 · 2015-10-23 19:08:38 +08:00 · 3320 次点击
    这是一个创建于 3314 天前的主题,其中的信息可能已经有所发展或是发生改变。

    开发环境: Go+Vim+AngularJS+HTML+C+Cross GCC+Python+各种脚本... 这么长只为装逼, 上图:

    http://ww3.sinaimg.cn/large/82874e85jw1exb9uf1lxmj213z0o6dpt.jpg

    " git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    "
    set nocompatible "set nocompatible must be the first line
    let vimrcLocal = ".vimrc.local"
    if has("win32")
        let vimrcLocal = "_vimrc.local"
        source $VIMRUNTIME/vimrc_example.vim
        source $VIMRUNTIME/mswin.vim
        behave mswin
        set diffexpr=MyDiff()
        function MyDiff()
          let opt = '-a --binary '
          if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
          if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
          let arg1 = v:fname_in
          if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
          let arg2 = v:fname_new
          if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
          let arg3 = v:fname_out
          if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
          let eq = ''
          if $VIMRUNTIME =~ ' '
            if &sh =~ '\<cmd'
              let cmd = '""' . $VIMRUNTIME . '\diff"'
              let eq = '"'
            else
              let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
            endif
          else
            let cmd = $VIMRUNTIME . '\diff'
          endif
          silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
        endfunction
    endif
    "set rtp+=$GOROOT/misc/vim
    set rtp+=$HOME/.vim/bundle/Vundle.vim
    
    set nocompatible              " be iMproved, required
    filetype off                  " required
    
    call vundle#begin()
    
    Bundle 'altercation/vim-colors-solarized'
    Bundle 'scrooloose/nerdcommenter'
    Bundle 'Lokaltog/vim-powerline'
    Bundle 'kien/ctrlp.vim'
    Bundle 'Shougo/neocomplcache'
    Bundle 'Lokaltog/vim-easymotion'
    Bundle 'tpope/vim-surround'
    Bundle 'terryma/vim-multiple-cursors'
    Bundle 'terryma/vim-expand-region'
    Bundle 'godlygeek/tabular'
    Bundle 'vim-scripts/Emmet.vim'
    Bundle 'rosenfeld/conque-term'
    Bundle 'nathanaelkane/vim-indent-guides'
    Bundle 'fatih/vim-go'
    Bundle 'honza/vim-snippets'
    Bundle 'sirver/ultisnips'
    Bundle 'majutsushi/tagbar'
    Bundle 'scrooloose/nerdtree'
    
    
    let g:UltiSnipsExpandTrigger = '<Tab>'
    let g:UltiSnipsJumpForwardTrigger = '<Tab>'
    let g:UltiSnipsJumpBackwardTrigger = '<S-Tab>'
    let g:UltiSnipsListSnippets = '<C-Tab>'
    
    Bundle 'XPstatusline'
    Bundle 'TaskList.vim'
    Bundle 'LustyExplorer'
    Bundle 'HTML-AutoCloseTag'
    Bundle 'workflowish'
    
    Bundle 'burnettk/vim-angular'
    call vundle#end()
    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
    
    
    " ------------------------------------------------------------------
    " Desc: Vim UI
    " ------------------------------------------------------------------
    set shortmess=atI " shortens messages to avoid 'press a key' prompt(hidden tip info when open the vim)
    set wildmenu " turn on wild menu, try typing :h and press <Tab>
    set showcmd " display incomplete commands
    set cmdheight=1 " 1 screen lines to use for the command-line
    set ruler " show the cursor position all the time
    set hid " allow to change buffer without saving
    set lazyredraw " do not redraw while executing macros (much faster)
    set display+=lastline " for easy browse last line with wrap text
    
    set makeef=error.err " the errorfile for :make and :grep
    set visualbell  "shut up
    set foldmethod=indent
    set nofoldenable
    
    "set clipboard=unnamed
    set bs=2    " make backspace behave like normal again
    set noeb
    
    set tw=79   " width of document (used by gd)
    set nowrap  " don't automatically wrap on load
    set fo-=t   " don't automatically wrap text when typing
    " set colorcolumn=80
    highlight ColorColumn ctermbg=233
    
    " Useful settings
    set history=700
    set undolevels=700
    
    
    syntax enable
    "set scrolloff=999 " set lines to show top and down in cursor line
    set autoread " file change auto load
    set autochdir " auto change work directory
    set number " show line number
    set nowrap " I don't like wrap, cause in split window mode, it feel strange
    set cindent shiftwidth=4 " Set cindent on to autoinent when editing C/C++ file, with 4 shift width
    "set awa " auto save
    set ai " auto indentation
    set nobackup " no create backup file with prefix '~'
    set nowritebackup
    set noswapfile
    
    " Real programmers don't use TABs but spaces
    set tabstop=4
    set softtabstop=4
    set shiftwidth=4
    set shiftround
    set expandtab
    
    
    " Make search case insensitive
    set hlsearch
    set incsearch
    set ignorecase
    set smartcase
    
    let mapleader = ","
    nmap <leader>b :ConqueTermVSplit bash<CR>
    nmap <leader>gc :GoDoc<CR>
    nmap <leader>p "+P
    nmap <leader>w :w<CR>
    nnoremap <leader>v <C-w>v
    nnoremap <leader>s <C-w>s
    nmap <silent> <leader>h :nohlsearch<CR>
    
    map <leader>o :tabnew<CR>
    map <leader><space> gt
    map <leader>n <esc>:tabprevious<CR>
    map <leader>m <esc>:tabnext<CR>
    noremap <leader>[ :cprev<cr>
    noremap <leader>] :cnext<cr>
    
    map <leader>x :quit<CR> " Quit current window
    map <leader>X :qa!<CR>  " Quick all windows
    nmap <leader>z :%s/\<<c-r>=expand("<cword>")<cr>\>/
    
    
    " nerdtree
    let g:NERDTreeQuitOnOpen = 1
    nmap <leader>F :NERDTreeToggle<CR>
    " close vim if the only window left open is a NERDTree
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
    
    " Execute python file being edited with <leader> + r:
    autocmd FileType * map <buffer> <leader>r :call ComplieCode()<CR>
    autocmd FileType python map <leader>b Oimport ipdb; ipdb.set_trace() # BREAKPOINT<C-c>
    autocmd FileType go map <leader>f :GoImports<CR>
    
    " Strip all whitespace in the current buffer
    nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
    
    " map sort function to a key
    vnoremap <Leader>s :sort<CR>" map sort function to a key
    
    " Search the current file for what's currently in the search register and display matches
    nmap <silent> <leader>gs :vimgrep /<C-r>// %<CR>:ccl<CR>:cwin<CR><C-W>J:nohls<CR>
    
    " Search the current file for the word under the cursor and display matches
    nmap <silent> <leader>gw :vimgrep /<C-r><C-w>/ %<CR>:ccl<CR>:cwin<CR><C-W>J:nohls<CR>
    
    " Search the current file for the WORD under the cursor and display matches
    nmap <silent> <leader>gW :vimgrep /<C-r><C-a>/ %<CR>:ccl<CR>:cwin<CR><C-W>J:nohls<CR>
    
    " easier moving of code blocks
    " Try to go into visual mode (v), thenselect several lines of code here and
    " then press ``>`` several times.
    " vnoremap < <gv  " better indentation
    " vnoremap > >gv  " better indentation
    
    " Show whitespace
    " MUST be inserted BEFORE the colorscheme command
    " autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
    " au InsertLeave * match ExtraWhitespace /\s\+$/
    
    
    " bind Ctrl+<movement> keys to move around the windows, instead of ctrl+w ctrl+<movement>
    map <c-j> <c-w>j
    map <c-k> <c-w>k
    map <c-l> <c-w>l
    map <c-h> <c-w>h
    
    " Bind nohl
    " Removes highlight of your last search
    " ``<C>`` stands for ``CTRL`` and therefore ``<C-n>`` stands for ``CTRL+n``
    "" noremap <C-n> :nohl<CR>
    "" vnoremap <C-n> :nohl<CR>
    "" inoremap <C-n> :nohl<CR>
    
    " Quicksave command
    noremap <C-Z> :update<CR>
    vnoremap <C-Z> <C-C>:update<CR>
    inoremap <C-Z> <C-O>:update<CR>
    
    " Settings for ctrlp
    " cd ~/.vim/bundle
    " git clone https://github.com/kien/ctrlp.vim.git
    let g:ctrlp_max_height = 30
    let g:ctrlp_mruf_max = 200
    let g:ctrlp_map = '<c-p>'
    let g:ctrlp_cmd = 'CtrlP'
    let g:ctrlp_working_path_mode = 'ra'
    " Make ctrlp's location sync with nerdtree window
    let g:ctrlp_dont_split = 'nerdtree'
    set wildignore+=*.o,*~,*.pyc,*_build/*,*/converage/*,*.mo,*.po,*.so
    let g:ctrlp_custom_ignore = 'node_modules\|bower_components\|.pyc|DS_Store|(\.(swp|ico|git|svn))'
    " Use tab to open new files in split windows
    let g:ctrlp_prompt_mappings = {
      \ 'AcceptSelection("e")': [],
      \ 'AcceptSelection("t")': ['<cr>', '<c-m>'],
      \ }
    nnoremap <c-b> :CtrlPBuffer<CR>
    nnoremap <leader>e :CtrlPMRUFiles<CR>
    
    " Indent Guides
    let g:indent_guides_guide_size = 1
    map <leader>i :IndentGuidesToggle<CR>
    let g:indent_guides_auto_colors = 0
    hi IndentGuidesOdd ctermbg=black
    hi IndentGuidesEven ctermbg=darkgrey
    let g:indent_guides_auto_colors = 0
    autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  guibg=red   ctermbg=3
    autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
    
    
    
    """"""""""""""""""""""""""""""
    " neocomplcache
    let g:acp_enableAtStartup = 0
    let g:neocomplcache_enable_at_startup = 1 " or run :NeoComplCacheEnable
    let g:neocomplcache_enable_smart_case = 1
    let g:neocomplcache_enable_camel_case_completion = 1
    let g:neocomplcache_enable_underbar_completion = 1
    " When you input 'ho-a',neocomplcache will select candidate 'a'.
    let g:neocomplcache_enable_quick_match = 1
    if !exists('g:neocomplcache_omni_patterns')
        let g:neocomplcache_omni_patterns = {}
    endif
    let g:neocomplcache_omni_patterns.go = '\h\w*\.\?'
    
    """"""""""""""""""""""""""""""
    
    " ------------------------------------------------------------------
    " Desc: snipMate
    " ------------------------------------------------------------------
    
    map <F7> :call CompileRunGcc()<CR>
    func! CompileRunGcc()
      exec "w"
      exec "!gcc % -o %<"
      exec "! ./%<"
    endfunc
    
    func! CompileRunNasm()
      exec "w"
      exec "!rm -rf %<.o"
      exec "!rm -rf %<"
      exec "!nasm -f macho64 % -o %<.o"
      exec "!ld %<.o -o %<"
      exec "! ./%<"
    endfunc
    
    func! ComplieRunObjc()
      exec "w"
      exec "!gcc -framework Foundation % -o %<"
      exec "! ./%<"
      echo "OKOK"
    endfunc
    
    func! ComplieCode()
        exec "w"
        if &filetype == "cpp"
        elseif &filetype == "nasm"
            exec "call CompileRunNasm()"
        elseif &filetype == "c"
            exec "call CompileRunGcc()"
        elseif &filetype == "objc"
            exec "call ComplieRunObjc()"
        elseif &filetype == "python"
            exec "!python \"%\""
        elseif &filetype == "ruby"
            exec "!ruby %"
        elseif &filetype == "perl"
            exec "!perl %"
        elseif &filetype == "lua"
            exec "!lua %"
        elseif &filetype == "go"
            "exec "!go run %"
            exec ":GoRun %"
        elseif &filetype == "php"
            exec "!php \"%\""
        elseif &filetype == "javascript"
            exec "!node \"%\""
        endif
    endfunc
    
    func! Commit()
        exec "w"
        exec "!git commit % -m 'vim commit for %'"
    endfunc
    
    map <C-F9> :call ComplieCode()<CR>
    map <leader>c :call Commit()<CR>
    nmap <F7> :make<cr>
    
    " set match method, when input a left '(', auto match twinning ')'
    set showmatch
    
    " disable beep sound
    "set vb t_vb=
    " disable cursor blink
    set gcr=a:block-blinkon0
    
    " solution chinese encode
    let &termencoding=&encoding
    set fileencodings=utf-8,gbk,ucs-bom,cp936
    
    nnoremap <silent> <F3> :Grep<CR>
    
    autocmd BufReadPost * set tags+=tags;
    set completeopt=longest,menuone
    autocmd FileType python set omnifunc=pythoncomplete#Complete
    
    let g:tagbar_type_go = {
        \ 'ctagstype' : 'go',
        \ 'kinds'     : [
            \ 'p:package',
            \ 'i:imports:1',
            \ 'c:constants',
            \ 'v:variables',
            \ 't:types',
            \ 'n:interfaces',
            \ 'w:fields',
            \ 'e:embedded',
            \ 'm:methods',
            \ 'r:constructor',
            \ 'f:functions'
        \ ],
        \ 'sro' : '.',
        \ 'kind2scope' : {
            \ 't' : 'ctype',
            \ 'n' : 'ntype'
        \ },
        \ 'scope2kind' : {
            \ 'ctype' : 't',
            \ 'ntype' : 'n'
        \ },
        \ 'ctagsbin'  : 'gotags',
        \ 'ctagsargs' : '-sort -silent'
    \ }
    
    nnoremap <unique> <silent> <leader>T :TagbarOpenAutoClose<CR>
    
    "Quickfix
    nmap \cc :cc<cr>
    nmap \cn :cn<cr>
    nmap \cp :cp<cr>
    nmap \cw :cw 6<cr>
    
    
    let g:LustyExplorerSuppressRubyWarning = 1
    let g:LustyJugglerSuppressRubyWarning = 1
    
    " git clone https://github.com/Lokaltog/vim-easymotion.git
    " http://net.tutsplus.com/tutorials/other/vim-essential-plugin-easymotion/
    let g:EasyMotion_leader_key = '<Leader><Leader>'
    
    " git clone http://github.com/mattn/zencoding-vim.git
    let g:use_zen_complete_tag = 1
    let g:user_zen_settings = {
    \ 'php' : {
    \ 'extends' : 'html',
    \ 'filters' : 'c',
    \ },
    \ 'tpl' : {
    \ 'extends' : 'html',
    \ },
    \}
    
    "javascript 语法高亮脚本的设置
    let g:javascript_enable_domhtmlcss=1
    
    map <leader>td <Plug>TaskList
    
    " Tabular.vim
    nmap <Leader>a= :Tabularize /^[^=]*\zs=>\?<CR>
    vmap <Leader>a= :Tabularize /^[^=]*\zs=>\?<CR>
    nmap <Leader>a: :Tabularize /:\zs/l0r1<CR>
    vmap <Leader>a: :Tabularize /:\zs/l0r1<CR>
    nmap <Leader>a, :Tabularize /,\zs/l1r0<CR>
    vmap <Leader>a, :Tabularize /,\zs/l1r0<CR>
    vmap <Leader>a  :Tabularize / \zs/l1r0<CR>
    
    " vim-go
    let g:gofmt_command = "goimports"
    let g:go_highlight_functions = 1
    let g:go_highlight_methods = 1
    let g:go_highlight_structs = 1
    
    """"""""""""""""""""""""""""
    " set guifont
    function s:SetGuiFont()
        if has("gui_gtk2")
            set guifont=Luxi\ Mono\ 10
        elseif has("x11")
            " Also for GTK 1
            set guifont=*-lucidatypewriter-medium-r-normal-*-*-180-*-*-m-*-*
        elseif has("gui_win32") || has("win32") || has("win64")
            let font_name = ""
            if getfontname("Monaco") != ""
                set guifont=Monaco:h12:w6.5
                let font_name = "Inconsolata"
            elseif getfontname( "Consolas" ) != ""
                set guifont=Consolas:h10.5:cANSI
                let font_name = "Consolas"
            elseif getfontname( "Bitstream_Vera_Sans_Mono" ) != ""
                set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI " this is the default visual studio font
                let font_name = "Bitstream_Vera_Sans_Mono"
            else
                " just make it, health to my eyes
                set guifont=Lucida_Console:h10.5:cANSI
                "set guifont=Lucida_Console:h15:cANSI
                let font_name = "Lucida_Console"
            endif
            silent exec "nnoremap <unique> <A-F1> :set guifont=".font_name.":h11:cANSI<CR>"
        elseif has("unix") && !has('gui_macvim')
            set guifont=Courier\ 11\ Pitch\ 12
        elseif has("mac") || hash("gui_macvim")
            set anti
            set guifont=Menlo:h18
            set guifontwide=Menlo:h18
        endif
    endfunction
    
    if has("gui_running")
        if has("win32")
            map <F11> :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>
        endif
        " check and determine the gui font after GUIEnter.
        " NOTE: getfontname function only works after GUIEnter.
        au GUIEnter * call s:SetGuiFont()
        set lines=40 columns=130
        "set guioptions-=m
        set guioptions-=T " hide toobar
        "set guioptions-=r " hide right scrollbar
        "set guioptions-=b " hide bottom scrollbar
        set showfulltag " show tag with function protype.
        set showtabline=1
        set background=light
    else
        let g:solarized_termcolors=256
        set background=light
    endif
    "set cuc    " highlight colum on cursor
    "set cul " highlith line on cursor
    colorscheme solarized
    
    
    if filereadable(vimrcLocal)
        exec 'source ' . vimrcLocal
    endif
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3793 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:18 · PVG 12:18 · LAX 20:18 · JFK 23:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.