├── README.md ├── bounce.lua ├── help └── bounce.md └── repo.json /README.md: -------------------------------------------------------------------------------- 1 | # BOUNCE 2 | 3 | micro-bounce is a plugin for the excellent [micro editor](https://github.com/zyedidia/micro). 4 | 5 | It provides various cursor manipulations: 6 | 7 | - smartHome: bounce between start of text and start of line, in that order 8 | - bounce: bounce between matching brackets 9 | - save/recall cursor location: save your spot in a file and jump back to it 10 | 11 | ## Installation 12 | 13 | micro-bounce is part of the official plugin channel. To install simply run the below command: 14 | 15 | `> plugin install bounce` 16 | 17 | 18 | ## Setup / Usage 19 | 20 | After installing, restart micro then run 'help bounce' to see how to bound the various plugin 21 | functions to shortcuts. 22 | 23 | `> help bounce` 24 | 25 | ## Tip / Example 26 | 27 | Getting back to the cursor location in a file after executing a find is a good use of the cursor saving functions the bounce plugin provides. 28 | 29 | Replace the default binding for CtrlF as shown: 30 | 31 | `"CtrlF": "lua:bounce.keepLoc,Find"` 32 | 33 | This will save the cursor location, then execute micro's find function. After you're done with your search you can call the bounce.gotoStoredLoc function to return to where the cursor was when the search was initiated. 34 | -------------------------------------------------------------------------------- /bounce.lua: -------------------------------------------------------------------------------- 1 | VERSION = "2.0.0" 2 | 3 | local micro = import("micro") 4 | local config = import("micro/config") 5 | local shell = import("micro/shell") 6 | local buffer = import("micro/buffer") 7 | 8 | -- NOTE: it's up to the user to bind the below functions to key presses. 9 | 10 | function init() 11 | config.AddRuntimeFile("bounce", config.RTHelp, "help/bounce.md") 12 | end 13 | 14 | -- bounce cursor between start of line and first non-whitespace character 15 | -- slightly different than how micro's default home works, this is first non-whitespace 16 | -- character, then start of line. micro works backwards, start of line, then 17 | -- the first non-whitespace character 18 | function smartHome(bp) 19 | local c = bp.Buf:GetActiveCursor() 20 | local origX = c.Loc.X 21 | c:StartOfText() 22 | if origX == c.Loc.X then 23 | c:Start() 24 | end 25 | bp:Relocate() 26 | end 27 | 28 | -- bounce cursor between matching brackets 29 | function bounce(bp) 30 | local bracketPairs = { {123,125}, {91,93}, {40,41} } 31 | 32 | local c = bp.Buf:GetActiveCursor() 33 | local start = -c.Loc 34 | for k,b in pairs(bracketPairs) do 35 | local matchLoc, onLeft, ok = bp.Buf:FindMatchingBrace(b,-c.Loc) 36 | if ok then 37 | c:GotoLoc(matchLoc) 38 | if onLeft then 39 | local nudge = buffer.Loc(c.X-1, c.Y) 40 | c:GotoLoc(nudge) 41 | end 42 | bp:Relocate() 43 | return 44 | end 45 | end 46 | end 47 | 48 | -- keepLoc / gotoStoredLoc - easier than memorizing line numbers 49 | local storedLoc = {} 50 | function keepLoc(bp) 51 | storedLoc[bp.Buf.AbsPath] = -bp.Cursor.Loc 52 | end 53 | 54 | function gotoStoredLoc(bp) 55 | local name = bp.Buf.AbsPath 56 | if storedLoc[name] ~= nil then 57 | bp.Cursor:GotoLoc(storedLoc[name]) 58 | bp.Cursor:ResetSelection() 59 | bp:Relocate() 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /help/bounce.md: -------------------------------------------------------------------------------- 1 | # Bounce Plugin 2 | 3 | The bounce plugin adds some nano-like functionality I felt was missing from micro. 4 | It's called 'bounce' because all features involving moving (bouncing) the cursor 5 | around. 6 | 7 | ## Smart Home 8 | The `smartHome` function is an alternative home-button function. 9 | 10 | Calling the smartHome function sends the cursor to the start of text (first 11 | non-whitespace character). Pressing again sends the cursor to the start of the line. 12 | 13 | ### Using 14 | Once the plugin is installed, to use simply bind a key to the smartHome function: 15 | 16 | In bindings.json: `"Home":"lua:bounce.smartHome",` 17 | 18 | Or from micro's commandline: `> bind Home "lua:bounce.smartHome"` 19 | 20 | 21 | ## Matching Bracket Bounce 22 | 23 | Bracket bounce bounces the cursor between matching brackets, currently: {,[,(. and 24 | their closing counterparts: },],) 25 | 26 | ### Using 27 | To use, bind a key to the bounce function: 28 | 29 | From micro's commandline: `> bind Alt-G "lua:bounce.bounce"` 30 | 31 | When the cursor is overtop a bracket, press the bound button to move the cursor 32 | to the matching bracket. 33 | 34 | The plugin uses micro's bracket matching function, so the cursor will always move 35 | to where micro has highlighted the matching bracket, (or fail to move, 36 | if micro has failed to match). 37 | 38 | ## Cursor Location Saving 39 | 40 | The below pair of functions allow you to store and jump to a cursor location. This 41 | location is *not* persistent across multiple instance of micro nor is it saved 42 | upon exiting. The location is unique per absolute file path (so new tabs with no 43 | filename share the same saved cursor location). An example use-case is saving your 44 | location before doing a search or replace command. Once done with your search, you can 45 | jump back to where you were. 46 | 47 | The below command bound to Ctrl-K will store the current cursor location. 48 | 49 | `> bind CtrlK "lua:bounce.keepLoc"` 50 | 51 | The below command bound to Ctrl-G will move the location to the saved position. 52 | 53 | `> bind CtrlG "lua:bounce.gotoStoredLoc"` 54 | 55 | 56 | ## Bugs And Feature Requests 57 | 58 | Please file issues and feature requests on github: 59 | https://github.com/deusnefum/micro-bounce 60 | 61 | -------------------------------------------------------------------------------- /repo.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "Name": "bounce", 3 | "Description": "plugin to add nano-style 'smart home' and bounce cursor between matching brackets", 4 | "Tags": ["bounce", "smarthome"], 5 | "Versions": [ 6 | { 7 | "Version": "1.1.2", 8 | "Url": "https://github.com/deusnefum/micro-bounce/archive/v1.1.2.zip", 9 | "Require": { 10 | "micro": ">=2.0.0" 11 | } 12 | }, 13 | { 14 | "Version": "1.1.1", 15 | "Url": "https://github.com/deusnefum/micro-bounce/archive/v1.1.1.zip", 16 | "Require": { 17 | "micro": ">=2.0.0" 18 | } 19 | }, 20 | { 21 | "Version": "1.1.0", 22 | "Url": "https://github.com/deusnefum/micro-bounce/archive/v1.1.0.zip", 23 | "Require": { 24 | "micro": ">=2.0.0" 25 | } 26 | }, 27 | { 28 | "Version": "1.0.0", 29 | "Url": "https://github.com/deusnefum/micro-bounce/archive/v1.0.0.zip", 30 | "Require": { 31 | "micro": ">=2.0.0" 32 | } 33 | } 34 | ] 35 | }] 36 | --------------------------------------------------------------------------------