Skip to content

Commit 01354b4

Browse files
committed
Support operator maps
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()
1 parent d36d5bf commit 01354b4

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

autoload/db.vim

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,30 @@ function! db#execute_command(bang, line1, line2, cmd) abort
213213
let outfile = file . '.' . db#adapter#call(conn, 'output_extension', [], 'dbout')
214214
let maybe_infile = matchstr(cmd, '^<\s*\zs.*\S')
215215
if a:line2 > 0
216-
if !empty(maybe_infile)
216+
if a:line1 == 0
217+
let saved = [&selection, &clipboard, @@]
218+
try
219+
set selection=inclusive clipboard-=unnamed clipboard-=unnamedplus
220+
if a:line2 == 1
221+
let setup = "`[v`]"
222+
elseif a:line2 == 2
223+
let setup = "`[\<C-V>`]"
224+
elseif a:line2 == 3
225+
let setup = "`<" . visualmode() . "`>"
226+
else
227+
return 'echoerr ' . string('DB: Invalid range')
228+
endif
229+
silent execute 'normal!' setup.'y'
230+
let str = repeat("\n", line(setup[0:1])-1)
231+
if setup[2] ==# 'v'
232+
let str .= repeat(' ', col(setup[0:1]) - 1)
233+
endif
234+
let str .= substitute(@@, "\n$", '', '')
235+
finally
236+
let [&selection, &clipboard, @@] = saved
237+
endtry
238+
let lines = split(db#adapter#call(conn, 'massage', [str], str), "\n", 1)
239+
elseif !empty(maybe_infile)
217240
let lines = repeat([''], a:line1-1) +
218241
\ readfile(expand(maybe_infile), a:line2)[(a:line1)-1 : -1]
219242
elseif a:line1 == 1 && a:line2 == line('$') && empty(cmd) && !&modified && filereadable(expand('%'))
@@ -328,6 +351,27 @@ function! db#command_complete(A, L, P) abort
328351
return ""
329352
endfunction
330353

354+
function! db#range(type) abort
355+
return get({
356+
\ 'line': "'[,']",
357+
\ 'char': "0,1",
358+
\ 'block': "0,2",
359+
\ 'V': "'<,'>",
360+
\ 'v': "0,3",
361+
\ "\<C-V>": "0,3",
362+
\ 0: "%",
363+
\ 1: "."},
364+
\ a:type, '.,.+' . (a:type-1)) . 'DB'
365+
endfunction
366+
367+
function! db#op_exec(...) abort
368+
if !a:0
369+
set opfunc=db#op_exec
370+
return 'g@'
371+
endif
372+
exe db#range(a:1)
373+
endfunction
374+
331375
let s:dbext_vars = ['type', 'profile', 'bin', 'user', 'passwd', 'dbname', 'srvname', 'host', 'port', 'dsnname', 'extra', 'integratedlogin', 'buffer_defaulted']
332376
function! db#clobber_dbext(...) abort
333377
let url = s:resolve(a:0 ? a:1 : '')

0 commit comments

Comments
 (0)