~smlavine/dots

dots/src/.config/nvim/init.vim -rw-r--r-- 3.8 KiB
69d3604bSebastian LaVine .config/nvim/init.vim: Add indentation rules for Python 15 days 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
" _________ _       __________________            _________ _______
" \__   __/( (    /|\__   __/\__   __/    |\     /|\__   __/(       )
"    ) (   |  \  ( |   ) (      ) (       | )   ( |   ) (   | () () |
"    | |   |   \ | |   | |      | |       | |   | |   | |   | || || |
"    | |   | (\ \) |   | |      | |       ( (   ) )   | |   | |(_)| |
"    | |   | | \   |   | |      | |        \ \_/ /    | |   | |   | |
" ___) (___| )  \  |___) (___   | |    _    \   /  ___) (___| )   ( |
" \_______/|/    )_)\_______/   )_(   (_)    \_/   \_______/|/     \|
"
" Copyright (c) 2017-2021 Sebastian LaVine <mail@smlavine.com>
" Copyright (c) 2017-2021 StackOverflow Contributors <stackoverflow.com>
" This file is licensed under the terms of CC BY-SA 4.0.
"_______________________________________________________________________

filetype plugin indent on

set wildmode=longest,list,full
set wildmenu

" Makes backspace 'normal'
set backspace=indent,eol,start

" Aligns C cases like:
" switch (x) {
" case 'a':
"     ...
" }
" instead of
" switch (x) {
"     case 'a':
"     ...
" }.
set cinoptions+=:0

" Aligns C function return type declarations like:
" static void
" usage()
" {
"   ...
" }
" instead of
"     static void
" usage()
" {
"   ...
" }
set cinoptions+=t0

set iskeyword-=-

if !isdirectory('/tmp/nvim')
	call mkdir('/tmp/nvim')
endif
set backupdir=/tmp/nvim
set directory=/tmp/nvim
set backup

set number relativenumber
augroup numbertoggle
	autocmd!
	autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
	autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
augroup END

set splitbelow
set splitright

set autoindent
set tabstop=8 shiftwidth=8 noexpandtab

" Disable .netrwhist being generated.
let g:netrw_dirhistmax=0

" I try to keep my max columns to 80 lines. This lets me know when I go over.
highlight ColorColumn ctermbg=0
let &colorcolumn=join(range(80,80),",")

" When writing Markdown, I prefer to use a 72 column max length. This allows
" me to toggle it quickly.
fun! ToggleColumnWidth()
	if (&colorcolumn == 80)
		let &colorcolumn=join(range(73, 80),",")
	else
		let &colorcolumn=join(range(80,80),",")
	endif
endfun
au BufNewFile,BufRead *.md call ToggleColumnWidth()

" html and css should be indented with spaces.
au BufNewFile,BufRead *.html setl shiftwidth=2 ts=2 softtabstop=2 expandtab
au BufNewFile,BufRead *.css  setl shiftwidth=2 ts=2 softtabstop=2 expandtab

" python should also be indented with spaces.
au BufNewFile,BufRead *.py setl shiftwidth=4 ts=4 softtabstop=4 expandtab

" This function makes it so invocations of the command :from will be
" interpreted as :to. See the following block including "W", "Wq", etc.
fun! SetupCommandAlias(from, to)
    exec 'cnoreabbrev <expr> '.a:from .' ((getcmdtype() is# ":" && getcmdline()
                \ is# "'.a:from.'")' .'? ("'.a:to.'") : ("'.a:from.'"))'
endfun

" I often misspell these. Just fix 'em.
call SetupCommandAlias("W", "w")
call SetupCommandAlias("Wq", "wq")
call SetupCommandAlias("Q", "q")
call SetupCommandAlias("wQ", "wq")
call SetupCommandAlias("WQ", "wq")

nnoremap <F4> :set rnu!<CR>

nnoremap <F3> :!pandoc % -o /tmp/example.pdf &<CR><CR>

nnoremap <C-B> :call ToggleColumnWidth()<CR>

" Better window switching hotkeys.
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" Center window when going up/down a paragraph.
nnoremap [[ [[zz
nnoremap ]] ]]zz

" Center window when viewing search results.
nnoremap n nzz

" Bind swap escape and "terminal escape" in a terminal window
tnoremap <Esc> <C-\><C-N>
tnoremap <C-\><C-N> <Esc>

" Indetation fix rebind
nnoremap <C-I> ==
vnoremap <C-I> ==

" Better window resizing hotkeys
nnoremap - :res -1<CR>
nnoremap = :res +1<CR>
nnoremap < :vertical res -1<CR>
nnoremap > :vertical res +1<CR>
nnoremap + <C-W>=

" Disable highlighting of searched terms.
nnoremap <C-C> :noh<CR>