From 192af8c7f52d0b9ab3660f83fd5605653a979bef Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 10 Aug 2018 00:20:51 +1200 Subject: Add vertical_region.vim plugin --- vim/plugin/vertical_region.vim | 67 ++++++++++++++++++++++++++++++++++++++++++ vim/vimrc | 10 +++++++ 2 files changed, 77 insertions(+) create mode 100644 vim/plugin/vertical_region.vim diff --git a/vim/plugin/vertical_region.vim b/vim/plugin/vertical_region.vim new file mode 100644 index 00000000..edd5731a --- /dev/null +++ b/vim/plugin/vertical_region.vim @@ -0,0 +1,67 @@ +" +" vertical_region.vim: Move to a line that has non-space characters before or +" in the current column, usually to find lines that begin or end blocks in +" languages where indenting is used to show or specify structure. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('g:loaded_vertical_region') || &compatible + finish +endif +if v:version < 700 + finish +endif +let g:loaded_vertical_region = 1 + +" Function for expression maps returning navigaton keys to press +function! s:VerticalRegion(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 + +" Define plugin maps +nnoremap (VerticalRegionUpNormal) + \ VerticalRegion(v:count1, 1, 'n') +nnoremap (VerticalRegionDownNormal) + \ VerticalRegion(v:count1, 0, 'n') +onoremap (VerticalRegionUpOperator) + \ VerticalRegion(v:count1, 1, 'o') +onoremap (VerticalRegionDownOperator) + \ VerticalRegion(v:count1, 0, 'o') +xnoremap (VerticalRegionUpVisual) + \ VerticalRegion(v:count1, 1, 'x') +xnoremap (VerticalRegionDownVisual) + \ VerticalRegion(v:count1, 0, 'x') diff --git a/vim/vimrc b/vim/vimrc index be9c63ab..2531327d 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -318,6 +318,16 @@ nnoremap . :lmake! nnoremap :'[,'] nnoremap > :'[,']> +" \{ and \} move to lines with non-space chars before current column +nmap { (VerticalRegionUpNormal) +nmap } (VerticalRegionDownNormal) +omap { (VerticalRegionUpOperator) +omap } (VerticalRegionDownOperator) +if exists(':xmap') + xmap { (VerticalRegionUpVisual) + xmap } (VerticalRegionDownVisual) +endif + " \/ types :vimgrep for me ready to enter a search pattern nnoremap / :vimgrep /\c/ ** " \? types :helpgrep for me ready to enter a search pattern -- cgit v1.2.3 From bd64d69db2bbb426fe9f4b439af4c3a9ed30f3ee Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 10 Aug 2018 00:34:11 +1200 Subject: Use autoloading for vertical_region.vim --- vim/autoload/vertical_region.vim | 37 +++++++++++++++++++++++++++++ vim/plugin/vertical_region.vim | 50 +++++----------------------------------- 2 files changed, 43 insertions(+), 44 deletions(-) create mode 100644 vim/autoload/vertical_region.vim diff --git a/vim/autoload/vertical_region.vim b/vim/autoload/vertical_region.vim new file mode 100644 index 00000000..6f2cf8d6 --- /dev/null +++ b/vim/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 diff --git a/vim/plugin/vertical_region.vim b/vim/plugin/vertical_region.vim index edd5731a..ddf83a53 100644 --- a/vim/plugin/vertical_region.vim +++ b/vim/plugin/vertical_region.vim @@ -14,54 +14,16 @@ if v:version < 700 endif let g:loaded_vertical_region = 1 -" Function for expression maps returning navigaton keys to press -function! s:VerticalRegion(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 - " Define plugin maps nnoremap (VerticalRegionUpNormal) - \ VerticalRegion(v:count1, 1, 'n') + \ vertical_region#Map(v:count1, 1, 'n') nnoremap (VerticalRegionDownNormal) - \ VerticalRegion(v:count1, 0, 'n') + \ vertical_region#Map(v:count1, 0, 'n') onoremap (VerticalRegionUpOperator) - \ VerticalRegion(v:count1, 1, 'o') + \ vertical_region#Map(v:count1, 1, 'o') onoremap (VerticalRegionDownOperator) - \ VerticalRegion(v:count1, 0, 'o') + \ vertical_region#Map(v:count1, 0, 'o') xnoremap (VerticalRegionUpVisual) - \ VerticalRegion(v:count1, 1, 'x') + \ vertical_region#Map(v:count1, 1, 'x') xnoremap (VerticalRegionDownVisual) - \ VerticalRegion(v:count1, 0, 'x') + \ vertical_region#Map(v:count1, 0, 'x') -- cgit v1.2.3 From aee7d1f40ee7bdaa3b9f1154329322c9b0305b8c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 10 Aug 2018 01:18:08 +1200 Subject: Spin out vertical_region.vim into submodule --- .gitmodules | 3 +++ vim/autoload/vertical_region.vim | 37 ------------------------------------- vim/bundle/vertical_region | 1 + vim/plugin/vertical_region.vim | 29 ----------------------------- 4 files changed, 4 insertions(+), 66 deletions(-) delete mode 100644 vim/autoload/vertical_region.vim create mode 160000 vim/bundle/vertical_region delete mode 100644 vim/plugin/vertical_region.vim diff --git a/.gitmodules b/.gitmodules index 38a03a11..9f9f3f62 100644 --- a/.gitmodules +++ b/.gitmodules @@ -50,6 +50,9 @@ [submodule "vim/bundle/uncap_ex"] path = vim/bundle/uncap_ex url = https://sanctum.geek.nz/code/vim-uncap-ex.git +[submodule "vim/bundle/vertical_region"] + path = vim/bundle/vertical_region + url = https://sanctum.geek.nz/code/vim-vertical-region.git [submodule "vim/bundle/vimrc_reload_filetype"] path = vim/bundle/vimrc_reload_filetype url = https://sanctum.geek.nz/code/vim-vimrc-reload-filetype.git diff --git a/vim/autoload/vertical_region.vim b/vim/autoload/vertical_region.vim deleted file mode 100644 index 6f2cf8d6..00000000 --- a/vim/autoload/vertical_region.vim +++ /dev/null @@ -1,37 +0,0 @@ -" 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 diff --git a/vim/bundle/vertical_region b/vim/bundle/vertical_region new file mode 160000 index 00000000..59ddae4b --- /dev/null +++ b/vim/bundle/vertical_region @@ -0,0 +1 @@ +Subproject commit 59ddae4b2adb102a37378814cce1a1ddbb72c2b1 diff --git a/vim/plugin/vertical_region.vim b/vim/plugin/vertical_region.vim deleted file mode 100644 index ddf83a53..00000000 --- a/vim/plugin/vertical_region.vim +++ /dev/null @@ -1,29 +0,0 @@ -" -" vertical_region.vim: Move to a line that has non-space characters before or -" in the current column, usually to find lines that begin or end blocks in -" languages where indenting is used to show or specify structure. -" -" Author: Tom Ryder -" License: Same as Vim itself -" -if exists('g:loaded_vertical_region') || &compatible - finish -endif -if v:version < 700 - finish -endif -let g:loaded_vertical_region = 1 - -" Define plugin maps -nnoremap (VerticalRegionUpNormal) - \ vertical_region#Map(v:count1, 1, 'n') -nnoremap (VerticalRegionDownNormal) - \ vertical_region#Map(v:count1, 0, 'n') -onoremap (VerticalRegionUpOperator) - \ vertical_region#Map(v:count1, 1, 'o') -onoremap (VerticalRegionDownOperator) - \ vertical_region#Map(v:count1, 0, 'o') -xnoremap (VerticalRegionUpVisual) - \ vertical_region#Map(v:count1, 1, 'x') -xnoremap (VerticalRegionDownVisual) - \ vertical_region#Map(v:count1, 0, 'x') -- cgit v1.2.3 From 5ae01f759ed8223ffc96989c4cc13ee730a3943e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 10 Aug 2018 01:33:18 +1200 Subject: Update vertical_region.vim with hotfix --- vim/bundle/vertical_region | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/vertical_region b/vim/bundle/vertical_region index 59ddae4b..f7989e2b 160000 --- a/vim/bundle/vertical_region +++ b/vim/bundle/vertical_region @@ -1 +1 @@ -Subproject commit 59ddae4b2adb102a37378814cce1a1ddbb72c2b1 +Subproject commit f7989e2bdd4ed6630cc7318296a6a25f594f1f70 -- cgit v1.2.3 From b12c7bd944b95c96c596a92835b6c3aac49d6d9c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 10 Aug 2018 01:33:49 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 97f3db47..8dcab59d 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v1.51.0 -Wed Aug 8 12:58:23 UTC 2018 +tejr dotfiles v1.52.0 +Thu Aug 9 13:33:49 UTC 2018 -- cgit v1.2.3