Code Monkey home page Code Monkey logo

move-less's Introduction

move-less.vim

move-less is all about faster navigation by moving less around.

The idea is that you fold the space between your line and the target destination and then jump to the target position. Just similar to some kind of warp drive ;)

To archive this there is a so called move-less-mode which you can enter by typing <LEADER>m.

Here you can see a little demo: move-less demonstration

First the user look up, then below and finally in both directions. At the end he jumps to the target position by using plain <number>k

You can now also use it to generate a temporary upper and or bottom folding. So, you can place to distance section from the upper and the bottom together. (see meaning of 'p' while in move less mode)

This can be very handy if you have to make multiple replacements or movings from two distance places.

If you want to remap the setting you can just create a mapping which calls the function MoveLessMode. For instance if you want to map it to ' then you can just add the following mapping to your vimrc:

noremap ' :call MoveLessMode()<cr>

If you are in the move-less mode you can navigate like the following:

j: Type once and your line will be displayed at the top (if possible). Every further click will fold lines below your cursor. So you can see the text under your cursor. The number of lines which are fold are defined by the scroll attribute.

k: Type once and your line will be displayed at the bottom (if possible). Every further click will fold lines below your cursor, so you can see the upper text. The number of lines which are fold are defined by the scroll attribute.

J: Type once and your line will be displayed at the top (if possible). Any further click will reduce the fold below your cursor position. So, that you are able to see text again which you already have fold (kind of an undo of j)

K: Type once and your line will be displayed at the bottom. Any further click will reduce the fold above your cursor position. So, that you are able to see text again which you already have fold (kind of an undo of k)

l, or H: Type once and your line will be displayed at the middle. Any further click will fold the text above and below your cursor position. So, that you are able to search your target positon in both directions.

h or L: Type once and your line will be displayed at the middle. Any further click will reduce the fold above and below your cursor position. So, you can see the text again which you already fold. It's kind of an undo for l.

<ESC>: Abort move less mode and delete all foldings, you are not able to jump to Any distance place now.

p: Stop the move less mode but let the folding remain (p)ermanently. In fact it's just more permanent then the normal behaviour it's also temporary until you use the mode less mode next time. If you just want to unfold later you can go to move less mode and end it directly with . This new feature permanent feature should be handy if you want to edit two places in the file which has a big distance.

<Any other key>: Move less mode will directly be ended, but folding will be temporary remain. From now on, you can jump or walk over the folding to get to your target position. You can use any vim method you like for this action. For example move-less is intended to work pretty well with easymotion for archiving super fast navigation.

As long as no jump or walk over the folding was taken the fold remains, if the move-less mode is activated again in such a situation it will just continue the last mode (by still using the actual folding). This behavior could also be used for going into the move less mode again and make a clean abort of the mode by typing <ESC>.

After such an action the folding will be immediately removed. It is only intended to be used for navigation without moving.

Customizing the navigation shortcuts

The key bindings mentioned above are controlled by the g:MoveLess#Mappings variable, which is a dictionary of actions and their activation keys.

Below is the DEFAULT dictionary, for reference.

{
  'FoldBelow': 'j',
  'FoldAbove': 'k',
  'UnfoldBelow': 'J',
  'UnfoldAbove': 'K',
  'FoldAboveAndBelowK1': 'l',
  'FoldAboveAndBelowK2': 'H',
  'UnfoldAboveAndBelowK1': 'h',
  'UnfoldAboveAndBelowK2': 'L',
  'StopMoveLess': 'p',
  'AbortMoveLess': "\<Esc>"
}

You can override the shorcuts by substituting this dictionary for your own, like the example below.

