Skip to content

Instantly share code, notes, and snippets.

@Bad-ptr
Last active March 4, 2020 13:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bad-ptr/c880141ad3a68e4e4bc0 to your computer and use it in GitHub Desktop.
Save Bad-ptr/c880141ad3a68e4e4bc0 to your computer and use it in GitHub Desktop.
Vim settings, compatible with vim.tiny
scriptencoding utf-8
set nocompatible
"Basic Settings {{{1
" Encoding {{{2
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
" Text Wrapping {{{2
set nowrap
set linebreak
set textwidth=0
set showbreak=>\ \ \
set colorcolumn=85
" Bells {{{2
set noerrorbells
set novisualbell
set visualbell
set t_vb=
set tm=500
" Tabs/Spaces {{{2
set tabstop=4
set softtabstop=2
set shiftwidth=2
"set shiftround
set smarttab
set expandtab
" Emacs like tabs? {{{3
"set cindent
set cinkeys+=!<Tab>
set indentkeys+=!<Tab>
" }}}
" KeyBindings {{{2
cnoremap w!! w !sudo tee > /dev/null %
nnoremap gV `[v`]
nnoremap <leader>s :mksession<CR>
nnoremap <leader>l :set list!<CR>
inoremap ii <Esc>
vnoremap <F2> "cy:@c<cr>
nnoremap <F2> "cyy:@c<cr>
inoremap <C-e> <Esc>A
inoremap <C-a> <Esc>I
nnoremap ,/ /<C-r><C-w>
"inoremap <Tab> <Esc>lvg_"zy<Esc>==/\V<C-R>z\$<CR>:nohlsearch<CR>a
inoremap <C-x><Tab> <Tab>
nnoremap <Tab> ==
vnoremap <Tab> =
inoremap ,,, <Esc>f,a
inoremap ,,( <Esc>/(<CR>:nohlsearch<CR>a
inoremap ,,) <Esc>/)<CR>:nohlsearch<CR>a
inoremap ,,[ <Esc>/[<CR>:nohlsearch<CR>a
inoremap ,,] <Esc>/]<CR>:nohlsearch<CR>a
inoremap ,,{ <Esc>/{<CR>:nohlsearch<CR>a
inoremap ,,} <Esc>/}<CR>:nohlsearch<CR>a
" Search {{{2
set incsearch
set hlsearch
set ignorecase
set smartcase
nnoremap <leader><space> :nohlsearch<CR>
" Backups {{{2
set backup
set backupdir=~/.vim/backup,~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set backupskip=/tmp/*,/private/tmp/*
set directory=~/.vim/swp,~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set writebackup
"set nobackup
"set nowb
"set noswapfile
" Persistent undo {{{2
if has('persistent_undo')
set undodir=~/.vim/undo
if !isdirectory(&undodir)
call mkdir(&undodir,'p')
endif
set undofile
endif
" Folding {{{2
if has('folding')
set foldenable
set foldlevelstart=10
set foldnestmax=10
set foldmethod=indent
nnoremap <space> za
endif
" Other {{{2
set ffs=unix,dos,mac
set modeline
set modelines=3
set history=700
set undolevels=1000
set clipboard=unnamed
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
set lazyredraw
set notimeout ttimeout ttimeoutlen=200
set hidden
"set autowrite
"set autoread
set confirm
set switchbuf=useopen,usetab,newtab
"set number
set nonumber
set showcmd
set showmode
set ruler
"set cmdheight=2
set showtabline=2
set laststatus=2
set statusline=%<%f\ (%{&ff}/%Y)\ %-4(%m%)%-19(%3l,%02c%03V%)
set cursorline
"set cursorcolumn
set wildchar=<TAB>
set wildmenu
set wildmode=longest,list,full
set completeopt=menuone,longest
set splitbelow
set scrolloff=7
set sidescroll=5
set virtualedit=block
set whichwrap+=<,>,[,]
set showmatch
set matchtime=2
setglobal display=lastline,uhex
set formatoptions=c,q,r,t
"set background=light
"set backspace=eol,start,indent
set bs=2
set magic
set diffopt=filler,vertical,iwhite
set listchars=tab:>.,trail:~,precedes:>,extends:>
"set list
set fillchars=
set autoindent
"set copyindent
"}}}1
if !1 | finish | endif
"This will not work in vim.tiny {{{1
if exists('g:my_vimrc_loaded') && g:my_vimrc_loaded | finish | endif
" NeoVim {{{2
if has('nvim')
set background=light
endif
" Options {{{2
syntax enable
filetype plugin indent on
set mouse=i
" set paste
highlight ExtraWhitespace ctermbg=red guibg=red
set foldtext=MinimalFoldText()
" Functions {{{2
function! MkNonExDir(file, buf)
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(fnamemodify(a:file, ':p'), ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfunction
function! Rename(name, bang)
let l:curfile=expand("%:p")
let l:curpath=expand("%:h").'/'
let l:name=fnamemodify(a:name,':p')
if l:name=~#'^[/\\\\]'
execute "saveas".a:bang." ".fnameescape(l:name)
else
execute "saveas".a:bang." ".fnameescape(l:curpath.l:name)
endif
let l:oldfile=l:curfile
let l:curfile=expand("%:p")
if l:curfile !=# l:oldfile && filewritable(l:curfile)
execute "bwipe! ".fnameescape(l:oldfile)
if delete(l:oldfile)
echoerr "Could not delete ".l:oldfile
endif
endif
endfunction
function! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
\ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), l:modeline)
endfunction
function! TabIndent()
if getline(".") =~# '^\s*$'
return "\<Esc>\"_cc"
endif
let l:cc=col(".")
let l:ateol=l:cc==#col("$")
normal! ^
let l:cd=l:cc-col(".")
normal! ==
if l:cd > 0
execute "normal! ".(l:cd)."l"
if l:ateol
return "\<RIGHT>"
endif
endif
return ''
endfunction
function! ListCurrentFilePath(a,l,p)
return [expand("%:p")]
endfunction
function! ListCurrentWord(a,l,p)
return [expand("<cword>")]
endfunction
function! MinimalFoldText()
return getline(v:foldstart)
endfunction
" Autocommands {{{2
augroup vimrcaugroup
autocmd!
autocmd FileType * setlocal indentkeys+=!<Tab>
autocmd FileType Makefile set noexpandtab
autocmd FileType vim :execute "command! -buffer Ws :w <bar> source %"|
\setlocal softtabstop=4 shiftwidth=4
autocmd FileType python set tabstop=4 softtabstop=4 expandtab shiftwidth=4
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
autocmd BufWritePre * :%s/\s\+$//e
autocmd BufWritePre * :call MkNonExDir(expand('<afile>'), +expand('<abuf>'))
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
augroup END
set updatetime=1500
set completeopt+=noinsert
augroup vimrcaugroup
"autocmd!
"autocmd InsertCharPre * call <SID>MyPopupCompleteCharPre()
autocmd CursorHoldI * call <SID>MyPopupCompleteCursorHold()
autocmd MenuPopup * call <SID>MyPopupDisable()
autocmd CompleteDone * call <SID>MyPopupEnable()
augroup END
let s:mypopupcompleteinaction=1
let s:count=0
function s:MyPopupDisable()
let s:count=0
let s:mypopupcompleteinaction=0
endfunction
function s:MyPopupEnable()
let s:count=0
let s:mypopupcompleteinaction=1
endfunction
function s:MyPopupComplete(inchr)
let AsciiCode=char2nr(a:inchr)
if (AsciiCode <=# 122 && AsciiCode >=# 97) || (AsciiCode <=# 90 && AsciiCode >=# 65)
let s:count+=2
if s:count >=# 2
call <SID>MyPopupDisable()
call feedkeys("\<c-n>\<c-n>")
"if (pumvisible())
" call feedkeys("\<c-n>\<down>")
"endif
endif
else
call <SID>MyPopupEnable()
endif
endfunction
function s:MyPopupCompleteCursorHold()
if (s:mypopupcompleteinaction)
call <SID>MyPopupComplete(strcharpart(getline('.')[col('.') - 2:], 0,1))
endif
endfunction
function s:MyPopupCompleteCharPre()
if (s:mypopupcompleteinaction)
call <SID>MyPopupComplete(v:char)
endif
endfunction
" Commands {{{2
command! -nargs=+ -bang -complete=customlist,ListCurrentFilePath
\ Rename :call Rename("<args>","<bang>")
"cnoreabbrev Rename Rename <C-r>=expand('%:p')<CR>
command! -nargs=0 Bd set buflisted | bp | sp | bn | bd
command! -nargs=+ -complete=customlist,ListCurrentWord
\ Rgrep execute 'silent grep -R -I -n . -e <args>'|
\copen|execute 'silent /<args>'|redraw!
" KeyBindings {{{2
let mapleader=","
nnoremap ,k :Bd<cr>
nnoremap ,ml :call AppendModeline()<cr>
vnoremap <F2> "cy:<c-u>exe join(split(getreg("c"),"\n"),'<bar>')<cr>
nnoremap <F2> :exe getline(".")<cr>
noremap ,cc :<C-B>silent <C-E>s/\V\s\*\zs\.\*/\=
\printf(&commentstring,matchstr(getline("."),'\s*\zs.*'))/<CR>
\:nohlsearch<CR>
noremap ,cu :<C-B>silent <C-E>s/\V\^\(\s\*\)<C-R>=
\escape(get(split(&commentstring,'%s'),0,''),'\/').'\\|\s\*'.
\escape(get(split(&commentstring,'%s'),1,''),'\/')
\<CR>\s\*\$/\1/g<CR>:nohlsearch<CR>
inoremap <Tab> <C-R>=TabIndent()<CR>
" Abbreviations {{{2
inoreabbrev <expr> >>>DATE<<< strftime('%d/%m/%Y %H:%M')
" Plugins {{{2
let s:my_plugins_dir="~/.vim/bundle"
let s:my_plugins=['fuzzyfinder', 'autocomplpop', 'vim-rsi'
\ , 'vim-multiple-cursors', 'vim-qfreplace'
\ , 'gundo.vim', 'tagbar', 'changesPlugin', 'vim-signify'
\ , 'ZoomWin', 'GoldenView.Vim'
\ , 'a.vim', 'sparkup', 'wrap-with.vim'
\ , 'vim-polyglot']
if !exists('s:my_plugins')
let s:my_plugins=glob(s:my_plugins_dir.'/*',1,1)
else
let s:my_plugins=map(s:my_plugins,'s:my_plugins_dir."/".v:val')
endif
if exists('s:my_plugins_exclude')
let s:my_plugins=filter(s:my_plugins,"v:val !~# '".join(s:my_plugin_exclude,'\|')."'")
endif
if exists('s:my_plugins_include')
let s:my_plugins=filter(s:my_plugins,"v:val =~# '".join(s:my_plugins_include,'\|')."'")
endif
" Libs {{{3
execute 'set runtimepath+='.s:my_plugins_dir.'/l9'
" }}}
execute "set runtimepath+=".join(s:my_plugins,',')
" FuzzyFinder {{{3
let g:fuf_dataDir="~/.vim/.vim-fuf-data"
nnoremap <leader>b :FufBuffer<cr>
nnoremap <leader>f :FufFileWithCurrentBufferDir<cr>
nnoremap <leader>d :FufDirWithCurrentBufferDir<cr>
nnoremap <leader>g :FufLine<cr>
" Gundo {{{3
nnoremap <F3> :GundoToggle<CR>
" tagbar {{{3
let g:tagbar_autoclose=0
nnoremap <silent> <F4> :TagbarToggle<CR>
" changes {{{3
let g:changes_sign_text_utf8=1
let g:changes_linehi_diff=0
let g:changes_fixed_sign_column=1
let g:changes_fast=1
" }}}2
let g:my_vimrc_loaded=1
"}}}1
" vim:foldmethod=marker:foldlevel=0:ts=4:sw=4:tw=0:et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment