It is possible to store any ex: commands in text file and then execute them.
For example. I want to periodically insert current content of some file in other text file.

Do the following:

  • Put to file the following line

:r /etc/hosts
  • Set cursor to this line an execute in command mode:

"zY@z
  • The result is:

:r /etc/hosts
127.0.0.1   localhost
127.0.1.1   HOSTNAME

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Explanation:


"zY

Put current line to buffer with name 'z'


@z

Execute content of buffer 'z' as ex: command

Vim short form:


Y@"

This command use unnamed buffer register. 'Y' put current string to unnamed register, @" execute content of unnamed register as ex: command. This operate only in Vim and doesn't operate in POSIX vi.

Examples:


:r!echo 'scale=2; ( 2 + 3 ) / 2' | bc
2.50

:r!date --iso-8601=seconds
2014-06-25T19:52:28+0400

:r!lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.4 LTS
Release:    12.04
Codename:   precise

Selectively set 'execute' permission for directories.

Mon 02 June 2014 by Mikhail Basov

Task:

Recursively change permissions:
user:
rwx - for directories
rw - for files
group:
rx - for directories
r - for files
other:
rx - for directories
r - for files

Solution:

chmod -R u+rwX,go+rX,go-w /directory

Explanation:

Quote from HP-UX chmod man page about 'X' (capital X) option:

X    Conditionally add or ...
read more

Copy directory tree with access rights but without files

Tue 15 April 2014 by Mikhail Basov

To copy only directory structure with access rights from current directory (./) to target directory (../test1) issue the following command:

read more