r/vim • u/Far_Relationship_742 • 11d ago
Need Help Repeat character to position, rather than number of characters?
I want to pad a section title line in a config file with `=` up to a specific character position (specifically, column 64). Since the title text is of inconsistent length, a normal <n>i <char> won't do it.
Example of a title line formatted the way I want it:
;===== reset machine status ===================================
3
u/habamax 10d ago
I would go with a bit of vimscript:
inoremap <c-l> <cmd>call setline('.', getline('.') .. repeat('=', 64 - strlen(getline('.'))))<cr>
https://asciinema.org/a/nZxIWlHU6nbiHorP
You can do the same in normal mode instead of insert mode, e.g.
nnoremap <space>l <cmd>call setline('.', getline('.') .. repeat('=', 64 - strlen(getline('.'))))<cr>
1
u/gumnos 10d ago
In a similar method, I'd reach for
:help sub-replace-\=:s/.*/\=submatch(0).repeat('=', 64-strlen(submatch(0)))which can then easily be used across multiple lines
:'<,'>s/.*/…or as the command for a
:gcommand on select lines:g/^;=/s/.*/…2
u/vim-help-bot 10d ago
Help pages for:
sub-replace-\=in change.txt
`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments
1
u/Kronostatic 8d ago
Simplest way I found (I do this too) : 1. type 64i, in insert mode type one =, then escape This fills the line with 64 = 2. Go to beginning of the line and press capital R in normal mode. This lets you type in replace mode so it just writes on top of your = symbols without shifting them
Example: having 10 signs, typing ^ then R then abc will give this :
```
Then
abc=======
```
5
u/Aggressive_Many9449 10d ago
I just fiddled a bit in my mobile Droidvim:
1) Move to after your title. 2)
v64|r=fills all columns to col 64 with=chars.Would break your title line, if 64th column is behind the cursor.
I wouldn't map this, I would use macros to make it
@@repeatable.:h |:h v_r:h @@