-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
146 lines (125 loc) · 4.5 KB
/
vimrc
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
set nocompatible " not vi compatible
"------------------
" Syntax and indent
"------------------
syntax on " turn on syntax highlighting
set showmatch " show matching braces when text indicator is over them
" highlight current line, but only in active window
augroup CursorLineOnlyInActiveWindow
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
filetype plugin indent on " enable file type detection
set autoindent
"---------------------
" Basic editing config
"---------------------
set shortmess+=I " disable startup message
set nu " number lines
"set rnu " relative line numbering
set incsearch " incremental search (as string is being typed)
set hls " highlight search
set listchars=tab:>>,nbsp:~ " set list to see tabs and non-breakable spaces
set lbr " line break
set scrolloff=5 " show lines above and below cursor (when possible)
set noshowmode " hide mode
set backspace=indent,eol,start " allow backspacing over everything
set timeout timeoutlen=1000 ttimeoutlen=100 " fix slow O inserts
set lazyredraw " skip redrawing screen in some cases
set autochdir " automatically set current directory to directory of last opened file
set hidden " allow auto-hiding of edited buffers
set history=8192 " more history
set nojoinspaces " suppress inserting two spaces between sentences
" use 4 spaces instead of tabs during formatting
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
" smart case-sensitive search
set ignorecase
set smartcase
" tab completion for files/bufferss
set wildmode=longest,list
set wildmenu
set mouse+=a " enable mouse mode (scrolling, selection, etc)
if &term =~ '^screen'
" tmux knows the extended mouse mode
set ttymouse=xterm2
endif
set laststatus=2
hi User1 ctermbg=black ctermfg=lightgrey guibg=black guifg=white
hi User2 ctermbg=lightgreen ctermfg=black guibg=lightgreen guifg=black
hi User3 ctermbg=lightred ctermfg=black guibg=lightred guifg=black
hi User4 ctermbg=NONE ctermfg=darkgray guibg=black guifg=darkgray
set statusline=
set statusline+=%#User1#%{(mode()=='n')?'\ \ NORMAL\ ':''}
set statusline+=%#User2#%{(mode()=='i')?'\ \ INSERT\ ':''}
set statusline+=%#User3#%{(mode()=='r')?'\ \ RPLACE\ ':''}
set statusline+=%#Cursor#%{(mode()=='v')?'\ \ VISUAL\ ':''}
set statusline+=\ %n\ " buffer number
set statusline+=%#Visual# " colour
set statusline+=%{&paste?'\ PASTE\ ':''}
set statusline+=%{&spell?'\ SPELL\ ':''}
set statusline+=%#Visual# " colour
set statusline+=%R " readonly flag
set statusline+=%M " modified [+] flag
set statusline+=%#User4#\ %F\ " short file name
set statusline+=%= " right align
set statusline+=%#Cursor#\ %Y\ " file type
set statusline+=%#User1#\ %3l:%-2c\ " line:column
set statusline+=%#User1#\ %3p%%\ " percentage
au FileType gitcommit setlocal tw=72
au FileType gitcommit setlocal cc=+1
"--------------------
" Misc configurations
"--------------------
" unbind keys
map <C-a> <Nop>
map <C-x> <Nop>
nmap Q <Nop>
" disable audible bell
set noerrorbells visualbell t_vb=
" open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
" quicker window movement
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" movement relative to display lines
nnoremap <silent> <Leader>d :call ToggleMovementByDisplayLines()<CR>
function SetMovementByDisplayLines()
noremap <buffer> <silent> <expr> k v:count ? 'k' : 'gk'
noremap <buffer> <silent> <expr> j v:count ? 'j' : 'gj'
noremap <buffer> <silent> 0 g0
noremap <buffer> <silent> $ g$
endfunction
function ToggleMovementByDisplayLines()
if !exists('b:movement_by_display_lines')
let b:movement_by_display_lines = 0
endif
if b:movement_by_display_lines
let b:movement_by_display_lines = 0
silent! nunmap <buffer> k
silent! nunmap <buffer> j
silent! nunmap <buffer> 0
silent! nunmap <buffer> $
else
let b:movement_by_display_lines = 1
call SetMovementByDisplayLines()
endif
endfunction
" toggle relative numbering
nnoremap <C-n> :set rnu!<CR>
" save read-only files
command -nargs=0 Sudow w !sudo tee % >/dev/null
"---------------------
" Local customizations
"---------------------
" local customizations in ~/.vimrc_local
let $LOCALFILE=expand("~/.vimrc_local")
if filereadable($LOCALFILE)
source $LOCALFILE
endif