If you are dealing with a long program file, it might be interesting to hide part(s) of it to make it more readable for instance. VIM provides these features : folding for hiding sections of text and unfolding for printing texts again.
Here are the basic VIM keyboard shortcuts to type in normal mode :
zfa} : create a fold within two brackets. the cursor is located after the opening bracket and the second one is indicated by }
zc : close the current fold
zo : open the current fold
zd : delete the fold at the cursor
[z : move to start of open fold
z] : move to end of open fold
You can create folders as many as you want within your current file. If you exit from your VIM editor, you will lose all of them.
For more details about folding/unfolding commands in VIM :
If you want to perform redirection of a command run by sudo, you will get the following error :
The file access permissions do not allow the specified action 0403-005 Cannot create the specified file
What does it mean?
Redirection is some kind of built-in features of your current running shell. (bash or ksh). When you issue a command with sudo, the built-in fonctions can not work within the child process. To overcome this issue, the only workaround is to launch your command within a subshell :
sudo sh -c ‘your command > file.out’
Here are some bash tips that might be useful to you for a better and more efficient use of the bash shell.
The variable CDPATH
This variable expands the scope of the cd command.
By default, cd looks for a possible subdirectory in the current working directory.
Let us take an example :
fool@localhost:~$ cd cron
If CDPATH is not set, cd will look for a subdirectory named cron. If it does not exist, cd will look through the directories added to CDPATH. As we want to display the content of the directory /var/spool/cron, here is what we have to do :
fool@localhost:~$ export CDPATH=/var/spool/cron
Then, cd cron will work well and the current working directory will be /var/spool/cron
The bash builtin fc
fc displays a list of all the latest commands typed. It is like the command history.
To list the 16 lastest commands typed :
fool@localhost:~$ fc -l
To list a range of commands typed :
fool@localhost:~$ fc -l 495 501
The numbers 495 and 501 refers to the lines numbers displayed by the command history.
To reexecute the command number 495
fool@localhost:~$ fc -s 495