aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-08-10 01:14:57 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-08-10 01:14:57 +1200
commit59ddae4b2adb102a37378814cce1a1ddbb72c2b1 (patch)
tree082141ba77bfa9c4f4fe99a0fd25be716a69bd2e
downloadvim-vertical-region-59ddae4b2adb102a37378814cce1a1ddbb72c2b1.tar.gz
vim-vertical-region-59ddae4b2adb102a37378814cce1a1ddbb72c2b1.zip
First versionv0.1.0
-rw-r--r--README.md15
-rw-r--r--VERSION1
-rw-r--r--autoload/vertical_region.vim37
-rw-r--r--doc/vertical_region.txt71
-rw-r--r--plugin/vertical_region.vim30
5 files changed, 154 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..855a464
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+vertical\_region.vim
+====================
+
+This plugin provides mapping targets to move up or down to lines that have
+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.
+
+License
+-------
+
+Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself.
+See `:help license`.
+
+[1]: https://sanctum.geek.nz/
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
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
diff --git a/doc/vertical_region.txt b/doc/vertical_region.txt
new file mode 100644
index 0000000..cc07b5d
--- /dev/null
+++ b/doc/vertical_region.txt
@@ -0,0 +1,71 @@
+*vertical_region.txt* For Vim version 7.0 Last change: 2018 Aug 10
+
+DESCRIPTION *vertical_region*
+
+This plugin provides mapping targets to move up or down to lines that have
+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.
+
+REQUIREMENTS *vertical_region-requirements*
+
+This plugin only loads if 'compatible' is not set.
+
+MAPPINGS *vertical_region-mappings*
+
+Six mappings are provided:
+
+ *<Plug>(VerticalRegionUpNormal)*
+`<Plug>(VerticalRegionUpNormal)` moves up to the previous line with non-space
+characters before or in the current column, in normal mode.
+
+ *<Plug>(VerticalRegionDownNormal)*
+`<Plug>(VerticalRegionDownNormal)` moves down to the next line with non-space
+characters before or in the current column, in normal mode.
+
+ *<Plug>(VerticalRegionUpOperator)*
+`<Plug>(VerticalRegionUpOperator)` moves up to the previous line with
+non-space characters before or in the current column, in visual mode.
+
+ *<Plug>(VerticalRegionDownOperator)*
+`<Plug>(VerticalRegionDownOperator)` moves down to the next line with
+non-space characters before or in the current column, in operating-pending
+mode.
+
+ *<Plug>(VerticalRegionUpVisual)*
+`<Plug>(VerticalRegionUpVisual)` moves up to the previous line with non-space
+characters before or in the current column, in visual mode.
+
+ *<Plug>(VerticalRegionDownVisual)*
+`<Plug>(VerticalRegionDownVisual)` moves down to the next line with non-space
+characters before or in the current column, in visual mode.
+
+All of them accept a [count] prefix to move by more than one matching line.
+
+There are no default key mappings; you should define those yourself in your
+|vimrc|. Here are the author's choices, using \{ and \} in all three modes:
+>
+ nmap <Bslash>{ <Plug>(VerticalRegionUpNormal)
+ nmap <Bslash>} <Plug>(VerticalRegionDownNormal)
+ omap <Bslash>{ <Plug>(VerticalRegionUpOperator)
+ omap <Bslash>} <Plug>(VerticalRegionDownOperator)
+ xmap <Bslash>{ <Plug>(VerticalRegionUpVisual)
+ xmap <Bslash>} <Plug>(VerticalRegionDownVisual)
+<
+AUTHOR *vertical_region-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+CREDITS *vertical_region-credits*
+
+Thanks to Antony in Freenode #vim for providing a working implementation of a
+very similar approach for reference, and informing the choice of plugin name.
+
+Antony has a funny habit of always already having written some form of what
+you're currently writing in Vimscript.
+
+LICENSE *vertical_region-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl:
diff --git a/plugin/vertical_region.vim b/plugin/vertical_region.vim
new file mode 100644
index 0000000..43b30b8
--- /dev/null
+++ b/plugin/vertical_region.vim
@@ -0,0 +1,30 @@
+"
+" vertical_region.vim: Mapping targets to move up or down to lines that have
+" 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 <tom@sanctum.geek.nz>
+" 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 <expr> <Plug>(VerticalRegionUpNormal)
+ \ vertical_region#Map(v:count1, 1, 'n')
+nnoremap <expr> <Plug>(VerticalRegionDownNormal)
+ \ vertical_region#Map(v:count1, 0, 'n')
+onoremap <expr> <Plug>(VerticalRegionUpOperator)
+ \ vertical_region#Map(v:count1, 1, 'o')
+onoremap <expr> <Plug>(VerticalRegionDownOperator)
+ \ vertical_region#Map(v:count1, 0, 'o')
+xnoremap <expr> <Plug>(VerticalRegionUpVisual)
+ \ vertical_region#Map(v:count1, 1, 'x')
+xnoremap <expr> <Plug>(VerticalRegionDownVisual)
+ \ vertical_region#Map(v:count1, 0, 'x')