Skip to content

Instantly share code, notes, and snippets.

@iboard
Last active September 13, 2019 12:20
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 iboard/53176a554f74b8097e4c06da795fb929 to your computer and use it in GitHub Desktop.
Save iboard/53176a554f74b8097e4c06da795fb929 to your computer and use it in GitHub Desktop.
my .vimrc file
"
" Andi Altendorfer's VIM Setup
" For macbook 'craftsman', started from scratch, 2019-05-03
" ---------------------------------------------------------
if filereadable(expand("~/.vimrc.plugins"))
source ~/.vimrc.plugins
endif
"
" BASIC SETUP
" -----------------------------------------------"
"
set path+=**
set number
set relativenumber
set tabstop=4 softtabstop=0 expandtab shiftwidth=2 smarttab
set mouse=a
set hidden
" Highlight all occurrences of a search
" See KEY MAPPING below: <leader>s to remove highlightings
set hlsearch
filetype on
let g:netrw_list_hide= '.*\.swp$'
" Set colorscheme
let g:enable_bold_font = 1
let g:enable_italic_font = 1
let g:hybrid_transparent_background = 1
let g:sierra_Pitch = 1
" colorscheme tender
colorscheme github
if filereadable(expand("~/.vim/colors/local.vim"))
source ~/.vim/colors/local.vim
colorscheme local
endif
" KEY MAPPING
" -----------------------------------------------"
let mapleader = ","
" Safe the shift-key and use ; just as :
nmap ; :
" back to last buffer
nmap <leader>b :b#<cr>
" open Vex
nmap <leader>v :Vex<cr>
" find files
nmap <leader>f :find
nmap <leader>o :Files<cr>
" Search (and replace)
" Search for the current word
nmap <silent>fw<leader> viwy<ESC>/<c-r>"<cr>
" Press c-f in visual to highlight all occurrences of the selection
vnoremap <c-f> y<ESC>/<c-r>"<CR>
" Toggle highlight
nmap <leader>r :set hlsearch!<cr>
" write and quit current buffer
nmap <leader>q :q<cr>
nmap <leader>w :w<cr>
nmap <leader>x :x<cr>
" Key mappings for programmers
nmap <leader>s viwy:vimgrep /<C-R>"/ ./lib/**/*.{ex,exs,eex}<cr>
nmap <leader>t :wall<cr>:call RunCTags()<cr>
" ZOOM current pane <leader>,z and <leader>=
" -------------------------------------------
function! ZoomWindow()
if winheight(0) >= (&lines - 4) && winwidth(0) >= (&columns - 2)
exec "resize " . g:lastwh " | vertical resize ". g:lastww
else
let g:lastwh = winheight(0)
let g:lastww = winwidth(0)
wincmd _
wincmd |
endif
endfun
nnoremap <silent> <leader>z :call ZoomWindow()<cr>
nnoremap <silent> <leader>= <C-w>=
"
" CODING SETUP
" -----------------------------------------------"
"
" General coding
syntax on
set wildignore+=**/node_modules/**,**/_build/**,**/.git/**,**/deps/**
set foldmethod=syntax
set foldlevelstart=20
" Remove trailing spaces before write
autocmd BufWritePre *{.ex,*exs,*rb,*eex,*html} %s/\s\+$//e
" Set filetype on new and read buffers
au BufNewFile,BufRead *.md set filetype=markdown
au BufNewFile,BufRead *.html.eex set filetype=html
au BufNewFile,BufRead *.ex set filetype=elixir
au BufNewFile,BufRead *.exs set filetype=elixir
" ======
" Elixir
" ======
function! RunFormatter()
exec '!mix format %'
endfunction
function! RunCurrentLineTest()
exec "!mix test %:" . line(".")
endfunction
nmap <silent>,tl :call RunCurrentLineTest()<cr>
nmap <silent>,ts :!mix test --stale<cr>
nmap <silent>,tf :!mix test % <cr>
function! RunCTags()
exec '!ctags -R --exclude=.git --exclude=node_modules --exclude=_build --exclude=deps --exclude=priv --exclude=**/*.js . &'
endfunction
set autoread
autocmd! BufWritePost *.{ex,exs} silent call RunCTags()
autocmd BufWritePost *.{ex,exs} silent call RunFormatter()
"
" AUTOSAVE SESSION PER DIRECTORY
" ==============================
fu! SaveSess()
if isdirectory(".vim")
execute 'mksession! ./.vim/session.vim'
endif
endfunction
fu! RestoreSess()
if isdirectory("./.vim")
so ./.vim/session.vim
if bufexists(1)
for l in range(1, bufnr('$'))
if bufwinnr(l) == -1
exec 'sbuffer ' . l
endif
endfor
endif
endif
endfunction
nmap <silent> <leader>ss :call SaveSess()<cr>
nmap <silent> <leader>sl :call RestoreSess()<cr>
" ------------------------------
"
" Andi Altendorfer's VIM Setup
" For macbook 'craftsman', started from scratch, 2019-05-03
" ---------------------------------------------------------
if filereadable(expand("~/.vimrc.plugins"))
source ~/.vimrc.plugins
endif
"
" BASIC SETUP
" -----------------------------------------------"
"
set path+=**
let mapleader = ","
set number
set relativenumber
filetype on
let g:netrw_list_hide= '.*\.swp$'
" Set colorscheme
let g:enable_bold_font = 1
let g:enable_italic_font = 1
let g:hybrid_transparent_background = 1
let g:sierra_Pitch = 1
colorscheme tender
" KEY MAPPING
" -----------------------------------------------"
nmap <leader>b :b#<cr>
nmap <leader>f :Vex<cr>
nmap <leader>q :q<cr>
"
" CODING SETUP
" -----------------------------------------------"
"
" General coding
syntax on
set wildignore+=**/node_modules/**,**/_build/**,**/.git/**,**/deps/**
set foldmethod=syntax
" Set filetype on new and read buffers
au BufNewFile,BufRead *.md set filetype=markdown
au BufNewFile,BufRead *.html.eex set filetype=html
au BufNewFile,BufRead *.ex set filetype=elixir
au BufNewFile,BufRead *.exs set filetype=elixir
" Elixir
function! RunFormatter()
exec '!mix format %'
endfunction
function! RunCTags()
exec '!ctags -R --exclude=.git --exclude=node_modules --exclude=_build --exclude=deps --exclude=priv % &'
endfunction
set autoread
autocmd! BufWritePost *.{ex,exs} silent call RunCTags()
autocmd BufWritePost *.{ex,exs} silent call RunFormatter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment