Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Mar 29, 2009

How to hide menu and tool bar in GVim

By default, GVim has a menu and tools bar, like this:

But most of the time, the reason why people use GVim or Vim is that they don't need to use mouse - the powerful keyboard shortcut is enough for an efficient editing. So it seems like a waste of space to have this menu and tools bar. Here I will introduce a tip to hide the menu and a keyboard shortcut to recall it.

In your .vimrc file, add the following lines.

"Toggle Menu and Toolbar
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>


The next time you use GVim, it will automatically hide the menu bar. And you can use F2 to recall it and hide it again.


Note that you can change the second and third lines to the following(with a "+" sign), and GVim will start with a menu bar and you still can toggle with F2 key.

set guioptions+=m
set guioptions+=T

Mar 17, 2009

Various Linux related Cheat Sheets

It is always easier to have cheat-sheet by hand, isn't it? Here I collected some popular Linux software (Linux/Unix basic commands, LaTeX, Emacs, Mutt, Ubuntu, Vim) cheat-sheets for your reference, as follows.

Latex cheat sheet
Vim cheat sheet
Linux/Unix command cheat sheet
Ubuntu cheat sheet
Emacs cheat sheet
Mutt cheat sheet

Link
(It's in my domain. Don't worry.)

Feb 27, 2009

How to archive your emails once a while?

If you are using Mutt, your mailbox files would grow larger and larger until it takes several seconds to open it in Mutt. One would say: gee, why do you keep old emails? Well, why not? I believe there should be enough space to store the old emails in hard drive nowadays. So here's the question: how do we save old emails?

Here's what we need to do:
  1. Don't delete emails, archive them into a specific mailbox, say, "archive" when hitting in Mutt. (By default, it is "d")
  2. Archive this mailbox into .tar file, and organize them in your mail directory so you can read them when you need to
  3. Delete the old "archive" mailbox file, and create a new and empty "archive" mailbox file.
  4. Do 1~3 every ten days.
OK, let's get started.

1 Save emails

This is simply redefine the "d" key, by default the delete key, in Mutt. Write the following in your .muttrc

macro index,pager d 's=archive'

Now when you hit "d", the email is not deleted, but saved to the archive mailbox.

2 Archive emails and delete old mailbox file

Here I assume you are using mbox mailboxes. Since we need to do this every ten days, a good choice is to write a script and let the system run this script every ten days. Here's the script I wrote.

#!/bin/sh

#set archive directory
basedir=/home/usrname/mail/archive/
#define archive directory suffix
suffix=$(date +%Y%m%d)
#define archive directory name
desdir=$basedir$suffix
cd /home/usrname/mail/
#create archive directory
mkdir $desdir
tar czf $desdir/archive.tar.gz archive
#remove old mailbox
rm archive
#create a new archive mailbox
touch archive
echo Email archive-$suffix successfully created #echo a success message


Save the script in your home directory, and change the mode of the script by running

chmod 700 email-archive


Then try the script in your home directory.

./email-archive


3 Configure crontab


Cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix, solaris. To set the script to run every ten days, run the following command to edit cron jobs.

crontab -e

By default, it will get you into a vim editor. If you don't know how to use vim, follow the instruction at the end of this post.

In the editor, add the following line.

30 21 1,10,20 * * $HOME/email-archive


Run the following command to see if the cron job is correctly set.

crontab -l


Done!

Vim basics


When vim is started, you are not in the edit mode. Move cursor by hitting "j, k, h, l", and hit "i" at where you want to edit. You can see the INSERT not at the bottom. After done editing, hit ESC to quit edit mode. Then hit shift-z twice to save and quit.
Welcome to Non-geek's
Linux Handbook!

or if you will, Linux Cookbook.

Read my READY-TO-USE
RECIPE-LIKE
tutorials on Linux applications~

Subscribe if you are willing to follow.

If you find the post useful, please click the donate button on the upper right corner. Any amount is useful.