PKT4=& DuplicateLineAndToggleComment.pyimport copy import sublime import sublimeplugin class DuplicateLineAndToggleComment(sublimeplugin.TextCommand): def run(self, view, args): clipboard = sublime.getClipboard() sel = view.sel() initial_selection = [s for s in sel] sel.clear() adjusted_selection = [] accumulated_shift = 0 for s in initial_selection: s = self.adjustPosition(s, accumulated_shift) adjusted_selection.append(s) sel.add(s) view.runCommand("expandSelectionTo line") accumulated_shift += sel[0].end() - sel[0].begin() view.runCommand("copy") begin = sel[0].begin() end = sel[0].end() view.runCommand("toggleComment") accumulated_shift += sel[0].end() - end self.gotoPosition(sel, begin) view.runCommand("paste") sel.clear() [sel.add(s) for s in adjusted_selection] sublime.setClipboard(clipboard) def adjustPosition(self, region, increment): if increment > 0: region = sublime.Region(region.begin() + increment, region.end() + increment) return region def gotoPosition(self, sel, pos): sel.clear() sel.add(sublime.Region(pos, pos)) PKT4='Default.sublime-keymap PKT4="cZmmDuplicateLine.pyimport copy import sublime import sublimeplugin class DuplicateLine(sublimeplugin.TextCommand): def run(self, view, args): clipboard = sublime.getClipboard() sel = view.sel() initial_selection = [s for s in sel] sel.clear() adjusted_selection = [] accumulated_selection_size = 0 for s in initial_selection: s = self.adjustPosition(s, accumulated_selection_size) adjusted_selection.append(s) sel.add(s) view.runCommand("expandSelectionTo line") accumulated_selection_size += self.selectionSize(sel[0]) view.runCommand("copy") view.runCommand("move characters 1") view.runCommand("paste") sel.clear() [sel.add(s) for s in adjusted_selection] sublime.setClipboard(clipboard) def selectionSize(self, region): return region.end() - region.begin() def adjustPosition(self, region, increment): if increment > 0: region = sublime.Region(region.begin() + increment, region.end() + increment) return region PKT4=*h README.txtThis plugin duplicates the currently selected line. It handles multiple selections (i.e. all lines with selections will be duplicated) and all selections are preserved. Just press ctrl-d, and you're golden. There is also an alternative version that comments out the duplicated lines. Ctrl-shift-D will give you that one. Any bug reports and/or suggestions will gladly be accepted at a.stenlund@gmail.com. PKT4=& DuplicateLineAndToggleComment.pyPKT4='RDefault.sublime-keymapPKT4="cZmmDuplicateLine.pyPKT4=*h README.txtPKr