Created
October 28, 2011 08:45
-
-
Save kearnh/1321887 to your computer and use it in GitHub Desktop.
Custom Vim mappings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ----------------------------------------------------------------------------- | |
" -- Navigation | |
" Find start of next number | |
noremap <silent> <c-f> /\<\d<CR> | |
"noremap <silent> <c-t> ?\<\d<CR> | |
" open empty tab | |
noremap <silent> <c-t> :tabe<CR> | |
" tab navigation | |
noremap <c-l> gt | |
noremap <c-h> gT | |
" Movement in command line mode | |
cnoremap <c-j> <Down> | |
cnoremap <c-k> <Up> | |
cnoremap <c-h> <Left> | |
cnoremap <c-l> <Right> | |
cnoremap <c-a> <c-b> | |
" navigating wrapped lines | |
nnoremap k gk | |
nnoremap j gj | |
nnoremap gk k | |
nnoremap gj j | |
" Overide gf to open file in a new tab | |
map <silent> gf :tabf <cfile><CR> | |
" like emacs when in insert mode (bleh) | |
imap <c-a> <c-o>^ | |
imap <c-e> <c-o>$ | |
imap <c-u> <c-o>cc | |
" Open tag in new tab | |
noremap g] :vs<CR><C-w>Tg]zt | |
" Open tag in vertical split (use <c-w><c-]> for horizontal split) | |
map <C-\> :vsp <CR>:exec("tag ".expand("<cword>"))<CR> | |
" :tjump made default | |
noremap <c-]> g<c-]>zt | |
" move paragraph, but on the line not after/before it | |
noremap { k{j | |
noremap } j}k | |
"noremap [] ][ | |
"noremap ][ [] | |
" Navigate quickfix list | |
noremap <silent> <leader>] :cn<CR>zz | |
noremap <silent> <leader>[ :cp<CR>zz | |
" ----------------------------------------------------------------------------- | |
" -- Windows Specific | |
" execute file (using Windows association for the file) | |
nmap <silent> <f9> :silent ! start "1" "%:p"<CR> | |
" Put Windows clipboard at cursor | |
noremap <silent> zp "+[p | |
" load file into ghci | |
"nmap <silent> <leader>gi :silent ! start "1" ghci "%:p"<CR> | |
" source file into tcl interpreter | |
nmap <silent> <leader>ti :silent ! start "1" C:\User\Tcl\runtime\ptcl-1602\bin\ptclwin86t.exe C:\User\Tcl\tcl85\Debug\bin\tkcon.tcl -rcfile u:\.tkconrc "%:p"<CR> | |
" ----------------------------------------------------------------------------- | |
" toggle between number and relative number on | |
"nnoremap <leader>l :call ToggleRelativeAbsoluteNumber()<CR> | |
function! ToggleRelativeAbsoluteNumber() | |
if &number | |
set relativenumber | |
else | |
set number | |
endif | |
endfunction | |
" yank onto clipboard as well | |
vnoremap y ygv"+y | |
" Center screen after incremental searches | |
noremap n nzz | |
noremap N Nzz | |
noremap * *zz | |
noremap # #zz | |
noremap g* g*zz | |
noremap g# g#zz | |
" Top of screen after... | |
noremap ]] ]]zt | |
" Ctrl-j/k inserts blank line below/above | |
"nnoremap <silent><C-j> :set paste<CR>m`o<Esc>``:set nopaste<CR> | |
"nnoremap <silent><C-k> :set paste<CR>m`O<Esc>``:set nopaste<CR> | |
nnoremap <silent><C-J> :set paste<CR>m`:noautocmd norm o<CR>``:set nopaste<CR> | |
nnoremap <silent><C-K> :set paste<CR>m`:noautocmd norm O<CR>``:set nopaste<CR> | |
" Replace word under cursor with " register | |
nmap <silent> S :let @x=@"<CR>"_diw"xP | |
" move tabs | |
python << ENDPY | |
def tabMovePlus1(): | |
tot = int(vim.eval('tabpagenr("$")')) | |
t = int(vim.eval('tabpagenr()')) | |
vim.command('tabm %d' % (t % tot)) | |
def tabMoveMinus1(): | |
tot = int(vim.eval('tabpagenr("$")')) | |
t = int(vim.eval('tabpagenr()')) | |
vim.command('tabm %d' % ((t-2) % tot)) | |
ENDPY | |
noremap <silent> gh :py tabMoveMinus1()<CR> | |
noremap <silent> gl :py tabMovePlus1()<CR> | |
" line completion | |
imap <c-l> <Esc>l"_C<c-x><c-l> | |
" write file | |
noremap <silent> s :w<CR> | |
" copy selection | |
vmap <c-c> "+y | |
" Select coloumn (works best for aligned words) | |
" doesn't work :P | |
"noremap <silent> <leader>cv viw<ESC>:let @l=virtcol(".")<CR>}k:call cursor(line("."),@l)<CR>bmb{:call GotoTopPara()<CR>:call cursor(line("."),@l-1)<CR><C-V>`b | |
" Quickfix window bigger | |
nmap <leader>cw :cw<CR><C-W>j<C-W>L:set nowrap<CR> | |
" Swap J and gJ | |
" nnoremap J gJ | |
" nnoremap gJ J | |
vnoremap J gJ | |
vnoremap gJ J | |
" 'Template' replace | |
map <leader>rp dwjvip:s/ZZ/\=@"/g<CR> | |
" shortcut :cn | |
" now using other quickfix window | |
function! Crotate() | |
try | |
lnext | |
catch /.*/ | |
lfirst | |
endtry | |
endfunction | |
nmap <silent> <leader>l :call Crotate()<CR>zz | |
" trim trailing whitespace | |
"noremap <silent> <leader>tt :%s/\s\+$//e<CR> | |
" quick adjust textwidth | |
map <silent> <leader>ww :setlocal textwidth=1024<CR> | |
map <silent> <leader>ws :setlocal textwidth=80<CR> | |
" for surround plugin | |
nmap ( ys$)% | |
" open vimrc in new tab | |
map <Leader>rc :tabe $MYVIMRC<CR> | |
" Tagbar | |
map <silent> <Leader>tl :TagbarToggle<CR> | |
" Easy Motion | |
map <silent> <leader>f :call EasyMotionF(0,0)<CR> | |
map <silent> <leader>d :call EasyMotionF(0,1)<CR> | |
" Fuzzyfinder | |
"nmap <silent> - :FuzzyFinderFileWithFullCwd<CR> | |
"nmap <silent> <C-_> :FuzzyFinderTag<CR> | |
"nmap <silent> _ :FuzzyFinderBuffer<CR> | |
"nmap <silent> M :FuzzyFinderMruFile<CR> | |
" Lusty Explorer / Juggler | |
"nmap <silent> <Leader>lf :LustyFilesystemExplorer<CR> | |
nmap <silent> - :LustyFilesystemExplorerFromHere<CR> | |
nmap <silent> _ :LustyBufferExplorer<CR> | |
"nmap <silent> <Leader>lg :LustyBufferGrep<CR> | |
"nmap <silent> <Leader>lj :LustyJuggler<CR> | |
" MRU | |
nmap <silent> M :MRU<CR> | |
" TFS Diff | |
let g:tfs_diff_on=0 | |
function! TFSDiffOn() | |
if g:tfs_diff_on==0 | |
let f = @% | |
let ft = &ft | |
vne | |
exe '.!tf view ' . f | |
exe 'set ft=' . ft | |
exe 'diffthis' | |
norm h | |
exe 'diffthis' | |
let g:tfs_diff_on=1 | |
endif | |
endfunction | |
function! TFSDiffOff() | |
if g:tfs_diff_on==1 | |
diffoff! | |
norm l | |
exe 'q!' | |
set nowrap | |
let g:tfs_diff_on=0 | |
endif | |
endfunction | |
function! TFSDiff() | |
if g:tfs_diff_on==0 | |
call TFSDiffOn() | |
else | |
call TFSDiffOff() | |
endif | |
endfunction | |
nmap <silent> <leader>cd :call TFSDiff()<CR> | |
" pycalc | |
nmap <silent> <C-Space> <Plug>PyCalcDefaultNormal | |
vmap <silent> <C-Space> :py pycalc(vis=True)<CR> | |
nmap <silent> <leader>po :py pycalc('o')<CR> | |
nmap <silent> <leader>pp :py pycalc('p')<CR> | |
nmap <silent> <leader>pi :py pycalc('i')<CR> | |
nmap <silent> <leader>p0 :py pycalc('0')<CR> | |
nmap <silent> <leader>pr :py eval_current_line('0"_D')<CR> | |
nmap <silent> <leader>pe :py eval_current_line('o')<CR> | |
nmap <silent> <S-Space> :py last_pycalc_cmd()<CR> | |
" view last tab | |
let g:lasttab = 1 | |
nmap <silent> L :exe "tabn ".g:lasttab<CR> | |
au TabLeave * let g:lasttab = tabpagenr() | |
" Tagmadebug | |
nmap <F7> <Plug>TagmaDebugStartStop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment