summaryrefslogtreecommitdiff
path: root/nvim/init.vim
blob: d7794b6a295cd9de4f651283823ddb6feb42cf03 (plain)
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
177
178
179
180
181
182
183
184
185
"" Manage plugins using vim-plug
if ! filereadable((isdirectory($XDG_CONFIG_HOME) ? $XDG_CONFIG_HOME : "./config") . "/nvim/autoload/plug.vim")
	echo "Downloading junegunn/vim-plug to manage plugins..."
	silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/
	silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim
	autocmd VimEnter * PlugInstall
endif

call plug#begin((isdirectory($XDG_DATA_HOME) ? $XDG_DATA_HOME : ".local/share") . "/vim-plug")
Plug 'alvan/vim-closetag'
Plug 'ap/vim-css-color'
Plug 'junegunn/goyo.vim'
Plug 'vimwiki/vimwiki'
Plug 'tpope/vim-commentary'
Plug 'hrsh7th/nvim-cmp'                  " The completion plugin
Plug 'hrsh7th/cmp-buffer'                " buffer completions
Plug 'hrsh7th/cmp-path'                  " path completions
Plug 'hrsh7th/cmp-cmdline'               " cmdline completions
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'saadparwaiz1/cmp_luasnip'          " snippet completions
Plug 'L3MON4D3/LuaSnip'                  " snippet engine
Plug 'rafamadriz/friendly-snippets'      " a bunch of snippets to use
Plug 'neovim/nvim-lspconfig'             " enable LSP
Plug 'williamboman/mason.nvim'           " simple to use language server installer
Plug 'williamboman/mason-lspconfig.nvim' " simple to use language server installer
call plug#end()

" lua require('user.cmp')
" lua require('user.lsp')

"" Basic options
set autochdir                  " Always change directory to current file
set autoindent                 " Keeps indentation on new lines
set hlsearch                   " Highlight search hits
set ignorecase                 " Case-insensitive search...
set linebreak                  " Word wrap
set list                       " Show whitespace characters defined in listchars
set listchars=tab:▏\ \,space:· " Highlight tabs and spaces
set mouse=a                    " Because sometimes it's just easier to use the mouse
set number relativenumber	   " Enable relative line numbers
set smartcase                  " ...Unless the search term is capital
set splitbelow splitright	   " Open splits on bottom/right instead of top/left
set termguicolors              " Enable GUI colors for the terminal to get truecolor
set wildmode=longest,list,full " Enable file auto-complete
set wrap!                      " Disable word wrapping
syntax on                      " Enable syntax highlighting

" Get rid of the pointless .viminfo files that clutter the home directory
let skip_defaults_vim=1
set viminfo=""

" Disables automatic commenting on newline:
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

" Tabbing
"let tabwidth = 4
set tabstop=4                  " Set width of tabs to 4 instead of default 8
set shiftwidth=4               " Tab key will only insert 1 tab
" Use tabs instead of spaces
autocmd FileType sass setlocal noet ci pi sts=0 sw=4 ts=4

"" Plugin options
" Closetag
let g:closetag_filenames = '*.html,*.xhtml,*.phtml'
" VimWiki
let g:vimwiki_list = [{'path': '~/docs/school/arc/docs/wiki/', 'path_html': '~/docs/school/arc/docs/wiki/site/'}]

" Filetype options
autocmd BufRead,BufNewFile *.tex set filetype=tex
au Filetype tex let b:autopairs_enabled = 0
au Filetype tex setlocal indentexpr=
au BufRead,BufNewFile *.tssg set filetype=tssg

