Questions tagged [text-generation]

Automatically generating text with Vim, using patterns like incrementing numbers, etc.

Vim supports automatically generating text following a pattern, via macros, motions and functions. For example, the following generates a sequence of numbers from 1 to 10:

i1<esc>qqYp<c-a>q8@q

Breaking down:

  • i1<esc> write 1 and back to normal mode
  • qq start recording a macro in the register q
  • Yp yank the line and paste it below
  • <c-a> increment it
  • q stop recording the macro
  • 8@q repeat the macro in the register q 8 times.

Other facilities for automation include using functions in the replacement of a :substitute command, looping over text, etc.

32 questions
31
votes
8 answers

How to generate random numbers?

I would like to generate one or few random numbers separated by new line. How this can be done?
kenorb
  • 18,433
  • 18
  • 72
  • 134
27
votes
8 answers

How to add permanent line numbers to a file?

I have a text file like this (using gVim on Windows) foo bar baz quux corge grault garply waldo fred plugh [...150 more lines...] xyzzy thud I want to add a number to each line in the file. Not using :set number, but to add the number as text…
roblogic
  • 707
  • 1
  • 7
  • 15
6
votes
2 answers

How do I automatically add a character at end of line?

I am very new to vim and would like to know if I could have a script in my vimrc file that automatically adds a ; to the end of every line. The only exceptions is if the line has the strings for(, while(, #include, //, /*, */ etc. I would like this…
iProgram
  • 1,589
  • 2
  • 15
  • 25
4
votes
2 answers

How to add a uid to html nodes?

I have a giant html file which is a mess (not my fault). I want to add to some nodes (about 400) a unique id. They all have are of the same class, so I can add the id like this :% s/class="some-class"/& id=/ My problem is generating the id…
elyashiv
  • 2,429
  • 2
  • 18
  • 23
3
votes
3 answers

Command to create \begin{} \end{} environment in LaTeX

How can I make a command that allows me to insert LaTeX environments in the current text? The idea is to press Ctrl+E or type :texenv and then enter the environment name in the bottom line, e.g. :texenv itemize. Which would then insert…
bitmask
  • 143
  • 8
2
votes
3 answers

How to write 1 or 0(binary string) randomly in a file using vim?

I want a file that contain only 1 and 0 for my java networking program. Writing a big file containing only 1 and 0 is boring. So, if vim do this, it is better. I don't know that it is whether possible or not, but I guess it is possible in vim.
alhelal
  • 659
  • 4
  • 10
  • 17
1
vote
1 answer

Plugin to ignore quote when it's already there?

Please forgive me as I'm sure this has been asked before, but my Google fu has really failed me here as I'm not sure what this feature is called. Given text like this: "Hello ~" with the cursor where the ~ is, is there a plugin that will ignore an…
Mahmoud Al-Qudsi
  • 296
  • 1
  • 10
0
votes
1 answer

Increment the number at the end of variable

In my C code I am dealing with many variables of type RxMsgType0 RxMsgType1 RxMsgType2 RxMsgType3 ... My Question: Is there a way in VIM by which I can create 4 more variables which follow the same format? Expected output: [Type Some…
HarshaD
  • 111
  • 2