Skip to content

Instantly share code, notes, and snippets.

@keelii
Created July 11, 2016 11:37
Show Gist options
  • Select an option

  • Save keelii/9b984c83d923b196a1028c7bceb3febd to your computer and use it in GitHub Desktop.

Select an option

Save keelii/9b984c83d923b196a1028c7bceb3febd to your computer and use it in GitHub Desktop.
vimrc for ubuntu
" ------------------------------
" Name: vimrc for windows
" Author: keelii
" Email: [email protected]
" ------------------------------
" Startup {{{
filetype indent plugin on
augroup vimrcEx
au!
autocmd FileType text setlocal textwidth=78
augroup END
" vim 文件折叠方式为 marker
augroup ft_vim
au!
autocmd FileType vim setlocal foldmethod=marker
" 打开文件总是定位到上次编辑的位置
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"<space>" |
\ endif
augroup END
augroup END
" }}}
" General {{{
set nocompatible
set nobackup
set noswapfile
set history=1024
set autochdir
set whichwrap=b,s,<,>,[,]
set nobomb
set backspace=indent,eol,start whichwrap+=<,>,[,]
" Vim 的默认寄存器和系统剪贴板共享
set clipboard+=unnamed
" 设置 alt 键不映射到菜单栏
set winaltkeys=no
" }}}
" Lang & Encoding {{{
set fileencodings=utf-8,gbk2312,gbk,gb18030,cp936
set encoding=utf-8
set langmenu=zh_CN
" http://vimcdoc.sourceforge.net/
set helplang=cn
let $LANG = 'en_US.UTF-8'
"language messages zh_CN.UTF-8
" }}}
" GUI {{{
" colorscheme Tomorrow-Night
" colorscheme desert
colorscheme onedark
" source $VIMRUNTIME/delmenu.vim
" source $VIMRUNTIME/menu.vim
set cursorline
set hlsearch
set nonumber
" 窗口大小
set lines=35 columns=140
" 分割出来的窗口位于当前窗口下边/右边
set splitbelow
set splitright
"不显示工具/菜单栏
set guioptions-=T
set guioptions-=m
set guioptions-=L
set guioptions-=r
set guioptions-=b
" 使用内置 tab 样式而不是 gui
set guioptions-=e
" set nolist
set listchars=trail:·,extends:>,precedes:<
set guifont=FiraMono:h12:cANSI
" 始终显示 tab 标签
set showtabline=2
set statusline=%f
set statusline+=%m
set statusline+=\ %{fugitive#head()}
set statusline+=%=
set statusline+=%{''.(&fenc!=''?&fenc:&enc).''}
set statusline+=/
set statusline+=%{&ff}
set statusline+=\ -\ " Separator
set statusline+=%l/%L
set statusline+=[%p%%]
set statusline+=\ -\ " Separator
set statusline +=%1*\ %y\ %*
" }}}
" Format {{{
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set foldmethod=indent
set foldlevel=10
syntax on
" }}}
" Keymap {{{
let mapleader=","
nmap <leader>s :source $MYVIMRC<cr>
nmap <leader>e :e $MYVIMRC<cr>
nmap <leader>tn :tabnew<cr>:NERDTree<cr><C-W>h
nmap <leader>tc :tabc!<cr>
nmap <leader>tco :tabo!<cr>
nmap <leader>th :tabp<cr>
nmap <leader>tl :tabn<cr>
" 移动分割窗口
nmap <C-j> <C-W>j
nmap <C-k> <C-W>k
nmap <C-h> <C-W>h
nmap <C-l> <C-W>l
" 正常模式下 alt+j,k,h,l 调整分割窗口大小
nnoremap <M-j> :resize +5<cr>
nnoremap <M-k> :resize -5<cr>
nnoremap <M-h> :vertical resize -5<cr>
nnoremap <M-l> :vertical resize +5<cr>
" 插入模式移动光标 alt + 方向键
inoremap <M-j> <Down>
inoremap <M-k> <Up>
inoremap <M-h> <left>
inoremap <M-l> <Right>
" IDE like delete
inoremap <C-BS> <Esc>bdei
nnoremap vv ^vg_
" 转换当前行为大写
inoremap <C-u> <esc>mzgUiw`za
" 命令模式下的行首尾
cnoremap <C-a> <home>
cnoremap <C-e> <end>
nnoremap <F2> :setlocal number!<cr>
nnoremap <leader>w :set wrap!<cr>
imap <C-v> "+gP
vmap <C-c> "+y
vnoremap <BS> d
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y
imap <C-V> "+gP
map <S-Insert> "+gP
cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
" 打开当前目录 windows
nmap <silent> <leader>ex :!start explorer %:p:h<CR>
" 打开当前目录CMD
nmap <silent> <leader>cmd :!start cmd /k cd %:p:h<cr>
" 打印当前时间
nmap <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
let NERDTreeBookmarksFile = $VIM . '/NERDTreeBookmarks'
" 复制当前文件/路径到剪贴板
nmap ,fn :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
nmap ,fp :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>
"设置切换Buffer快捷键"
nnoremap <C-left> :bn<CR>
nnoremap <C-right> :bp<CR>
" }}}
" Plugin {{{
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin('~/.vim/bundle')
" ----- Vundle ----- {{{
Plugin 'VundleVim/Vundle.vim'
" }}}
" ----- NerdTree ----- {{{
Plugin 'scrooloose/nerdtree'
let NERDTreeIgnore=['.idea', '.vscode', 'node_modules', '*.pyc']
let NERDTreeBookmarksFile = $VIM . '/NERDTreeBookmarks'
let NERDTreeMinimalUI = 1
let NERDTreeBookmarksSort = 1
let NERDTreeShowLineNumbers = 0
let NERDTreeShowBookmarks = 1
let g:NERDTreeWinPos = 'right'
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
nmap <leader>n :NERDTreeToggle <cr>
if exists('g:NERDTreeWinPos')
autocmd vimenter * NERDTree ~/repo
endif
" }}}
" ----- Multiple-cursors ----- {{{
Plugin 'terryma/vim-multiple-cursors'
" }}}
" ----- Tabular ----- {{{
Plugin 'godlygeek/tabular'
" }}}
" ----- Markdown ----- {{{
Plugin 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled = 1
" }}}
" ----- Yet Other JavaScript Syntax ----- {{{
Plugin 'othree/yajs.vim'
" }}}
" ----- Ctrlp ----- {{{
Plugin 'kien/ctrlp.vim'
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:10,results:10'
set wildignore+=*\\.git\\*,*\\tmp\\*,*.swp,*.zip,*.exe,*.pyc
" }}}
" ----- Nerdcommenter ----- {{{
Plugin 'scrooloose/nerdcommenter'
" }}}
" ----- Emmet ----- {{{
Plugin 'mattn/emmet-vim'
" }}}
" ----- SnipMate ----- {{{
" Plugin 'MarcWeber/vim-addon-mw-utils'
" Plugin 'tomtom/tlib_vim'
" Plugin 'garbas/vim-snipmate'
" Replace your repo
" Plugin 'keelii/vim-snippets'
" Allow for vimrc re-sourcing
let g:snipMate = get(g:, 'snipMate', {})
" }}}
" ----- ultisnips----- {{{
Plugin 'SirVer/ultisnips'
" Plugin 'honza/vim-snippets'
Plugin 'keelii/vim-snippets'
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'
" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" }}}
" ----- Fugitive ----- {{{
Plugin 'tpope/vim-fugitive'
" }}}
" ----- YouCompleteMe ----- {{{
Plugin 'Valloric/YouCompleteMe'
" }}}
" ----- ternjs ----- {{{
Plugin 'ternjs/tern_for_vim'
" }}}
" ----- Jinja2 ----- {{{
Plugin 'Glench/Vim-Jinja2-Syntax'
" }}}
" ----- Jinja2 ----- {{{
Plugin 'hynek/vim-python-pep8-indent'
" }}}
filetype on
call vundle#end()
" }}}
" Function {{{
" Remove trailing whitespace when writing a buffer, but not for diff files.
" From: Vigil
" @see http://blog.bs2.to/post/EdwardLee/17961
function! RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment