最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】vi/vim使用记录

工作和技术 crifan 1779浏览 0评论

 

【整理】vi/vim使用记录

用putty通过SSH连接了一个Linux server,用vi打开一个文件,然后查找某字符串时候,结果搜索出来的字符,会高亮显示,但是颜色很难看,而且看不清,所以想要设置一下对应的颜色。

所以要做的事情就是

1. 设置搜索的高亮的颜色

网上找了半天,发现对应的高亮相关的设置,是命令hi,即在vi的普通模式下,先输入冒号”:”,然后再输入”hi”,即:

:hi

然后确定,就可以看到对应的所有的相关的颜色设置了:

:hi
。。。
Search         xxx term=standout ctermfg=0 ctermbg=3
。。。。。。

Todo           xxx term=standout ctermfg=0 ctermbg=3
。。。。

其中可以看到,关于搜索出来的字符的高亮的颜色设置,是对应的:

Search         xxx term=standout ctermfg=0 ctermbg=3
而另外有个Todo的颜色设置,我觉得很喜欢,希望将Search的颜色设置成Todo的样式,所以可以直接输入对应的命令去设置:

:hi Search term=standout ctermfg=0 ctermbg=3

这样就可以立刻看到效果了,刚才搜索的字符的高亮的颜色就变成和Todo显示出来的一样了。

但是有个问题,一旦推出vi,此设置就失效了。所以就又有了下面的问题,即如何进行其他相关颜色设置,而保证每次启动都是我要的设置。

2.如何自己配置vi

之前就知道,vi有个对应的当前个人用户的配置文件,~/.vimrc

所以,可以将对应的配置加入到里面:

“colorscheme desert
“colorscheme peachpuff

:hi Search term=standout ctermfg=0 ctermbg=3
其中,用双引号”表示注释内容

对应的命令设置以冒号:开头,后面跟上你的命令设置。

具体细节参考引用1.

3.如何将vi显示的彩色的内容,输入到HTML

参考附录3,输入命令:

:runtime! syntax/2html.vim

就可以生成同样代码着色的FILENAME.html文件,然后退出保存成html文件:

先按ESC,然后输入:

:w colorful_code.html

然后就退出html编辑,回到原先文件编辑模式了,然后继续输入

:q

退出vi,用ls命令查看当前文件夹,就可以看到对应的文件了:

colorful_code.html

 

下面随便贴出部分彩色代码给大家看看,总的来说还是不错的:

————————————————————————————

# When none of the above methods is used the local build is performed and
# the object files are placed in the source directory.
#

ifdef O
ifeq ($(origin O), “command line”)
BUILD_DIR := $(O)
endif
endif

ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)

# Attempt to create a output directory.
$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})

# Verify if it was successful.
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory $(saved-output) does not exist))
endif # ifneq ($(BUILD_DIR),)
————————————————————————————

关于颜色方面,如果你觉得不爽,可以去~/.vimrc中配置颜色方案,比如

colorscheme desert

等等。

4.Vi/Vim的帮助文档

http://vimdoc.sourceforge.net/htmldoc/help.html
内容很全,包括复制内容到寄存器中的寄存器有哪些,以及具体的含义说明,比如星号*和加号+的区别:

“7. Selection and drop registers “*, “+ and “~
Use these register for storing and retrieving the selected text for the GUI.
See |quotestar| and |quoteplus|.  When the clipboard is not available or not working, the unnamed register is used instead.  For Unix systems the clipboard is only available when the |+xterm_clipboard| feature is present.  {not in Vi}

Note that there is only a distinction between “* and “+ for X11 systems.  For an explanation of the difference, see |x11-selection|.  Under MS-Windows, use of “* and “+ is actually synonymous and refers to the |gui-clipboard|.”

 

【引用】

1. vim 颜色和中文支持设置

http://liuhongdan.bokee.com/6752843.html

2. 配置 vim 命令行下的颜色主题与语法高亮

http://www.ncq8.com/2010/11/328.html

3. 将Vim高亮语法显示输出到HTML

http://vimdoc.sourceforge.net/htmldoc/vimfaq.html#24.14

转载请注明:在路上 » 【整理】vi/vim使用记录

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.157 seconds, using 22.06MB memory