summaryrefslogtreecommitdiffstats
path: root/vim/plugin/opinionated-defaults.vim
blob: db07888a09a4b5188f472d5c83d0abb466a7aaba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
" use a separate swapfile directory
let s:swapfiledir = $HOME . '/.cache/vim/swap'
if !isdirectory(s:swapfiledir)
    call mkdir(s:swapfiledir, 'p')
endif
exe "set directory=" . s:swapfiledir


""" 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 <Esc> 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
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  <up>   gk
noremap  <down> gj
inoremap <up>   <C-o>gk
inoremap <down> <C-o>gj