I find myself often aligning certain code blocks by inserting one or more spaces, like in the following situation:
case something of Just a▉-> ... Nothing -> ...
▉ is the position of my cursor. In order to align the arrows, I enter insert mode with
<Esc>. In my vim configuration the
<Space> key doesn't do anything meaningful, so I tried creating the following mapping, hoping that it would do the same job with just one keystroke:
nnoremap <Space> i<Space><Esc>
In case of one space character this works without any problems, and even repeating with
. works. However,
3<Space> won't insert 3 spaces without moving the cursor. With the help of this Vim Tips wiki article, I made the following mapping:
nnoremap <Space> @="i\<lt>Space>\<lt>Esc>"<CR>
This successfully inserts
n number of spaces with
n<Space>, but the problem is that I cannot repeat
.. I would like to make this repeatable in a way, that when I first insert 2 spaces with
2<Space> and hit the repeat operation
., it would insert 2 spaces again instead of one.
My knowledge of Vimscript is very limited, but I suppose one could write such mapping with help of a function, and use a plugin like repeat to do the repetition part? Or is this possible to do without any plugins?