diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-08-24 11:45:12 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-08-24 11:58:23 -0500 |
commit | 0a58dd8ca4d962998b077da24b3985988b3f3092 (patch) | |
tree | b930dcaee403de24c9c0743b41953a848b031515 /vim/ftplugin/perl.vim | |
parent | 1945fa39df25aeb85c399e11a0cab97a575beeeb (diff) | |
download | conf-0a58dd8ca4d962998b077da24b3985988b3f3092.tar.gz conf-0a58dd8ca4d962998b077da24b3985988b3f3092.zip |
mapping to un-postfix perl expressions (inspired by xdg)
Diffstat (limited to 'vim/ftplugin/perl.vim')
-rw-r--r-- | vim/ftplugin/perl.vim | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index ec994ec..b86d4e2 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -21,3 +21,27 @@ nmap <buffer> <silent>gf :exe v:count . 'find ' . substitute(expand('<cfile>'), " XXX: <cfile> is wrong here, need to do something like i do for Help "vmap <buffer> <silent>gf :exe v:count . 'find ' . substitute(expand('<cfile>'), '::', '/', 'g') . '.pm'<CR> nnoremap <buffer> t :FufCoverageFile lib/<CR> + +function! s:unpostfix() + let postop_pattern = '\<\(if\|unless\|while\|until\|for\)\>' + let indent = repeat(' ', &sw) + + if getline('.') =~ postop_pattern + normal kJ + else + normal J + endif + + " XXX this doesn't insert newlines properly + " let line = getline('.') + " let line = substitute( + " \line, + " \'\(\s*\)\(.*\) ' . postop_pattern . ' \(.*\);', + " \'\1\3 (\4) {\1' . indent . '\2;\n\1}', + " \'' + " \) + " call setline('.', line) + exe 's/\(\s*\)\(.*\) ' . postop_pattern . ' \(.*\);/\1\3 (\4) {\r\1' . indent . '\2;\r\1}/' +endfunction + +map <buffer> <silent> <Leader>i :call <SID>unpostfix()<CR> |