-
Notifications
You must be signed in to change notification settings - Fork 127
/
mappings.vim
155 lines (119 loc) · 3.74 KB
/
mappings.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
" ----------------------------------------
" Mappings
" ----------------------------------------
" Set leader to ,
" Note: This line MUST come before any <leader> mappings
let mapleader=','
let maplocalleader = ' '
" -----------------------
" Unmapped While Learning
" -----------------------
" No-op ^ and $ while learning H and L
noremap ^ <nop>
noremap $ <nop>
nnoremap <leader>sc <nop>
" ---------------
" Regular Mappings
" ---------------
" Use ; for : in normal and visual mode, less keystrokes
nnoremap ; :
vnoremap ; :
" Quit with one key
nnoremap <M-x> :qa<cr>
" Yank entire buffer with gy
nnoremap gy :0,$ y<cr>
" Make Y behave like other capital commands.
" Hat-tip http://vimbits.com/bits/11
nnoremap Y y$
" Just to beginning and end of lines easier. From http://vimbits.com/bits/16
noremap H ^
noremap L $
" Create newlines without entering insert mode
nnoremap go m`o<Esc>``
nnoremap gO m`O<Esc>``
" remap U to <C-r> for easier redo
" from http://vimbits.com/bits/356
nnoremap U <C-r>
" Swap implementations of ` and ' jump to markers
" By default, ' jumps to the marked line, ` jumps to the marked line and
" column, so swap them
nnoremap ' `
nnoremap ` '
" ---------------
" Window Movement
" ---------------
" Move windows directionally
nnoremap <silent> <M-h> :wincmd h<CR>
nnoremap <silent> <M-j> :wincmd j<CR>
nnoremap <silent> <M-k> :wincmd k<CR>
nnoremap <silent> <M-l> :wincmd l<CR>
" Swap Windows
nnoremap <silent> gx :wincmd x<CR>
" ---------------
" Modifer Mappings
" ---------------
" Make line completion easier.
inoremap <C-l> <C-x><C-l>
" ---------------
" Leader Mappings
" ---------------
" Clear search
noremap <silent><leader>/ :nohls<CR>
" Quickly switch to last buffer
nnoremap <leader>, :e#<CR>
" Surround the commented line with lines.
"
" Example:
" # Test 123
" becomes
" # --------
" # Test 123
" # --------
nnoremap <silent> <leader>cul :normal "lyy"lpwvLr-^"lyyk"lP<cr>
" Split window vertically or horizontally *and* switch to the new split!
nnoremap <silent> <leader>hs :split<Bar>:wincmd j<CR>:wincmd =<CR>
nnoremap <silent> <leader>vs :vsplit<Bar>:wincmd l<CR>:wincmd =<CR>
" Close the current window
nnoremap <silent> <M-w> :close<CR>
" Plug mappings here because they don't work in plug.vim
nnoremap <leader>pi :PlugInstall<CR>
nnoremap <leader>pu :PlugUpdate<CR>
nnoremap <leader>pc :PlugClean<CR>
" ---------------
" Typo Fixes
" ---------------
" Disable the ever-annoying Ex mode shortcut key. Type visual my ass. Instead,
" make Q repeat the last macro instead. *hat tip* http://vimbits.com/bits/263
nnoremap Q @@
" Removes doc lookup mapping because it's easy to fat finger and never useful.
nnoremap K k
vnoremap K k
" Toggle paste mode with F5
nnoremap <silent> <F5> :set paste!<CR>
" Paste and select pasted
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" Insert date
iabbrev ddate <C-R>=strftime("%Y-%m-%d")<CR>
" Insert ellipsis
iabbrev '..ell' …
" copy current file name (relative/absolute) to system clipboard
" from http://stackoverflow.com/a/17096082/22423
if has('mac') || has('gui_macvim') || has('gui_mac')
" relative path (src/foo.txt)
nnoremap <silent> <leader>yp :let @*=expand("%")<CR>
" absolute path (/something/src/foo.txt)
nnoremap <silent> <leader>yP :let @*=expand("%:p")<CR>
" filename (foo.txt)
nnoremap <silent> <leader>yf :let @*=expand("%:t")<CR>
" directory name (/something/src)
nnoremap <silent> <leader>yd :let @*=expand("%:p:h")<CR>
endif
" ------------
" Tab Movement
" ------------
nnoremap <silent> <M-1> :tabnext 1<CR>
nnoremap <silent> <M-2> :tabnext 2<CR>
nnoremap <silent> <M-3> :tabnext 3<CR>
nnoremap <silent> <M-4> :tabnext 4<CR>
nnoremap <silent> <M-5> :tabnext 5<CR>
nnoremap <silent> <M-.> :tabprevious<CR>