aboutsummaryrefslogtreecommitdiff
path: root/vim/config/join.vim
blob: 7d764dceb1d83db08445e175b6eec2fa425c166c (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
25
26
27
" Don't join lines with two spaces at the end of sentences; I don't two-space,
" despite the noble Steve Losh's exhortations
set nojoinspaces

" 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