-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
136 lines (110 loc) · 5 KB
/
Copy pathvimrc
File metadata and controls
136 lines (110 loc) · 5 KB
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
"
" .vimrc
"
" Vim configuration resource file. Specifies desired behavior for the vim editor
"
set nocompatible " Forget compatibility with Vi. Who cares about Vi?
set showmode " Show which mode you're in
set ruler " Display cursor position in the lower right corner
"set number " Line numbers. ruler makes this redundant
set showmatch " Show matching [] () {} etc...
set showcmd " Show commands as you type them
set smartindent " Let vim help with indentation
set nowrap " Do not wrap lines longer than the window
set linebreak " Wrap long lines on whitespace instead of mid-word
set scrolloff=5 " Minimum number of lines to keep above/below the cursor
set backspace=2 " Make Backspace work like you expect
set formatoptions+=ro " Automatically insert the comment character when you
" hit <Enter> (r) or o/O (o) in a comment block
set showbreak=└\ " Prefix wrapped continuation lines with '└ '
let mapleader='\' " The <leader> key for key maps
syntax enable " Syntax highlighting
filetype plugin on " Enable the filetype plugin
" Tab options
set expandtab " Soft tabs, changes tabs to spaces
set tabstop=4 " Number of spaces in a tab
set softtabstop=0 " Number of spaces in a soft tab. 0 is disabled
set shiftwidth=4 " Number of spaces in an indentation level
" Searching options
set nowrapscan " Do not wrap to the top of the file while searching
set ignorecase " Case insensitive searching
set smartcase " Except when the query includes an uppercase character
set incsearch " Begin matching query as you type it
set hlsearch " Highlight search matches
" Modeline options
set modeline " Enable the Vim modeline in files
set modelines=5 " The number of lines to check for :set commands
" Code folding
"set foldmethod=indent
"set foldenable
" Use solarized colorscheme
set background=dark
" Reduce to 256 colors for compatibility with normal terminal color palettes
let g:solarized_termcolors=256
" Increase visibility of listchars (trailing whitespace, tabs, etc.)
let g:solarized_visibility='high'
"let g:solarized_underline=0
"let g:solarized_bold=0
"let g:solarized_italic=0
colorscheme solarized_dark
" Allow saving of files as sudo when I forget to start vim using sudo
cmap w!! w !sudo tee > /dev/null %
" Clear the search highlighting. Call with `<leader>/`
nnoremap <silent> <leader>/ :set nohlsearch<CR>
" Show invisible characters. Toggle with <F10>
set nolist
set listchars=tab:\|·,trail:·,nbsp:¤,extends:>,precedes:<,eol:¬
nnoremap <silent> <F10> :set list!<CR>
" Put a vertical ruler in columns 81 and 121. Toggle with <F9>
set colorcolumn=81,121
if get(g:, 'colors_name') ==? 'solarized_dark'
highlight ColorColumn ctermbg=232
elseif get(g:, 'colors_name') ==? 'solarized_darker'
highlight ColorColumn ctermbg=233
elseif get(g:, 'colors_name') ==? 'default'
highlight ColorColumn ctermbg=234
else
highlight ColorColumn cterm=standout
set colorcolumn&
endif
nnoremap <silent> <F9> :call ToggleColorColumn()<CR>
function! ToggleColorColumn()
if &colorcolumn
setlocal colorcolumn&
else
setlocal colorcolumn=81,121
endif
endfunction
" Set the terminal title to reflect the open file. Even works with Vim tabs.
autocmd BufEnter * let &titlestring = expand("%:t") . " - %{$USER}@" . hostname() | setlocal title
autocmd VimLeave * let &titleold = $USER . "@" . hostname() | setlocal title
" Add a modeline at the beginning of a file. Call with `<leader>ml`
"
" By default, it formats the modeline as a line comment so it gets ignored by
" anything that isn't Vim. You can override the commentstring by setting
" b:ml_commentstring to something else.
nnoremap <silent> <leader>ml :call AddModeline()<CR>
function! AddModeline()
" Prefer b:ml_commentstring if it is set, otherwise use commentstring
let l:commentstring = get(b:, 'ml_commentstring', &commentstring)
let l:modeline = printf(l:commentstring, printf("vi: set ts=%d sw=%d %set %sft=%s:", &ts, &sw, &et ? '' : 'no', &wrap ? 'wrap ' : '', &ft))
call append(0, l:modeline)
endfunction
" Remove trailing whitespace from all lines. Call with `<leader>ts`
"
" Uses a substitution to remove the trailing whitespace, and the 'e' silences
" errors when the search pattern doesn't match any lines in the file. Calling
" the substitution with 'keeppatterns' prevents the substitution from being
" added to the search history, or modifying the existing substitute pattern or
" string.
"
" Uses winsaveview() and winrestoreview() to restore the window view after the
" substitution, since the substitution would scroll to the last replacement by
" default.
nnoremap <silent> <leader>ts :call RemoveTrailingWhitespace()<CR>
function! RemoveTrailingWhitespace()
let l:view = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:view)
endfunction
" vi: set ts=4 sw=4 et ft=vim: