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'
7 "" state files in xdg state
8 let x = ($XDG_STATE_HOME??($HOME.'/.local/state')).'/vim'
10 call mkdir(x, 'p', 0700)
14 " NOTE: keep backup files in vim state dir for both vim and neovim
17 call mkdir(y, 'p', 0700)
19 execute 'set backupdir='.y.'//'
20 set backup backupcopy=yes
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.
30 " NOTE: 'viminfofile' is a deprecated alias for 'shada' in neovim
31 execute 'set viminfofile='.x.'/.viminfo'
36 call mkdir(y, 'p', 0700)
38 execute 'set directory='.y.'//'
43 call mkdir(y, 'p', 0700)
45 execute 'set undodir='.y.'//'
54 " neovim defaults are already set
55 source $VIMRUNTIME/defaults.vim
57 " disable jumping to last edit, we use vim-lastplace instead
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
67 autocmd BufRead * set autoindent
75 " always use color column with less intrusive colors
76 autocmd VimEnter,WinNew * set colorcolumn=80
77 " always use cursor line for better visibility
78 autocmd VimEnter,WinNew * set cursorline
80 " unique highlighting for leading spaces and in-line spaces
81 " NOTE: this leaves tabs and other special whitespace untouched intentionally
82 autocmd VimEnter,ColorScheme * highlight SpaceInner ctermfg=Grey guifg=#686868
83 autocmd VimEnter,ColorScheme * highlight link SpaceOuter NonText
84 autocmd VimEnter,WinNew * match SpaceInner / /
85 autocmd VimEnter,WinNew * 2match SpaceOuter /\(^ \+\)\|\( \+$\)/
87 " always show statusline
90 " truncate > lastline; lastline is nvim default, sensible.vim may also set it
93 " more context while scrolling
97 " show number column on all buffers
98 autocmd VimEnter,WinNew * set number
99 " use relative numbers in normal modes when focused, but not if number is off
100 function! s:SetRelativeNumber(enable)
101 if !getwinvar(winnr(), '&number')
110 autocmd InsertEnter,FocusLost,WinLeave * call s:SetRelativeNumber(0)
111 autocmd VimEnter,WinNew,
112 \InsertLeave,FocusGained,WinEnter * call s:SetRelativeNumber(1)
114 " always show custom listchars
115 autocmd VimEnter,WinNew * set list
116 set listchars=tab:├─,extends:»,precedes:«,space:·,trail:∙,nbsp:■
120 " always save undo file for all file buffers
121 autocmd BufReadPre * setlocal undofile
123 " explicitly use modeline, even on systems where it's disabled by system vimrc
124 autocmd BufRead * set modeline
125 " should be default disabled but just in case
129 " always use shiftwidth instead of tabsize
131 " filetype preferences
132 autocmd FileType python set softtabstop=4 shiftwidth=4 expandtab
133 autocmd FileType markdown set softtabstop=4 shiftwidth=4 expandtab
134 autocmd FileType javascript set softtabstop=2 shiftwidth=2 expandtab
135 autocmd FileType json set softtabstop=2 shiftwidth=2 expandtab
136 autocmd FileType html set softtabstop=2 shiftwidth=2 expandtab
137 let g:EditorConfig_enable_for_new_buf = 1
140 autocmd Syntax php syn clear phpHereDoc phpNowDoc
143 " use more accessible escapes, as C-n and C-o are shadowed by some terminals
145 tnoremap <C-\>n <C-\><C-N>
146 tnoremap <C-\>o <C-\><C-O>
149 " move windows any time
152 tnoremap <A-h> <C-\><C-N><C-w>h
153 tnoremap <A-j> <C-\><C-N><C-w>j
154 tnoremap <A-k> <C-\><C-N><C-w>k
155 tnoremap <A-l> <C-\><C-N><C-w>l
158 inoremap <A-h> <C-\><C-N><C-w>h
159 inoremap <A-j> <C-\><C-N><C-w>j
160 inoremap <A-k> <C-\><C-N><C-w>k
161 inoremap <A-l> <C-\><C-N><C-w>l
163 nnoremap <A-h> <C-w>h
164 nnoremap <A-j> <C-w>j
165 nnoremap <A-k> <C-w>k
166 nnoremap <A-l> <C-w>l
168 "" CTRL-L to clear highlighting and also update diff
169 " NOTE: sensible.vim and nvim already do this, so copy sensible.vim
170 " functionality if it hasn't been set or we aren't nvim. taken from
171 " sensible.vim by Tim Pope, under Vim license; see :help license
172 " https://github.com/tpope/vim-sensible/blob/0ce2d843d6f588bb0c8c7eec6449171615dc56d9/plugin/sensible.vim#L57
173 if !has('nvim') && maparg('<C-L>', 'n') ==# ''
174 nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
180 " https://github.com/lambdalisue/vim-suda/issues/32#issuecomment-829608925
182 let g:suda_smart_edit = 1
184 " re-enable backup, swap, undo for suda buffers that we can read
185 " https://github.com/lambdalisue/vim-suda/issues/25
186 function s:SudaSettingsSave()
187 let b:sev_suda_backup = &backup
188 let b:sev_suda_swapfile = &swapfile
189 let b:sev_suda_undofile = &undofile
191 function s:SudaSettingsRestore()
192 if filereadable(expand('<afile>')[7:])
193 if exists('b:sev_suda_backup') && b:sev_suda_backup
194 " XXX: suda.vim uses setlocal for this, even though it's global...
195 " https://github.com/lambdalisue/vim-suda/issues/85
198 if exists('b:sev_suda_swapfile') && b:sev_suda_swapfile
201 if exists('b:sev_suda_undofile') && b:sev_suda_undofile
206 autocmd BufReadPre suda://* call s:SudaSettingsSave()
207 autocmd BufReadPost suda://* call s:SudaSettingsRestore()