Author Topic: [OK] editing all instances of a word in a block  (Read 27079 times)

Offline tokapi

  • Single posting newcomer
  • *
  • Posts: 4
[OK] editing all instances of a word in a block
« on: December 07, 2011, 01:26:33 am »
Hi everyone.

I'm posting here because I'm looking for a very practical option in codeblocks if it exists and I just cant find it : I am currently writting a very annoying code with long repeated sequences in which only one or two repeated word change each time.

I noticed that when you select a word in codeblocks it highlights in red every instance of this word in the whole code, so I was wondering whether or not it was possible to do the following :

-> selecting a block (I mean a {})
-> selecting one word in this block
-> using the red highliting thing to select at once every instances of this word in the selected block
-> changing at once all these instances for an other word

This would be practical to copy/paste huge pieces of code and I am pretty sure codeblocks can do this but I can't find how.
If you know if it is possible and can tell me I would be thankful. =)

Thanks for your help.
« Last Edit: December 09, 2011, 12:19:55 pm by tokapi »

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: editing all instances of a word in a block
« Reply #1 on: December 07, 2011, 02:19:43 am »
This is not exactly what you are asking about, but the Code Snippets plugin and/or the Abbreviations plugin may help with some of your requests.

Offline tokapi

  • Single posting newcomer
  • *
  • Posts: 4
Re: editing all instances of a word in a block
« Reply #2 on: December 07, 2011, 12:31:36 pm »
Ok thank you I will have a look at these

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2773
Re: editing all instances of a word in a block
« Reply #3 on: December 07, 2011, 01:32:28 pm »
The keymacs plugin may be more helpful.
http://forums.codeblocks.org/index.php/topic,9980.msg70445.html#msg70445

You could mark the area to be modified, then issue a macro that replaced the desired word in the marked area.


Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: editing all instances of a word in a block
« Reply #4 on: December 07, 2011, 02:41:27 pm »
Notepad++ lets you do such cool things, I've wished for Code::Blocks to work as well as that in the past.

You can Ctrl-select several independent locations and start typing, and it will insert into each loaction, replacing the original. You can Alt-select an entire column and start typing, and it will write into each line within the selection... which is totally cool e.g. when you need to manually build a list of strings from #defines in a header.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: editing all instances of a word in a block
« Reply #5 on: December 07, 2011, 02:55:28 pm »
Notepad++ lets you do such cool things, I've wished for Code::Blocks to work as well as that in the past.
It works like hat if you enable the appropriate options.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: editing all instances of a word in a block
« Reply #6 on: December 07, 2011, 03:03:49 pm »
@tokapi: What's wrong with Find and Replace?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: editing all instances of a word in a block
« Reply #7 on: December 07, 2011, 03:06:36 pm »
Notepad++ lets you do such cool things, I've wished for Code::Blocks to work as well as that in the past.
It works like hat if you enable the appropriate options.
Really? Where would I enable that?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: editing all instances of a word in a block
« Reply #8 on: December 07, 2011, 03:15:41 pm »
Really? Where would I enable that?
I can't believe you are asking that, but here you go:
Settings -> Editor -> Margins and Caret -> Selections -> Play with:
- enable virtual space
- allow multiple sections
- enable typing (and deleting) in multiple selections...

Surely you'll need a recent nightly. 10/05 does not have that.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline tokapi

  • Single posting newcomer
  • *
  • Posts: 4
Re: editing all instances of a word in a block
« Reply #9 on: December 07, 2011, 06:39:27 pm »
@tokapi: What's wrong with Find and Replace?
I dont know how to do this  :)

Settings -> Editor -> Margins and Caret -> Selections -> Play with:
- enable virtual space
- allow multiple sections
- enable typing (and deleting) in multiple selections...
This helped me a little, I didnt know this trick either, thank you  :)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: editing all instances of a word in a block
« Reply #10 on: December 07, 2011, 07:09:32 pm »
@tokapi: What's wrong with Find and Replace?
I dont know how to do this  :)

1. Select a block
2. Ctrl + R
3. Type word to find and word to replace in the dialog
4. Click replace (make sure selected text is checked)
5. Click all.

(If you know regular expressions, you can do really powerful stuff with this)

Offline tokapi

  • Single posting newcomer
  • *
  • Posts: 4
Re: editing all instances of a word in a block
« Reply #11 on: December 09, 2011, 12:19:21 pm »
Pretty much exactly what I was looking for, many thanks dmoore.