Git Product home page Git Product logo

vim-hardtime's Introduction

Hardtime

Hardtime helps you break that annoying habit vimmers have of scrolling up and down the page using jjjjj and kkkkk but without compromising the rest of our vim experience.

It works using a timeout on the keys you want to stop repeating, i.e. h, j, k, l, UP, DOWN, LEFT, RIGHT. This timeout is set to 1000 milliseconds. After this time you can use a movement key again. It also allows to completely disable keys that you never under any circumstances want to use.

Stop repeating jjjjj... Stop repeating kkkk...

Kick the habit now!

Inspired by vim-hardmode, but where hardmode fell short was that sometimes h,j,k,l are needed! Hardtime lets you use these keys but only once every second. You can still create macros in hardtime where you need to move down lines, and you can still move that one character over to make that edit.

Resources to help you kick the bad habits

  • Drew Neil has a great blog post on Habit breaking, habit making
  • Practising some Vim golf will certainly improve your movement skills
  • Vim help, :h word-motions and :h motion are both great resources
  • A good Vim wiki article

Usage

Once installed you can call the command :HardTimeOn to activate hardtime, conversely you can use :HardTimeOff to switch it off. You can also use :HardTimeToggle toggle it on an off.

If you want hardtime to run in every buffer, add this to .vimrc

let g:hardtime_default_on = 1

The default is 0.

Customization

Add the following variables to your .vimrc to enable customizations.

Keys

Set the list of keys to be banned of use with hardtime

Defaults to

let g:list_of_normal_keys = ["h", "j", "k", "l", "-", "+", "<UP>", "<DOWN>", "<LEFT>", "<RIGHT>"]
let g:list_of_visual_keys = ["h", "j", "k", "l", "-", "+", "<UP>", "<DOWN>", "<LEFT>", "<RIGHT>"]
let g:list_of_insert_keys = ["<UP>", "<DOWN>", "<LEFT>", "<RIGHT>"]
let g:list_of_disabled_keys = []

Note that the keys added to g:list_of_disabled_keys are disabled in all of normal, visual and insert modes.

Timeout

It is possible to tweak the timeout allowed between keypresses. specifying the time in milliseconds.

let g:hardtime_timeout = 2000

This allows you increase the amount of time

The default is 1000.

Enable Notifications

To enable the notification about HardTime being enabled set

let g:hardtime_showmsg = 1

The default is 0.

Ignore Buffers

To enable hardtime to ignore certain buffer patterns set

let g:hardtime_ignore_buffer_patterns = [ "CustomPatt[ae]rn", "NERD.*" ]

The default is [].

Ignore Quickfix

The quickfix window cannot be added to the ignore buffers array to have hardtime ignore it set

let g:hardtime_ignore_quickfix = 1

The default is 0.

Allow different keys

To make hardtime allow a key if it is different from the previous key, set

let g:hardtime_allow_different_key = 1

This, for example, makes it possible to input "jh", but not "jj".

The default is 0.

Maximum number of repetitive key preses

This setting will let you press a key n number of times before hardtime starts ignoring subsequent keypresses.

let g:hardtime_maxcount = 2

Setting this value to 2 will allow a user to press jj but not jjj.

The default is 1.

Reset counter if motion is used with a count

Using a key with a count (5j) will lead to a reset of the key's count.

let g:hardtime_motion_with_count_resets = 1

Setting this to 1 allows you to press j5j if g:hardtime_maxcount is 1.

The default is 0.

Installation

I recommend installing using Vundle:

Add Bundle 'takac/vim-hardtime' to your ~/.vimrc and then:

  • either within Vim: :BundleInstall
  • or in your shell: vim +BundleInstall +qall

Installing using vim-plug

  1. Install vim-plug using the instructions

  2. Add vim-hardtime to your plugin list in .vimrc or plugins.vim and re-source it:

    insert vim-hardtime

    " Vim HardTime
    Plug 'takac/vim-hardtime'
    

    between call plug#begin('~/.vim/plugged')

    and call plug#end()

  3. Run :PlugInstall

vim-hardtime's People

Contributors

alexshepard avatar awlayton avatar bwells avatar danilamihailov avatar dmalikov avatar genki-s avatar grazfather avatar jbernard avatar jrasmusbm avatar kovetskiy avatar kusnier avatar lstephen avatar marcolucidi01 avatar narfdotpl avatar rasendubi avatar renenyffenegger avatar rski avatar takac avatar theremix avatar tjbrn avatar twe4ked avatar watkins 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vim-hardtime's Issues

Disable when YCM shows autocomplete

Whenever YCM is showing its autocomplete list, I can't just fast scrolling looking up modules that I want to use/explore. Here is what I meant by YCM autocomplete :

image

For this autocomplete, vim-hardtime will limit my scrolling movement for 1 second.
So can we disable whenever this autocomplete popup appears and enable vim-hardtime back when popup disappears?

Disable hardtime on vimshell

Hello, such a great plugin over here, I'm trying to disable hardtime on the vimshell buffers but I can not make it to work, I've tried this with no success:

let g:hardtime_ignore_buffer_patterns = ["NERD.*", "*vimshell*"]
let g:hardtime_ignore_buffer_patterns = ["NERD.*", "vimshell"]
let g:hardtime_ignore_buffer_patterns = ["NERD.*", "vimshell*"]

On vim-shell buffer name appears as [vimshell] - default and filetype is vimshell.

Thanks in advance!

Weird errors when trying to use movement keys

With vim-hardtime enabled sometimes I see wield error messages like:

E109: Missing ':' after '?'
E15: Invalid expression: TryKey('j') ? 'TryKey('j') ? 'TryKey('j') ? 'TryKey('j') ? 'j' : TooSoon()' : TooSoon()' : TooSoon() : TooSoon()

If I disable vim-hardtime then this does not happen. I see this error come up more when working with splits than anything else.

Allow {motion}[h,j,k,l]

It would be really nice if there was an option to allow h,j,k,l if it's after a motion.

For example. 3j or 5k should be entirely allowed. I use relative numbers so for me I use this method to navigate round a lot. Would it be possible to have an option to allow this?

Thanks!

Vim-hardtime compatiblity to SnipMate

It seems as though vim-hardtime is incompatibel with Snipmate. Snippets that contain for example ${1:var} won't execute correctly if ${1:var} is replaced with a word that starts with j, k, l or h.

Conflicts with tpope/vim-vinegar

This plugin introduces a map on the - key that conflicts with the invocation of vim-vinegar.

not sure what the reason of this map is but when looking at active mapings I saw the following:
screen shot 2017-02-07 at 23 58 13

in other words somehow vim-hardtime tries to wrap the - mapping but it never invokes vinegar.

Recommended way of doing stuff

While I've been using vim for a few years and even though I use b,e,etc. keys sometimes, most of the times I find myself using h,j,k,l to browse code.

Adding to the Readme what you should do instead of navigating using arrow keys would benefit some users.

Is it possible to make this plugin work with ideavim?

Hi,

Thank you very much for this plugin! It's exactly what I need to learn how to not rely so much on hjkl.

