summaryrefslogtreecommitdiffstats
path: root/init.vim
blob: d8d7d0631dccdf713d2173a5d12d94b42a1f5f50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
" Neovim init file for Harald Eilertsen
"
filetype on
syntax on
colorscheme nord "substrata
set number
filetype indent on
set nowrap
set tabstop=2
set shiftwidth=2
set expandtab
set smartindent
set autoindent
set guioptions-=T
set statusline=%q%m%r\ %f%=%y\ %c,%l/%L\ %{FugitiveStatusline()}

" highlight cursor line
set cursorline

" highlight search matches
set hlsearch

" show matching parenthesis/brackets
set showmatch

" remove whitespace on write
autocmd BufWritePre * :%s/\s\+$//e

" press esc to cancel search
noremap <silent> <Esc> :nohlsearch<Bar>:echo<CR>

" Arrow keys move visually up/down.
noremap <up> gk
noremap <down> gj

" toggle nerdtree with ctrl-o
map <C-o> :NERDTreeToggle<CR>

" Toggle word-wrap mode
" This will also fix movement keys so they move by visual
" lines instead of physical lines in word-wrap mode.
" See https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping
noremap <silent> <leader>w :call ToggleWrap()<CR>
function ToggleWrap()
  if &wrap
    echo "Wrap OFF"
    setlocal nowrap
    set virtualedit=all
    silent! nunmap <buffer> <Up>
    silent! nunmap <buffer> <Down>
    silent! nunmap <buffer> <Home>
    silent! nunmap <buffer> <End>
    silent! iunmap <buffer> <Up>
    silent! iunmap <buffer> <Down>
    silent! iunmap <buffer> <Home>
    silent! iunmap <buffer> <End>
  else
    echo "Wrap ON"
    setlocal wrap linebreak nolist
    set virtualedit=
    setlocal display+=lastline
    noremap  <buffer> <silent> <Up>   gk
    noremap  <buffer> <silent> <Down> gj
    noremap  <buffer> <silent> <Home> g<Home>
    noremap  <buffer> <silent> <End>  g<End>
    inoremap <buffer> <silent> <Up>   <C-o>gk
    inoremap <buffer> <silent> <Down> <C-o>gj
    inoremap <buffer> <silent> <Home> <C-o>g<Home>
    inoremap <buffer> <silent> <End>  <C-o>g<End>
  endif
endfunction

" Suppress excessive tex errors
let g:tex_no_error=1

function SaveSession()
    if !empty(v:this_session)
        echo "Saving session " . v:this_session
        execute "mksession! " . v:this_session
    endif
endfunction

autocmd VimLeave * :call SaveSession()
:nmap <F2> :wa<Bar>call SaveSession()<CR>:so ~/.vim/sessions/