opened
chmike
username_0
## Description of the problem or steps to reproduce

## Specifications

$ micro -version
Version: 2.0.2
Commit hash: c51f849
Compiled on February 26, 2020

Commit hash: c51f849
OS: Ubuntu
Terminal: bash


When hitting the home button, the cursor moves the first non-space character of the line or the end of line if the line contains only space characters. 

The expected behavior, that is seen in other editors, is that the home button moves the cursor on he left to the first non-space character, and if there are none, to the beginning of the line. I had the impression that the later was the behavior of micro in versions 1.x. 

In micro 2.x, hitting ctrl-left arrow moves the cursor to the beginning of the line. Hitting ctrl-home moves the cursor to the beginning of the file. This happens often since I mix the left arrow and home button. Unfortunately, I don’t know how to jump back to last cursor position, and I’m not sure this is even possible. 

Is there an option to change the effect of hitting the home button ?
Home button does not move cursor to beginning of line
issue
created
deusnefum
username_1
I wrote a plugin that changes the home button behavior to match that of nano when "smart home" is enabled which is what you described as typical editor behavior. Press to send to beginning of text. Press again to go to beginning of line. I could add an option to restore simple beggining of line functionality.

Here's the lua code:

```
-- bounce cursor between start of line and first non-whitespace character
-- slightly different than how micro's default home works, this is first non-whitespace
-- character, then start of line. micro works backwards, start of line, then 
-- the first non-whitespace character
function smartHome(bp)
        local c = bp.Buf:GetActiveCursor()
        local origX = c.Loc.X
        local origY = c.Loc.Y
        c:StartOfText()
        if origX == c.Loc.X and origY == c.Loc.Y then
                c:Start()
        end
        bp:Relocate()
end
```
comment
created
chmike
username_0
@username_1 Thank you very much. That’s great. How do I install this plugin and use it ? Have you considered adding it to https://micro-editor.github.io/plugins.html ? I looks like the installation is trivial.
comment
created
chmike
username_0
@username_1 I found out how to install the function:

1. Create the file ~/.config/micro/init.lua
2. In the file, write the following
```
local config = import("micro/config")
local shell = import("micro/shell")

function init()
    -- true means overwrite any existing binding to Home
    -- this will modify the bindings.json file
    config.TryBindKey("Home", "lua:initlua.smartHome", true)
end

-- bounce cursor between start of line and first non-whitespace character
-- slightly different than how micro's default home works, this is first non-whitespace
-- character, then start of line. micro works backwards, start of line, then 
-- the first non-whitespace character
function smartHome(bp)
        local c = bp.Buf:GetActiveCursor()
        local origX = c.Loc.X
        local origY = c.Loc.Y
        c:StartOfText()
        if origX == c.Loc.X and origY == c.Loc.Y then
                c:Start()
        end
        bp:Relocate()
end
```
3. Start micro and enjoy the new Home key behavior.

Thank you very much. It’s great. I was so frustrated by this Home key behavior.
comment
created
deusnefum
username_1
Glad it's helpful! Yes, I keep meaning to do a PR to add my plugins to the official channel.

I also have a plugin that bounces the cursor between matching brackets (also in the same style as nano).
comment
created
deusnefum
username_1
Okay, Finally put in the time to get some repos going for my plugins. Got an open PR to add them to the official channel https://github.com/micro-editor/plugin-channel/pull/48
comment
created
sta-c0000
username_2
username_1's plugins' functionality feel very natural to me ...like maybe they could be default functionality? ;-)

- smartHome makes the Home key work as expected to me.
- bounce is super handy ("Alt-]" binding works best for me)
- quoter (= autoSurround) is especially great for markdown editing (sometimes language specific pairs in other editors, but seems ok generalized here)

Thanks for this!
comment
created
deusnefum
username_1
@username_0 my plugins are now part of the official channel. Is this a good enough solution that you can close the issue?
comment
created
chmike
username_0
@username_1 I installed the bounce plugin, and everything works fine. Thank you very much.
comment
closed
chmike
username_0
issue