views:

199

answers:

3

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?

A: 

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!

Dean Putney
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
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
I also started writing a mapping for Vim before I realized that it needed to be for Screen instead.
too much php
+2  A: 

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
copy
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).

rampion
@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
@rampion: Which Screen do you use? I use 4.00.03 (OS X) and it does not seem to have the defzombie -command.
Masi
well, you misspelled escaped. and it's two commands , which is why it's on two lines.
rampion
try zombie rather than defzombie, then.
rampion
(Also using that same screen - didn't realize that defzombie wasn't supported)
rampion
Did you install the manpages correctly? Pick a directory from your $MANPATH and put all the `.1` files in the `man1` subdirectory and the `mysqld.8` file in a `man8` subdirectory.
rampion
@rampion: Thank you for your last answer! - I have now manuals correctly installed. --- I suggests the following improvement to the code http://stackoverflow.com/questions/1082966/to-have-vim-like-k-in-screen-for-mysql/1117061#1117061
Masi
@Rabion: A new question about the bug is at http://stackoverflow.com/questions/1120438/to-fix-a-bug-in-vim-like-k-in-screen-for-manuals
Masi
@rambion: please, see this question about your codes at github http://stackoverflow.com/questions/1120756/unable-to-understand-a-code-in-screenrc
Masi
A: 

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

Rampion

screen /bin/sh -c 'man `cat /tmp/screen-copied-term` || read'

Me

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.

Masi
Here's what I'm actually using these days: http://gist.github.com/139318
rampion
@rampion: Please, see this thread about your command http://stackoverflow.com/questions/1120756/unable-to-understand-a-code-in-screenrc
Masi