Stuck & confused

classic Classic list List threaded Threaded
3 messages Options
M.C
Reply | Threaded
Open this post in threaded view
|

Stuck & confused

M.C
Hi

I am new to macs (and kinda vim & mysql) and am having some problems with the above.

I have installed both and can run the mysql server from terminal using 'mysql -p'. I have used sql commands before and have a pretty good grasp on how to text edit in vim. I can also launch a vim window from terminal.

The problem is I want to be able to launch vim and then use this window to launch mysql before submitting queries to the mysql server which are written in vim(the server is local on my comp btw). how would I put 'mysql -p' into vim so that I can connect to the server and then how would I submit the queries?

I have looked for tutorials through google but all I keep getting are instructions how to text edit in vim.

It is possible that I have go myself very muddled re how vim & mysql interact but any help you could give would be gratefully recieved....

cheers
Reply | Threaded
Open this post in threaded view
|

Re: Stuck & confused

Muskoka Auto Parts Limited
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 13-Mar-07, at 11:42 AM, M.C wrote:
> The problem is I want to be able to launch vim and then use this  
> window to
> launch mysql before submitting queries to the mysql server which  
> are written
> in vim(the server is local on my comp btw). how would I put 'mysql -
> p' into
> vim so that I can connect to the server and then how would I submit  
> the
> queries?

IIUC,  you want to run a shell command and 'capture the output' in vim.

To run a command inside vim you preface it with :!
   :!ls  will list your current directory, then prompt you to hit  
enter to go back to using vim

To read in external files you use :r
   :r addMe.txt will add the file to your current document

To run a command inside vim and read in the output you combine the  
commands (very vimmish)
   :r!ls  will add the directory listing to the bottom of your document

So, you should be able to do something like
    :r!mysql -e help
or whatever - the sql I leave to you.

HTH
Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Verify this email or encrypt your email for free - see gnupg.org

iD8DBQFF9snMGnOmb9xIQHQRAstWAJ9MKA/ieYfOObBVIY0xbkcRj78JPQCeLdZt
0MTOwGrib/WatFSX9BnYw4c=
=cFXu
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Stuck & confused

Benji Fisher
On Tue, Mar 13, 2007 at 11:56:59AM -0400, Brian McKee wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 13-Mar-07, at 11:42 AM, M.C wrote:
> >The problem is I want to be able to launch vim and then use this  
> >window to
> >launch mysql before submitting queries to the mysql server which  
> >are written
> >in vim(the server is local on my comp btw). how would I put 'mysql -
> >p' into
> >vim so that I can connect to the server and then how would I submit  
> >the
> >queries?
>
> IIUC,  you want to run a shell command and 'capture the output' in vim.
>
> To run a command inside vim you preface it with :!
>   :!ls  will list your current directory, then prompt you to hit  
> enter to go back to using vim
>
> To read in external files you use :r
>   :r addMe.txt will add the file to your current document
>
> To run a command inside vim and read in the output you combine the  
> commands (very vimmish)
>   :r!ls  will add the directory listing to the bottom of your document
>
> So, you should be able to do something like
>    :r!mysql -e help
> or whatever - the sql I leave to you.
>
> HTH
> Brian

     I do not think there is anything mac-specific about this question,
so you may get more help on the general vim users' list.

     If your SQL commands are in the vim buffer, you can yank them and
paste to the command line.  For example (starting in Normal mode)

y$:<C-R>"

will yank the current line, enter Command-line mode, and paste the
yanked text.  If you want to do this a lot, you may want to define a
mapping for it.

:help y
:help c_CTRL-R

     If you want an interactive SQL session in vim, then some plugins
may help.  I have never used them myself.  For example,
http://www.vim.org/scripts/script.php?script_id=165
(The site is behaving oddly.  Maybe it is just me, but reloading a page
seems to help when it initially comes up blank.)

HTH --Benji Fisher