I use vim for about a year or more, and I like it, however I'm still having trouble with copying and pasting tiny fragments of text. Maybe someone can help me out with this?
1) If I yank a line with yy, pressing P or p will insert the text into a new line.
2) If I go to visual mode and select a region, yank it with y, then press p/P, it gets it inserted into the current line.
That is, vim preserves new lines.
What I can't figure out is how to paste into the current line in the first case, and, vice-versa, how to easily paste into a new line in the second case (without doing :put, or opening a new line).
There's no good way to do it, unfortunatly. You need to yank the contents of the line without yanking the entire line qua line. Now, if 'l' were a text object for 'line' then there would be an obvious 'yil' for just getting the inner stuff, but since there isn't you'll have to do
0y$
to go to the start of the line and yank until the end of the line. That'll store the line contents instead of the line itself, so p will do what you want it to.
That is, i<C-r>0 will paste a line character-wise, but the EOL will still be there, so you might have to join lines afterward. Alternatively, you could not yank the EOL with ^y$.
For making a newline with a character-wise yank, use o or O to make the new line and you can use <C-r>0. Or Escape and p.
Whether it pastes a newline or not depends on whether you yanked one. I guess this is what you mean by "vim preserves new lines". Don't all editors work this way?
If you want to yank a line character-wise, you would do something like ^y$. I have Y mapped to y$ for this sort of thing.
You cannot yank a substring of a line line-wise. That doesn't really make sense. I typically open a new line with o and then paste in insert mode with <C-r>". So o<C-r>".
Seems like my description was incorrect. I meant that there are two ways to deal with text: line-wise and fragment-wise.
In most other text editors, if you copy a line, and then paste it, it gets pasted into the cursor position regardless whether you copied a line or a fragment (fragment-wise). In Vim, lines yanked with 'yy' disregard the cursor column and get pasted into a line above or below, while fragments yanked with 'y' (e.g. '0y$'), take into account the column.
I like how in Vim you can do line-wise editing, but I just miss an easy way to paste text to the position starting with the current column regardless of the way I yanked it.
you can always map <leader>y to yank line except for end.
Mapping the leader to , and it's even nicer. then all you need to do is ,y and you get the line in fragment mode.
nnoremap <leader>y 0y$
or if you want just first non whitespace char you could do an uppercase y for the leader command. swap the upper and lower to make it how you want. seems like this would be a more useful command to have:
nnoremap <leader>Y ^y$
edit: saw that you found a workaround by pasting in insert mode. ctrl-r" any other ways to paste in insert mode?
Put this into your vimrc to make lines behave like they're a text-object. Then to yank a line without the carraige-return, it's just yil or yal (yank in/a line)
vnoremap <silent> al :<c-u>norm!0v$h<cr>
vnoremap <silent> il :<c-u>norm!^vg_<cr>
onoremap <silent> al :norm val<cr>
onoremap <silent> il :norm vil<cr>
For the first, you need to do a 0yt$ .. this will yank to endline, but not include it. The whole line can then be pasted into another without breaking it.
The 2nd can be o/O<esc>p .. Maybe there's a more elegant way though!
You could bind these to, say, <leader>p and <leader>P, if you find yourself doing it a lot.
For #1, the yy command will yank the entire line (including the newline). Try using y$, which will yank from the cursor to the end of the line (not including the newline).
To the certain extent, yes, it makes sense. This trouble is rather small compared to benefits. I'm in constant search for the perfect editor, but every editor has its quirks, and of course, most editors require learning.
As for the controls that contradict with the rest of the software, there's no trouble for me at all. I don't suddenly start pressing :wq in the browser. As a simple example, consider people like me, who use two keyboard layouts: one for their native language and the other one for English. Even punctuation marks are on the different keys, but I don't have trouble typing the correct ones depending on the current layout.
'basic functions' in this case being the subtle difference in two kinds of pasting that he already knows how to achieve, and is asking for another way to do one of the paste formats.
Yes, joining works when I want it to appear at the end of the current line, but I want to it to appear at the cursor. Anyway, seems like pasting in the insert mode works the way I want, for the first case.
1) If I yank a line with yy, pressing P or p will insert the text into a new line.
2) If I go to visual mode and select a region, yank it with y, then press p/P, it gets it inserted into the current line.
That is, vim preserves new lines.
What I can't figure out is how to paste into the current line in the first case, and, vice-versa, how to easily paste into a new line in the second case (without doing :put, or opening a new line).