My vim configuration
git clone https://github.com/m-col/vim-misc
Files | Refs | Readme

-rw-r--r-- start/self/plugin/keybindings.vim


      1 "------------------------------------------------------------------"
      2 " Global keybindings                                               "
      3 "------------------------------------------------------------------"
      4 
      5 " reload current buffer
      6 "nnoremap <C-l> :e<CR>
      7 
      8 " toggle fold
      9 nnoremap <space> za
     10 
     11 " yank to end of line
     12 nnoremap Y y$
     13 
     14 " buffer navigation
     15 nnoremap <leader>b :ls<CR>:b<space>
     16 nnoremap <Leader>v :ls<CR>:vert sb<space>
     17 nnoremap <Leader>j :bnext<CR> 
     18 nnoremap <Leader>k :bprevious<CR>
     19 "nnoremap <Leader><BS> :w<CR>:Bdelete<CR>
     20 
     21 " move between tabs
     22 nnoremap <Leader>n gT
     23 nnoremap <Leader>m gt
     24 
     25 " indent selection
     26 vnoremap < <gv
     27 vnoremap > >gv
     28 
     29 " quitting and writing shortcuts
     30 nnoremap QQ :q<CR>
     31 nnoremap !Q :q!<CR>
     32 nnoremap QW :wq<CR>
     33 nnoremap :Q :q
     34 nnoremap :W :w
     35 
     36 " disable K man
     37 nnoremap K k
     38 
     39 " copy and paste system clipboard
     40 nmap <C-y> "+y
     41 nmap <C-y><C-y> ms0v$"+y`s
     42 vmap <C-y> "+y
     43 imap <C-y> <Esc>"+y
     44 if exists("$WAYLAND_DISPLAY")
     45     xmap "+y y:call system("wl-copy", @")\|echo '' <cr>
     46 endif
     47 
     48 " save read-only file with sudo trick
     49 cnoremap w!! w !sudo tee > /dev/null %
     50 
     51 " move between split views (these are configured by the vim-tmux plugin)
     52 " except for insert mode:
     53 "inoremap <silent> <C-H> <Esc>:TmuxNavigateLeft<cr>
     54 "inoremap <silent> <C-J> <Esc>:TmuxNavigateDown<cr>
     55 "inoremap <silent> <C-K> <Esc>:TmuxNavigateUp<cr>
     56 "inoremap <silent> <C-L> <Esc>:TmuxNavigateRight<cr>
     57 "inoremap <silent> <C-\> <Esc>:TmuxNavigatePrevious<cr>
     58 nnoremap <C-H> <C-W><C-H>
     59 nnoremap <C-J> <C-W><C-J>
     60 nnoremap <C-K> <C-W><C-K>
     61 nnoremap <C-L> <C-W><C-L>
     62 inoremap <C-H> <Esc><C-W><C-H>
     63 inoremap <C-J> <Esc><C-W><C-J>
     64 inoremap <C-K> <Esc><C-W><C-K>
     65 inoremap <C-L> <Esc><C-W><C-L>
     66 
     67 " move to start or end of line more easily
     68 nnoremap 0 ^
     69 nnoremap H 0
     70 nnoremap L $
     71 vnoremap H 0
     72 vnoremap L g_
     73 
     74 " resize splits
     75 nnoremap <silent> <Up> :res -1<CR>
     76 nnoremap <silent> <Down> :res +1<CR>
     77 nnoremap <silent> <Left> :vertical resize -5<CR>
     78 nnoremap <silent> <Right> :vertical resize +5<CR>
     79 
     80 " toggle search highlight
     81 nnoremap <Leader>h :set hlsearch!<CR>
     82 
     83 " shortcut to fix lines
     84 nnoremap <leader>p gqip
     85 
     86 " shortcut to vert split
     87 nnoremap vs :vsp<CR>
     88 
     89 " toggle spell checking
     90 "nnoremap <leader>S :setlocal spell! spelllang=en_gb spell?<CR>:echo "zg to add new word"<CR>
     91 
     92 " toggle [ ] tick box on current line with ctrl-space
     93 "function! ToggleTodo()
     94 "    let l:line = getline('.')
     95 "    if match(l:line, '\[x\]') != -1
     96 "	let l:line = substitute(l:line, '\[x\]', '\[ \]', '')
     97 "	call setline('.', l:line)
     98 "    elseif match(l:line, '\[ \]') != -1
     99 "	let l:line = substitute(l:line, '\[ \]', '\[x\]', '')
    100 "	call setline('.', l:line)
    101 "    endif
    102 "endfunction
    103 "nnoremap <silent> <C-@> :call ToggleTodo()<CR>
    104 
    105 " quickfix navigation
    106 "nnoremap <localleader>cn :cn<CR>
    107 "nnoremap <localleader>cp :cp<CR>
    108 
    109 " netrw
    110 nmap <C-n> :Explore<CR>
    111 
    112 " bind number keys to scroll so i can use foot terminal's alt scrolling
    113 map <Down> j
    114 map <Up> k
    115 
    116 " bind scroll to move cursor up and down
    117 nnoremap <ScrollWheelDown> <Down>
    118 nnoremap <ScrollWheelUp> <Up>
    119 inoremap <ScrollWheelDown> <Down>
    120 inoremap <ScrollWheelUp> <Up>
    121 vnoremap <ScrollWheelDown> <Down>
    122 vnoremap <ScrollWheelUp> <Up>
    123 
    124 " ALE
    125 "nmap <silent> <C-S-f> <Plug>(ale_fix)
    126 nmap <silent> <C-i> <Plug>(ale_find_references)
    127 nmap <silent> <C-]> <Plug>(ale_go_to_definition)
    128 nmap <silent> <C-f> <Plug>(ale_fix)
    129 nmap <silent> <leader>r :ALERename \| w<CR>
    130 
    131 " telescope
    132 nnoremap <silent> <C-p> :Telescope git_files<CR>
    133 "nnoremap <silent> <C-o> :Telescope tags<CR>  " isn't working
    134 
    135 " CtrlP (in addition to the default Ctrl-p binding)
    136 nnoremap <silent> <C-o> :CtrlPTag<CR>
    137 
    138 " marks
    139 nnoremap mm mM
    140 nnoremap `m `M
    141 
    142 " buffer write close
    143 nnoremap <silent> <leader><BS> :write<CR>:BuffCls<CR>
    144 
    145 " pg_format visual blocks with Ctrl-f
    146 "vmap <C-f> <ESC>:'<,'>! pg_format --comma-break --redundant-parenthesis --format-type<CR>
    147 
    148 "buffer close window
    149 autocmd FileType ale-preview-selection nnoremap <buffer> <Esc> :close<CR>
    150