"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " keywords.vim -- functions to move and quote keyword text " " Author: Anders Thøgersen " Email: NaOnSdPeArMslt@gmail.com -- remove the capitol letters " Last Change: 12-Okt-2004 " Version: 0.4 " " Licence: This program is public domain; " " Download From: " http://www.vim.org/scripts/script.php?script_id=?? " " Description: " " This scripts provides two functionalities that use the iskeyword setting of " the current buffer. " " The following mappings are provided for moving keywords in normal mode: " " : exchange the current keyword with the previous one. " : exchange the current keyword with the next one. " " These mappings can be changed by changing the value of the following variables. " " let g:keywords_MoveWordL = '' " let g:keywords_MoveWordR = '' " " Also several mappings for adding/deleting "quotes" to/from a keyword or a " visually selected area. The mappings are as follows: " " qw, q" : double quote " qs, q' : single quote " qe, q` : quote execute " q[, q] : quote with square brackets " q{, q} : quote with brackets " q(, q) : quote with parantheses " q<, q> : quote with xml style tag. " " If you wish to provide a different map leader than 'q' use this variable: " " let g:keywords_MapLeader = 'q' " " There is one normal mode mapping for removing quotes from a keyword: " " wq : removes non iskeyword material around the current keyword. " " Consider sending an email if you have suggestions or comments :-) " if exists('loaded_keywords_script') || &cp finish endif let loaded_keywords_script = 1 if !exists("g:keywords_MoveWordL") let g:keywords_MoveWordR = '' endif if !exists("g:keywords_MoveWordL") let g:keywords_MoveWordL = '' endif if !exists("g:keywords_MapLeader") let g:keywords_MapLeader = 'q' endif let b:keywords_isk = 'a-zA-Z0-9_' " {{{1 Quote(l, r) : quote a word konsisting of letters from iskeyword fun! KeywordsQuote(lquote, rquote) normal mz exe 's/\(\k*\%#\k*\)/' . a:lquote . '\1' . a:rquote . '/' normal `zl endfun " {{{1 QuoteVisual(l, r) function! KeywordsQuoteVisual(lquote, rquote) let save = @" silent normal gvy let @" = a:lquote . @" . a:rquote silent normal gvp let @" = save endfunction " {{{1 UnQuote fun! KeywordsUnQuote() normal mz exe 's/[^' . b:keywords_isk . ']\(\k*\%#\k*\)[^' . b:keywords_isk . ']/\1/' normal `zh endfun " {{{1 IskeywordChars : output a regex for matching a keyword fun! KeywordsIskeywordChars() let isk = escape(&iskeyword, "^$.\\/") let chars = substitute(isk, '\(\d\+\)-\(\d\+\)', '\=nr2char(submatch(1))."-".nr2char(submatch(2))', 'g') let chars = substitute(chars, ",-,", ',', "g") " cheat! let chars = substitute(chars, ",a-z,", ',', "g") " cheat! let chars = substitute(chars, ",A-Z,", ',', "g") " cheat! let chars = substitute(chars, ",", "", "g") . 'a-zA-Z' return chars endfun " {{{1 MoveWordsSetup augroup augroup KeywordsMoveWordsSetup au! autocmd BufReadPost * if &modifiable autocmd BufReadPost * let b:keywords_isk = KeywordsIskeywordChars() autocmd BufReadPost * exe 'nnoremap '. g:keywords_MoveWordR .' "_yiw?\k\+\_[^'. b:keywords_isk .']\+\%#:s/\(\%#\k\+\)\(\_[^'. b:keywords_isk .']\+\)\(\k\+\)/\3\2\1/e' autocmd BufReadPost * exe 'nnoremap '. g:keywords_MoveWordL .' "_yiw:s/\(\%#\k\+\)\(\_[^'. b:keywords_isk .']\+\)\(\k\+\)/\3\2\1/e/\k\+\_[^'. b:keywords_isk .']\+' autocmd BufReadPost * endif augroup END " {{{1 Default mappings " KeywordsAddMap(key, left, right) : Add mappings for visual and normal modes fun! KeywordsAddMap(key, left, right) let lmapping = 'noremap ' . g:keywords_MapLeader . a:key . ' :call ' let rmapping = '("' . a:left . '", "' . a:right . '")' exe 'n' . lmapping . 'KeywordsQuote' . rmapping exe 'v' . lmapping . 'KeywordsQuoteVisual' . rmapping endfun " {{{1 The mappings call KeywordsAddMap('w', "\\\"", "\\\"") call KeywordsAddMap('s', "'", "'") call KeywordsAddMap('e', "`", "`") " quote execute call KeywordsAddMap('m', "`", "'") " m4 quotes call KeywordsAddMap("'" , "'" , "'") call KeywordsAddMap('\\\"' , "\\\"" , "\\\"") call KeywordsAddMap('`' , "`" , "`") call KeywordsAddMap(']', "[", "]") call KeywordsAddMap('}', "(", ")") call KeywordsAddMap(')', "{", "}") call KeywordsAddMap('>', "<", ">") call KeywordsAddMap('[', "[", "]") call KeywordsAddMap('{', "(", ")") call KeywordsAddMap('(', "{", "}") call KeywordsAddMap('<', "<", ">") " for tags nnoremap wq :call KeywordsUnQuote()