~alexdavid/dotfiles

ref: e41da60478508d45b875ef7aa13ebb77d2fa90fb dotfiles/nvim/shortcuts.vim -rw-r--r-- 4.1 KiB
e41da604 — Alex David Add mpd config 1 year, 7 months ago
                                                                                
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
let mapleader = "\<space>"

" Tab management
nmap <silent> <leader>, :tabprevious<CR>
nmap <silent> <leader>. :tabnext<CR>
nmap <silent> <leader>t :tabnew<CR>
nmap <silent> <leader>< :exec 'silent! tabm ' . (tabpagenr()-2)<CR>
nmap <silent> <leader>> :exec 'silent! tabm ' . tabpagenr()<CR>

" Buffer/Split management
nmap <silent> <leader>s :split<CR>
nmap <silent> <leader>v :vsplit<CR>
nmap <silent> <leader>S :new<CR>
nmap <silent> <leader>V :vnew<CR>
nmap <silent> <leader>x :bd<CR>

" Function Resize - resizes split panes like tmux does:
" When focus is on the last pane it reverses resizing
fun! Resize(direction, scalar, notLastCommand, lastCommand)
  let startWinnr = winnr()
  exec "normal! " . a:direction
  if winnr() == startWinnr
    " We are on the last pane use lastCommand
    exec "normal! " . a:scalar . "" . a:lastCommand
  else
    exec startWinnr . "wincmd w"
    " We are not on the last pane use notLastCommand
    exec "normal! " . a:scalar . "" . a:notLastCommand
  endif
endfun

nmap <silent> <leader>h :call Resize('l', 1, '<', '>')<CR>
nmap <silent> <leader>l :call Resize('l', 1, '>', '<')<CR>
nmap <silent> <leader>j :call Resize('j', 1, '+', '-')<CR>
nmap <silent> <leader>k :call Resize('j', 1, '-', '+')<CR>

nmap <silent> <leader>H :call Resize('l', 10, '<', '>')<CR>
nmap <silent> <leader>L :call Resize('l', 10, '>', '<')<CR>
nmap <silent> <leader>J :call Resize('j', 10, '+', '-')<CR>
nmap <silent> <leader>K :call Resize('j', 10, '-', '+')<CR>

function! s:moveToPane(direction)
  let oldnr = winnr()
  execute 'wincmd ' . a:direction
  if oldnr == winnr()
    call system('select-pane ' . a:direction)
  endif
endfunction

command! MoveToLeft call s:moveToPane('h')
command! MoveToDown call s:moveToPane('j')
command! MoveToUp call s:moveToPane('k')
command! MoveToRight call s:moveToPane('l')
nnoremap <silent> <C-h> :MoveToLeft<cr>
nnoremap <silent> <C-j> :MoveToDown<cr>
nnoremap <silent> <C-k> :MoveToUp<cr>
nnoremap <silent> <C-l> :MoveToRight<cr>

map <ScrollWheelUp> <C-Y>
map <ScrollWheelDown> <C-E>

" Quickfix list mappings
autocmd BufReadPost quickfix nnoremap <buffer> s <C-W><CR><C-w>K
autocmd BufReadPost quickfix nnoremap <buffer> v <C-w><CR><C-w>H<C-W>b<C-W>J<C-W>t
autocmd BufReadPost quickfix nnoremap <buffer> t <C-w><CR><C-w>T
autocmd BufReadPost quickfix nnoremap <buffer> T <C-w><CR><C-w>TgT<C-W><C-W>

" Indenting
vmap < <gv
vmap > >gv
nmap > >>
nmap < <<

" Consistency
nmap Y y$

" Prevent paste in visual mode from copying text
xnoremap p pgvy
xnoremap P Pgvy

" visual sort
vmap s :sort<CR>

" Vim diff
fun! DiffUpdate()
  if &diff
    diffupdate
  endif
endfun
autocmd InsertLeave * call DiffUpdate()
noremap <leader>g :diffget \| diffupdate<CR>
noremap <leader>p :diffput \| diffupdate<CR>

" Git/fugitive shortcuts
nmap gd :Gdiff<CR>
nmap g3d :Gdiff HEAD<CR><C-W>l:Gdiff<CR>
nmap gs :Gministatus<CR>:wincmd K<CR>
nmap gc :Gcommit<CR>:set spell<CR><C-W>Ki
nmap git :!git<Space>
" Find merge conflicts
nmap gmc /\v^[<=>\|]{7}.*$<CR>

" Netrw directory of current file and position cursor over current file
map <silent> <leader>n :exec 'E ' . fnameescape(expand('%:h')) . ' \| call search("^' . escape(expand('%:t'), '\"') . '$", "cw")'<CR>

" Ctrl-p
let g:ctrlp_map = '<leader>o'

" TComment
let g:tcomment_mapleader1 = ''
let g:tcomment_opleader = ''
nnoremap <leader>/ :TComment<CR>
vnoremap <leader>/ :TCommentMaybeInline<CR>gv<ESC>

" Hide highlight
map <silent> <leader><space> :noh<CR>:match<CR>

" Mark line
nmap <silent> mm mm:execute 'match Search /\%'.line('.').'l/'<CR>

" Run q macro
nmap <silent> <leader>q @q
vmap <silent> <leader>q :norm! @q<CR>

" Use vim keybindings when running a command
nmap <silent> <leader>; q:i

" Tab number shortcuts
nnoremap <silent> <Leader>1        :tabnext 1<CR>
nnoremap <silent> <Leader>2        :tabnext 2<CR>
nnoremap <silent> <Leader>3        :tabnext 3<CR>
nnoremap <silent> <Leader>4        :tabnext 4<CR>
nnoremap <silent> <Leader>5        :tabnext 5<CR>
nnoremap <silent> <Leader>6        :tabnext 6<CR>
nnoremap <silent> <Leader>7        :tabnext 7<CR>
nnoremap <silent> <Leader>8        :tabnext 8<CR>
nnoremap <silent> <Leader>9        :tabnext 9<CR>