1 " Configuration file for vim
2 " vim: set softtabstop=4 shiftwidth=4 foldmethod=marker:
4 " Opciones generales {{{
5 " Normally we use vim-extensions. If you want true vi-compatibility
6 " remove change the following statements
7 set nocompatible " Use Vim defaults (much better!)
8 set binary " Para que no guarde \n al final
9 "set backspace=indent,eol,start " more powerful backspacing
10 " Now we set some defaults for the editor
11 "set autoindent " always set autoindenting on
12 set textwidth=80 " Wrap words by default
13 set nobackup " Don't keep a backup file
14 set viminfo='20,\"50 " read/write a .viminfo file, don't store more than
15 " 50 lines of registers
16 set history=50 " keep 50 lines of command line history
17 set ruler " show the cursor position all the time
19 " Suffixes that get lower priority when doing tab completion for filenames.
20 " These are files we are not likely to want to edit or read.
21 set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
23 " Vim5 and later versions support syntax highlighting. Uncommenting the next
24 " line enables syntax highlighting by default.
27 " The following are commented out as they cause vim to behave a lot
28 " different from regular vi. They are highly recommended though.
29 set showcmd " Show (partial) command in status line.
30 set showmatch " Show matching brackets.
31 set ignorecase " Do case insensitive matching
32 set incsearch " Incremental search
33 set autowrite " Automatically save before commands like :next and :make
34 set linebreak " Breaks the line by words
35 set showbreak=-> " Shows this string before broken lines
42 set modelines=5 " Hace que el vim busque opciones en los archivos con vim:<opts>:
45 " colorscheme darkblue
48 " Funcion para actualizar los ctags. {{{
50 let php_ctagsfile = tempname()
51 exec 'silent ! ctags -f ' . php_ctagsfile . ' %'
53 exec 'setlocal tags=' . php_ctagsfile
59 " Mapeo del teclado {{{
61 " Inserta fecha con Ctrl-d
62 noremap <C-D> <esc>:read !date<cr>kJ<end>a
64 " Arregla Shift-Backspace
65 inoremap <S-Del> <backspace>
67 " Pegar en modo inserción.
68 inoremap <C-V> <Esc>lpa
70 " Make p in Visual mode replace the selected text with the "" register.
71 vnoremap p <esc>:let current_reg = @"<cr>gvdi<C-R>=current_reg<cr><esc>
73 " Mapea <F1> para sincronizar ctags.
74 noremap <F1> :call SyncCTags()<CR>
76 " WindowManager y ctags (mié abr 9 14:01:54 ART 2003) {{{
77 noremap <silent> <F2> :WMToggle<CR>:FirstExplorerWindow<CR>
78 noremap <silent> <F3> :FirstExplorerWindow<CR>
79 noremap <silent> <F4> :BottomExplorerWindow<CR>
80 let Tlist_WinWidth = 20
81 let winManagerWindowLayout = 'TagList,FileExplorer|BufExplorer'
84 " Autocompletion con Tab y Shift-Tab {{{
86 if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
91 function! CleverShiftTab()
92 if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
97 inoremap <Tab> <C-R>=CleverTab()<CR>
98 inoremap <S-Tab> <C-R>=CleverShiftTab()<CR>
99 "inoremap <C-Tab> <C-N>
100 "inoremap <S-C-Tab> <C-P>
103 " Teclas para salir. {{{
104 noremap <silent> <F10> <Esc>:WMClose<CR>:xa<CR>
105 noremap <silent> <F11> <Esc>:qa!<CR>
108 " Chequeo de ortografía con F8. {{{
109 noremap <f8> :w<cr>:!aspell -c %<cr>:e<cr>
111 " Chequeo de ortografía para mails.
112 autocmd FileType mail :nmap <f8> :w<cr>:!aspell -e -c %<cr>:e<cr>
114 " Chequeo de ortografía para SGML-like.
115 autocmd FileType html,xml,sgmllnx,sgml,smil,docbk :nmap <f8> :w<cr>:!aspell -H -c %<cr>:e<cr>
117 " Chequeo de ortografía para TeX.
118 autocmd FileType tex :nmap <f8> :w<cr>:!aspell -t -c %<cr>:e<cr>
124 " Definicion de llamados a funciones por autocommands {{{
125 if !exists("autocommads_loaded")
126 let autocommads_loaded = 1
128 "autocmd BufNewFile,BufRead *.c call C()
130 autocmd FileType html call Html()
131 "autocmd BufNewFile,BufRead *.sh call Sh()
132 autocmd FileType php call Php()
133 autocmd FileType xml call Xml()
134 " Resaltado de svn commit logs.
135 autocmd BufNewFile,BufRead svn-commit.*tmp setf svn
139 " Configuración de syntax highlight de PHP {{{
140 " (parece que no se puede poner en el autocomando
141 " porque se carga después que el php.vim).
143 let php_sql_query = 1
144 let php_htmlInStrings = 1
146 let php_parent_error_open = 1
147 let php_parent_error_close = 1
150 " Autocommands para PHP {{{
152 " Asigna phpman para manejar las 'man pages'
153 setlocal keywordprg=phpman
154 " Asigna Ctrl-K para ver un hint sobre la sintaxis de la función.
155 nnoremap <C-K> :call PhpMan()<CR>
156 inoremap <C-K> <Esc>:call PhpMan()<CR>a
157 nnoremap <S-K> :call PhpManHint()<CR>
158 " Ordena mejor el autocompletado y usa diccionario de funciones de PHP.
159 setlocal complete=],k~/.vim/php.dict,.,w,b,u,i
160 " Limita el ancho a 80 caracteres.
161 setlocal textwidth=80
164 " Set 'comments' to format dashed lists in comments.
165 setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://,:#
166 " Set 'formatoptions' to break comment lines but not other lines,
167 " and insert the comment leader when hitting <CR> or using "o".
168 setlocal fo-=t fo+=croql
169 " Don't concatenate a line that ends with a backslash
173 " Mapea keywords de PHP.
174 inorea <buffer> <? <? ?><Esc>2hi
175 inorea <buffer> <?= <?= ?><Esc>2hi
176 inorea <buffer> class class {<CR>}<Esc>k<End>hi
177 inorea <buffer> function function() {<CR>}<Esc>k<End>3hi
178 inorea <buffer> if if {<CR>}<Esc>k<End>hi
179 inorea <buffer> elseif elseif {<CR>}<Esc>k<End>hi
180 inorea <buffer> else else {<CR>}<Esc>k<End>o <Esc>xxa
181 inorea <buffer> while while {<CR>}<Esc>k<End>hi
182 inorea <buffer> for for {<CR>}<Esc>k<End>hi
183 inorea <buffer> foreach foreach {<CR>}<Esc>k<End>hi
185 inoremap <buffer> " ""<Esc>i
186 inoremap <buffer> ' ''<Esc>i
187 inoremap <buffer> ` ``<Esc>i
188 inoremap <buffer> ( ()<Esc>i
189 inoremap <buffer> { {}<Esc>i
190 inoremap <buffer> [ []<Esc>i
194 " Función para emular man con el manual de PHP usando links. {{{
196 let func = substitute(expand('<cword>'), '_', '-', 'g')
197 let file = '/usr/share/doc/phpdoc/html/function.' . func . '.html'
198 let hint = system('links --dump ' . file . ' 2>&1 |egrep -A2 -m1 "^Description" |tail -n1 |cut -b 4-')
199 let hint = strpart(hint, 0, stridx(hint, "\n"))
201 exe 'silent ! links ' . file
205 echomsg 'No existe la función "' . func . '"!'
211 " Función para dar un hint sobre la sintaxis de una función de PHP. {{{
212 function PhpManHint()
213 let func = substitute(expand('<cword>'), '_', '-', 'g')
214 let file = '/usr/share/doc/phpdoc/html/function.' . func . '.html'
215 let hint = system('links --dump ' . file . ' 2>&1 |egrep -A2 -m1 "^Description" |tail -n1 |cut -b 4-')
216 let hint = strpart(hint, 0, stridx(hint, "\n"))
221 echomsg 'No existe la función "' . func . '"!'
227 " Funcion para manejo de archivos Html {{{
229 " Format comments to be up to 80 characters long
231 " Don't concatenate a line that ends with a backslash
236 let htmltags = "html head title body h1 h2 h3 h4 h5 p b i u abbr code"
237 let htmltags = htmltags . "pre center strong font span div ul ol li"
238 let htmltags = htmltags . "table thead tbody tfoot th tr td form select"
239 let htmltags = htmltags . "textarea tt a"
240 " Obtengo próximo elemento.
241 let htmltag = substitute(htmltags, "\\([^ ]\\+\\).*", "\\1", "")
242 " Borro elemento de la lista temporal
243 let rest = substitute(htmltags, "[^ ]\\+ \\(.*\\)", "\\1", "")
245 " Mapeo en insersión.
246 call MapInsertHtmlTag(htmltag)
248 call MapVisualHtmlTag(htmltag)
249 " Si se acabaron los TAGs.
252 " Si hay más, obtengo el próximo.
254 " Obtengo próximo elemento.
255 let htmltag = substitute(rest, "\\([^ ]\\+\\).*", "\\1", "")
256 " Borro elemento de la lista temporal
257 let rest = substitute(rest, "[^ ]\\+ \\(.*\\)", "\\1", "")
260 " Limpio variables que no uso más.
264 " Mapeo en insersión.
265 inoremap <buffer> <C-H><C-B> <B></B><Esc>3hi
266 inoremap <buffer> <C-H><C-U> <U></U><Esc>3hi
267 inoremap <buffer> <C-H><C-I> <I></I><Esc>3hi
268 " Identa un HTML y pone atributos en minusculas.
269 noremap <buffer> <silent> <C-I> :w<cr>1GdG:read !hindent -i4 -t0 %<cr>
270 " Corige HTML con el tidy.
271 noremap <buffer> <silent> <C-T> :w<cr>1GdG:read !tidy % 2> /dev/null<cr>1Gdd
272 " Cambia el case a minuscula de atributos y a mayusculas de tags.
273 noremap <buffer> <silent> <C-U> :%s/<\(\/\?\)\([a-z0-9]\+\)\(\( .[^>]\+\)\?\/\?\)>/<\1\U\2\E\3>/g<cr>:%s/\([a-z-]\+\)=/\L\1\e=/g<CR>/laksjlakjdaklsj<CR>:<Esc>
275 inoremap <buffer> " ""<Esc>i
279 " Función que mapea en modo visual un TAG HTML {{{
280 " de modo que nombre se convierte en <NOMBRE></NOMBRE>.
281 function MapVisualHtmlTag(name)
282 let name = substitute(a:name, "\.*", "\\U\\0\\E", "")
283 exec "vnoremap <buffer> " . a:name . " di<" . name . "><Esc>pa</" . name . "><Esc>"
287 " Función que mapea en modo insersión un TAG HTML. {{{
288 function MapInsertHtmlTag(name)
289 let leng = strlen(a:name) + 2
290 let name = substitute(a:name, "\.*", "\\U\\0\\E", "")
291 exec "inorea <buffer> <" . a:name . "> <" . name . "></" . name . "><Esc>" . leng . "hi"
292 exec "inorea <buffer> <" . name . "> <" . name . "></" . name . "><Esc>" . leng . "hi"
296 " Autocommands para XML {{{
299 setlocal foldmethod=syntax
301 inoremap <buffer> " ""<Esc>i
302 inoremap <buffer> ' ''<Esc>i
303 inoremap <buffer> ` ``<Esc>i
304 inoremap <buffer> ( ()<Esc>i
305 inoremap <buffer> { {}<Esc>i
306 inoremap <buffer> [ []<Esc>i