I would like to auto-indent text blocks that I have just put
. At a minimum, I would like to retab
the new block of text, since otherwise I sometimes end up with tabs in files that shouldn't have tabs when I copy them from files that do have tabs without noticing.
This is my current solution, but I'm certianly open to better ones:
nnoremap p pV`]=
nnoremap P PV`]=
This makes use of the ]
built-in mark, which is the "last character of the previously changed or yanked text" (from :help marks
).
I'd prefer not to remap primitive fundamental keys such as p
, and this won't work with other methods of pasting (e.g. the middle-click in X11). Also, I haven't used this for very long so I'm not sure yet if there are any behavioral oddities.
-
3
-
@romainl I didn't know about that, but that does indeed seem to do what I want. – Kyle Strand May 28 '15 at 21:09
-
1@romainl Actually, that appears to remove leading spaces when pasting below a blank line, which is not necessarily what I want. – Kyle Strand May 28 '15 at 21:52
-
Which is why there are both a
[p
(which is probably better written as]P
) and a]p
– lcd047 May 29 '15 at 5:01 -
[p
and]p
are to be used when you want to paste while keeping the indent of the line above or below. They are not magical replacements forP
andp
. – romainl May 29 '15 at 7:19
:set listchars=tab:\|\ ,trail:_,extends:>,precedes:<,nbsp:% list
– cychoi May 30 '15 at 0:20listchars
. I suppose I could include tabs as well, though.... – Kyle Strand May 30 '15 at 0:25