diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 02b72659..b1c18d60 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -428,6 +428,11 @@ func (v *View) InsertNewline(usePlugin bool) bool { for i := 0; i < len(ws); i++ { v.Cursor.Right() } + + if IsSpacesOrTabs(v.Buf.Line(v.Cursor.Y - 1)) { + line := v.Buf.Line(v.Cursor.Y - 1) + v.Buf.Remove(Loc{0, v.Cursor.Y - 1}, Loc{Count(line), v.Cursor.Y - 1}) + } } v.Cursor.LastVisualX = v.Cursor.GetVisualX() diff --git a/cmd/micro/util.go b/cmd/micro/util.go index f5d77abc..c477c41e 100644 --- a/cmd/micro/util.go +++ b/cmd/micro/util.go @@ -112,6 +112,17 @@ func IsSpaces(str string) bool { return true } +// IsSpacesOrTabs checks if a given string contains only spaces and tabs +func IsSpacesOrTabs(str string) bool { + for _, c := range str { + if c != ' ' && c != '\t' { + return false + } + } + + return true +} + // ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off' // as 'true' and 'false' respectively func ParseBool(str string) (bool, error) {