Skip to content

Commit

Permalink
Merge pull request sublimehq#58 from misfo/r-enter-reindents
Browse files Browse the repository at this point in the history
Reindent after ["r", "enter"] if 'auto_indent' in on (like Vim)
  • Loading branch information
Sublime HQ Pty Ltd committed Feb 14, 2012
2 parents 9166abf + 8587b29 commit dac2795
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Default.sublime-keymap
Expand Up @@ -173,8 +173,8 @@

{ "keys": ["."], "command": "repeat", "context": [{"key": "setting.command_mode"}] },

{ "keys": ["r", "enter"], "command": "run_macro_file",
"args": {"file": "Packages/Vintage/Replace With Newline.sublime-macro"},
{ "keys": ["r", "enter"], "command": "replace_character",
"args": {"character": "\n"},
"context": [{"key": "setting.command_mode"}]
},

Expand Down
3 changes: 0 additions & 3 deletions Replace With Newline.sublime-macro

This file was deleted.

20 changes: 17 additions & 3 deletions vintage.py
Expand Up @@ -903,18 +903,32 @@ def is_enabled(self, register, forward = True):
class ReplaceCharacter(sublime_plugin.TextCommand):
def run(self, edit, character):
new_sel = []
created_new_line = False
for s in reversed(self.view.sel()):
if s.empty():
self.view.replace(edit, sublime.Region(s.b, s.b + 1), character)
new_sel.append(s)
if character == "\n":
created_new_line = True
# selection should be in the first column of the newly
# created line
new_sel.append(sublime.Region(s.b + 1))
else:
new_sel.append(s)
else:
self.view.replace(edit, s, character * len(s))
new_sel.append(s)
# Vim replaces characters with unprintable ones when r<enter> is
# pressed from visual mode. Let's not make a replacement in
# that case.
if character != "\n":
self.view.replace(edit, s, character * len(s))
new_sel.append(sublime.Region(s.begin()))

self.view.sel().clear()
for s in new_sel:
self.view.sel().add(s)

if created_new_line and self.view.settings().get('auto_indent'):
self.view.window().run_command('reindent')

class CenterOnCursor(sublime_plugin.TextCommand):
def run(self, edit):
self.view.show_at_center(self.view.sel()[0])
Expand Down

0 comments on commit dac2795

Please sign in to comment.