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