vim相关配置

vim配置

vim配置


前言

对vim配置的一些记录。


配色

主题

主题我使用的是经久不衰的molokai,哈哈,这个配色个人还是很喜欢的。下面是它的github地址:

https://github.com/tomasr/molokai.git

下载完成后将molokai文件夹下的colors文件夹复制~/.vim目录下(没有请自已创建),然后~.vimrc中添加如下内容:

set t_Co=256                "开启256配色
colorscheme molokai
let g:molokai_original = 1
let g:rehash256 =1

在设置t_Co后可能还不能正常显示,就是terminal没有开启256色的原因,手动开启下就好了。
先查看终端类型

[fatty@ARCHGZZ ~]$ echo $TERM
xterm-256color

为xterm-256color则正常,若为xterm则需手动开启256模式。在~/.bashrc中添 加下面内容:

if [ "$TERM" == "xterm" ]; then
export TERM=xterm-256color
fi

如果系统默认没有 xterm-256color 类型,可安装 ncurses-term 包,里面有许多附加的终端类型定义,里面还有一个终端类型xterm+256color,也可以开启 256 色支持,不知道与 xterm-256color 有什么区别。
第一次添加完后记得重新source下。

source ~/.bashrc

缩进相关的配置

平时写代码的过程中,为了避免不必要的麻烦恼,我个人习惯使用这些命令把tab替换为四个space,并且设置自动缩进的长度为4个字符

set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4
set cindent
  1. tabstop
    下面是vim中对tabstop的解释

Number of spaces that a <Tab> in the file counts for. Also see the :retab command, and the ‘softtabstop’ option.
Note: Setting ‘tabstop’ to any other value than 8 can make your file appear wrong in many places, e.g., when printing it.The value must be more than 0 and less than 10000.

根据help文档,可以看出,tabstop指的是与一个tab等价的space的数量,(默认值为8,可以修改为0-1000的任意值,但最好不要超过8)。我平时习惯替换为4个所以使用如下命令:

set tabstop=4         #equal set ts=4
  1. softtabstop
    先看下官方给出的解释:

Number of spaces that a counts for while performing editing operations, like inserting a <Tab> or using<BS>. It “feels” like
<Tab>s are being inserted, while in fact a mix of spaces and <Tab>s is used. This is useful to keep the ‘ts’ setting at its standard value of 8, while being able to edit like it is set to ‘sts’. However,commands like “x” still work on the actual characters.

从以上内容来看,此选项为tab键的功能性重写。softtabstop指的当你按下一个tab键时,实际产生的缩进长度,假设你当时的配置为1个tab的长度为4个space,而softtabstop10,并且不用space替换tab,那么实际在文档中写入则是2个tab+2个space.实验效果如下:

^I^I  $

使用以下命令设置softtabstop值:

set softtabstop=4
  1. expandtab
    还是先了解下官方解释

In Insert mode: Use the appropriate number of spaces to insert a<Tab>. Spaces are used in indents with the ‘>’ and ‘<’ commands and when ‘autoindent’ is on. To insert a real tab when ‘expandtab’ is on, use CTRL-V<Tab>. See also |:retab| and |ins-expandtab|.This option is reset when the ‘paste’ option is set and restored when the ‘paste’ option is reset.
NOTE: This option is reset when ‘compatible’ is set.

说白了就是:是否用spaces替换tab。打开的方式为

set expandtab
  1. shiftwidth

Number of spaces to use for each step of (auto)indent. Used for |‘cindent’|, |>>|, |<<|, etc. When zero the ‘ts’ value will be used. Use the |shiftwidth()| function to get the effective shiftwidth value.

就是自动缩进的长度。设置方法为

set shiftwidth=4
  1. set cindent
    此命令为打开自动缩进功能,此模式下按下换行后会根据具体的文件类型进行相关的缩进,若没有对应的缩进设置,则换行后会保持和上一行对齐。

不能删除的问题

vim刚开始朽置好的时候,插入模式下发现新增加的字符只能新增不能删除,上网搜索资料后有了以下发现:

  1. 原因:
VIM使用了 compatible 模式,或者把 backspace 变量设置为空了…其实compatible模式是VIM为了兼容vi而出现的配置,它的作用是使VIM的操作行为和规范和vi一致,而这种模式下backspace配置是空的。即意味着backspace无法删除 indent , end of line , start 这三种字符。

在默认状态下,delete(backspace)按下只会删除本次插入模式下插入的文本,这跟backspace的模式设置有关,其模式可以设置为以下三种模式:

0 same as “:set backspace=(Vi compatible)

1 same as “:set backspace=indent,eol”

2 same as “:set backspace=indent,eol,start”

也就是默认的是模式0。

  1. 解决:
    知道了原因,只要把backspace设置成模式2就可以了,在~/.vimrc中添加以下内容:
set backspace=2

总结

在修改完配置文件后记得重启一下vim,或者在命令模式下执行如下命令:

:source ~/.vimrc

以上都是个人理解,不免会有错误,还请大家批评指正。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值