init.vim

  1let mapleader =","
  2
  3if ! filereadable(expand('~/.config/nvim/autoload/plug.vim'))
  4    echo "Downloading junegunn/vim-plug to manage plugins..."
  5    silent !mkdir -p ~/.config/nvim/autoload/
  6    silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ~/.config/nvim/autoload/plug.vim
  7endif
  8
  9call plug#begin()
 10Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }     " FZF integration
 11Plug 'junegunn/fzf.vim'                 " FZF integration
 12Plug 'ap/vim-css-color'                 " highlight css colour codes with that color
 13Plug 'vim-airline/vim-airline'          " status bar
 14Plug 'vim-airline/vim-airline-themes'   " status bar themes
 15Plug 'tpope/vim-surround'               " highlight open/close characters like [], {}, ()
 16Plug 'cespare/vim-toml'					" toml syntax highlighting
 17Plug 'edkolev/tmuxline.vim'             " apply vim statusbar theme to tmux
 18Plug 'christoomey/vim-tmux-navigator'   " Tmux integration
 19" Plug 'chriskempson/base16-vim'        " base16 color schemes
 20" Plug 'morhetz/gruvbox'                  " gruvbox theme
 21Plug 'rhysd/vim-grammarous'				" LanguageTool integration
 22Plug 'vim-syntastic/syntastic'			" syntax checking for various languages
 23Plug 'godlygeek/tabular'                " required for aligning tables with next plugin
 24Plug 'wakatime/vim-wakatime'            " Aggregate editor stats and metrics
 25Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
 26Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
 27call plug#end()
 28
 29lua <<EOF
 30require'nvim-treesitter.configs'.setup {
 31  highlight = {
 32    enable = true,
 33    custom_captures = {
 34      -- Highlight the @foo.bar capture group with the "Identifier" highlight group.
 35      ["foo.bar"] = "Identifier",
 36    },
 37    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
 38    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
 39    -- Using this option may slow down your editor, and you may see some duplicate highlights.
 40    -- Instead of true it can also be a list of languages
 41    additional_vim_regex_highlighting = false,
 42  },
 43}
 44EOF
 45lua <<EOF
 46require'nvim-treesitter.configs'.setup {
 47  incremental_selection = {
 48    enable = true,
 49    keymaps = {
 50      init_selection = "gnn",
 51      node_incremental = "grn",
 52      scope_incremental = "grc",
 53      node_decremental = "grm",
 54    },
 55  },
 56}
 57EOF
 58lua <<EOF
 59require'nvim-treesitter.configs'.setup {
 60  indent = {
 61    enable = true
 62  }
 63}
 64EOF
 65
 66" LaTeX config
 67let g:livepreview_previewer = 'zathura'
 68let g:livepreview_use_biber = 1
 69
 70" Grammorous config
 71let g:grammarous#languagetool_cmd = 'java -cp ~/languagetool/languagetool-server.jar org.languagetool.server.HTTPServer --port 8081 --allow-origin "*"'
 72
 73" netrw configuration
 74let g:netrw_banner=0
 75let g:netrw_browse_split=4
 76let g:netrw_altv=1
 77let g:netrw_liststyle=3
 78let g:netrw_list_hide=netrw_gitignore#Hide()
 79let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
 80
 81" syntastic settings
 82set statusline+=%#warningmsg#
 83set statusline+=%{SyntasticStatuslineFlag()}
 84set statusline+=%*
 85let g:syntastic_always_populate_loc_list = 1
 86let g:syntastic_auto_loc_list = 1
 87let g:syntastic_check_on_open = 1
 88let g:syntastic_check_on_wq = 0
 89
 90""
 91" Some basics
 92""
 93" Make ctags for supported languages
 94command! MakeTags !ctags -R .
 95" Add all subdirs to working path so :find works well
 96set path+=**
 97" Status line completion menu
 98set wildmenu
 99" Set above menu to a vertical instead of horizontal list
100set wildmode=full,list,full
101" Wrap long lines that continue past the viewport
102set linebreak
103" Highlight the column the cursor is on
104set cursorcolumn
105" Highlight the line the cursor is on
106set cursorline
107" Enables more colors
108set termguicolors
109" If there are folds, close some of them on startup
110set foldlevelstart=99
111" Use system clipboard for all yanking/pasting
112set clipboard+=unnamedplus
113" Use tabs but display them as 4 spaces instead of 8
114set ts=4 sts=4 sw=4 expandtab
115" Round the indent to a multiple of sw
116set shiftround
117" Set hidden character characters
118set listchars=tab:▸\ ,eol,nbsp:␣,trail:•,space:.,extends:→,precedes:←
119set backspace=indent,eol,start
120" Keep 12 lines above and below the cursor when scrolling
121set scrolloff=12
122" Disable mouse support
123set mouse=
124" Use indents to determine folds
125set foldmethod=indent
126" Set line numbers relative to current line
127set number relativenumber
128" Show partial commands in the bottom right
129set showcmd
130" Show which mode you're in
131set showmode
132" Display partial matches when searching
133set incsearch
134" Highlight search results—hide with :noh
135set hlsearch
136" Wrap searches around the end of the file
137set wrapscan
138" Tell Vim to be more liberal with creating hidden buffers
139set hidden
140" Case-insensitive search unless term contains uppercase chars
141set smartcase
142
143" Statusbar theme
144let g:airline_powerline_fonts = 1
145let g:airline_theme='bubblegum'
146if !exists('g:airline_symbols')
147	let g:airline_symbols = {}
148endif
149
150" Configure thesaurus
151let g:tq_mthesaur_file="~/.config/nvim/thesaurus/mthesaur.txt"
152let g:tq_enabled_backends=["datamuse_com","mthesaur_txt","openoffice_en"]
153
154""
155" Keybindings
156""
157" Insert timestamp at the end of the line in this format: 20200527T113245
158nnoremap <C-t><C-s> m'A<C-R>=strftime('%Y%m%dT%H%M%S')<CR>
159" Open a new tab
160nnoremap <C-t>t :tabnew<CR>
161" Toggle hidden characters
162nnoremap <C-l> :set list!<CR>
163
164" Window management
165map <C-h> <C-w>h
166map <C-j> <C-w>j
167map <C-k> <C-w>k
168map <C-l> <C-w>l
169
170" Snippets
171nnoremap ,nnm :read $HOME/.config/nvim/snippets/nnmail<CR>2jA
172nnoremap ,sig :read $HOME/.config/nvim/snippets/signature<CR>
173
174" only enable persistent undo if vim supports
175if has('persistent_undo')
176  set undodir=$HOME/.config/nvim/undofile
177  set undofile
178endif
179
180" Only enable autocommands when Vim supports them
181if has("autocmd")
182	" Disables automatic commenting on newline:
183	autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
184
185	""
186	" File-specific indentation settings
187	""
188	autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
189	autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
190
191	""
192	" Email configuration
193	""
194	" Spellcheck in British English
195	autocmd FileType eml setlocal spell spelllang=en_gb
196	" Set lines to hard wrap at 72 chars
197	autocmd FileType eml set tw=72
198
199	""
200	" Markdown Configuration
201	""
202	" Treat all .md files as markdown
203	autocmd BufNewFile,BufRead *.md set filetype=markdown
204	" Spellcheck in British English
205	autocmd FileType markdown setlocal spell spelllang=en_gb
206
207	""
208	" Working with LaTeX
209	""
210	" Reduce udpatetime for faster previews
211    autocmd BufNewFile,BufRead *.tex setfiletype tex
212    autocmd FileType tex set ut=250
213    autocmd FileType tex set colorcolumn=72
214
215endif