aboutsummaryrefslogtreecommitdiff
path: root/vim/config/join.vim
blob: 7365c85e01c48ebeb10b4855cdbbdeedd7d19723 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
" Keep my cursor in place when I join lines
if has('eval')

  " Declare function
  function! s:StableNormalJoin()

    " Save current cursor position
    let l:lc = line('.')
    let l:cc = col('.')

    " Build and execute join command
    let l:command = '.,+' . v:count1 . 'join'
    execute l:command

    " Restore cursor position
    call cursor(l:lc, l:cc)

  endfunction

  " Remap J to the above function
  nnoremap <silent> J :<C-U>call <SID>StableNormalJoin()<CR>

endif