0

您好,我正在尝试将所选文本放入变量中,然后将其添加到我要执行的字符串中。这是我要使用的列表

 SHOW CREATE PROCEDURE name\G
 SHOW CREATE PROCEDURE add_contact_us\G
 SHOW CREATE PROCEDURE add_customer\G
 SHOW CREATE PROCEDURE add_order\G
 SHOW CREATE PROCEDURE add_to_cart\G
 SHOW CREATE PROCEDURE add_to_wish_list\G
 SHOW CREATE PROCEDURE add_transaction\G
 SHOW CREATE PROCEDURE clear_cart\G
 SHOW CREATE PROCEDURE get_order_contents\G
 SHOW CREATE PROCEDURE get_shopping_cart_contents\G
 SHOW CREATE PROCEDURE get_wish_list_contents\G
 SHOW CREATE PROCEDURE receipt_retrieve\G
 SHOW CREATE PROCEDURE remove_from_cart\G
 SHOW CREATE PROCEDURE remove_from_wish_list\G
 SHOW CREATE PROCEDURE select_categories\G
 SHOW CREATE PROCEDURE select_products\G
 SHOW CREATE PROCEDURE select_sale_items\G
 SHOW CREATE PROCEDURE update_cart\G
 SHOW CREATE PROCEDURE update_wish_list\G

这是创建这些行的函数

function Myproc()
r !mysql -uroot -ppass sas -e 'SELECT name FROM mysql.proc;'
let q = 'mysql -uroot -ppass sas -e'
echom q
normal! gg /name
normal! ndd
%normal! I SHOW CREATE PROCEDURE 
normal! ggdd0 
%normal A\G
normal! gg0
//here where im having porblems.. i think
normal! <shift>.Vy\<C-r>".q 

endfunction

我想要的是构建一个查询字符串并输出它,以便我可以查看和编辑字符串应该看起来像的存储过程

!mysql -uroot -ppass sas -e SHOW CREATE PROCEDURE update_wish_list\G

vim 和 i 的新手在正确的轨道上

4

1 回答 1

1

这是我认为编写此脚本的更好方法:

" get proc names from mysql and split them into an list
let output = system("mysql -uroot -ppass sas -e 'SELECT name FROM mysql.proc'")
let proc_list = split(output, '\n')

"set cursor to first line
call cursor('1', '1')

" output as you like
for proc in proc_list
    put ='SHOW CREATE PROCEDURE ' . proc .'\G'
endfor

当然,您也可以将其包装为一个函数。

于 2013-07-04T07:07:33.297 回答