]> git.sev.monster Git - dotfiles.git/blame - etc/vim/.vimrc
vim: update vim-commentary
[dotfiles.git] / etc / vim / .vimrc
CommitLineData
39d7f74f 1""" paths
2"" config dir in xdg config
afd175d7 3let x = ($XDG_CONFIG_HOME??($HOME.'/.config')).'/vim'
8d4a98e1 4execute 'set runtimepath='.x.','.&runtimepath.','.x.'/after'
5execute 'set packpath='.x.','.&packpath.','.x.'/after'
1b8a4102 6
39d7f74f 7"" state files in xdg state
afd175d7 8let x = ($XDG_STATE_HOME??($HOME.'/.local/state')).'/vim'
4850f4c2 9if !isdirectory(x)
afd175d7 10 call mkdir(x, 'p', 0700)
11endif
afd175d7 12
39d7f74f 13" backup
14" NOTE: keep backup files in vim state dir for both vim and neovim
afd175d7 15let y = x.'/backup'
16if !isdirectory(y)
17 call mkdir(y, 'p', 0700)
8d4a98e1 18endif
afd175d7 19execute 'set backupdir='.y.'//'
58a8dbcc 20set 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.
28if !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 46endif
58a8dbcc 47
4850f4c2 48unlet x
afd175d7 49unlet y
1b8a4102 50
39d7f74f 51""" vim-only defaults
52if !has('nvim')
53 " neovim defaults are already set
54 source $VIMRUNTIME/defaults.vim
b3b23234 55
39d7f74f 56 " disable jumping to last edit, we use vim-lastplace instead
57 autocmd! vimStartup
58a8dbcc 58
39d7f74f 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
67endif
68
69""" styling
70" nice default theme
71colorscheme murphy
72
73" always use color column with less intrusive colors
58a8dbcc 74autocmd VimEnter,WinNew * set colorcolumn=80
39d7f74f 75" always use cursor line for better visibility
58a8dbcc 76autocmd VimEnter,WinNew * set cursorline
58a8dbcc 77
39d7f74f 78" unique highlighting for leading spaces and in-line spaces
79" NOTE: this leaves tabs and other special whitespace untouched intentionally
1ac43be8 80autocmd VimEnter,ColorScheme * highlight SpaceInner ctermfg=Grey guifg=#686868
81autocmd VimEnter,ColorScheme * highlight link SpaceOuter NonText
82autocmd VimEnter,WinNew * match SpaceInner / /
83autocmd VimEnter,WinNew * 2match SpaceOuter /\(^ \+\)\|\( \+$\)/
39d7f74f 84
85" always show statusline
86set laststatus=2
87
88" truncate > lastline; lastline is nvim default, sensible.vim may also set it
89set display=truncate
90
91" more context while scrolling
92set scrolloff=5
93set sidescrolloff=8
94
95" show number column on all buffers
96autocmd VimEnter,WinNew * set number
97" use relative numbers in normal modes when focused, but not if number is off
98function! 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
107endfunction
108autocmd InsertEnter,FocusLost,WinLeave * call s:SetRelativeNumber(0)
109autocmd VimEnter,WinNew,
110 \InsertLeave,FocusGained,WinEnter * call s:SetRelativeNumber(1)
111
112" always show custom listchars
58a8dbcc 113autocmd VimEnter,WinNew * set list
1b8a4102 114set listchars=tab:├─,extends:»,precedes:«,space:·,trail:∙,nbsp:■
58a8dbcc 115
39d7f74f 116""" editor
117" always save undo file for all file buffers
118autocmd BufRead * set undofile
ddcfe43c 119
39d7f74f 120"" indent
121" always use shiftwidth instead of tabsize
122set smarttab
123" filetype preferences
58a8dbcc 124autocmd FileType python set softtabstop=4 shiftwidth=4 expandtab
125autocmd FileType markdown set softtabstop=4 shiftwidth=4 expandtab
126autocmd FileType javascript set softtabstop=2 shiftwidth=2 expandtab
127autocmd FileType json set softtabstop=2 shiftwidth=2 expandtab
128autocmd FileType html set softtabstop=2 shiftwidth=2 expandtab
e69caf64 129let g:EditorConfig_enable_for_new_buf = 1
58a8dbcc 130
39d7f74f 131"" syntax
58a8dbcc 132autocmd FileType todo set colorcolumn=0
b3b23234 133
39d7f74f 134"" mappings
135" use more accessible escapes, as C-n and C-o are shadowed by some terminals
b3b23234 136if has('nvim')
137 tnoremap <C-\>n <C-\><C-N>
138 tnoremap <C-\>o <C-\><C-O>
139endif
140
39d7f74f 141" move windows any time
b3b23234 142if has('nvim')
143 " terminal
144 tnoremap <A-h> <C-\><C-N><C-w>h
145 tnoremap <A-j> <C-\><C-N><C-w>j
146 tnoremap <A-k> <C-\><C-N><C-w>k
147 tnoremap <A-l> <C-\><C-N><C-w>l
148endif
149" insert
150inoremap <A-h> <C-\><C-N><C-w>h
151inoremap <A-j> <C-\><C-N><C-w>j
152inoremap <A-k> <C-\><C-N><C-w>k
153inoremap <A-l> <C-\><C-N><C-w>l
154" normal
155nnoremap <A-h> <C-w>h
156nnoremap <A-j> <C-w>j
157nnoremap <A-k> <C-w>k
158nnoremap <A-l> <C-w>l
39d7f74f 159
160"" CTRL-L to clear highlighting and also update diff
161" NOTE: sensible.vim and nvim already do this, so copy sensible.vim
162" functionality if it hasn't been set or we aren't nvim. taken from
163" sensible.vim by Tim Pope, under Vim license; see :help license
164" https://github.com/tpope/vim-sensible/blob/0ce2d843d6f588bb0c8c7eec6449171615dc56d9/plugin/sensible.vim#L57
165if !has('nvim') && maparg('<C-L>', 'n') ==# ''
166 nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
167endif
This page took 0.098486 seconds and 4 git commands to generate.