Skip to content

Instantly share code, notes, and snippets.

@zkbpkp
Created February 28, 2017 21:14
Show Gist options
  • Save zkbpkp/3846e9e7952ce1c1a5fc8b5aff591953 to your computer and use it in GitHub Desktop.
Save zkbpkp/3846e9e7952ce1c1a5fc8b5aff591953 to your computer and use it in GitHub Desktop.
My vimrc (for vim and neovim)
set nocompatible
set runtimepath+=~/.config/nvim/repos/github.com/Shougo/dein.vim
let s:bundle_dir = expand('~/.config/nvim')
let s:plugin_dir = s:bundle_dir . '/repos/github.com'
if dein#load_state(s:bundle_dir)
call dein#begin(s:bundle_dir)
" --- Dein ---
call dein#add(s:plugin_dir . '/Shougo/dein.vim')
" --- Appearance ---
call dein#add('chriskempson/base16-vim')
" --- Autocomplete & Snippets ---
if has('nvim')
call dein#add('Shougo/deoplete.nvim')
else
call dein#add('Shougo/neocomplete.vim')
endif
call dein#add('Shougo/neosnippet')
call dein#add('Shougo/neosnippet-snippets')
" --- Code style ---
call dein#add('editorconfig/editorconfig-vim')
" --- Build & Run ---
call dein#add('neomake/neomake')
" --- Debugging ---
call dein#add('critiqjo/lldb.nvim')
" --- Localization ---
call dein#add('powerman/vim-plugin-ruscmd')
" --- Navigation ---
call dein#add('scrooloose/nerdtree')
call dein#add('ctrlpvim/ctrlp.vim')
" --- Misc ---
call dein#add('kassio/neoterm')
call dein#add('LucHermitte/lh-vim-lib')
call dein#add('tpope/vim-commentary')
" --- Language-specific ---
" {{{
""" JavaScript/TypeScript
call dein#add('leafgarland/typescript-vim')
""" Rust
call dein#add('rust-lang/rust.vim')
""" TOML
call dein#add('cespare/vim-toml')
" }}}
call dein#end()
call dein#save_state()
endif
" === General ===
" {{{
" --- Local vimrc ---
autocmd BufEnter * silent! source local.vim
autocmd BufEnter * silent! source .local.vim
" --- General mappings ---
map ; :
let g:mapleader=" "
noremap j gj
noremap k gk
" --- Filetype plugins ---
filetype plugin on
filetype indent on
" --- Indentation ---
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
set smartindent
" --- Search ---
set hlsearch
set ignorecase
set smartcase
map <Leader>h :noh<CR>
" --- Splitting ---
set splitright
set splitbelow
" --- Line numbers ---
set relativenumber
autocmd InsertEnter * :set number norelativenumber
autocmd InsertLeave * :set nonumber relativenumber
" --- Line wrap ---
set wrap
set linebreak
" --- Misc ---
set ruler
set cursorline
" }}}
" === Appearance ===
" {{{
set background=dark
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
source ~/.vimrc_background
endif
syntax enable
" }}}
" === Autocomplete & Snippets ===
" {{{
let g:deoplete#enable_at_startup = 1
let g:neocomplete#enable_at_startup = 1
imap <C-Space> <Plug>(neosnippet_expand_or_jump)
smap <C-Space> <Plug>(neosnippet_expand_or_jump)
xmap <C-Space> <Plug>(neosnippet_expand_target)
" }}}
" === Build & Run ===
" {{{
function! Build() abort
if exists('g:buildcmd')
exec 'Texec ' . g:buildcmd
elseif &ft =~# '^\%(rust\)$'
Texec cargo build
elseif &ft =~# '^\%(javascript\|typescript\)$'
Texec npm run build
else
Texec make
endif
endfunction
function! Run() abort
if exists('g:runcmd')
exec 'Texec ' . g:runcmd
elseif &ft =~# '^\%(rust\)$'
Texec cargo run
endif
endfunction
function! Test() abort
if exists('g:testcmd')
exec 'Texec ' . g:testcmd
elseif &ft =~# '^\%(rust\)$'
Texec cargo test
elseif &ft =~# '^\%(javascript\|typescript\)$'
Texec npm run test
else
Texec make test
endif
endfunction
function! EmitAsm() abort
if &ft =~# '^\%(rust\)$'
RustEmitAsm
endif
endfunction
map <F5> :call Build()<CR>
imap <F5> <C-o>:call Build()<CR>
map <F6> :call Run()<CR>
imap <F6> <C-o>:call Run()<CR>
map <F7> :call Test()<CR>
imap <F7> <C-o>:call Test()<CR>
map <F8> :call EmitAsm()<CR>
imap <F8> <C-o>:call EmitAsm()<CR>
" F9-F12 are reserved for debug hotkeys
" }}}
" === Code style ===
" {{{
" --- Auto formatting ---
" {{{
map <Leader>f :call AutoFormat()<cr>
autocmd! BufWritePre * call AutoFormat()
""" ClangFormat
let g:clang_format_fallback_style = 'LLVM'
""" RustFmt
let g:rustfmt_fail_silently=1
function! AutoFormat() abort
if &ft =~# '^\%(c\|cpp\|objc\|java\|javascript\|typescript\|proto\)$'
ClangFormat
elseif &ft =~# '^\%(rust\)$'
RustFmt
endif
endfunction
" }}}
" --- Linting ---
" {{{
function! Check() abort
if exists('g:checkmaker')
exec 'Neomake! ' . g:checkmaker
elseif exists('g:checkcmd')
exec 'Texec ' . g:checkcmd
else
Neomake
endif
endfunction
let g:neomake_error_sign = { 'text': '*', 'texthl': 'NeomakeErrorSign' }
let g:neomake_warning_sign = { 'text': '*', 'texthl': 'NeomakeWarningSign' }
let g:neomake_message_sign = { 'text': '*', 'texthl': 'NeomakeMessageSign' }
let g:neomake_info_sign = { 'text': '*', 'texthl': 'NeomakeInfoSign' }
autocmd! BufWritePost * call Check()
" }}}
" }}}
" === Localization ===
" {{{
set enc=utf-8
" }}}
" === Navigation ===
" {{{
map <F3> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" }}}
" === Terminal ===
" {{{
if has('nvim')
command! -nargs=+ Texec :T <args>
else
command! -nargs=+ Texec :! <args>
endif
if has('nvim')
command! -nargs=+ Git :Texec git <args>
command! -nargs=* Make :Texec make <args>
tnoremap <Esc> <C-\><C-n>
tnoremap <C-w>h <C-\><C-n><C-w>h
tnoremap <C-w>j <C-\><C-n><C-w>j
tnoremap <C-w>k <C-\><C-n><C-w>k
tnoremap <C-w>l <C-\><C-n><C-w>l
nnoremap <silent> <Leader>tq :call neoterm#close()<cr>
nnoremap <silent> <Leader>tc :call neoterm#clear()<cr>
nnoremap <silent> <Leader>tk :call neoterm#kill()<cr>
endif
" }}}
" === Language-specific ===
" {{{
" --- C/C++ ---
command! -nargs=0 ClangFormat :pyf /usr/share/clang/clang-format.py
let g:neomake_c_enabled_makers = ['clang']
" --- Rust ---
command! -nargs=+ Cargo :Texec cargo <args>
let g:neomake_rust_enabled_makers = ['rustc']
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment