Monday, April 8, 2013

Re: Forcing myself to learn vim properly

On 08/04/13 16:10, Flavius Aspra wrote:
> Hi
>
> While learning vim the hard way, I was also playing around with scripting and I
> was wondering of a way to enforce the avoidance of repeatedly pressing movement
> keys, instead of using a count<movement>.
>
> Having a code like this:
>
> let g:cursor_moving = 0
>
> function! TrapMovementKeys(key)
> augroup CursorMoving
> autocmd!
> autocmd CursorMoved * let g:cursor_moving += 1
> augroup END
> if g:cursor_moving <= 2
> return a:key
> else
> return ''
> endif
> endfunction
>
> nnoremap <expr> h TrapMovementKeys('h')
> nnoremap <expr> j TrapMovementKeys('j')
> nnoremap <expr> k TrapMovementKeys('k')
> nnoremap <expr> l TrapMovementKeys('l')
>
> augroup CursorMovingOff
> autocmd!
> autocmd CursorHold * let g:cursor_moving = 0
> augroup END
>
> which kind of works. The problem is though that CursorHold won't be triggered
> while recording a macro (which is the documented behavior).
>
> Now I am wondering if there is any workaround for this. Ideas?
>
> Regards,
> Flavius
>

One of the great plus-points of Vim is that in many cases there are
several ways to achieve the same result. IOW, the "proper" way to use
Vim is not the one and only way "the teacher" uses it: it is whatever
way suits you best.

Yes, as Marc said, a lot of different motions are documented in the
motion.txt helpfile; and don't let keyboard fanatics sway you. Yes, the
ability to do everything by keyboard alone is great; but sometimes the
fastest way to go to a random point in the current window is just to
click on it.

hjkl and ←↓↑→ do the same thing: some people take that as an argument to
shun the arrow keys. I have a different take on this: with the following
mappings:

map <Down> gj
map <Up> gk

↓ and ↑ (in Normal mode) move by "screen lines", leaving j and k to move
by "file lines". This is particularly useful if 'wrap' is set, which is
what I use.


Best regards,
Tony.
--
Today is National Existential Ennui Awareness Day.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment