> For the complete documentation index, see [llms.txt](https://dofy.gitbook.io/learn-vim/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dofy.gitbook.io/learn-vim/en/chapter06.md).

# Chapter 6: Block Operations

We often come across a situation where we have a multi-line text somewhere and we want to copy it into our code to initialize an array of array. Most of the time we do this:

* Write the array declaration;
* copy the contents into parentheses (roughly the length of the text below)
* Then add `'` at the beginning of the line, `',` at the end of the line, and repeat until the last line (imagine 50 lines of text).

> With Vim, you don't have to do this, just press `17gg` and follow the instructions for the selected line.

```javascript
const myArray = [
Ctrl-v to enter block operation, $ to the end of the line, j to the next line (do it!).
Press j to the next line
There are many lines below, so let's jump a few more lines with 4j
https://www.yahaha.net
https://www.yahaha.net
Look at the line number later and jump! Now press A to insert, then enter <single quote><comma><Esc> to complete the first step.
// Oops... Jump too much, no problem, press k to go back to the previous line
];
```

> Now that you've completed the first step, you still need to add the leading `'`, press `17gg` to go back to that line and do it again, but this time there are three things to change:
>
> 1. press `0` instead of `$` on the first line, because this time you want to insert at the beginning of the line;
> 2. when pressing `A` at the end of the last line, press `I` instead, because in block operations `A` inserts after the character and `I` inserts before the character;
> 3. press `<single quote><Esc>` at the end.
>
> Finally, to finish up, `22gg$x` deletes `,` at the end of the last line, and then `17gg7==` indents the code a bit.
>
> Done!

*Note: Selecting the beginning and end of a line can also be done after selecting what to work with, i.e. `Ctrl-v jjj$A',<Esc>`*

Next we talk about [macros in Vim](/learn-vim/en/chapter07.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dofy.gitbook.io/learn-vim/en/chapter06.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
