Giter Club home page Giter Club logo

pipe-mysql.vim's Introduction

pipe-mysql.vim

License: ISC Patreon donate button PayPal donate button Amazon donate button

Buy Me A Coffee

Easy-to-use MySQL client for Vim

Based on pipe.vim

Features

  • Work with MySQL database at local (with respect to Vim) or at remote machine (via SSH)
  • No need to have MySQL installed at local if you plan to execute MySQL statements at remote machine
  • Edit MySQL script locally, execute at remote machine, and get result back in Vim's Preview window at local
  • Execute a whole MySQL script file, a single line, or a block of MySQL statements
  • Set SSH remote and MySQL access on the fly; or use preset for frequently used login info
  • Each buffer has independent login info to database
  • Easily switch database on the fly
  • Include common queries to operate on the target where the cursor is at

by default, it works for filetype 'mysql'. so if you want to use othertype (ex. sql), set in your .vimrc like au BufRead,BufNewFile *.sql set filetype=mysql

Install

Using Vundle plugin manager:

Plugin 'NLKNguyen/pipe.vim' "required
Plugin 'NLKNguyen/pipe-mysql.vim'

Default Keymaps

The plugin comes with default keymaps for MySQL filetype. To turn off, add let g:pipemysql_no_mappings = 0 to your .vimrc file

Set Actions

Mode Key Action Function call
Normal <leader>sr Set remote info (SSH) g:PipeMySQL_SetRemote()
Normal <leader>sa Set MySQL access info g:PipeMySQL_SetAccess()
Normal <leader>sd Set database to use g:PipeMySQL_SetDatabase()
Normal <leader>se Set all fields empty g:PipeMySQL_SetEmpty()
Normal <leader>sp Select preset info* g:PipeMySQL_SelectPreset()

* See Use Preset Login Info for how to store preset login info in .vimrc file

Run Actions

Mode Key Action Function call
Normal <leader>rf Run MySQL script file g:PipeMySQL_RunFile()
Normal <leader>rs Run statement on the current line (table view) g:PipeMySQL_RunLine('table')
Visual <leader>rs Run selected block of statements (table view) g:PipeMySQL_RunBlock('table')
Normal <leader>rS Run statement on the current line (batch view) g:PipeMySQL_RunLine('batch')
Visual <leader>rS Run selected block of statements (batch view) g:PipeMySQL_RunBlock('batch')
Normal <leader>rc Run custom statement (prompt) g:PipeMySQL_RunCustom()

Common Actions

Mode Key Action Function call
Normal <leader>dl List databases g:PipeMySQL_DatabaseListing()
Normal <leader>ds Switch database g:PipeMySQL_DatabaseSwitching()
Normal <leader>tl List tables g:PipeMySQL_TableListing()
Normal <leader>ts Select * from table at cursor g:PipeMySQL_TableSelectAll()
Normal <leader>td Describe table at cursor g:PipeMySQL_TableDescription()
Normal <leader>tD Show create SQL definition of table at cursor g:PipeMySQL_TableDefinition()

Use Preset Login Info

In .vimrc you can store frequently used login info like the below snippet. The description value is what you see in the list of preset info in order to select. All other fields are optional. They can be set on the fly using the Set Actions; therefore, you don't have to store sensitive information like password in .vimrc if you don't want to. if in your preset mysql_password is not specified, then follow mysql-clients setting for that. (for example, find it from .my.cnf). and you can also use defaults file for mysql access configuration. in below example, using .test.my.cnf file for 4th preset.

let g:pipemysql_login_info = [
                             \ {
                             \    'description' : 'my server 1',
                             \    'ssh_address' : 'root@server1',
                             \    'ssh_port' : '',
                             \    'mysql_hostname' : 'somehostname',
                             \    'mysql_username' : 'my_username',
                             \    'mysql_password' : 'my_password',
                             \    'mysql_database' : 'cs332h20'
                             \ },
                             \ {
                             \    'description' : 'my server 2',
                             \    'ssh' : 'root@server2',
                             \    'mysql_hostname' : 'somehostname',
                             \    'mysql_username' : 'my_username',
                             \ },
                             \ {
                             \    'description' : 'my local',
                             \    'mysql_hostname' : 'localhost',
                             \ },
                             \ {
                             \    'decription' : 'using defaults file',
                             \    'mysql_defaults_file' : '$HOME/.test.my.cnf'
                             \ }
                           \ ]

example for .test.my.cnf this configuration is can be used when your enviroments are diverse, and maintain connection with seperated file as traditional in mysql configuration.

[mysql]
host=my-awesome-prod-server
user=my-user
password=my_password

Use Variables