let g:MoveLess#Mappings =
  \   {
  \     'FoldBelow': 'e',
  \     'FoldAbove': 'i',
  \     'UnfoldBelow': 'I',
  \     'UnfoldAbove': 'E',
  \     'FoldAboveAndBelowK1': 's',
  \     'FoldAboveAndBelowK2': 'O',
  \     'UnfoldAboveAndBelowK1': 'o',
  \     'UnfoldAboveAndBelowK2': 'S',
  \     'StopMoveLess': 'p',
  \     'AbortMoveLess': "\<Esc>"
  \   }

Note that you need to provide the full dictionary through the g:MoveLess#Mappings variable.

Scenarios, how this plugin might help you

Faster navigaton without move

Let's pretend our cursor is in the middle of a huge file (300 lines) lets say line number 150. And then we are searching for a function. But we are not sure about the function name, we are not even sure if it's located inside the current file at all.

Normally we would now navigate up the file. If we don't find something we have to navigate the file down.

With the plugin you activate the so called move-less mode. Then you look up by first clicking of k. If you don't find the target position you would click k again and fold the lines above you (which you already have checked). If you click to fast k, and may miss something you could decrease the folding via K.

In this way you could see "screen by screen (feels a little bit like less ;)) until you you see the top of the file.

If you dont have found something you can do the same in the down direction (j/J).

If you like you could search in both directions at the same time (l / h).

If you found your function you could jump or walk to it by simple use your prefered way to do it. (i like easymotion a lot for this step but it's not necessary). The navigation is recorded in the jumplist, so you could easily switch between source and target positon afterwards.

If you have found nothing you can click ESC and you don't have even changed your positoon at all.

So long talk short:

  • don't move cursor position just for searching the right line

  • use jkhl keys instead of c-u, c-d or something similiar

  • search up and down together

  • easily abort your "navigation"

Installation

Use Vundle

Add Plugin 'anschnapp/move-less' to your ~/.vimrc and run PluginInstall.

git clone https://github.com/anschnapp/move-less ~/.vim/bundle/move-less

Contribution

I welcome every kind of contribution like sending issue's, feature requests or pull requests.

License

Copyright (c) Andreas Schnapp. Distributed under the same terms as Vim itself. See :help license.

move-less's People

Contributors

anschnapp avatar resolritter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

aileot

move-less's Issues

Key mapping does not work

Plug-in command manual input can work, but the key mapping does not work, I used neovim. Previously the mapping worked, but now only manual output works.
My English is not good! I am sorry, but I like this plugin very much.
图片
图片
This is the result given by echo maparg('z', 'n') and the feedback seems to be ok
图片

Provide a way to continue and redo Move-Less mode navigation from a location

Possible use cases:

  • Save folds before exiting a file and then restore the fold configuration when coming back. I think this is low priority but would be nice.
    :call MoveLess#Save
    :call MoveLess#Restore
  • Modification:
    • Pop the fold configuration from a stack. Enables MoveLess mode.
      :call MoveLess#Pop
    • Modify it as he wants it with H h J K...
    • Put it back into the stack. This exits the fold and puts the configuration in the stack.
      :call MoveLess#Push
  • Switch between different folds configuration in the stack.
    :call MoveLess#EnableFold(2) -- enables the second fold in the stack.

The main benefits would be to quickly switch to navigate on sections of the file.

Example workflow:

  • :call MoveLessMode() and navigate a bit in the top of the file. [FOLD1]
  • :call MoveLess#Push() to put the fold in the stack [FOLD1]. Now I want to go to the bottom of the file.
  • :call MoveLess#EnableFold(2) -- loads the second fold configuration and navigate to the bottom of the file. [FOLD2]
  • Navigate, stop. Make some edits, then :call MoveLess#Pop [FOLD1]. Now I'm back at the top of the file in MoveLess mode and my bottom configuration [FOLD2] is still saved in the stack.

What do you think? I didn't use fold much before finding this plugin, but the workflow seems useful.

Populate the jumplist

After using move-less, the expected behavior of '' is to take me to where I were before the jump. This can be achieved with nmap <leader>m m':call MoveLessMove()<cr>, but it would be nice if it was the default behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.