" Configuration file for vim " vim: set softtabstop=4 shiftwidth=4 foldmethod=marker: " Opciones generales {{{ " Normally we use vim-extensions. If you want true vi-compatibility " remove change the following statements set nocompatible " Use Vim defaults (much better!) set binary " Para que no guarde \n al final "set backspace=indent,eol,start " more powerful backspacing " Now we set some defaults for the editor "set autoindent " always set autoindenting on set textwidth=80 " Wrap words by default set nobackup " Don't keep a backup file set viminfo='20,\"50 " read/write a .viminfo file, don't store more than " 50 lines of registers set history=50 " keep 50 lines of command line history set ruler " show the cursor position all the time " Suffixes that get lower priority when doing tab completion for filenames. " These are files we are not likely to want to edit or read. set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc " Vim5 and later versions support syntax highlighting. Uncommenting the next " line enables syntax highlighting by default. syntax on " The following are commented out as they cause vim to behave a lot " different from regular vi. They are highly recommended though. set showcmd " Show (partial) command in status line. set showmatch " Show matching brackets. set ignorecase " Do case insensitive matching set incsearch " Incremental search set autowrite " Automatically save before commands like :next and :make set linebreak " Breaks the line by words set showbreak=-> " Shows this string before broken lines "set wrapmargin=2 set ttyfast "set tabstop=8 "set shiftwidth=4 "set softtabstop=4 set modeline set modelines=5 " Hace que el vim busque opciones en los archivos con vim:: " Colores. " colorscheme darkblue " }}} " Funcion para actualizar los ctags. {{{ function SyncCTags() let php_ctagsfile = tempname() exec 'silent ! ctags -f ' . php_ctagsfile . ' %' redraw! exec 'setlocal tags=' . php_ctagsfile endfunction " Sincroniza ctags. call SyncCTags() " }}} " Mapeo del teclado {{{ " Inserta fecha con Ctrl-d noremap :read !datekJa " Arregla Shift-Backspace inoremap " Pegar en modo inserción. inoremap lpa " Make p in Visual mode replace the selected text with the "" register. vnoremap p :let current_reg = @"gvdi=current_reg " Mapea para sincronizar ctags. noremap :call SyncCTags() " WindowManager y ctags (mié abr 9 14:01:54 ART 2003) {{{ noremap :WMToggle:FirstExplorerWindow noremap :FirstExplorerWindow noremap :BottomExplorerWindow let Tlist_WinWidth = 20 let winManagerWindowLayout = 'TagList,FileExplorer|BufExplorer' " }}} " Autocompletion con Tab y Shift-Tab {{{ function! CleverTab() if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' return "\" else return "\" endfunction function! CleverShiftTab() if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' return "\" else return "\" endfunction inoremap =CleverTab() inoremap =CleverShiftTab() "inoremap "inoremap " }}} " Teclas para salir. {{{ noremap :WMClose:xa noremap :qa! " }}} " Chequeo de ortografía con F8. {{{ noremap :w:!aspell -c %:e " Chequeo de ortografía para mails. autocmd FileType mail :nmap :w:!aspell -e -c %:e " Chequeo de ortografía para SGML-like. autocmd FileType html,xml,sgmllnx,sgml,smil,docbk :nmap :w:!aspell -H -c %:e " Chequeo de ortografía para TeX. autocmd FileType tex :nmap :w:!aspell -t -c %:e " }}} " }}} " Autocomands {{{ " Definicion de llamados a funciones por autocommands {{{ if !exists("autocommads_loaded") let autocommads_loaded = 1 "augroup c "autocmd BufNewFile,BufRead *.c call C() "augroup END autocmd FileType html call Html() "autocmd BufNewFile,BufRead *.sh call Sh() autocmd FileType php call Php() autocmd FileType xml call Xml() " Resaltado de svn commit logs. autocmd BufNewFile,BufRead svn-commit.*tmp setf svn endif " }}} " Configuración de syntax highlight de PHP {{{ " (parece que no se puede poner en el autocomando " porque se carga después que el php.vim). let php_folding = 1 let php_sql_query = 1 let php_htmlInStrings = 1 let php_baselib = 1 let php_parent_error_open = 1 let php_parent_error_close = 1 " }}} " Autocommands para PHP {{{ function Php() " Asigna phpman para manejar las 'man pages' setlocal keywordprg=phpman " Asigna Ctrl-K para ver un hint sobre la sintaxis de la función. nnoremap :call PhpMan() inoremap :call PhpMan()a nnoremap :call PhpManHint() " Ordena mejor el autocompletado y usa diccionario de funciones de PHP. setlocal complete=],k~/.vim/php.dict,.,w,b,u,i " Limita el ancho a 80 caracteres. setlocal textwidth=80 " Indenta tipo C. setlocal cindent " Set 'comments' to format dashed lists in comments. setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://,:# " Set 'formatoptions' to break comment lines but not other lines, " and insert the comment leader when hitting or using "o". setlocal fo-=t fo+=croql " Don't concatenate a line that ends with a backslash setlocal cpo-=C " Compilador tidy compiler tidy " Mapea keywords de PHP. inorea 2hi inorea 2hi inorea class class {}khi inorea function function() {}k3hi inorea if if {}khi inorea elseif elseif {}khi inorea else else {}ko xxa inorea while while {}khi inorea for for {}khi inorea foreach foreach {}khi " Quotes. inoremap " ""i inoremap ' ''i inoremap ` ``i inoremap ( ()i inoremap { {}i inoremap [ []i endfunction " }}} " Función para emular man con el manual de PHP usando links. {{{ function PhpMan() let func = substitute(expand(''), '_', '-', 'g') let file = '/usr/share/doc/phpdoc/html/function.' . func . '.html' let hint = system('links --dump ' . file . ' 2>&1 |egrep -A2 -m1 "^Description" |tail -n1 |cut -b 4-') let hint = strpart(hint, 0, stridx(hint, "\n")) if hint != '' exe 'silent ! links ' . file redraw! else echohl WarningMsg echomsg 'No existe la función "' . func . '"!' echohl None endif endfunction " }}} " Función para dar un hint sobre la sintaxis de una función de PHP. {{{ function PhpManHint() let func = substitute(expand(''), '_', '-', 'g') let file = '/usr/share/doc/phpdoc/html/function.' . func . '.html' let hint = system('links --dump ' . file . ' 2>&1 |egrep -A2 -m1 "^Description" |tail -n1 |cut -b 4-') let hint = strpart(hint, 0, stridx(hint, "\n")) if hint != '' echo hint else echohl WarningMsg echomsg 'No existe la función "' . func . '"!' echohl None endif endfunction " }}} " Funcion para manejo de archivos Html {{{ function Html() " Format comments to be up to 80 characters long setlocal tw=80 " Don't concatenate a line that ends with a backslash setlocal cpo-=C " Compilador tidy compiler tidy " Lista de TAGs. let htmltags = "html head title body h1 h2 h3 h4 h5 p b i u abbr code" let htmltags = htmltags . "pre center strong font span div ul ol li" let htmltags = htmltags . "table thead tbody tfoot th tr td form select" let htmltags = htmltags . "textarea tt a" " Obtengo próximo elemento. let htmltag = substitute(htmltags, "\\([^ ]\\+\\).*", "\\1", "") " Borro elemento de la lista temporal let rest = substitute(htmltags, "[^ ]\\+ \\(.*\\)", "\\1", "") while strlen(rest) " Mapeo en insersión. call MapInsertHtmlTag(htmltag) " Mapeo Visual. call MapVisualHtmlTag(htmltag) " Si se acabaron los TAGs. if rest == htmltag let rest = "" " Si hay más, obtengo el próximo. else " Obtengo próximo elemento. let htmltag = substitute(rest, "\\([^ ]\\+\\).*", "\\1", "") " Borro elemento de la lista temporal let rest = substitute(rest, "[^ ]\\+ \\(.*\\)", "\\1", "") endif endwhile " Limpio variables que no uso más. unlet htmltags unlet htmltag unlet rest " Mapeo en insersión. inoremap 3hi inoremap 3hi inoremap 3hi " Identa un HTML y pone atributos en minusculas. noremap :w1GdG:read !hindent -i4 -t0 % " Corige HTML con el tidy. noremap :w1GdG:read !tidy % 2> /dev/null1Gdd " Cambia el case a minuscula de atributos y a mayusculas de tags. noremap :%s/<\(\/\?\)\([a-z0-9]\+\)\(\( .[^>]\+\)\?\/\?\)>/<\1\U\2\E\3>/g:%s/\([a-z-]\+\)=/\L\1\e=/g/laksjlakjdaklsj: " Quotes. inoremap " ""i endfunction " }}} " Función que mapea en modo visual un TAG HTML {{{ " de modo que nombre se convierte en . function MapVisualHtmlTag(name) let name = substitute(a:name, "\.*", "\\U\\0\\E", "") exec "vnoremap " . a:name . " di<" . name . ">pa" endfunction " }}} " Función que mapea en modo insersión un TAG HTML. {{{ function MapInsertHtmlTag(name) let leng = strlen(a:name) + 2 let name = substitute(a:name, "\.*", "\\U\\0\\E", "") exec "inorea <" . a:name . "> <" . name . ">" . leng . "hi" exec "inorea <" . name . "> <" . name . ">" . leng . "hi" endfunction " }}} " Autocommands para XML {{{ function Xml() " Usa folding. setlocal foldmethod=syntax " Quotes. inoremap " ""i inoremap ' ''i inoremap ` ``i inoremap ( ()i inoremap { {}i inoremap [ []i endfunction " }}} " }}}