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
188
189
190
191
192
193
|
" NeoVim init.vim
"
" Differences with good ol' Vim:
"
" NeoVim has so many of the modern and helpful Vim options on by default. I'll
" remove most of the old Vim configurations that now come by default in NeoVim.
"
" Also NeoVim uses XDG directories by default, keeping a clean directory tree.
"
" NeoVim also allows for this file to be written in Lua. I'll stick to using
" Vim script becuase it has more documentation and is more concise configuring
" Vim options.
"
" Instead of viminfo, NeoVim uses shada files (SHared DAta) (different format).
" See shada-file-name.
"
" For some reason, as of version v0.8.3 of NeoVim, Vim internal codes for shift-
" and control- function keys change in NeoVim. <S-F1> changes to <F13>, and
" <C-F1> changes to <F25>. See https://github.com/neovim/neovim/issues/7384
"
" Plugins: There are a lot of ways to install "plug-in"s in Vim. My prefered
" way is using Vim packages, available since Vim version 8. See packages.
"
" Tips:
" * To show navigate help files:
" K " while on an option to see it's documentation
" CTRL-] " navigation while on a Vim help file
" * To re-indent:
" tab->spaces :set tabstop=n :set expandtab :retab
" spaces->tab :set noexpandtab :set tabstop={softtabstop} :retab!
" * To justify:
" To 'justify' comments or block of text (paragraph) use `gq{motion}` or
" `gp{motion}`, where {motion} can be `[/`, `]/`, `ip`, `i{`, `a{`.
" * To see the last page of previous command:
" `g<`
" * Buffer stuff:
" :ls " shows all buffers
" :b N " Go to buffer N (integer)
" Settings
" ----------------------------------------------------------------------
" Common
colorscheme industry
filetype plugin on
" Command line:
set cmdheight=1
set wildmenu
set wildignore+=*.o,.git,*.class
set path+=./**30 " For gf and :find, add all subdirectories relative to
" current file (30 max) to the "search space"
" Search
set ignorecase
set smartcase
" Screen
set nonumber
set scrolloff=5 " show a few lines of context
set colorcolumn=+1 " show ruler at position tabstop+1
set laststatus=2
" Add buffer number to the default status line with ruler
set statusline=%<%f\ %h%m%r%=b%02n\ \ %-14.(%l,%c%V%)\ %P
" TODO: move to ftplugin
" TODO: create tags automatically (:!ctags -R . after :w if ft=c)
" Tag Jumping
" Instructions: create tag index (e.g. $ ctags -R .)
" place cursor on tag
" ^] to jump to definition
" g^] if more than 1 definition
" ^T to return (or ^O)
"set cindent
"set cinoptions=:0,g0 " See C-indenting
" Indentation: 4 spaces
" See also: autoindent, smartindent, cindent, indentexpr
set tabstop=4 " Each '\t' takes 8 virtual (screen) columns
set shiftwidth=0 " (Auto)indentation. Also affects: >>, i_C-T, i_C-D
set expandtab " Expand inserted <Tab>s with <Space>
set smartindent " Smart indenting when starting a new line
" Formatting: See fo-table
set formatoptions+=t " auto-wrap text (when inserting)
set formatoptions+=c " auto-wrap comments (when inserting)
set formatoptions+=q " Allow formatting of comments with "gq"
set formatoptions+=j " Removes comment leader when joining lines
set formatoptions+=l " Don't break long lines that are already typed
set formatoptions+=r " Insert current leader after <Enter> in Insert mode
set formatoptions+=p " Don't break honorifics like Prof. Smith
set formatoptions+=n " Recognize numbered lists
set formatoptions+=o " Automatically insert the current comment
" leader after `o`.
" Wrap: Auto-break lines longer than 80 colums
set textwidth=80
set wrap
set linebreak " Don't break words
" Mouse
set mouse=a " Enable mouse for all modes
" Buffers
set hidden " Allow for hidden modified buffers
" Split
set splitbelow splitright
" Mappings
" ----------------------------------------------------------------------
let $VIMFILES = split(&rtp, ",")[0]
map <F5> :source $VIMFILES/init.vim<CR>
map <F17> :e $VIMFILES/init.vim<CR>
map <F7> :tabp<CR>
map <F8> :tabn<CR>
map <F19> :bNext<LF>
map <F20> :bnext<LF>
" TODO: move to ftplugin
" C/C++ Programming:
map <F6> :w<CR>:!clear && make<CR>
"map <F10> :!./%:r<CR>
"map <F10> :!./a.out<CR>
map <F11> :cnext<CR>
map <S-F11> :cprev<CR>
" "Run cTags"
map <Leader>rt :!ctags -R .<CR>
map <C-\> :tnext<CR>
" Motion to go to beggining of function while cursor is inside
nmap [f [m[{k0
" pandoc (& website):
nnoremap mm :w<CR>:Md2Html<CR><CR><CR>
nmap mM mm:!updatewebsite_zaz<CR><CR>
" asciidoctor:
nnoremap ma :w<CR>:!asciidoctor %<CR><CR>
nmap mA ma:!updatewebsite.sh<CR><CR>
" Funcionallity of the following depends on terminal emulator. Needs 8-bit
" input enabled
" for <Meta> = Alt key combos
" From: https://vim.fandom.com/wiki/Get_Alt_key_to_work_in_terminal
nmap <M-H> <C-W>h
nmap <M-J> <C-W>j
nmap <M-K> <C-W>k
nmap <M-L> <C-W>l
" Go Title Case (and clear highlighted matches)
" Ref.: https://vim.fandom.com
vmap gt :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g<CR><C-L>
" Autoformat JSON jumbled data
" Ref.: https://stackoverflow.com/questions/26214156/how-to-auto-format-json-on-save-in-vim
nnoremap gJ :%!python3 -m json.tool<CR>
" Replaces previous WORD arithmetic expression with result (from Vim
" fandom-wiki)
inoremap <C-A> <Esc>diWi<C-R>=<C-R>"<CR>
" Views and Sessions (Window layout and Line folding)
" ----------------------------------------------------------------------
" It is possible to create folds automatically but idk how to do it.
" :mkview so save them :loadview to load them (zo open one, zc close one,
" zR to open all, zM to close all, zx to restore))
" Views saves folds. Sessions saves all windows configuration and layout
" Load Sessions with $ vim -S Session.vim
" To automatically save and restore views for *.c *.cpp files:
"au BufWinLeave *.c mkview
"au BufWinEnter *.c silent loadview
"au BufWinLeave *.cpp mkview
"au BufWinEnter *.cpp silent loadview
" Playground
" ----------
"autocmd FileType tex nnoremap <buffer> <F6> :!./build.sh %<CR>
"augroup TeX
" autocmd!
" autocmd BufWritePost *.tex !./build.sh %
"augroup END
|