In .vimrc you can set mysql options by using variables.

let g:pipemysql_option = '-vvv'
let g:pipemysql_pager = 'grcat ~/.grcat'

the variables

variable description
pipemysql_option set mysql custom option. for example (-vvv, -show-warnings). some options actually does not affect behavior cause the client was disconnected after executes. check: mysql-doc
pipemysql_pager give pager option to mysql client. check: mysql-doc

๐Ÿ‘‹ Author

๐Ÿ‘ค Nikyle Nguyen

Twitter: NLKNguyen

๐Ÿค Contributing

Give a โญ๏ธ if this project helped you working with MySQL in Vim seamlessly!

Contributions, issues and feature requests are welcome! Feel free to check issues page.

๐Ÿ™‡ Your support is very much appreciated

I create open-source projects on GitHub and continue to develop/maintain as they are helping others. You can integrate and use these projects in your applications for free! You are free to modify and redistribute anyway you like, even in commercial products.

I try to respond to users' feedback and feature requests as much as possible. Obviously, this takes a lot of time and efforts (speaking of mental context-switching between different projects and daily work). Therefore, if these projects help you in your work, and you want to encourage me to continue create, here are a few ways you can support me:

  • ๐Ÿ’ฌ Following my blog and social profiles listed above to help me connect with your network
  • โญ๏ธ Starring this project and sharing with others as more users come, more great ideas arrive!
  • โ˜˜๏ธ Donating any amount is a great way to help me work on the projects more regularly!

Buy Me A Coffee

Thanks to all contributors who make pipe-mysql.vim great! โค๏ธ

๐Ÿ“ License

Copyright ยฉ 2015 - 2020 Nikyle Nguyen

The project is MIT License

pipe-mysql.vim's People

Contributors

egyptianbman avatar indeedhat avatar keelerm84 avatar nlknguyen avatar nolleh avatar vimfun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pipe-mysql.vim's Issues

temp file not found

Hello

very interesting your plugin, thanks.

I am running into an issue with the temp file

._temp_pipemysql_ac59330d: No such file or directory

the issue seems to around those lines

file: pipe-mysql.vim

  184   call writefile([g:PipeGetCurrentLine()], s:tempfilename, 'w')
  185
  186   let l:shell_command .= ' -t < ' . s:tempfilename

I am quite newbie at vim so any pointer would be great. thanks

pipe-mysql's vim's functions are not defined in some environments

hello,

when I check - command pipe(dependent plugin), It is well defined it's functions,
but when check pipe-mysql, there isn't any commands..
so I am having trouble to use this awesome feature.

any I idea that enlighten you?
Thanx in advance!

my OS: Mac OS Monterey (12.3.1)

:verbose command Pipe
    Name              Args Address Complete    Definition
    Pipe              1            shellcmd    :call g:Pipe(<f-args>)
        Last set from ~/.vim/plugged/pipe.vim/plugin/pipe.vim line 73
    PipeLast          0                        :call g:PipeLast()
        Last set from ~/.vim/plugged/pipe.vim/plugin/pipe.vim line 186
    PipeToFile        ?            file        :call g:PipeToFile(<f-args>)
        Last set from ~/.vim/plugged/pipe.vim/plugin/pipe.vim line 53
    PipeToggleWindow  0                        :call g:PipeToggleWindow()
        Last set from ~/.vim/plugged/pipe.vim/plugin/pipe.vim line 348
    PipeUse           1                        :call g:PipeUse("<args>")
        Last set from ~/.vim/plugged/pipe.vim/plugin/pipe.vim line 32
Press ENTER or type command to continue
:verbose command PipeMySql
No user-defined commands found

plugin was installed successfully when I check my .vim/plugged

โžœ  pipe-mysql.vim git:(master) l
total 32
drwxr-xr-x   6 nolleh  staff   192B Dec 23 17:02 .
drwxr-xr-x  19 nolleh  staff   608B Dec 23 17:02 ..
drwxr-xr-x  13 nolleh  staff   416B Dec 23 21:55 .git
-rw-r--r--   1 nolleh  staff   1.1K Dec 23 17:02 LICENSE
-rw-r--r--   1 nolleh  staff   8.7K Dec 23 17:02 README.md
drwxr-xr-x   3 nolleh  staff    96B Dec 23 21:06 plugin
โžœ  pipe-mysql.vim git:(master)

Screenshots

Example: Set autocommand to compile C++ file

au Filetype cpp nmap <buffer> <leader>cc :update <bar> call g:Pipe('clang++-3.6 -g -Wall ' . expand('%') . ' && echo "Compiled successfully."') <CR> 

pipe_and_cpp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.