13 votes

How to generate closing tags for HTML?

Here is a simple ad-hoc solution to put in ~/.vim/after/ftplugin/html.vim: inoremap <buffer> > ></<C-x><C-o><C-y><C-o>%<CR><C-o>O Breakdown: >&...
romainl's user avatar
  • 39.3k
13 votes

How to generate random numbers?

Here is a pure vimscript solution. I did not create it, it was developed by Charles E. Campbell. You can find a Github repo with his code here. The algorithm uses 3 seeds generated at Vim startup and ...
statox's user avatar
  • 49.4k
10 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

You could do this by recording a macro, then using the global ex command to execute the macro n number of times for each line in the file. After recording the macro, undo the changes done while ...
jjaderberg's user avatar
  • 3,439
9 votes
Accepted

How can I create a /* comments section with /// like in XCode?

The method in my earlier answer doesn't transform well to dynamic content. This is where snippet plugins like UltiSnips and SnipMate come in. I'll provide a demo of UltiSnips here. Install it using ...
muru's user avatar
  • 24.7k
8 votes
Accepted

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

Here's a substitution that solves the problem: :%s/\(.*\)1\(.*\)/\=join(map(range(1, 12), 'submatch(1) . v:val . submatch(2)'), "\n") The substitution matches each line that contains "1" and ...
djjcast's user avatar
  • 911
7 votes

How to insert repetitive text with minor difference in vim?

You can use the following function: function! GenerateLines() let firstpart="similar text part 1" let secondpart="similar text part 2" let words=["wordA","wordB","wordC","wordD","wordE"] ...
statox's user avatar
  • 49.4k
7 votes

How to generate random numbers?

You can use the rand() and srand() functions, provided your Vim binary includes the patch 8.1.2342. As an example, to generate 10 random numbers separated by newlines: let seed = srand() echo range(...
user938271's user avatar
  • 5,867
7 votes
Accepted

Create indented comment box vim

Well, "put text into a box" is a well-known Vim excercise. I'm not sure where I saw it for the first time, but the most elegant solution, IMO, is to use :h v_r So it becomes: nnoremap <leader>#...
Matt's user avatar
  • 20.4k
6 votes

How can I create a /* comments section with /// like in XCode?

One way would be to create a file containing this snippet, and read it when you type ///. For example, create ~/.vim/snippets/my_header.snip containing this header. Then define this mapping: ...
muru's user avatar
  • 24.7k
6 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

Two ways: Use a macro! Starting with 1stlineblahblahblah/nt/1blah 2ndlineblahblahblah/nt/1blah 3rdlineblahblahblah/nt/1blah With your cursor on the first line qqyyp$?\d<CR><Ctrl-a>q ...
fruglemonkey's user avatar
  • 1,530
6 votes

Copy text from one buffer to another using Vimscript

You can use appendbufline() like: call appendbufline("other.txt", "$", "Appended Line") or if you want to work with buffer numbers: call appendbufline(3, "$", "Appended Line") See :help ...
Ralf's user avatar
  • 9,097
5 votes

How to generate closing tags for HTML?

See vim-closetag It's exactly what you're looking for. From it's README: If this is the current content: <table| Now you press >, the content will be: <table>|</table> ...
Sheharyar's user avatar
  • 751
5 votes
Accepted

Can I write Japanese (SKK) text in Vim?

OK, this took several days of struggle against the skk.vim plugin mentioned by @SatoKatsura. All the documentation is in Japanese therefore I still do not know of most of its features, and, certainly,...
grochmal's user avatar
  • 1,656
5 votes

How to insert repetitive text with minor difference in vim?

My strategy in such cases will vary, but it often follows the following steps: Write the unique word(s), e.g. wordA wordB ... wordK Either a) do a search and replace, e.g. :%s/\w\+/similar text \...
Karl Yngve Lervåg's user avatar
5 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

I find it easiest to use macros for one-shot tasks like that. Just start recording a macro with q + name of register and do the task once. I see one repeatable task here: Select the line yank paste (...
kba's user avatar
  • 249
4 votes

How can I generate a list of sequential numbers, one per line?

I know this question is really old, but there's another way you can do it also. Try this: 99o<esc>:%s/^/\=line('.')<cr> 99o<esc> will just open up 100 blank lines. Then, we run a ...
DJMcMayhem's user avatar
  • 17.4k
4 votes

Can I write Japanese (SKK) text in Vim?

Since I was in search for a good way to input unicode Japanese characters in VIM, this post was really helpful. I tried using skk.vim but found it really difficult, because contrary to the OP, I ...
aignas's user avatar
  • 141
4 votes

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

To use a purely vimscript solution you can use some functions I described in another answer of mine: " Randomization Variables " with a little extra randomized start from localtime() let g:rndm_m1 = ...
statox's user avatar
  • 49.4k
4 votes
Accepted

Insert character until column number

Well, doing this in vimscript is not that hard. For example, the following command will do what you describe to the line your cursor is on: :exec 'norm '.(&cc - strlen(getline('.'))).'A=' The ...
DJMcMayhem's user avatar
  • 17.4k
4 votes

In Vim ex mode how to re-use a string from the default buffer in the command

Using ex Ex is the command-line successor to the venerable ed, a line-oriented editor. You can access ex-mode from vim by typing Q (unless you have it mapped). gQ gives an improved ex-mode. See :help ...
D. Ben Knoble's user avatar
  • 25.4k
3 votes
Accepted

How to copy each line 19 times, incrementing two different numbers by 180?

You can record a macro, carry out your instructions, close the macro, then run it. In your case you may start with the cursor at the beginning of the line to copy. Press qa to start recording macro '...
asoundmove's user avatar
3 votes

Add line at the end of text

Here is a different version. Call Vim from the directory with all files: vim *.txt Now you can do :bufdo call append('$', 'abc') | upd, which will run through your buffer list and add a single line '...
Christian Brabandt's user avatar
3 votes

Add line at the end of text

I would probably use the argument-list for this. First you have to add all files to the argument list and then you can use argdo to operate on all of them. So first let's populate the argument list. ...
Tumbler41's user avatar
  • 7,706
3 votes

How can I create a /* comments section with /// like in XCode?

Write a function that returns the string and call it. function! InsertHeader() let l:header = "/*!\n" \. "* @author Robbie Yi JIANG, " . strftime('%d-%b-%Y %H:%M:%S') . "\n" ...
dash-tom-bang's user avatar
3 votes

Can I write Japanese (SKK) text in Vim?

I'm trying to summarize here the experience of the other two users, while trying to keep it simple. Some issues were resolved (e.g. eskk now supports nvim). Also, I'm using pathogen which somewhat ...
x-yuri's user avatar
  • 349
3 votes

In Vim ex mode how to re-use a string from the default buffer in the command

ex -s +'norm! gg"adiwdd' +'exec printf("%%s/^/%s : /", @a)' +'x' ex_txt norm! gg"adiwdd delete black in 1st line to register a, delete first line exec printf("%%s/^/%s : /", @a) add content of ...
dedowsdi's user avatar
  • 6,188
3 votes
Accepted

In Vim ex mode how to re-use a string from the default buffer in the command

@D.BenKnoble has already given you a terrific answer explaining all the ins and outs of batch mode, but in case you were looking for a one liner similar to the one you already tried, here's one that I ...
Rich's user avatar
  • 31.3k
2 votes

How to insert repetitive text with minor difference in vim?

I'll argue that this is a job for the visual block (Ctrl+v). First I would write all distinct words: wordA wordB wordC wordD wordE Starting with the cursor on the first w I would then perform: <...
grochmal's user avatar
  • 1,656
2 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

Save the following macro and use it for each line: qqyy11p/\/\zs1<CR><C-v>10jg<C-a>q The main difference over the other answers is that this makes use of g<C-a> on a column ...
Vitor's user avatar
  • 1,742
2 votes

How to generate random numbers?

Vim v8.1.2342 add rand and srand function. I prefer this way to generate 20 random numbers in range 0-100 in current buffer: :put =rand()%100 20@:
Francis Niu's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible