Skip to content

Instantly share code, notes, and snippets.

@lucasgruwez
Last active December 20, 2020 00:49
Show Gist options
  • Save lucasgruwez/447c118ba0e031e813af85c3ae91eb23 to your computer and use it in GitHub Desktop.
Save lucasgruwez/447c118ba0e031e813af85c3ae91eb23 to your computer and use it in GitHub Desktop.
My .vimrc file
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
set nocompatible
" Set to auto read when a file is changed from the outside
set autoread
" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on
" Enable syntax highlighting
syntax on
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = "`"
" Autosave when leaving insert mode
autocmd InsertLeave * write
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Highlight searches (use <C-L> to temporarily turn off highlighting; see the
" mapping of <C-L> below)
" incsearch ensures results are highlighted as charachters are entered
set incsearch
set hlsearch
" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase
" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start
" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent
" Indent line breaks like they should be.
set breakindent
" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline
" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler
" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm
" Display line numbers on the left
set number relativenumber
" Always keep at least five lines above and below the cursor
set scrolloff=5
" Show current command in the bottom
set showcmd
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fast saving
nmap <leader>w :w!<cr>
" Fast quitting
nmap <leader>q :q<cr>
" Fast commenting
nmap <leader>c gcc
" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
" which is the default
map Y y$
" Map B to beginning of line, and E to end of line
map B ^
map E $
" move vertically by visual line (don't skip wrapped lines)
nmap j gj
nmap k gk
map <Down> gj
map <Up> gk
" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
nnoremap <C-L> :nohl<cr><C-L>
" Use F9 as a quick way to run python files
autocmd FileType python map <buffer> <F9> :w<CR>:exec '!python3' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F9> <esc>:w<CR>:exec '!python3' shellescape(@%, 1)<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Indentation settings for using hard tabs for indent. Display tabs as
" four characters wide.
set shiftwidth=4
set tabstop=4
" Set the encoding to UTF-8
set encoding=utf-8
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spellcheck configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType tex setlocal spell
set spelllang=en_gb
inoremap <C-l> <c-g>u<Esc>[s1z=gi<c-g>u
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins, via VimPlug
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
" VimTex pluggin for using latex in Vim
Plug 'lervag/vimtex'
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
" Vim Snips for latex snippets
Plug 'sirver/ultisnips'
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
let g:UltiSnipsEditSplit = 'vertical'
" Color scheme wal
Plug 'dylanaraps/wal'
" Comment and uncomment using "gcc" command
Plug 'tpope/vim-commentary'
" Goyo, Distraction-free writing in Vim
Plug 'junegunn/goyo.vim'
call plug#end()
" Set colorscheme
colorscheme wal
set background=dark
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Goyo settings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Shortcut for entering Goyo
nmap <leader>g :Goyo<cr>
" Ensure :q to quit even when Goyo is active
" https://github.com/junegunn/goyo.vim/wiki/Customization
function! s:goyo_enter()
let b:quitting = 0
let b:quitting_bang = 0
autocmd QuitPre <buffer> let b:quitting = 1
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction
function! s:goyo_leave()
" Quit Vim if this is the only remaining buffer
if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting_bang
qa!
else
qa
endif
endif
endfunction
autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment