From cf56205e0bb0382595425f077bd272e08b1779f3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 29 Oct 2017 17:44:43 -0400 Subject: split out my settings into a plugin too --- vim/ftplugin/c.vim | 1 + vim/ftplugin/cpp.vim | 1 + vim/plugin/opinionated-defaults.vim | 154 ++++++++++++++++++++++++++++++++++++ vimrc | 132 ++++++------------------------- 4 files changed, 181 insertions(+), 107 deletions(-) create mode 100644 vim/ftplugin/c.vim create mode 100644 vim/plugin/opinionated-defaults.vim diff --git a/vim/ftplugin/c.vim b/vim/ftplugin/c.vim new file mode 100644 index 0000000..13c7d4a --- /dev/null +++ b/vim/ftplugin/c.vim @@ -0,0 +1 @@ +setlocal cinoptions+=:0,l1,g0,(0,W1s diff --git a/vim/ftplugin/cpp.vim b/vim/ftplugin/cpp.vim index 073956b..83d7802 100644 --- a/vim/ftplugin/cpp.vim +++ b/vim/ftplugin/cpp.vim @@ -1 +1,2 @@ let b:load_doxygen_syntax = 1 +setlocal cinoptions+=:0,l1,g0,(0,W1s diff --git a/vim/plugin/opinionated-defaults.vim b/vim/plugin/opinionated-defaults.vim new file mode 100644 index 0000000..54341fc --- /dev/null +++ b/vim/plugin/opinionated-defaults.vim @@ -0,0 +1,154 @@ +""" GENERAL """ +set nocompatible +syntax on +filetype indent plugin on +augroup opinionated_defaults + autocmd! +augroup END + + +""" PERSISTENCE """ + +" remember as many history items as possible (command, search, etc) +set history=10000 +" enable persistent undo (undo even after closing and reopening vim) +if has('persistent_undo') + let s:undocachedir = $HOME . '/.cache/vim/undo' + if !isdirectory(s:undocachedir) + call mkdir(s:undocachedir, 'p') + endif + exe "set undodir=" . s:undocachedir + set undofile +endif + + +""" BUFFERS """ + +" automatically write the buffer before :make, shell commands, etc +set autowrite +" ask to save modified buffers when quitting, instead of throwing an error +set confirm +" allow switching to other buffers when the current one is modified +set hidden +" these two restore the last known cursor position when a buffer is loaded +set nostartofline +autocmd opinionated_defaults BufReadPost * + \ if line("'\"") <= line('$') | + \ exe 'normal! g`"' | + \ endif + + +""" DISPLAY """ + +" show as much of a line as possible if it doesn't all fit on the screen +set display+=truncate +" more useful display of nonprinting characters (<07> instead of ^G) +set display+=uhex +" don't redraw in the middle of noninteractive commands (maps, macros, etc) +set lazyredraw +" always give a message for the number of lines delete/changed +set report=0 +" keep some additional context visible when scrolling +set scrolloff=5 +if has('cmdline_info') + " display the current partial command and size of the visual selection + set showcmd +endif +if has('conceal') + " enable syntax-specific hiding of text + set conceallevel=2 +endif +if has('linebreak') + " display a marker when a line was wrapped + set showbreak=> +endif + + +""" EDITING """ + +" automatically use an indent that matches the previous line +set autoindent +" allow backspacing over everything +set backspace=indent,eol,start +" remove leading comment characters intelligently when joining lines +set formatoptions+=j +" always join with a single space, even between sentences +set nojoinspaces +" try to always keep indentation lined up on shiftwidth boundaries +set shiftround +" keep softtabstop and shiftwidth in sync +set softtabstop=-1 + + +""" COMMAND MODE """ + +" make command mode completion work more like the shell: +" first, complete the longest common sequence, +" then show a list, +" then cycle through completing the full names in the list in order +set wildmode=longest,list,full +if exists('+wildignorecase') + " make command mode completion case insensitive + set wildignorecase +endif + + +""" SEARCH """ + +" make searches case-insensitive +set ignorecase +" unless they include a capital letter +set smartcase +if has('extra_search') + " highlight all matches when searching + set hlsearch +endif + + +""" TERMINAL STUFF """ + +" wait a much shorter amount of time for escape sequences +" (this makes much more responsive) +set ttimeoutlen=50 +" send text to the terminal in such a way that line wrapping is done at the +" terminal level, so copying and pasting wrapped lines works correctly +" (assuming you temporarily unset showbreak) +set ttyfast +" entirely disable error bells: +" make all bells visual bells +set visualbell +" and then disable visual bells +set t_vb= + + +""" COLORS """ + +" force vim to use 256 colors +" (it typically can't detect this while in screen/tmux since TERM=screen +" doesn't advertise it, even though ~everything does support it these days) +set t_Co=256 +" globally highlight diff conflict markers +match ErrorMsg '^\(<\||\|=\|>\)\{7\}\([^=].\+\)\?$' +" override some obnoxious default color choices +highlight Folded NONE ctermfg=darkgreen guifg=green +highlight Search NONE ctermfg=red guifg=red + + +""" MAPPINGS """ + +" keep the current selection when indenting +xnoremap < >gv +" make Y behave analogously to D instead of dd +nnoremap Y y$ +" make arrow keys move visually (since j/k already move linewise) +noremap gk +noremap gj +inoremap gk +inoremap gj +" use tab for completion +inoremap + \ strpart(getline('.'), 0, col('.') - 1) =~ '\(^\\|\s\+\)$' + \ ? "\" + \ : "\" +inoremap diff --git a/vimrc b/vimrc index 7f1ed9d..1b6e6d0 100644 --- a/vimrc +++ b/vimrc @@ -1,94 +1,17 @@ " options {{{ -" persistence {{{ -set history=10000 -if has("persistent_undo") - set undofile - set undodir=~/.cache/vim/undo -endif -" }}} -" buffers {{{ -set autoread -set autowrite -set confirm -set hidden -set nostartofline -" }}} -" display {{{ -set display+=lastline,uhex -set lazyredraw -set linebreak -set report=0 -set scrolloff=3 -set showbreak=> -set showcmd -if has('conceal') - set conceallevel=2 -endif -" }}} -" editing {{{ -set autoindent -set backspace=indent,eol,start -set cinoptions+=:0,l1,g0,(0,W1s -set expandtab -set formatoptions+=j -set nojoinspaces -set shiftround set shiftwidth=4 -set softtabstop=-1 -" }}} -" command mode {{{ -set wildignore+=*.o,.git/*,.svn/*,blib/* -set wildmenu -set wildmode=longest,list,full -if exists("+wildignorecase") - set wildignorecase -endif -" }}} -" search {{{ -set hlsearch -set ignorecase -set smartcase -" }}} -" terminal stuff {{{ -set ttimeoutlen=50 -set ttyfast -set t_vb= -set visualbell -" }}} -" }}} -" colors {{{ -" general {{{ -syntax on -set background=light -set t_Co=256 -" }}} -" recolorings {{{ -highlight Folded ctermfg=darkgreen ctermbg=black guifg=green guibg=black -highlight Search NONE ctermfg=red guifg=red -" }}} -" highlight diff conflict markers {{{ -match ErrorMsg '^\(<\||\|=\|>\)\{7\}\([^=].\+\)\?$' -" }}} +set expandtab " }}} " hooks {{{ -" general {{{ augroup vimrc autocmd! augroup END " }}} -" When editing a file, always jump to the last cursor position {{{ -autocmd vimrc BufReadPost * if line("'\"") <= line("$") | exe "normal! g`\"" | endif -" }}} -" }}} " bindings {{{ " general {{{ let g:mapleader = ';' let g:maplocalleader = ';' " }}} -" keep the current selection when indenting {{{ -xnoremap < >gv -" }}} " M to :make {{{ noremap M :makek " }}} @@ -96,20 +19,10 @@ noremap M :makek noremap &spell ? ":\setlocal nospell\" : ":\setlocal spell\" inoremap &spell ? "\:setlocal nospell\" : "\:setlocal spell\" " }}} -" arrow keys {{{ -noremap gk -noremap gj -inoremap gk -inoremap gj -" }}} " editing binary files {{{ nnoremap :%!xxd nnoremap :%!xxd -r " }}} -" tab for completion {{{ -inoremap strpart(getline('.'), 0, col('.')-1) =~ '^\s*$' ? "\" : "\" -inoremap -" }}} " easier tag traversal {{{ nnoremap nnoremap @@ -128,7 +41,6 @@ nmap \ nnoremap e c nnoremap E C nnoremap r -nnoremap Y y$ nnoremap , : xnoremap , : nnoremap ! :! @@ -141,9 +53,6 @@ nnoremap :bd " }}} " }}} " plugin configuration {{{ -" general {{{ -filetype indent plugin on -" }}} " ale {{{ let g:ale_lint_on_text_changed = 'normal' let g:ale_lint_on_insert_leave = 1 @@ -187,21 +96,30 @@ endif let g:neosnippet#snippets_directory = '~/.vim/snippets' let g:neosnippet#disable_runtime_snippets = { '_' : 1 } -let g:i_tab = maparg("", "i", 0, 1) -let g:i_stab = maparg("", "i", 0, 1) -let g:s_tab = maparg("", "s", 0, 1) -imap - \ neosnippet#expandable_or_jumpable() ? - \ "\(neosnippet_expand_or_jump)" : - \ g:i_tab["expr"] ? eval(g:i_tab["rhs"]) : g:i_tab["rhs"] -imap - \ neosnippet#expandable_or_jumpable() ? - \ "\(neosnippet_expand_or_jump)" : - \ g:i_stab["expr"] ? eval(g:i_stab["rhs"]) : g:i_stab["rhs"] -smap - \ neosnippet#expandable_or_jumpable() ? - \ "\(neosnippet_expand_or_jump)" : - \ g:s_tab["expr"] ? eval(g:s_tab["rhs"]) : g:s_tab["rhs"] +function! s:configure_neosnippet_tab_mappings() + let g:neosnippet_tab_override_i_tab = maparg("", "i", 0, 1) + let g:neosnippet_tab_override_i_stab = maparg("", "i", 0, 1) + let g:neosnippet_tab_override_s_tab = maparg("", "s", 0, 1) + imap + \ neosnippet#expandable_or_jumpable() ? + \ "\(neosnippet_expand_or_jump)" : + \ g:neosnippet_tab_override_i_tab["expr"] + \ ? eval(g:neosnippet_tab_override_i_tab["rhs"]) + \ : g:neosnippet_tab_override_i_tab["rhs"] + imap + \ neosnippet#expandable_or_jumpable() ? + \ "\(neosnippet_expand_or_jump)" : + \ g:neosnippet_tab_override_i_stab["expr"] + \ ? eval(g:neosnippet_tab_override_i_stab["rhs"]) + \ : g:neosnippet_tab_override_i_stab["rhs"] + smap + \ neosnippet#expandable_or_jumpable() ? + \ "\(neosnippet_expand_or_jump)" : + \ g:neosnippet_tab_override_s_tab["expr"] + \ ? eval(g:neosnippet_tab_override_s_tab["rhs"]) + \ : g:neosnippet_tab_override_s_tab["rhs"] +endfunction +autocmd vimrc VimEnter * call configure_neosnippet_tab_mappings() " }}} " rainbow {{{ let g:rainbow = 1 -- cgit v1.2.3-54-g00ecf