txt.wrap - wrap selected text in %symbols%

Post your working scripts, libraries and tools
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

txt.wrap - wrap selected text in %symbols%

05 Dec 2016, 08:10

wrap selected text in %symbols% using a two stage hotkey

alt + w then " ...will wrap selected text like this: "quotes"
alt + w then % ...will wrap selected text like: %parenthesis% and so on

you can add your own custom text to the ini section at the top of the file. the format is:

Code: Select all

key character = left-wrap TXT right-wrap



check out the readme for more about the settings and some wrap examples



related scripts:
txt.swap - interactively swap text at a certain character or word
txt.replace - interactively replace a character with another
Last edited by davebrny on 26 Jun 2019, 04:38, edited 1 time in total.
guest3456
Posts: 2556
Joined: 09 Oct 2013, 10:31

Re: text wrap

05 Dec 2016, 10:32

for any programmer, these hotkeys are essential.

luckily for me, my text editor (Vim) lets me do this with a simple plugin:
https://github.com/tpope/vim-surround

vimscript code is pretty rough to understand. but you might look there for some inspiration. it has other features that you may want to implement, such as delete wrapping and change/swap:

Code: Select all

Details follow on the exact semantics, but first, consider the following
examples.  An asterisk (*) is used to denote the cursor position.

  Old text                  Command     New text ~
  "Hello *world!"           ds"         Hello world!
  [123+4*56]/2              cs])        (123+456)/2
  "Look ma, I'm *HTML!"     cs"<q>      <q>Look ma, I'm HTML!</q>
  if *x>3 {                 ysW(        if ( x>3 ) {
  my $str = *whee!;         vllllS'     my $str = 'whee!';
so for example, Vim lets me just type in which surrounder i want to use. when my cursor is inside a word, i just type ysiw% and my word is wrapped in %%s. perhaps you could use AHKs Input command to do something similar, that way you dont have to rely on memory. like, have a global hotkey alt+2 and then press the char you want to wrap with. so something like Alt+2 followed by "

good job

User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

Re: text wrap

06 Dec 2016, 16:08

sublime text does a good few of these as well, which i mostly use when programming since it doesnt need to use the clipboard. i mostly use these hotkeys when editing text elsewhere, or when using markdown online or using the quotes to narrow down searches or whatever.
guest3456 wrote:perhaps you could use AHKs Input command to do something similar
thats a great idea. less hotkeys to remember and you dont have to set up the characters before hand

guest3456 wrote:vimscript code is pretty rough to understand
its a bit hard on the eyes at first but it started to make sense after i read it a few times :D
thats a really cool ability to have though. dam maybe ill take a look at vim after all. ... someday haha
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

Re: txt.wrap - wrap selected text in %symbols%

26 Jun 2019, 05:07

i wrote this again from "the ground up", or whatever the current buzzword is this week. it now uses a 2 stage hotkey (credit to @guest3456 for that idea!) so there is less setup needed before hand... just press alt + w and then the character you want wrapped

if you want different characters on either side then they can be added to the ini section at the top of the file

gist: txt.wrap.ahk

(i didnt add the hotstring feature this time around as i didnt use it that much in the end, but the original script can still be found here if anyone is still interested in that part)
User avatar
jeeswg
Posts: 6649
Joined: 19 Dec 2016, 01:58
Location: UK

Re: txt.wrap - wrap selected text in %symbols%

27 Jun 2019, 04:00

This is interesting, here is a list of hotkeys that I use for various text wrapping/unwrapping. I press the hotkey to toggle:

Code: Select all

^#2:: ;enclose in characters "" [MAIN]
^+2:: ;enclose in characters ""
^#':: ;enclose in characters ""
^+':: ;enclose in characters ""
^4:: ;enclose in characters $$ (for LaTeX)
^5:: ;enclose in characters %% (for AutoHotkey)
^8:: ;enclose in characters ** (for emphasis/search wildcards)
^9:: ;enclose in characters () [MAIN]
^0:: ;enclose in characters () [MAIN]
^[:: ;enclose in characters {} [MAIN]
^]:: ;enclose in characters {} [MAIN]
^+[:: ;enclose in characters [] 
^+]:: ;enclose in characters []
#[:: ;enclose in characters []
#]:: ;enclose in characters []
^#[:: ;enclose in characters [] [MAIN]
^#]:: ;enclose in characters [] [MAIN]
^':: ;enclose in characters ''
#k:: ;enclose in characters <kbd></kbd> (for Stack Overflow)

;I use an InputBox menu/hotstrings for:
;[url]text[/url] ;BBCode
;<!-- text --> ;html
;[quote]text[/quote] ;BBCode
;[c]text[/c] ;BBCode
;[code]text[ /code] ;BBCode [space added to '/code' to display this properly on the forum]
;std::cout << text << std::endl; ;C++
;;text ;comments [prepend characters e.g. semicolons]

;I don't currently do anything for:
;<text>
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], DataLife, robodesign and 36 guests