aboutsummaryrefslogtreecommitdiff
path: root/vim/keymaps.vim
blob: 2da1ae3117431e3c6179b10b0028d796ac0d2daa (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
186
187
"""""""""""""""""""""""""""""
"	Keymaps
"""""""""""""""""""""""""""""

let g:mapleader = "\<Space>"
let g:maplocalleader = ','
nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>

" Treat long paragraph as a line
map j gj
map k gk

""""""""""""""""""""
" Window movement
""""""""""""""""""""

" Go to the bottom window
noremap <C-j> <C-w>j

" Go to the top window
noremap <C-k> <C-w>k

" Go to the right window
noremap <C-l> <C-w>l

" Go to the left window
noremap <C-h> <C-w>h

""""""""""""""""""""""""
" Remove highlighting
""""""""""""""""""""""""

nnoremap <leader>hl :nohlsearch<CR>

" Save file
nnoremap <C-s> :w!<CR>

""""""""""""""""""""""""""
" Buffer
"""""""""""""""""""""""""

" Close the current buffer
noremap <leader>bd :Bclose<cr>:tabclose<cr>gT

" Close all the buffers
noremap <leader>ba :bufdo bd<cr>

" Go to the next buffer
noremap <leader>bn :bnext<cr>

" Go to the previous buffer
noremap <leader>bp :bprevious<cr>

""""""""""""""""""""""""""""
" Tabs
"""""""""""""""""""""""""""

" Open a new tab
noremap <leader>tn :tabnew<cr>

" Close all others tab
noremap <leader>to :tabonly<cr>

" Close current tab page
noremap <leader>tc :tabclose<cr>

" Move tabs after another
noremap <leader>tm :tabmove

" Go to the next tab
noremap <leader>t<leader> :tabnext<cr>

" Let 'tl' toggle between this and the last accessed tab
let g:lasttab = 1
nnoremap <leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()

" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
noremap <leader>te :tabedit <C-r>=escape(expand("%:p:h"), " ")<cr>/

" Switch CWD to the directory of the open buffer
noremap <leader>cd :cd %:p:h<cr>:pwd<cr>

" Specify the behavior when switching between buffers
try
  set switchbuf=useopen,usetab,newtab
  set stal=2
catch
endtry

" Return to last edit position when opening files (You want this!)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

""""""""""""""""""""""""
" Netrw
"""""""""""""""""""""""

" Toggle tree view
nnoremap <C-f> :Lexplore<CR>

""""""""""""""""""""
" GitGutter
""""""""""""""""""""

let g:gitgutter_enabled=1 " Enable by default gitgutter

" Go to the previous hunk
nnoremap <leader>hp <Plug>(GitGutterPrevHunk)

" Go to the next hunk
nnoremap <leader>hn <Plug>(GitGutterNextHunk)

" Enable / Disable GitGutter
nnoremap <leader>ht <Plug>(GitGutterToggle)

" Stage Hunk in Git
nnoremap <leader>hs <Plug>(GitGutterStageHunk)

" Undo Hunk
nnoremap <leader>hu <Plug>(GitGutterUndoHunk)

" Preview Hunk
nnoremap <leader>hP :GitGutterPreviewHunk<CR>

" Always show the status line
set laststatus=2

"""""""""""""""""""""
" Spell
"""""""""""""""""""""

" Toggle and untoggle spell checking
noremap <leader>ss :setlocal spell!<cr>

" Next word to spellcheck
noremap <leader>sn ]s

" Previous word to spellcheck
noremap <leader>sp [s

" Add word into the spellcheck dictionnary
noremap <leader>sa zg

" show the list of alternatives for the word
noremap <leader>s? z=

"""""""""""""""""""
" LSP
"""""""""""""""""""
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

nmap <silent> gp <Plug>(coc-diagnostic-prev)
nmap <silent> gn <Plug>(coc-diagnostic-next)

" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window
nnoremap <silent> gh :call ShowDocumentation()<CR>

function! ShowDocumentation()
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  else
    call feedkeys('K', 'in')
  endif
endfunction

" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming
nmap <leader>gR <Plug>(coc-rename)

" Formatting selected code
xmap <leader>gf  <Plug>(coc-format-selected)
nmap <leader>gf  <Plug>(coc-format-selected)
ArKa projects. All rights to me, and your next child right arm.