Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version 1.22: - Add TextTransform/Selections.vim.

  • Loading branch information...
commit 46902dd5efb0c98f6802653d52ac97aab106d71c 1 parent 30df295
authored March 06, 2014 vim-scripts committed March 08, 2014
40  autoload/TextTransform/Selections.vim
... ...
@@ -0,0 +1,40 @@
  1
+" TextTransform/Selections.vim: General-purpose text selections.
  2
+"
  3
+" DEPENDENCIES:
  4
+"
  5
+" Copyright: (C) 2011-2014 Ingo Karkat
  6
+"   The VIM LICENSE applies to this script; see ':help copyright'.
  7
+"
  8
+" Maintainer:	Ingo Karkat <ingo@karkat.de>
  9
+"
  10
+" REVISION	DATE		REMARKS
  11
+"   1.22.002	06-Mar-2014	Add to TextTransform plugin.
  12
+"	001	08-Mar-2011	file creation
  13
+
  14
+function! TextTransform#Selections#SurroundedByCharsInSingleLine( chars )
  15
+    " Cursor must be inside (not on!) one of the characters in a:chars.
  16
+    let l:surroundPattern = '^.*\zs\([' . a:chars . ']\)\%(\1\@!.\)\{-}\%#\%(\1\@!.\)\{1,}\1\ze.*$'
  17
+
  18
+    let l:save_cursor = getpos('.')
  19
+    if search(l:surroundPattern, 'b', line('.'))	" Beginning of surrounded text.
  20
+	" Start characterwise visual mode _inside_ the surrounds.
  21
+	normal! lv
  22
+	if search(l:surroundPattern, 'e', line('.')) " End of surrounded text.
  23
+	    " Note: Need to leave visual mode to enable 'gv' to re-select the
  24
+	    " current selection.
  25
+	    execute 'normal! ' . (&selection ==# 'exclusive' ? '' : 'h') . "\<Esc>"
  26
+	    return 1
  27
+	else
  28
+	    " Undo visual mode and backwards search.
  29
+	    execute "normal! \<Esc>"
  30
+	    call setpos('.', l:save_cursor)
  31
+	endif
  32
+    endif
  33
+    return 0
  34
+endfunction
  35
+
  36
+function! TextTransform#Selections#QuotedInSingleLine()
  37
+    return TextTransform#Selections#SurroundedByCharsInSingleLine('''"')
  38
+endfunction
  39
+
  40
+" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
3  doc/TextTransform.txt
@@ -255,6 +255,9 @@ IDEAS							 *TextTransform-ideas*
255 255
 ==============================================================================
256 256
 HISTORY						       *TextTransform-history*
257 257
 
  258
+1.22	06-Mar-2014
  259
+- Add TextTransform/Selections.vim.
  260
+
258 261
 1.21	15-Jan-2014
259 262
 - Minor: Use functions for newer ingo-library.
260 263
 - Need to use ingo#compat#setpos() to restore the selection in Vim versions

0 notes on commit 46902dd

Please sign in to comment.
Something went wrong with that request. Please try again.