问题
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?
回答1:
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).
回答2:
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!
回答3:
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.
来源:https://stackoverflow.com/questions/1082966/to-have-vim-like-k-in-screen-for-mysql