Last active
December 31, 2022 22:07
-
-
Save akaron/1a989f0b79915e29c3d38774a63204a0 to your computer and use it in GitHub Desktop.
vimrc (using vimplug)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible " be iMproved, required | |
" vim-plug, see https://github.com/junegunn/vim-plug | |
call plug#begin('~/.vim/plugged') | |
" plugins | |
Plug 'tpope/vim-sensible' | |
Plug 'tpope/vim-commentary' | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-repeat' | |
Plug 'tpope/vim-fugitive' | |
Plug 'skywind3000/asyncrun.vim' | |
Plug 'nanotech/jellybeans.vim' | |
Plug 'majutsushi/tagbar' | |
Plug 'w0rp/ale' | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/goyo.vim' " write mode | |
" Plug 'junegunn/limelight.vim' " spotlight on cursorline | |
Plug 'mileszs/ack.vim' | |
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' | |
Plug 'sheerun/vim-polyglot' | |
Plug 'tmhedberg/SimpylFold' " for python | |
Plug 'matze/vim-tex-fold' | |
Plug 'akaron/vim-markdown-fold' | |
Plug '~/.vim/my_plug/vim-tex-sync-skim' | |
" Plug 'Yggdroot/indentLine' | |
" plugins considering alternatives or just to keep in mind | |
Plug 'vim-airline/vim-airline' " alt.: lightline; manually build statusline (see below) | |
" Plug 'junegunn/fzf.vim' " the :FZF is enough | |
" Plug 'tpope/vim-jdaddy' " for json | |
" Plug 'tpope/vim-unimpaired' " define some paired key-bindings | |
" load plugin for specific filetypes. It does not prevent plugins from activing | |
" while open other filetypes in another buffers | |
Plug 'vim-scripts/restore_view.vim', { 'for': ['python', 'tex', 'html', 'htmldjango'] } | |
" end of vimplug settings, below are other vimrc settings | |
call plug#end() | |
" | |
" ==== Basic settings ==== | |
" | |
" some settings are in vim-sensible plugin | |
syntax on | |
set showcmd " Show (partial) command in status line. | |
set number " or 'relativenumber' | |
set cursorline | |
set hlsearch | |
set showmode | |
set wildmenu | |
set wildchar=<TAB> " start wild expansion in the command line using <TAB> | |
set wildignore=*.o,*.class,*.pyc | |
set wildignore+=*.so,*.swp,*.zip " MacOSX/Linux | |
set nobackup " no *~ backup files | |
set copyindent " copy the previous indentation on autoindenting | |
set smartcase " ignore case if search pattern is all lowercase,case-sensitive otherwise | |
set noerrorbells | |
"set textwidth=90 | |
set nomodeline " in rare case it cause problem. Turn it off since and I never use it | |
" set clipboard=unnamed " use system clipboard from unnamed register | |
" Note: instead of 'set clipboard=unnamed', one can access system clipboard via register | |
" '"*' (without ''). For example, '"*yy' to copy current line into clipboard or '"*p' to | |
" paste from clipboard. | |
" useful when open multiple buffers | |
set hidden "avoid 'No write since last change' while :bn or :bp | |
set confirm "avoid close un-saved (hidden) buffer | |
" TAB settings | |
set expandtab "replace <TAB> with spaces | |
set softtabstop=4 | |
set shiftwidth=4 | |
au FileType Makefile set noexpandtab | |
au FileType snippet set noexpandtab | |
" jump to the last position when reopening a file | |
augroup reopen | |
autocmd! | |
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif | |
augroup END | |
" | |
" ==== filetype specific settings ==== | |
" | |
" add ':' to keyword for auto-completion (so that I can find the word like | |
" 'Smith:2006dh' in bibtex file and auto-complete it in latex file) | |
augroup tex | |
autocmd! | |
autocmd FileType tex,bib setlocal iskeyword+=: | |
augroup END | |
" vim may recognize tex file as 'plaintex' flavor instead of 'latex', this cause | |
" problems in packages which only work on 'latex'. (options: plain/context/latex) | |
let g:tex_flavor='latex' | |
" | |
" ==== Theme/color/fonts ==== | |
" theme-variables has to be configured before using the colorscheme | |
" | |
let g:jellybeans_use_term_background_color=1 | |
colors jellybeans | |
if has('gui_running') | |
set vb " visual bell | |
"set linespace=1 " looks better for some fonts | |
set guifont=Dejavu\ Sans\ Mono\ for\ Powerline:h18 | |
" remove scrollbars on the right and on the left | |
set guioptions-=R | |
set guioptions-=L | |
endif | |
" ex: visualize the 80th column | |
"if (exists('+colorcolumn')) | |
" set colorcolumn=80 | |
" highlight ColorColumn ctermbg=7 | |
"endif | |
" GNU screen | |
if match($TERM, "screen")!=-1 | |
set term=xterm-256color | |
endif | |
" statusline | |
" ========== | |
" vim-airline or not? | |
" airline is not bad if turn off almost all extensions except tabline | |
" For status line, see: | |
" https://gist.github.com/akaron/1a989f0b79915e29c3d38774a63204a0/016c44eb348a43e5bd4eda638589e121222011ff#file-vimrc-L41 (also L146-183) | |
" https://github.com/sodiumjoe/dotfiles/blob/master/vimrc | |
" | |
" ==== key bindings ==== | |
" | |
let mapleader = "\<Space>" | |
inoremap jk <Esc> | |
nnoremap <leader>bb :ls<CR>:b | |
nnoremap <leader>bn :bnext<CR> | |
nnoremap <leader>bp :bprev<CR> | |
nnoremap <leader>bd :bdelete<CR> | |
nnoremap <leader>g :Goyo<CR> | |
nnoremap <leader>T :TagbarToggle<CR> | |
nnoremap <c-p> :FZF<cr> | |
" from vim-tex-sync-skim | |
nnoremap <leader>v :call SynctexShow()<CR> | |
" toggle quickfix window the `right' way (better than :copen), see | |
" https://github.com/skywind3000/asyncrun.vim/wiki/Quickfix-Best-Practice | |
nnoremap <leader>q :call asyncrun#quickfix_toggle(8)<CR> | |
" For a single latex file, one may use the following: | |
" nnoremap <leader>l :!latexmk -pdf %<CR> | |
" nnoremap <leader>v :silent !/Applications/Skim.app/Contents/SharedSupport/displayline <C-r>=line('.')<CR> %<.pdf %<CR><C-L> | |
" make these repeatable (need vim-repeat plugin) | |
silent! call repeat#set("\<Plug>(ale_previous_wraptab)", v:count) | |
silent! call repeat#set("\<Plug>(ale_next_wrap)", v:count) | |
" | |
" ==== compile and run ==== | |
" | |
" noremap <F5> :w<CR>:AsyncRun make<CR> | |
" the following are inspired by https://www.zhihu.com/question/20271508#answer-47185463 | |
" also see https://zhuanlan.zhihu.com/p/30022074 | |
noremap <F5> :call CompileRunGcc()<CR> | |
func! CompileRunGcc() | |
exec "w" | |
if &filetype == 'c' | |
exec "!g++ % -o %<" | |
exec "!time ./%<" | |
elseif &filetype == 'cpp' | |
exec "!g++ % -o %<" | |
exec "!time ./%<" | |
elseif &filetype == 'sh' | |
exec "!time bash %" | |
elseif &filetype == 'python' | |
exec "AsyncRun python %" | |
elseif &filetype == 'html' | |
exec "!firefox % &" | |
elseif &filetype == 'markdown' | |
exec "!pandoc -t html % -o %.html &" | |
exec "!open %.html &" | |
elseif &filetype == 'tex' | |
" use AsyncRun + Makefile to typeset | |
exec "AsyncRun make" | |
endif | |
endfunc | |
" | |
" ==== Plugins specific settings ==== | |
" | |
" Tell ack.vim to use ag (the Silver Searcher) instead | |
let g:ackprg = 'ag --vimgrep' | |
" indentline | |
" let g:indentLine_enabled = 0 "use :IndentLinesToggle to toggle | |
" I use this plugin in HTML files. While foldmethod=Manual (vim default), | |
" under normal mode one can press zfat to 'create fold [in] a tag' (for | |
" example, a paired <div>...</div> in HTML). | |
" limelight | |
" let g:limelight_paragraph_span = 1 | |
" let g:limelight_default_coefficient = 0.7 | |
" AsyncRun | |
augroup vimrc | |
autocmd! | |
autocmd User AsyncRunStart call asyncrun#quickfix_toggle(8, 1) | |
" dont know why this cannot work | |
"autocmd FileType tex autocmd User AsyncRunStop echom 'Press <leader>v to view' | |
"autocmd FileType tex autocmd User AsyncRunStop call SynctexShow() "this steal the focus | |
augroup END | |
" vim-tex-fold | |
let g:tex_fold_additional_envs = ['sidewaystable', 'frontmatter', 'comment'] | |
" let g:tex_fold_enabled=1 | |
" restore_view | |
" use it for folded files, personally I prefer to remember the fold status in | |
" tex, python, markdown only | |
set viewoptions=cursor,folds,slash,unix | |
let g:skipview_files = ['*\.vim', '*rc', '*\.txt', '*\.bib', '*COMMIT_EDITMSG', '.gitignore', '\*.f95', '\*.c', '\*.h', 'Makefile'] | |
" ale | |
let g:ale_lint_on_text_changed = 'never' | |
let g:ale_lint_on_save = 1 | |
let g:ale_tex_chktex_options = '-n24 -n3' | |
" "use chktex args to ignore warnings, see http://www.nongnu.org/chktex/ChkTeX.pdf | |
let g:ale_python_flake8_options = ' --ignore=E501,C0103,E225,E226,E231' | |
let g:ale_linters = { | |
\ 'python': ['flake8'], | |
\} | |
" vim-airline | |
let g:airline_extensions = ['tabline'] " no need 'tagbar', 'branch', 'wordcount', ... | |
let g:airline_powerline_fonts = 0 | |
" let g:airline#extensions#tagbar#enabled = 0 " slow | |
" airline + AsyncRun | |
let g:airline_section_error = airline#section#create_right(['%{g:asyncrun_status}']) | |
" uncomment the following lines in case there is no airline installed | |
" augroup QuickfixStatus | |
" au! BufWinEnter quickfix setlocal | |
" \ statusline=%t\ [%{g:asyncrun_status}]\ %{exists('w:quickfix_title')?\ '\ '.w:quickfix_title\ :\ ''}\ %=%-15(%l,%c%V%)\ %P | |
" augroup END | |
" Tagbar | |
" use Exuberant ctags 5.5 or higher (not the one in OSX 10.9) | |
let g:tagbar_ctags_bin = '/opt/local/bin/ctags' | |
let g:tagbar_compact = 1 | |
let g:tagbar_width = 32 | |
" fix for Makefile: kind 't' is not defined but is returned by Exuberant Ctags 5.8 | |
let g:tagbar_type_make = { | |
\ 'kinds' : [ | |
\ 'm:macros', | |
\ 't:typedef', | |
\ ], | |
\ } | |
" add tex support (same as the example in :help tagbar) | |
" 1. add/update ~/.ctags | |
" 2. use the right file type. ".tex" can be "tex" or "plaintex", use :set filetype | |
" to check, see also | |
" https://stackoverflow.com/questions/26145505/using-vims-tagbar-plugin-for-latex-files | |
let g:tagbar_type_tex = { | |
\ 'ctagstype' : 'latex', | |
\ 'kinds' : [ | |
\ 's:sections', | |
\ 'g:graphics:0:0', | |
\ 'l:labels', | |
\ 'r:refs:1:0', | |
\ 'p:pagerefs:1:0' | |
\ ], | |
\ 'sort' : 0, | |
\ } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment