aboutsummaryrefslogtreecommitdiff
path: root/vim/plugin/fixed_join.vim
blob: 18f563f3d0b6d88e0f43ab0842b7cde885217352 (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
28
29
30
31
32
33
"
" User-defined key mapping to keep cursor in place when joining lines in
" normal mode
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
if exists('g:loaded_fixed_join')
      \ || &compatible
  finish
endif
let g:loaded_fixed_join = 1

" Declare function
function! s:FixedJoin()

  " 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

" Create mapping proxy to the function just defined
noremap <silent> <unique>
      \ <Plug>FixedJoin
      \ :<C-U>call <SID>FixedJoin()<CR>