This repository has been archived on 2021-12-21. You can view files and clone it, but cannot push or open issues/pull-requests.
neovim-config/init/keys.vim

91 lines
3.1 KiB
VimL
Raw Normal View History

2021-02-01 10:26:29 +01:00
" zz centers the cursor, so combining this with navigation commands keeps my
" cursor centered
2020-08-08 20:27:01 +02:00
nnoremap j jzz
nnoremap k kzz
nnoremap gg ggzz
nnoremap G Gzz
2021-02-01 10:26:29 +01:00
" I navigate my splits using <leader>hjkl. This setup allows for fast
" switching, which is important as I often end up with 3-4 splits after a while
2020-08-08 20:27:01 +02:00
nnoremap <silent> <leader>h :wincmd h<CR>
nnoremap <silent> <leader>j :wincmd j<CR>
nnoremap <silent> <leader>k :wincmd k<CR>
nnoremap <silent> <leader>l :wincmd l<CR>
2021-02-01 10:26:29 +01:00
" These mappings just exist because I'm lazy, and they only really work in
" QWERTY
2020-08-08 20:27:01 +02:00
nnoremap <silent> <leader>w :w<CR>
nnoremap <silent> <leader>q :q<CR>
2021-02-01 10:26:29 +01:00
" As I don't use the arrow keys for navigation, I remapped them to allow for
" resizing of my splits. If you hold down shift, you can control the size of
" the splits more precisely
nnoremap <silent> <Up> :resize +5<CR>
nnoremap <silent> <Down> :resize -5<CR>
nnoremap <silent> <Right> :vertical resize +5<CR>
nnoremap <silent> <Left> :vertical resize -5<CR>
nnoremap <silent> <S-Up> :resize +1<CR>
nnoremap <silent> <S-Down> :resize -1<CR>
nnoremap <silent> <S-Right> :vertical resize +1<CR>
nnoremap <silent> <S-Left> :vertical resize -1<CR>
2020-08-08 20:27:01 +02:00
2021-02-01 10:26:29 +01:00
" Disable arrow keys in editing & visual mode, as I have no need for them
2020-08-08 20:27:01 +02:00
inoremap <Right> <nop>
inoremap <Left> <nop>
inoremap <Up> <nop>
inoremap <Down> <nop>
vnoremap <Right> <nop>
vnoremap <Left> <nop>
vnoremap <Up> <nop>
vnoremap <Down> <nop>
" Tabs bindings
2021-02-01 10:26:29 +01:00
" TODO improve on these
2020-08-08 20:27:01 +02:00
" Create tab
nnoremap <silent> <leader>o :tabnew<CR>
" Close current tab
nnoremap <silent> <leader>p :tabclose<CR>
" Go to next tab
nnoremap <silent> <leader>i :tabnext<CR>
" Go to previous tab
nnoremap <silent> <leader>u :tabprevious<CR>
2021-02-01 10:26:29 +01:00
" This function allows me to switch between a dark & light theme. I mainly use
" the dark theme, but when I'm sitting outside, the light theme can be much
" more readable
2020-08-08 20:27:01 +02:00
function! ColorschemeToggle()
if g:colors_name == 'flattened_dark'
colorscheme flattened_light
else
colorscheme flattened_dark
endif
endfunction
nnoremap <silent> <leader>c :call ColorschemeToggle()<CR>
2021-02-01 10:26:29 +01:00
" As I'm constantly tweaking my config, I use keybindings to easily open &
" source it without leaving my session
2020-08-08 20:27:01 +02:00
nnoremap <silent> <leader>vs :source $MYVIMRC<CR>
2021-02-01 10:26:29 +01:00
" Opens CtrlP in my config directory
2020-08-08 20:27:01 +02:00
nnoremap <silent> <leader>ve :split<CR>:exec 'CtrlP ' . fnamemodify($MYVIMRC, ':h')<CR>
2020-08-09 07:49:51 +02:00
2021-02-01 10:26:29 +01:00
" This was probably one of the best ideas I found (it wasn't my original idea).
" By remapping Esc to jk, I could switch between modes without moving my hands.
" This improved my speed by much more than I was expecting, and helped with not
" straining my hands as much.
2020-08-09 07:49:51 +02:00
inoremap jk <Esc>
inoremap <Esc> <nop>
2020-08-20 14:29:03 +02:00
2021-02-01 10:26:29 +01:00
" I use this binding to quickly switch between two files.
2020-08-20 14:29:03 +02:00
nnoremap <leader>a <C-^>
" Terminal keybindings
" Use jk in terminal as well
tnoremap <silent> jk <C-\><C-n>
" Open terminal in different locations
nnoremap <silent> <leader>rr :terminal<CR>
nnoremap <silent> <leader>rh :vsp<CR>:wincmd h<CR>:term<CR>
nnoremap <silent> <leader>rl :vsp<CR>:term<CR>
nnoremap <silent> <leader>rk :sp<CR>:wincmd k<CR>:term<CR>
nnoremap <silent> <leader>rj :sp<CR>:term<CR>