Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 261 lines (224 sloc) 7.981 kB
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
1 " ----------------------------------------------------------------------------------------------------
2 " @file map.vim
3 " @description Keyboard mappings
4 " @author Rémi Prévost (remi, exomel.com)
5 " vim: fdm=marker noet ts=4 sts=4 sw=4
6 " ----------------------------------------------------------------------------------------------------
7
7e5a21d @remiprev Add <Leader>d and <Leader>e mappings
authored
8 " Remove support for regular system-wide bindings {{{
5379113 @remiprev Remove support for <Up>, <Down>, <Left> and <Right>
authored
9 " ----------------------------------------------------------------------------------------------------
10 nnoremap <Up> <Esc>
11 vnoremap <Up> <NOP>
12 inoremap <Up> <NOP>
13 nnoremap <Down> <Esc>
14 vnoremap <Down> <NOP>
15 inoremap <Down> <NOP>
16 nnoremap <Left> <Esc>
17 vnoremap <Left> <NOP>
18 inoremap <Left> <NOP>
19 nnoremap <Right> <Esc>
20 vnoremap <Right> <NOP>
21 inoremap <Right> <NOP>
22 " }}}
23
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
24 " Strip HTML tags in selected line {{{
25 " ----------------------------------------------------------------------------------------------------
26 vnoremap <Leader>h :s/<\/*\([a-z][a-z0-9]*\)[^>]*>//g<CR><Esc>:silent noh<Bar>echo<CR>
27 " }}}
28
29 " Easy fold navigation {{{
30 " ----------------------------------------------------------------------------------------------------
427a784 @remiprev Disable ⌘-J and ⌘-K old mappings
authored
31 noremap <silent> <D-J> <Nop>
32 noremap <silent> <D-K> <Nop>
0175e33 @remiprev Remove ⌘-style fold mappgins
authored
33 noremap <silent> ∆ zj
34 noremap <silent> ˚ zk
35 noremap <silent>  za
36 noremap <silent> <S-CR> zMzo
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
37 " }}}
38
6054dd2 @remiprev Change mappings for <D-j> and <D-k>
authored
39 " Easy lines navigation {{{
40 " ----------------------------------------------------------------------------------------------------
41 noremap <silent> <D-j> gj
42 noremap <silent> <D-k> gk
43 " }}}
44
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
45 " Easy new lines {{{
46 " ----------------------------------------------------------------------------------------------------
98b02a5 @remiprev Keep cursor position when inserting blank lines with <Alt-O>
authored
47 noremap <silent> ø mo<Esc>o<Esc>k`o
48 noremap <silent> Ø mo<Esc>O<Esc>j`o
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
49 map K <Esc>i<CR><Esc><Esc>
50 " }}}
51
52 " Always go to the mark’s line and column {{{
53 " ----------------------------------------------------------------------------------------------------
54 noremap ' `
55 vnoremap ' `
56 noremap g' g`
57 vnoremap g' g`
58 " }}}
59
60 " Remap ^ caracters {{{
61 " ----------------------------------------------------------------------------------------------------
62 noremap â ^a
63 noremap î ^i
64 noremap ô ^o
65 " }}}
66
67 " Add a new '/' text object {{{
68 " ----------------------------------------------------------------------------------------------------
69 onoremap i/ :normal T/vt/<CR>
70 vnoremap i/ t/oT/
e071f0f @remiprev Add ; text object
authored
71 onoremap a/ :normal F/vf/<CR>
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
72 vnoremap a/ f/oF/
e071f0f @remiprev Add ; text object
authored
73 onoremap i; :normal T:lvt;<CR>
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
74 " }}}
75
76 " We often press 'Shift' when we should not {{{
77 " ----------------------------------------------------------------------------------------------------
db3e70d @remiprev Add some useful typo-commands
authored
78 command! -nargs=* -complete=file Q q <args>
79 command! -nargs=* -complete=file W w <args>
80 command! -nargs=* -complete=file Wq wq <args>
81 command! -nargs=* -complete=file WQ wq <args>
82 command! -nargs=* -complete=file E e <args>
83 command! -nargs=* -complete=file Cd cd <args>
84 command! -nargs=* -complete=file CD cd <args>
aa67f44 @remiprev Add custom Set alias
authored
85 command! -nargs=* -complete=option Set set <args>
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
86 " }}}
87
88 " Let's remap Enter and Backspace {{{
89 " ----------------------------------------------------------------------------------------------------
ecff054 @remiprev Clean mappings file
authored
90 vnoremap
91 <NOP>
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
92 vnoremap <BS> dk$
93 " }}}
94
95 " Easy split navigation {{{
96 " ----------------------------------------------------------------------------------------------------
97 noremap <C-H> <C-W>h
98 noremap <C-L> <C-W>l
99 noremap <C-K> <C-W>k
100 noremap <C-J> <C-W>j
101 " }}}
102
103 " Because 'CTRL-T' is easier to type on a canadian keyboard {{{
104 " ----------------------------------------------------------------------------------------------------
105 noremap <C-T> <C-]>
106 " }}}
107
108 " Easy line moving {{{
109 " ----------------------------------------------------------------------------------------------------
110 noremap <C-Up> ddkkp
111 noremap <C-Down> ddp
112 " }}}
113
114 " Easy tab navigation {{{
6d92dd4 @remiprev No more tab navigation
authored
115 " ----------------------------------------------------------------------------------------------------
116 "noremap <S-C-Tab> :tabprevious<CR>
117 "inoremap <S-C-Tab> <Esc>:tabprevious<CR>
118 "vnoremap <S-C-Tab> <Esc>:tabprevious<CR>
119 "noremap <C-Tab> :tabnext<CR>
120 "inoremap <C-Tab> <Esc>:tabnext<CR>
121 "vnoremap <C-Tab> <Esc>:tabnext<CR>
122 "noremap <M-D-Left> <Esc>:tabprevious<CR>
123 "noremap <M-D-Right> <Esc>:tabnext<CR>
124
125 noremap <S-C-Tab> :bprevious<CR>
126 inoremap <S-C-Tab> <Esc>:bprevious<CR>
127 vnoremap <S-C-Tab> <Esc>:bprevious<CR>
128 noremap <C-Tab> :bnext<CR>
129 inoremap <C-Tab> <Esc>:bnext<CR>
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
130 vnoremap <C-Tab> <Esc>:bnext<CR>
131
132 " }}}
133
134 " Reload the current file {{{
8dd4375 @remiprev Restore <C-l> and use <C-]> to go to previous jump
authored
135 " ----------------------------------------------------------------------------------------------------
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
136 "noremap <D-r> :e<CR>
137 " }}}
138
139 " Function keys {{{
140 " ----------------------------------------------------------------------------------------------------
4a46b7c @remiprev <F8> now toggles soft text wrapping
authored
141 noremap <F9> :set list!<Bar>set list?<CR>
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
142 noremap <F8> :set wrap! linebreak! nolist!<Bar>set wrap?<CR>
143 noremap <F10> :set paste!<Bar>set paste?<CR>
144 noremap <F11> :set expandtab!<Bar>set expandtab?<CR>
145 " }}}
146
147 " Insert current date {{{
148 " ----------------------------------------------------------------------------------------------------
149 " format YYYYMMDD (eg. 20100105)
150 inoremap <D-d> <C-R>=strftime("%Y%m%d")<CR>
151 noremap ª cw<C-R>=strftime("%Y%m%d")<CR><Esc>b
152 " format ISO 8601 (eg. 2010-01-05T20:51:15-0500)
153 inoremap <D-D> <C-R>=strftime("%Y-%m-%dT%H:%M:%S%z")<CR>
154 noremap ˇ cw<C-R>=strftime("%Y-%m-%dT%H:%M:%S%z")<CR><Esc>b
155 " }}}
156
157 " Duplicate line {{{
158 " ----------------------------------------------------------------------------------------------------
159 noremap <D-d> m'yyP`'k
160 vnoremap <D-d> m'y'>p`'
161 " }}}
162
163 " Select only the text caracters in the current line {{{
164 " ----------------------------------------------------------------------------------------------------
165 noremap √ ^v$h
166 " }}}
167
168 " Easy indentation in visual mode {{{
169 " ----------------------------------------------------------------------------------------------------
170 vnoremap < <gv
171 vnoremap > >gv|
172 vnoremap <Tab> >gv|
8dd4375 @remiprev Restore <C-l> and use <C-]> to go to previous jump
authored
173 vnoremap <S-Tab> <gv
22d9e83 @remiprev <Tab> and <S-Tab> in normal mode keeps the current cursor position
authored
174 nnoremap  <C-i>
175 nnoremap <Tab> mzV>`zl
b520a5e @remiprev Refactor file structure (for easier maintenance!)
authored
176 nnoremap <S-Tab> mzV<`zh
177 " }}}
178
179 " Clear search-highlighted terms {{{
180 " ----------------------------------------------------------------------------------------------------
181 noremap <silent> <Space> :silent noh<Bar>echo<CR>
aadede0 @remiprev Add ;zo and ;zc mappings
authored
182 " }}}
183
184 inoremap ;zo {{{<Esc>
f9b1000 @remiprev Add a few handy mappings
authored
185 inoremap ;zc }}}<Esc>
186
187 " Always use magic regexes {{{
188 " ----------------------------------------------------------------------------------------------------
189 nnoremap / /\v
190 vnoremap / /\v
191 " }}}
192
193 " Prevent accidental uses of <F1> {{{
194 " ----------------------------------------------------------------------------------------------------
195 inoremap <F1> <ESC>
196 nnoremap <F1> <ESC>
197 vnoremap <F1> <ESC>
198 " }}}
1575c90 @remiprev Add split mappings.
authored
199
200 " Splits! {{{
7acba6b @remiprev Add zero-width help
authored
201 " ----------------------------------------------------------------------------------------------------
202 nnoremap <C-c> <C-W>c<CR>
203 " }}}
204
205 " Get help with zero-width {{{
206 " ----------------------------------------------------------------------------------------------------
207 function! ZeroWidth_help()
208 split ~/.vim/doc/zero_width.mkd
209 endfunction
1575c90 @remiprev Add split mappings.
authored
210 command! ZeroWidth call ZeroWidth_help()
41531a9 @remiprev Add ⌘+Shift+P to print the current word syntax styles
authored
211 " }}}
212
213 " Show syntax highlighting groups for word under cursor {{{
214 nmap <D-P> :call <SID>SynStack()<CR>
215 function! <SID>SynStack()
216 if !exists("*synstack")
217 return
218 endif
219 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
220 endfunc
9d6f7aa @remiprev Move “èè” mapping where it belongs
authored
221 " }}}
222
223 " Change the working directory to the current file directory {{{
224 noremap èè :lcd %:p:h<CR>
948e1ff @remiprev Add ToggleScratch command
authored
225 " }}}
226
227 " Toggle Scratch buffer {{{
228 " Credit: http://weblog.jamisbuck.org/2008/11/17/vim-follow-up
229 function! ToggleScratch()
230 if expand('%') == g:ScratchBufferName
231 quit
232 else
233 Sscratch
234 endif
235 endfunction
236
237 map <leader>x :call ToggleScratch()<CR>
0176e6f @remiprev Add Alt-4 to go to the end of the line, without the CR/LF
authored
238 " }}}
239
240 " Use Alt-4 to go to the end of the line, but not totally.{{{
241 noremap € $h
db08d93 @remiprev Let’s try not to use ESC anymore
authored
242 " }}}
243
244 " Let’s try not to use ESC anymore {{{
245 inoremap jj <Esc>
246 inoremap jk <Esc>
fa311d2 @remiprev Add tmux-like split panes navigation
authored
247 " }}}
248
249 " Tmux-like split panes navigation {{{
250 noremap <C-A>% :vsplit<CR><C-W>l
251 noremap <C-A>s :split<CR><C-W>j
252 noremap <C-A>h <C-W>h
253 noremap <C-A>l <C-W>l
254 noremap <C-A>k <C-W>k
255 noremap <C-A>j <C-W>j
bef4a46 @remiprev Add custom surround tags
authored
256 " }}}
257
258 let g:surround_45 = "#{\r}"
259 let g:surround_61 = "\"#{\r}\""
Something went wrong with that request. Please try again.