Paste from insert mode <Ctrl-r>0
You can also insert the yanked text from insert mode when autoindent
has added the correct indentation:
yiw
yank
o<CR>
switch to insert mode and add new line
<Ctrl-r>0
paste text from register 0
Drew Neil has created a vimcast
I would also recommend two articles by Drew Neil:
Note pasting a code block in insert mode
If you want to paste not a single word but a code block,
this answer might not be satisfactory. Replace in step 1 yiw
with yG
and then execute steps 2 and 3, you will end up with
function Scene:get(...)
function Scene:get(...)
local l = {}
for i, e in ipaires(self.nodelist) do
if (e:is(...)) then
l[#l +1] = e
end
end
return l
end
local l = {}
for i, e in ipaires(self.nodelist) do
if (e:is(...)) then
l[#l +1] = e
end
end
return l
end
To fix this you would have to set paste
after you switched to insert mode to take advantage of the autoindentation because paste
disables autoindentation.
I do not know a simple way to do this and would recommend to paste from normal mode with the help of vim-unimpaired (=p
). Also note yanking into the system clipboard and using the bracketed paste feature does not work for me flawlessly (macOS, Terminals: iTerm2.app v3.1.7 or Terminal.app v2.7.4).
inoremap <return> <return>yo<backspace><backspace>
and it works as expected! i'm not sure if this is exactly what you meant but it worked. but still if i press<esc>
the cursor goes back a full tab, but if i enter insert mode again it went back to the correct indent, and the indent seems actually there (can be selected), i don't understand why in normal mode it's ignoring the last indent..<esc>
puts the indent back. For me, after<esc>
the indent is gone, and pressingi
puts you at the beginning of the line.<enter><enter>
to create an empty line between different pieces of your code, the empty line is gonna have the indent whitespace. In git, if you setcore.whitespace
toblank-at-eol
for example, you're gonna have a bad time.tab
all the way is straight up bad experience haha