diff --git a/lib/ex.coffee b/lib/ex.coffee index be1ba80..3cc3151 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -349,6 +349,11 @@ class Ex range = [[range[0], 0], [range[1] + 1, 0]] atom.workspace.getActiveTextEditor().buffer.setTextInRange(range, '') + yank: ({ range }) -> + range = [[range[0], 0], [range[1] + 1, 0]] + txt = atom.workspace.getActiveTextEditor().getTextInBufferRange(range) + atom.clipboard.write(txt); + set: ({ range, args }) -> args = args.trim() if args == "" diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index b1b0201..e8f3fdf 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -585,6 +585,23 @@ describe "the commands", -> submitNormalModeInputText(':%substitute/abc/ghi/ig') expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi') + describe ":yank", -> + beforeEach -> + editor.setText('abc\ndef\nghi\njkl') + editor.setCursorBufferPosition([2, 0]) + + it "yanks the current line", -> + keydown(':') + submitNormalModeInputText('yank') + expect(atom.clipboard.read()).toEqual('ghi\n') + + it "yanks the lines in the given range", -> + processedOpStack = false + exState.onDidProcessOpStack -> processedOpStack = true + keydown(':') + submitNormalModeInputText('1,2yank') + expect(atom.clipboard.read()).toEqual('abc\ndef\n') + describe "illegal delimiters", -> test = (delim) -> keydown(':')