Vim 7.4 won't let us quit windows from a script.
[profile.git] / .vim / plugin / textformat.vim
1 " Text formatter plugin for Vim text editor
2 "
3 " This plugin provides commands and key mappings to quickly align and format
4 " text. Text can be aligned to either left or right margin or justified to
5 " both margins or centered. The text formatting commands in this plugin are
6 " a bit different from those integrated to Vim.
7 "
8 " Version:    0.9
9 " Maintainer: Teemu Likonen <tlikonen@iki.fi>
10 " GetLatestVimScripts: 0 0 :AutoInstall: textformat.vim
11 "
12 " {{{ Copyright and license
13 "
14 " Copyright (C) 2008 Teemu Likonen <tlikonen@iki.fi>
15 "
16 " This program is free software; you can redistribute it and/or modify
17 " it under the terms of the GNU General Public License as published by
18 " the Free Software Foundation; either version 2 of the License, or
19 " (at your option) any later version.
20 "
21 " This program is distributed in the hope that it will be useful,
22 " but WITHOUT ANY WARRANTY; without even the implied warranty of
23 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 " GNU General Public License for more details.
25 "
26 " You should have received a copy of the GNU General Public License
27 " along with this program; if not, write to the Free Software
28 " Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
29 "
30 " The License text in full:
31 "       http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
32 "
33 " }}}
34
35 command! -nargs=? -range AlignLeft <line1>,<line2>call textformat#Align_Command('left',<args>)
36 command! -nargs=? -range AlignRight <line1>,<line2>call textformat#Align_Command('right',<args>)
37 command! -nargs=? -range AlignJustify <line1>,<line2>call textformat#Align_Command('justify',<args>)
38 command! -nargs=? -range AlignCenter <line1>,<line2>call textformat#Align_Command('center',<args>)
39
40 nnoremap <silent> <Plug>Quick_Align_Paragraph_Left :call textformat#Quick_Align_Left()<CR>
41 nnoremap <silent> <Plug>Quick_Align_Paragraph_Right :call textformat#Quick_Align_Right()<CR>
42 nnoremap <silent> <Plug>Quick_Align_Paragraph_Justify :call textformat#Quick_Align_Justify()<CR>
43 nnoremap <silent> <Plug>Quick_Align_Paragraph_Center :call textformat#Quick_Align_Center()<CR>
44
45 vnoremap <silent> <Plug>Align_Range_Left :call textformat#Align_Command('left')<CR>
46 vnoremap <silent> <Plug>Align_Range_Right :call textformat#Align_Command('right')<CR>
47 vnoremap <silent> <Plug>Align_Range_Justify :call textformat#Align_Command('justify')<CR>
48 vnoremap <silent> <Plug>Align_Range_Center :call textformat#Align_Command('center')<CR>
49
50 function! s:Add_Mapping(mode, lhs, rhs)
51         if maparg(a:lhs, a:mode) == '' && !hasmapto(a:rhs, a:mode)
52                 execute a:mode.'map '.a:lhs.' '.a:rhs
53         endif
54 endfunction
55
56 call s:Add_Mapping('n', '<Leader>al', '<Plug>Quick_Align_Paragraph_Left')
57 call s:Add_Mapping('n', '<Leader>ar', '<Plug>Quick_Align_Paragraph_Right')
58 call s:Add_Mapping('n', '<Leader>aj', '<Plug>Quick_Align_Paragraph_Justify')
59 call s:Add_Mapping('n', '<Leader>ac', '<Plug>Quick_Align_Paragraph_Center')
60
61 call s:Add_Mapping('v', '<Leader>al', '<Plug>Align_Range_Left')
62 call s:Add_Mapping('v', '<Leader>ar', '<Plug>Align_Range_Right')
63 call s:Add_Mapping('v', '<Leader>aj', '<Plug>Align_Range_Justify')
64 call s:Add_Mapping('v', '<Leader>ac', '<Plug>Align_Range_Center')
65
66 delfunction s:Add_Mapping
67
68 " vim600: fdm=marker