-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.mappings-custom.vim
141 lines (120 loc) · 4.98 KB
/
init.mappings-custom.vim
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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Function keys {{{1
" NOTE: reserving F1 for documentation lookup
if exists('g:nvim')
nnoremap <C-F1> <Cmd>NvimTreeToggle<CR>
else
nnoremap <C-F1> <Cmd>NERDTreeToggle<CR>
endif
if exists('g:tui_nvim')
call MapKey('<F13>', '<Cmd>helpclose<CR>')
else
call MapKey('<S-F1>', '<Cmd>helpclose<CR>')
endif
call MapKey('<C-S-F1>', '<Cmd>messages<CR>')
" Override default so that we don't have the slow preview
command! -bar -bang -nargs=? -complete=buffer MyBuffers call fzf#vim#buffers(<q-args>, <bang>0)'
" But FZF is too slow
"nmap <C-F2> <Cmd>MyBuffers<CR>
nmap <C-F2> <Cmd>CtrlPBuffer<CR>
if exists('g:nvim')
" Until telescope can do this: https://github.com/nvim-telescope/telescope.nvim/issues/2188
"nmap <C-F2> <Cmd>Telescope buffers show_all_buffers=false ignore_current_buffer=true sort_mru=true<CR>
nmap <C-S-F2> <Cmd>Telescope buffers sort_mru=true<CR>
nmap <C-F3> <Cmd>Telescope live_grep<CR>
nmap <C-S-F3> <Cmd>Telescope live_grep no_ignore=true follow=true<CR>
nmap <C-F4> <Cmd>Telescope find_files<CR>
nmap <C-S-F4> <Cmd>Telescope find_files no_ignore=true follow=true<CR>
else
nmap <C-F3> <Cmd>Rg<CR>
nmap <C-S-F3> <Cmd>RG<CR>
nmap <C-F4> <Cmd>GFiles --cached --others --exclude-standard<CR>
nmap <C-S-F4> <Cmd>FZF<CR>
endif
nmap <F5> <Leader>o1
" Make pastetoggle also work in insert mode
set pastetoggle=<F5>
" Free up <C-p> for other uses (2022-11-10 for coc): use <C-F5>
let g:ctrlp_map = '<C-F5>'
nmap <F6> <Leader>o2
nmap <C-F7> <Cmd>SymbolsOutline<CR>
if exists('g:nvim')
nmap <C-F9> <Cmd>LazyGit<CR>
endif
nmap <C-F10> <Cmd>Startify<CR>
nmap <F11> <Leader>o3
nmap <F12> <Leader>o4
nmap <C-F12> <Cmd>UndotreeToggle<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Display modes {{{1
" Different display options
nnoremap <Leader>o0 <Cmd>set sts=2 sw=2 wrap linebreak showbreak=↪ number
\ relativenumber cursorline nocursorcolumn colorcolumn=+1,80,100,120<CR>
nnoremap <Leader>o1 <Cmd>call TogglePaste()<CR>
nnoremap <Leader>o2 <Cmd>call CycleEditDisplay()<CR>
nnoremap <Leader>o3 <Cmd>call CycleTextwidth()<CR>
nnoremap <Leader>o4 <Cmd>call ToggleVirtualEdit()<CR>
"nnoremap <Leader>o5 <Cmd>!elinks -default-mime-type "text/html" file://%<CR>
" Indentation options
nnoremap <Leader>t1 <Cmd>set et<CR><Cmd>set sts=2 sw=2<CR>
nnoremap <Leader>t2 <Cmd>set et<CR><Cmd>set sts=4 sw=2<CR>
nnoremap <Leader>t3 <Cmd>set et<CR><Cmd>set sts=8 sw=4<CR>
nnoremap <Leader>t4 <Cmd>set noet<CR><Cmd>set sts=8 sw=8<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Misc {{{1
" Folding http://vim.wikia.com/wiki/Folding
nnoremap <silent> <Space><Space> @=(foldlevel('.')?'za':'l')<CR>
vnoremap <Space><Space> zf
" Liberate <C-k> in insert mode so we can use it to kill the rest of the line
" and to navigate Coc menu
" NOTE: MapKey doesn't work here, but do we even need it?
" call MapKey('<C-q><C-k>', '<C-k>', ['imap'])
inoremap <C-q><C-k> <C-k>
" Suspend from any mode, liberating <C-z> for toggling value
call MapKey('<C-q><C-z>', '<C-z>')
" Closing without saving
nmap Zw <Cmd>bdelete!<CR>
" Save all and exit
nmap ZA <Cmd>confirm qall<CR>
" Closes buffer without messing up split window
" (goes to the next buffer first so that the split window is not closed)
" 2022-10-25 Now use bbye plugin
"noremap <C-w><C-q> <Cmd>bnext<CR><Cmd>bdel #<CR>
" Switch to alternate buffer
call MapKey('<M-a>', '<C-^>')
" Edit .vimrc
call MapKey('<C-q><C-e>', '<Cmd> $MYVIM/.vimrc<CR>')
" Reload configs and re-run Sleuth
call MapKey('<C-q><C-r>', '<Cmd>so $MYVIM/.vimrc<CR><Cmd>silent! Sleuth<CR><Cmd>syn on<CR><Cmd>echo "Configs reloaded"<CR>')
" Save buffer
" NOTE: MacVim and VimR already map <D-s>
" NOTE: we don't use MapControlKey because we don't want to conflict with <M-s>, which is one of
" our chord prefixes
call MapKey('<C-s>', '<Cmd>write<CR>', ['nmap', 'map!'])
" Recover the visual->select command that's normally mapped to <C-g>
" NOTE: `xmap` doesn't work for some reason
call MapKey('<C-s>', '<C-g>', ['vmap', 'smap'])
" Save buffer and reload configs
" NOTE: we don't use MapControlKey because we don't want to conflict with <M-q>
call MapKey('<C-q><C-s>', '<Cmd>write<CR><C-q><C-r>', 'all', v:false, v:true)
" Allow saving of files as sudo when you forget to start vim using sudo.
" Shortcut matches my zsh binding
if exists('g:nvim')
cnoremap <C-x><C-s> <C-u>SudaWrite
else
cnoremap <C-x><C-s> <C-u>w !sudo tee > /dev/null %
endif
" Use Q for par formating
" NOTE: regular formatting is still done with `gq` and emacs formatting with <M-q>
vnoremap Q !par -w<CR>
" Select last pasted block
nnoremap <expr> gb '`[' . strpart(getregtype(), 0, 1) . '`]'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Typo Corrections {{{1
" I hold <shift> too long when typing ':'
" NOTE: we add the ! so we can re-source .vimrc
command! Q q
command! Qa qa
command! QA qa
command! W w
" vim:foldmethod=marker: