Clipboard
The key commands to copy/cut/delete text are:
- e:
copy current line or selection
- d:
cut current line or selection
- c:
delete current line or selection
Which are easy to remember because they are placed together vertically in the keyboard:
Once you have text in the clipboard, you can paste it with:
- p:
paste
The copy, cut and delete actions operate on the current selection if there is one or the current line if there's none. This is very practical to work with single lines in code. For example, to move a single line you only have to press d when the cursor is over it and p on the place you want to move it to.
Secondary clipboard
In Vem you have two clipboards. To access the second one, use the uppercase version of the above actions:
- E:
copy current line or selection (secondary clipboard)
- D:
cut current line or selection (secondary clipboard)
- P:
paste (secondary clipboard)
The primary clipboard is the one connected to the system clipboard, while the secondary one can help you when you don't want to lose the contents of the primary one but need to copy or move additional text.
Directional paste
When you paste, you'll notice that the text is added after the current position of the cursor. For example, if foo is in the clipboard:
# Characterwise paste: bar() → bar(foo) # Linewise paste: bar → bar baz foo baz
This is different from what you can find in other editors, which paste text before the cursor, however, it is very easy to get used to it. In addition, you can also paste before the cursor position using:
- Ctrl-p h:
paste to the left of the cursor (characterwise)
- Ctrl-p k:
paste above the cursor (linewise)
You can also paste at the beginning and the end of a line without having to move the cursor to that position:
- Ctrl-p ,:
paste at the beginning of the line —first non-blank character (linewise)
- Ctrl-p .:
paste at the end of the line (linewise)
- Ctrl-p ,:
paste at the beginning of the line —first non-blank character (linewise)
- Ctrl-p .:
paste at the end of the line (linewise)
- Ctrl-p ,:
paste at the beginning of the line —first non-blank character (linewise)
- Ctrl-p ;:
paste at the end of the line (linewise)
Pasting different selection types
As shown in the Selecting text section, there are three kinds of visual selections:
Characterwise: the common one in other text editors, for an arbitrary character to another one.
Linewise: full lines of text
Blockwise: an arbitrary rectangle of text
The type of selection is taken into consideration when pasting. Characterwise selections are pasted like in most editors, inserting the text in the current line. For linewise selections, text is pasted inserting the text between the current and the next line (without modifying them):
111 111 111 222 Press d 444 Press p 444 333 → 555 → 222 444 333 555 555
Notice that you don't have to open blank lines to paste a linewise selection.
Blockwise selections are pasted by displacing all characters around the block that is being pasted, as you could expect.
Paste while indenting
Sometimes you may want to paste text keeping the same level of indentation as the current line. That is useful when you move pieces of code to a inner or outer level of indentation. To paste and indent at the same time, use:
- Ctrl-p Tab:
paste with the same level of indentation as the current line
Pasting in terminal
If you are running Vem in a terminal and paste text using the paste command of the terminal itself (eg. typically using Command-v or Ctrl-Shift-v) while in insert mode, then, instead of getting something like this:
def dotted_netmask(mask): """Converts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 :rtype: str """ bits = 0xffffffff ^ (1 << 32 - mask) - 1 return socket.inet_ntoa(struct.pack('>I', bits))
you may end up with the text wrongly formatted and showing some staircase effect:
def dotted_netmask(mask): """Converts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 :rtype: str """ bits = 0xffffffff ^ (1 << 32 - mask) - 1 return socket.inet_ntoa(struct.pack('>I', bits))
This happens because, in terminal, Vim is unable to differentiate when text is entered manually or pasted. Consequently, it will autoformat some things according to the stream of characters that it receives (like for example auto indenting after every newline).
To avoid this from happening, just enter and exit paste mode before and after pasting using the terminal shortcut:
- Ctrl-^ or Ctrl-6:
toggle paste mode
When you start paste mode, the status line will display it. And as long as you remain in paste mode, you'll be able to correctly paste using the terminal clipboard shortcut. Press Ctrl-^ or Ctrl-6 again to exit paste mode so the editor can format the text correctly when you enter it manually.