Tuesday, August 24, 2010

Vim with status.

It is obviously for VIM editor users only :)

Why? - You might have so many mappings in your .vimrc,
but while editing are you really using all of
your mappings?

Sometimes a question might also answers you !!

How? -

$ vim .vimrc

Lets take an example :

I wanna add a mapping to display line numbers when ever
I press F2 key twice.

add below line to your .vimrc to map F2 key to display line numbers:

nnoremap <F2><F2> :set invnu nu?<CR> " use F2F2 to toggle line numbers.

Now its time to add Status Bar.

add below lines to your .vimrc to show status bar:

" first, enable status line always
set laststatus=2
highlight StatusLine guifg=darkred ctermbg=darkred ctermfg=blue
set statusline =%F%m%r%h%w\ [<F2>=nu]


launch vim with a text file:

$ man grep | col -b > /tmp/grep.txt && vim /tmp/grep.txt

now you can see bottom of vim editor status bar appears which shows your mapping as '[<F2>=nu]'.

Press F2 twice to show line numbers, again press F2 twice to switch off line numbers.

Go Ahead and add more mappings:

Example:

let g:I=0
function! INC(increment)
let g:I =g:I + a:increment
return g:I
endfunction

nnoremap <F1><F1> :set invnu nu?<CR>

nnoremap <F5><F5> :set invhls hls?<CR>

nnoremap <F4><F4> :set invwrap wrap?<CR>

nnoremap <F2><F2> :vsplit<CR>

nnoremap <F3><F3> <C-W>w

nnoremap <F6><F6> :set invpaste paste?<CR>

nnoremap <F7> mz:let g:I=0 \|sil\| .,.+24s/^/\=INC(1).'<TAB>'/<CR>:'z<CR>:set nohls<CR>

nnoremap <F7><F7> mz:let g:I=0 \|sil\| .,$s/^/\=INC(1).'<TAB>'/<CR>:'z<CR>:set nohls<CR>

nnoremap <F8> :'z,$s/^[0-9]\+<TAB>//<CR>:'z<CR>

" first, enable status line always
set laststatus=2
highlight StatusLine guifg=darkred ctermbg=darkred ctermfg=blue

set statusline =%F%m%r%h%w\ [<F1>=nu]\ [<F2>='vsplit']\ [<F3>=]\ [<F4>=wrap]\ [<F5>=highlight]\ [<F6>=paste]\ [<F7>=num]\ [<F8>=remove\ num]


You can change color of status bar based on your taste, use vim 7.0 or greater.

HAPPY VIMMING !!

Cheers - Satya.

Use 'ack' better than grep.

Ack : Is written in perl..so you can use perl regex to search.

http://betterthangrep.com/

Installation :

$ curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 !#:3

Top 10 reasons to use ack instead of grep.

1. It's blazingly fast because it only searches the stuff you want searched.
2. ack is pure Perl, so it runs on Windows just fine.
3. The standalone version uses no non-standard modules, so you can put it in your ~/bin without fear.
4. Searches recursively through directories by default, while ignoring .svn, CVS and other VCS directories.
* Which would you rather type?
$ grep pattern $(find . -type f | grep -v '\.svn')
$ ack pattern
5. ack ignores most of the crap you don't want to search
* VCS directories
* blib, the Perl build directory
* backup files like foo~ and #foo#
* binary files, core dumps, etc
6. Ignoring .svn directories means that ack is faster than grep for searching through trees.
7. Lets you specify file types to search, as in --perl or --nohtml.
* Which would you rather type?
$ grep pattern $(find . -name '*.pl' -or -name '*.pm' -or -name '*.pod' | grep -v .svn)
$ ack --perl pattern
Note that ack's --perl also checks the shebang lines of files without suffixes, which the find command will not.
8. File-filtering capabilities usable without searching with ack -f. This lets you create lists of files of a given type.
$ ack -f --perl > all-perl-files
9. Color highlighting of search results.
10. Uses real Perl regular expressions, not a GNU subset.
11. Allows you to specify output using Perl's special variables
* Example: ack '(Mr|Mr?s)\. (Smith|Jones)' --output='$&'
12. Many command-line switches are the same as in GNU grep:
-w does word-only searching
-c shows counts per file of matches
-l gives the filename instead of matching lines
etc.
13. Command name is 25% fewer characters to type! Save days of free-time! Heck, it's 50% shorter compared to grep -r.


Cheers !!
Satya

Followers