diff --git a/cmd/micro/settings.go b/cmd/micro/settings.go index 23660d15..c8e50e12 100644 --- a/cmd/micro/settings.go +++ b/cmd/micro/settings.go @@ -231,6 +231,7 @@ func DefaultGlobalSettings() map[string]interface{} { "scrollmargin": float64(3), "scrollspeed": float64(2), "softwrap": false, + "smartpaste": true, "splitbottom": true, "splitright": true, "statusline": true, @@ -271,6 +272,7 @@ func DefaultLocalSettings() map[string]interface{} { "scrollmargin": float64(3), "scrollspeed": float64(2), "softwrap": false, + "smartpaste": true, "splitbottom": true, "splitright": true, "statusline": true, diff --git a/cmd/micro/view.go b/cmd/micro/view.go index d6d9470f..7c9a0f12 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -198,16 +198,18 @@ func (v *View) ToggleTabbar() { } func (v *View) paste(clip string) { - leadingWS := "" - if v.Cursor.X > 0 { - leadingWS = GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y)) + if v.Buf.Settings["smartpaste"].(bool) { + if v.Cursor.X > 0 && GetLeadingWhitespace(strings.TrimLeft(clip, "\r\n")) == "" { + leadingWS := GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y)) + clip = strings.Replace(clip, "\n", "\n"+leadingWS, -1) + } } if v.Cursor.HasSelection() { v.Cursor.DeleteSelection() v.Cursor.ResetSelection() } - clip = strings.Replace(clip, "\n", "\n"+leadingWS, -1) + v.Buf.Insert(v.Cursor.Loc, clip) // v.Cursor.Loc = v.Cursor.Loc.Move(Count(clip), v.Buf) v.freshClip = false diff --git a/runtime/help/options.md b/runtime/help/options.md index a767f5bd..da502ab7 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -164,6 +164,12 @@ Here are the options that you can set: default value: `2` +* `smartpaste`: should micro add leading whitespace when pasting multiple lines? + This will attempt to preserve the current indentation level when pasting an + unindented block. + + default value: `true` + * `softwrap`: should micro wrap lines that are too long to fit on the screen. default value: `false`