Does anyone know how one can get this working with [ideavim[(https://github.com/JetBrains/ideavim)?

Please feel free to close this if it doesn't fit here.

installation fail

Hi,
I installed hardtime with Vundle, but nothing happen here:

Plugin 'takac/vim-hardtime' 

:bundleInstall

"hardtime
let g:list_of_normal_keys = ["h", "j", "k", "l", "-", "+", "<UP>", "<DOWN>", "<LEFT>", "<RIGHT>"]
let g:list_of_visual_keys = ["h", "j", "k", "l", "-", "+", "<UP>", "<DOWN>", "<LEFT>", "<RIGHT>"]
let g:list_of_insert_keys = ["<UP>", "<DOWN>", "<LEFT>", "<RIGHT>"]
"let g:list_of_disabled_keys = []
let g:hardtime_timeout = 2000 "2 sec
let g:hardtime_showmsg = 1

Nvim unexpected behaviour

The plugin works when running starting nvim, provided you specify the file name.
Running the command

nvim test.txt

makes the plugin work as expected.
However, when running

nvim

by itself, the plugin doesn't initiate.
I have the plugin config set in ~/.config/nvim/init.vim

Running

:HardTimeOn

when in nvim enables the plugin. But it still doesn't enable itself on startup without a file name specified.

let g:hardtime_default_on = 1

is of course set

Why should we break this habit?

I agree in some cases repeating could be inefficient, and should be done with some advanced movements. But sometimes repeating could be faster than complex key sequences. For example, I normally set keyboard repeat rate to maximum, so it is not only easier, but also faster to hold j, than the key sequence 20j, to go down 20 lines. But of course jumping more lines it is generally better to instead use ctrl-f.

Mappings conflict even when on ignore_buffer_pattern

I'm using tpope's fugitive. - is used to (un)stage a file to git's index.
When Hardtime is enabled it overrides this shortcut (visual and normal modes) so I can't do the mentioned action anymore.

I added .git/index (the result from :echo bufname('%') to:

let g:hardtime_ignore_buffer_patterns = [ "NERD.*", ".git/index" ]

restarted vim, but didn't work. I've run :verbose map - and it showed that - mapping was last set by hardtime, still.

Disabling the plugin & restarting vim put the behaviour back to normal...

What should I do with this plugin if I want to go UP/DOWN?

What should I do with this plugin if I want to go UP/DOWN?

  1. easymotion to jump to the word.

  2. Repeat 'W' times to next line
    or repeat 'E' times to prev' line.
    [ It's horrible ... ]

  3. Search the word even the word is at EOL of next line.

  4. ? I just using vim the wrong way.

Add ability to ignore help buffers

I'd like the ability to disable hardtime while in a help buffer. Generally I find non-optimal patterns like holding down j to scroll within buffers that are mostly just text to be just fine.

I'm happy to code it up and submit a pull request. Do you have any preference on implementation?

We could add g:hardtime_ignore_help and s:IsIgnoreHelp() just like the quickfix counterparts, or combine the implementations of s:IsIgnoreQuickfix and call it something like s:IsIgnoreSystem

Quickfix window

First of all: thank you for taking the time to write this plugin. It's cool that you want us to be better Vimmers ๐Ÿ˜„

I'd like to disable vim-hardtime when moving through the quickfix window. Is that possible? I tried using g:hardtime_ignore_buffer_patterns, but didn't worked.

Macros hit the key limit.

If you have a macro that does an action and run it again, if the action is j or something else, it doesn't work. To reproduce:

qqjq to record a macro of going down a line, @q@@ to run the macro, then again. The second time you run the macro, nothing happens because HardTime is blocking you. I don't know if you can detect a macro being run though.

Doesn't work for CamelCaseMotion motions mapped to Ctrl-E/B/W keys

I'm using CamelCaseMotion with the following config:

NeoBundle 'bkad/CamelCaseMotion'
map <C-W> <Plug>CamelCaseMotion_w
map <C-B> <Plug>CamelCaseMotion_b
map <C-E> <Plug>CamelCaseMotion_e

NeoBundle 'takac/vim-hardtime'
let g:hardtime_default_on = 1
let g:list_of_normal_keys = ["w", "b", "e", "W", "B", "E",
      \ "<c-w>", "<c-b>", "<c-e>", "gj", "gk", "h", "j", "k", "l"]

For some reason specifically keys <C-e/b/w> do nothing when I press them while others work OK. Without vim-hardtime C-* keys work OK.

Add exception list feature?

Hi, this plugin is great! Thanks for it.

But it would be cool to list some exceptions like NERDTree buffer. Imagine we have:

folderA
folderB

And the cursor is in folderA and we want to go to folderB and then open it, and then open the first file under it... You can see this quickly become annoying as in this case just navigating down is the quickest way...

Enable hardtime in buffers without a name

When g:hardtime_default_on is set, hardtime is supposed to be enabled in every buffer. This is what the README says.

The following line [link to source] does this:

autocmd BufRead,BufNewFile * call s:HardTime()

However, when creating a new buffer that does not yet have a name (e.g. using :tabnew), the BufNewFile event will not fire, and hardtime will not be run. The same is true for buffers that are opened by a plugin: opening a netrw window (:Ex) doesn't enable hardtime, which means that the user can freely use the hjkl and arrow keys.

Is this behavior intended? If not, this commit could possibly help.

Refactor <SID> with original script ID

First of all, thank you for the great plugin! It really helps to boost productivity and to break the bad habits.

I have one problem with it, it clashes with kana's vim-arpeggio. I thought it was a problem in vim-arpeggio and so I reported the issue in kana's repository. He pointed out that the problem is in the way the mappings are defined in vim-hardtime:

kana/vim-arpeggio#21 (comment)

Could this be updated so it doesn't clash with other plugins? Thank you very much.

Conflict with mapped key

Adding "w" to the keys and trying to use vim-wordmotion results in:
E109: ':' missing after '?'

The problem seems to be with the arguments, so:
let mapping["rhs"] = substitute(mapping["rhs"], "'", "''", "g")
But know I get E117: Unknown function.

This works for me, but I don't know if it is equivalent (there's a reason to execute rhs and not the key itself?):

fun! s:RetrieveMapping(key, mode)
    let mapping = maparg(a:key, a:mode, 0, 1)
    if empty(mapping) || mapping["expr"] == 0
        return "'" . a:key . "'"
    endif
    return mapping["expr"]
endf

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.