├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── Rakefile
├── tmux.conf
├── vim
├── autoload
│ └── pathogen.vim
├── bundle
│ ├── align
│ │ ├── autoload
│ │ │ └── Align.vim
│ │ ├── doc
│ │ │ └── Align.txt
│ │ └── plugin
│ │ │ ├── AlignPlugin.vim
│ │ │ └── cecutil.vim
│ └── whitespace
│ │ └── plugin
│ │ └── whitespace.vim
└── snippets
│ ├── coffee
│ ├── bef.snippet
│ ├── des.snippet
│ ├── ex.snippet
│ └── it.snippet
│ └── javascript
│ ├── bef.snippet
│ ├── des.snippet
│ ├── ex.snippet
│ ├── fn.snippet
│ └── it.snippet
├── vimrc
└── vimrc.local
/.gitignore:
--------------------------------------------------------------------------------
1 | vim/.netrwhist
2 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "vim/bundle/nerdtree"]
2 | path = vim/bundle/nerdtree
3 | url = git://github.com/scrooloose/nerdtree.git
4 | [submodule "vim/bundle/ack"]
5 | path = vim/bundle/ack
6 | url = git://github.com/mileszs/ack.vim.git
7 | [submodule "vim/bundle/cucumber"]
8 | path = vim/bundle/cucumber
9 | url = git://github.com/tpope/vim-cucumber.git
10 | [submodule "vim/bundle/endwise"]
11 | path = vim/bundle/endwise
12 | url = git://github.com/tpope/vim-endwise.git
13 | [submodule "vim/bundle/fugitive"]
14 | path = vim/bundle/fugitive
15 | url = git://github.com/tpope/vim-fugitive
16 | [submodule "vim/bundle/indentobject"]
17 | path = vim/bundle/indentobject
18 | url = git://github.com/austintaylor/vim-indentobject.git
19 | [submodule "vim/bundle/rails"]
20 | path = vim/bundle/rails
21 | url = git://github.com/tpope/vim-rails.git
22 | [submodule "vim/bundle/repeat"]
23 | path = vim/bundle/repeat
24 | url = git://github.com/tpope/vim-repeat.git
25 | [submodule "vim/bundle/ruby"]
26 | path = vim/bundle/ruby
27 | url = git://github.com/vim-ruby/vim-ruby.git
28 | [submodule "vim/bundle/surround"]
29 | path = vim/bundle/surround
30 | url = git://github.com/tpope/vim-surround.git
31 | [submodule "vim/bundle/unimpaired"]
32 | path = vim/bundle/unimpaired
33 | url = git://github.com/tpope/vim-unimpaired.git
34 | [submodule "vim/bundle/bundler"]
35 | path = vim/bundle/bundler
36 | url = git://github.com/tpope/vim-bundler.git
37 | [submodule "vim/bundle/vividchalk"]
38 | path = vim/bundle/vividchalk
39 | url = git://github.com/tpope/vim-vividchalk.git
40 | [submodule "vim/bundle/greplace"]
41 | path = vim/bundle/greplace
42 | url = git://github.com/vim-scripts/greplace.vim.git
43 | [submodule "vim/bundle/pastie"]
44 | path = vim/bundle/pastie
45 | url = git://github.com/tpope/vim-pastie.git
46 | [submodule "vim/bundle/snipmate"]
47 | path = vim/bundle/snipmate
48 | url = git://github.com/msanders/snipmate.vim
49 | [submodule "vim/bundle/solarized"]
50 | path = vim/bundle/solarized
51 | url = git://github.com/altercation/vim-colors-solarized.git
52 | [submodule "vim/bundle/javascript"]
53 | path = vim/bundle/javascript
54 | url = git://github.com/pangloss/vim-javascript.git
55 | [submodule "vim/bundle/ragtag"]
56 | path = vim/bundle/ragtag
57 | url = git://github.com/tpope/vim-ragtag.git
58 | [submodule "vim/bundle/commentary"]
59 | path = vim/bundle/commentary
60 | url = git://github.com/tpope/vim-commentary
61 | [submodule "vim/bundle/handlebars"]
62 | path = vim/bundle/handlebars
63 | url = git://github.com/nono/vim-handlebars.git
64 | [submodule "vim/bundle/tagbar"]
65 | path = vim/bundle/tagbar
66 | url = git://github.com/majutsushi/tagbar.git
67 | [submodule "vim/bundle/vim-coffee-script"]
68 | path = vim/bundle/vim-coffee-script
69 | url = git://github.com/kchmck/vim-coffee-script.git
70 | [submodule "vim/bundle/jshint"]
71 | path = vim/bundle/jshint
72 | url = git://github.com/rmanalan/jshint.vim.git
73 | [submodule "vim/bundle/protobuf"]
74 | path = vim/bundle/protobuf
75 | url = git://github.com/uarun/vim-protobuf.git
76 | [submodule "vim/bundle/gitgutter"]
77 | path = vim/bundle/gitgutter
78 | url = git://github.com/airblade/vim-gitgutter.git
79 | [submodule "vim/bundle/vim-slim"]
80 | path = vim/bundle/vim-slim
81 | url = git://github.com/slim-template/vim-slim.git
82 | [submodule "vim/bundle/typescript-vim"]
83 | path = vim/bundle/typescript-vim
84 | url = https://github.com/leafgarland/typescript-vim.git
85 | [submodule "vim/bundle/vim-tmux-navigator"]
86 | path = vim/bundle/vim-tmux-navigator
87 | url = https://github.com/christoomey/vim-tmux-navigator.git
88 | [submodule "vim/bundle/syntastic"]
89 | path = vim/bundle/syntastic
90 | url = https://github.com/scrooloose/syntastic
91 | [submodule "vim/bundle/matchit"]
92 | path = vim/bundle/matchit
93 | url = https://github.com/vim-scripts/matchit.zip.git
94 | [submodule "vim/bundle/kwbd"]
95 | path = vim/bundle/kwbd
96 | url = https://github.com/vim-scripts/kwbdi.vim.git
97 | [submodule "vim/bundle/vim-indent-guides"]
98 | path = vim/bundle/vim-indent-guides
99 | url = https://github.com/nathanaelkane/vim-indent-guides.git
100 | [submodule "vim/bundle/mustache"]
101 | path = vim/bundle/mustache
102 | url = https://github.com/juvenn/mustache.vim.git
103 | [submodule "vim/bundle/ctrlp.vim"]
104 | path = vim/bundle/ctrlp.vim
105 | url = https://github.com/kien/ctrlp.vim.git
106 | [submodule "vim/bundle/vim-markdown"]
107 | path = vim/bundle/vim-markdown
108 | url = https://github.com/plasticboy/vim-markdown.git
109 | [submodule "vim/bundle/vim-golang"]
110 | path = vim/bundle/vim-golang
111 | url = https://github.com/jnwhiteh/vim-golang.git
112 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2013 Square Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Maximum Awesome Linux Port
2 |
3 | * Still somewhat experimental, so use with caution.
4 | Linux (currently just Ubuntu) port of Maximum Awesome from (https://github.com/square/maximum-awesome).
5 |
6 | ## What do you need to do it
7 | Ubuntu, with `git` and `rake` installed. To get them you could do
8 |
9 | ```bash
10 | sudo apt-get install git rake
11 | ```
12 |
13 | ## What's in it?
14 |
15 | * [tmux](http://tmux.sourceforge.net/)
16 | * Awesome syntax highlighting with the [Solarized color scheme](http://ethanschoonover.com/solarized)
17 |
18 | ### vim
19 |
20 | * `,d` brings up [NERDTree](https://github.com/scrooloose/nerdtree), a sidebar buffer for navigating and manipulating files
21 | * `,t` brings up [ctrlp.vim](https://github.com/kien/ctrlp.vim), a project file filter for easily opening specific files
22 | * `,b` restricts ctrlp.vim to open buffers
23 | * `,a` starts project search with [ack.vim](https://github.com/mileszs/ack.vim) using [ag](https://github.com/ggreer/the_silver_searcher) (like ack)
24 | * `ds`/`cs` delete/change surrounding characters (e.g. `"Hey!"` + `ds"` = `Hey!`, `"Hey!"` + `cs"'` = `'Hey!'`) with [vim-surround](https://github.com/tpope/vim-surround)
25 | * `\\\` toggles current line comment
26 | * `\\` toggles visual selection comment lines
27 | * `vii`/`vai` visually select *in* or *around* the cursor's indent
28 | * `,[space]` strips trailing whitespace
29 | * `^]` jump to definition using ctags
30 | * `,l` begins aligning lines on a string, usually used as `,l=` to align assignments
31 | * `^hjkl` move between windows, shorthand for `^w hjkl`
32 |
33 | ### tmux
34 |
35 | * `^a` is the prefix
36 | * mouse scroll initiates tmux scroll
37 | * `prefix v` makes a vertical split
38 | * `prefix s` makes a horizontal split
39 |
40 | ## Install
41 |
42 | rake
43 |
44 | ## Contributing
45 |
46 | 1. Fork it
47 | 2. Create your feature branch (`git checkout -b my-new-feature`)
48 | 3. Commit your changes (`git commit -am 'Add some feature'`)
49 | 4. Push to the branch (`git push origin my-new-feature`)
50 | 5. Create new Pull Request
51 |
52 | ## Acknowledgements
53 |
54 | Thanks to the owners of the original maximum-awesome repo (https://github.com/square/maximum-awesome).
55 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'tmpdir'
2 |
3 | def step(description)
4 | description = "-- #{description} "
5 | description = description.ljust(80, '-')
6 | puts
7 | puts "\e[32m#{description}\e[0m"
8 | end
9 |
10 | def app_path(name)
11 | path = "/Applications/#{name}.app"
12 | ["~#{path}", path].each do |full_path|
13 | return full_path if File.directory?(full_path)
14 | end
15 |
16 | return nil
17 | end
18 |
19 | def app?(name)
20 | return !app_path(name).nil?
21 | end
22 |
23 | def link_file(original_filename, symlink_filename)
24 | original_path = File.expand_path(original_filename)
25 | symlink_path = File.expand_path(symlink_filename)
26 | if File.exists?(symlink_path)
27 | # Symlink already configured properly. Leave it alone.
28 | return if File.symlink?(symlink_path) and File.readlink(symlink_path) == original_path
29 | # Never move user's files without creating backups first
30 | number = 1
31 | loop do
32 | backup_path = "#{symlink_path}.bak"
33 | if number > 1
34 | backup_path = "#{backup_path}#{number}"
35 | end
36 | if File.exists?(backup_path)
37 | number += 1
38 | next
39 | end
40 | mv symlink_path, backup_path, :verbose => true
41 | break
42 | end
43 | end
44 | ln_s original_path, symlink_path, :verbose => true
45 | end
46 |
47 | namespace :install do
48 |
49 | desc 'Apt-get Update'
50 | task :update do
51 | step 'apt-get update'
52 | sh 'sudo apt-get update'
53 | end
54 |
55 | desc 'Install Vim'
56 | task :vim do
57 | step 'vim'
58 | sh 'sudo apt-get install vim'
59 | end
60 |
61 | desc 'Install tmux'
62 | task :tmux do
63 | step 'tmux'
64 | sh 'sudo apt-get install tmux'
65 | end
66 |
67 | desc 'Install ctags'
68 | task :ctags do
69 | step 'ctags'
70 | sh 'sudo apt-get install ctags'
71 | end
72 |
73 | # https://github.com/ggreer/the_silver_searcher
74 | desc 'Install The Silver Searcher'
75 | task :the_silver_searcher do
76 | step 'the_silver_searcher'
77 | sh 'sudo apt-get install build-essential automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev'
78 | sh 'git clone https://github.com/ggreer/the_silver_searcher.git'
79 | Dir.chdir 'the_silver_searcher' do
80 | sh './build.sh'
81 | sh 'sudo make install'
82 | end
83 | end
84 |
85 | # instructions from http://www.webupd8.org/2011/04/solarized-must-have-color-paletter-for.html
86 | desc 'Install Solarized and fix ls'
87 | task :solarized, :arg1 do |t, args|
88 | args[:arg1] = "dark" unless ["dark", "light"].include? args[:arg1]
89 | color = ["dark", "light"].include?(args[:arg1]) ? args[:arg1] : "dark"
90 |
91 | step 'solarized'
92 | sh 'git clone https://github.com/sigurdga/gnome-terminal-colors-solarized.git' unless File.exist? 'gnome-terminal-colors-solarized'
93 | Dir.chdir 'gnome-terminal-colors-solarized' do
94 | sh "./solarize #{color}"
95 | end
96 |
97 | step 'fix ls-colors'
98 | Dir.chdir do
99 | sh "wget --no-check-certificate https://raw.github.com/seebi/dircolors-solarized/master/dircolors.ansi-#{color}"
100 | sh "mv dircolors.ansi-#{color} .dircolors"
101 | sh 'eval `dircolors .dircolors`'
102 | end
103 | end
104 | end
105 |
106 | desc 'Install these config files.'
107 | task :default do
108 | Rake::Task['install:update'].invoke
109 | Rake::Task['install:vim'].invoke
110 | Rake::Task['install:tmux'].invoke
111 | Rake::Task['install:ctags'].invoke
112 | Rake::Task['install:the_silver_searcher'].invoke
113 |
114 | step 'git submodules'
115 | sh 'git submodule update --init'
116 |
117 | # TODO install gem ctags?
118 | # TODO run gem ctags?
119 |
120 | step 'symlink'
121 | link_file 'vim' , '~/.vim'
122 | link_file 'tmux.conf' , '~/.tmux.conf'
123 | link_file 'vimrc' , '~/.vimrc'
124 | unless File.exist?(File.expand_path('~/.vimrc.local'))
125 | cp File.expand_path('vimrc.local'), File.expand_path('~/.vimrc.local'), :verbose => true
126 | end
127 |
128 | step 'solarized dark or light'
129 | puts
130 | puts " You're almost done! Inside of the maximum-awesome-linux directory, do: "
131 | puts " rake install:solarized['dark'] "
132 | puts " or "
133 | puts " rake install:solarized['light']"
134 |
135 | puts " You may need to close your terminal and re-open it for it to take effect."
136 | end
137 |
--------------------------------------------------------------------------------
/tmux.conf:
--------------------------------------------------------------------------------
1 | # use C-a, since it's on the home row and easier to hit than C-b
2 | set-option -g prefix C-a
3 | unbind-key C-a
4 | bind-key C-a send-prefix
5 | set -g base-index 1
6 |
7 | # vi is good
8 | setw -g mode-keys vi
9 |
10 | # mouse behavior
11 | setw -g mode-mouse on
12 | set -g mouse-select-pane on
13 | set -g mouse-resize-pane on
14 |
15 | set-option -g default-terminal screen-256color
16 |
17 | bind-key : command-prompt
18 | bind-key r refresh-client
19 | bind-key L clear-history
20 |
21 | bind-key space next-window
22 | bind-key bspace previous-window
23 | bind-key enter next-layout
24 |
25 | # use vim-like keys for splits and windows
26 | bind-key v split-window -h
27 | bind-key s split-window -v
28 | bind-key h select-pane -L
29 | bind-key j select-pane -D
30 | bind-key k select-pane -U
31 | bind-key l select-pane -R
32 |
33 | bind-key C-o rotate-window
34 |
35 | bind-key + select-layout main-horizontal
36 | bind-key = select-layout main-vertical
37 | set-window-option -g other-pane-height 25
38 | set-window-option -g other-pane-width 80
39 |
40 | bind-key a last-pane
41 | bind-key q display-panes
42 | bind-key c new-window
43 | bind-key t next-window
44 | bind-key T previous-window
45 |
46 | bind-key [ copy-mode
47 | bind-key ] paste-buffer
48 |
49 | # Clunkily connect tmux buffers with the pasteboard.
50 | bind-key y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
51 |
52 | set-window-option display-panes-time 1500
53 |
54 | # Status Bar
55 | set-option -g status-interval 1
56 | set-option -g status-left ''
57 | set-option -g status-right '%l:%M%p'
58 | set-window-option -g window-status-current-fg magenta
59 | set-option -g status-fg default
60 |
61 | # Status Bar solarized-dark (default)
62 | set-option -g status-bg black
63 | set-option -g pane-active-border-fg black
64 | set-option -g pane-border-fg black
65 |
66 | # Status Bar solarized-light
67 | if-shell "[ \"$COLORFGBG\" = \"11;15\" ]" "set-option -g status-bg white"
68 | if-shell "[ \"$COLORFGBG\" = \"11;15\" ]" "set-option -g pane-active-border-fg white"
69 | if-shell "[ \"$COLORFGBG\" = \"11;15\" ]" "set-option -g pane-border-fg white"
70 |
71 | # Set window notifications
72 | setw -g monitor-activity on
73 | set -g visual-activity on
74 |
75 | # Enable native Mac OS X copy/paste
76 | set-option -g default-command "/bin/bash -c 'which reattach-to-user-namespace >/dev/null && exec reattach-to-user-namespace $SHELL -l || exec $SHELL -l'"
77 |
78 | # Allow the arrow key to be used immediately after changing windows
79 | set-option -g repeat-time 0
80 |
--------------------------------------------------------------------------------
/vim/autoload/pathogen.vim:
--------------------------------------------------------------------------------
1 | " pathogen.vim - path option manipulation
2 | " Maintainer: Tim Pope
3 | " Version: 2.0
4 |
5 | " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
6 | "
7 | " For management of individually installed plugins in ~/.vim/bundle (or
8 | " ~\vimfiles\bundle), adding `call pathogen#infect()` to your .vimrc
9 | " prior to `filetype plugin indent on` is the only other setup necessary.
10 | "
11 | " The API is documented inline below. For maximum ease of reading,
12 | " :set foldmethod=marker
13 |
14 | if exists("g:loaded_pathogen") || &cp
15 | finish
16 | endif
17 | let g:loaded_pathogen = 1
18 |
19 | " Point of entry for basic default usage. Give a directory name to invoke
20 | " pathogen#runtime_append_all_bundles() (defaults to "bundle"), or a full path
21 | " to invoke pathogen#runtime_prepend_subdirectories(). Afterwards,
22 | " pathogen#cycle_filetype() is invoked.
23 | function! pathogen#infect(...) abort " {{{1
24 | let source_path = a:0 ? a:1 : 'bundle'
25 | if source_path =~# '[\\/]'
26 | call pathogen#runtime_prepend_subdirectories(source_path)
27 | else
28 | call pathogen#runtime_append_all_bundles(source_path)
29 | endif
30 | call pathogen#cycle_filetype()
31 | endfunction " }}}1
32 |
33 | " Split a path into a list.
34 | function! pathogen#split(path) abort " {{{1
35 | if type(a:path) == type([]) | return a:path | endif
36 | let split = split(a:path,'\\\@,'edit',,0)
225 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(,'edit',,0)
226 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(,'edit',,1)
227 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(,'split',,1)
228 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(,'vsplit',,1)
229 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(,'tabedit',,1)
230 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(,'pedit',,1)
231 | command! -bar -bang -count=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(,'read',,1)
232 |
233 | " vim:set ft=vim ts=8 sw=2 sts=2:
234 |
--------------------------------------------------------------------------------
/vim/bundle/align/autoload/Align.vim:
--------------------------------------------------------------------------------
1 | " Align: tool to align multiple fields based on one or more separators
2 | " Author: Charles E. Campbell, Jr.
3 | " Date: Jun 18, 2012
4 | " Version: 36
5 | " GetLatestVimScripts: 294 1 :AutoInstall: Align.vim
6 | " GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim
7 | " Copyright: Copyright (C) 1999-2012 Charles E. Campbell, Jr. {{{1
8 | " Permission is hereby granted to use and distribute this code,
9 | " with or without modifications, provided that this copyright
10 | " notice is copied with it. Like anything else that's free,
11 | " Align.vim is provided *as is* and comes with no warranty
12 | " of any kind, either expressed or implied. By using this
13 | " plugin, you agree that in no event will the copyright
14 | " holder be liable for any damages resulting from the use
15 | " of this software.
16 | "
17 | " Romans 1:16,17a : For I am not ashamed of the gospel of Christ, for it is {{{1
18 | " the power of God for salvation for everyone who believes; for the Jew first,
19 | " and also for the Greek. For in it is revealed God's righteousness from
20 | " faith to faith.
21 | "redraw!|call DechoSep()|call inputsave()|call input("Press to continue")|call inputrestore()
22 |
23 | " ---------------------------------------------------------------------
24 | " Load Once: {{{1
25 | if exists("g:loaded_Align") || &cp
26 | finish
27 | endif
28 | let g:loaded_Align = "v36"
29 | if v:version < 700
30 | echohl WarningMsg
31 | echo "***warning*** this version of Align needs vim 7.0"
32 | echohl Normal
33 | finish
34 | endif
35 | let s:keepcpo= &cpo
36 | set cpo&vim
37 | "DechoTabOn
38 |
39 | " ---------------------------------------------------------------------
40 | " Debugging Support: {{{1
41 | "if !exists("g:loaded_Decho") | runtime plugin/Decho.vim | endif
42 |
43 | " ---------------------------------------------------------------------
44 | " Options: {{{1
45 | if !exists("g:Align_xstrlen")
46 | if &enc == "latin1" || $LANG == "en_US.UTF-8" || !has("multi_byte")
47 | let g:Align_xstrlen= 0
48 | else
49 | let g:Align_xstrlen= 1
50 | endif
51 | endif
52 |
53 | " ---------------------------------------------------------------------
54 | " Align#AlignCtrl: enter alignment patterns here {{{1
55 | "
56 | " Styles = all alignment-break patterns are equivalent
57 | " C cycle through alignment-break pattern(s)
58 | " l left-justified alignment
59 | " r right-justified alignment
60 | " c center alignment
61 | " - skip separator, treat as part of field
62 | " : treat rest of line as field
63 | " + repeat previous [lrc] style
64 | " < left justify separators
65 | " > right justify separators
66 | " | center separators
67 | "
68 | " Builds = s:AlignPat s:AlignCtrl s:AlignPatQty
69 | " C s:AlignPat s:AlignCtrl s:AlignPatQty
70 | " p s:AlignPrePad
71 | " P s:AlignPostPad
72 | " w s:AlignLeadKeep
73 | " W s:AlignLeadKeep
74 | " I s:AlignLeadKeep
75 | " l s:AlignStyle
76 | " r s:AlignStyle
77 | " - s:AlignStyle
78 | " + s:AlignStyle
79 | " : s:AlignStyle
80 | " c s:AlignStyle
81 | " g s:AlignGPat
82 | " v s:AlignVPat
83 | " < s:AlignSep
84 | " > s:AlignSep
85 | " | s:AlignSep
86 | fun! Align#AlignCtrl(...)
87 |
88 | " call Dfunc("Align#AlignCtrl(...) a:0=".a:0)
89 |
90 | " save options that may be changed later
91 | call s:SaveUserOptions()
92 |
93 | " turn ignorecase off
94 | setlocal noic
95 |
96 | " clear visual mode so that old visual-mode selections don't
97 | " get applied to new invocations of Align().
98 | if v:version < 602
99 | if !exists("s:Align_gavemsg")
100 | let s:Align_gavemsg= 1
101 | echomsg "Align needs at least Vim version 6.2 to clear visual-mode selection"
102 | endif
103 | elseif exists("s:dovisclear")
104 | " call Decho("clearing visual mode a:0=".a:0." a:1<".a:1.">")
105 | let clearvmode= visualmode(1)
106 | endif
107 |
108 | " set up a list akin to an argument list
109 | if a:0 > 0
110 | let A= s:QArgSplitter(a:1)
111 | else
112 | let A=[0]
113 | endif
114 |
115 | if A[0] > 0
116 | let style = A[1]
117 |
118 | " Check for bad separator patterns (zero-length matches)
119 | " (but zero-length patterns for g/v is ok)
120 | if style !~# '[gv]'
121 | let ipat= 2
122 | while ipat <= A[0]
123 | if "" =~ A[ipat]
124 | echoerr "(AlignCtrl) separator<".A[ipat]."> matches zero-length string"
125 | call s:RestoreUserOptions()
126 | " call Dret("Align#AlignCtrl")
127 | return
128 | endif
129 | let ipat= ipat + 1
130 | endwhile
131 | endif
132 | endif
133 | " call Decho("(AlignCtrl) passed bad-separator pattern check (no zero-length matches)")
134 |
135 | " call Decho("(AlignCtrl) A[0]=".A[0])
136 | if !exists("s:AlignStyle")
137 | let s:AlignStyle= 'l'
138 | endif
139 | if !exists("s:AlignPrePad")
140 | let s:AlignPrePad= 0
141 | endif
142 | if !exists("s:AlignPostPad")
143 | let s:AlignPostPad= 0
144 | endif
145 | if !exists("s:AlignLeadKeep")
146 | let s:AlignLeadKeep= 'w'
147 | endif
148 |
149 | if A[0] == 0
150 | " ----------------------
151 | " List current selection
152 | " ----------------------
153 | if !exists("s:AlignPatQty")
154 | let s:AlignPatQty= 0
155 | endif
156 | echo "AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep
157 | " call Decho("(AlignCtrl) AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep)
158 | if exists("s:AlignGPat") && !exists("s:AlignVPat")
159 | echo "AlignGPat<".s:AlignGPat.">"
160 | elseif !exists("s:AlignGPat") && exists("s:AlignVPat")
161 | echo "AlignVPat<".s:AlignVPat.">"
162 | elseif exists("s:AlignGPat") && exists("s:AlignVPat")
163 | echo "AlignGPat<".s:AlignGPat."> AlignVPat<".s:AlignVPat.">"
164 | endif
165 | let ipat= 1
166 | while ipat <= s:AlignPatQty
167 | echo "Pat".ipat."<".s:AlignPat_{ipat}.">"
168 | " call Decho("(AlignCtrl) Pat".ipat."<".s:AlignPat_{ipat}.">")
169 | let ipat= ipat + 1
170 | endwhile
171 |
172 | else
173 | " ----------------------------------
174 | " Process alignment control settings
175 | " ----------------------------------
176 | " call Decho("process the alignctrl settings")
177 | " call Decho("style<".style.">")
178 |
179 | if style ==? "default"
180 | " Default: preserve initial leading whitespace, left-justified,
181 | " alignment on '=', one space padding on both sides
182 | if exists("s:AlignCtrlStackQty")
183 | " clear AlignCtrl stack
184 | while s:AlignCtrlStackQty > 0
185 | call Align#AlignPop()
186 | endwhile
187 | unlet s:AlignCtrlStackQty
188 | endif
189 | " Set AlignCtrl to its default value
190 | call Align#AlignCtrl("Ilp1P1=<",'=')
191 | call Align#AlignCtrl("g")
192 | call Align#AlignCtrl("v")
193 | let s:dovisclear = 1
194 | call s:RestoreUserOptions()
195 | " call Dret("Align#AlignCtrl")
196 | return
197 | endif
198 |
199 | if style =~# 'm'
200 | " map support: Do an AlignPush now and the next call to Align()
201 | " will do an AlignPop at exit
202 | " call Decho("style case m: do AlignPush")
203 | call Align#AlignPush()
204 | let s:DoAlignPop= 1
205 | endif
206 |
207 | " = : record a list of alignment patterns that are equivalent
208 | if style =~# "=" || (A[0] >= 2 && style !~# "C" && s:AlignCtrl =~# '=')
209 | " call Decho("style case =: record list of equiv alignment patterns")
210 | let s:AlignCtrl = '='
211 | if A[0] >= 2
212 | let s:AlignPatQty= 1
213 | let s:AlignPat_1 = A[2]
214 | let ipat = 3
215 | while ipat <= A[0]
216 | let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat]
217 | let ipat = ipat + 1
218 | endwhile
219 | let s:AlignPat_1= '\('.s:AlignPat_1.'\)'
220 | " call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">")
221 | endif
222 |
223 | "c : cycle through alignment pattern(s)
224 | elseif style =~# 'C' || (A[0] >= 2 && s:AlignCtrl =~# '=')
225 | " call Decho("style case C: cycle through alignment pattern(s)")
226 | let s:AlignCtrl = 'C'
227 | if A[0] >= 2
228 | let s:AlignPatQty= A[0] - 1
229 | let ipat = 1
230 | while ipat < A[0]
231 | let s:AlignPat_{ipat}= A[ipat+1]
232 | " call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">")
233 | let ipat= ipat + 1
234 | endwhile
235 | endif
236 | endif
237 |
238 | if style =~# 'p'
239 | let s:AlignPrePad= substitute(style,'^.*p\(\d\+\).*$','\1','')
240 | " call Decho("style case p".s:AlignPrePad.": pre-separator padding")
241 | if s:AlignPrePad == ""
242 | echoerr "(AlignCtrl) 'p' needs to be followed by a numeric argument'"
243 | call s:RestoreUserOptions()
244 | " call Dret("Align#AlignCtrl")
245 | return
246 | endif
247 | endif
248 |
249 | if style =~# 'P'
250 | let s:AlignPostPad= substitute(style,'^.*P\(\d\+\).*$','\1','')
251 | " call Decho("style case P".s:AlignPostPad.": post-separator padding")
252 | if s:AlignPostPad == ""
253 | echoerr "(AlignCtrl) 'P' needs to be followed by a numeric argument'"
254 | call s:RestoreUserOptions()
255 | " call Dret("Align#AlignCtrl")
256 | return
257 | endif
258 | endif
259 |
260 | if style =~# 'w'
261 | " call Decho("style case w: ignore leading whitespace")
262 | let s:AlignLeadKeep= 'w'
263 | elseif style =~# 'W'
264 | " call Decho("style case W: keep leading whitespace")
265 | let s:AlignLeadKeep= 'W'
266 | elseif style =~# 'I'
267 | " call Decho("style case I: retain initial leading whitespace")
268 | let s:AlignLeadKeep= 'I'
269 | endif
270 |
271 | if style =~# 'g'
272 | " first list item is a "g" selector pattern
273 | " call Decho("style case g: global selector pattern")
274 | if A[0] < 2
275 | if exists("s:AlignVPat")
276 | unlet s:AlignVPat
277 | " call Decho("unlet s:AlignGPat")
278 | endif
279 | else
280 | let s:AlignGPat= A[2]
281 | " call Decho("s:AlignGPat<".s:AlignGPat.">")
282 | endif
283 | elseif style =~# 'v'
284 | " first list item is a "v" selector pattern
285 | " call Decho("style case v: global selector anti-pattern")
286 | if A[0] < 2
287 | if exists("s:AlignGPat")
288 | unlet s:AlignGPat
289 | " call Decho("unlet s:AlignVPat")
290 | endif
291 | else
292 | let s:AlignVPat= A[2]
293 | " call Decho("s:AlignVPat<".s:AlignVPat.">")
294 | endif
295 | endif
296 |
297 | "[-lrc+:] : set up s:AlignStyle
298 | if style =~# '[-lrc+:*]'
299 | " call Decho("style case [-lrc+:]: field justification")
300 | let s:AlignStyle= substitute(style,'[^-lrc:+*]','','g')
301 | " call Decho("AlignStyle<".s:AlignStyle.">")
302 | endif
303 |
304 | "[<>|] : set up s:AlignSep
305 | if style =~# '[<>|]'
306 | " call Decho("style case [-lrc+:]: separator justification")
307 | let s:AlignSep= substitute(style,'[^<>|]','','g')
308 | " call Decho("AlignSep ".s:AlignSep)
309 | endif
310 | endif
311 |
312 | " sanity
313 | if !exists("s:AlignCtrl")
314 | let s:AlignCtrl= '='
315 | endif
316 |
317 | " restore options and return
318 | call s:RestoreUserOptions()
319 | " call Dret("Align#AlignCtrl ".s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle)
320 | return s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle
321 | endfun
322 |
323 | " ---------------------------------------------------------------------
324 | " s:MakeSpace: returns a string with spacecnt blanks {{{1
325 | fun! s:MakeSpace(spacecnt)
326 | " call Dfunc("MakeSpace(spacecnt=".a:spacecnt.")")
327 | let str = ""
328 | let spacecnt = a:spacecnt
329 | while spacecnt > 0
330 | let str = str . " "
331 | let spacecnt = spacecnt - 1
332 | endwhile
333 | " call Dret("MakeSpace <".str.">")
334 | return str
335 | endfun
336 |
337 | " ---------------------------------------------------------------------
338 | " Align#Align: align selected text based on alignment pattern(s) {{{1
339 | fun! Align#Align(hasctrl,...) range
340 | " call Dfunc("Align#Align(hasctrl=".a:hasctrl.",...) a:0=".a:0)
341 |
342 | " sanity checks
343 | if string(a:hasctrl) != "0" && string(a:hasctrl) != "1"
344 | echohl Error|echo 'usage: Align#Align(hasctrl<'.a:hasctrl.'> (should be 0 or 1),"separator(s)" (you have '.a:0.') )'|echohl None
345 | " call Dret("Align#Align")
346 | return
347 | endif
348 | if exists("s:AlignStyle") && s:AlignStyle == ":"
349 | echohl Error |echo '(Align#Align) your AlignStyle is ":", which implies "do-no-alignment"!'|echohl None
350 | " call Dret("Align#Align")
351 | return
352 | endif
353 |
354 | " save user options
355 | call s:SaveUserOptions()
356 |
357 | " set up a list akin to an argument list
358 | if a:0 > 0
359 | let A= s:QArgSplitter(a:1)
360 | else
361 | let A=[0]
362 | endif
363 |
364 | " if :Align! was used, then the first argument is (should be!) an AlignCtrl string
365 | " Note that any alignment control set this way will be temporary.
366 | let hasctrl= a:hasctrl
367 | " call Decho("hasctrl=".hasctrl)
368 | if a:hasctrl && A[0] >= 1
369 | " call Decho("Align! : using A[1]<".A[1]."> for AlignCtrl")
370 | if A[1] =~ '[gv]'
371 | let hasctrl= hasctrl + 1
372 | call Align#AlignCtrl('m')
373 | call Align#AlignCtrl(A[1],A[2])
374 | " call Decho("Align! : also using A[2]<".A[2]."> for AlignCtrl")
375 | elseif A[1] !~ 'm'
376 | call Align#AlignCtrl(A[1]."m")
377 | else
378 | call Align#AlignCtrl(A[1])
379 | endif
380 | endif
381 |
382 | " Check for bad separator patterns (zero-length matches)
383 | let ipat= 1 + hasctrl
384 | while ipat <= A[0]
385 | if "" =~ A[ipat]
386 | echoerr "(Align) separator<".A[ipat]."> matches zero-length string"
387 | call s:RestoreUserOptions()
388 | " call Dret("Align#Align")
389 | return
390 | endif
391 | let ipat= ipat + 1
392 | endwhile
393 |
394 | " record current search pattern for subsequent restoration
395 | " (these are all global-only options)
396 | set noic report=10000 nohls
397 |
398 | if A[0] > hasctrl
399 | " Align will accept a list of separator regexps
400 | " call Decho("A[0]=".A[0].": accepting list of separator regexp")
401 |
402 | if s:AlignCtrl =~# "="
403 | "= : consider all separators to be equivalent
404 | " call Decho("AlignCtrl: record list of equivalent alignment patterns")
405 | let s:AlignCtrl = '='
406 | let s:AlignPat_1 = A[1 + hasctrl]
407 | let s:AlignPatQty= 1
408 | let ipat = 2 + hasctrl
409 | while ipat <= A[0]
410 | let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat]
411 | let ipat = ipat + 1
412 | endwhile
413 | let s:AlignPat_1= '\('.s:AlignPat_1.'\)'
414 | " call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">")
415 |
416 | elseif s:AlignCtrl =~# 'C'
417 | "c : cycle through alignment pattern(s)
418 | " call Decho("AlignCtrl: cycle through alignment pattern(s)")
419 | let s:AlignCtrl = 'C'
420 | let s:AlignPatQty= A[0] - hasctrl
421 | let ipat = 1
422 | while ipat <= s:AlignPatQty
423 | let s:AlignPat_{ipat}= A[(ipat + hasctrl)]
424 | " call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">")
425 | let ipat= ipat + 1
426 | endwhile
427 | endif
428 | endif
429 |
430 | " Initialize so that begline
432 | " is greater than the line's string length -> ragged right.
433 | " Have to be careful about visualmode() -- it returns the last visual
434 | " mode used whether or not it was used currently.
435 | let begcol = virtcol("'<")-1
436 | let endcol = virtcol("'>")-1
437 | if begcol > endcol
438 | let begcol = virtcol("'>")-1
439 | let endcol = virtcol("'<")-1
440 | endif
441 | " call Decho("begcol=".begcol." endcol=".endcol)
442 | let begline = a:firstline
443 | let endline = a:lastline
444 | if begline > endline
445 | let begline = a:lastline
446 | let endline = a:firstline
447 | endif
448 |
449 | " Expand range to cover align-able lines when the given range is only the current line.
450 | " Look for the first line above the current line that matches the first separator pattern, and
451 | " look for the last line below the current line that matches the first separator pattern.
452 | if begline == endline
453 | " call Decho("case begline == endline")
454 | if !exists("s:AlignPat_{1}")
455 | echohl Error|echo "(Align) no separators specified!"|echohl None
456 | call s:RestoreUserOptions()
457 | " call Dret("Align#Align")
458 | return
459 | endif
460 | let seppat = s:AlignPat_{1}
461 | let begline= search('^\%(\%('.seppat.'\)\@!.\)*$',"bnW")
462 | if begline == 0|let begline= 1|else|let begline= begline + 1|endif
463 | let endline= search('^\%(\%('.seppat.'\)\@!.\)*$',"nW")
464 | if endline == 0|let endline= line("$")|else|let endline= endline - 1|endif
465 | " call Decho("begline=".begline." endline=".endline." curline#".line("."))
466 | endif
467 | " call Decho("begline=".begline." endline=".endline)
468 | let fieldcnt = 0
469 | if (begline == line("'>") && endline == line("'<")) || (begline == line("'<") && endline == line("'>"))
470 | let vmode= visualmode()
471 | " call Decho("vmode=".vmode)
472 | if vmode == "\"
473 | let ragged = ( col("'>") > s:Strlen(getline("'>")) || col("'<") > s:Strlen(getline("'<")) )
474 | else
475 | let ragged= 1
476 | endif
477 | else
478 | let ragged= 1
479 | endif
480 | if ragged
481 | let begcol= 0
482 | endif
483 | " call Decho("lines[".begline.",".endline."] col[".begcol.",".endcol."] ragged=".ragged." AlignCtrl<".s:AlignCtrl.">")
484 |
485 | " record initial whitespace
486 | if s:AlignLeadKeep == 'W'
487 | let wskeep = map(getline(begline,endline),"substitute(v:val,'^\\(\\s*\\).\\{-}$','\\1','')")
488 | endif
489 |
490 | " Align needs these options
491 | setl et
492 | set paste
493 |
494 | " convert selected range of lines to use spaces instead of tabs
495 | " but if first line's initial white spaces are to be retained
496 | " then use 'em
497 | if begcol <= 0 && s:AlignLeadKeep == 'I'
498 | " retain first leading whitespace for all subsequent lines
499 | let bgntxt= substitute(getline(begline),'^\(\s*\).\{-}$','\1','')
500 |
501 | " exception: retain first leading whitespace predicated on g and v patterns
502 | " if such a selected line exists
503 | if exists("s:AlignGPat")
504 | let firstgline= search(s:AlignGPat,"cnW",endline)
505 | if firstgline > 0
506 | let bgntxt= substitute(getline(firstgline),'^\(\s*\).\{-}$','\1','')
507 | endif
508 | elseif exists("s:AlignVPat")
509 | let firstvline= search(s:AlignVPat,"cnW",endline)
510 | if firstvline > 0
511 | let bgntxt= substitute('^\%(\%('.getline(firstvline).')\@!\)*$','^\(\s*\).\{-}$','\1','')
512 | endif
513 | endif
514 | " call Decho("retaining 1st leading whitespace: bgntxt<".bgntxt.">")
515 | let &l:et= s:keep_et
516 | endif
517 | exe begline.",".endline."ret"
518 |
519 | " record transformed to spaces leading whitespace
520 | if s:AlignLeadKeep == 'W'
521 | let wsblanks = map(getline(begline,endline),"substitute(v:val,'^\\(\\s*\\).\\{-}$','\\1','')")
522 | endif
523 |
524 | " Execute two passes
525 | " First pass: collect alignment data (max field sizes)
526 | " Second pass: perform alignment
527 | let pass= 1
528 | while pass <= 2
529 | " call Decho(" ")
530 | " call Decho("---- Pass ".pass.": ----")
531 |
532 | let line= begline
533 | while line <= endline
534 | " Process each line
535 | let txt = getline(line)
536 | " call Decho(" ")
537 | " call Decho("Pass".pass.": Line ".line." <".txt.">")
538 |
539 | " AlignGPat support: allows a selector pattern (akin to g/selector/cmd )
540 | if exists("s:AlignGPat")
541 | " call Decho("Pass".pass.": AlignGPat<".s:AlignGPat.">")
542 | if match(txt,s:AlignGPat) == -1
543 | " call Decho("Pass".pass.": skipping")
544 | let line= line + 1
545 | continue
546 | endif
547 | endif
548 |
549 | " AlignVPat support: allows a selector pattern (akin to v/selector/cmd )
550 | if exists("s:AlignVPat")
551 | " call Decho("Pass".pass.": AlignVPat<".s:AlignVPat.">")
552 | if match(txt,s:AlignVPat) != -1
553 | " call Decho("Pass".pass.": skipping")
554 | let line= line + 1
555 | continue
556 | endif
557 | endif
558 |
559 | " Always skip blank lines
560 | if match(txt,'^\s*$') != -1
561 | " call Decho("Pass".pass.": skipping")
562 | let line= line + 1
563 | continue
564 | endif
565 |
566 | " Extract visual-block selected text (init bgntxt, endtxt)
567 | let txtlen= s:Strlen(txt)
568 | if begcol > 0
569 | " Record text to left of selected area
570 | let bgntxt= strpart(txt,0,begcol)
571 | " call Decho("Pass".pass.": record text to left: bgntxt<".bgntxt.">")
572 | elseif s:AlignLeadKeep == 'W'
573 | let bgntxt= substitute(txt,'^\(\s*\).\{-}$','\1','')
574 | " call Decho("Pass".pass.": retaining all leading ws: bgntxt<".bgntxt.">")
575 | elseif s:AlignLeadKeep == 'w' || !exists("bgntxt")
576 | " No beginning text
577 | let bgntxt= ""
578 | " call Decho("Pass".pass.": no beginning text")
579 | endif
580 | if ragged
581 | let endtxt= ""
582 | else
583 | " Elide any text lying outside selected columnar region
584 | let endtxt= strpart(txt,endcol+1,txtlen-endcol)
585 | let txt = strpart(txt,begcol,endcol-begcol+1)
586 | endif
587 | " call Decho(" ")
588 | " call Decho("Pass".pass.": bgntxt<".bgntxt.">")
589 | " call Decho("Pass".pass.": txt<". txt .">")
590 | " call Decho("Pass".pass.": endtxt<".endtxt.">")
591 | if !exists("s:AlignPat_{1}")
592 | echohl Error|echo "(Align) no separators specified!"|echohl None
593 | call s:RestoreUserOptions()
594 | " call Dret("Align#Align")
595 | return
596 | endif
597 |
598 | " Initialize for both passes
599 | let seppat = s:AlignPat_{1}
600 | let ifield = 1
601 | let ipat = 1
602 | let bgnfield = 0
603 | let endfield = 0
604 | let alignstyle = s:AlignStyle
605 | let doend = 1
606 | let newtxt = ""
607 | let alignprepad = s:AlignPrePad
608 | let alignpostpad= s:AlignPostPad
609 | let alignsep = s:AlignSep
610 | let alignophold = " "
611 | let alignop = 'l'
612 | " call Decho("Pass".pass.": initial alignstyle<".alignstyle."> seppat<".seppat.">")
613 |
614 | " Process each field on the line
615 | while doend > 0
616 |
617 | " C-style: cycle through pattern(s)
618 | if s:AlignCtrl == 'C' && doend == 1
619 | let seppat = s:AlignPat_{ipat}
620 | " call Decho("Pass".pass.": processing field: AlignCtrl=".s:AlignCtrl." ipat=".ipat." seppat<".seppat.">")
621 | let ipat = ipat + 1
622 | if ipat > s:AlignPatQty
623 | let ipat = 1
624 | endif
625 | endif
626 |
627 | " cyclic alignment/justification operator handling
628 | let alignophold = alignop
629 | let alignop = strpart(alignstyle,0,1)
630 | if alignop == '+' || doend == 2
631 | let alignop= alignophold
632 | else
633 | let alignstyle = strpart(alignstyle,1).strpart(alignstyle,0,1)
634 | let alignopnxt = strpart(alignstyle,0,1)
635 | if alignop == ':'
636 | let seppat = '$'
637 | let doend = 2
638 | " call Decho("Pass".pass.": alignop<:> case: setting seppat<$> doend==2")
639 | endif
640 | endif
641 |
642 | " cyclic separator alignment specification handling
643 | let alignsepop= strpart(alignsep,0,1)
644 | let alignsep = strpart(alignsep,1).alignsepop
645 |
646 | " ------------------------------------------------------
647 | " mark end-of-field and the subsequent end-of-separator.
648 | " ------------------------------------------------------
649 | let endfield = match(txt,seppat,bgnfield)
650 | let sepfield = matchend(txt,seppat,bgnfield)
651 | let skipfield= sepfield
652 | " call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop)
653 |
654 | " Mark eof: Extend field if alignop is '*' and AlignSkip() is true.
655 | if alignop == '*' && exists("g:AlignSkip") && type(g:AlignSkip) == 2
656 | " call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop)
657 | " a '*' acts like a '-' while the g:AlignSkip function reference is true except that alignop doesn't advance
658 | while g:AlignSkip(line,endfield) && endfield != -1
659 | let endfield = match(txt,seppat,skipfield)
660 | let sepfield = matchend(txt,seppat,skipfield)
661 | let skipfield = sepfield
662 | " call Decho("Pass".pass.": extend field: endfield<".strpart(txt,bgnfield,endfield-bgnfield)."> alignop<".alignop."> alignstyle<".alignstyle.">")
663 | endwhile
664 | let alignop = strpart(alignstyle,0,1)
665 | let alignstyle= strpart(alignstyle,1).strpart(alignstyle,0,1)
666 | " call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop." (after *)")
667 | endif
668 |
669 | " Mark eof: Extend field if alignop is '-'
670 | while alignop == '-' && endfield != -1
671 | let endfield = match(txt,seppat,skipfield)
672 | let sepfield = matchend(txt,seppat,skipfield)
673 | let skipfield = sepfield
674 | let alignop = strpart(alignstyle,0,1)
675 | let alignstyle= strpart(alignstyle,1).strpart(alignstyle,0,1)
676 | " call Decho("Pass".pass.": extend field: endfield<".strpart(txt,bgnfield,endfield-bgnfield)."> alignop<".alignop."> alignstyle<".alignstyle.">")
677 | endwhile
678 | let seplen= sepfield - endfield
679 | " call Decho("Pass".pass.": seplen=[sepfield=".sepfield."] - [endfield=".endfield."]=".seplen)
680 |
681 | if endfield != -1
682 | if pass == 1
683 | " ---------------------------------------------------------------------
684 | " Pass 1: Update FieldSize to max
685 | " call Decho("Pass".pass.": before lead/trail remove: field<".strpart(txt,bgnfield,endfield-bgnfield).">")
686 | let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','')
687 | if s:AlignLeadKeep == 'W'
688 | let field = bgntxt.field
689 | let bgntxt= ""
690 | endif
691 | let fieldlen = s:Strlen(field)
692 | let sFieldSize = "FieldSize_".ifield
693 | if !exists(sFieldSize)
694 | let FieldSize_{ifield}= fieldlen
695 | " call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">")
696 | elseif fieldlen > FieldSize_{ifield}
697 | let FieldSize_{ifield}= fieldlen
698 | " call Decho("Pass".pass.": oset FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">")
699 | endif
700 | let sSepSize= "SepSize_".ifield
701 | if !exists(sSepSize)
702 | let SepSize_{ifield}= seplen
703 | " call Decho(" set SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">")
704 | elseif seplen > SepSize_{ifield}
705 | let SepSize_{ifield}= seplen
706 | " call Decho("Pass".pass.": oset SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">")
707 | endif
708 |
709 | else
710 | " ---------------------------------------------------------------------
711 | " Pass 2: Perform Alignment
712 | let prepad = strpart(alignprepad,0,1)
713 | let postpad = strpart(alignpostpad,0,1)
714 | let alignprepad = strpart(alignprepad,1).strpart(alignprepad,0,1)
715 | let alignpostpad = strpart(alignpostpad,1).strpart(alignpostpad,0,1)
716 | let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','')
717 | if s:AlignLeadKeep == 'W'
718 | let field = bgntxt.field
719 | let bgntxt= ""
720 | endif
721 | if doend == 2
722 | let prepad = 0
723 | let postpad= 0
724 | endif
725 | let fieldlen = s:Strlen(field)
726 | let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad)
727 | if seplen < SepSize_{ifield}
728 | if alignsepop == "<"
729 | " left-justify separators
730 | let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen)
731 | elseif alignsepop == ">"
732 | " right-justify separators
733 | let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep
734 | else
735 | " center-justify separators
736 | let sepleft = (SepSize_{ifield} - seplen)/2
737 | let sepright = SepSize_{ifield} - seplen - sepleft
738 | let sep = s:MakeSpace(sepleft).sep.s:MakeSpace(sepright)
739 | endif
740 | endif
741 | let spaces = FieldSize_{ifield} - fieldlen
742 | " call Decho("Pass".pass.": Field #".ifield."<".field."> spaces=".spaces." be[".bgnfield.",".endfield."] pad=".prepad.','.postpad." FS_".ifield."<".FieldSize_{ifield}."> sep<".sep."> ragged=".ragged." doend=".doend." alignop<".alignop.">")
743 |
744 | " Perform alignment according to alignment style justification
745 | if spaces > 0
746 | if alignop == 'c'
747 | " center the field
748 | let spaceleft = spaces/2
749 | let spaceright= FieldSize_{ifield} - spaceleft - fieldlen
750 | let newtxt = newtxt.s:MakeSpace(spaceleft).field.s:MakeSpace(spaceright).sep
751 | elseif alignop == 'r'
752 | " right justify the field
753 | let newtxt= newtxt.s:MakeSpace(spaces).field.sep
754 | elseif ragged && doend == 2
755 | " left justify rightmost field (no trailing blanks needed)
756 | let newtxt= newtxt.field
757 | else
758 | " left justfiy the field
759 | let newtxt= newtxt.field.s:MakeSpace(spaces).sep
760 | endif
761 | elseif ragged && doend == 2
762 | " field at maximum field size and no trailing blanks needed
763 | let newtxt= newtxt.field
764 | else
765 | " field is at maximum field size already
766 | let newtxt= newtxt.field.sep
767 | endif
768 | " call Decho("Pass".pass.": newtxt<".newtxt.">")
769 | endif " pass 1/2
770 |
771 | " bgnfield indexes to end of separator at right of current field
772 | " Update field counter
773 | let bgnfield= sepfield
774 | let ifield = ifield + 1
775 | if doend == 2
776 | let doend= 0
777 | endif
778 | " handle end-of-text as end-of-field
779 | elseif doend == 1
780 | let seppat = '$'
781 | let doend = 2
782 | else
783 | let doend = 0
784 | endif " endfield != -1
785 | endwhile " doend loop (as well as regularly separated fields)
786 |
787 | if pass == 2
788 | " Write altered line to buffer
789 | " call Decho("Pass".pass.": bgntxt<".bgntxt."> line=".line)
790 | " call Decho("Pass".pass.": newtxt<".newtxt.">")
791 | " call Decho("Pass".pass.": endtxt<".endtxt.">")
792 | keepj call setline(line,bgntxt.newtxt.endtxt)
793 | endif
794 |
795 | let line = line + 1
796 | endwhile " line loop
797 |
798 | let pass= pass + 1
799 | endwhile " pass loop
800 | " call Decho("end of two pass loop")
801 |
802 | " restore original leading whitespace
803 | if s:AlignLeadKeep == 'W'
804 | let iline= begline
805 | let i = 0
806 | " call Decho("restore original leading whitespace")
807 | while iline <= endline
808 | " call Decho("exe ".iline."s/^".wsblanks[i]."/".wskeep[i]."/")
809 | exe "keepj ".iline."s/^".wsblanks[i]."/".wskeep[i]."/"
810 | let iline= iline + 1
811 | let i = i + 1
812 | endwhile
813 | endif
814 |
815 | if exists("s:DoAlignPop")
816 | " AlignCtrl Map support
817 | call Align#AlignPop()
818 | unlet s:DoAlignPop
819 | endif
820 |
821 | " restore user options and return
822 | call s:RestoreUserOptions()
823 | " call Dret("Align#Align")
824 | return
825 | endfun
826 |
827 | " ---------------------------------------------------------------------
828 | " Align#AlignPush: this command/function pushes an alignment control string onto a stack {{{1
829 | fun! Align#AlignPush()
830 | " call Dfunc("Align#AlignPush()")
831 |
832 | " initialize the stack
833 | if !exists("s:AlignCtrlStackQty")
834 | let s:AlignCtrlStackQty= 1
835 | else
836 | let s:AlignCtrlStackQty= s:AlignCtrlStackQty + 1
837 | endif
838 |
839 | " construct an AlignCtrlStack entry
840 | if !exists("s:AlignSep")
841 | let s:AlignSep= ''
842 | endif
843 | let s:AlignCtrlStack_{s:AlignCtrlStackQty}= s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle.s:AlignSep
844 | " call Decho("AlignPush: AlignCtrlStack_".s:AlignCtrlStackQty."<".s:AlignCtrlStack_{s:AlignCtrlStackQty}.">")
845 |
846 | " push [GV] patterns onto their own stack
847 | if exists("s:AlignGPat")
848 | let s:AlignGPat_{s:AlignCtrlStackQty}= s:AlignGPat
849 | else
850 | let s:AlignGPat_{s:AlignCtrlStackQty}= ""
851 | endif
852 | if exists("s:AlignVPat")
853 | let s:AlignVPat_{s:AlignCtrlStackQty}= s:AlignVPat
854 | else
855 | let s:AlignVPat_{s:AlignCtrlStackQty}= ""
856 | endif
857 |
858 | " call Dret("Align#AlignPush")
859 | endfun
860 |
861 | " ---------------------------------------------------------------------
862 | " Align#AlignPop: this command/function pops an alignment pattern from a stack {{{1
863 | " and into the AlignCtrl variables.
864 | fun! Align#AlignPop()
865 | " call Dfunc("Align#AlignPop()")
866 |
867 | " sanity checks
868 | if !exists("s:AlignCtrlStackQty")
869 | echoerr "(AlignPop) AlignPush needs to be used prior to AlignPop"
870 | " call Dret("Align#AlignPop <> : AlignPush needs to have been called first")
871 | return ""
872 | endif
873 | if s:AlignCtrlStackQty <= 0
874 | unlet s:AlignCtrlStackQty
875 | echoerr "(AlignPop) AlignPush needs to be used prior to AlignPop"
876 | " call Dret("Align#AlignPop <> : AlignPop needs to have been called first")
877 | return ""
878 | endif
879 |
880 | " pop top of AlignCtrlStack and pass value to AlignCtrl
881 | let retval=s:AlignCtrlStack_{s:AlignCtrlStackQty}
882 | unlet s:AlignCtrlStack_{s:AlignCtrlStackQty}
883 | call Align#AlignCtrl(retval)
884 |
885 | " pop G pattern stack
886 | if s:AlignGPat_{s:AlignCtrlStackQty} != ""
887 | call Align#AlignCtrl('g',s:AlignGPat_{s:AlignCtrlStackQty})
888 | else
889 | call Align#AlignCtrl('g')
890 | endif
891 | unlet s:AlignGPat_{s:AlignCtrlStackQty}
892 |
893 | " pop V pattern stack
894 | if s:AlignVPat_{s:AlignCtrlStackQty} != ""
895 | call Align#AlignCtrl('v',s:AlignVPat_{s:AlignCtrlStackQty})
896 | else
897 | call Align#AlignCtrl('v')
898 | endif
899 |
900 | unlet s:AlignVPat_{s:AlignCtrlStackQty}
901 | let s:AlignCtrlStackQty= s:AlignCtrlStackQty - 1
902 |
903 | " call Dret("Align#AlignPop <".retval."> : AlignCtrlStackQty=".s:AlignCtrlStackQty)
904 | return retval
905 | endfun
906 |
907 | " ---------------------------------------------------------------------
908 | " Align#AlignReplaceQuotedSpaces: {{{1
909 | fun! Align#AlignReplaceQuotedSpaces()
910 | " call Dfunc("Align#AlignReplaceQuotedSpaces()")
911 |
912 | let l:line = getline(line("."))
913 | let l:linelen = s:Strlen(l:line)
914 | let l:startingPos = 0
915 | let l:startQuotePos = 0
916 | let l:endQuotePos = 0
917 | let l:spacePos = 0
918 | let l:quoteRe = '\\\@, is needed. {{{1
949 | " However, doesn't split at all, so this function returns a list
950 | " of arguments which has been:
951 | " * split at whitespace
952 | " * unless inside "..."s. One may escape characters with a backslash inside double quotes.
953 | " along with a leading length-of-list.
954 | "
955 | " Examples: %Align "\"" will align on "s
956 | " %Align " " will align on spaces
957 | "
958 | " The resulting list: qarglist[0] corresponds to a:0
959 | " qarglist[i] corresponds to a:{i}
960 | fun! s:QArgSplitter(qarg)
961 | " call Dfunc("s:QArgSplitter(qarg<".a:qarg.">)")
962 |
963 | if a:qarg =~ '".*"'
964 | " handle "..." args, which may include whitespace
965 | let qarglist = []
966 | let args = a:qarg
967 | " call Decho("handle quoted arguments: args<".args.">")
968 | while args != ""
969 | let iarg = 0
970 | let arglen = strlen(args)
971 | " call Decho(".args[".iarg."]<".args[iarg]."> arglen=".arglen)
972 | " find index to first not-escaped '"'
973 | " call Decho("find index to first not-escaped \"")
974 | while args[iarg] != '"' && iarg < arglen
975 | if args[iarg] == '\'
976 | let args= strpart(args,1)
977 | endif
978 | let iarg= iarg + 1
979 | endwhile
980 | " call Decho(".args<".args."> iarg=".iarg." arglen=".arglen)
981 |
982 | if iarg > 0
983 | " handle left of quote or remaining section
984 | " call Decho(".handle left of quote or remaining section")
985 | if args[iarg] == '"'
986 | let qarglist= qarglist + split(strpart(args,0,iarg-1))
987 | else
988 | let qarglist= qarglist + split(strpart(args,0,iarg))
989 | endif
990 | let args = strpart(args,iarg)
991 | let arglen = strlen(args)
992 |
993 | elseif iarg < arglen && args[0] == '"'
994 | " handle "quoted" section
995 | " call Decho(".handle quoted section")
996 | let iarg= 1
997 | while args[iarg] != '"' && iarg < arglen
998 | if args[iarg] == '\'
999 | let args= strpart(args,1)
1000 | endif
1001 | let iarg= iarg + 1
1002 | endwhile
1003 | " call Decho(".args<".args."> iarg=".iarg." arglen=".arglen)
1004 | if args[iarg] == '"'
1005 | call add(qarglist,strpart(args,1,iarg-1))
1006 | let args= strpart(args,iarg+1)
1007 | else
1008 | let qarglist = qarglist + split(args)
1009 | let args = ""
1010 | endif
1011 | endif
1012 | " call Decho(".qarglist".string(qarglist)." iarg=".iarg." args<".args.">")
1013 | endwhile
1014 | " call Decho("end of loop (handling quoted arguments)")
1015 |
1016 | else
1017 | " split at all whitespace
1018 | " call Decho("split at all whitespace")
1019 | let qarglist= split(a:qarg,"[ \t]")
1020 | endif
1021 |
1022 | let qarglistlen= len(qarglist)
1023 | let qarglist = insert(qarglist,qarglistlen)
1024 | " call Dret("s:QArgSplitter ".string(qarglist))
1025 | return qarglist
1026 | endfun
1027 |
1028 | " ---------------------------------------------------------------------
1029 | " s:Strlen: this function returns the length of a string, even if its {{{1
1030 | " using two-byte etc characters.
1031 | " Currently, its only used if g:Align_xstrlen is set to a
1032 | " nonzero value. Solution from Nicolai Weibull, vim docs
1033 | " (:help strlen()), Tony Mechelynck, and my own invention.
1034 | fun! s:Strlen(x)
1035 | " call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen)
1036 |
1037 | if type(g:Align_xstrlen) == 1
1038 | " allow user to specify a function to compute the string length
1039 | exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
1040 |
1041 | elseif g:Align_xstrlen == 1
1042 | " number of codepoints (Latin a + combining circumflex is two codepoints)
1043 | " (comment from TM, solution from NW)
1044 | let ret= strlen(substitute(a:x,'.','c','g'))
1045 |
1046 | elseif g:Align_xstrlen == 2
1047 | " number of spacing codepoints (Latin a + combining circumflex is one spacing
1048 | " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
1049 | " (comment from TM, solution from TM)
1050 | let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
1051 |
1052 | elseif g:Align_xstrlen == 3
1053 | " virtual length (counting, for instance, tabs as anything between 1 and
1054 | " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
1055 | " preceded by lam, one otherwise, etc.)
1056 | " (comment from TM, solution from me)
1057 | let modkeep= &l:mod
1058 | exe "norm! o\"
1059 | call setline(line("."),a:x)
1060 | let ret= virtcol("$") - 1
1061 | d
1062 | let &l:mod= modkeep
1063 |
1064 | else
1065 | " at least give a decent default
1066 | if v:version >= 703
1067 | let ret= strdisplaywidth(a:x)
1068 | else
1069 | let ret= strlen(a:x)
1070 | endif
1071 | endif
1072 | " call Dret("s:Strlen ".ret)
1073 | return ret
1074 | endfun
1075 |
1076 | " ---------------------------------------------------------------------
1077 | " s:SaveUserOptions: {{{1
1078 | fun! s:SaveUserOptions()
1079 | " call Dfunc("s:SaveUserOptions() s:saved_user_options=".(exists("s:saved_user_options")? s:saved_user_options : 'n/a'))
1080 | if !exists("s:saved_user_options")
1081 | let s:saved_user_options = 1
1082 | let s:keep_search = @/
1083 | let s:keep_et = &l:et
1084 | let s:keep_hls = &hls
1085 | let s:keep_ic = &ic
1086 | let s:keep_paste = &paste
1087 | let s:keep_report = &report
1088 | else
1089 | let s:saved_user_options = s:saved_user_options + 1
1090 | endif
1091 | " call Dret("s:SaveUserOptions : s:saved_user_options=".s:saved_user_options)
1092 | endfun
1093 |
1094 | " ---------------------------------------------------------------------
1095 | " s:RestoreUserOptions: {{{1
1096 | fun! s:RestoreUserOptions()
1097 | " call Dfunc("s:RestoreUserOptions() s:saved_user_options=".(exists("s:saved_user_options")? s:saved_user_options : 'n/a'))
1098 | if exists("s:saved_user_options") && s:saved_user_options == 1
1099 | let @/ = s:keep_search
1100 | let &l:et = s:keep_et
1101 | let &hls = s:keep_hls
1102 | let &ic = s:keep_ic
1103 | let &paste = s:keep_paste
1104 | let &report = s:keep_report
1105 | unlet s:keep_search
1106 | unlet s:keep_et
1107 | unlet s:keep_hls
1108 | unlet s:keep_ic
1109 | unlet s:keep_paste
1110 | unlet s:keep_report
1111 | unlet s:saved_user_options
1112 | elseif exists("s:saved_user_options")
1113 | let s:saved_user_options= s:saved_user_options - 1
1114 | endif
1115 | " call Dret("s:RestoreUserOptions : s:saved_user_options=".(exists("s:saved_user_options")? s:saved_user_options : 'n/a'))
1116 | endfun
1117 |
1118 | " ---------------------------------------------------------------------
1119 | " Set up default values: {{{1
1120 | "call Decho("-- Begin AlignCtrl Initialization --")
1121 | call Align#AlignCtrl("default")
1122 | "call Decho("-- End AlignCtrl Initialization --")
1123 |
1124 | " ---------------------------------------------------------------------
1125 | " Restore: {{{1
1126 | let &cpo= s:keepcpo
1127 | unlet s:keepcpo
1128 | " vim: ts=4 fdm=marker
1129 |
--------------------------------------------------------------------------------
/vim/bundle/align/doc/Align.txt:
--------------------------------------------------------------------------------
1 | *align.txt* The Alignment Tool Jun 18, 2012
2 |
3 | Author: Charles E. Campbell
4 | (remove NOSPAM from Campbell's email first)
5 | Copyright: (c) 2004-2012 by Charles E. Campbell *Align-copyright*
6 | The VIM LICENSE applies to Align.vim, AlignMaps.vim, and Align.txt
7 | (see |copyright|) except use "Align and AlignMaps" instead of "Vim"
8 | NO WARRANTY, EXPRESS OR IMPLIED. USE AT-YOUR-OWN-RISK.
9 |
10 | ==============================================================================
11 | 1. Contents *align* *align-contents* {{{1
12 |
13 | 1. Contents.................: |align-contents|
14 | 2. Alignment Manual.........: |align-manual|
15 | 3. Alignment Usage..........: |align-usage|
16 | Alignment Concepts.......: |align-concepts|
17 | Alignment Commands.......: |align-commands|
18 | Alignment Control........: |align-control|
19 | Separators.............: |alignctrl-separators|
20 | Initial Whitespace.....: |alignctrl-w| |alignctrl-W| |alignctrl-I|
21 | Justification..........: |alignctrl-l| |alignctrl-r| |alignctrl-c|
22 | Justification Control..: |alignctrl--| |alignctrl-+| |alignctrl-:|
23 | Cyclic/Sequential......: |alignctrl-=| |alignctrl-C|
24 | Separator Justification: |alignctrl-<| |alignctrl->| |alignctrl-||
25 | Line (de)Selection.....: |alignctrl-g| |alignctrl-v|
26 | Temporary Settings.....: |alignctrl-m|
27 | Padding................: |alignctrl-p| |alignctrl-P|
28 | Current Options........: |alignctrl-settings| |alignctrl-|
29 | Alignment Control Init...: |alignctrl-init|
30 | Alignment................: |align-align|
31 | 4. Alignment Maps...........: |align-maps|
32 | \a,....................: |alignmap-a,|
33 | \a?....................: |alignmap-a?|
34 | \a<....................: |alignmap-a<|
35 | \abox..................: |alignmap-abox|
36 | \acom..................: |alignmap-acom|
37 | \anum..................: |alignmap-anum|
38 | \ascom.................: |alignmap-ascom|
39 | \adec..................: |alignmap-adec|
40 | \adef..................: |alignmap-adef|
41 | \afnc..................: |alignmap-afnc|
42 | \adcom.................: |alignmap-adcom|
43 | \aocom.................: |alignmap-aocom|
44 | \tsp...................: |alignmap-tsp|
45 | \tsq...................: |alignmap-tsq|
46 | \tt....................: |alignmap-tt|
47 | \t=....................: |alignmap-t=|
48 | \T=....................: |alignmap-T=|
49 | \Htd...................: |alignmap-Htd|
50 | 5. Alignment Tool History...: |align-history|
51 |
52 | ==============================================================================
53 | 2. Align Manual *alignman* *alignmanual* *align-manual* {{{1
54 |
55 | Align comes as a vimball; simply typing >
56 | vim Align.vba.gz
57 | :so %
58 | < should put its components where they belong. The components are: >
59 | .vim/plugin/AlignPlugin.vim
60 | .vim/plugin/AlignMapsPlugin.vim
61 | .vim/plugin/cecutil.vim
62 | .vim/autoload/Align.vim
63 | .vim/autoload/AlignMaps.vim
64 | .vim/doc/Align.txt
65 | < To see a user's guide, see |align-userguide|
66 | To see examples, see |alignctrl| and |alignmaps|
67 | >
68 | /=============+=========+=====================================================\
69 | || \ Default/ ||
70 | || Commands \ Value/ Explanation ||
71 | || | | ||
72 | ++==============+====+=======================================================++
73 | || AlignCtrl | | =Clrc-+:pPIWw [..list-of-separator-patterns..] ||
74 | || | +-------------------------------------------------------+|
75 | || | | may be called as a command or as a function: ||
76 | || | | :AlignCtrl =lp0P0W & \\ ||
77 | || | | :call Align#AlignCtrl('=lp0P0W','&','\\') ||
78 | || | | ||
79 | || | +-------------------------------------------------------++
80 | || 1st arg | = | = all separator patterns are equivalent and are ||
81 | || | | simultaneously active. Patterns are |regexp|. ||
82 | || | | C cycle through separator patterns. Patterns are ||
83 | || | | |regexp| and are active sequentially. ||
84 | || | | ||
85 | || | < | < left justify separator Separators are justified, ||
86 | || | | > right justify separator too. Separator styles ||
87 | || | | | center separator are cyclic. ||
88 | || | | ||
89 | || | l | l left justify Justification styles are always ||
90 | || | | r right justify cyclic (ie. lrc would mean left j., ||
91 | || | | c center then right j., then center, repeat. ||
92 | || | | - skip this separator ||
93 | || | | + re-use last justification method ||
94 | || | | : treat rest of text as a field ||
95 | || | | * use AlignSkip() function (to skip or not) ||
96 | || | | ||
97 | || | p1 | p### pad separator on left by # blanks ||
98 | || | P1 | P### pad separator on right by # blanks ||
99 | || | | ||
100 | || | I | I preserve and apply first line's leading white ||
101 | || | | space to all lines ||
102 | || | | W preserve leading white space on every line, even ||
103 | || | | if it varies from line to line ||
104 | || | | w don't preserve leading white space ||
105 | || | | ||
106 | || | | g second argument is a selection pattern -- only ||
107 | || | | align on lines that have a match (inspired by ||
108 | || | | :g/selection pattern/command) ||
109 | || | | v second argument is a selection pattern -- only ||
110 | || | | align on lines that _don't_ have a match (inspired ||
111 | || | | by :v/selection pattern/command) ||
112 | || | | ||
113 | || | | m Map support: AlignCtrl will immediately do an ||
114 | || | | AlignPush() and the next call to Align() will do ||
115 | || | | an AlignPop at the end. This feature allows maps ||
116 | || | | to preserve user settings. ||
117 | || | | ||
118 | || | | default ||
119 | || | | AlignCtrl default ||
120 | || | | will clear the AlignCtrl ||
121 | || | | stack & set the default: AlignCtrl "Ilp1P1=" '=' ||
122 | || | | ||
123 | || +----+-------------------------------------------------------+|
124 | || More args | More arguments are interpreted as describing separators ||
125 | || +------------------------------------------------------------+|
126 | || No args | AlignCtrl will display its current settings ||
127 | ||==============+============================================================+|
128 | ||[range]Align | [..list-of-separators..] ||
129 | ||[range]Align! | [AlignCtrl settings] [..list-of-separators..] ||
130 | || +------------------------------------------------------------+|
131 | || | Aligns text over the given range. The range may be ||
132 | || | selected via visual mode (v, V, or ctrl-v) or via ||
133 | || | the command line. The Align operation may be invoked ||
134 | || | as a command or as a function; as a function, the first ||
135 | || | argument is 0=separators only, 1=AlignCtrl option string ||
136 | || | followed by a list of separators. ||
137 | || | :[range]Align ||
138 | || | :[range]Align [list of separators] ||
139 | || | :[range]call Align#Align(0) ||
140 | || | :[range]call Align#Align(0,"list","of","separators",...) ||
141 | \=============================================================================/
142 |
143 | ==============================================================================
144 | 3. Alignment Usage *alignusage* *align-usage* *align-userguide* {{{1
145 |
146 |
147 | ALIGNMENT CONCEPTS *align-concept* *align-concepts* {{{2
148 |
149 | The typical text to be aligned is considered to be:
150 |
151 | * composed of two or more fields
152 | * separated by one or more separator pattern(s):
153 | * two or more lines
154 | >
155 | ws field ws separator ws field ws separator ...
156 | ws field ws separator ws field ws separator ...
157 | <
158 | where "ws" stands for "white space" such as blanks and/or tabs,
159 | and "fields" are arbitrary text. For example, consider >
160 |
161 | x= y= z= 3;
162 | xx= yy= zz= 4;
163 | zzz= yyy= zzz= 5;
164 | a= b= c= 3;
165 | <
166 | Assume that it is desired to line up all the "=" signs; these,
167 | then, are the separators. The fields are composed of all the
168 | alphameric text. Assuming they lie on lines 1-4, one may align
169 | those "=" signs with: >
170 | :AlignCtrl l
171 | :1,4Align =
172 | < The result is: >
173 | x = y = z = 3;
174 | xx = yy = zz = 4;
175 | zzz = yyy = zzz = 5;
176 | a = b = c = 3;
177 |
178 | < Note how each "=" sign is surrounded by a single space; the
179 | default padding is p1P1 (p1 means one space before the separator,
180 | and P1 means one space after it). If you wish to change the
181 | padding, say, to no padding, use (see |alignctrl-p|) >
182 |
183 | :AlignCtrl lp0P0
184 |
185 | < Next, note how each field is left justified; that's what the "l"
186 | in the AlignCtrl parameters (a small letter "ell") does. If
187 | right-justification of the fields had been desired, an "r"
188 | could've been used: >
189 | :AlignCtrl r
190 | < yielding >
191 | x = y = z = 3;
192 | xx = yy = zz = 4;
193 | zzz = yyy = zzz = 5;
194 | a = b = c = 3;
195 | < There are many more options available for field justification: see
196 | |alignctrl-c| and |alignctrl--|.
197 |
198 | Separators, although commonly only one character long, are actually
199 | specified by regular expressions (see |regexp|), and one may left
200 | justify, right justify, or center them, too (see |alignctrl-<|).
201 |
202 | Assume that for some reason a left-right-left-right-... justification
203 | sequence was desired. This wish is simply achieved with >
204 | :AlignCtrl lr
205 | :1,4Align =
206 | < because the justification commands are considered to be "cyclic"; ie.
207 | lr is the same as lrlrlrlrlrlrlr...
208 |
209 | There's a lot more discussed under |alignctrl|; hopefully the examples
210 | there will help, too.
211 |
212 |
213 | ALIGNMENT COMMANDS *align-command* *align-commands* {{{2
214 |
215 | The script includes two primary commands and two
216 | minor commands:
217 |
218 | AlignCtrl : this command/function sets up alignment options
219 | which persist until changed for later Align calls.
220 | It controls such things as: how to specify field
221 | separators, initial white space, padding about
222 | separators, left/right/center justification, etc. >
223 | ex. AlignCtrl wp0P1
224 | Interpretation: during subsequent alignment
225 | operations, preserve each line's initial
226 | whitespace. Use no padding before separators
227 | but provide one padding space after separators.
228 | <
229 | Align : this command/function operates on the range given it to
230 | align text based on one or more separator patterns. The
231 | patterns may be provided via AlignCtrl or via Align
232 | itself. >
233 |
234 | ex. :%Align ,
235 | Interpretation: align all commas over the entire
236 | file.
237 | < The :Align! format permits alignment control commands
238 | to precede the alignment patterns. >
239 | ex. :%Align! p2P2 =
240 | < This will align all "=" in the file with two padding
241 | spaces on both sides of each "=" sign.
242 |
243 | NOTE ON USING PATTERNS WITH ALIGN:~
244 | Align and AlignCtrl use || to obtain their
245 | input patterns and they use an internal function to
246 | split arguments at whitespace unless inside "..."s.
247 | One may escape characters inside a double-quote string
248 | by preceding such characters with a backslash.
249 |
250 | AlignPush : this command/function pushes the current AlignCtrl
251 | state onto an internal stack. >
252 | ex. :AlignPush
253 | Interpretation: save the current AlignCtrl
254 | settings, whatever they may be. They'll
255 | also remain as the current settings until
256 | AlignCtrl is used to change them.
257 | <
258 | AlignPop : this command/function pops the current AlignCtrl
259 | state from an internal stack. >
260 | ex. :AlignPop
261 | Interpretation: presumably AlignPush was
262 | used (at least once) previously; this command
263 | restores the AlignCtrl settings when AlignPush
264 | was last used.
265 | < Also see |alignctrl-m| for a way to automatically do
266 | an AlignPop after an Align (primarily this is for maps).
267 |
268 | ALIGNMENT OPTIONS *align-option* *align-options* *align-xstrlen* {{{2
269 | *align-utf8* *align-utf* *align-codepoint* *align-strlen* *align-multibyte*
270 |
271 | For those of you who are using 2-byte (or more) characters such as are
272 | available with utf-8, Align now provides a special option which you
273 | may choose based upon your needs:
274 |
275 | Use Built-in strlen() ~
276 | >
277 | let g:Align_xstrlen= 0
278 |
279 | < This is the fastest method, but it doesn't handle multibyte characters
280 | well. It is the default for:
281 |
282 | enc=latin1
283 | vim compiled without multi-byte support
284 | $LANG is en_US.UTF-8 (assuming USA english)
285 |
286 | Number of codepoints (Latin a + combining circumflex are two codepoints)~
287 | >
288 | let g:Align_xstrlen= 1 (default)
289 | <
290 | Number of spacing codepoints (Latin a + combining circumflex is one~
291 | spacing codepoint; a hard tab is one; wide and narrow CJK are one~
292 | each; etc.)~
293 | >
294 | let g:Align_xstrlen= 2
295 | <
296 | Virtual length (counting, for instance, tabs as anything between 1 and~
297 | 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when~
298 | immediately preceded by lam, one otherwise, etc.)~
299 | >
300 | let g:Align_xstrlen= 3
301 | <
302 | User may specify a function to compute the string length~
303 | >
304 | let g:Align_xstrlen= "strlen"
305 | < This method will cause Align to call upon the named function returning
306 | string length. it should resemble the |strlen()| function, taking one
307 | argument (the string) for input and returning the string length.
308 |
309 | By putting one of these settings into your <.vimrc>, Align will use an
310 | internal (interpreted) function to determine a string's length instead
311 | of Vim's built-in |strlen()| function. Since the function is
312 | interpreted, Align will run a bit slower but will handle such strings
313 | correctly. The last settings (g:Align_xstrlen= 3 and
314 | g:Align_xstrlen="userfuncname") probably will run the slowest but be
315 | the most accurate. (thanks to Tony Mechelynck for these)
316 |
317 |
318 | ALIGNMENT CONTROL *alignctrl* *align-control* {{{2
319 |
320 | This command doesn't do the alignment operation itself; instead, it
321 | controls subsequent alignment operation(s).
322 |
323 | The first argument to AlignCtrl is a string which may contain one or
324 | more alignment control settings. Most of the settings are specified
325 | by single letters; the exceptions are the p# and P# commands which
326 | interpret a digit following the p or P as specifying padding about the
327 | separator.
328 |
329 | The typical text line is considered to be composed of two or more
330 | fields separated by one or more separator pattern(s): >
331 |
332 | ws field ws separator ws field ws separator ...
333 | <
334 | where "ws" stands for "white space" such as blanks and/or tabs.
335 |
336 |
337 | SEPARATORS *alignctrl-separators* {{{3
338 |
339 | As a result, separators may not have white space (tabs or blanks) on
340 | their outsides (ie. ": :" is fine as a separator, but " :: " is
341 | not). Usually such separators are not needed, although a map has been
342 | provided which works around this limitation and aligns on whitespace
343 | (see |alignmap-tsp|).
344 |
345 | However, if you really need to have separators with leading or
346 | trailing whitespace, consider handling them by performing a substitute
347 | first (ie. s/ :: /@/g), do the alignment on the temporary pattern
348 | (ie. @), and then perform a substitute to revert the separators back
349 | to their desired condition (ie. s/@/ :: /g).
350 |
351 | The Align#Align() function (which is invoked by the :Align command)
352 | will first convert tabs over the region into spaces and then apply
353 | alignment control. Except for initial white space, white space
354 | surrounding the fields is ignored. One has three options just for
355 | handling initial white space:
356 |
357 |
358 | --- *alignctrl-w*
359 | wWI INITIAL WHITE SPACE *alignctrl-W* {{{3
360 | --- *alignctrl-I*
361 | w : ignore all selected lines' initial white space
362 | W : retain all selected lines' initial white space
363 | I : retain only the first line's initial white space and
364 | re-use it for subsequent lines
365 |
366 | Example: Leading white space options: >
367 | +---------------+-------------------+-----------------+
368 | |AlignCtrl w= :=| AlignCtrl W= := | AlignCtrl I= := |
369 | +------------------+---------------+-------------------+-----------------+
370 | | Original | w option | W option | I option |
371 | +------------------+---------------+-------------------+-----------------+
372 | | a := baaa |a := baaa | a := baaa | a := baaa |
373 | | caaaa := deeee |caaaa := deeee | caaaa := deeee | caaaa := deeee|
374 | | ee := f |ee := f | ee := f | ee := f |
375 | +------------------+---------------+-------------------+-----------------+
376 | <
377 | The original has at least one leading white space on every line.
378 | Using Align with w eliminated each line's leading white space.
379 | Using Align with W preserved each line's leading white space.
380 | Using Align with I applied the first line's leading white space
381 | (three spaces) to each line.
382 |
383 |
384 | ------ *alignctrl-l*
385 | lrc-+: FIELD JUSTIFICATION *alignctrl-r* {{{3
386 | ------ *alignctrl-c*
387 |
388 | With "lrc", the fields will be left-justified, right-justified, or
389 | centered as indicated by the justification specifiers (lrc). The
390 | "lrc" options are re-used by cycling through them as needed:
391 |
392 | l means llllll....
393 | r means rrrrrr....
394 | lr means lrlrlr....
395 | llr means llrllr....
396 |
397 | Example: Justification options: Align = >
398 | +------------+-------------------+-------------------+-------------------+
399 | | Original | AlignCtrl l | AlignCtrl r | AlignCtrl lr |
400 | +------------+-------------------+-------------------+-------------------+
401 | | a=bb=ccc=1 |a = bb = ccc = 1| a = bb = ccc = 1|a = bb = ccc = 1|
402 | | ccc=a=bb=2 |ccc = a = bb = 2|ccc = a = bb = 2|ccc = a = bb = 2|
403 | | dd=eee=f=3 |dd = eee = f = 3| dd = eee = f = 3|dd = eee = f = 3|
404 | +------------+-------------------+-------------------+-------------------+
405 | | Alignment |l l l l| r r r r|l r l r|
406 | +------------+-------------------+-------------------+-------------------+
407 | <
408 | AlignCtrl l : The = separator is repeatedly re-used, as the
409 | cycle only consists of one character (the "l").
410 | Every time left-justification is used for fields.
411 | AlignCtrl r : The = separator is repeatedly re-used, as the
412 | cycle only consists of one character (the "r").
413 | Every time right-justification is used for fields
414 | AlignCtrl lr: Again, the "=" separator is repeatedly re-used,
415 | but the fields are justified alternately between
416 | left and right.
417 |
418 | Even more separator control is available! With "-+:":
419 |
420 | - : skip treating the separator as a separator. *alignctrl--*
421 | + : repeat use of the last "lrc" justification *alignctrl-+*
422 | : : treat the rest of the line as a single field *alignctrl-:*
423 | * : like -, but only if g:AlignSkip() returns true *alignctrl-star*
424 | (see |alignctrl-alignskip|)
425 |
426 | Example: More justification options: Align = >
427 | +------------+---------------+--------------------+---------------+
428 | | Original | AlignCtrl -l | AlignCtrl rl+ | AlignCtrl l: |
429 | +------------+---------------+--------------------+---------------+
430 | | a=bb=ccc=1 |a=bb = ccc=1 | a = bb = ccc = 1 |a = bb=ccc=1 |
431 | | ccc=a=bb=2 |ccc=a = bb=2 |ccc = a = bb = 2 |ccc = a=bb=2 |
432 | | dd=eee=f=3 |dd=eee = f=3 | dd = eee = f = 3 |dd = eee=f=3 |
433 | +------------+---------------+--------------------+---------------+
434 | | Alignment |l l | r l l l |l l |
435 | +------------+---------------+--------------------+---------------+
436 | <
437 | In the first example in "More justification options":
438 |
439 | The first "=" separator is skipped by the "-" specification,
440 | and so "a=bb", "ccc=a", and "dd=eee" are considered as single fields.
441 |
442 | The next "=" separator has its (left side) field left-justified.
443 | Due to the cyclic nature of separator patterns, the "-l"
444 | specification is equivalent to "-l-l-l ...".
445 |
446 | Hence the next specification is a "skip", so "ccc=1", etc are fields.
447 |
448 | In the second example in "More justification options":
449 |
450 | The first field is right-justified, the second field is left
451 | justified, and all remaining fields repeat the last justification
452 | command (ie. they are left justified, too).
453 |
454 | Hence rl+ is equivalent to rlllllllll ...
455 | (whereas plain rl is equivalent to rlrlrlrlrl ... ).
456 |
457 | In the third example in "More justification options":
458 |
459 | The text following the first separator is treated as a single field.
460 |
461 | Thus using the - and : operators one can apply justification to a
462 | single separator.
463 |
464 | ex. 1st separator only: AlignCtrl l:
465 | 2nd separator only: AlignCtrl -l:
466 | 3rd separator only: AlignCtrl --l:
467 | etc.
468 |
469 | *g:AlignSkip*
470 | Align Skip Control *alignctrl-alignskip*
471 |
472 | The separator control '*' permits a function to decide whether or
473 | not a character which matches the current separator pattern should
474 | instead be skipped.
475 |
476 | 1. Define a function; example: >
477 |
478 | fun! AlignSkipString(lineno,indx)
479 | let synid = synID(a:lineno,a:indx+1,1)
480 | let synname = synIDattr(synIDtrans(synid),"name")
481 | let ret= (synname == "String")? 1 : 0
482 | return ret
483 | endfun
484 | <
485 | Input: lineno: current line number
486 | indx : index to character; leftmost character
487 | in the line has an indx of 0 (like |strpart()|)
488 | Output: 0 : if separator is ok
489 | 1 : skip separator like it was a '-'
490 |
491 | 2. Set up |g:AlignSkip| as a function reference (see |Funcref|): >
492 |
493 | let g:AlignSkip= function("AlignSkipString")
494 | <
495 | 3. Use * as a separator control where a separator potentially should
496 | be skipped over.
497 |
498 |
499 | --- *alignctrl-=*
500 | =C CYCLIC VS ALL-ACTIVE SEPARATORS *alignctrl-C* {{{3
501 | ---
502 |
503 | The separators themselves may be considered as equivalent and
504 | simultaneously active ("=") or sequentially cycled through ("C").
505 | Separators are regular expressions (|regexp|) and are specified as the
506 | second, third, etc arguments. When the separator patterns are
507 | equivalent and simultaneously active, there will be one pattern
508 | constructed: >
509 |
510 | AlignCtrl ... pat1 pat2 pat3
511 | < becomes >
512 | \(pat1\|pat2\|pat3\)
513 | < (ie. pat1 -or- pat2 -or- pat3; see |/bar|)
514 |
515 | Each separator pattern is thus equivalent and simultaneously active.
516 | The cyclic separator AlignCtrl option stores a list of patterns, only
517 | one of which is active for each field at a time.
518 |
519 | Example: Equivalent/Simultaneously-Active vs Cyclic Separators >
520 | +-------------+------------------+---------------------+----------------------+
521 | | Original | AlignCtrl = = + -| AlignCtrl = = | AlignCtrl C = + - |
522 | +-------------+------------------+---------------------+----------------------+
523 | |a = b + c - d|a = b + c - d |a = b + c - d |a = b + c - d |
524 | |x = y = z + 2|x = y = z + 2 |x = y = z + 2|x = y = z + 2 |
525 | |w = s - t = 0|w = s - t = 0 |w = s - t = 0 |w = s - t = 0 |
526 | +-------------+------------------+---------------------+----------------------+
527 | <
528 | The original is initially aligned with all operators (=+-) being
529 | considered as equivalent and simultaneously active field separators.
530 | Thus the "AlignCtrl = = + -" example shows no change.
531 |
532 | The second example only accepts the '=' as a field separator;
533 | consequently "b + c - d" is now a single field.
534 |
535 | The third example illustrates cyclic field separators and is analyzed
536 | in the following illustration: >
537 |
538 | field1 separator field2 separator field3 separator field4
539 | a = b + c - d
540 | x = y = z + 2
541 | w = s - t = 0
542 | <
543 | The word "cyclic" is used because the patterns form a cycle of use; in
544 | the above case, its = + - = + - = + - = + -...
545 |
546 | Example: Cyclic separators >
547 | Label : this is some text discussing ":"s | ex. abc:def:ghi
548 | Label : this is some text with a ":" in it | ex. abc:def
549 | <
550 | apply AlignCtrl lWC : | |
551 | (select lines)Align >
552 | Label : this is some text discussing ":"s | ex. abc:def:ghi
553 | Label : this is some text with a ":" in it | ex. abcd:efg
554 | <
555 | In the current example,
556 | : is the first separator So the first ":"s are aligned
557 | | is the second separator but subsequent ":"s are not.
558 | | is the third separator The "|"s are aligned, too.
559 | : is the fourth separator Since there aren't two bars,
560 | | is the fifth separator the subsequent potential cycles
561 | | is the sixth separator don't appear.
562 | ...
563 |
564 | In this case it would probably have been a better idea to have used >
565 | AlignCtrl WCl: : |
566 | < as that alignment control would guarantee that no more cycling
567 | would be used after the vertical bar.
568 |
569 | Example: Cyclic separators
570 |
571 | Original: >
572 | a| b&c | (d|e) & f-g-h
573 | aa| bb&cc | (dd|ee) & ff-gg-hh
574 | aaa| bbb&ccc | (ddd|eee) & fff-ggg-hhh
575 | <
576 | AlignCtrl C | | & - >
577 | a | b&c | (d|e) & f - g-h
578 | aa | bb&cc | (dd|ee) & ff - gg-hh
579 | aaa | bbb&ccc | (ddd|eee) & fff - ggg-hhh
580 | <
581 | In this example,
582 | the first and second separators are "|",
583 | the third separator is "&", and
584 | the fourth separator is "-",
585 |
586 | (cycling)
587 | the fifth and sixth separators are "|",
588 | the seventh separator is "&", and
589 | the eighth separator is "-", etc.
590 |
591 | Thus the first "&"s are (not yet) separators, and hence are treated as
592 | part of the field. Ignoring white space for the moment, the AlignCtrl
593 | shown here means that Align will work with >
594 |
595 | field | field | field & field - field | field | field & field - ...
596 | <
597 |
598 | --- *alignctrl-<*
599 | <>| SEPARATOR JUSTIFICATION *alignctrl->* {{{3
600 | --- *alignctrl-|*
601 |
602 | Separators may be of differing lengths as shown in the example below.
603 | Hence they too may be justified left, right, or centered.
604 | Furthermore, separator justification specifications are cyclic:
605 |
606 | < means <<<<<... justify separator(s) to the left
607 | > means >>>>>... justify separator(s) to the right
608 | | means |||||... center separator(s)
609 |
610 | Example: Separator Justification: Align -\+ >
611 | +-----------------+
612 | | Original |
613 | +-----------------+
614 | | a - bbb - c |
615 | | aa -- bb -- ccc |
616 | | aaa --- b --- cc|
617 | +---------------------+-+-----------------+-+---------------------+
618 | | AlignCtrl < | AlignCtrl > | AlignCtrl | |
619 | +---------------------+---------------------+---------------------+
620 | | a - bbb - c | a - bbb - c | a - bbb - c |
621 | | aa -- bb -- ccc | aa -- bb -- ccc | aa -- bb -- ccc |
622 | | aaa --- b --- cc | aaa --- b --- cc | aaa --- b --- cc |
623 | +---------------------+---------------------+---------------------+
624 | <
625 |
626 | --- *alignctrl-g*
627 | gv SELECTIVE APPLICATION *alignctrl-v* {{{3
628 | ---
629 |
630 |
631 | These two options provide a way to select (g) or to deselect (v) lines
632 | based on a pattern. Ideally :g/pat/Align would work; unfortunately
633 | it results in Align#Align() being called on each line satisfying the
634 | pattern separately. >
635 |
636 | AlignCtrl g pattern
637 | <
638 | Align will only consider those lines which have the given pattern. >
639 |
640 | AlignCtrl v pattern
641 | <
642 | Align will only consider those lines without the given pattern. As an
643 | example of use, consider the following example: >
644 |
645 | :AlignCtrl v ^\s*/\*
646 | Original :Align = :Align =
647 | +----------------+------------------+----------------+
648 | |one= 2; |one = 2; |one = 2; |
649 | |three= 4; |three = 4; |three = 4; |
650 | |/* skip=this */ |/* skip = this */ |/* skip=this */ |
651 | |five= 6; |five = 6; |five = 6; |
652 | +----------------+------------------+----------------+
653 | <
654 | The first "Align =" aligned with all "="s, including the one in the
655 | "/* skip=this */" comment.
656 |
657 | The second "Align =" had a AlignCtrl v-pattern which caused it to skip
658 | (ignore) the "/* skip=this */" line when aligning.
659 |
660 | To remove AlignCtrl's g and v patterns, use (as appropriate) >
661 |
662 | AlignCtrl g
663 | AlignCtrl v
664 | <
665 | To see what g/v patterns are currently active, just use the reporting
666 | capability of an unadorned call to AlignCtrl: >
667 |
668 | AlignCtrl
669 | <
670 |
671 | ---
672 | m MAP SUPPORT *alignctrl-m* {{{3
673 | ---
674 |
675 | This option primarily supports the development of maps. The
676 | Align#AlignCtrl() call will first do an Align#AlignPush() (ie. retain
677 | current alignment control settings). The next Align#Align() will, in
678 | addition to its alignment job, finish up with an Align#AlignPop().
679 | Thus the Align#AlignCtrl settings that follow the "m" are only
680 | temporarily in effect for just the next Align#Align().
681 |
682 |
683 | ---
684 | p### *alignctrl-p*
685 | P### PADDING *alignctrl-P* {{{3
686 | ---
687 |
688 | These two options control pre-padding and post-padding with blanks
689 | about the separator. One may pad separators with zero to nine spaces;
690 | the padding number(s) is/are treated as a cyclic parameter. Thus one
691 | may specify padding separately for each field or re-use a padding
692 | pattern. >
693 |
694 | Example: AlignCtrl p102P0
695 | +---------+----------------------------------+
696 | | Original| a=b=c=d=e=f=g=h=1 |
697 | | Align = | a =b=c =d =e=f =g =h=1 |
698 | +---------+----------------------------------+
699 | | prepad | 1 0 2 1 0 2 1 0 |
700 | +---------+----------------------------------+
701 | <
702 | This example will cause Align to:
703 |
704 | pre-pad the first "=" with a single blank,
705 | pre-pad the second "=" with no blanks,
706 | pre-pad the third "=" with two blanks,
707 | pre-pad the fourth "=" with a single blank,
708 | pre-pad the fifth "=" with no blanks,
709 | pre-pad the sixth "=" with two blanks,
710 | etc.
711 |
712 | --------------- *alignctrl-settings*
713 | No option given DISPLAY STATUS *alignctrl-* {{{3
714 | --------------- *alignctrl-no-option*
715 |
716 | AlignCtrl, when called with no arguments, will display the current
717 | alignment control settings. A typical display is shown below: >
718 |
719 | AlignCtrl<=> qty=1 AlignStyle Padding<1|1>
720 | Pat1<\(=\)>
721 | <
722 | Interpreting, this means that the separator patterns are all
723 | equivalent; in this case, there's only one (qty=1). Fields will be
724 | padded on the right with spaces (left justification), and separators
725 | will be padded on each side with a single space.
726 |
727 | To change one of these items, see:
728 |
729 | AlignCtrl......|alignctrl|
730 | qty............|align-concept|
731 | AlignStyle.....|alignctrl--| |alignctrl-+| |alignctrl-:| |alignctrl-c|
732 | Padding........|alignctrl-p| |alignctrl-P|
733 |
734 | One may get a string which can be fed back into AlignCtrl: >
735 |
736 | :let alignctrl= Align#AlignCtrl()
737 | <
738 | This form will put a string describing the current AlignCtrl options,
739 | except for the "g" and "v" patterns, into a variable. The
740 | Align#AlignCtrl() function will still echo its settings, however. One
741 | can feed any non-supported "option" to AlignCtrl() to prevent this,
742 | however: >
743 |
744 | :let alignctrl= Align#AlignCtrl("d")
745 |
746 |
747 | ALIGNMENT CONTROL INITIALIZATION *alignctrl-init* *alignctrl-initialization* {{{2
748 |
749 | If you'd like to have your own default AlignCtrl, you'll be wanting to
750 | put it in a file such as: >
751 |
752 | $HOME/.vim/after/plugin/AlignPlugin.vim
753 |
754 | < Anything in that file would be sourced at startup, but after your
755 | .vimrc and after $HOME/.vim/plugin/AlignPlugin.vim; hence, :Align
756 | and :AlignCtrl will then be defined.
757 |
758 |
759 | ALIGNMENT *align-align* {{{2
760 |
761 | Once the alignment control has been determined, the user specifies a
762 | range of lines for the Align command/function to do its thing.
763 | Alignment is often done on a line-range basis, but one may also
764 | restrict alignment to a visual block using ctrl-v. For any visual
765 | mode, one types the colon (:) and then "Align". One may, of course,
766 | specify a range of lines: >
767 |
768 | :[range]Align [list-of-separators]
769 | <
770 | where the |:range| is the usual Vim-powered set of possibilities; the
771 | list of separators is the same as the AlignCtrl capability. There is
772 | only one list of separators, but either AlignCtrl or Align can be used
773 | to specify that list.
774 |
775 | An alternative form of the Align command can handle both alignment
776 | control and the separator list: >
777 |
778 | :[range]Align! [alignment-control-string] [list-of-separators]
779 | <
780 | The alignment control string will be applied only for this particular
781 | application of Align (it uses |alignctrl-m|). The "g pattern" and
782 | "v pattern" alignment controls (see |alignctrl-g| and |alignctrl-v|)
783 | are also available via this form of the Align command.
784 |
785 | Align makes two passes over the text to be aligned. The first pass
786 | determines how many fields there are and determines the maximum sizes
787 | of each field; these sizes are then stored in a vector. The second
788 | pass pads the field (left/right/centered as specified) to bring its
789 | length up to the maximum size of the field. Then the separator and
790 | its AlignCtrl-specified padding is appended.
791 |
792 | Pseudo-Code:~
793 | During pass 1
794 | | For all fields in the current line
795 | || Determine current separator
796 | || Examine field specified by current separator
797 | || Determine length of field and save if largest thus far
798 | Initialize newline based on initial whitespace option (wWI)
799 | During pass 2
800 | | For all fields in current line
801 | || Determine current separator
802 | || Extract field specified by current separator
803 | || Prepend/append padding as specified by AlignCtrl
804 | || (right/left/center)-justify to fit field into max-size field
805 | || Append separator with AlignCtrl-specified separator padding
806 | || Delete current line, install newly aligned line
807 |
808 | The g and v AlignCtrl patterns cause the passes not to consider lines
809 | for alignment, either by requiring that the g-pattern be present or
810 | that the v-pattern not be present.
811 |
812 | The whitespace on either side of a separator is ignored.
813 |
814 |
815 | ==============================================================================
816 | 4. Alignment Maps *alignmaps* *align-maps* {{{1
817 |
818 | There are a number of maps provided in the AlignMaps plugin which
819 | depend upon the Align plugin. The maps provided by AlignMaps
820 | typically start with a leading "t" (for the older "textab" program
821 | which Align supercedes) or with an "a" for the more complicated
822 | alignment maps.
823 |
824 | The AlignMaps plugin, although provided in the vimball containing
825 | Align.vim, is really a separate plugin (Align doesn't depend on
826 | AlignMaps). Consequently, if you'd rather not have AlignMaps's
827 | mappings, just use the *:AlignMapsClean* command to remove its
828 | components. The :AlignMapsClean command does not remove any maps
829 | generated by AlignMaps in the current instance of vim.
830 |
831 | The maps are shown below with a leading backslash (\). However, the
832 | actual maps use the construct (see |mapleader|), so the maps'
833 | leading kick-off character is easily customized.
834 |
835 | Furthermore, all the maps specified by the AlignMaps plugin use the
836 | construct (see ||and |usr_41.txt|). Hence, if one wishes
837 | to override the mapping(s) entirely, one may do that, too. As an
838 | example: >
839 | map ACOM AM_acom
840 | < would have \ACOM do
841 | what \acom previously did (assuming that the mapleader has been left
842 | at its default value of a backslash).
843 |
844 | \a, : useful for breaking up comma-separated
845 | declarations prior to \adec |alignmap-a,|
846 | \a( : aligns ( and , (useful for prototypes) *alignmap-a(*
847 | \a? : aligns (...)? ...:... expressions on ? and : |alignmap-a?|
848 | \a< : aligns << and >> for c++ |alignmap-a<|
849 | \a= : aligns := assignments |alignmap-a=|
850 | \abox : draw a C-style comment box around text lines |alignmap-abox|
851 | \acom : useful for aligning comments |alignmap-acom|
852 | \adcom: useful for aligning comments in declarations |alignmap-adcom|
853 | \anum : useful for aligning numbers |alignmap-anum|
854 | NOTE: For the visual-mode use of \anum, is needed!
855 | See http://mysite.verizon.net/astronaut/vim/index.html#VIS
856 | \aenum: align a European-style number |alignmap-anum|
857 | \aunum: align a USA-style number |alignmap-anum|
858 | \adec : useful for aligning declarations |alignmap-adec|
859 | \adef : useful for aligning definitions |alignmap-adef|
860 | \afnc : useful for aligning ansi-c style functions'
861 | argument lists |alignmap-afnc|
862 | \adcom: a variant of \acom, restricted to comment |alignmap-adcom|
863 | containing lines only, but also only for
864 | those which don't begin with a comment.
865 | Good for certain declaration styles.
866 | \aocom: a variant of \acom, restricted to comment |alignmap-aocom|
867 | containing lines only
868 | \tab : align a table based on tabs *alignmap-tab*
869 | (converts to spaces)
870 | \tml : useful for aligning the trailing backslashes |alignmap-tml|
871 | used to continue lines (shell programming, etc)
872 | \tsp : use Align to make a table separated by blanks |alignmap-tsp|
873 | (left justified)
874 | \ts, : like \t, but swaps whitespace on the right of *alignmap-ts,*
875 | the commas to their left
876 | \ts: : like \t: but swaps whitespace on the right of *alignmap-ts:*
877 | the colons to their left
878 | \ts< : like \t< but swaps whitespace on the right of *alignmap-ts<*
879 | the less-than signs to their left
880 | \ts= : like \t= but swaps whitespace on the right of *alignmap-ts=*
881 | the equals signs to their left
882 | \Tsp : use Align to make a table separated by blanks |alignmap-Tsp|
883 | (right justified)
884 | \tsq : use Align to make a table separated by blanks |alignmap-tsq|
885 | (left justified) -- "strings" are not split up
886 | \tt : useful for aligning LaTeX tabular tables |alignmap-tt|
887 | \Htd : tabularizes html tables: |alignmap-Htd|
888 | ...field... | ...field... |
889 |
890 | *alignmap-t|* *alignmap-t#* *alignmap-t,* *alignmap-t:*
891 | *alignmap-t;* *alignmap-t<* *alignmap-t?* *alignmap-t~*
892 | *alignmap-m=*
893 | \tx : make a left-justified alignment on
894 | character "x" where "x" is: ,:<=@|# |alignmap-t=|
895 | \Tx : make a right-justified alignment on
896 | character "x" where "x" is: ,:<=@# |alignmap-T=|
897 | \m= : like \t= but aligns with %... style comments
898 |
899 | The leading backslash is actually (see |mapleader| to learn
900 | how to customize the leader to be whatever you like). These maps use
901 | the package and are defined in the file.
902 | Although the maps use AlignCtrl options, they typically use the "m"
903 | option which pushes the options (AlignPush). The associated Align
904 | call which follows will then AlignPop the user's original options
905 | back.
906 |
907 | ALIGNMENT MAP USE WITH MARK AND MOVE~
908 | In the examples below, one may select the text with a "ma" at the
909 | first line, move to the last line, then execute the map.
910 |
911 | ALIGNMENT MAP USE WITH VISUAL MODE~
912 | Alternatively, one may select the text with the "V" visual mode
913 | command.
914 |
915 | If you want to use visual-block mode (ctrl-v), I suggest using
916 | an AlignMap with the vis.vim plugin, available at either
917 |
918 | stable: http://vim.sourceforge.net/scripts/script.php?script_id=1195
919 | devel : http://mysite.verizon.net/astronaut/vim/index.html#VIS
920 |
921 | Use it with commands such as >
922 |
923 | ctrl-v (move)
924 | :B norm \alignmap_sequence
925 | <
926 |
927 | ALIGNMENT MAP USE WITH MENUS~
928 | One may use the mark-and-move style (ma, move, use the menu) or
929 | the visual mode style (use the V visual mode, move, then select
930 | the alignment map with menu selection). The alignment map menu
931 | items are under DrChip.AlignMaps .
932 |
933 | One may even change the top level menu name to whatever is wished; by
934 | default, its >
935 | let g:DrChipTopLvlMenu= "DrChip."
936 | < If you set the variable to the empty string (""), then no menu items
937 | will be produced. Of course, one must have a vim with +menu, the gui
938 | must be running, and |'go'| must have the menu bar suboption (ie. m
939 | must be included).
940 |
941 | COMPLEX ALIGNMENT MAP METHOD~
942 | For those complex alignment maps which do alignment on constructs
943 | (e.g. \acom, \adec, etc), a series of substitutes is used to insert
944 | "@" symbols in appropriate locations. Align#Align() is then used to
945 | do alignment directly on "@"s; then it is followed by further
946 | substitutes to do clean-up. However, the maps \WS and \WE, used by
947 | every map supported by AlignMaps, protect any original embedded "@"
948 | symbols by first converting them to characters, doing the
949 | requested job, and then converting them back. >
950 |
951 | \WS calls AlignMaps#WrapperStart()
952 | \WE calls AlignMaps#WrapperEnd()
953 | <
954 |
955 | ---------------------------
956 | Alignment Map Examples: \a, *alignmap-a,* {{{3
957 | ---------------------------
958 |
959 | Original: illustrates comma-separated declaration splitting: >
960 | int a,b,c;
961 | struct ABC_str abc,def;
962 | <
963 | Becomes: >
964 | int a;
965 | int b;
966 | int c;
967 | struct ABC_str abc;
968 | struct ABC_str def;
969 | <
970 |
971 | ---------------------------
972 | Alignment Map Examples: \a? *alignmap-a?* {{{3
973 | ---------------------------
974 |
975 | Original: illustrates ()?: aligning >
976 | printf("<%s>\n",
977 | (x == ABC)? "abc" :
978 | (x == DEFG)? "defg" :
979 | (x == HIJKL)? "hijkl" : "???");
980 | <
981 | Becomes: select "(x == ..." lines, then \a? >
982 | printf("<%s>\n",
983 | (x == ABC)? "abc" :
984 | (x == DEFG)? "defg" :
985 | (x == HIJKL)? "hijkl" : "???");
986 | <
987 |
988 | ---------------------------
989 | Alignment Map Examples: \a< *alignmap-a<* {{{3
990 | ---------------------------
991 |
992 | Original: illustrating aligning of << and >> >
993 | cin << x;
994 | cin << y;
995 | cout << "this is x=" << x;
996 | cout << "but y=" << y << "is not";
997 | <
998 | Becomes: select "(x == ..." lines, then \a< >
999 | cin << x;
1000 | cin << y;
1001 | cout << "this is x=" << x;
1002 | cout << "but y=" << y << "is not";
1003 | <
1004 |
1005 | ---------------------------
1006 | Alignment Map Examples: \a= *alignmap-a=* {{{3
1007 | ---------------------------
1008 |
1009 | Original: illustrates how to align := assignments >
1010 | aa:=bb:=cc:=1;
1011 | a:=b:=c:=1;
1012 | aaa:=bbb:=ccc:=1;
1013 | <
1014 | Bcomes: select the three assignment lines, then \a:= >
1015 | aa := bb := cc := 1;
1016 | a := b := c := 1;
1017 | aaa := bbb := ccc := 1;
1018 | <
1019 |
1020 | ---------------------------
1021 | Alignment Map Examples: \abox *alignmap-abox* {{{3
1022 | ---------------------------
1023 |
1024 | Original: illustrates how to comment-box some text >
1025 | This is some plain text
1026 | which will
1027 | soon be surrounded by a
1028 | comment box.
1029 | <
1030 | Becomes: Select "This..box." with ctrl-v, press \abox >
1031 | /***************************
1032 | * This is some plain text *
1033 | * which will *
1034 | * soon be surrounded by a *
1035 | * comment box. *
1036 | ***************************/
1037 | <
1038 |
1039 | ---------------------------
1040 | Alignment Map Examples: \acom *alignmap-acom* {{{3
1041 | ---------------------------
1042 |
1043 | Original: illustrates aligning C-style comments (works for //, too) >
1044 | if(itworks) { /* this */
1045 | then= dothis; /* is a */
1046 | } /* set of three comments */
1047 | <
1048 | Becomes: Select the three lines, press \acom >
1049 | if(itworks) { /* this */
1050 | then= dothis; /* is a */
1051 | } /* set of three comments */
1052 | <
1053 | Also see |alignmap-aocom|
1054 |
1055 |
1056 | ---------------------------
1057 | Alignment Map Examples: \anum *alignmap-anum* {{{3
1058 | ---------------------------
1059 |
1060 | First, note that the behavior of the \anum map depends on the existence
1061 | of either the vim variable >
1062 | g:alignmaps_usanumber
1063 | < or >
1064 | g:alignmaps_euronumber
1065 | < when AlignMaps is loaded.
1066 |
1067 | Essentially, "usa" numbers use "."s and "euro" numbers use ","s to
1068 | separate the integer from the fractional portion of a number.
1069 | "Usa" numbers are default.
1070 |
1071 | Original: illustrates how to get numbers lined up >
1072 | -1.234 .5678 -.901e-4
1073 | 1.234 5.678 9.01e-4
1074 | 12.34 56.78 90.1e-4
1075 | 123.4 567.8 901.e-4
1076 | <
1077 | Becomes: Go to first line, ma. Go to last line, press \anum >
1078 | -1.234 .5678 -.901e-4
1079 | 1.234 5.678 9.01e-4
1080 | 12.34 56.78 90.1e-4
1081 | 123.4 567.8 901.e-4
1082 | <
1083 | Original: >
1084 | | -1.234 .5678 -.901e-4 |
1085 | | 1.234 5.678 9.01e-4 |
1086 | | 12.34 56.78 90.1e-4 |
1087 | | 123.4 567.8 901.e-4 |
1088 | <
1089 | Becomes: Select the numbers with ctrl-v (visual-block mode), >
1090 | press \anum
1091 | | -1.234 .5678 -.901e-4 |
1092 | | 1.234 5.678 9.01e-4 |
1093 | | 12.34 56.78 90.1e-4 |
1094 | | 123.4 567.8 901.e-4 |
1095 | <
1096 | Original: >
1097 | -1,234 ,5678 -,901e-4
1098 | 1,234 5,678 9,01e-4
1099 | 12,34 56,78 90,1e-4
1100 | 123,4 567,8 901,e-4
1101 | <
1102 | Becomes: (assuming g:alignmaps_euronumber exists)
1103 | Go to first line, ma. Go to last line, press \anum >
1104 | -1,234 ,5678 -,901e-4
1105 | 1,234 5,678 9,01e-4
1106 | 12,34 56,78 90,1e-4
1107 | 123,4 567,8 901,e-4
1108 | <
1109 | In addition:
1110 | \aenum is provided to support European-style numbers
1111 | \aunum is provided to support USA-style numbers
1112 |
1113 | *g:alignmaps_usanumber* *g:alignmaps_euronumber*
1114 | One may get \aenum behavior for \anum by putting >
1115 | let g:alignmaps_euronumber= 1
1116 | < or \aunum behavior for \anum by putting >
1117 | let g:alignmaps_usanumber= 1
1118 | < in one's <.vimrc>.
1119 |
1120 |
1121 | ---------------------------
1122 | Alignment Map Examples: \ascom *alignmap-ascom* {{{3
1123 | ---------------------------
1124 |
1125 | Original: >
1126 | /* A Title */
1127 | int x; /* this is a comment */
1128 | int yzw; /* this is another comment*/
1129 | <
1130 | Becomes: Select the three lines, press \ascom >
1131 | /* A Title */
1132 | int x; /* this is a comment */
1133 | int yzw; /* this is another comment */
1134 | <
1135 |
1136 | ---------------------------
1137 | Alignment Map Examples: \adec *alignmap-adec* {{{3
1138 | ---------------------------
1139 |
1140 | Original: illustrates how to clean up C/C++ declarations >
1141 | int a;
1142 | float b;
1143 | double *c=NULL;
1144 | char x[5];
1145 | struct abc_str abc;
1146 | struct abc_str *pabc;
1147 | int a; /* a */
1148 | float b; /* b */
1149 | double *c=NULL; /* b */
1150 | char x[5]; /* x[5] */
1151 | struct abc_str abc; /* abc */
1152 | struct abc_str *pabc; /* pabc */
1153 | static int a; /* a */
1154 | static float b; /* b */
1155 | static double *c=NULL; /* b */
1156 | static char x[5]; /* x[5] */
1157 | static struct abc_str abc; /* abc */
1158 | static struct abc_str *pabc; /* pabc */
1159 | <
1160 | Becomes: Select the declarations text, then \adec >
1161 | int a;
1162 | float b;
1163 | double *c = NULL;
1164 | char x[5];
1165 | struct abc_str abc;
1166 | struct abc_str *pabc;
1167 | int a; /* a */
1168 | float b; /* b */
1169 | double *c = NULL; /* b */
1170 | char x[5]; /* x[5] */
1171 | struct abc_str abc; /* abc */
1172 | struct abc_str *pabc; /* pabc */
1173 | static int a; /* a */
1174 | static float b; /* b */
1175 | static double *c = NULL; /* b */
1176 | static char x[5]; /* x[5] */
1177 | static struct abc_str abc; /* abc */
1178 | static struct abc_str *pabc; /* pabc */
1179 | <
1180 |
1181 | ---------------------------
1182 | Alignment Map Examples: \adef *alignmap-adef* {{{3
1183 | ---------------------------
1184 |
1185 | Original: illustrates how to line up #def'initions >
1186 | #define ONE 1
1187 | #define TWO 22
1188 | #define THREE 333
1189 | #define FOUR 4444
1190 | <
1191 | Becomes: Select four definition lines, apply \adef >
1192 | # define ONE 1
1193 | # define TWO 22
1194 | # define THREE 333
1195 | # define FOUR 4444
1196 | <
1197 |
1198 | ---------------------------
1199 | Alignment Map Examples: \afnc *alignmap-afnc* {{{3
1200 | ---------------------------
1201 |
1202 | This map is an exception to the usual selection rules.
1203 | It uses "]]" to find the function body's leading "{".
1204 | Just put the cursor anywhere in the function arguments and
1205 | the entire function declaration should be processed.
1206 |
1207 | Because "]]" looks for that "{" in the first column, the
1208 | "original" and "becomes" examples are in the first column,
1209 | too.
1210 |
1211 | Original: illustrates lining up ansi-c style function definitions >
1212 | int f(
1213 | struct abc_str ***a, /* one */
1214 | long *b, /* two */
1215 | int c) /* three */
1216 | {
1217 | }
1218 | <
1219 | Becomes: put cursor anywhere before the '{', press \afnc >
1220 | int f(
1221 | struct abc_str ***a, /* one */
1222 | long *b, /* two */
1223 | int c) /* three */
1224 | {
1225 | }
1226 | <
1227 |
1228 | ---------------------------
1229 | Alignment Map Examples: \adcom *alignmap-adcom* {{{3
1230 | ---------------------------
1231 |
1232 | Original: illustrates aligning comments that don't begin
1233 | lines (optionally after some whitespace). >
1234 | struct {
1235 | /* this is a test */
1236 | int x; /* of how */
1237 | double y; /* to use adcom */
1238 | };
1239 | <
1240 | Becomes: Select the inside lines of the structure,
1241 | then press \adcom. The comment-only
1242 | line is ignored but the other two comments
1243 | get aligned. >
1244 | struct {
1245 | /* this is a test */
1246 | int x; /* of how */
1247 | double y; /* to use adcom */
1248 | };
1249 | <
1250 |
1251 | ---------------------------
1252 | Alignment Map Examples: \aocom *alignmap-aocom* {{{3
1253 | ---------------------------
1254 |
1255 | Original: illustrates how to align C-style comments (works for //, too)
1256 | but restricted only to aligning with those lines containing
1257 | comments. See the difference from \acom (|alignmap-acom|). >
1258 | if(itworks) { /* this comment */
1259 | then= dothis;
1260 | } /* only appears on two lines */
1261 | <
1262 | Becomes: Select the three lines, press \aocom >
1263 | if(itworks) { /* this comment */
1264 | then= dothis;
1265 | } /* only appears on two lines */
1266 | <
1267 | Also see |alignmap-acom|
1268 |
1269 |
1270 | --------------------------- *alignmap-Tsp*
1271 | Alignment Map Examples: \tsp *alignmap-tsp* {{{3
1272 | ---------------------------
1273 |
1274 | Normally Align can't use white spaces for field separators as such
1275 | characters are ignored surrounding field separators. The \tsp and
1276 | \Tsp maps get around this limitation.
1277 |
1278 | Original: >
1279 | one two three four five
1280 | six seven eight nine ten
1281 | eleven twelve thirteen fourteen fifteen
1282 | <
1283 | Becomes: Select the lines, \tsp >
1284 | one two three four five
1285 | six seven eight nine ten
1286 | eleven twelve thirteen fourteen fifteen
1287 | <
1288 | Becomes: Select the lines, \Tsp >
1289 | one two three four five
1290 | six seven eight nine ten
1291 | eleven twelve thirteen fourteen fifteen
1292 | <
1293 |
1294 | ---------------------------
1295 | Alignment Map Examples: \tsq *alignmap-tsq* {{{3
1296 | ---------------------------
1297 |
1298 | The \tsp map is useful for aligning tables based on white space,
1299 | but sometimes one wants double-quoted strings to act as a single
1300 | object in spite of embedded spaces. The \tsq map was invented
1301 | to support this. (thanks to Leif Wickland)
1302 |
1303 | Original: >
1304 | "one two" three
1305 | four "five six"
1306 | <
1307 | Becomes: Select the lines, \tsq >
1308 | "one two" three
1309 | four "five six"
1310 | <
1311 |
1312 | ---------------------------
1313 | Alignment Map Examples: \tt *alignmap-tt* {{{3
1314 | ---------------------------
1315 |
1316 | Original: illustrates aligning a LaTex Table >
1317 | \begin{tabular}{||c|l|r||}
1318 | \hline\hline
1319 | one&two&three\\ \hline
1320 | four&five&six\\
1321 | seven&eight&nine\\
1322 | \hline\hline
1323 | \end{tabular}
1324 | <
1325 | Becomes: Select the three lines inside the table >
1326 | (ie. one..,four..,seven..) and press \tt
1327 | \begin{tabular}{||c|l|r||}
1328 | \hline\hline
1329 | one & two & three \\ \hline
1330 | four & five & six \\
1331 | seven & eight & nine \\
1332 | \hline\hline
1333 | \end{tabular}
1334 | <
1335 |
1336 | ----------------------------
1337 | Alignment Map Examples: \tml *alignmap-tml* {{{3
1338 | ----------------------------
1339 |
1340 | Original: illustrates aligning multi-line continuation marks >
1341 | one \
1342 | two three \
1343 | four five six \
1344 | seven \\ \
1345 | eight \nine \
1346 | ten \
1347 | <
1348 | Becomes: >
1349 | one \
1350 | two three \
1351 | four five six \
1352 | seven \\ \
1353 | eight \nine \
1354 | ten \
1355 | <
1356 |
1357 | ---------------------------
1358 | Alignment Map Examples: \t= *alignmap-t=* {{{3
1359 | ---------------------------
1360 |
1361 | Original: illustrates left-justified aligning of = >
1362 | aa=bb=cc=1;/*one*/
1363 | a=b=c=1;/*two*/
1364 | aaa=bbb=ccc=1;/*three*/
1365 | <
1366 | Becomes: Select the three equations, press \t= >
1367 | aa = bb = cc = 1; /* one */
1368 | a = b = c = 1; /* two */
1369 | aaa = bbb = ccc = 1; /* three */
1370 | <
1371 |
1372 | ---------------------------
1373 | Alignment Map Examples: \T= *alignmap-T=* {{{3
1374 | ---------------------------
1375 |
1376 | Original: illustrates right-justified aligning of = >
1377 | aa=bb=cc=1; /* one */
1378 | a=b=c=1; /* two */
1379 | aaa=bbb=ccc=1; /* three */
1380 | <
1381 | Becomes: Select the three equations, press \T= >
1382 | aa = bb = cc = 1; /* one */
1383 | a = b = c = 1; /* two */
1384 | aaa = bbb = ccc = 1; /* three */
1385 | <
1386 |
1387 | ---------------------------
1388 | Alignment Map Examples: \Htd *alignmap-Htd* {{{3
1389 | ---------------------------
1390 |
1391 | Original: for aligning tables with html >
1392 | ...field one... | ...field two... |
1393 | ...field three... | ...field four... |
1394 | <
1395 | Becomes: Select ... lines, press \Htd >
1396 |
...field one... | ...field two... |
1397 | ...field three... | ...field four... |
1398 | <
1399 | ==============================================================================
1400 | 4. Alignment Tools' History *align-history* {{{1
1401 |
1402 | ALIGN HISTORY {{{2
1403 | 36 : May 20, 2009 * Previously, the "W" AlignCtrl setting, intended
1404 | to retain initial white space, did so by convert-
1405 | ing any leading tabs into an equivalent quantity
1406 | of blanks (using the current tabstop setting).
1407 | Align will now retain leading tabs.
1408 | Nov 24, 2009 * QArgSplitter() used split(), intending to split
1409 | on white space only. However, the \tab map
1410 | uses ctrl-o as a separator instead of tabs; the
1411 | split() function treated the ctrl-o as a whitespace
1412 | character, too. Solution: give split() an explicit
1413 | pattern matching blanks and tabs, only. \tab now
1414 | works again!
1415 | Jun 29, 2010 * included |g:AlignSkip| and |alignctrl-star| support
1416 | May 10, 2011 * if the range is only one line, then Align will
1417 | automatically grow the range to accommodate all
1418 | lines containing the first separator pattern
1419 | surrounding the current line.
1420 | Aug 05, 2011 * g:Align_xstrlen usage extended to permit users to
1421 | specify a function by name which computes string
1422 | length.
1423 | Oct 27, 2011 * (reported by Fco Javier) reported a problem with
1424 | the default s:Strlen() result; there was a missing
1425 | "let". Fixed.
1426 | Nov 10, 2011 * (Lewis Thompson) Align was doing "set noet" when
1427 | it should've been doing "setlocal noet".
1428 | Dec 22, 2011 * modifed s:Strlen() to use |strdisplaywidth()| when
1429 | g:Align_xstrlen is zero.
1430 | 35 : Nov 02, 2008 * g:loaded_AlignPlugin testing to prevent re-loading
1431 | installed
1432 | Nov 19, 2008 * new sanity check for an AlignStyle of just ":"
1433 | Jan 08, 2009 * save&restore of |'mod'| now done with local
1434 | variant
1435 | 34 : Jul 08, 2008 * using :AlignCtrl before entering any alignment
1436 | control commands was causing an error.
1437 | 33 : Sep 20, 2007 * s:Strlen() introduced to support various ways
1438 | used to represent characters and their effects
1439 | on string lengths. See |align-strlen|.
1440 | * Align now accepts "..." -- so it can accept
1441 | whitespace as separators.
1442 | 32 : Aug 18, 2007 * uses || instead of || plus a
1443 | custom argument splitter to allow patterns with
1444 | backslashes to slide in unaltered.
1445 | 31 : Aug 06, 2007 * :[range]Align! [AlignCtrl settings] pattern(s)
1446 | implemented.
1447 | 30 : Feb 12, 2007 * now uses |setline()|
1448 | 29 : Jan 18, 2006 * cecutil updated to use keepjumps
1449 | Feb 23, 2006 * Align now converted to vim 7.0 style using
1450 | auto-loading functions.
1451 | 28 : Aug 17, 2005 * report option workaround
1452 | Oct 24, 2005 * AlignCtrl l: wasn't behaving as expected; fixed
1453 | 27 : Apr 15, 2005 : cpo workaround
1454 | ignorecase workaround
1455 | 26 : Aug 20, 2004 : loaded_align now also indicates version number
1456 | GetLatestVimScripts :AutoInstall: now supported
1457 | 25 : Jul 27, 2004 : For debugging, uses Dfunc(), Dret(), and Decho()
1458 | 24 : Mar 03, 2004 : (should've done this earlier!) visualmode(1)
1459 | not supported until v6.2, now Align will avoid
1460 | calling it for earlier versions. Visualmode
1461 | clearing won't take place then, of course.
1462 | 23 : Oct 07, 2003 : Included Leif Wickland's ReplaceQuotedSpaces()
1463 | function which supports \tsq
1464 | 22 : Jan 29, 2003 : Now requires 6.1.308 or later to clear visualmode()
1465 | 21 : Jan 10, 2003 : BugFix: similar problem to #19; new code
1466 | bypasses "norm! v\" until initialization
1467 | is over.
1468 | 20 : Dec 30, 2002 : BugFix: more on "unable to highlight" fixed
1469 | 19 : Nov 21, 2002 : BugFix: some terminals gave an "unable to highlight"
1470 | message at startup; Hari Krishna Dara tracked it
1471 | down; a silent! now included to prevent noise.
1472 | 18 : Nov 04, 2002 : BugFix: re-enabled anti-repeated-loading
1473 | 17 : Nov 04, 2002 : BugFix: forgot to have AlignPush() push s:AlignSep
1474 | AlignCtrl now clears visual-block mode when used so
1475 | that Align won't try to use old visual-block
1476 | selection marks '< '>
1477 | 16 : Sep 18, 2002 : AlignCtrl <>| options implemented (separator
1478 | justification)
1479 | 15 : Aug 22, 2002 : bug fix: AlignCtrl's ":" now acts as a modifier of
1480 | the preceding alignment operator (lrc)
1481 | 14 : Aug 20, 2002 : bug fix: AlignCtrl default now keeps &ic unchanged
1482 | bug fix: Align, on end-field, wasn't using correct
1483 | alignop bug fix: Align, on end-field, was appending
1484 | padding
1485 | 13 : Aug 19, 2002 : bug fix: zero-length g/v patterns are accepted
1486 | bug fix: always skip blank lines
1487 | bug fix: AlignCtrl default now also clears g and v
1488 | patterns
1489 | 12 : Aug 16, 2002 : moved keep_ic above zero-length pattern checks
1490 | added "AlignCtrl default"
1491 | fixed bug with last field getting separator spaces
1492 | at end line
1493 | 11 : Jul 08, 2002 : prevent separator patterns which match zero length
1494 | -+: included as additional alignment/justification
1495 | styles
1496 | 10 : Jun 26, 2002 : =~# used instead of =~ (for matching case)
1497 | ignorecase option handled
1498 | 9 : Jun 25, 2002 : implemented cyclic padding
1499 |
1500 | ALIGNMENT MAP HISTORY *alignmap-history* {{{2
1501 | v42 Jan 06, 2010 * new maps for \anum, \aenum, \aunum
1502 | Feb 16, 2010 * map for \t=, \T= now handles x++ = something;
1503 | for c, c++ correctly.
1504 | Oct 29, 2010 * added a note on having one's own default
1505 | AlignCtrl (see |alignctrl-init|)
1506 | Feb 22, 2011 * for menus, &go =~# used to insure correct case
1507 | Jun 10, 2011 * |:AlignMapsClean| command provided to make it
1508 | easy for those who would prefer not to have
1509 | AlignMaps' maps not to have them.
1510 | v41 Nov 02, 2008 * g:loaded_AlignMapsPlugin testing to prevent
1511 | re-loading installed
1512 | * AlignMaps now use 0x0f (ctrl-p) for special
1513 | character substitutions (instead of 0xff).
1514 | Seems to avoid some problems with having to
1515 | use Strlen().
1516 | * bug fixed with \ts,
1517 | * new maps: \ts; \ts, \ts: \ts< \ts= \a(
1518 | v40 Oct 21, 2008 * Modified AlignMaps so that its maps use s
1519 | and