forked from gpoulter/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mappings.vim
136 lines (105 loc) · 3.47 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
" Map semicolon to start command-line mode just like colon
nnoremap ; :
vnoremap ; :
" Map apostrophe to repeate f/F/t/T since we took semicolon
nnoremap ' ;
" Use comma as <leader> key
let mapleader = ","
" Map double-leader to exit insert mode
imap <Leader><Leader> <Esc>
" Fix visual paste to not overwrite default register with deleted text
vnoremap p "_dP
" Map single-char deletes to null register instead of overwriting last yank
noremap x "_x
" Map Q to format selection instead of ex-mode
noremap Q gq
" Make Y consistent with C and D by yanking to end
nnoremap Y y$
" Make down/up behave as expected with lines of different length
" inoremap <Down> <C-o>g<Down>
" inoremap <Up> <C-o>g<Up>
" Map return to break line after character
nnoremap <CR> a<CR><Esc>
" Map key to toggle search highlighting
nmap <silent> <leader>h :silent :set hlsearch!<CR>
" Map key to toggle showing whitespace characters
nmap <silent> <leader>s :set nolist!<CR>
" Map key to toggle line numbers
nmap <silent> <leader># :silent :set number!<CR>
" Map keys to scroll viewport and take cursor with it
nnoremap <C-e> 3<C-e>3<Down>
nnoremap <C-y> 3<C-y>3<Up>
" Make insert-mode key to clear highlight and redraw
inoremap <C-l> <C-o>:noh<CR><C-o>:redraw<CR>
" Map normal-mode key to clear highlight and redraw
nnoremap \ :noh<CR>:redraw<CR>
" Map key to start NERDTree
nnoremap <Leader>d :NERDTreeToggle<CR>
" Map key to start bufexplorer
nnoremap <leader>x :BufExplorer<cr>
" Map key to do CommandT TextMate-style finder
nnoremap <leader>t :CommandT<CR>
" Map key to do CommandT buffer finder
nnoremap <leader>f :CommandTBuffer<CR>
" Map key to use Gundo
nnoremap <F4> :GundoToggle<CR>
" Map key to replace word under cursor
nnoremap <leader>e :%s/\<<C-r><C-w>\>//gcI<Left><Left><Left><Left>
" Map key to replace yanked text in selection
vnoremap <leader>e :s/\<<C-r>"\>//gcI<Left><Left><Left><Left>
" Toggle relative numbers
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <Leader>n :call NumberToggle()<CR>
autocmd FocusLost * :set number
autocmd FocusGained * :set relativenumber
autocmd InsertEnter * :set number
autocmd InsertLeave * :set relativenumber
" Map keys for quick window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Map arrow keys for quick window navigation
map <M-Left> <C-w><Left>
map <M-Down> <C-w><Down>
map <M-Up> <C-w><Up>
map <M-Right> <C-w><Right>
" Map key to change tabs
nmap <Tab> gt
nmap <S-Tab> gT
" Map keys to quick indent like textmate
nmap <M-[> <<
nmap <M-]> >>
vmap <M-[> <gv
vmap <M-]> >gv
" Map key for Session Save
nmap SS <ESC>:mksession! ~/.vim/session.vim<CR>
" Map key for Session Save & Quit
nmap SQ <ESC>:mksession! ~/.vim/session.vim<CR>:wqa<CR>
" Map key for Session Restore
nmap SR <ESC>:source ~/.vim/session.vim<CR>
" Map key to open URL under cursor in chrome
nnoremap <leader>w :silent !google-chrome <C-R>=escape("<C-R><C-F>", "#?&;\|%")<CR><CR>
" Go to defn of tag under the cursor, forcing noignorecase
fun! MatchCaseTag()
let ignorecase = &ignorecase
set noignorecase
try
execute 'tjump ' . expand('<cword>')
finally
let &ignorecase = ignorecase
endtry
endfun
nnoremap <silent> <C-]> :call MatchCaseTag()<CR>
nnoremap <silent> <leader>c :!ctags -R . &<CR>
" Map key to make vim convenient on Colemak (set lmap)
nmap <leader>C :set langmap=jekn;eknj,JEKN;EKNJ<CR>
nmap <leader>Q :set langmap=<CR>
" Map auto complete
inoremap <Nul> <C-x><C-o>