Contents |
The following command maps <Leader>-return to executing the current line in the shell.
" mark position, execute line, jump back to original position
:nmap <Leader><CR> mZ:exe "r!" . getline('.')<CR>'Z
The output of the command is pasted into Vim. If you don't want the output, just press 'u' to undo.
date <- press <Leader>-return Sun Jul 12 11:33:17 CEST 2009
This kind of editor / shell is a throwback to old school computers like the Commodore 64 or the Acorn Electron, where the editor and shell were integrated. However, obviously Vim is superior due to better editing facilities and unlimited space for command history. This cute example requires SSH:
ssh server.com df -h <- press <Leader>-return Filesystem Size Used Avail Use% Mounted on /dev/sda3 73G 16G 54G 22% / udev 10M 164K 9.9M 2% /dev shm 500M 0 500M 0% /dev/shm /dev/sda1 38M 30M 6.9M 82% /boot
Mapping the command to <CR> like on the old school computers is not a good idea, as this will break the q: command-line window.
The following command maps <Leader>r to evaluating the current line using Ruby. Note that Vim needs Ruby support to be compiled in for this to work (i.e. +ruby):
:nmap <Leader>r :ruby b=VIM::Buffer.current;b.append(b.line_number,eval(b.line).to_s)<CR>
Using Ruby as a calculator is very handy:
2**24 <- press <Leader>r 16777216
You can include Math:
include Math <- press <Leader>r cos(PI) <- press <Leader>r -1.0