Vim ways of adding a character to the end of the line

Ok, so in these annoying little languages that require a ; at the end of the line or they piss and cry, how can I add that easily? I mean in situation when I finish writing my code and the cursor isn't at the end of the line, like when you have a function or a string that pair () "" is added automatically so your cursor ends up before those characters like in the picture, how do I add the ; at the end of the line in the easiest way?
35 Replies
ErickO
ErickOOP2y ago
using the arrow keys is annoying and not really the vim way of doing things, but going into normal mode like <esc>$a; is so much work, maybe there's some hidden command I don't know about? ok nvm I remembered there's uppercase letters too and uh... <esc>A;does the job without using $, is that the shortest method?
Jochem
Jochem2y ago
that's what I was going to suggest, but you could look for a plugin. I got one for when I use vscode so that alt+; adds a semicolon at the end of the line regardless of where I am.
Joao
Joao2y ago
I have this shortcut added that does that, as well as for commas, useful when editing objects/lists/dicts
vim.keymap.set('i', ';;', '<Esc>A;')
vim.keymap.set('i', ',,', '<Esc>A,')
vim.keymap.set('i', ';;', '<Esc>A;')
vim.keymap.set('i', ',,', '<Esc>A,')
Just tap ; twice while in insert mode and it will append it to the end of the line.
Jochem
Jochem2y ago
I am definitely stealing that one
Joao
Joao2y ago
Full credit goes to Jess Archer: https://github.com/jessarcher/dotfiles
GitHub
GitHub - jessarcher/dotfiles: $HOME sweet $HOME
$HOME sweet $HOME. Contribute to jessarcher/dotfiles development by creating an account on GitHub.
Jochem
Jochem2y ago
in case anyone needs this in vimscript instead of lua:
inoremap ;; <Esc>A;
inoremap ,, <Esc>A,
inoremap ;; <Esc>A;
inoremap ,, <Esc>A,
also, wow, Discord has highlighting for vim
Joao
Joao2y ago
I think it uses highlight.js for syntax highlighting
ErickO
ErickOOP2y ago
Brilliant
-- When text is wrapped, move by terminal rows, not lines, unless a count is provided
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true })
-- When text is wrapped, move by terminal rows, not lines, unless a count is provided
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true })
5Head remaps
b1mind
b1mind2y ago
I personally use a n map and use leader ; , Something about the delay in insert bugs me for stuff like this. Same with jk escapes I also used ; to exit insert for a long time, recently been trying to kick the habit 😂
ErickO
ErickOOP2y ago
delay? I didn't feel any you used ; to EXIT insert mode? what in the JS developer is wrong with you
b1mind
b1mind2y ago
Yea I mean I always just hit ; leader ; if I need one or if it needs to be at the end of a word ; leader leader ; I am trying to break away from using ; to exit insert though cause it screws with me if I'm without my binds xD its really nice though >.>;; I think you can set the time to accept next combo it but there is forget how it screwed with me but it did xD
ErickO
ErickOOP2y ago
idk what my timing is but the whole thing happens pretty fast, even if I try to immediately do something else it works fine so we good 😎
Jochem
Jochem2y ago
the way it works for me, is that there's a delay before inserting the first ; if you don't press the second, but if you tap it twice it immediately inserts the semicolon at the end as soon as you press it
ErickO
ErickOOP2y ago
oooh didn't try that but yeah I'll just be pressing it immediately since I know when I want it to happen unless my brain shuts down
b1mind
b1mind2y ago
what if you just need one after a word then you have to pause for it to insert esc leader ; ❤️ stays in normal mode and i just roll tide
ErickO
ErickOOP2y ago
then I have to esc ResidentSleeper
Jochem
Jochem2y ago
typing hello ; world produces exactly that, even if you don't wait
ErickO
ErickOOP2y ago
yeah just tried it, I can see the delay, it's small but it is there
b1mind
b1mind2y ago
how often are you just in insert after ending a line though?
Jochem
Jochem2y ago
; isn't a shortcut, so it defaults to just entering both characters
ErickO
ErickOOP2y ago
it does keep writing as you would expect it to tho
b1mind
b1mind2y ago
oh that's true good point
ErickO
ErickOOP2y ago
I mean, every line needs a ; in Rust so... I gotta add it but I need to keep writing
Jochem
Jochem2y ago
the delay is visible until you press space, there's no actual difference in entering characters or timing on your part
b1mind
b1mind2y ago
I think my issue was more with jj jk bindings I never could get used to them for esc ah I just use o xD like same amount of keypress if I was in insert still and hitting enter 🤷‍♂️
Jochem
Jochem2y ago
as for how often? often enough that I installed plugins for it in vscode so that I don't have to do [end]; and can just do alt+; or alt+shift+; for "semicolon at the end, new line"
b1mind
b1mind2y ago
this is what I love about keybinds hah everyone has a personal preference, its neat to see how others do things
Jochem
Jochem2y ago
in languages where they're required, and if you're used to it in javascript too, there's a lot of times where your (I|P)DE will autocomplete the closing brackets and quotes, and you have to add stuff to the end. When I'm writing PHP, it's at least every other line I'd use something like this
ErickO
ErickOOP2y ago
I'm experimenting cause I forget what I normally do lol, right now the keybind is ;; <Esc>A;<Esc> so I do end up in normal mode this was my issue yes I didn't think about just adding a bind for it in insert mode good thing Jao shared that link
Jochem
Jochem2y ago
I didn't even really consciously know that was an option I might add some more, there's a bunch of commands that I'd love to shorten ci" or ci( might be nice to just have as cc
b1mind
b1mind2y ago
dangerous though cause you get in those habits you only have them in your env xD I do shift+hjkl for word movement and it always screws me with J hah start merging lines cib and ciB do b=() and B={} too if you didn't know, probably easier to type for most.
ErickO
ErickOOP2y ago
I'm fine with just ;; because it's a character that doesn't happen besides the end of a line, I'm not really writing them all over the place (except the occasional for loop) but if I start adding more letters I would notice that delay and it would bother me even if I can just keep typing normally this is what a dotfiles repo is for 5Head
b1mind
b1mind2y ago
sure I do that for ssh too but I'm talking all over codepen i.e.
Jochem
Jochem2y ago
ah, I forget you can set that to use vim keybinds too
ErickO
ErickOOP2y ago
codepen? TIL not that I use it anyway PepeLaugh with vim keybinds pretty good tho 👍
Want results from more Discord servers?
Add your server