add a line -- .vimrc instead of plugin

19 views
Skip to first unread message

meine

unread,
Mar 27, 2021, 12:38:30 PM3/27/21
to vim...@googlegroups.com
Hi,

I read about the 'unimpaired.vim' plugin and its nifty feature to add a
blank line below or above the line you're on. Quite often needed when
editing the final layout of your document.

But why with a plugin? As I want to learn Vim the 'less comfortable'
way, I tried some things and made just two lines in my .vimrc that do
just the same. The challenge was to return the cursor to the original
position (line and column) after the new line was made.

" add a line below or above without moving
noremap <Leader>o mpo<Esc>`p
noremap <Leader>O mpO<Esc>`p

'mp' marks the position (just chose p because I don't use that edge of
my keyboard often)

'o' or 'O' adds an empty line below or above

<Esc> gets back to Normal mode

`p gets back to the previous position (mind the backtick!)

Probably no higer Vim skills or rocket science, but I am happy to have
solved this instead of just downloading a plugin. Also learned the
difference between an apostrophe and backtick when going to a mark :-)

//meine

Salman Halim

unread,
Mar 27, 2021, 12:41:52 PM3/27/21
to Vim Users
Regarding the difference between the apostrophe and back tick, I couldn't figure out when I would need the apostrophe version, so I also mapped the apostrophe to the back tick:

map ' `

--

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/YF9fexRFHtyzYvfI%40trackstand.
Reply all
Reply to author
Forward
0 new messages