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

Monday, February 7, 2011

Perl Omni Completion with VIM ( aka intelli sense)


Download omniperl Vim pluginn :
http://www.vim.org/scripts/script.php?script_id=1924

goto your Vim's runtime directory :
Ex: ~/.vim

extract omniperl.zip there then open omniperl.vba with vim :
$cd ~/.vim
$unzip omniperl.zip
$vim omniperl.vba

they type :so %
(so that it will extracts required files from vba file
*Note: if you got any errors try to install vimball plug in before doing above step
http://www.vim.org/scripts/script.php?script_id=1502
follow instructions in 'install details section
)

open your .vimrc file and put below lines :
"===================================
filetype plugin on
autocmd FileType pl set omnifunc=perlcomplete#OmniPerl_Complete
function! SmartComplete ()
" Remember where we parked...
let cursorpos = getpos('.')
let cursorcol = cursorpos[2]
let curr_line = getline('.')

" Special subpattern to match only at cursor position...
let curr_pos_pat = '\%' . cursorcol . 'c'

" Tab as usual at the left margin...
if curr_line =~ '^\s*' . curr_pos_pat
return "\<TAB>"
endif

" If no contextual match and after an identifier, do keyword completion...
if curr_line =~ '\k' . curr_pos_pat
return "\<C-N>"

" Otherwise, just be a ...
endif
if curr_line =~ '\(\->\|::\)' . curr_pos_pat
return "\<C-X>\<C-O>"
else
return "\<TAB>"
endif
endfunction

" Remap for smart completion on various characters...
inoremap =SmartComplete()
"===================================





you are done with it !!

now you can test it , open a new perl file :

$vim test.pl

now type below :

use DBI;
DBI->

pressing tab after typing DBI-> will popup methods of that module.

Damn good isn't it???

Happy Vimming !!


Saturday, January 29, 2011

Generate CSV list in Vim

Put below mappings in your .vimrc file :

nnoremap \, :%s/$/,/:%g/^/-j
vnoremap \, y:$opmz:'z,$s/$/,/:'z,$g/^/-j


Example :

for example if you have numbers as :
1
2
3
4
5
6
7
8
9
10

inorder to make csv list out of that, after putting those mappings in .vimrc file just press \,
in command mode will generate :
1 2, 3, 4, 5, 6, 7, 8, 9, 10,

you can select particular lines or block using visual mode and can generate csv only for that values also.

Happy Vimming !!

Regards,
Satya

Wednesday, January 5, 2011

Free WinRAR equivalent for Mac(View .rar file contents).

Itz : Zipeg(shareware).
URL : http://www.zipeg.com/

Thanks
Satya

Followers