]>
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 | """ vim-only defaults | |
52 | if !has('nvim') | |
53 | " neovim defaults are already set | |
54 | source $VIMRUNTIME/defaults.vim | |
55 | ||
56 | " disable jumping to last edit, we use vim-lastplace instead | |
57 | autocmd! vimStartup | |
58 | ||
59 | " packages | |
60 | packadd! matchit | |
61 | packadd! editorconfig " this is now built to [n]vim in but optional | |
62 | packadd! vim-commentary " nvim has built in commenting now | |
63 | ||
64 | " options | |
65 | set hlsearch | |
66 | autocmd BufRead * set autoindent | |
67 | endif | |
68 | ||
69 | """ styling | |
70 | " nice default theme | |
71 | colorscheme murphy | |
72 | ||
73 | " always use color column with less intrusive colors | |
74 | autocmd VimEnter,WinNew * set colorcolumn=80 | |
75 | " always use cursor line for better visibility | |
76 | autocmd VimEnter,WinNew * set cursorline | |
77 | ||
78 | " unique highlighting for leading spaces and in-line spaces | |
79 | " NOTE: this leaves tabs and other special whitespace untouched intentionally | |
80 | autocmd VimEnter,ColorScheme * highlight SpaceInner ctermfg=Grey guifg=#686868 | |
81 | autocmd VimEnter,ColorScheme * highlight link SpaceOuter NonText | |
82 | autocmd VimEnter,WinNew * match SpaceInner / / | |
83 | autocmd VimEnter,WinNew * 2match SpaceOuter /\(^ \+\)\|\( \+$\)/ | |
84 | ||
85 | " always show statusline | |
86 | set laststatus=2 | |
87 | ||
88 | " truncate > lastline; lastline is nvim default, sensible.vim may also set it | |
89 | set display=truncate | |
90 | ||
91 | " more context while scrolling | |
92 | set scrolloff=5 | |
93 | set sidescrolloff=8 | |
94 | ||
95 | " show number column on all buffers | |
96 | autocmd VimEnter,WinNew * set number | |
97 | " use relative numbers in normal modes when focused, but not if number is off | |
98 | function! s:SetRelativeNumber(enable) | |
99 | if !getwinvar(winnr(), '&number') | |
100 | return | |
101 | endif | |
102 | if a:enable | |
103 | set relativenumber | |
104 | else | |
105 | set norelativenumber | |
106 | endif | |
107 | endfunction | |
108 | autocmd InsertEnter,FocusLost,WinLeave * call s:SetRelativeNumber(0) | |
109 | autocmd VimEnter,WinNew, | |
110 | \InsertLeave,FocusGained,WinEnter * call s:SetRelativeNumber(1) | |
111 | ||
112 | " always show custom listchars | |
113 | autocmd VimEnter,WinNew * set list | |
114 | set listchars=tab:├─,extends:»,precedes:«,space:·,trail:∙,nbsp:■ | |
115 | ||
116 | """ editor | |
117 | " always save undo file for all file buffers | |
118 | autocmd BufRead * set undofile | |
119 | ||
120 | " explicitly use modeline, even on systems where it's disabled by system vimrc | |
121 | autocmd BufRead * set modeline | |
122 | " should be default disabled but just in case | |
123 | set nomodelineexpr | |
124 | ||
125 | "" indent | |
126 | " always use shiftwidth instead of tabsize | |
127 | set smarttab | |
128 | " filetype preferences | |
129 | autocmd FileType python set softtabstop=4 shiftwidth=4 expandtab | |
130 | autocmd FileType markdown set softtabstop=4 shiftwidth=4 expandtab | |
131 | autocmd FileType javascript set softtabstop=2 shiftwidth=2 expandtab | |
132 | autocmd FileType json set softtabstop=2 shiftwidth=2 expandtab | |
133 | autocmd FileType html set softtabstop=2 shiftwidth=2 expandtab | |
134 | let g:EditorConfig_enable_for_new_buf = 1 | |
135 | ||
136 | "" syntax | |
137 | autocmd FileType todo set colorcolumn=0 | |
138 | ||
139 | "" mappings | |
140 | " use more accessible escapes, as C-n and C-o are shadowed by some terminals | |
141 | if has('nvim') | |
142 | tnoremap <C-\>n <C-\><C-N> | |
143 | tnoremap <C-\>o <C-\><C-O> | |
144 | endif | |
145 | ||
146 | " move windows any time | |
147 | if has('nvim') | |
148 | " terminal | |
149 | tnoremap <A-h> <C-\><C-N><C-w>h | |
150 | tnoremap <A-j> <C-\><C-N><C-w>j | |
151 | tnoremap <A-k> <C-\><C-N><C-w>k | |
152 | tnoremap <A-l> <C-\><C-N><C-w>l | |
153 | endif | |
154 | " insert | |
155 | inoremap <A-h> <C-\><C-N><C-w>h | |
156 | inoremap <A-j> <C-\><C-N><C-w>j | |
157 | inoremap <A-k> <C-\><C-N><C-w>k | |
158 | inoremap <A-l> <C-\><C-N><C-w>l | |
159 | " normal | |
160 | nnoremap <A-h> <C-w>h | |
161 | nnoremap <A-j> <C-w>j | |
162 | nnoremap <A-k> <C-w>k | |
163 | nnoremap <A-l> <C-w>l | |
164 | ||
165 | "" CTRL-L to clear highlighting and also update diff | |
166 | " NOTE: sensible.vim and nvim already do this, so copy sensible.vim | |
167 | " functionality if it hasn't been set or we aren't nvim. taken from | |
168 | " sensible.vim by Tim Pope, under Vim license; see :help license | |
169 | " https://github.com/tpope/vim-sensible/blob/0ce2d843d6f588bb0c8c7eec6449171615dc56d9/plugin/sensible.vim#L57 | |
170 | if !has('nvim') && maparg('<C-L>', 'n') ==# '' | |
171 | nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L> | |
172 | endif |