Skip to content

Instantly share code, notes, and snippets.

@qixiao986
Last active July 12, 2021 01:01
Show Gist options
  • Save qixiao986/a8a856661c27d7636c8c7b46fe2f5283 to your computer and use it in GitHub Desktop.
Save qixiao986/a8a856661c27d7636c8c7b46fe2f5283 to your computer and use it in GitHub Desktop.
vim config
set nocompatible " be iMproved, required
filetype off " required
syntax on
language en_US
" set list
" set listchars=tab:--,trail:.,eol:¬,extends:>,precedes:<
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=/usr/local/opt/fzf
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'preservim/nerdtree'
Plugin 'octol/vim-cpp-enhanced-highlight'
Plugin 'preservim/nerdcommenter'
Plugin 'voldikss/vim-floaterm'
Plugin 'ycm-core/YouCompleteMe'
Plugin 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plugin 'junegunn/fzf.vim'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tpope/vim-surround'
"Plugin 'sjl/gundo.vim'
"Plugin 'terryma/vim-multiple-cursors'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
set exrc
set mouse=a
set tabstop=4
set shiftwidth=4
set smarttab
set autoindent
set smartindent
set cindent
set showcmd
set autowrite
set autoread
"set nowrap
"map <F3> :<C-U>w<CR>:<C-U>term ++close g++-11 -std=c++17 -O2 -Wall -Wextra -pedantic -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -Wno-unused-result -Wno-sign-conversion -DLOCAL %:r.cpp -o %:r<CR>
map <F3> :<C-U>w<CR>:FloatermNew --autoclose=1 g++-11 -std=c++17 -O2 -Wall -Wextra -pedantic -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -Wno-unused-result -Wno-sign-conversion -fsanitize=address -fsanitize=undefined -DLOCAL %:r.cpp -o %:r<CR>
"map <F4> :<C-U>!./%:r<CR>
map <F4> :<C-U>FloatermNew --autoclose=0 %:p:h/%:t:r<CR>
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
\,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
\,sm:block-blinkwait175-blinkoff150-blinkon175
let g:cpp_posix_standard = 1
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_concepts_highlight = 1
let g:airline#extensions#tabline#enabled = 1
let g:ycm_global_ycm_extra_conf = '/Users/ndz/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'
let g:ycm_enable_diagnostic_highlighting = 0
let g:fzf_preview_window = ['right:50%', 'ctrl-/']
let g:AutoPairsMapCh = 0
let g:AutoPairsShortcutJump = '≥' "M-.
set nu
set relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
"inoremap { {}<Left>
"inoremap {<CR> {<CR>}<Esc>O
"inoremap {{ {
"inoremap {} {}
inoremap jk <ESC>
inoremap <C-l> <right>
inoremap <C-h> <left>
inoremap <C-j> <down>
inoremap <C-k> <up>
let mapleader="\<space>"
nnoremap <leader>d "_d
nnoremap <leader>x "_x
nnoremap yA :%y<CR>
nnoremap dA gg"_dG
xnoremap <leader>d "_d
nnoremap Zz :q<CR>
nnoremap <CR> 10j
nnoremap \ 10k
nnoremap <C-L> :nohl<CR><C-L>
noremap <leader>l gt
noremap <leader>h gT
noremap <S-l> :bn<CR>
noremap <S-h> :bp<CR>
noremap <leader>q :w<CR>:bd<CR>
nnoremap <leader>w :w<CR>
nnoremap <leader>t :NERDTreeToggle<CR>
nnoremap <leader>ff :Files<CR>
nnoremap <leader>fh :History:<CR>
nnoremap <leader>fw :Windows<CR>
nnoremap <leader>fb :Buffers<CR>
nnoremap <leader>N :FloatermNew<CR>
nnoremap <leader>n :FloatermToggle<CR>
nnoremap <F7> :FloatermPrev<CR>
nnoremap <F8> :FloatermNext<CR>
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
nnoremap <leader>e :e <C-r>=expand("%:p:h")<cr>/
" Switch CWD to the directory of the open buffer
"map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Move a line of text using ALT+[jk] or Command+[jk] on mac
nnoremap ∆ mz:m+<cr>`z
nnoremap ˚ mz:m-2<cr>`z
vnoremap ∆ :m'>+<cr>`<my`>mzgv`yo`z
vnoremap ˚ :m'<-2<cr>`>my`<mzgv`yo`z
" Pressing leader ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
"vnoremap jk <Esc>
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
tnoremap <F7> <C-\><C-n>:FloatermPrev<CR>
tnoremap <leader>n <C-\><C-n>:FloatermToggle<CR>
tnoremap <leader>N <C-\><C-n>:FloatermNew<CR>
tnoremap <F8> <C-\><C-n>:FloatermNext<CR>
tnoremap <Esc> <C-\><C-n>
tnoremap <leader>v <C-w>"*
cnoremap <C-l> <right>
cnoremap <C-h> <left>
cnoremap qq FloatermKill!<CR>:q
:set list
":set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»
:set listchars=tab:→\ ,nbsp:␣,trail:•,precedes:«,extends:»
set clipboard^=unnamed,unnamedplus
set scrolloff=3 " keep 3 lines when scrolling
set ai " set auto-indenting on for programming
set showcmd " display incomplete commands
set nobackup " do not keep a backup file
set number " show line numbers
set ruler " show the current row and column
set hlsearch " highlight searches
set incsearch " do incremental searching
set showmatch " jump to matches when entering regexp
"set mat=2
set ignorecase " ignore case when searching
set smartcase " no ignorecase if Uppercase char present
set visualbell t_vb= " turn off error beep/flash
set novisualbell " turn off visual bell
set backspace=indent,eol,start " make that backspace key work the way it should
"set runtimepath=$VIMRUNTIME " turn off user scripts, https://github.com/igrigorik/vimgolf/issues/129
set splitbelow
set laststatus=2
set linebreak
set sidescrolloff=5
set wrap
set wildmenu
set tabpagemax=50
set cursorline
"set visualbell
set title
"set background=dark
colo desert
hi CursorLine term=bold cterm=bold guibg=Grey40
set foldmethod=syntax
au BufRead * normal zR
"noremap <silent> <Leader>w :call ToggleWrap()<CR>
function WrapOn()
setlocal wrap linebreak
set virtualedit=
setlocal display+=lastline
noremap <buffer> <silent> <Up> g<Up>
noremap <buffer> <silent> <Down> g<Down>
noremap <buffer> <silent> <Home> g<Home>
noremap <buffer> <silent> <End> g<End>
inoremap <buffer> <silent> <Up> <C-o>gk
inoremap <buffer> <silent> <Down> <C-o>gj
inoremap <buffer> <silent> <Home> <C-o>g<Home>
inoremap <buffer> <silent> <End> <C-o>g<End>
endfunction
function WrapOff()
setlocal nowrap
set virtualedit=
silent! nunmap <buffer> <Up>
silent! nunmap <buffer> <Down>
silent! nunmap <buffer> <Home>
silent! nunmap <buffer> <End>
silent! iunmap <buffer> <Up>
silent! iunmap <buffer> <Down>
silent! iunmap <buffer> <Home>
silent! iunmap <buffer> <End>
endfunction
function ToggleWrap()
if &wrap
echo "Wrap OFF"
call WrapOff()
else
echo "Wrap ON"
call WrapOn()
endif
endfunction
call WrapOn()
" Returns true if paste mode is enabled
"function! HasPaste()
"if &paste
"return 'PASTE MODE '
"endif
"return ''
"endfunction
" Don't close window, when deleting a buffer
" command! Bclose call <SID>BufcloseCloseIt()
"function! <SID>BufcloseCloseIt()
"let l:currentBufNum = bufnr("%")
"let l:alternateBufNum = bufnr("#")
"if buflisted(l:alternateBufNum)
"buffer #
"else
"bnext
"endif
"if bufnr("%") == l:currentBufNum
"new
"endif
"if buflisted(l:currentBufNum)
"execute("bdelete! ".l:currentBufNum)
"endif
"endfunction
function! CmdLine(str)
call feedkeys(":" . a:str)
endfunction
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'gv'
call CmdLine("Ack '" . l:pattern . "' " )
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
function! <SID>StripTrailingWhitespaces()
if !&binary && &filetype != 'diff'
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
keeppatterns %s/\n\{3,}/\r\r/e
call winrestview(l:save)
endif
endfun
autocmd BufWritePre,FileWritePre,FileAppendPre,FilterWritePre * :call <SID>StripTrailingWhitespaces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment