Skip to content
Browse files

swapit looks good. Also some hacking here and there.

  • Loading branch information...
1 parent 7beb59e commit b022a8de58233deed63d558c850a9a87917009da @romainl committed Nov 26, 2012
View
4 after/ftplugin/html.vim
@@ -6,8 +6,8 @@ nnoremap <buffer> <leader>é :call ReverseEntities()<CR>
vnoremap <buffer> <leader>& :call Entities()<CR>
vnoremap <buffer> <leader>é :call ReverseEntities()<CR>
-nnoremap <leader>< /<\w*\(\s\\|>\)<CR>
-nnoremap <leader>> ?<\w*\(\s\\|>\)<CR>
+nnoremap <buffer> <leader>< /<\w*\(\s\\|>\)<CR>
+nnoremap <buffer> <leader>> ?<\w*\(\s\\|>\)<CR>
let b:match_words='<:>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
View
4 after/ftplugin/markdown.vim
@@ -14,4 +14,8 @@ setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+
let b:undo_ftplugin .= "|setl cms< com< fo<"
+vnoremap +b <Esc>`>a**<Esc>`<i**<Esc>
+vnoremap +i <Esc>`>a*<Esc>`<i*<Esc>
+vnoremap +c <Esc>`>a`<Esc>`<i`<Esc>
+
" vim:set sw=2:
View
1 bundle/swapit/.gitignore
@@ -0,0 +1 @@
+doc/tags
View
206 bundle/swapit/README
@@ -0,0 +1,206 @@
+
+swapit.txt Extensible Keyword Swapper
+
+Author: Michael Brown <mjbrownie @ NOSPAMMY gmail.com>
+
+ Usage Notes
+
+1. SwapIt Introduction |swapit-intro|
+
+2. Setup |swapit-setup|
+ 2.1 Requirements |swapit-requirements|
+ 2.2 Installation |swapit-installation|
+ 2.3 Bugs |swapit-bugs|
+ 2.4 Limitations/Annoyances |swapit-annoyances|
+
+3. Swapping
+ 3.1 Built in swap lists |swapit-builtin|
+ 3.2 Defining a swap list |swapit-define|
+ 3.3 xml/html swaps |swapit-html|
+ 3.4 Multi word swaps |swapit-multiword|
+
+4. Filetype Swaps |swapit-filetype|
+
+ 4.1 Defining a filetype swap list |swapit-cleanup|
+
+5. Omnicomplete Swapping |swapit-omnicomplete|
+
+================================================================================
+1. SwapIt Introduction *swapit-intro*
+
+ swapit.vim is a plugin designed to make it easier to perform common changes
+ to various filetypes. It's designed to fill a niche where onmnicomplete for
+ a given filetype is not providing any options. It is very easy to define your
+ own lists for your own projects.
+
+ It's most effective if you have a set of keywords between 2 and 10 in size.
+ By default it uses the increment/decrement keystrokes |ctrl-a| |ctrl-x|.
+ Although this can be custom mapped for screen users.
+
+ A simple builtin example:
+
+ setting=false
+
+ moving the cursor over false in normal mode and pressing ctrl-a will result
+ in
+
+ setting=true
+
+ The git repository is here http://github.com/mjbrownie/swapit/tree/master.
+ I'd appreciate any additions.
+
+================================================================================
+2. Setup *swapit-setup*
+
+2.1 Requirements *swapit-requirements*
+
+ Swapit has been tested on vim 7.0.
+
+ If you are looking to use the xml/html tag complete option you need to have
+ matchit.vim working correctly.
+
+2.2 Installation *swapit-installation*
+
+ Copy the swapit.tar.gz file in your ~/.vim/ directory and extract.
+
+2.3 Bugs *swapit-bugs*
+
+ This is still a work in progress. There are still some bugs where the swap
+ gets stuck in visual mode and on some line extremities the cursor can jump
+ away from where you want it.
+
+ In some cases having |'selection'| set to exclusive mode can break things.
+ Try:
+
+ :set selection=inclusive
+
+2.4 Limitations/Annoyances *swapit-annoyances*
+
+ Swapping is based on naive lists so the biggest limitation is when there is
+ the same keyword in more than one list. If this happens then a selection
+ box comes up where you decide which list to use, but its not as smoothe an
+ operation. To combat this issue lists are filetype specific.
+
+ For example if you have the following two lists:
+
+ :SwapList octave do re me fa so la ti
+ :SwapList self me myself I
+
+ trying to swap the keyword 'me' will result in an option list coming up.
+
+ Swap Options: A . octave (me > fa) B . self (me > myself)
+ (A), (B):
+
+ It would probably be possible to differentiate lists with some regex but
+ this plugin is probably overkill already.
+
+================================================================================
+
+3 Swapping
+
+ 3.1 Built in swap lists *swapit-builtin*
+
+ swapit has a number of obvious lists defined eg. yes/no true/false etc.
+
+ 3.2 Defining a swap list *SwapList* *swapit-define*
+
+ :SwapList <list_name> <member1> <member2> .. <membern>
+
+ eg. :SwapList roman I II III IV V VI VII VII IX X
+
+ 3.3 xml/html swaps *swapit-html*
+
+ One of the most recent and useful features is you can swap xml/html
+ tags.
+
+ If you vim has matchit.vim loaded you can swap. Eg:
+
+ <p> This should be an h1 </p>
+
+ ctrl-a on the p will cycle to...
+
+ <h1> This should be an h1 </h1>
+
+ This behavior is defined by the command SwapXmlMatchit
+
+ which is as follows
+
+ SwapXmlMatchit <swap_list> <swap_list> ...
+
+ ~/.vim/after/ftplugin/html_swapit.vim
+
+ SwapList formats h1 h2 h3 h4 p strong em a
+ SwapList layout div span script style
+ SwapXmlMatchit formats layout
+
+ 3.4 Multi word swaps *swapit-multiword*
+
+ swapit can handle multiword swapping by entering into visual mode.
+
+ I wrote it and didn't find a use for it so defining multiword swaps
+ isn't as easy as single word swaps. you could manually define a list.
+
+ ~/.vim/after/ftplugin/{filetype}_swapit.vim
+
+ ClearSwapList
+
+ let g:swap_lists = [
+ \{'name':'hello_world', 'options':
+ \['Hello World!','GoodBye Cruel World!' , 'See You Next Tuesday!']},
+ ...
+ \]
+
+ etc.
+
+================================================================================
+
+4. Filetype Swaps
+
+ 4.1 Defining a filetype swap list *SwapIdea* *swapit-filetype*
+
+ The command
+
+ :SwapIdea
+
+ will open
+
+ ~/.vim/after/ftplugin/{filetype}_swapit.vim
+
+ The filetype file can be used to define custom swaps for
+
+ 4.2 Clearing a Swap List *ClearSwapList* *swapit-cleanup*
+
+ The ClearSwapList command cleans up existing swap lists. Its useful to
+ put this at the top of an after/ftplugin file.
+
+ ClearSwapList
+
+5. Omnicomplete Swapping *swapit-omnicomplete*
+
+ Rather than repeating SwapLists that are similar to omnicomplete patterns
+ it would be more preferable to use the omnicomplete function for the
+ language.
+
+ Swapit is capable of experimental looking up omnicomplete patterns
+ currently only for CSS as of writing. I'd appreciate any ideas and
+ additions in this area.
+
+ For additions please fork.
+
+ http://github.com/mjbrownie/swapit/tree/master
+
+ Example of setting up a callback swapit function is as follows
+
+ Firstly define the callback function in the
+
+ after/ftplugin/<filetype>_swapit.vim file
+
+ Eg in after/ftplugin/css_swapit.vim
+
+ let b:swap_completefunc = 'cssswapit#CssSwapComplete'
+
+ then define a function in the autoload folder
+
+ autoload/cssswapit.vim. The function must take one argument specifying the
+ direction 'forward' or 'backward' and return 1 on a successful swap or 0
+ if no matches are made. Look at the cssswapit for an example.
View
8 bundle/swapit/after/ftplugin/css_swapit.vim
@@ -0,0 +1,8 @@
+ClearSwapList
+
+SwapList formats h1 h2 h3 h4 p strong em a
+SwapList lists ol ul
+SwapList tables td tr thead tbody table
+SwapList layout div span script style
+
+let b:swap_completefunc = 'cssswapit#CssSwapComplete'
View
11 bundle/swapit/after/ftplugin/html_swapit.vim
@@ -0,0 +1,11 @@
+"InputTypes for forms
+ClearSwapList
+
+SwapList input_types text checkbox radio hidden button submit file
+SwapList form_method post get
+SwapList target _blank _parent _self _top
+SwapList formats h1 h2 h3 h4 p strong em a
+SwapList layout div span img script
+SwapList atri id class href src alt title
+
+SwapXmlMatchit formats layout
View
13 bundle/swapit/after/ftplugin/htmldjango_swapit.vim
@@ -0,0 +1,13 @@
+"InputTypes for forms
+ClearSwapList
+
+SwapList input_types text checkbox radio hidden button submit file
+SwapList form_method post get
+SwapList target _blank _parent _self _top
+SwapList formats h1 h2 h3 h4 p strong em a
+SwapList layout div span script style
+SwapList lists ol ul This wont work as matchit is matching li rows
+SwapList tables td tr thead tbody table
+SwapList atri id class href src alt title
+
+SwapXmlMatchit formats layout tables lists
View
3 bundle/swapit/after/ftplugin/php_swapit.vim
@@ -0,0 +1,3 @@
+ClearSwapList
+SwapList function_scope private protected public
+SwapList php_date DATE_ATOM DATE_COOKIE DATE_ISO8601 DATE_RFC822 DATE_RFC850 DATE_RFC1036 DATE_RFC1123 DATE_RFC2822 DATE_RSS DATE_W3C
View
3 bundle/swapit/after/ftplugin/python_swapit.vim
@@ -0,0 +1,3 @@
+if findfile("settings.py")
+ source django_swapit.vim
+endif
View
6 bundle/swapit/after/ftplugin/vim_swapit.vim
@@ -0,0 +1,6 @@
+ClearSwapList
+
+ exec "SwapList color brown red blue"
+
+ "call add(g:swap_lists, {'name':'Multi Word Example', 'options': ['swap with spaces','swap with @#$@# chars in it' , 'running out of ideas here...']})
+
View
40 bundle/swapit/autoload/cssswapit.vim
@@ -0,0 +1,40 @@
+fun! cssswapit#CssSwapComplete(direction)
+
+ let column = col(".")
+ let line = getline(".")
+
+ let keyword = &iskeyword
+ setlocal iskeyword+=-
+ let cur_word = expand('<cword>')
+ if match (getline("."),"[0-9A-Za-z_-]\+\s*:\s*[0-9A-Za-z_-]\+")
+ let temp_reg = @s
+ let matches = csscomplete#CompleteCSS(0, substitute(strpart(getline('.'),0, col('.')),':[^:]*$'," : ",""))
+
+ if index(matches,cur_word) != -1
+ let word_index = index(matches, cur_word)
+
+ if a:direction == 'forward'
+ let word_index = (word_index + 1) % len(matches)
+ else
+ let word_index = (word_index - 1) % len(matches)
+ endif
+
+ if match (matches[word_index],'[^0-9A-Za-z_-]') != -1 "This is to stop url(
+ return 0
+ endif
+ let @s = matches[word_index]
+
+ exec 'norm viw"sp'
+ exec "setlocal iskeyword=". keyword
+
+ return 1
+ endif
+
+ let @s = temp_reg
+
+ endif
+ return 0
+endfun
+
+" modeline: {{{
+" vim: expandtab softtabstop=4 shiftwidth=4 foldmethod=marker
View
233 bundle/swapit/doc/swapit.txt
@@ -0,0 +1,233 @@
+*swapit.txt* Extensible Keyword Swapper
+
+Author: Michael Brown <mjbrownie @ NOSPAMMY gmail.com>
+License: MIT License {{{
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify,
+ merge, publish, distribute, sublicense, and/or sell copies of the
+ Software, and to permit persons to whom the Software is furnished
+ to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+}}}
+
+
+==============================================================================
+Contents *swapit-contents*
+
+1. SwapIt Introduction |swapit-intro|
+
+2. Setup |swapit-setup|
+ 2.1 Requirements |swapit-requirements|
+ 2.2 Installation |swapit-installation|
+ 2.3 Bugs |swapit-bugs|
+ 2.4 Limitations/Annoyances |swapit-annoyances|
+
+3. Swapping
+ 3.1 Built in swap lists |swapit-builtin|
+ 3.2 Defining a swap list |swapit-define|
+ 3.3 xml/html swaps |swapit-html|
+ 3.4 Multi word swaps |swapit-multiword|
+
+4. Filetype Swaps |swapit-filetype|
+
+ 4.1 Defining a filetype swap list |swapit-cleanup|
+
+5. Omnicomplete Swapping |swapit-omnicomplete|
+
+
+==============================================================================
+1. SwapIt Introduction *swapit-intro*
+
+ *swapit.vim* is a plugin designed to make it easier to perform common
+ changes to various filetypes. It's designed to fill a niche where
+ onmnicomplete for a given filetype is not providing any options. It is
+ very easy to define your own lists for your own projects.
+
+ It's most effective if you have a set of keywords between 2 and 10 in
+ size. By default it uses the increment/decrement keystrokes |CTRL-A|
+ |CTRL-X|. Although this can be custom mapped for screen users.
+
+ A simple builtin example: >
+
+ setting=false
+<
+ moving the cursor over false in normal mode and pressing CTRL-A will
+ result in >
+
+ setting=true
+<
+ The git repository is here http://github.com/mjbrownie/swapit/tree/master.
+ I'd appreciate any additions.
+
+
+==============================================================================
+2. Setup *swapit-setup*
+
+2.1 Requirements *swapit-requirements*
+
+ Swapit has been tested on vim 7.0.
+
+ If you are looking to use the xml/html tag complete option you need to
+ have matchit.vim working correctly. |swapit-html|
+
+2.2 Installation *swapit-installation*
+
+ Copy the swapit.tar.gz file in your ~/.vim/ directory and extract.
+
+2.3 Bugs *swapit-bugs*
+
+ This is still a work in progress. There are still some bugs where the swap
+ gets stuck in visual mode and on some line extremities the cursor can jump
+ away from where you want it.
+
+ In some cases having |'selection'| set to exclusive mode can break
+ things. Try: >
+
+ :set selection=inclusive
+<
+
+2.4 Limitations/Annoyances *swapit-annoyances*
+
+ Swapping is based on native lists so the biggest limitation is when there
+ are same keywords in more than one list. If this happens, a selection box
+ comes up where you can decide which list to use, but its not as smoothe an
+ operation. To combat this issue, lists are filetype specific.
+
+ For example if you have the following two lists: >
+
+ :SwapList octave do re me fa so la ti
+ :SwapList self me myself I
+<
+ trying to swap the keyword "me" will result in an option list coming up. >
+
+ Swap Options: A . octave (me > fa) B . self (me > myself)
+ (A), (B):
+<
+ It would probably be possible to differentiate lists with some regex but
+ this plugin is probably overkill already.
+
+
+==============================================================================
+3 Swapping
+
+ 3.1 Built in swap lists *swapit-builtin*
+
+ swapit has a number of obvious lists defined, e.g.: yes/no true/false
+ etc.
+
+ 3.2 Defining a swap list *:SwapList* *swapit-define*
+
+ :SwapList <list_name> <member1> <member2> .. <membern>
+
+ Example: >
+
+ :SwapList roman I II III IV V VI VII VII IX X
+<
+
+ 3.3 xml/html swaps *:SwapXmlMatchit* *swapit-html*
+
+ One of the most recent and useful feature is you can swap xml/html
+ tags.
+
+ If you has matchit.vim loaded then you can swap, e.g.: >
+
+ <p> This should be an h1 </p>
+<
+ CTRL-A on the p will cycle to... >
+
+ <h1> This should be an h1 </h1>
+<
+ This behavior is defined by the command :SwapXmlMatchit
+
+ which is as follows
+
+ :SwapXmlMatchit <swap_list> <swap_list> ...
+
+ ~/.vim/after/ftplugin/html_swapit.vim
+
+ :SwapList formats h1 h2 h3 h4 p strong em a
+ :SwapList layout div span script style
+ :SwapXmlMatchit formats layout
+
+ 3.4 Multi word swaps *swapit-multiword*
+
+ swapit can handle multi-word swapping with |Visual-mode|.
+
+ I wrote it and didn't find a use for it so defining multi-word swaps
+ isn't as easy as single word swaps. You could manually define a list.
+
+ ~/.vim/after/ftplugin/{filetype}_swapit.vim
+
+ let g:swap_lists = [
+ \ {'name':'hello_world', 'options':
+ \ ['Hello World!','GoodBye Cruel World!' , 'See You Next Tuesday!']},
+ ...
+ \ ]
+
+ etc.
+
+
+==============================================================================
+4. Filetype Swaps
+
+ 4.1 Defining a filetype swap list *:SwapIdea* *swapit-filetype*
+
+ The command :SwapIdea will open
+
+ ~/.vim/after/ftplugin/{filetype}_swapit.vim
+
+ This file can be used to define custom swaps for specific filetype.
+
+ 4.2 Clearing a Swap List *:ClearSwapList* *swapit-cleanup*
+
+ The :ClearSwapList command cleans up existing swap lists. It's useful
+ to put this at the top of an after/ftplugin file.
+
+
+==============================================================================
+5. Omnicomplete Swapping *swapit-omnicomplete*
+
+ Rather than repeating SwapLists that are similar to omnicomplete patterns,
+ it would be more preferable to use the omnicomplete function for the
+ language.
+
+ Swapit is capable of experimental looking up omnicomplete patterns
+ currently only for CSS as of writing. I'd appreciate any ideas and
+ additions in this area.
+
+ For additions please fork.
+
+ http://github.com/mjbrownie/swapit/tree/master
+
+ Example of setting up a callback swapit function is as follows
+
+ Firstly define the callback function in the
+
+ after/ftplugin/<filetype>_swapit.vim file
+
+ *b:swap_completefunc*
+ e.g. in after/ftplugin/css_swapit.vim >
+
+ let b:swap_completefunc = 'cssswapit#CssSwapComplete'
+<
+ then define a function in the autoload folder
+
+ autoload/cssswapit.vim. The function must take one argument specifying the
+ direction 'forward' or 'backward' and return 1 on a successful swap or 0
+ if no matches are made. Look at the cssswapit for an example.
+
+
+==============================================================================
+vim:tw=78:fo=tcroq2mM:et:sts=4:sw=4:ft=help:norl:fdm=marker:
View
465 bundle/swapit/plugin/swapit.vim
@@ -0,0 +1,465 @@
+"SwapIt: General Purpose related word swapping for vim
+" Script Info and Documentation {{{1
+"=============================================================================
+"
+" Copyright: Copyright (C) 2008 Michael Brown {{{2
+" License: The MIT License
+"
+" Permission is hereby granted, free of charge, to any person obtaining
+" a copy of this software and associated documentation files
+" (the "Software"), to deal in the Software without restriction,
+" including without limitation the rights to use, copy, modify,
+" merge, publish, distribute, sublicense, and/or sell copies of the
+" Software, and to permit persons to whom the Software is furnished
+" to do so, subject to the following conditions:
+"
+" The above copyright notice and this permission notice shall be included
+" in all copies or substantial portions of the Software.
+"
+" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"
+" Name Of File: swapit.vim {{{2
+" Description: system for swapping related words
+" Maintainer: Michael Brown
+" Contributors: Ingo Karkat (speedating compatability)
+" Last Change:
+" URL:
+" Version: 0.1.2
+"
+" Usage: {{{2
+"
+" On a current word that is a member of a swap list use the
+" incrementor/decrementor keys (:he ctrl-a,ctrl-x). The script
+" will cycle through a list of related options.
+"
+" eg. 1. Boolean
+"
+" foo=yes
+"
+" in normal mode, pressing ctrl-a on the y will make it.
+"
+" foo=no
+"
+" The plugin handles clashes. Eg. if yes appears in more than
+" one swap list (eg. yes/no or yes/no/maybe), a confirm dialog will appear.
+"
+" eg. 2. Multi Word Swaps.
+"
+" Hello World! is a test multi word swap.
+"
+" on 'Hello World!' go select in visual (vi'<ctrl-a>) to get
+"
+" 'GoodBye Cruel World!'
+"
+" eg 3. Defining custom swaps
+"
+" A custom list is defined as follows.
+"
+" :SwapList datatype bool char int float double
+"
+" The first argument is the list name and following args
+" are members of the list.
+"
+" if there is no match then the regular incrementor decrementor
+" function will work on numbers
+"
+" At the bottom of the script I've added some generic stuff but
+"
+" You can create a custom swap file for file types at
+"
+" ~/.vim/after/ftplugins/<filetype>_swapit.vim
+" with custom execs eg.
+" exec "SwapList function_scope private protected public"
+"
+" For this alpha version multi word swap list is a bit trickier
+" to to define. You can add to the swap list directly using .
+"
+" call add(g:swap_lists, {'name':'Multi Word Example',
+" \'options': ['swap with spaces',
+" \'swap with @#$@# chars in it' , \
+" \'running out of ideas here...']})
+"
+" Future versions will make this cleaner
+"
+" Also if you have a spur of the moment Idea type
+" :SwapIdea
+" To get to the current filetypes swapit file
+"
+" 4. Insert mode completion
+"
+" You can use a swap list in insert mode by typing the list name
+" and hitting ctrl+b eg.
+"
+" datatype<ctrl+b> once will provide a complete list of datatypes.
+"
+" (Note: insert mode complete is still buggy and will eat your current
+" word if you keep hitting ctrl+b on an incorrect. It's disabled
+" by default so as not to annoy anyone. Uncomment the line in the
+" command configuration if you want to try it out.
+"
+" Note: This alpha version doesnt create the directory structure
+"
+" To integrate with other incrementor scripts (such as
+" speeddating.vim or monday.vim), :nmap
+" <Plug>SwapItFallbackIncrement and <Plug>SwapItFallbackDecrement
+" to the keys that should be invoked when swapit doesn't have a
+" proper option. For example for speeddating.vim:
+"
+" nmap <Plug>SwapItFallbackIncrement <Plug>SpeedDatingUp
+" nmap <Plug>SwapItFallbackDecrement <Plug>SpeedDatingDown
+"
+" Bugs: {{{2
+"
+" Will only give swap options for first match (eg make sure
+" options are unique).
+"
+" The visual mode is inconsistent on highlighting the end of a
+" phrase occasionally one character under see VISHACK
+"
+" Visual selection bug: if you have set selection=exclusive. You
+" might have trouble with the last character not being selected
+" on a multi word swap
+"
+" To Do: {{{2
+"
+" - improve filetype handling
+" - look at load performance if it becomes an issue
+" - might create a text file swap list rather than vim list
+" - look at clever case option to reduce permutations
+" - look at possibilities beyond <cword> for non word swaps
+" eg swap > for < , == to != etc.
+" - add a repeated keyword warning for :SwapList
+" - add repeat resolition confirm option eg.
+" SwapSelect> a. (yes/no) b. (yes/no/maybe)
+"
+" ideas welcome at mjbrownie (at) gmail dot com.
+"
+" I'd like to compile some useful swap lists for different
+" languages to package with the script
+"
+"Variable Initialization {{{1
+"if exists('g:loaded_swapit')
+" finish
+"elseif v:version < 700
+" echomsg "SwapIt plugin requires Vim version 7 or later"
+" finish
+"endif
+let g:loaded_swapit = 1
+let g:swap_xml_matchit = []
+
+if !exists('g:swap_lists')
+ let g:swap_lists = []
+endif
+if !exists('g:swap_list_dont_append')
+ let g:swap_list_dont_append = 'no'
+endif
+if empty(maparg('<Plug>SwapItFallbackIncrement', 'n'))
+ nnoremap <Plug>SwapItFallbackIncrement <c-a>
+endif
+if empty(maparg('<Plug>SwapItFallbackDecrement', 'n'))
+ nnoremap <Plug>SwapItFallbackDecrement <c-x>
+endif
+
+"Command/AutoCommand Configuration {{{1
+"
+" For executing the listing
+nnoremap <silent><c-a> :<c-u>call SwapWord(expand("<cword>"),'forward', 'no')<cr>
+nnoremap <silent><c-x> :<c-u>call SwapWord(expand("<cword>"),'backward','no')<cr>
+vnoremap <silent><c-a> "dy<esc>:call SwapWord(@d,'forward','yes')<cr>
+vnoremap <silent><c-x> "dy<esc>:call SwapWord(@d,'backward','yes')<cr>
+"inoremap <silent><c-b> <esc>b"sdwi <c-r>=SwapInsert()<cr>
+"inoremap <expr> <c-b> SwapInsert()
+
+" For adding lists
+com! -nargs=* SwapList call AddSwapList(<q-args>)
+com! ClearSwapList let g:swap_lists = []
+com! SwapIdea call OpenSwapFileType()
+com! -range -nargs=1 SwapWordVisual call SwapWord(getline('.'),<f-args>,'yes')
+"au BufEnter call LoadFileTypeSwapList()
+com! SwapListLoadFT call LoadFileTypeSwapList()
+com! -nargs=+ SwapXmlMatchit call AddSwapXmlMatchit(<q-args>)
+"Swap Processing Functions {{{1
+"
+"
+"SwapWord() main processiong event function {{{2
+fun! SwapWord (word, direction, is_visual)
+
+ let comfunc_result = 0
+ "{{{3 css omnicomplete property swapping
+ if exists('b:swap_completefunc')
+ exec "let complete_func = " . b:swap_completefunc . "('". a:direction ."')"
+ if ( comfunc_result == 1 )
+ return 1
+ endif
+ endif
+
+ if g:swap_list_dont_append == 'yes'
+ let test_lists = g:swap_lists
+ else
+ let test_lists = g:swap_lists + g:default_swap_list
+ endif
+
+ let cur_word = a:word
+ let match_list = []
+
+ " Main for loop over each swaplist {{{3
+ for swap_list in test_lists
+ let word_options = swap_list['options']
+ let word_index = index(word_options, cur_word)
+
+ if word_index != -1
+ call add(match_list, swap_list)
+ endif
+ endfor
+
+ "}}}
+
+ let out = ProcessMatches(match_list, cur_word , a:direction, a:is_visual)
+ return ''
+endfun
+
+"ProcessMatches() handles various result {{{2
+fun! ProcessMatches(match_list, cur_word, direction, is_visual)
+
+ if len(a:match_list) == 0
+ if a:direction == 'forward'
+ exec 'normal' (v:count ? v:count : '') . "\<Plug>SwapItFallbackIncrement"
+ else
+ exec 'normal' (v:count ? v:count : '') . "\<Plug>SwapItFallbackDecrement"
+ endif
+ return ''
+ endif
+
+ if len(a:match_list) == 1
+ let swap_list = a:match_list[0]
+ call SwapMatch(swap_list, a:cur_word, a:direction, a:is_visual)
+ return ''
+ endif
+
+ if len(a:match_list) > 7
+ echo "Too many matches for " . a:cur_word . ". "
+ echo a:match_list
+ return ''
+ endif
+
+ if len(a:match_list) > 1
+ call ShowSwapChoices(a:match_list, a:cur_word, a:direction, a:is_visual)
+ endif
+
+endfun
+
+" SwapMatch() handles match {{{2
+fun! SwapMatch(swap_list, cur_word, direction, is_visual)
+
+ let word_options = a:swap_list['options']
+ let word_index = index(word_options, a:cur_word)
+
+ if a:direction == 'forward'
+ let word_index = ( word_index + 1 ) % len(word_options)
+ else
+ let word_index = ( word_index - 1 ) % len(word_options)
+ endif
+
+ let next_word = word_options[word_index]
+
+ let temp_reg = @s
+ let @s = next_word
+ let in_visual = 0
+
+ "XML matchit handling {{{3
+ if index(g:swap_xml_matchit, a:swap_list['name']) != -1
+
+ if match(getline("."),"<\\(\\/".a:cur_word."\\|".a:cur_word."\\)[^>]*>" ) == -1
+ return 0
+ endif
+
+ exec "norm T<ma%"
+
+ "If the cursor is on a / then jump to the front and mark
+
+ if getline(".")[col(".") -1] != "/"
+ exec "norm ma%"
+ endif
+
+ exec "norm lviw\"sp`aviw\"sp"
+ " Regular swaps {{{3
+ else
+
+ if a:is_visual == 'yes'
+ if next_word =~ '\W'
+ let in_visual = 1
+ exec 'norm! gv"sp`[v`]'
+ else
+ exec 'norm! gv"spb'
+ endif
+ else
+ if next_word =~ '\W'
+ let in_visual = 1
+ exec 'norm! maviw"sp`[v`]'
+ else
+ exec 'norm! maviw"spb`a'
+ endif
+ endif
+ endif
+ " 3}}}
+
+ "TODO VISHACK This is a silly hack to fix the visual range. if the v ends with
+ "a word character the visual range is onw column over but not for
+ "non word characters.
+
+" if in_visual == 1 && next_word =~ "\\w$" && &selection == 'inclusive'
+" exec 'norm! h'
+" endif
+
+" if in_visual == 1 && (next_word =~ "\\W$") && &selection == 'exclusive'
+" exec 'norm! l'
+" endif
+
+ let @s = temp_reg
+ " echo "Swap: " . a:swap_list['name'] .' '. a:cur_word . " > " . next_word
+ "\. ' ' . word_index . ' ' . a:direction . ' ' . len(word_options)
+ return 1
+endfun
+"
+"ShowSwapChoices() shows alternative swaps {{{2
+fun! ShowSwapChoices(match_list, cur_word, direction, is_visual)
+
+ let a_opts = ['A','B','C','D','E','F','G']
+ let con_index = 0
+ let confirm_options = ''
+ let confirm_but = ''
+
+ "Generate the prompt {{{3
+ for swap_list in a:match_list
+ let confirm_options = confirm_options . ' ' . a_opts[con_index] . " . " . swap_list['name'] . ' (' .
+ \a:cur_word . ' > ' . swap_list['options'][index(swap_list['options'], a:cur_word) + 1] . ') '
+
+ " For some reason concatenating stuffs up the string, using an
+ " if con_index > 0
+ " let confirm_but = confirm_but + '\n'
+ " endif
+ " let confirm_but = confirm_but + "option&". a_opts[con_index]
+
+ let con_index = con_index + 1
+ endfor
+ " }}}
+ " TODO Prompt This is a bit inelegant but I'm using it as the second argument of
+ " confirm wont take a concatenated string (some escape issue). At the moment I just want it
+ " to work
+ " {{{3
+ if len(a:match_list) == 2
+ let choice = confirm("Swap Options: " . confirm_options , "&A\n&B" , 0)
+ elseif len(a:match_list) == 3
+ let choice = confirm("Swap Options: ". confirm_options , "&A\n&B\n&C" , 0)
+ elseif len(a:match_list) == 4
+ let choice = confirm("Swap Options: ". confirm_options , "&A\n&B\n&C\n&D" , 0)
+ elseif len(a:match_list) == 5
+ let choice = confirm("Swap Options: ". confirm_options , "&A\n&B\n&C\n&D\n&E" , 0)
+ elseif len(a:match_list) == 6
+ let choice = confirm("Swap Options: ". confirm_options , "&A\n&B\n&C\n&D\n&E\n&F" , 0)
+ elseif len(a:match_list) == 7
+ let choice = confirm("Swap Options: ". confirm_options , "&A\n&B\n&C\n&D\n&E\&F\&G" , 0)
+ endif
+ " }}}
+ if choice != 0
+ call SwapMatch(a:match_list[choice -1], a:cur_word, a:direction, a:is_visual)
+ else
+ echo "Swap: Cancelled"
+ endif
+endfun
+"Insert Mode List Handling {{{1
+"
+"SwapInsert() call a swap list from insert mode
+fun! SwapInsert()
+ for swap_list in (g:swap_lists + g:default_swap_list)
+ if swap_list['name'] == @s
+ call complete(col('.'), swap_list['options'])
+ return ''
+ endif
+ endfor
+ return ''
+endfun
+"List Maintenance Functions {{{1
+"AddSwapList() Main Definition Function {{{2
+"use with after/ftplugin/ vim files to set up file type swap lists
+fun! AddSwapList(s_list)
+
+ let word_list = split(a:s_list,'\s\+')
+
+ if len(word_list) < 3
+ echo "Usage :SwapList <list_name> <member1> <member2> .. <membern>"
+ return 1
+ endif
+
+ let list_name = remove (word_list,0)
+
+ call add(g:swap_lists,{'name':list_name, 'options':word_list})
+endfun
+
+fun! AddSwapXmlMatchit(s_list)
+ let g:swap_xml_matchit = split(a:s_list,'\s\+')
+endfun
+"LoadFileTypeSwapList() "{{{2
+"sources .vim/after/ftplugins/<file_type>_swapit.vim
+fun! LoadFileTypeSwapList()
+
+ "Initializing the list {{{3
+" call ClearSwapList()
+ let g:swap_lists = []
+ let g:swap_list = []
+ let g:swap_xml_matchit = []
+
+ let ftpath = "~/.vim/after/ftplugin/". &filetype ."_swapit.vim"
+ let g:swap_lists = []
+ if filereadable(ftpath)
+ exec "source " . ftpath
+ endif
+
+endfun
+
+"OpenSwapFileType() Quick Access to filtype file {{{2
+fun! OpenSwapFileType()
+ let ftpath = "~/.vim/after/ftplugin/". &filetype ."_swapit.vim"
+ if !filereadable(ftpath)
+ "TODO add a directory check
+ exec "10 split " . ftpath
+ "exec 'norm! I "SwapIt.vim definitions for ' . &filetype . ': eg exec "SwapList names Tom Dick Harry\"'
+ return ''
+ else
+ exec "10 split " . ftpath
+ endif
+ exec "norm! G"
+endfun
+"Default DataSet. Add Generic swap lists here {{{1
+if g:swap_list_dont_append == 'yes'
+
+ let g:default_swap_list = []
+
+else
+ let g:default_swap_list = [
+ \{'name':'yes/no', 'options': ['yes','no']},
+ \{'name':'Yes/No', 'options': ['Yes','No']},
+ \{'name':'True/False', 'options': ['True','False']},
+ \{'name':'true/false', 'options': ['true','false']},
+ \{'name':'AND/OR', 'options': ['AND','OR']},
+ \{'name':'Hello World', 'options': ['Hello World!','GoodBye Cruel World!' , 'See You Next Tuesday!']},
+ \{'name':'On/Off', 'options': ['On','Off']},
+ \{'name':'on/off', 'options': ['on','off']},
+ \{'name':'ON/OFF', 'options': ['ON','OFF']},
+ \{'name':'comparison_operator', 'options': ['<','<=','==', '>=', '>' , '=~', '!=']},
+ \{'name': 'datatype', 'options': ['bool', 'char','int','unsigned int', 'float','long', 'double']},
+ \{'name':'weekday', 'options': ['Sunday','Monday', 'Tuesday', 'Wednesday','Thursday', 'Friday', 'Saturday']},
+ \]
+endif
+"NOTE: comparison_operator doesn't work yet but there in the hope of future
+"
+"capability
+
+" modeline: {{{
+" vim: expandtab softtabstop=4 shiftwidth=4 foldmethod=marker
View
156 snippets/html.snippets
@@ -1,52 +1,3 @@
-# Some useful Unicode entities
-# Non-Breaking Space
-snippet nbs
- &nbsp;
-# ←
-snippet left
- &#x2190;
-# →
-snippet right
- &#x2192;
-# ↑
-snippet up
- &#x2191;
-# ↓
-snippet down
- &#x2193;
-# ↩
-snippet return
- &#x21A9;
-# ⇤
-snippet backtab
- &#x21E4;
-# ⇥
-snippet tab
- &#x21E5;
-# ⇧
-snippet shift
- &#x21E7;
-# ⌃
-snippet control
- &#x2303;
-# ⌅
-snippet enter
- &#x2305;
-# ⌘
-snippet command
- &#x2318;
-# ⌥
-snippet option
- &#x2325;
-# ⌦
-snippet delete
- &#x2326;
-# ⌫
-snippet backspace
- &#x232B;
-# ⎋
-snippet escape
- &#x238B;
# Generic Doctype
snippet doctype HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
@@ -132,40 +83,40 @@ snippet meta
snippet br
<br`Close()[1:]`>
snippet div
- <div${1: }>
+ <div${1}>
${2}
</div>
snippet p
- <p${1: }>
+ <p${1}>
${2}
</p>
snippet t
- <${1:p}${2: }>${3}</$1>
+ <${1:p}${2}>${3}</$1>
snippet h1
<h1>${1}</h1>
snippet img
<img src="${1}" width="${2}" height="${3}" alt="${4}"${5: border="0" style="display:block;"}`Close()`>${6}
snippet fix
border="0" style="display:block;"
-snippet a html
- <a href="${1:}" title="${2:}" ${3}>${4}</a>
-snippet a sparkup
+snippet a
+ <a href="${1}" title="${2}" ${3}>${4}</a>
+snippet as
a[href=${1:#}][title=${2}]${3:[target=_blank]}${4}
snippet mailto
<a href="mailto:${1:joe@example.com}?subject=${2:feedback}">${3:email me}</a>
#
# <TABLE>
-snippet table html
+snippet table
<table border="${1:0}" cellpadding="${2:0}" cellspacing="${3:0}" width="${4:100%}">
${5}
</table>
-snippet table sparkup
+snippet tables
table[border=${1:0}][cellpadding=${2:0}][cellspacing=${3:0}][width=${4:100%}] > tr${5} > td[width=${6}][align=${7:left}][valign=${8:top}]${9}
snippet tr
<tr>${1}</tr>
-snippet td html
+snippet td
<td${1}>${2}</td>
-snippet td sparkup
+snippet tds
td[width=${1}][align=${2:left}][valign=${3:top}]${4}
#
# <FORM>
@@ -226,21 +177,22 @@ snippet qtmovie
pluginspage="http://www.apple.com/quicktime/download/"
`Close()[1:]`>
</object>${6}
+# http://camendesign.com/code/video_for_everybody
snippet video
- <video controls poster="$1" width="${2}" height="${3}">
- <source src="${1}.mp4" type="video/mp4">
- <source src="$1.ogv" type="video/webm">
- <source src="$1.webm" type="video/ogg">
- <object type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="$2" height="$3">
- <param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">
- <param name="allowFullScreen" value="true">
- <param name="wmode" value="transparent">
- <param name="flashVars" value="config={'playlist':['$1.jpg',{'url':'$1.mp4','autoPlay':false}]}">
- <img alt="${4:}" src="$1.jpg" width="$2" height="$3" title="No video playback capabilities, please download the video below">
+ <video width="${2}" height="${3}" controls>
+ <source src="${1}.mp4" type="video/mp4" />
+ <source src="$1.ogv" type="video/ogg" />
+ <object width="$2" height="$3" type="application/x-shockwave-flash" data="${4:player.swf}">
+ <param name="movie" value="$4" />
+ <param name="flashvars" value="controlbar=over&amp;image=$1.jpg&amp;file=$1.mp4" />
+ <img src="$1.jpg" width="$2" height="$3" alt="${5}"
+ title="No video playback capabilities, please download the video below" />
</object>
</video>
<p>
- <strong>Download video:</strong> <a href="$1.mp4">MP4 format</a> | <a href="$1.ogv">Ogg format</a> | <a href="$1.webm">WebM format</a>
+ <strong>Download Video:</strong>
+ Closed Format: <a href="$1.mp4">"MP4"</a>
+ Open Format: <a href="$1.ogv">"Ogg"</a>
</p>
#
# TEMPLATES
@@ -254,10 +206,11 @@ snippet page
<title>${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
<meta name="keywords" content="">
<meta name="description" content="">
+ ${2}
</head>
<body>
- ${2}
+ ${3}
</body>
</html>
#
@@ -275,19 +228,19 @@ snippet mail
<table cellpadding="0" width="100%" cellspacing="0" border="0">
<tr>
<td width="100%" align="center" valign="top">
- <table cellpadding="0" width="600" cellspacing="0" border="0">
+ <table cellpadding="0" width="${2:600}" cellspacing="0" border="0">
<tr>
- <td width="600" align="left" valign="top">
+ <td width="$2" align="left" valign="top">
<!--header-->
</td>
</tr>
<tr>
- <td width="600" align="left" valign="top">
- ${2:<!--content-->}
+ <td width="$2" align="left" valign="top">
+ ${3:<!--content-->}
</td>
</tr>
<tr>
- <td width="600" align="left" valign="top">
+ <td width="$2" align="left" valign="top">
<!--footer-->
</td>
</tr>
@@ -298,7 +251,56 @@ snippet mail
</body>
</html>
#
-# ENTITIES
+# Some useful Unicode entities
+# Non-Breaking Space
+snippet nbs
+ &nbsp;
+# ←
+snippet left
+ &#x2190;
+# →
+snippet right
+ &#x2192;
+# ↑
+snippet up
+ &#x2191;
+# ↓
+snippet down
+ &#x2193;
+# ↩
+snippet return
+ &#x21A9;
+# ⇤
+snippet backtab
+ &#x21E4;
+# ⇥
+snippet tab
+ &#x21E5;
+# ⇧
+snippet shift
+ &#x21E7;
+# ⌃
+snippet control
+ &#x2303;
+# ⌅
+snippet enter
+ &#x2305;
+# ⌘
+snippet command
+ &#x2318;
+# ⌥
+snippet option
+ &#x2325;
+# ⌦
+snippet delete
+ &#x2326;
+# ⌫
+snippet backspace
+ &#x232B;
+# ⎋
+snippet escape
+ &#x238B;
+# accented letters
snippet &A À
&Agrave;
snippet &A Á
View
3 vimrc
@@ -229,7 +229,7 @@ nnoremap & :'{,'}s/<c-r>=expand('<cword>')<cr>/
autocmd FileType vim nnoremap <leader>g I" <Esc>A "<Esc>yyp0lv$hhr"yykPjj
autocmd FileType python,ruby,sh,zsh nnoremap <leader>g I# <Esc>A #<Esc>yyp0lv$hhr-yykPjj
-autocmd InsertLeave * if &modified && expand('%')!=''|write|endif
+autocmd InsertLeave * if &modified && expand('%') != '' | write | endif
"""""""""""""""""""
" PLUGIN SETTINGS "
@@ -263,6 +263,7 @@ let g:ctrlp_buftag_types={
let delimitMate_expand_cr=1
let delimitMate_expand_space=1
+let delimitMate_excluded_ft = "html"
let g:syntastic_check_on_open=0
let g:syntastic_enable_balloons=0

0 comments on commit b022a8d

Please sign in to comment.
Something went wrong with that request. Please try again.