Skip to content

Instantly share code, notes, and snippets.

@clarksun
Last active December 8, 2019 12:55
Show Gist options
  • Save clarksun/d2273aa91d546dfb6994adae0fb2c531 to your computer and use it in GitHub Desktop.
Save clarksun/d2273aa91d546dfb6994adae0fb2c531 to your computer and use it in GitHub Desktop.
vim配置 #vim
set shell=/bin/bash
" config Vundle
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'ctrlpvim/ctrlp.vim' " fuzzy find files
Plugin 'scrooloose/nerdtree' " file drawler, open with :NERDTreeToggle
Plugin 'benmills/vimux'
Plugin 'tpope/vim-fugitive' " the ultimate git helper
Plugin 'tpope/vim-commentary' " comment/uncomment lines with gcc or gc in visual mode
Plugin 'tpope/vim-surround'
" Plugin 'Valloric/YouCompleteMe' " 2.7
" Plugin 'scrooloose/syntastic' "和异步的ale冲突
" colorschemes
" Plugin 'chriskempson/base16-vim'
Plugin 'joshdick/onedark.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
"Plugin 'w0rp/ale'
Plugin 'Yggdroot/indentLine'
"Plugin 'powerline/powerline',{'rtp': 'powerline/bindings/vim/'} " 2.7
Plugin 'CodeFalling/fcitx-vim-osx'
"golang
Plugin 'fatih/vim-go'
"ansible
Plugin 'pearofducks/ansible-vim'
"pep8 indent
Plugin 'Vimjas/vim-python-pep8-indent'
call vundle#end()
filetype plugin indent on
set nocompatible " not compatible with vi
set autoread " detect when a file is changed
" Disable backups and .swp files.
set nobackup
set noswapfile
set nowritebackup
" make backspace behave in a sane manner
set backspace=indent,eol,start
" set a map leader for more key combos
let mapleader = ','
" Tab control
set expandtab " tabs ftw
" set smarttab " tab respects 'tabstop', 'shiftwidth', and 'softtabstop'
set tabstop=4 " the visible width of tabs
set softtabstop=4 " edit as if the tabs are 4 characters wide
set shiftwidth=4 " number of spaces to use for indent and unindent
" set shiftround " round indent to a multiple of 'shiftwidth'
" set cindent
" set autoindent " automatically set indent of new line
" set smartindent
imap jj <ESC>
" use system clipboard
set clipboard=unnamed
" faster redrawing
" set ttyfast
" code folding settings
" set foldmethod=syntax " fold based on indent
" set foldnestmax=10 " deepest fold is 10 levels
set nofoldenable " don't fold by default
" set foldlevel=999999
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => User Interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Searching
set ignorecase " case insensitive searching
set smartcase " case-sensitive if expresson contains a capital letter
set hlsearch
set incsearch " set incremental search, like modern browsers
set nolazyredraw " don't redraw while executing macros
set magic " Set magic on, for regex
set showmatch " show matching braces
set mat=2 " how many tenths of a second to blink
" switch syntax highlighting on
let python_highlight_all=1
syntax enable
set encoding=utf8
"let base16colorspace=256 " Access colors present in 256 colorspace"
"set t_Co=256 " Explicitly tell vim that the terminal supports 256 colors"
"set background=dark
colorscheme onedark
set number
set laststatus=2 " show the satus line all the time
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>ev :e! ~/.vimrc<cr> " edit ~/.vimrc
map <leader>wc :wincmd q<cr>
" moving up and down work as you would expect
nnoremap <silent> j gj
nnoremap <silent> k gk
" helpers for dealing with other people's code
nmap \t :set ts=4 sts=4 sw=4 noet<cr>
nmap \s :set ts=4 sts=4 sw=4 et<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <C-h> :call WinMove('h')<cr>
map <C-j> :call WinMove('j')<cr>
map <C-k> :call WinMove('k')<cr>
map <C-l> :call WinMove('l')<cr>
" Window movement shortcuts
" move to the window in the direction shown, or create a new window
function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
if (match(a:key,'[jk]'))
wincmd v
else
wincmd s
endif
exec "wincmd ".a:key
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin settings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" close NERDTree after a file is opened
let g:NERDTreeQuitOnOpen=0
" show hidden files in NERDTree
let NERDTreeShowHidden=1
" Toggle NERDTree
nmap <silent> <leader>k :NERDTreeToggle<cr>
" expand to the path of the file in the current buffer
nmap <silent> <leader>y :NERDTreeFind<cr>
" map fuzzyfinder (CtrlP) plugin
" nmap <silent> <leader>t :CtrlP<cr>
" nmap <silent> <leader>r :CtrlPBuffer<cr>
nmap <silent> <leader>r :CtrlPMixed<cr>
let g:ctrlp_map='<leader>t'
let g:ctrlp_dotfiles=1
let g:ctrlp_working_path_mode = 'ra'
" CtrlP ignore patterns
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|node_modules$\|\.hg$\|\.svn$\|build$\|__pycache__$',
\ 'file': '\.exe$\|\.so$'
\ }
" search the nearest ancestor that contains .git, .hg, .svn
let g:ctrlp_working_path_mode = 2
" vim-commentary
autocmd FileType python,shell set commentstring=#\ %s
" powerline
"set rtp+=/usr/local/lib/python2.7/site-packages/powerline/bindings/vim
" python3
set encoding=utf-8
"python with virtualenv support
" py << EOF
" import os
" import sys
" if 'VIRTUAL_ENV' in os.environ:
" project_base_dir = os.environ['VIRTUAL_ENV']
" activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
" execfile(activate_this, dict(__file__=activate_this))
" EOF
" Youcompleteme
" map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
" let g:ycm_autoclose_preview_window_after_insertion = 1
" let g:ycm_autoclose_preview_window_after_completion = 1
" syntastic
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
" let g:syntastic_python_checkers = ['pylint']
"Vimux
" Run last command executed by VimuxRunCommand
map <Leader>vp :VimuxPromptCommand<CR>
map <Leader>vl :VimuxRunLastCommand<CR>
map <Leader>vq :VimuxCloseRunner<CR>
map <Leader>vz :call VimuxZoomRunner()<CR>
map <Leader>vx :VimuxInterruptRunner<CR>
map <Leader>vi :VimuxInspectRunner<CR>
" ale python3
"let g:ale_python_pylint_executable = 'python3'
" nerdtree ignore
let NERDTreeIgnore = ['\.pyc$', '\.swp$', '\.DS_Store$']
" 120 column layout mark
" highlight OverLength ctermbg=darkred ctermfg=white guibg=#FFD9D9
" match OverLength /\%121v.\+/
" mypy
map <Leader>mp :Mypy<CR>
" boxes
" autocmd BufEnter * nmap ,mc !!boxes -d pound-cmt<CR>
" autocmd BufEnter * vmap ,mc !boxes -d pound-cmt<CR>
" autocmd BufEnter * nmap ,xc !!boxes -d pound-cmt -r<CR>
" autocmd BufEnter * vmap ,xc !boxes -d pound-cmt -r<CR>
autocmd BufEnter * nmap ,mc !!boxes -d shell<CR>
autocmd BufEnter * vmap ,mc !boxes -d shell<CR>
autocmd BufEnter * nmap ,xc !!boxes -d shell -r<CR>
autocmd BufEnter * vmap ,xc !boxes -d shell -r<CR>
autocmd BufEnter *.html nmap ,mc !!boxes -d html-cmt<CR>
autocmd BufEnter *.html vmap ,mc !boxes -d html-cmt<CR>
autocmd BufEnter *.html nmap ,xc !!boxes -d html-cmt -r<CR>
autocmd BufEnter *.html vmap ,xc !boxes -d html-cmt -r<CR>
autocmd BufEnter *.[chly],*.[pc]c nmap ,mc !!boxes -d c-cmt<CR>
autocmd BufEnter *.[chly],*.[pc]c vmap ,mc !boxes -d c-cmt<CR>
autocmd BufEnter *.[chly],*.[pc]c nmap ,xc !!boxes -d c-cmt -r<CR>
autocmd BufEnter *.[chly],*.[pc]c vmap ,xc !boxes -d c-cmt -r<CR>
autocmd BufEnter *.C,*.cpp,*.java nmap ,mc !!boxes -d java-cmt<CR>
autocmd BufEnter *.C,*.cpp,*.java vmap ,mc !boxes -d java-cmt<CR>
autocmd BufEnter *.C,*.cpp,*.java nmap ,xc !!boxes -d java-cmt -r<CR>
autocmd BufEnter *.C,*.cpp,*.java vmap ,xc !boxes -d java-cmt -r<CR>
autocmd BufEnter .vimrc*,.exrc nmap ,mc !!boxes -d vim-cmt<CR>
autocmd BufEnter .vimrc*,.exrc vmap ,mc !boxes -d vim-cmt<CR>
autocmd BufEnter .vimrc*,.exrc nmap ,xc !!boxes -d vim-cmt -r<CR>
autocmd BufEnter .vimrc*,.exrc vmap ,xc !boxes -d vim-cmt -r<CR>
" firacode font
" set macligatures
" set guifont=Fira\ Code:h12
" ansible
let g:ansible_unindent_after_newline = 1
"vimdiff
if &diff
set cursorline
map Q :cquit<CR>
map ] ]c
map [ [c
hi DiffAdd ctermfg=233 ctermbg=LightGreen guifg=#003300 guibg=#DDFFDD gui=none cterm=none
hi DiffChange ctermbg=white guibg=#ececec gui=none cterm=none
hi DiffText ctermfg=233 ctermbg=yellow guifg=#000033 guibg=#DDDDFF gui=none cterm=none
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment