sublimetext2 - Copy entire line shortcuts then paste it UNDER cursor -


on sublime text 3 (but guess it's same st2), know when copy ( ctrl + c ) when there nothing selected, entire line copied need know how paste below cursor.

it paste above , doesn't seem logical me, there way modify behaviour ?

it's not pastes "above" or "below", it's operating on current line. when copy without first making selection, copies current line. when paste that, operates on current line -- pastes buffer line, , side effect, whatever on line bumped out of way next line. can't bumped upward instead - file can grow or add new lines downward, can't grow upward beyond line 1.

as how modify behavior, suggest trying make macro.

http://docs.sublimetext.info/en/latest/extensibility/macros.html

as pointed out in comments, macro works leaves 2 different ways paste, 1 normal use , other "entire line" behavior. unfortunate, though there (harder) solution. try write sublime plugin detect how behave , want in each case. bit beyond ability you... in thinking this, realized vintage package has command this, because p , p keys paste before , after cursor, respectively. looked inside vintage package find did it. here code, though couldn't explain how works. want try emulate vipasteright.

class viprefixablecommand(sublime_plugin.textcommand):     # ensure register , repeat picked g_input_state, ,     # it'll recorded on undo stack     def run_(self, edit_token, args):         if not args:             args = {}          if g_input_state.register:             args['register'] = g_input_state.register             g_input_state.register = none          if g_input_state.prefix_repeat_digits:             args['repeat'] = digits_to_number(g_input_state.prefix_repeat_digits)             g_input_state.prefix_repeat_digits = []          if 'event' in args:             del args['event']          edit = self.view.begin_edit(edit_token, self.name(), args)         try:             return self.run(edit, **args)         finally:             self.view.end_edit(edit)  class vipasteright(viprefixablecommand):     def advance(self, pt):         if self.view.substr(pt) == '\n' or pt >= self.view.size():             return pt         else:             return pt + 1      def run(self, edit, register = '"', repeat = 1):         visual_mode = self.view.has_non_empty_selection_region()         if not visual_mode:             transform_selection(self.view, lambda pt: self.advance(pt))         self.view.run_command('paste_from_register', {'forward': not visual_mode,                                                       'repeat': repeat,                                                       'register': register})  class vipasteleft(viprefixablecommand):     def run(self, edit, register = '"', repeat = 1):         self.view.run_command('paste_from_register', {'forward': false,                                                       'repeat': repeat,                                                       'register': register}) 

and here how bind them keys. if wanted try adapt not need context, need due vintage mode's modal nature.

{ "keys": ["p"], "command": "vi_paste_left",     "context": [{"key": "setting.command_mode"}] },  { "keys": ["p"], "command": "vi_paste_right",     "context": [{"key": "setting.command_mode"}] }, 

here docs section plugins, if want try tackle way.

http://docs.sublimetext.info/en/latest/extensibility/plugins.html


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -