Eclipse surround with quotes and other blocks
Go to Java > Editor > Templates and add a new template, e. g. called quote
, as follows:
"${word_selection}"${cursor}
Then, in the editor, write a text you want to quote, select it, press Ctrl+Space, type quote
and hit Return. The highlighted text should be quoted now.
If you don't get template proposals when pressing Ctrl+Space, make sure you have them checked in Java > Editor > Content Assist > Advanced.
Just tried it and it works for me!
Related videos on Youtube
dstarh
88OOOOOZZZZZ$$$$$7777777III????+++++===~~~~~~~~===+++??II7$$ 8OOOOZZ$ZZ$$$$$$777777IIII???I??I+?I~:~~~~~~~~~~~====+??II77 OOZZ$$$$$$$$$77777IIIIIII7?DI$D88ND8I+I=::::::::~~====+??II7 OZ$$$$$$$$$7777IIIIII?I$+ON78D8O888D8O8$:~,,,,::::~~===++?II ZZZZ$$$$$7777IIIIIII?$7Z$DD$??+~~:~++?ZN7?,,,,,,:::~~===++?? ZZZ$$$$77II7IIIIIII??NO8ZO=:::,.......~$NN??,,,,,:::~~==++?? Z$$$$77777IIIII?????I$DZ$~~~~~::,,,,,.,:OZZ$~,,,,,:::~~==++? $$$77I77IIII???????+=?DO7??+=+=~~=====~,=I?7I,..,,,:::~~==++ $$$7777IIII???????+==N88$I?+++=+====++=::+?77....,,,::~~~=++ $$7777IIII??+++?++++?ND87I??+~~~=~::~~~=~?Z$:......,,::~~==+ $7777IIII??????++++=7DN$7I?+=++++=++~,:?+I88~.....,,,::~~==+ 7777IIII?????++++++=$DD7$777OOO$?ZO88O7~?$NDI......,,,::~~== 777IIII?????++++====DDZ7$OZMD8O?+O8OD8ZO$$DN+......,,,::~~== 77IIII?????++++++:.,,,.,,:~:,,,~,$I$77Z$7$8D8......,,,::~~== 7II????????++++=,,,,..,..=IZ7?~.,.=++???~7D8=......,,,::~~== 7III??????++++=~::,.:,,.~::.........+?I7$Z8,.......,,,::~~== 7IIII??????++=:~?7+:,~$Z7Z$ ........+I$ZZ8?........,,,::~~== 7IIII????+=~~==+$ZMOI7ND:..........,7$ZZZ8,.......,,,:::~~== 7IIII???=:::==?Z8ZMM77NMMM$::ZZ77,~+ZZOZOZ,.......,,,:::~~== 7III?I=~:::~=?ZDO8NND8MNND88~,..,IIDZOOO$,,.....,,,,,:::~~== 7II?=~::::~+$888DNNNNND$DNDNMD+?8DD88DD8,,,,.,,,,,,,:::~~=== I+=~::~~~=I$DZ++=~==7D8NDNMNNNNNMNDODNNZ7IZ.,,,,,,,:::~~~==+ ===~~~=+?OO?+=~IZO8DDDDNN8NNNNMMNN8ND88OZI.,,,.,,:::::~~===+ +====+?$8OII++ZO8DDDDDDMNDDNDNMNNNDDDD8Z$7.=~:,,,..,:~~~==++ +=+?I788777IZ88MNDNDNNNMMMMNNNNNNNNDD88Z7?7=+~,::,,:,,:~=++? ??I$ODOOZZO8DNNMNNNNNNNMMMMMMNNNNNNND8O$ONDI:~::~:~==~~~~=?? 7ZONDDNNDDDMMMMMMMMMMMMMMMMMNNMMNNNDOONDNDD==~=~===++==++?+? 8DDDNMMDNMNMMNNNNMMMMMMMMMMNDDNMMMMNNMNMNDO++====++++?+????I DDDNDDMMNMMMNNNNNNMMMMMNMMMNNNMMMMMMNNNNDD$++=+=++I7I777I7II NNNNNMMMMMMMMMNNMMNMMNNNNNNMNNNMMNNNNNNDDDI?++++?+I7$7$ZZ$8Z MMMNMNDNMMMMMMO8MNNNDNDDNDNNNDDDDDDDDDDDDO??+?+?I?I7$$OD8OD8 MMMMDMMNMMNMMNZ$DDDD8N8OZD8DDD8888DD8888D$??????I??$$$OD88DM NMMMMMMMMMNNMND7ZDNDND87IIO88D88OOO888888$IIIIII7III$ZO8DDMN DNMMMMNMMMNNNNOD$$DNO7I$ZDO888D8OOO88888Z7II7I7I77I$Z888NMNM NMMMMMMMMMNNNNO+I$7$7$DO88O8888DDDDDDND88$II$$77$$77Z88N8MNM MMMMOOONMMNNNNN88O88OIZI8O8O888DDNDDO8D8Z$I7$$7$$ZZZ$ODNNMMM MMNO8OOONMNNNNDD88+8O77D888OO88DDNN88DD8ZZZ$Z7$$OOZ8ZZDNMMMM DDDD8888DMNNNDDDDD8DDD888888888DDNDDNN8DO7$ZZ$$$O8ODDO8MMMMM
Updated on October 02, 2020Comments
-
dstarh over 3 years
I find myself wanting to highlight a string in eclipse and double or single quoting it. I can't seem to find a shortcut for it. In textmate for example if i highlight a string and type either a ' or a " the string will be surrounded with them. The same should work with ) and } i think as well.
I've added a code template for doing it but it doesn't ever appear in the menu and there doesn't seem to be a way to create shortcuts for it either. Note that this should be entirely keyboard driven and not involve any secondary menus, that's my goal anyway.
-
Mike about 13 yearsYou could also call it " and that way its even closer to what the OP asked! (ie. ctrl + space then " + enter)
-
janhink about 13 yearsTrue, but now you have to hit Return twice in order for the template to apply. But if you call it "" (two double quotes) it works :)
-
Mike about 13 yearsReally? I tried it with MyEclipse for Spring and I only had to hit Return once for it to apply. Although you do have to be sort of quick, if you wait too long it will just place a quote in place of the string :P
-
dstarh about 13 yearsThis works but doesn't really meet the "secondary menus" part. Ideally I'd like to be able to type ctrl+shift+" (or similar) and that's it
-
janhink about 13 years@Mike Yep, when I select the " from the templates, two quotes are displayed instead of the original text. When I hit Return for the first time, the cursor skips after the second quote and when I hit it for the second time, the quotes get actually replaced by the whole quoted string.
-
dstarh almost 13 yearsI'm going to accept this answer since it's the closest i've seen even though I'm still not thrilled with the solution.
-
gustafbstrom almost 7 yearsAgreeing with @dstarh, this is awfully hackish for commonplace functionality in a modern IDE.
-
dstarh over 6 yearsNearly 7 years later, still missing from a "modern" ide
-
ZhekaKozlov over 3 years@howlger Can we add this feature to Eclipse? It should work out-of-the-box
-
howlger over 3 years@ZhekaKozlov You can suggest feature requests here, best with an implementation as a Gerrit change (I'm not a committer, but most of my proposals and bugs that I reported have been accepted/fixed).