~wrm/dotfiles

ref: 123b158daa220a00fac6f19c375ef16b91a168cc dotfiles/.config/nvim/init.vim -rw-r--r-- 4.7 KiB
123b158d — +wrm misc: Apply numerous minor changes 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
" TODO Port LaTeX setup.

set nocompatible
filetype off

" ---------
"  Plugins
" ---------

" All plugins require justification. Note frequency of use and compare to raw
" vim alternative.

set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin('~/.config/nvim/')

" Vundle - Often. Managing vim stuff in vimrc is useful and vundle
" specifically means you don't have to think whatsover about dirs or git or
" helpdocs.
Plugin 'VundleVim/Vundle.vim'

" Bufferline - Constantly. 60 line script to list open buffers that stays out
" of the way. :buffers obvs works but I like being able to just look.
Plugin 'bling/vim-bufferline'

" Fugitive - Constantly. As tpope says, as much a vim plugin for git as vice
" versa. I still regularly ^Zg... but it's a supplement not a replacement.
Plugin 'tpope/vim-fugitive'

" Ctrl-P - Rarely, vim wildmode+wildmenu expansion of */** is pretty great.
"Plugin 'ctrlpvim/ctrlp.vim'

" ferret - Performance-wise vimgrep works fine even hitting 1mil+ sloc by
" using it properly, keeping this in my pocket because I want to play with its
" extra options and quickfix changes.
"Plugin 'wincent/ferret'

" VimCompletesMe - Just use i_^X, it's really great.
"Plugin 'ackyshake/VimCompletesMe'

" YouCompleteMe - YCM is Bloat with a capital client-server architecture, but
" instantly IDEfies your text editor. Sometimes I'm in the mood to use this.
" Usually ^Xpand is good enough.
"Plugin 'ycm-core/YouCompleteMe'

call vundle#end()

" ---------
"  General
" ---------

let mapleader=" "

" Things that should be vim defaults:
"set nocompatible " Required for vundle anyway.
filetype plugin indent on
syntax on
set encoding=utf-8
set number
set hidden
set splitbelow
set splitright
set title

" Search defaults
set ignorecase
set smartcase

" Read local .vimrc in parent dirs
set exrc
set secure

" Toggle between relative and absolute linenums if in insert mode
set relativenumber

augroup relativenumbering
	autocmd!
	autocmd InsertEnter * :set norelativenumber
	autocmd InsertLeave * :set relativenumber
augroup end

" Delete trailing whitespace on save
autocmd BufWritePre * %s/\s\+$//e

" Command-line mode autocompletion
set path+=**
set wildmode=longest,list,full
set wildmenu

" Steal code faster
set clipboard+=unnamedplus

" Disable comments carrying onto newlines
autocmd filetype * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

" Auto-wrap common non-code files
autocmd BufRead,BufNewFile README*,*.txt,*.md,*.tex setlocal tw=80

" Highlight others
set t_Co=256 " Not needed anymore but doesn't hurt.
set colorcolumn=80
highlight ColorColumn ctermbg=233

" Treat CNatural files as having C++ syntax
autocmd BufNewFile,BufRead *.cn setfiletype cn
autocmd FileType cn setlocal syntax=cpp

" Treat .html.sh extra specially.
autocmd BufNewFile,BufRead *.html.sh setlocal syntax=htmlsh

" Some general tab rules.
" Usually defined by a local vimrc file to suite a project's style rules.
set noexpandtab
set tabstop=8
set shiftwidth=8
autocmd FileType python setlocal expandtab tabstop=4 shiftwidth=4

" Transparent editing of gpg encrypted files
" Based on https://vim.fandom.com/wiki/Edit_gpg_encrypted_files

" Don't save backups of *.gpg files
set backupskip+=*.gpg
augroup gpgencrypted
	autocmd!
	" To avoid that parts of the file is saved to shared data when yanking
	" or deleting, empty the 'viminfo/shada' option.
	autocmd BufReadPre,FileReadPre *.gpg set shada=
	" Disable swap files, and set binary file format before reading the file
	autocmd BufReadPre,FileReadPre *.gpg setlocal noswapfile bin
	" Decrypt the contents after reading the file, reset binary file format
	" and run any BufReadPost autocmds matching the file name without the
	" .gpg extension
	autocmd BufReadPost,FileReadPost *.gpg
		\ execute "'[,']!gpg --decrypt --default-recipient-self" |
		\ setlocal nobin |
		\ execute "doautocmd BufReadPost " . expand("%:r")
	" Set binary file format and encrypt the contents before writing the file
	autocmd BufWritePre,FileWritePre *.gpg
		\ setlocal bin |
		\ '[,']!gpg --quiet --encrypt --default-recipient-self
	" After writing the file, do an :undo to revert the encryption in the
	" buffer, and reset binary file format
	autocmd BufWritePost,FileWritePost *.gpg
		\ silent undo |
		\ setlocal nobin
augroup END

" Shortcuts
" ---------

" Spell check
map <F6> :setlocal spell! spelllang=en_gb<CR>

" Disable search highlighting
nnoremap <leader>/ :nohlsearch<CR>

" Split navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" Replace all
nnoremap S :%s//g<Left><Left>

" Buffer movement
nnoremap <Left> :bp<CR>
nnoremap <Right> :bn<CR>

" Quickfix movement
nnoremap <C-Left> :cp<CR>
nnoremap <C-Right> :cn<CR>

" Skeletons n Snippets
let closet = "~/.local/share/skeletons/"
nnoremap ,sh :read <C-r>=closet<CR>sh/
imap ,sh <Esc>,sh