Skip to content

Commit

Permalink
Support operator maps
Browse files Browse the repository at this point in the history
Have not decided what will become the default maps if any, but here's
some to try:

    nmap <expr> dy db#op_exec()
    nmap dyy dy_
    xmap <expr> D db#op_exec()
  • Loading branch information
tpope committed Apr 8, 2018
1 parent d36d5bf commit 01354b4
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion autoload/db.vim
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,30 @@ function! db#execute_command(bang, line1, line2, cmd) abort
let outfile = file . '.' . db#adapter#call(conn, 'output_extension', [], 'dbout')
let maybe_infile = matchstr(cmd, '^<\s*\zs.*\S')
if a:line2 > 0
if !empty(maybe_infile)
if a:line1 == 0
let saved = [&selection, &clipboard, @@]
try
set selection=inclusive clipboard-=unnamed clipboard-=unnamedplus
if a:line2 == 1
let setup = "`[v`]"
elseif a:line2 == 2
let setup = "`[\<C-V>`]"
elseif a:line2 == 3
let setup = "`<" . visualmode() . "`>"
else
return 'echoerr ' . string('DB: Invalid range')
endif
silent execute 'normal!' setup.'y'
let str = repeat("\n", line(setup[0:1])-1)
if setup[2] ==# 'v'
let str .= repeat(' ', col(setup[0:1]) - 1)
endif
let str .= substitute(@@, "\n$", '', '')
finally
let [&selection, &clipboard, @@] = saved
endtry
let lines = split(db#adapter#call(conn, 'massage', [str], str), "\n", 1)
elseif !empty(maybe_infile)
let lines = repeat([''], a:line1-1) +
\ readfile(expand(maybe_infile), a:line2)[(a:line1)-1 : -1]
elseif a:line1 == 1 && a:line2 == line('$') && empty(cmd) && !&modified && filereadable(expand('%'))
Expand Down Expand Up @@ -328,6 +351,27 @@ function! db#command_complete(A, L, P) abort
return ""
endfunction

function! db#range(type) abort
return get({
\ 'line': "'[,']",
\ 'char': "0,1",
\ 'block': "0,2",
\ 'V': "'<,'>",
\ 'v': "0,3",
\ "\<C-V>": "0,3",
\ 0: "%",
\ 1: "."},
\ a:type, '.,.+' . (a:type-1)) . 'DB'
endfunction

function! db#op_exec(...) abort
if !a:0
set opfunc=db#op_exec
return 'g@'
endif
exe db#range(a:1)
endfunction

let s:dbext_vars = ['type', 'profile', 'bin', 'user', 'passwd', 'dbname', 'srvname', 'host', 'port', 'dsnname', 'extra', 'integratedlogin', 'buffer_defaulted']
function! db#clobber_dbext(...) abort
let url = s:resolve(a:0 ? a:1 : '')
Expand Down

0 comments on commit 01354b4

Please sign in to comment.