aboutsummaryrefslogtreecommitdiff
path: root/plugin/novim-mode.vim
blob: 5df9bbae5c1c566f8b8011241d5f7c3fe8796171 (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
85
86
87
88
89
90
91
92
" Make sure insert mode is the default mode when opening/switching to files
function! InsertMode()
  if &buftype ==# 'nofile'
     \|| !&modifiable
     \|| &readonly
     \|| bufname('%') =~# 'NERD_tree_'
    exe "set noinsertmode"
  else
    exe "set insertmode"
  endif
endfunction

augroup start_insertmode
  autocmd!
  autocmd BufEnter * call InsertMode()
augroup END

" Mostly changes the way selection works.
" See: http://vimdoc.sourceforge.net/htmldoc/gui.html#:behave
" An extract from the docs about the difference between `behave mswin`
" and `behave xterm`:
"               mswin              xterm
"  'selectmode' 'mouse,key'        ''
"  'mousemodel' 'popup'            'extend'
"  'keymodel'   'startsel,stopsel' ''
"  'selection'  'exclusive'        'inclusive'
behave mswin

" Copy and paste stuff
inoremap <C-V> <C-O>p
vnoremap <C-C> y
vnoremap <C-X> x

" CTRL-A for selecting all text
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
vnoremap <C-A> <C-C>gggH<C-O>G

" Indenting
" TODO: TAB doesn't work in mswin selection mode, but SHIFT+TAB does??
vnoremap <Tab> >
vnoremap <S-Tab> <

" CTRL+q to exit pane/app
inoremap <C-Q> <C-O>:q<CR>
" Useful for exiting buffers like NERDTree that don't use insertmode
nnoremap <C-Q> :q<CR>

" Find
inoremap <C-F> <C-O>/
" Find next
inoremap <F3> <C-O>n
" Find previous
inoremap <S-F3> <C-O>N
" Clears highlighting. NB. Overriding ESC makes it very hard to get into
" NORMAL mode.
inoremap <silent> <Esc> <C-O>:noh<CR>

" Undo/redo
" Doesn't use Ctrl+Z because that's already a significant *nix shortcut
" Unfortunately Vim can't use uppercase (shifted) key combos, otherwise
" we'd use CTRL+SHIFT+U here.
inoremap <silent> <C-U> <C-O>u
inoremap <silent> <C-R> <C-O><C-R>

" CTRL+s saves
inoremap <silent> <C-S> <C-O>:update<CR>

" CTRL+k deletes the current line
inoremap <silent> <C-K> <C-O>"_dd

" CTRL+d duplicates current line
" TODO: don't put it in vim's clipboard, so CTRL+V works as expected
inoremap <silent> <C-D> <C-O>yy<C-O>p

" Alt+/- moves the current line up and down
inoremap <silent> <M--> <C-O>:m -2<CR>
inoremap <silent> <M-=> <C-O>:m +1<CR>

" Home goes back to the first non-whitespace character of the line
inoremap <silent> <Home> <C-O>^

" Allow text to wrap in text files
au BufNewFile,BufRead *.txt,*.md,*.markdown setlocal linebreak spell
" Make arrow keys move through wrapped lines
" TODO:
"   * Make this feature optional.
"   * Make End key move to end of current wrapped piece of line.
"   * Scroll window 1 wrapped soft line at a time rather an entire block of wrapped
"     lines.
au BufNewFile,BufRead *.txt,*.md,*.markdown inoremap <buffer> <Up> <C-O>gk
au BufNewFile,BufRead *.txt,*.md,*.markdown inoremap <buffer> <Down> <C-O>gj