diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-08-10 01:14:57 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-08-10 01:14:57 +1200 |
commit | 59ddae4b2adb102a37378814cce1a1ddbb72c2b1 (patch) | |
tree | 082141ba77bfa9c4f4fe99a0fd25be716a69bd2e /autoload/vertical_region.vim | |
download | vim-vertical-region-59ddae4b2adb102a37378814cce1a1ddbb72c2b1.tar.gz vim-vertical-region-59ddae4b2adb102a37378814cce1a1ddbb72c2b1.zip |
First versionv0.1.0
Diffstat (limited to 'autoload/vertical_region.vim')
-rw-r--r-- | autoload/vertical_region.vim | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/autoload/vertical_region.vim b/autoload/vertical_region.vim new file mode 100644 index 0000000..6f2cf8d --- /dev/null +++ b/autoload/vertical_region.vim @@ -0,0 +1,37 @@ +" Function for expression maps returning navigaton keys to press +function! vertical_region#Map(count, up, mode) abort + + " Get line and column number + let l:num = line('.') + let l:col = col('.') + + " Move up or down through buffer, counting hits as we go + let l:hits = 0 + while a:up ? l:num > 1 : l:num < line('$') + + " Increment or decrement line number + let l:num += a:up ? -1 : 1 + + " If the line has any non-space characters up to the current column, we + " have a hit; break the loop as soon as we have the count we need + let l:line = getline(l:num) + if strpart(l:line, 0, l:col) =~# '\S' + let l:hits += 1 + if l:hits == a:count + break + endif + endif + + endwhile + + " If not moving linewise for operator mode and not in first column, move to + " same column after line jump; is there a way to do this in one jump? + let l:keys = l:num . 'G' + if a:mode !=# 'o' && l:col > 1 + let l:keys .= l:col - 1 . 'l' + endif + + " Return normal mode commands + return l:keys + +endfunction |