"" Keybindings
" Set leader-key to comma
let mapleader =","
" Invoke goyo with comma-m
nmap <leader>m :Goyo 120x<CR>
" Invoke spellcheck mode with comma-l
nmap <leader>l :setlocal spell! spelllang=en_us<CR>
" Set cursorcolumn with comma-c
nmap <leader>c :set cursorcolumn!<CR>
" Navigate faster than hjkl with ctrl-hjlk
nmap <C-h> zh
nmap <C-j> <C-e>
nmap <C-k> <C-y>
nmap <C-l> zl
" Faster split navigation (leader-wasd, as opposed to ctrl-w + hjlk)
map <leader>a <C-w>h
map <leader>s <C-w>j
map <leader>w <C-w>k
map <leader>d <C-w>l
" Keys for tab navigation
nmap <leader><TAB> gt
nmap <leader>t :tabnew<CR>
nmap <C-T> :tabnew<CR>
" Copy and cut with standard bindings
map <C-c> "+y
map <C-x> "+x
" Unmap Ex mode
map Q <NOP>
" Perform dot commands over visual blocks:
vnoremap . :normal .<CR>
" Save file as sudo on files that require root permission
cnoremap w!! execute 'silent! write !doas tee % >/dev/null' <bar> edit!
" Camel case every word on the line
"nmap gcc :s/\v<(.)(\w*)/\u\1\L\2/g<CR>
"nmap gCC :%s/\v<(.)(\w*)/\u\1\L\2/g<CR>
" HTML shortcuts
nmap gwp I<p><ESC>l4xA</p><ESC>
nmap gwh1 I<h1><ESC>l5xA</h1><ESC>
nmap gwh2 I<h2><ESC>l5xA</h2><ESC>
nmap gwh3 I<h3><ESC>l5xA</h3><ESC>

"" Extra functionality
" Colorscheme for root and normal users (since vimrc is just symlinked to the root user's home)
if ($USER) == 'root'
	colorscheme koehler
else
"	if empty($DISPLAY)
"		colorscheme koehler
"	else
		set bg=dark
		let g:gruvbox_contrast_dark = 'hard'
		colorscheme gruvbox-timmy
"	endif
endif

" Functions for changing the terminal emulator's class name to 'Vim'
function GetTermPID(temu)
	let pinfo = ['', getpid(), '']
	while !(pinfo[2] =~ a:temu || pinfo[1] == '0')
		let pinfo = split(system('ps h -o pid,ppid,command= -p' . pinfo[1]))
	endwhile
	return pinfo[0]
endfunction

function SetTermClassName(termpid, name)
	" Command chaining in xdotool doesn't work here for some reason
	silent exec "!xdotool set_window --class " . a:name . " $(xdotool search --pid " . a:termpid . ")"
endfunction

" Behaviors exclusive to either a tty or a graphical terminal emulator
if empty($DISPLAY)
	" Clear the tty screen after exiting vim
	autocmd VimLeave * :clear
else
	" Highlight current line
	set cursorline
	" Change window title
	autocmd BufEnter * :set title
	let &titleold="st"
	" Change class name
	let temu = "st"
	let temupid = GetTermPID(temu)
	if (temupid != 1)
		autocmd VimEnter * call SetTermClassName(temupid, "Vim")
		autocmd VimLeave * call SetTermClassName(temupid, temu)
	endif
endif

" Automatically deletes all trailing whitespace on save
function DelWS()
	let l:save_view = winsaveview()
	:%s/\s*$//e
	call winrestview(l:save_view)
endfunction
autocmd BufWritePre * call DelWS()


" vim -b : edit binary using xxd-format!
augroup Binary
  au!
  au BufReadPre  *.bin let &bin=1
  au BufReadPost *.bin if &bin | %!xxd
  au BufReadPost *.bin set ft=xxd | endif
  au BufWritePre *.bin if &bin | %!xxd -r
  au BufWritePre *.bin endif
  au BufWritePost *.bin if &bin | %!xxd
  au BufWritePost *.bin set nomod | endif
augroup END

"" Auto compile
" Sass
"autocmd BufWritePost [^_]*.sass,[^_]*.scss silent !sass %:p %:p:r.css