| 1 | # Multi-Cursor Test: Ctrl+D Select Next Match |
| 2 | # ============================================= |
| 3 | # |
| 4 | # Instructions: |
| 5 | # 1. Place cursor on any word (e.g., "value" below) |
| 6 | # 2. Press Ctrl+D to select that word |
| 7 | # 3. Press Ctrl+D again to select the next occurrence and add a cursor |
| 8 | # 4. Keep pressing Ctrl+D to select all occurrences |
| 9 | # 5. Now type to replace all selected occurrences at once! |
| 10 | # 6. Press Escape to collapse back to a single cursor |
| 11 | # |
| 12 | # Other multi-cursor shortcuts: |
| 13 | # - Ctrl+Alt+Up: Add cursor above |
| 14 | # - Ctrl+Alt+Down: Add cursor below |
| 15 | # - Ctrl+Click: Add/remove cursor at click position |
| 16 | # - Escape: Collapse to single cursor |
| 17 | # |
| 18 | # Test Area - Try selecting "value" with repeated Ctrl+D: |
| 19 | |
| 20 | value = 10 |
| 21 | another_value = value * 2 |
| 22 | third_value = value + another_value |
| 23 | print(f"The value is {value}") |
| 24 | |
| 25 | def process_value(value): |
| 26 | """Process the value and return a new value.""" |
| 27 | return value * value |
| 28 | |
| 29 | result = process_value(value) |
| 30 | final_value = result + value |
| 31 | |
| 32 | |
| 33 | # Test with "item" - has many occurrences: |
| 34 | |
| 35 | items = ["apple", "banana", "cherry"] |
| 36 | |
| 37 | for item in items: |
| 38 | print(item) |
| 39 | process_item(item) |
| 40 | if item == "banana": |
| 41 | special_item = item |
| 42 | |
| 43 | def process_item(item): |
| 44 | """Process a single item.""" |
| 45 | return item.upper() |
| 46 | |
| 47 | first_item = items[0] |
| 48 | last_item = items[-1] |
| 49 | |
| 50 | |
| 51 | # Test with "count" - various contexts: |
| 52 | |
| 53 | count = 0 |
| 54 | max_count = 100 |
| 55 | |
| 56 | while count < max_count: |
| 57 | count += 1 |
| 58 | if count % 10 == 0: |
| 59 | print(f"count = {count}") |
| 60 | |
| 61 | final_count = count |
| 62 | print(f"Final count: {final_count}") |
| 63 | |
| 64 | |
| 65 | # Test with "data" - in a class: |
| 66 | |
| 67 | class DataProcessor: |
| 68 | def __init__(self, data): |
| 69 | self.data = data |
| 70 | self.processed_data = None |
| 71 | |
| 72 | def process(self): |
| 73 | self.processed_data = self.transform_data(self.data) |
| 74 | return self.processed_data |
| 75 | |
| 76 | def transform_data(self, data): |
| 77 | return [x * 2 for x in data] |
| 78 | |
| 79 | def get_data(self): |
| 80 | return self.data |
| 81 | |
| 82 | processor = DataProcessor([1, 2, 3]) |
| 83 | data = processor.get_data() |
| 84 | new_data = processor.process() |
| 85 | |
| 86 | |
| 87 | # Test with "name" - strings and variables: |
| 88 | |
| 89 | name = "Alice" |
| 90 | user_name = name |
| 91 | full_name = f"{name} Smith" |
| 92 | |
| 93 | def greet_by_name(name): |
| 94 | print(f"Hello, {name}!") |
| 95 | return f"Greeted {name}" |
| 96 | |
| 97 | greet_by_name(name) |
| 98 | greet_by_name("Bob") # Different name |
| 99 | |
| 100 | names = [name, "Bob", "Charlie"] |
| 101 | for n in names: |
| 102 | print(f"Name: {n}") |
| 103 | |
| 104 | |
| 105 | # Test edge cases: |
| 106 | |
| 107 | # Same word at start and end of line |
| 108 | test test test test test |
| 109 | |
| 110 | # Word appears in comments too |
| 111 | # The word appears here and in code: word = "word" |
| 112 | word = "word" |
| 113 | print(word) # prints the word |
| 114 | |
| 115 | |
| 116 | # Numbers and underscores in identifiers: |
| 117 | var_1 = 100 |
| 118 | var_2 = var_1 + var_1 |
| 119 | var_3 = var_1 * 2 |
| 120 | |
| 121 | my_var_1 = var_1 |