@snisnik esta bueno.. Pero es bastante incomodo acostumbrarse

Finding file under cursor on VIM

Working in a big project, I had the problem that the scripts included lots of files and used a lot of templates that were called programatically, because of that, I was looking for files a lot.

Searching the vim wiki I found a script that is used to find files inside a directory and choose the file you need. I’ve modified it a bit and finally it looks like this:

"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>")

The function is used doing something like

:Find <name>

The real thing here is to map a keybiding to search the file where the cursor is standing.. Like this:

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

This way, with the keystroke “\f” you start the function searching for the word under cursor. Be aware that the keybinding changes if you modified your leader variable.

Recursive search inside files in vim

I just knew about the :vimgrep command inside vim, it is used to search a pattern in a filetree, us it like:

vimgrep /$.ajax/ **/*.html

then, you can check all the files that resulted of that command with:

:copen

BTW: vim is *awesome*!

Encrypt files in unix

As my memory sucks I have an encrypted file that stores passwords. Of course I need a secure way to do that.. what I do is this:

To encrypt:

openssl des3 -salt -in passwords -out passwords.crypt

To decrypt:

openssl des3 -d -salt -in passwords.crypt -out passwords

UPDATE:
I just realized that VIM has a built in way to encrypt and decrypt files that works great.. You must use the -x option

vim -x [filename]

Css tip of the day

*{ outline: none; }

It get rids of the stupid border around inputs

I love VIM

If you read the previous post, you will understand why this is awesome

:%s/^\(\d\d\)\(.*\)/<li><a href="images\/membranofonos\/\1.jpg">\2<\/a><\/li>

Renaming files in batch

Yesterday I stumbled upon a problem renaming files. I had a really big bunch of files named as [numbers]{abigpileofcharacters}.jpeg/gif. I needed to work with filenames more standarized, something like [numbers].jpeg/gif.

First problem was finding a way to rename those files. I thought of a piped mv command with some sed or something like that, but it got complicated.. so I asked on my favorite IRC channel and a friend told me about a script that comes inside a Debian package when you install XFCE, that script is named prename, it is a modification of an old script named rename. It’s written in perl and its Awesome!

It’s awesome because of this:

perl renamer.pl 's/(\d+).*\.([\w]+)/$1.$2/' *.*

If you dont understand that, go read about Regular expressions. The script renames the files according to the regular expressions using $1 and $2. That’s just awesome.

As the Debian package is not usable in OsX I’ve uploaded to GitHub and BitBucket.