News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

[OK] editing all instances of a word in a block

Started by tokapi, December 07, 2011, 01:26:33 AM

Previous topic - Next topic

tokapi

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.

Alpha

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.

tokapi


Pecan

The keymacs plugin may be more helpful.
http://forums.next.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.


thomas

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."

MortenMacFly

Quote from: thomas 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.
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

dmoore

@tokapi: What's wrong with Find and Replace?
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

thomas

Quote from: MortenMacFly on December 07, 2011, 02:55:28 PM
Quote from: thomas 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.
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."

MortenMacFly

Quote from: thomas on December 07, 2011, 03:06:36 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

tokapi

Quote from: dmoore on December 07, 2011, 03:03:49 PM
@tokapi: What's wrong with Find and Replace?
I dont know how to do this  :)

Quote from: MortenMacFly on December 07, 2011, 03:15:41 PM
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  :)

dmoore

Quote from: tokapi on December 07, 2011, 06:39:27 PM
Quote from: dmoore on December 07, 2011, 03:03:49 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)
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

tokapi

Pretty much exactly what I was looking for, many thanks dmoore.