Last active
July 20, 2022 06:33
-
-
Save xbol0/1eb2ecad7ba398667d03d1d5398f8296 to your computer and use it in GitHub Desktop.
vimrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " 自用vim配置 | |
| " 特性说明 | |
| " | |
| " 适配iterm2指针 | |
| " 空格作为leader键 | |
| " c-jkhl移动分屏 | |
| " c-q替换esc键,方便在ipad上用 | |
| set background=dark | |
| colorscheme default | |
| let mapleader = ' ' | |
| let g:mapleader = ' ' | |
| syntax on | |
| set history=2000 | |
| filetype on | |
| filetype plugin on | |
| filetype indent on | |
| set nocompatible | |
| set autoread | |
| set shortmess=atI | |
| set magic | |
| set title | |
| set nobackup | |
| set novisualbell | |
| set noerrorbells | |
| set visualbell t_vb= | |
| set t_vb= | |
| set tm=500 | |
| set cursorline | |
| set scrolloff=7 | |
| set ruler | |
| set number | |
| set nowrap | |
| set showcmd | |
| set showmode | |
| set showmatch | |
| set matchtime=2 | |
| set hlsearch | |
| set incsearch | |
| set ignorecase | |
| set smartcase | |
| set expandtab | |
| set smarttab | |
| set shiftround | |
| set autoindent smartindent shiftround | |
| set shiftwidth=4 | |
| set tabstop=4 | |
| set softtabstop=4 | |
| set foldenable | |
| set foldmethod=indent | |
| set foldlevel=99 | |
| let g:FoldMethod = 0 | |
| set encoding=utf-8 | |
| set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 | |
| set termencoding=utf-8 | |
| set ffs=unix,dos,mac | |
| set formatoptions+=m | |
| set formatoptions+=B | |
| set selection=inclusive | |
| set selectmode=mouse,key | |
| set completeopt=longest,menu | |
| set wildmenu | |
| set wildmode=longest,list,full | |
| set wildignore=*.o,*~,*.pyc,*.class | |
| set backspace=indent,eol,start | |
| set whichwrap+=<,>,h,l | |
| hi! link SignColumn LineNr | |
| hi! link ShowMarksHLl DiffAdd | |
| hi! link ShowMarksHLu DiffChange | |
| set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P | |
| set laststatus=2 | |
| set mouse=a | |
| " Change cursor shape between insert and normal mode in iTerm2.app | |
| if $TERM_PROGRAM =~ "iTerm" | |
| let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode | |
| let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode | |
| endif | |
| " fold | |
| map <leader>zz :call ToggleFold()<cr> | |
| fun! ToggleFold() | |
| if g:FoldMethod == 0 | |
| exe "normal! zM" | |
| let g:FoldMethod = 1 | |
| else | |
| exe "normal! zR" | |
| let g:FoldMethod = 0 | |
| endif | |
| endfun | |
| " if this not work ,make sure .viminfo is writable for you | |
| if has("autocmd") | |
| au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif | |
| endif | |
| " ============================ specific file type =========================== | |
| autocmd FileType python set tabstop=4 shiftwidth=4 expandtab ai | |
| autocmd FileType ruby set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai | |
| autocmd BufRead,BufNew *.md,*.mkd,*.markdown set filetype=markdown.mkd | |
| autocmd BufNewFile *.sh,*.py exec ":call AutoSetFileHead()" | |
| function! AutoSetFileHead() | |
| " .sh | |
| if &filetype == 'sh' | |
| call setline(1, "\#!/bin/bash") | |
| endif | |
| " python | |
| if &filetype == 'python' | |
| call setline(1, "\#!/usr/bin/env python") | |
| call append(1, "\# encoding: utf-8") | |
| endif | |
| normal G | |
| normal o | |
| normal o | |
| endfunc | |
| autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces() | |
| fun! <SID>StripTrailingWhitespaces() | |
| let l = line(".") | |
| let c = col(".") | |
| %s/\s\+$//e | |
| call cursor(l, c) | |
| endfun | |
| " ============================ key map ============================ | |
| nnoremap k gk | |
| nnoremap gk k | |
| nnoremap j gj | |
| nnoremap gj j | |
| nnoremap <c-d> 5gj | |
| nnoremap <c-u> 5gk | |
| map <C-j> <C-W>j | |
| map <C-k> <C-W>k | |
| map <C-h> <C-W>h | |
| map <C-l> <C-W>l | |
| nnoremap <F2> :set nu! nu?<CR> | |
| nnoremap <F3> :set list! list?<CR> | |
| nnoremap <F4> :set wrap! wrap?<CR> | |
| set pastetoggle=<F5> " when in insert mode, press <F5> to go to | |
| " paste mode, where you can paste mass data | |
| " that won't be autoindented | |
| au InsertLeave * set nopaste | |
| nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR> | |
| " kj 替换 Esc | |
| inoremap <c-q> <Esc> | |
| " Quickly close the current window | |
| nnoremap <leader>q :q<CR> | |
| " Quickly save the current file | |
| nnoremap <leader>w :w<CR> | |
| " select all | |
| map <Leader>sa ggVG" | |
| " remap U to <C-r> for easier redo | |
| nnoremap U <C-r> | |
| " Swap implementations of ` and ' jump to markers | |
| " By default, ' jumps to the marked line, ` jumps to the marked line and | |
| " column, so swap them | |
| nnoremap ' ` | |
| nnoremap ` ' | |
| " switch # * | |
| " nnoremap # * | |
| " nnoremap * # | |
| "Keep search pattern at the center of the screen." | |
| nnoremap <silent> n nzz | |
| nnoremap <silent> N Nzz | |
| nnoremap <silent> * *zz | |
| nnoremap <silent> # #zz | |
| nnoremap <silent> g* g*zz | |
| " remove highlight | |
| noremap <silent><leader>/ :nohls<CR> | |
| "Reselect visual block after indent/outdent.调整缩进后自动选中,方便再次操作 | |
| vnoremap < <gv | |
| vnoremap > >gv | |
| " y$ -> Y Make Y behave like other capitals | |
| map Y y$ | |
| "Map ; to : and save a million keystrokes | |
| " ex mode commands made easy 用于快速进入命令行 | |
| nnoremap ; : | |
| " Shift+H goto head of the line, Shift+L goto end of the line | |
| nnoremap H ^ | |
| nnoremap L $ | |
| " save | |
| cmap w!! w !sudo tee >/dev/null % | |
| " command mode, ctrl-a to head, ctrl-e to tail | |
| cnoremap <C-j> <t_kd> | |
| cnoremap <C-k> <t_ku> | |
| cnoremap <C-a> <Home> | |
| cnoremap <C-e> <End> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment