Skip to content

Instantly share code, notes, and snippets.

@jasonliao
Last active August 16, 2018 06:21
Show Gist options
  • Save jasonliao/03cded53bbbf3ec3602e99ca671c2dcb to your computer and use it in GitHub Desktop.
Save jasonliao/03cded53bbbf3ec3602e99ca671c2dcb to your computer and use it in GitHub Desktop.
my awesome `.vimrc`
execute pathogen#infect()
filetype plugin on
filetype indent on
set history=700
set autoread
set so=7
set wildmenu
set ruler
set cmdheight=1
set hid
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set ignorecase
set smartcase
set hlsearch " highlight matches
set incsearch " search as characters are entered
set lazyredraw
set magic
set showmatch " highlight matching [{()}]
set mat=2
set noerrorbells
set novisualbell
set t_vb=
set t_Co=256
set tm=500
syntax enable
set background=dark
colorscheme monokai
set encoding=utf8
set ffs=unix,dos,mac
set nobackup
set nowb
set noswapfile
set expandtab " tabs are space
set smarttab
set shiftwidth=2
set tabstop=2
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
:set number
set mouse=a
set laststatus=2
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
set cursorline
" tern for vim
set completeopt-=preview
" ============== leader shortcut start ==============
let mapleader = ","
let g:mapleader = ","
" save file
nmap <leader>w :w!<cr>
"
nmap <leader>l iconsole.log(
" remove highlight
map <silent> <leader><cr> :noh<cr>
" tab operation
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tj :tabprevious<cr>
map <leader>tk :tabnext<cr>
map <leader>tm :tabmove
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" move whole line
nmap <leader>j :m .+1<cr>==
nmap <leader>k :m .-2<cr>==
vmap <leader>j :m '>+1<cr>gv=gv
vmap <leader>k :m '<-2<cr>gv=gv
" replace highlight with current text
nmap <leader>s :%s//<c-r><c-w>/g<cr>
" ============== leader shortcut end ==============
" Set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T
set guioptions+=e
set guifont=Monaco\ for\ Powerline\ Bold\ 11
set t_Co=256
set guitablabel=%M\ %t
set guioptions-=m "remove menu bar
set guioptions-=T "remove toolbar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=L "remove left-hand scroll bar
set lines=999 columns=999
let g:Powerline_symbols="fancy"
endif
:imap jj <Esc>
map 0 ^
map <space> /
map <c-space> ?
map <F3> :NERDTreeToggle<CR>
" option/(alt) move the line, not working in mac os
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
" indent using tab
nmap <tab> v>
nmap <s-tab> v<
vmap <tab> >gv
vmap <s-tab> <gv
function! CheckLeftBuffers()
if tabpagenr('$') == 1
let i = 1
while i <= winnr('$')
if getbufvar(winbufnr(i), '&buftype') == 'help' ||
\ getbufvar(winbufnr(i), '&buftype') == 'quickfix' ||
\ exists('t:NERDTreeBufName') &&
\ bufname(winbufnr(i)) == t:NERDTreeBufName ||
\ bufname(winbufnr(i)) == '__Tag_List__'
let i += 1
else
break
endif
endwhile
if i == winnr('$') + 1
qall
endif
unlet i
endif
endfunction
autocmd BufEnter * call CheckLeftBuffers()
autocmd vimenter * NERDTree
highlight Cursor ctermbg=Green
au FileType mail let b:delimitMate_autoclose = 0
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END
" vim-jsx settings
let g:jsx_ext_required = 0
let g:ctrlp_working_path_mode = 0
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
if has("mac") || has("macunix")
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif
" Delete trailing white space on save, useful for Python and CoffeeScript ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
autocmd BufWrite *.coffee :call DeleteTrailingWS()
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:dir == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
en
return ''
endfunction
" toggle between number and relativenumber
function! ToggleNumber()
if(&relativenumber == 1)
set norelativenumber
set number
else
set relativenumber
endif
endfunction
@zhanyuzhang
Copy link

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment