Take the 2-minute tour ×

This question is based on this thread.

Problem: to access MySQL's manual when the cursor is at the beginning of the word by

Ctrl-A Esc Ctrl-m

where m reminds about Mysql.

How can you build a Vim-like K in Screen for MySQL's manuals?

share|improve this question
I opened a thread about installing MySQL manuals at stackoverflow.com/questions/1104536/… –  Masi Jul 9 '09 at 15:15
add comment

3 Answers

up vote 3 down vote accepted

Assuming you've installed the man pages from MySQL's documentation site:

Put the following in /path/to/mysql-help.screen:

# mysql-help.screen

# prevent messages from slowing this down
msgminwait 0
# copy term starting at cursor
stuff " e "
# write term to a file
writebuf /tmp/screen-copied-term
# open that file in man in a new screen window
# (use `read` to pause on error, so user can see error message)
screen /bin/sh -c 'man `cat /tmp/screen-copied-term` || read'
# turn message waiting back on
msgminwait 1

# vi: ft=screen

Then add this to your ~/.screenrc

# Have CTRL-A ESC put you in a mode to accept commands in the 'escaped' class
bind \033 command -c escaped
# add CTRL-M as an 'escaped' class command to run the given screen script
bind -c escaped ^M source /path/to/mysql-help.screen

Then your keybinding should work. If you're using a different program to display the manual other than man, you'll have to change the script accordingly.

The man pages for mysql that I found at the link above only include documentation for the following commands:

mysqlbug mysqlhotcopy perror mysqldump resolveip mysqltest_embedded mysql_setpermission mysql_client_test mysql_find_rows mysql_fix_privilege_tables mysql_waitpid mysql_config mysql_client_test_embedded myisampack replace msql2mysql make_win_bin_dist my_print_defaults mysql-stress-test.pl mysqlaccess mysql_secure_installation mysql.server mysql_convert_table_format mysql_zap mysql_fix_extensions myisamlog myisam_ftdump mysqlbinlog mysql_install_db resolve_stack_dump mysqlslap mysql-test-run.pl mysqld_safe mysqladmin mysqlshow mysql_tzinfo_to_sql mysqltest mysqlbackup mysqld_multi mysql mysqldumpslow mysqlcheck mysql_upgrade mysqlimport comp_err mysqld myisamchk innochecksum

You may also want to consider adding

zombie kr

to your .screenrc, so that if you run the manual on a term that it doesn't recognize, screen doesn't automatically close the window (and hide the error message).

share|improve this answer
@rampion: There seems to be a bug in the binding commnad ` bind -c ... -c escpaped`. I tried to fix it unsuccessfully by bindkey -m ^m source /Users/masi/bin/screen/mysql-help.screen. –  Masi Jul 9 '09 at 15:17
@rampion: Which Screen do you use? I use 4.00.03 (OS X) and it does not seem to have the defzombie -command. –  Masi Jul 9 '09 at 15:31
well, you misspelled escaped. and it's two commands , which is why it's on two lines. –  rampion Jul 9 '09 at 15:31
try zombie rather than defzombie, then. –  rampion Jul 9 '09 at 15:32
@rampion: Thank you for your last answer! - I have now manuals correctly installed. --- I suggests the following improvement to the code stackoverflow.com/questions/1082966/… –  Masi Jul 12 '09 at 22:10
show 4 more comments

I love to recycle my Man -pages such that I can read easily manuals. I suggests the following improvement to Rampion's command.




screen /bin/sh -c 'man `cat /tmp/screen-copied-term` > /tmp/manual | less /tmp/manual'

My code gives you the percent sign to the bottom of a manual.

share|improve this answer
Here's what I'm actually using these days: gist.github.com/139318 –  rampion Jul 13 '09 at 1:03
@rampion: Please, see this thread about your command stackoverflow.com/questions/1120756/… –  Masi Jul 13 '09 at 17:00
add comment

While I'm not sure how to start you off creating a wrapper for vim to do exactly what you want, I might make a suggestion on how you can achieve a similar effect with a function built into vim.

:! <command> will allow you to run shell commands with a similar interface to vim's K command. It might not be the cleanest way to do it, but by using :! you should be able to call the MySQL manuals for a given term quickly without completely leaving vim.

If you really need to write your own plugin for vim, this article might be able to give you some pointers and a handhold on where to start.

I hope this helps!

share|improve this answer
The problem is to build such an component to Screen such that you can use those manuals everywhere where you MySQL error messages in terminal. --- To build such an component to Vim would make us editor-dependent which is not a good thing. –  Masi Jul 8 '09 at 8:38
Ah, you're not looking to build a plugin for vim, you want to build a plugin for Screen. Sorry, that wasn't quite clear. –  Dean Putney Jul 8 '09 at 15:03
I also started writing a mapping for Vim before I realized that it needed to be for Screen instead. –  too much php Jul 10 '09 at 3:21
add comment

Your Answer


