]>
Commit | Line | Data |
---|---|---|
1 | """ paths | |
2 | "" config dir in xdg config | |
3 | let x = ($XDG_CONFIG_HOME??($HOME.'/.config')).'/vim' | |
4 | execute 'set runtimepath='.x.','.&runtimepath.','.x.'/after' | |
5 | execute 'set packpath='.x.','.&packpath.','.x.'/after' | |
6 | ||
7 | "" state files in xdg state | |
8 | let x = ($XDG_STATE_HOME??($HOME.'/.local/state')).'/vim' | |
9 | if !isdirectory(x) | |
10 | call mkdir(x, 'p', 0700) | |
11 | endif | |
12 | ||
13 | " backup | |
14 | " NOTE: keep backup files in vim state dir for both vim and neovim | |
15 | let y = x.'/backup' | |
16 | if !isdirectory(y) | |
17 | call mkdir(y, 'p', 0700) | |
18 | endif | |
19 | execute 'set backupdir='.y.'//' | |
20 | set backup backupcopy=yes | |
21 | ||
22 | " NOTE: neovim uses ShaDa (SHAred DAta) format for viminfo and swap, and uses a | |
23 | " different version of undo file, so these types of files when created by | |
24 | " vim cannot be used with neovim, and the 'viminfofile', 'directory', and | |
25 | " 'undodir' directories cannot be shared. | |
26 | " NOTE: neovim has a nice default for these directories and files so | |
27 | " customizing them is not necessary for it. | |
28 | if !has('nvim') | |
29 | " viminfo | |
30 | " NOTE: 'viminfofile' is a deprecated alias for 'shada' in neovim | |
31 | execute 'set viminfofile='.x.'/.viminfo' | |
32 | ||
33 | " swap | |
34 | let y = x.'/swap' | |
35 | if !isdirectory(y) | |
36 | call mkdir(y, 'p', 0700) | |
37 | endif | |
38 | execute 'set directory='.y.'//' | |
39 | ||
40 | " undo | |
41 | let y = x.'/undo' | |
42 | if !isdirectory(y) | |
43 | call mkdir(y, 'p', 0700) | |
44 | endif | |
45 | execute 'set undodir='.y.'//' | |
46 | endif | |
47 | ||
48 | unlet x | |
49 | unlet y | |
50 | ||
51 | ||
52 | """ vim-only defaults | |
53 | if !has('nvim') | |
54 | " neovim defaults are already set | |
55 | source $VIMRUNTIME/defaults.vim | |
56 | ||
57 | " disable jumping to last edit, we use vim-lastplace instead | |
58 | autocmd! vimStartup | |
59 | ||
60 | " packages | |
61 | packadd! matchit " included with [n]vim but disabled by default | |
62 | packadd! editorconfig " now included with [n]vim but disabled by default | |
63 | packadd! vim-commentary " nvim has this built in now, vim still needs it | |
64 | ||
65 | " options | |
66 | set hlsearch | |
67 | autocmd BufRead * set autoindent | |
68 | endif | |
69 | ||
70 | ||
71 | """ package config | |
72 | "" suda | |
73 | " https://github.com/lambdalisue/vim-suda/issues/32#issuecomment-829608925 | |
74 | if ! &diff | |
75 | let g:suda_smart_edit = 1 | |
76 | endif | |
77 | " re-enable backup, swap, undo for suda buffers that we can read | |
78 | " https://github.com/lambdalisue/vim-suda/issues/25 | |
79 | function s:SudaSettingsSave() | |
80 | let l:f = expand('<afile>') | |
81 | if stridx(l:f, 'suda://') == 0 | |
82 | let g:sev_suda_file = expand('<afile>') | |
83 | let g:sev_suda_backup = &backup | |
84 | let g:sev_suda_swapfile = &swapfile | |
85 | let g:sev_suda_undofile = &undofile | |
86 | endif | |
87 | endfunction | |
88 | function s:SudaSettingsRestore() | |
89 | if exists('g:sev_suda_file') && filereadable(g:sev_suda_file) | |
90 | if exists('g:sev_suda_backup') && g:sev_suda_backup | |
91 | " XXX: suda.vim uses setlocal for this, even though it's global... | |
92 | setlocal backup | |
93 | endif | |
94 | if exists('g:sev_suda_swapfile') && g:sev_suda_swapfile | |
95 | setlocal swapfile | |
96 | endif | |
97 | if exists('g:sev_suda_undofile') && g:sev_suda_undofile | |
98 | setlocal undofile | |
99 | endif | |
100 | endif | |
101 | endfunction | |
102 | autocmd BufReadPre * call s:SudaSettingsSave() | |
103 | autocmd BufReadPost suda://* call s:SudaSettingsRestore() | |
104 | ||
105 | ||
106 | """ styling | |
107 | " nice default theme | |
108 | colorscheme murphy | |
109 | ||
110 | " always use color column with less intrusive colors | |
111 | autocmd VimEnter,WinNew * set colorcolumn=80 | |
112 | " always use cursor line for better visibility | |
113 | autocmd VimEnter,WinNew * set cursorline | |
114 | ||
115 | " unique highlighting for leading spaces and in-line spaces | |
116 | " NOTE: this leaves tabs and other special whitespace untouched intentionally | |
117 | autocmd VimEnter,ColorScheme * highlight SpaceInner ctermfg=Grey guifg=#686868 | |
118 | autocmd VimEnter,ColorScheme * highlight link SpaceOuter NonText | |
119 | autocmd VimEnter,WinNew * match SpaceInner / / | |
120 | autocmd VimEnter,WinNew * 2match SpaceOuter /\(^ \+\)\|\( \+$\)/ | |
121 | ||
122 | " always show statusline | |
123 | set laststatus=2 | |
124 | ||
125 | " truncate > lastline; lastline is nvim default, sensible.vim may also set it | |
126 | set display=truncate | |
127 | ||
128 | " more context while scrolling | |
129 | set scrolloff=5 | |
130 | set sidescrolloff=8 | |
131 | ||
132 | " show number column on all buffers | |
133 | autocmd VimEnter,WinNew * set number | |
134 | " use relative numbers in normal modes when focused, but not if number is off | |
135 | function! s:SetRelativeNumber(enable) | |
136 | if !getwinvar(winnr(), '&number') | |
137 | return | |
138 | endif | |
139 | if a:enable | |
140 | set relativenumber | |
141 | else | |
142 | set norelativenumber | |
143 | endif | |
144 | endfunction | |
145 | autocmd InsertEnter,FocusLost,WinLeave * call s:SetRelativeNumber(0) | |
146 | autocmd VimEnter,WinNew, | |
147 | \InsertLeave,FocusGained,WinEnter * call s:SetRelativeNumber(1) | |
148 | ||
149 | " always show custom listchars | |
150 | autocmd VimEnter,WinNew * set list | |
151 | set listchars=tab:├─,extends:»,precedes:«,space:·,trail:∙,nbsp:■ | |
152 | ||
153 | ||
154 | """ editor | |
155 | " always save undo file for all file buffers | |
156 | autocmd BufReadPre * setlocal undofile | |
157 | ||
158 | ||
159 | " explicitly use modeline, even on systems where it's disabled by system vimrc | |
160 | autocmd BufRead * set modeline | |
161 | " should be default disabled but just in case | |
162 | set nomodelineexpr | |
163 | ||
164 | "" indent | |
165 | " always use shiftwidth instead of tabsize | |
166 | set smarttab | |
167 | " filetype preferences | |
168 | autocmd FileType python set softtabstop=4 shiftwidth=4 expandtab | |
169 | autocmd FileType markdown set softtabstop=4 shiftwidth=4 expandtab | |
170 | autocmd FileType javascript set softtabstop=2 shiftwidth=2 expandtab | |
171 | autocmd FileType json set softtabstop=2 shiftwidth=2 expandtab | |
172 | autocmd FileType html set softtabstop=2 shiftwidth=2 expandtab | |
173 | let g:EditorConfig_enable_for_new_buf = 1 | |
174 | ||
175 | "" syntax | |
176 | autocmd Syntax php syn clear phpHereDoc phpNowDoc | |
177 | ||
178 | "" mappings | |
179 | " use more accessible escapes, as C-n and C-o are shadowed by some terminals | |
180 | if has('nvim') | |
181 | tnoremap <C-\>n <C-\><C-N> | |
182 | tnoremap <C-\>o <C-\><C-O> | |
183 | endif | |
184 | ||
185 | " move windows any time | |
186 | if has('nvim') | |
187 | " terminal | |
188 | tnoremap <A-h> <C-\><C-N><C-w>h | |
189 | tnoremap <A-j> <C-\><C-N><C-w>j | |
190 | tnoremap <A-k> <C-\><C-N><C-w>k | |
191 | tnoremap <A-l> <C-\><C-N><C-w>l | |
192 | endif | |
193 | " insert | |
194 | inoremap <A-h> <C-\><C-N><C-w>h | |
195 | inoremap <A-j> <C-\><C-N><C-w>j | |
196 | inoremap <A-k> <C-\><C-N><C-w>k | |
197 | inoremap <A-l> <C-\><C-N><C-w>l | |
198 | " normal | |
199 | nnoremap <A-h> <C-w>h | |
200 | nnoremap <A-j> <C-w>j | |
201 | nnoremap <A-k> <C-w>k | |
202 | nnoremap <A-l> <C-w>l | |
203 | ||
204 | "" CTRL-L to clear highlighting and also update diff | |
205 | " NOTE: sensible.vim and nvim already do this, so copy sensible.vim | |
206 | " functionality if it hasn't been set or we aren't nvim. taken from | |
207 | " sensible.vim by Tim Pope, under Vim license; see :help license | |
208 | " https://github.com/tpope/vim-sensible/blob/0ce2d843d6f588bb0c8c7eec6449171615dc56d9/plugin/sensible.vim#L57 | |
209 | if !has('nvim') && maparg('<C-L>', 'n') ==# '' | |
210 | nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L> | |
211 | endif |