Skip to content

Instantly share code, notes, and snippets.

@pblocz
Last active October 17, 2017 22:08
Show Gist options
  • Save pblocz/7227647f9e33d25f2229e12bfcf7b116 to your computer and use it in GitHub Desktop.
Save pblocz/7227647f9e33d25f2229e12bfcf7b116 to your computer and use it in GitHub Desktop.
"
" 0. configure proxy:
" git config --global http.proxy http://proxyuser:[email protected]:8080
" 1. Download and install vim-plug
"
" 2. Do a :PlugInstall
"
" 3. If command-t not working try `rake make` from its folder
" if not in path, install it with
" export HTTP_PROXY=<proxy>; gem install --local rake
"
" 4. For vim-airline, download patched font:
" https://github.com/powerline/fonts/blob/master/InconsolataDz/Inconsolata-dz%20for%20Powerline.otf?raw=true
"
" Add fonts to cache: `fc-cache -f /usr/share/fonts/`
"
"
"=== General settings {{{1
" if has("multi_byte")
" if &termencoding == ""
" let &termencoding = &encoding
" endif
" set encoding=utf-8 " better default than latin1
" setglobal fileencoding=utf-8 " change default file encoding when writing new files
" endif
set clipboard=unnamedplus
set expandtab
set shiftwidth=4
set softtabstop=4
set autoindent
set smartindent
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set showmode " Show current mode.
set ruler " Show the line and column numbers of the cursor.
set number " Show the line numbers on the left side.
set formatoptions+=o " Continue comment marker in new lines.
set textwidth=0 " Hard-wrap long lines as you type them.
set noerrorbells " No beeps.
set modeline " Enable modeline.
" set esckeys " Cursor keys in insert mode.
set linespace=0 " Set line-spacing to minimum.
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
" More natural splits
set splitbelow " Horizontal split below current.
set splitright " Vertical split to right of current.
if !&scrolloff
set scrolloff=3 " Show next 3 lines while scrolling.
endif
if !&sidescrolloff
set sidescrolloff=5 " Show next 5 columns while side-scrolling.
endif
set nostartofline " Do not jump to first character with page commands.
filetype plugin on
"=== General remaps and commands {{{1
let mapleader = "\<Space>"
let maplocalleader = "_"
" Esc remaps to change modes
imap <M-x> <Esc>
vmap <M-x> <Esc>
cmap <M-x> <Esc>
imap <M-i> <Esc>
vmap <M-i> <Esc>
cmap <M-i> <Esc>
" swaps some movement keys to make them behave with visual lines by default
noremap <buffer> <silent> k gk
noremap <buffer> <silent> j gj
noremap <buffer> <silent> 0 g0
noremap <buffer> <silent> $ g$
noremap <buffer> <silent> gk k
noremap <buffer> <silent> gj j
noremap <buffer> <silent> g0 0
noremap <buffer> <silent> g$ $
" associate common actions to leader for easy access
nnoremap <silent> <Leader>q :bd<CR>
nnoremap <silent> <Leader>Q :q<CR>
nnoremap <silent> <Leader>w :w<CR>
nnoremap <silent> <Leader><Leader> /\c
nnoremap <silent> <Leader>a ^
nnoremap <silent> <Leader>e $
nnoremap <silent> <Leader>v <C-v>
nnoremap <silent> <Leader>h :bprevious<CR>
nnoremap <silent> <Leader>l :bnext<CR>
" remap back and forward in the changelist
nnoremap <Leader>, g;
nnoremap <Leader>. g,
" Other useful remaps
" Oposite of J (join two lines), breaK a line
nnoremap <silent> K i<Enter><Esc>
" disable Q to enter ex mode (it doesnt behave well with <Leader>Q)
nnoremap Q <nop>
" map folds increase decrease to jk (move keys)
nnoremap <silent> zj zm
nnoremap <silent> zk zr
" provide hjkl movements and others in Insert mode via the <Alt> key
inoremap <A-h> <C-o>h
inoremap <A-j> <C-o>j
inoremap <A-k> <C-o>k
inoremap <A-l> <C-o>l
inoremap <A-o> <C-o>
inoremap <A-d> <C-o>x
command! Vimrc edit $MYVIMRC " Open to your edit .vimrc/init.vim file
"=== Plugin installation using vim-plug {{{1
"
" curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
"
call plug#begin()
" Useful for repeating functions with `.`, v.g. vim-surround
Plug 'tpope/vim-repeat'
" Hightlights all trailing whitespaces
Plug 'ntpeters/vim-better-whitespace'
" Insert or delete brackets...
Plug 'jiangmiao/auto-pairs'
" different command to interact with encasing elements (parenthesis, escapes,...)
Plug 'tpope/vim-surround'
" press v multiple times to expand visual region
Plug 'terryma/vim-expand-region'
" Fuzzy lookup for files, tags...
Plug 'wincent/command-t'
" Displays tags in a window, ordered by scope (ctags)
Plug 'majutsushi/tagbar'
" Miscellaneous auto-load Vim scripts
Plug 'xolox/vim-misc'
" Automated tag file generation and syntax highlighting of tags (ctags)
Plug 'xolox/vim-easytags'
" A tree explorer plugin for vim.
Plug 'scrooloose/nerdtree'
" Open a shell in a buffer
" Plug 'vim-scripts/Conque-Shell'
" autocomplete for vim, needs extra steps
Plug 'Valloric/YouCompleteMe', { 'do': './install.py' }
" org-mode for vim
Plug 'jceb/vim-orgmode'
" A collection of language packs for Vim.
Plug 'sheerun/vim-polyglot'
" Ada syntax highlights and more
Plug 'vim-scripts/Ada-Bundle'
" Git wrapper (status integrates with vim-airline)
Plug 'tpope/vim-fugitive'
" A Vim plugin which shows a git diff in the 'gutter' (sign column)
Plug 'airblade/vim-gitgutter'
" Uses the sign column to indicate added, modified and removed lines
Plug 'mhinz/vim-signify'
" One dark atom style
Plug 'joshdick/onedark.vim'
" Precision colors
Plug 'altercation/vim-colors-solarized'
" Vim airline
Plug 'vim-airline/vim-airline'
call plug#end()
set rtp+=~/.vim/plugged/solarized
"=== Configure colorscheme and syntax {{{1
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
endif
let g:onedark_terminal_italics = 1
syntax on
set background=dark
colorscheme onedark
" colorscheme solarized
"=== Configure vim-airline {{{1
" Use a patched font
" https://github.com/powerline/fonts/blob/master/InconsolataDz/Inconsolata-dz%20for%20Powerline.otf?raw=true
if has('gui_running')
set guifont=Inconsolata-dz\ for\ Powerline\ Medium\ 12
endif
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
" let g:airline#extensions#tabline#left_sep = ' '
" let g:airline#extensions#tabline#left_alt_sep = '|'
" let g:airline#extensions#tabline#right_sep = ' '
" let g:airline#extensions#tabline#right_alt_sep = '|'
let g:airline_powerline_fonts=1
" let g:airline_right_alt_sep = ''
" let g:airline_right_sep = ''
" let g:airline_left_alt_sep= ''
" let g:airline_left_sep = ''
" let g:airline_theme= 'gruvbox'
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#hunks#enabled = 1
let g:airline_theme='onedark'
"=== Show invisible whitespaces {{{1
set list!
set listchars=eol:¬,space:·,tab:»»,extends:>,precedes:<,trail:⎵,nbsp:␠
"=== Hack to stop highlighting search when entering INSERT {{{1
" when entering insert mode, stop highlight
autocmd InsertEnter * setlocal nohlsearch
autocmd InsertLeave * setlocal hlsearch lz
inoremap <silent><Esc> <Esc>:nohl<bar>set nolz<CR>
inoremap <silent><C-c> <C-c>:nohl<bar>set nolz<CR>
"=== Settings of vim-better-whitespace plugin {{{1
autocmd BufEnter * EnableStripWhitespaceOnSave
nnoremap <F5> :StripWhitespace<CR>
"=== tagbar plugin config {{{1
nmap <F8> :TagbarToggle<CR>
"=== maps for surround.vim {{{1
nmap Ss ys
nmap Sl yss
nmap Sw ysiw
nmap SW ysiW
nmap Sc cs
nmap Sd ds
" no need to replace in VISUAL, it already uses S
"=== Command-T configuration {{{1
" it already uses "<Leader>t", "<Leader>b" and "<Leader>j" for files, buffers
" and jumplist respectively
" If there is a perl error try going to command-t/ and doing `rake make`
nmap <silent> <Leader>f <Plug>(CommandT)
nmap <silent> <Leader>x <Plug>(CommandTCommand)
nmap <silent> <Leader>t <Plug>(CommandTTag)
"=== vim-expand-region configuration {{{1
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
"=== NerdTree configuration {{{1
map <silent> <Leader>F :NERDTreeToggle<CR>
"=== ycm configuration (see also ultisnips conf) {{{1
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_autoclose_preview_window_after_insertion=1
"=== ultisnips configuration {{{1
" make YCM compatible with UltiSnips (using supertab) [it doesn't work]
"let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
"let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
"let g:SuperTabDefaultCompletionType = '<C-n>'
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<C-n>"
let g:UltiSnipsJumpForwardTrigger="<C-n>"
let g:UltiSnipsJumpBackwardTrigger="<C-N>"
"=== auto-pairs config {{{1
let g:AutoPairsMapSpace=0 " disabled to allow editing markdown, in check fields [ ] it inserted 2 spaces
"=== tip to view scriptnames in buffer: http://vim.wikia.com/wiki/List_loaded_scripts {{{1
function! s:Scratch (command, ...)
redir => lines
let saveMore = &more
set nomore
execute a:command
redir END
let &more = saveMore
call feedkeys("\<cr>")
new | setlocal buftype=nofile bufhidden=hide noswapfile
put=lines
if a:0 > 0
execute 'vglobal/'.a:1.'/delete'
endif
if a:command == 'scriptnames'
%substitute#^[[:space:]]*[[:digit:]]\+:[[:space:]]*##e
endif
silent %substitute/\%^\_s*\n\|\_s*\%$
let height = line('$') + 3
execute 'normal! z'.height."\<cr>"
0
endfunction
command! -nargs=? Scriptnames call <sid>Scratch('scriptnames', <f-args>)
command! -nargs=+ Scratch call <sid>Scratch(<f-args>)
" view hightlight under cursor: http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
"=== add TODO, DONE,... keywords highlight to markdown {{{1
augroup vimrc_todo
au!
au Syntax markdown syn match MyTodo /\C\v<(TODO|FIXME|BUG):?/ containedin=htmlH.*,mkdListItemLine
au Syntax markdown syn match MyDone /\C\v<(DONE):?/ containedin=htmlH.*,mkdListItemLine
augroup END
hi myTodo cterm=bold ctermfg=170 gui=bold guifg=#C678DD
" hi def link myTodo Statement
hi def link myDone Type
"=== add :Shell command to open a new scratch buffer and execute command {{{1
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
echo a:cmdline
let expanded_cmdline = a:cmdline
for part in split(a:cmdline, ' ')
if part[0] =~ '\v[%#<]'
let expanded_part = fnameescape(expand(part))
let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
endif
endfor
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1, 'You entered: ' . a:cmdline)
call setline(2, 'Expanded Form: ' .expanded_cmdline)
call setline(3,substitute(getline(2),'.','=','g'))
execute '$read !'. expanded_cmdline
setlocal nomodifiable
1
endfunction
" Same as Shell but uses the content of current buffer as command input
command! -complete=shellcmd -nargs=+ IShell call s:RunStdInShellCommand(<q-args>)
function! s:RunStdInShellCommand(cmdline)
echo a:cmdline
let expanded_cmdline = a:cmdline
for part in split(a:cmdline, ' ')
if part[0] =~ '\v[%#<]'
let expanded_part = fnameescape(expand(part))
let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
endif
endfor
let temp_reg = @"
silent %yank "
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
silent put! "
let @" = temp_reg
silent execute '% !'. expanded_cmdline
setlocal nomodifiable
endfunction
"=== Modelines: {{{1
" vim:fdm=marker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment