Skip to content

Instantly share code, notes, and snippets.

@lazydao
Last active April 24, 2024 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazydao/ab00c8bef9f60c8c6063a92c7411edc4 to your computer and use it in GitHub Desktop.
Save lazydao/ab00c8bef9f60c8c6063a92c7411edc4 to your computer and use it in GitHub Desktop.
vim配置
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) | PlugInstall --sync | source $MYVIMRC | endif
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/joshdick/onedark.vim
Plug 'joshdick/onedark.vim'
Plug 'tpope/vim-fugitive'
Plug 'psf/black', { 'branch': 'stable' }
Plug 'spin6lock/vim_sproto'
Plug 'preservim/nerdtree'
Plug 'airblade/vim-gitgutter'
Plug 'python-mode/python-mode'
" YouCompleteMe 下载后需要手动安装:
" cd ~/.vim/plugged/YouCompleteMe
" python3 install.py --all
" 另外下面两个插件都是 python 的,需要编译 vim 支持 python,在 Debian 系下可以执行 `sudo apt install vim-nox` 来安装。
Plug 'ycm-core/YouCompleteMe'
Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
call plug#end()
" black
let g:black_linelength = 120
autocmd BufWritePre *.py execute ':Black'
set termguicolors " 开启24位颜色
set background=dark
colorscheme onedark " 设定主题为onedark
" Turn on syntax highlighting.
syntax enable
" Disable the default Vim startup message.
set shortmess+=I
" Show line numbers.
set number
" 不换行
set nowrap
" Always show the status line at the bottom, even if you only have one window open.
set laststatus=2
" The backspace key has slightly unintuitive behavior by default. For example,
" by default, you can't backspace before the insertion point set with 'i'.
" This configuration makes backspace behave more reasonably, in that you can
" backspace over anything.
set backspace=indent,eol,start
" By default, Vim doesn't let you hide a buffer (i.e. have a buffer that isn't
" shown in any window) that has unsaved changes. This is to prevent you from "
" forgetting about unsaved changes and then quitting e.g. via `:qa!`. We find
" hidden buffers helpful enough to disable this protection. See `:help hidden`
" for more information on this.
set hidden
" This setting makes search case-insensitive when all characters in the string
" being searched are lowercase. However, the search becomes case-sensitive if
" it contains any capital letters. This makes searching more convenient.
set ignorecase
set smartcase
" Enable searching as you type, rather than waiting till you press enter.
set incsearch
" Unbind some useless/annoying default key bindings.
nmap Q <Nop> " 'Q' in normal mode enters Ex mode. You almost never want this.
" Disable audible bell because it's annoying.
set noerrorbells visualbell t_vb=
" Enable mouse support. You should avoid relying on this too much, but it can
" sometimes be convenient.
set mouse+=a
set expandtab " 将 Tab 转换为空格
set tabstop=4 " 设置 Tab 的宽度为 4 个空格
set shiftwidth=4 " 设置缩进宽度为 4 个空格
set softtabstop=4 " 在插入模式下,按 Tab 键插入 4 个空格
set autoindent " 开启自动缩进
set hlsearch " search highlight
" Start NERDTree when Vim starts with a directory argument.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') | execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * if &buftype != 'quickfix' && getcmdwintype() == '' | silent NERDTreeMirror | endif
let g:NERDTreeFileLines = 1
let g:Lf_WindowPosition = 'popup'
let g:Lf_ShortcutF = '<C-P>'
  • u: Undo
  • Ctrl+R: Redo
  • %s/old/new/g: Replace old with new globally
  • Ctrl+O 会将光标移动到上次您离开的位置
  • zz 当前行移动到屏幕中央,zt,zb
  • di" 删除双引号内的内容,i 代表 inside
  • ci" 重写双引号内的内容,逻辑同上
  • dt" 删除到双引号为止,t 代表 till
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment