Under Windows the most practical configuration Gvim

vim has been called the God of the editor in Windows it is difficult to play its powerful features, from a practical point of view this article explains how to adjust a relatively easy to use vim

But still have to note, in many vim builds in MacVim Mac OS platform is a version I think the best use. Major companies because of their use Windows, because I have experience is a requirement for the editor Yan value front-end engineers, so only the following ^! ^

First described the development environment:

  • ThinkPad T450 (company standard)
  • Windows 7 SP1 64bit Enterprise Edition
  • Programming language JavasSript, HTML, CSS, NodeJS, Python

Foreword

This article aims to configure and use vim, vim is not suitable for primary users too, the author is not vim diehard powder, often mixed Webstrom and vim

Start

Before we begin to look at a Windows installation on the default interface Gvim, we will start a step by step learning and configuration here

gvim-default

Configuration _vimrc

Since vimrc there will be a lot of configuration items, in order to avoid confusion, I probably according to their own habits divided into several groups:

  • Startup - some configurations need to be added when the editor starts
  • General - General Configuration
  • Lang & Encoding - the language and encoding
  • GUI - Interface
  • Format - basic code format
  • Keymap - generic shortcuts
  • Plugin - related plugins (including the current plug-ins and associated configuration and shortcut keys, etc.)
  • Function - which used the common methods vimrc

Startup

" Startup {{{
filetype indent plugin on


" vim 文件折叠方式为 marker
augroup ft_vim
    au!

    au FileType vim setlocal foldmethod=marker
augroup END
" }}}

Set vim default documents unfolded after the way marker, convention with three braces comments wrapped up, so that when you open the configuration file vim will help you fold up the profile looks a lot cleaner, as :

vim-fold-config

General

" General {{{
set nocompatible
set nobackup
set noswapfile
set history=1024
set autochdir
set whichwrap=b,s,<,>,[,]
set nobomb
set backspace=indent,eol,start whichwrap+=<,>,[,]
" Vim 的默认寄存器和系统剪贴板共享
set clipboard+=unnamed
" 设置 alt 键不映射到菜单栏
set winaltkeys=no
" }}}

Basically one can tell These are hell, but behind the two projects I personally feel relatively easy to use:

clipboard + = unnamed for example, you copy a piece of text in other places which you can paste it back to vim

winaltkeys=no 一般 windows 下应用程序的 alt 是用来定位菜单栏目的快捷键,我们需要禁用它,因为我们后面很多设置都需要使用 alt,需要使用 alt 来定位菜单的情况很少

Lang & Encoding

" Lang & Encoding {{{
set fileencodings=utf-8,gbk2312,gbk,gb18030,cp936
set encoding=utf-8
set langmenu=zh_CN
let $LANG = 'en_US.UTF-8'
"language messages zh_CN.UTF-8
" }}}

vim 里面设置编码的地方很多,上面这些配置可以保证不会出现乱码,像文件菜单、vim默认语言建议设置成 en_US

GUI

" GUI {{{
colorscheme Tomorrow-Night

source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set cursorline
set hlsearch
set number
" 窗口大小
set lines=35 columns=140
" 分割出来的窗口位于当前窗口下边/右边
set splitbelow
set splitright
"不显示工具/菜单栏
set guioptions-=T
set guioptions-=m
set guioptions-=L
set guioptions-=r
set guioptions-=b
" 使用内置 tab 样式而不是 gui
set guioptions-=e
set nolist
" set listchars=tab:▶\ ,eol:¬,trail:·,extends:>,precedes:<
set guifont=Inconsolata:h12:cANSI
" }}}

编辑器配色建议使用 Tomorrow-Night,下载文件 copy 到 colors 目录即可

从上面的设置可以看出来,为了得到一个简洁漂亮的界面,我们去掉了菜单栏、各种滚动条、使用 vim 内置 tab 而不是 gvim 系统的 tab 样式,注意很多开发者喜欢显示不可见字符,比如:tab 制表符、换行符号、尾空格等。

我自己并不喜欢这样,因为这样只会使界面看起来更零乱,尤其是某插件纵向标尺

字体方面个人推荐 Inconsolata 这个在我看来是 Windows 平台最漂亮的等宽字体了

此时你的编辑器应该好看了很多:

more-beauty-vim

Format

" Format {{{
set autoindent
set smartindent
set tabstop=4
set expandtab
set softtabstop=4
set foldmethod=indent
syntax on
" }}}

这个设置容易引起争议,我自己是这么个设置,大家按个人喜好就行了,反正我是不建议使用 tab 的,对代码格式有强迫症的人一般都会设置 foldmethod=indent

Keymap

可以说快捷键是每个编辑器必备的功能,科学的设置快捷键能很大程度的提高效率。快捷键的设置要遵循一个规则:尽量不要修改系统默认配置的快捷键,非要设置的话选择好相应的模式

" Keymap {{{
let mapleader=","

nmap <leader>s :source $VIM/_vimrc<cr>
nmap <leader>e :e $VIM/_vimrc<cr>

map <leader>tn :tabnew<cr>
map <leader>tc :tabclose<cr>
map <leader>th :tabp<cr>
map <leader>tl :tabn<cr>

" 移动分割窗口
nmap <C-j> <C-W>j
nmap <C-k> <C-W>k
nmap <C-h> <C-W>h
nmap <C-l> <C-W>l

" 正常模式下 alt+j,k,h,l 调整分割窗口大小
nnoremap <M-j> :resize +5<cr>
nnoremap <M-k> :resize -5<cr>
nnoremap <M-h> :vertical resize -5<cr>
nnoremap <M-l> :vertical resize +5<cr>

" 插入模式移动光标 alt + 方向键
inoremap <M-j> <Down>
inoremap <M-k> <Up>
inoremap <M-h> <left>
inoremap <M-l> <Right>

" IDE like delete
inoremap <C-BS> <Esc>bdei

nnoremap vv ^vg_
" 转换当前行为大写
inoremap <C-u> <esc>mzgUiw`za
" 命令模式下的行首尾
cnoremap <C-a> <home>
cnoremap <C-e> <end>

nnoremap <F2> :setlocal number!<cr>
nnoremap <leader>w :set wrap!<cr>

imap <C-v> "+gP
vmap <C-c> "+y
vnoremap <BS> d
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y
imap <C-V>		"+gP
map <S-Insert>		"+gP
cmap <C-V>		<C-R>+
cmap <S-Insert>		<C-R>+

exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']

" 打开当前目录 windows
map <leader>ex :!start explorer %:p:h<CR>

" 打开当前目录CMD
map <leader>cmd :!start<cr>
" 打印当前时间
map <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>

" 复制当前文件/路径到剪贴板
nmap ,fn :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
nmap ,fp :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>

" 设置切换Buffer快捷键"
nnoremap <C-left> :bn<CR>
nnoremap <C-right> :bp<CR>

" }}}

首页我们设置了 leaderkey 为逗号「,」,不要问为什么约定的就是它。别设置成空格就行了

注意「,e」和「,s」分别用编辑配置文件,刷新配置文件,后面的路径要按你自己的情况去写,我默认使用了 vim 安装目录里面的 vimrc

分屏编辑操作的时候经常要在不同的屏之间跳来跳去 「Ctrl + vim方向」设置跳转方便顺滑的切换,顺便说下我个人的习惯是在当前tab下编辑一个项目的文件,如果要临时维护其它项目就新开tab,每个tab单独编辑一个项目文件

后面还设置了一些和 Windows 默认编辑操作兼容的快捷键,比如:复制,粘贴

注意有个细节,因为 vim 里面多行操作快捷键是 Ctrl + v 和 windows 粘贴冲突了,一个机智的做法是仅仅在 vim 插件模式设置 Ctrl 为粘贴,正常模式 Ctril + v 进入多选模式,两全其美

插入模式下要移动光标 还得 ESC 一下进入插入模式,这样太麻烦了,使用 「alt + vim方向」就简单多了

Plugin

插件方面根据我自己的工作内容和个人喜好,选择了以下几个,全部使用 vundle 来管理:

  • NERDTree
  • Vim-multiple-cursors
  • Tabular
  • Airline
  • Ctrlp
  • NERDCommenter
  • Emmet
  • SnipMate
  • Fugitive
  • Neocomplete

具体配置我就不帖代码了,可以上git上参观,下面大概解释下每个插件的用途

NERDTree

文件目录树管理,我一般设置成打开 vim 就启动

if exists('g:NERDTreeWinPos')
    autocmd vimenter * NERDTree D:\repo
endif

Vim-multiple-cursors

类似 sublime 多选,进入 visual 模式选择文本 Ctrl+shif+n 即可一直选择下一个匹配文本

many-ass

Tabular

对齐插件,文章末尾 gif 图里面有展示,visual 模式下选择要对齐的多行文本,进入命令模式 :Tabularize /对齐符号<cr>

Airline

状态栏美化插件,准备弃用了

Ctrlp

类似IDE里面的最近打开的文件,用于快速定位文件/Buffer

NERDCommenter

注释插件,默认是快捷键是 <leader> c <SPACE>

Emmet

用来快速写 HTML

emmet

SnipMate

代码片段管理, 这个插件很早之前的那个版本不维护了,现在最新版的非常强大,不过有另外两个依赖,默认是没有任何内置的 snippet 的,如果需要样版,可以安装 这个插件 需要自定义的话手动更改 snippets 目录下的文件即可(其实就是个git仓库,你可以换成自己的)

snipmate

Fugitive

Git 命令增强工具,在 vim 使用 git,状态栏的分类名称就是调用的这个插件的方法 fugitive#head()

Neocomplete

Autocomplete plug, the plug-in is required lua code examples support, you may need to manually compile a gvim with lua supported version of next article  I will own the process of compiling on Windows installation record

what? You say why do not install YouCompleteMe, the official authors do not support plug-ins do not toss it, Neocomplete this example plug-in for my case have been enough

Function

Here I have only one common method, remove trailing spaces

" Function {{{
" Remove trailing whitespace when writing a buffer, but not for diff files.
" From: Vigil
" @see http://blog.bs2.to/post/EdwardLee/17961
function! RemoveTrailingWhitespace()
    if &ft != "diff"
        let b:curcol = col(".")
        let b:curline = line(".")
        silent! %s/\s\+$//
        silent! %s/\(\s*\n\)\+\%$//
        call cursor(b:curline, b:curcol)
    endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
" }}}

No picture U say a … ?

complete-vimrc

This is a moving map, not moving a large stamp

gif-show-vim

Epilogue

Another point not explain, vimrc inside some windows unique set I did not add some judgment is compatible with other platforms, this is just a personal preference, I will separately maintain separate profiles for different platforms, but not all put together each species determination logic

Quote

Complete profile

<< application and configuration free https certificate (Let's Encrypt) using MinGW compile and install (g) under Windows to add lua vim and other programming languages supported >>

Comments

Guess you like

Origin blog.csdn.net/l471094842/article/details/90726415