~ashn/setup

ref: b482741c9cb8eaf2083d5ac4fddc127ef097fc26 setup/dotfiles/.vimrc -rw-r--r-- 4.9 KiB
b482741cashn Use setlocal instead of set for language-specific indentation 2 months ago
                                                                                
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" GENERAL CONFIGURATION SETTINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible

color desert
syntax enable

filetype plugin on
filetype indent on

set encoding=utf-8
set spell spelllang=en_us

" Show line numbers by default.
set number
" Turn off wrapping by default.
set nowrap
" Turn off spellchecking by default.
set nospell
" Do not insert two spaces after a period when joining separate lines with gq.
set nojoinspaces
" Highlight matching parentheses, braces, and brackets by default.
set showmatch
" Show an 81 column magenta colorcolumn by default.
" Text left of the colorcolum is less than or equal to an 80 column width.
set colorcolumn=81
highlight ColorColumn ctermbg=DarkMagenta guibg=DarkMagenta

" TABS   : >---
" EOL SP : •
set listchars=tab:>-,trail:•
set list

" Set 6 lines to the cursor - when moving vertically using j/k.
set so=6

" Copy indent from the current line when starting a new line.
set autoindent

" Render tabs with 4 space width.
set tabstop=4
" <Tab>, '<', '>', and autoindent use spaces.
set expandtab
" <Tab>, '<', and '>', insert four spaces.
set shiftwidth=4

" Ignore case when searching.
set ignorecase
" Highlight results when searching.
set hlsearch
" Begin searching as characters are entered.
set incsearch

" Change default temp file directories to avoid clutter.
set backupdir=~//
set directory=~//
set undodir=~//

" Lisp style preferences.
autocmd FileType lisp,scheme setlocal tabstop=2 shiftwidth=2 expandtab
" HTML/JavaScript/CSS style preferences.
autocmd FileType html,javascript,json,css setlocal ts=2 sw=2 expandtab
autocmd BufNewFile,BufRead *.ts setlocal syntax=javascript ts=2 sw=2 expandtab
" Markdown style preferences.
autocmd BufNewFile,BufRead *.md setlocal ts=2 sw=2 expandtab

" Linux Kernel style preferences.
function s:SetLinuxKernelStyleConfig()
    setlocal tabstop=8
    setlocal shiftwidth=8
    setlocal noexpandtab
endfunction

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" KEY BINDINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Leader
let mapleader = " "

" Arrow keys are for wusses.
nnoremap <up>    <nop>
nnoremap <down>  <nop>
nnoremap <left>  <nop>
nnoremap <right> <nop>
inoremap <up>    <nop>
inoremap <down>  <nop>
inoremap <left>  <nop>
inoremap <right> <nop>
vnoremap <up>    <nop>
vnoremap <down>  <nop>
vnoremap <left>  <nop>
vnoremap <right> <nop>

" Remove misc commands that I never use.
nnoremap <F> <nop>
nnoremap <M> <nop>
nnoremap <S-L> <nop>
nnoremap <T> <nop>
nnoremap <U> <nop>
nnoremap <C-Y> <nop>
nnoremap <S-J> <nop>
nnoremap <S-k> <nop>
"" <S-L> does not play nice with `set so=<NUMBER>`.
nnoremap <S-L> <nop>
"" <S-M> does not play nice with `set so=<NUMBER>`.
nnoremap <S-M> <nop>
"" <S-Q> is bound to ex mode for historical compatibility.
"" It has only ever been an annoyance.
nnoremap <S-Q> <nop>

" Bash-like backspace and delete.
inoremap <C-H> <bs>
inoremap <C-D> <del>

" More natural splits.
set splitbelow
set splitright
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" Tab navigation.
nnoremap <C-n> :tabnext<Return>
nnoremap <C-m> :tabprevious<Return>
nnoremap <C-t> :tabnew<Return>

" Backtab with <shift>+<tab> in insert mode.
inoremap <S-Tab> <C-d>

" Turn off search highlight.
nnoremap <leader><space> :nohlsearch<Return>

" Toggle spellchecking.
function s:ToggleSpellCheck()
    set spell!
    if &spell
        echo "Spellcheck ON"
    else
        echo "Spellcheck OFF"
    endif
endfunction
nnoremap <silent><Leader>sp :call <SID>ToggleSpellCheck()<Return>

" Alternative write-file command.
nnoremap <leader>w :w<Return>

" Insert empty lines without entering insert mode.
nnoremap <leader>o o<Esc>^d$
nnoremap <leader>O O<Esc>^d$

" Explore bindings.
let g:netrw_liststyle=0
nnoremap <leader>ex  :Explore<Return>
nnoremap <leader>tex :Texplore<Return>
nnoremap <leader>vex :Vexplore!<Return>
nnoremap <leader>sex :Sexplore<Return>

" <F1> => Toggle number.
" NOTE: GNOME Terminal will intercept <F1> before vim.
nnoremap <silent><F1> :set number!<Return>

" <F2> => Switch color column between 80 columns, 72 columns, and off.
function s:SwitchColorColumn()
    if &colorcolumn == 81
        set colorcolumn=73
    elseif &colorcolumn == 73
        set colorcolumn=0
    else
        set colorcolumn=81
    endif
endfunction

nnoremap <silent><F2> :call <SID>SwitchColorColumn()<Return>
inoremap <silent><F2> :call <SID>SwitchColorColumn()<Return>
vnoremap <silent><F2> :call <SID>SwitchColorColumn()<Return>

" <F3> => Toggle between 'insert' and 'insert (paste)' modes.
set pastetoggle=<F3>

" <F4> => Toggle word wrap.
nnoremap <silent><F4> :set wrap!<Return>

" <F5> => Switch to Linux Kernel Editing
nnoremap <silent><F5> :call <SID>SetLinuxKernelStyleConfig()<Return>