dotfiles

Cross platform dotfiles for linux, mac and windows

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 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
" General keybindings
inoremap <C-{> <esc>:
nnoremap <C-{> :

nnoremap <C-/> :vim9cmd scope#fuzzy#Grep('git grep')<cr>
nnoremap <C-`> :terminal<cr>

nnoremap <F4> :call SaveAndBuild()<cr>

nnoremap <leader>co :botright copen<cr>
nnoremap <leader>cs :cdo<space>s/
nnoremap <leader>ec :call OpenSource("$XDG_HOME/.vimrc")<cr>
nnoremap <leader>ek :call OpenSource("$XDG_DATA_HOME/vim/keybindings.vim")<cr>
nnoremap <leader>et :set expandtab<cr>
nnoremap <leader>fa :find *
nnoremap <leader>ff :find *
nnoremap <leader>lb :ls<cr>:b<space>
nnoremap <leader>ld :ldo<space>s/
nnoremap <leader>lo :lopen<cr>
nnoremap <leader>ls :ldo<space>s/
nnoremap <leader>pp :Rg<cr>
nnoremap <leader>pv :packadd vimspector<cr>
nnoremap <leader>sc :source $XDG_CONFIG_HOME/vim/vimrc<cr>
nnoremap <leader>so :source %<cr>
nnoremap <leader>spp :set paste<cr>
nnoremap <leader>spa :set path+=**<cr>
nnoremap <leader>tt :tabnew<cr>
nnoremap <leader>ta :tab *
nnoremap <leader>vg :vimgrep<space>
nnoremap <leader>/ :cdo %s/
nnoremap <leader>cd :cd %:p:h<cr>
nnoremap <leader>gcd :Gcd<cr>
nnoremap <leader>qd :cdo s/

" Buffer Creation
nnoremap <leader>sc :source $XDG_CONFIG_HOME/vim/vimrc<cr>
nnoremap <leader>ss :split<cr>
nnoremap <leader>vv :vsplit<cr>

nnoremap <leader>ds :call DiffWithSaved()<cr>
" TODO Add du to diff with undo
" nnoremap <leader>ds :call DiffWithSaved()<cr>

fun! SaveAndSuspend()
    :w
    :suspend
endfun

nnoremap <silent> <leader>zj :call NextClosedFold('j')<cr>
nnoremap <silent> <leader>zk :call NextClosedFold('k')<cr>

function! NextClosedFold(dir)
    let cmd = 'norm!z'..a:dir
    let view = winsaveview()
    let [l0, l, open] = [0, view.lnum, 1]
    while l != l0 && open
        exe cmd
        let [l0, l] = [l, line('.')]
        let open = foldclosed(l) < 0
    endwhile
    if open
        call winrestview(view)
    endif
endfunction


" Control
nnoremap <c-z> :call SaveAndSuspend()<cr>
inoremap <c-z> :call SaveAndSuspend()<cr>

" Accessible completions
inoremap <c-l> <c-x><c-l>
" Emacs line navigation in insert mode
inoremap <c-a> <c-o>0
inoremap <c-e> <c-o>A
inoremap <c-k> <c-o>D
inoremap <c-y> <c-o>p
inoremap <c-f> <Right>
inoremap <c-b> <Left>

cnoremap <c-a> <home>
cnoremap <c-e> <end>
cnoremap <c-y> <c-r>"
cnoremap <c-p> <c-f>
cnoremap <c-f> <Right>
cnoremap <c-b> <Left>

nnoremap <c-x><c-f> :Explore<cr>/
nnoremap <c-x><c-c> :q<cr>
nnoremap <c-x><c-g> :G<cr>/
nnoremap <c-x><c-s-g> :G<cr>
nnoremap <c-x><c-d> :Debugger<cr>
nnoremap <c-x><c-s> :w<cr>

" Behave vim
nnoremap Y y$
nnoremap Q :noh<cr>

" development
nnoremap <leader>oc :grepadd /:: %
nnoremap <leader>oh :grepadd /:: %

nnoremap <leader>fb :b *

" TODO reflect on whether <leader><leader> is productive, I keep hitting it
" accidentally
"nnoremap <leader><leader> :Rg<cr>

fun! SetupCommandAlias(from, to)
  exec 'cnoreabbrev <expr> '.a:from
        \ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:from.'")'
        \ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfun
call SetupCommandAlias("W","w")
call SetupCommandAlias("Wq","wq")
call SetupCommandAlias("man","help")

nnoremap <leader>tb :call ToggleBackground()<CR>
nnoremap <leader>tl :call ToggleList()<CR>

" useful
nnoremap <leader>nn :set number<cr>

" development
nnoremap <M-F9> :call SaveAndBuild()<cr>
inoremap <M-F9> :call SaveAndBuild()<cr>
nnoremap <leader>bc :Make clean<CR>

nnoremap <leader>fmv :call FileMvHelper()<CR>

" Quick save and write
nnoremap <leader>wq :wq<cr>
nnoremap <leader>ww :w<cr>
nnoremap <leader>qq :q<cr>

" vim-fugitive
nnoremap <leader>gb :G blame<cr>
nnoremap <leader>dg :Gvdiff<CR>
nnoremap <leader>gg :Ggrep -q <space>
nnoremap <leader>gr :G reset %<cr>
nnoremap <leader>gwq :Gwq<cr>
nnoremap <leader>lg :Glgrep<space>


" Generate ctags
nnoremap<leader>gt :!sh -c "ctags `git ls-files`"<CR>

nnoremap <C-L> :nohl<CR><C-L>

" Markdown - Add checkbox mode?
nnoremap <leader>cc :ChecklistToggleCheckbox<cr>
nnoremap <leader>ct :ChecklistToggleCheckbox<cr>
nnoremap <leader>ce :ChecklistEnableCheckbox<cr>

let g:gutentags_file_list_command = 'rg --files'


autocmd FileType markdown set cursorline

" Hide and format markdown elements like **bold**
autocmd FileType markdown set conceallevel=2

nnoremap <leader>h1 :call QuickUnderline(1)<cr>
nnoremap <leader>h2 :call QuickUnderline(2)<cr>

fun! GotoWindow(id)
    call win_gotoid(a:id)
endfun


fun! StartDebugging()
    doautocmd User DebuggingStarted
    :Termdebug .\payredu.exe<cr>
endfun

" Easy save
nnoremap <esc>s :w<cr>

" Fly through windows
nnoremap <esc>h <c-w>h
nnoremap <esc>j <c-w>j
nnoremap <esc>k <c-w>k
nnoremap <esc>l <c-w>l

" Debugger remaps
nnoremap <F5> :call StartDebugging()<cr>
nnoremap <leader>dc :call GotoWindow(g:vimspector_session_windows.code)<CR>
nnoremap <leader>dt :call GotoWindow(g:vimspector_session_windows.tagpage)<CR>
nnoremap <leader>dv :call GotoWindow(g:vimspector_session_windows.variables)<CR>
nnoremap <leader>dw :call GotoWindow(g:vimspector_session_windows.watches)<CR>
" nnoremap <leader>ds :call GotoWindow(g:vimspector_session_windows.stack_trace)<CR>
nnoremap <leader>do :call GotoWindow(g:vimspector_session_windows.output)<CR>
nnoremap <S-F5> :call vimspector#Reset()<CR>

nnoremap <leader>dtcb :call vimspector#CleanLineBreakpoint()<CR>

fun! SetupDebuggingKeymaps()
    nmap <> <Plug>VimspectorStepOver
    nmap <c-i> <Plug>VimspectorStepInto
    nmap <m-i> <Plug>VimspectorStepOut
    nmap <c-s-r> <Plug>VimspectorRestart
    nmap <F9> :Break<cr>
    nmap <C-S-F9> :Clear<CR>
    nmap <F5> :Continue<CR>
    nmap <S-F5> :Finish<CR>
endfun

augroup debugmode
    autocmd User DebuggingStarted :call SetupDebuggingKeymaps()
augroup END

nmap <leader>drc <Plug>VimspectorRunToCursor
nmap <leader>dbp <Plug>VimspectorToggleBreakpoint
nmap <leader>dcbp <Plug>VimspectorToggleConditionalBreakpoint

nnoremap cn *``cgn
nnoremap cN *``cgN
let g:mc = "y/\\V\<C-r>=escape(@\", '/')\<CR>\<CR>"
vnoremap <expr> cn g:mc . "``cgn"

let g:ctrlp_map = '<F2>'
nnoremap <F1> :CtrlPBuffer<cr>
inoremap <F1> :CtrlPBuffer<cr>
nnoremap <S-F1> :CtrlPMRU<cr>
inoremap <S-F1> :CtrlPMRU<cr>
"
" TODO setup this up with fzf
nnoremap <F2> :vim9cmd scope#fuzzy#GitFile()<cr>
nnoremap <S-F2> :vim9cmd scope#fuzzy#File()<cr>

nnoremap <F3> :vim9cmd call scope#fuzzy#Quickfix()<cr>

if has('macunix')
    :imap <D-V> ^O"+p
en