Thursday, June 21, 2012

Merge many PDF files into one in linux shell

Do you want to merge many PDF files into one? There you are:

Shell code:
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf

- out.pdf - destination file name
- in1.pdf, in2.pdf - source file names

(gs - Ghost Script - on Ubuntu 12.04 and OpenSuse 11.3 is installed by default)

VIM - inserting UTF-8 symbols (digraphs)

In VIM in very simple way we can insert some of UTF-8 symbols. List of available symbols we can display by running  :digraphs command


If you locate interesting symbol, you can insert him by pressing  <C-k> key combination and two letters on the left of that symbol on the left. For example equilateral triangle right ordered <C-k>PR
and here you are.



I've tested this technique in UTF-8 encoded files (in LATIN-1,2 or other there could be problems).

Linux Shell Tips - rm exclude emulation

If you want to remove all files and sub-directories from directory exept some files you can use  rm and find combination as described below: :

rm -rf $(find . ! -wholename './web/index.php' ! -wholename './web/.htaccess' ! -name '.' ! -name 'web')

You can see more find power examples on  http://www.infoanda.com/resources/find.htm

Linux Shell Tips - watch

If you want to monitor some command execution in time like "tail -f" for files, probably your linux box have nice solution for you:

watch -n 1 'ls -l'

Where:
'-n 1' - time (in seconds) to refresh command output
'ls -l' - command to execute in interval above

When we add '-d' option (help: highlight changes between updates), watch inform Us what was changed between command executions.

Example for 'ls' command below:


watch --color -n 10 -d 'ls -la'

Output:



After change in directory structure watch informs us about changes:

Monday, June 18, 2012

VIM faster Text-blocks with onoremap

I've found nice VIM feature to add mapping to operators

onoremap p i(
onoremap m i{
onoremap " i"
onoremap ' i'

Now i can press
c' d'
to use defined text-blocks

This technique didn't work with visual mode (you must press vi')

Friday, June 15, 2012

VIM + gpicker = SublimeText 2 like files fuzzy searching

Authors of SublimeText2 make great job with Fuzzy searching. In the past I've used Command-T and CtrlP plugins but both of them doesn't works well for me. Then i found Gpicker project it is written in C so its very fast and can be used in two most powerful editors: VIM (gpicker.vim) or Emacs (gpicker.el). I'm using now gpicker for both of them. It's not so powerful like SublimeText but it get the job done very well.

You can install gpicker in ubuntu

$ sudo apt-get install gpicker

Next step is to configure your favourite editor. In VIM you must put gpicker.vim to ~/.vim/plugins directory (or use any other technique pathogen, vundle or whatever). In emacs you must load gpicker.el in your init.el file (I'm using prelude for that ~/.emacs.d/vendor/). It is working out of the box for me (Ubuntu 12.04, Vim 7.3.429, Emacs-snapshot - 24.1.50.1).

My key bindings in VIM:

map <Leader>p :GPickFile<CR>
noremap <C-p> :GPickFile<CR>
map <Leader>. :GPickBuffer<CR>


Final result:

Gpicker in VIM


Gpicker in Emacs



You can use it in shell too: 


You can look in my vim dotfiles for more information. If you want try my VIM configs you can run command below in your shell

$ curl -L https://raw.github.com/exu/vim-dotfiles/master/gitinstall|bash

WARNING this command will kill your .vimrc file and .vim/ directory so BACKUP your old configs! look at https://raw.github.com/exu/vim-dotfiles/master/gitinstall for more details