Wednesday, March 23, 2011

Extend your bash completion !!

I have downloaded zip file, I wanna extract it on command line.

$ unzip [tab][tab] -> if it displays only zip files instead of all files is that won't be good ?

Yes !!

here you go :

put below line(s) in your .bashrc file or in .bash_profile you are done with it !!
complete -A file -X '!*.zip' unzip

for other completions :

complete -A file -X '!*.php' php
complete -A file -X '!*.pl' perl
complete -A file -X '!*.c' gcc
complete -A file -X '!*.sh' bash
complete -A file -X '!*.gz' gunzip
complete -A file -X '!*.tgz' gunzip
complete -A file -X '!*.Z' gunzip
complete -A file -X '!*.gz' tar
complete -A file -X '!*.tgz' tar
complete -A file -X '!*.Z' tar
complete -A file -X '!*.awk' awk
complete -A file -X '!*.sed' sed
complete -A file -X '!*.zip' unzip

now you can get completion for php,perl or create for any of your favorite language.

Thanks,
Satya

Thursday, March 3, 2011

Persistent undo with Vim 7.3

Persistent Undo -> You can do undo after save and quit, reopen later on a file.

Create a directory 'undodir' under your Vim's runtime path i.e ~/.vim
$ mkdir ~/.vim/undodir

Put below settings in your .vimrc file :
"================================
au BufWritePre /tmp/* setlocal noundofile
set undodir=~/.vim/undodir
set undofile
set undolevels=1000 "maximum number of changes that can be undone
set undoreload=10000 "maximum number lines to save for undo on a buffer reload
"================================

Save .vimrc and quit.

Now open some text file do some changes in it, save and exit. Re-open the same file and press 'u' will undo your previous changes.

Happy Vimming !!

Thanks,
Satya

Followers