@Andy_McPalace http://t.co/BkcDzHSK

Buscar archivo debajo del cursor en VIM

Trabajando con una aplicación que usa templates, me encontré muchas veces viendo que cierto script abre después cierto template, si quiero ver ese archivo, tengo que buscarlo. Lo mismo si tengo imports..

Buscando en el wiki de vim encontre un script que sirve para encontrar archivos dentro del directorio donde estas parado (cd).. Yo lo modifiqué un poco y quedó asi:

"Function for finding files
" Find file in current directory and edit it.
function! Find(name)
  let l:list=system("find . -name '".a:name."*[htm|html|php]' | grep -v .svn | perl -ne 'print \"$.\\t$_\"'")
  let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))
  if l:num < 1
    echo "'".a:name."' not found"
    return
  endif
  if l:num != 1
    echo l:list
    let l:input=input("Which ? (CR=nothing)\n")
    if strlen(l:input)==0
      return
    endif
    if strlen(substitute(l:input, "[0-9]", "", "g"))>0
      echo "Not a number"
      return
    endif
    if l:input<1 || l:input>l:num
      echo "Out of range"
      return
    endif
    let l:line=matchstr("\n".l:list, "\n".l:input."\t[^\n]*")
  else
    let l:line=l:list
  endif
  let l:line=substitute(l:line, "^[^\t]*\t./", "", "")
  execute ":e ".l:line
endfunction
command! -nargs=1 Find :call Find("<args>")

Esta funcion se usa haciendo algo como

:Find <nombre>

Lo que hice fue que busce archivos con extension especificas [html|htm|php] y evita el directorio “.svn”. Este script se puede modificar de muchas formas, así es como me sirve a mi…

Otro detalle que le hice, fue hacer un keybiding para buscar directamente, sin escribir el comando.

:nmap <leader>f "zyiw:exe "Find ".@z.""<CR>

De esta forma con ”\f” buscas el archivo en el que el cursor esta parado. OJO si cambiaste el leader de VIM que cambia el binding.