Using the Mouse for Vim in an Xterm
If you prefer working in an xterm rather than the GUI version of Vim, you might encounter some inconveniences. One common issue is copying text from Vim within the xterm, which includes line numbers. The GUI version of Vim handles this better, as it selects only the text, leaving out the line numbers. However, you can achieve similar functionality in the xterm version of Vim by adding the following line to your vimrc
:
|
|
This setting enables mouse support, allowing you to select text without including line numbers. You can also selectively enable mouse support for specific modes by using a different argument in place of ‘a’.
While you might be more comfortable using the keyboard for most tasks, when it comes to transferring text between X applications or xterms, using the mouse can be more efficient. If you have a modern mouse with a scroll wheel that can also function as a middle mouse button, you can simulate the mouse wheel’s behavior in GUI Vim by implementing some mappings in your vimrc
and configuring VT100 translations in your .Xresources
file. After editing the .Xresources
file, make sure to run the following command for the changes to take effect:
|
|
Note that the changes won’t affect the currently running xterm; you’ll need to open a new one to see the mouse wheel scrolling in action.
However, please be aware that the mappings provided in the Vim documentation might not work perfectly for all setups. You might need to adjust them to match your system’s configuration. For instance, you may need to replace <M-Esc>
with <xCSI>
in the mappings. Here’s an example:
|
|
Once you’ve made these adjustments and loaded a large text file, you can enjoy mousewheel scrolling in Vim.
References
Comments
Pasting into an xterm Vim can be a bit tricky. To paste text from your browser into Vim, follow these steps:
- Select the text in your browser.
- Go to Vim.
- Enter insert mode (
i
orI
). - Middle-click (button 2) to paste.
However, if you don’t set paste mode, you might encounter issues with indentation and formatting. To toggle paste mode in Vim, you can use a key binding. Here’s an example of how to set it up in your vimrc
:
|
|
This configuration allows you to toggle paste mode with the F11 key, both in insert mode and normal mode.
If you want to use Vim in xterm with :set mouse=a
, you might notice that mouse middle-click paste no longer works as expected. In this case, use Shift+middle-click to paste the X selection.
In summary, you can enjoy the convenience of using the mouse in Vim while working in an xterm by configuring mouse support and adjusting your settings to ensure smooth text copying and pasting.