Use Mouse in Terminal Vim like a modern editor

现代的编辑器(Ultraeditor, Editplus) 对于鼠标的使用非常频繁,最常见的是使用鼠标单击来移动光标,鼠标滚轮来上下翻页,或者鼠标双击选中某个词,然后拷贝或者粘贴替换。我最近学到了如何在Terminal-Based Vim 中也这样操作。

首先设置Vim 在 Normal Mode 和 Visual Mode 下激活鼠标:

set mouse=nv

这样我们就可以用鼠标单击或者滚轮移动光标了。另外,鼠标双击选中单词也正常工作了。

值得一提的是,我们也可以用键盘来选中一个词:假定我们的光标停在 information 这个词上(任何位置都可以),按下

viw

就可以选中整个词,这个操作不需要鼠标,在某些情况下很方便。

接下来的事情就容易了,拷贝:

y

粘贴并替换当前选中的词:

p

 

编译 Vim (Compile Vim Wiht Python 3 Support on Debian)

下载源文件

$ git clone https://github.com/vim/vim.git
$ cd vim/src
$ vi Makefile

编辑Makefile

  • 选择编译器
# COMPILER - Name of the compiler {{{1
# The default from configure will mostly be fine, no need to change this, just
# an example. If a compiler is defined here, configure will use it rather than
# probing for one. It is dangerous to change this after configure was run.
# Make will use your choice then -- but beware: Many things may change with
# another compiler. It is wise to run 'make reconfig' to start all over
# again.
#CC = cc

# For some reason, gcc does not install itself as /usr/bin/gcc
CC = gcc-9
#CC = clang

if gcc is not installed, installing it by running

$ sudo apt update
$ sudo apt install build-essential
  • 关闭图形
# GUI - For creating Vim with GUI (gvim) (B)
# Uncomment this line when you don't want to get the GUI version, although you
# have GTK, Motif and/or Athena. Also use --without-x if you don't want X11
# at all.
CONF_OPT_GUI = --disable-gui

# X WINDOWS DISABLE - For creating a plain Vim without any X11 related fancies
# (otherwise Vim configure will try to include xterm titlebar access)
# Also disable the GUI above, otherwise it will be included anyway.
# When both GUI and X11 have been disabled this may save about 15% of the
# code and make Vim startup quicker.
CONF_OPT_X = --without-x
  • 支持  Python3

安装 Python3 库文件

$ sudo apt install python3.8 python3.8-dev python3-distutils

静态链接 Python 解释器。

# PYTHON
# Uncomment lines here when you want to include the Python interface.
# This requires at least "normal" features, "tiny" and "small" don't work.
# NOTE: This may cause threading to be enabled, which has side effects (such
# as using different libraries and debugging becomes more difficult).
# For Python3 support make a symbolic link in /usr/local/bin:
# ln -s python3 python3.1
# If both python2.x and python3.x are enabled then the linking will be via
# dlopen(), dlsym(), dlclose(), i.e. pythonX.Y.so must be available
# However, this may still cause problems, such as "import termios" failing.
# Build two separate versions of Vim in that case.
#CONF_OPT_PYTHON = --enable-pythoninterp
#CONF_OPT_PYTHON = --enable-pythoninterp --with-python-command=python2.7
#CONF_OPT_PYTHON = --enable-pythoninterp=dynamic
#CONF_OPT_PYTHON3 = --enable-python3interp
#CONF_OPT_PYTHON3 = --enable-python3interp --with-python3-command=python3.8
#CONF_OPT_PYTHON3 = --enable-python3interp=dynamic

CONF_OPT_PYTHON3 = --enable-python3interp --with-python3-command=python3.8 --with-python3-config-dir=/usr/lib/python3.8/config-3.8-x86_64-linux-gnu

编译和安装

$ make

$ sudo make install

清理一切,从头开始

$ make distclean