目 录CONTENT

文章目录

gvim的学习

在水一方
2022-06-18 / 0 评论 / 0 点赞 / 1,047 阅读 / 2,994 字 / 正在检测是否收录...

网上看到很多文章说gvim是一款功能非常强大的文档编辑器,作为一名开发人员你来说,因为平时也经常需要和linux服务器打交道,对于linux命令的熟悉是非常有必要的,今天来学习一下这款gvim编辑器,来感受一下,刚入门可能会有比较多问题,一步一步来。

官网地址:

https://www.vim.org/sponsor/index.php
中文文档地址:
https://github.com/yianwillis/vimcdoc/releases

配置背景

由于默认的白色背景不太友好,这里需要进行设置一下
image.png

原始配置文件的内容


" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim

" Use the internal diff if available.
" Otherwise use the special 'diffexpr' for Windows.
if &diffopt !~# 'internal'
  set diffexpr=MyDiff()
endif
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg1 = substitute(arg1, '!', '\!', 'g')
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg2 = substitute(arg2, '!', '\!', 'g')
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let arg3 = substitute(arg3, '!', '\!', 'g')
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  let cmd = substitute(cmd, '!', '\!', 'g')
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction

加上背景修改和字体的设置

source $VIMRUNTIME/vimrc_example.vim

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg1 = substitute(arg1, '!', '\!', 'g')
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg2 = substitute(arg2, '!', '\!', 'g')
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let arg3 = substitute(arg3, '!', '\!', 'g')
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  let cmd = substitute(cmd, '!', '\!', 'g')
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction

"乱码设置
let &termencoding=&encoding
set fileencodings=utf-8,gbk,gb18030,gb2312,cp936,ucs-bom,latin1


set nobackup
set noswapfile
set noundofile


"自己配置的东西

"字体
filetype off
set guifont=Consolas:h9:cGB2312
"显示行数
set nu!
"关闭兼容
set nocompatible
"语法高亮
syntax on
"括号匹配
set showmatch
"set smartindent
"开启代码折叠
set foldenable
"tab按键的空格数
set tabstop=4
"显示光标列数
set ruler
"自动缩进
set autoindent 

"键盘映射
map ti :tabe.<cr>
"设置背景颜色
colorscheme desert

image.png

vim键盘图
vim.png

命令

G:跳转到底部
gg:光标指导开头
冒号+行数=调到指定的行数
~~表示跳回原有的地方

使用 jj 替代 esc 了。用 esc 确实很烦。一种方式是自己映射一堆快捷键。加入到你的 vimrc 配置文件里


" 替代 esc
inoremap jj <Esc>`^

" Fast saving
nnoremap <silent><Leader>w :update<CR>
vnoremap <silent><Leader>w <Esc>:update<CR>

或者用 +c 或者 +[

待续.........

小结

一开始接触这款编辑器确实会感觉很不适应,学习起来也是有点难度,很多的快捷键需要去记,先迈出第一步

0

评论区