I'm using one of Vim distribution called SpaceVim and everything is good enough except some details. How do I make spacevim to preserve column position when moving between lines? For instance - move from first line and 10 column (1:10) to second line without any columns (2:1) and then get back (all using j
and k
keys). Now you are on 1:1 position instead of 1:10 as expected and how nvim behaves by default. What option or toggle is responsible for column position preserving? Thanks.
2 Answers
As author of SpaceVim, I can not reproduce this issue in master branch. and we do not map j
and k
in spacevim.
I think you should check result of :verbose map j
or :verbose map k
, this command will show what and where j and k is mapped.
if the result is empty, you need to check autocmd like CursorMoved
via :au CursorMoved
, the output will what autocmd will be called when move cursor.
-
thx for ur support. I've created the issue on github github.com/SpaceVim/SpaceVim/issues/1464. The problem has already gone as it was problem of my installation.– aryndinCommented Mar 26, 2018 at 13:35
-
nice! If you encounter other issue , you can use spacevim tag in this channel Commented Mar 29, 2018 at 14:57
I am learning light vimscripting, so I am not sure if this will work. But put these in your .vimrc
:
function! NextLine()
let c = col(".")
execute "normal! j" . c . "|"
endfunction
function! PreviousLine()
let c = col(".")
execute "normal! k" . c . "|"
endfunction
nnoremap j :call NextLine()
nnoremap k :call PreviousLine()
These will not give you native vim experience because if you go down to a line of zero column, then the next line will also be on the zeroth column, not the column of the previous column. This would require, I think, another function for checking if any h or l has been pressed in between the function calls to preserve intelligent column number preservation.
But I think it should get the job done for now.
-
The not "native vim experience" you describe seems to be exactly the behaviour the OP wants to fix?– RichCommented Mar 5, 2018 at 15:57
nunmap j | nunmap k
fix the problem? If so, what SpaceVim behaviour have you lost, and do you care about that?autocmd
responsible for this. Check if there's anything suspicious in the output of:autocmd CursorMoved