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