1c612e4a09164f9550738c9cc9ba3210e1f19491
dblume Remove explicit settings th...

dblume authored 8 months ago

1) " Version 2024-03-07.1 - First misc fixes
dblume Add Neovim configs

dblume authored 8 months ago

2) set bs=2            " allow backspacing over everything in insert mode
3) set smartindent     " Do smart auto indenting when starting  new line
4) set foldlevel=99
5) set nowrap          " no wrapping text lines on the screen (exceptions below)
6) set sidescroll=5
7) set listchars+=tab:>-,precedes:<,extends:>,nbsp:· " for :set list
8) set iskeyword+=-    " Add - to list of non-word-breaking chars.
9) set scrolloff=0     " EC2 defaults to 5. Set explicitly to be consistent
10) set notermguicolors " Only needed for neovim while I port my color schemes
dblume Remove explicit settings th...

dblume authored 8 months ago

11) set undofile        " undo even after closing and reopening a file
dblume Small responsiveness improv...

dblume authored 8 months ago

12) set noshowcmd       " Show size of selected area in visual mode on last line
13) set noruler         " Show coordinates on status line
dblume nvim set hidden

dblume authored 8 months ago

14) set hidden          " Don't abandon Scratch buffer when hidden.
dblume Add Neovim configs

dblume authored 8 months ago

15) 
16) " The following two lines set the use of perl regex, aka "very magic"
17) nnoremap / /\v
18) vnoremap / /\v
19) 
20) " Make j and k move to the next row, not file line
21) nnoremap j gj
22) nnoremap k gk
23) 
24) " From Steve Losh: http://learnvimscriptthehardway.stevelosh.com/chapters/10.html
25) " Map jk to ESC in insert mode (except when navigating popup menu)
26) inoremap <expr> jk pumvisible() ? '' : '<esc>'
27) inoremap <expr> j pumvisible() ? '<Down>' : 'j'
28) inoremap <expr> k pumvisible() ? '<Up>' : 'k'
29) 
30) " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
31) nnoremap <leader>v <C-w>v<C-w>l
32) nnoremap <C-h> <C-w>h
33) nnoremap <C-j> <C-w>j
34) nnoremap <C-k> <C-w>k
35) nnoremap <C-l> <C-w>l
36) 
37) " clear search highlights
38) nnoremap <cr> :noh<cr><cr>
39) 
40) " tab switches to previous/next buffer
41) nnoremap <Tab> :bp<cr>
42) nnoremap <S-Tab> :bn<cr>
43) 
44) set t_Co=256
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

45) set colorcolumn=80
dblume Add Neovim configs

dblume authored 8 months ago

46) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
47)   " Light backgrounds for GUI experiences
48)   set background=light
49)   " colorscheme peaksea
50)   colorscheme tolerable
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

51)   highlight ColorColumn ctermbg=255 guibg=#F6F6F6
dblume nvim ColorColumn was inverted

dblume authored 8 months ago

52)   highlight statusline   ctermfg=17 ctermbg=Gray  " override scheme
53)   highlight statuslineNC ctermfg=20 ctermbg=LightGray  " override scheme
dblume Add Neovim configs

dblume authored 8 months ago

54)   if has('win32')
55)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
56)   endif
57)   set lines=50 columns=100
58) else
59)   " Dark backgrounds for tty experiences
60)   set background=dark
61)   colorscheme nvim_desert
62) endif
63) 
dblume Soften the status line colo...

dblume authored 7 months ago

64) au InsertEnter * hi statusline guibg=Cyan ctermfg=26 guifg=Black ctermbg=248
dblume Add Neovim configs

dblume authored 8 months ago

65) au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=24 ctermbg=250 guifg=black guibg=#c2bfa5
66) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

67) " May want to "set mouse=" See https://neovim.io/doc/user/vim_diff.html#_default-mouse
68) " set mouse=v  " visual mode, not great in PuTTY, neovim defaults to nvi
dblume Add Neovim configs

dblume authored 8 months ago

69) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

70) " Consider neovim default "./tags;,tags"
dblume Add Neovim configs

dblume authored 8 months ago

71) set tags=tags;/
72) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

73) set history=500
dblume Add Neovim configs

dblume authored 8 months ago

74) 
dblume Retrieve git branch only on...

dblume authored 7 months ago

75) function! GitBranch()
dblume Make vim StatuslineGit() re...

dblume authored 8 months ago

76)   let l:branchname = system("git -C " . expand('%:p:h') . " rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
dblume Make git branch fit on stat...

dblume authored 8 months ago

77)   return strlen(l:branchname) > 0 ? '  │ '.l:branchname : ''
dblume Add Neovim configs

dblume authored 8 months ago

78) endfunction
79) 
dblume Only show encoding and form...

dblume authored 7 months ago

80) function! EncodingAndFormat()
81)   if (len(&fileencoding) && &fileencoding != 'utf-8') || &fileformat != 'unix'
82)     return &fileencoding?&fileencoding:&encoding .'['. &fileformat . '] │ '
83)   endif
84)   return ''
85) endfunction
86) 
dblume Add Neovim configs

dblume authored 8 months ago

87) function! Current_mode()
88)   let l:currentmode={
89)     \ 'n'  : 'NORMAL',
90)     \ 'v'  : 'VISUAL',
91)     \ 'V'  : 'V·LINE',
92)     \ '' : 'V·BLOCK',
93)     \ 's'  : 'SELECT',
94)     \ 'S'  : 'S·LINE',
95)     \ 'i'  : 'INSERT',
96)     \ 'r'  : 'I·REPLACE',
97)     \ 'R'  : 'REPLACE',
98)     \ 'Rv' : 'V·REPLACE',
99)     \ 'c'  : 'COMMAND',
100)     \}
101)     return get(l:currentmode, mode(), mode())
102) endfunction
103) 
104) function! Trim_brackets(fn)
105)   if v:version > 800
106)     return trim(a:fn, "[]")
107)   else
108)     return a:fn
109)   endif
110) endfunction
111) 
112) set statusline=\ %{Current_mode()}
113) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
dblume Retrieve git branch only on...

dblume authored 7 months ago

114) set statusline+=%{b:git_branch}
dblume Add Neovim configs

dblume authored 8 months ago

115) set statusline+=\ │\ %f
116) set statusline+=%m
117) set statusline+=\ %r
118) set statusline+=\ %=
119) set statusline+=%h
120) set statusline+=\ %{Trim_brackets(&filetype)}
121) set statusline+=\ %#StatusLineNC#
dblume Only show encoding and form...

dblume authored 7 months ago

122) set statusline+=\ %{b:enc_fmt}
123) set statusline+=%p%%\ of
dblume Drop column and line number...

dblume authored 7 months ago

124) set statusline+=\ %L\ 
dblume Add Neovim configs

dblume authored 8 months ago

125) 
126) " Fast saving
127) nmap <leader>w :w!<cr>
128) " I use relative number for cursor movement.
129) nmap <leader>r :set relativenumber!<cr>
130) nmap <leader>n :set number!<cr>
131) 
132) " Useful mappings for managing tabs
133) " Tab Previous: gT or C-PageUp
134) " Tab Next: gt or C-PageDown
135) nmap <leader>tn :tabnew
136) nmap <leader>to :tabonly<cr>
137) nmap <leader>tc :tabclose<cr>
138) nmap <leader>tm :tabmove
139) nmap <leader>1 1gt
140) nmap <leader>2 2gt
141) nmap <leader>3 3gt
142) nmap <leader>4 4gt
143) nmap <leader>5 5gt
144) nmap <leader>6 6gt
145) nmap <leader>7 7gt
146) nmap <leader>8 8gt
147) nmap <leader>9 9gt
148) 
149) " Open current buffer in new tab. Close with C-w,c
150) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
151) function! OpenCurrentAsNewTab()
152)     let l:currentView = winsaveview()
153)     tabedit %
154)     call winrestview(l:currentView)
155) endfunction
156) nmap <leader>o :call OpenCurrentAsNewTab()<CR>
157) 
158) " pastetoggle
159) nmap <leader>p :set invpaste paste?<cr>
160) 
161) " Control+p to paste onto next line
162) nmap <C-p> :pu<cr>
163) 
164) " Make netrw's Explore behave a little like NERDTreeToggle
165) " http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
166) function! ToggleNetrw()
167)   if bufwinnr("NetrwTreeListing") > 0
168)     for i in range(1, bufnr("$"))
169)       if (getbufvar(i, "&filetype") == "netrw")
170)         silent exe "bwipeout " . i
171)         return
172)       endif
173)     endfor
174)   endif
175)   silent Vexplore %:p:h
176) endfunction
177) nmap <leader>e :call ToggleNetrw()<cr>
178) 
179) " install taglist
180) let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
181) let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
182) let Tlist_Close_On_Select = 1          " Close taglist window on select
183) nmap <leader>l :TlistToggle<cr>
184) 
185) " install vim-bbye
186) nmap <leader>bd :Bdelete<cr>
187) 
188) " Visual mode mappings
189) """
190) 
191) " map sort function to a key
192) vnoremap <leader>s :sort<cr>
193) 
194) "easier moving of code blocks
195) vnoremap < <gv
196) vnoremap > >gv
197) 
198) " If too many file system events are getting triggered.
199) set nobackup       " ~ files
200) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
201) set noswapfile     " .swp files
202) 
203) " Switch between source and header files
204) function! SwitchSourceHeader()
205)   let s:ext  = expand("%:e")
206)   let s:base = expand("%:t:r")
207)   let s:cmd  = "find " . s:base
208)   if (s:ext == "cpp" || s:ext == "c")
209)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
210)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
211)   else
212)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
213)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
214)   endif
215) endfunc
216) 
217) " Demonstrates a way to look in a mirror directory
218) " function! OpenOther()
219) "    if expand("%:e") == "cpp"
220) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
221) "    elseif expand("%:e") == "h"
222) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
223) "    endif
224) " endfunc
225) 
226) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
227) function! DeleteTrailingWS()
228)   exe "normal mz"
229)   %s/\s\+$//ge
230)   exe "normal `z"
231) endfunc
232) 
233) function! OpenInOtherWindow()
234)   if winnr('$') == 1
235)     exe "wincmd F"
236)   else
237)     let curNum = winnr()
238)     let oldBuf = bufnr( "%" )
239)     if curNum == 1
240)       let othNum = 2
241)     else
242)       let othNum = 1
243)     endif
244)     exe "normal! gF"
245)     let newBuf = bufnr( "%" )
246)     let newLine = line(".")
247)     exe 'hide buf' oldBuf
248)     exe othNum . "wincmd w"
249)     exe 'hide buf' newBuf
250)     exe "normal! " . newLine . "G"
251)   endif
252) endfunc
253) 
254) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
255) nmap <silent> <leader>f :call OpenInOtherWindow()<cr>
256) 
257) if has("autocmd")
258)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
259)   " Don't let smartindent unindent the # character in Python files
260)   autocmd FileType python  inoremap # X<c-h>#
261)   autocmd FileType python,c,cpp,php,brs,sh  set expandtab  " Use spaces instead of tabs
262)   autocmd Filetype make    setl noexpandtab       " ...not for files that use tabs.
263) 
264)   " Use the vim command %retab before applying the following
265)   " two with files that have 8-space tabs.
266)   autocmd FileType c,cpp,python,php  set tabstop=4
267)   autocmd FileType c,cpp,php  set shiftwidth=4
268) 
269)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
270) 
271)   autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
272)   autocmd FileType c,cpp set foldmethod=syntax
273) 
dblume Improve focus-based switchi...

dblume authored 7 months ago

274) " https://jeffkreeftmeijer.com/vim-number/
275) augroup numbertoggle
276)   autocmd!
277)   autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu   | endif
278)   autocmd BufLeave,FocusLost,InsertEnter,WinLeave   * if &nu                  | set nornu | endif
279) augroup END
dblume Add Neovim configs

dblume authored 8 months ago

280) 
281)   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
282)   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
283)   autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
284) 
dblume Always start on first line...

dblume authored 7 months ago

285)   " When editing a file, always jump to the last cursor position...
dblume Add Neovim configs

dblume authored 8 months ago

286)   autocmd BufReadPost *
dblume Always start on first line...

dblume authored 7 months ago

287)   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
dblume Add Neovim configs

dblume authored 8 months ago

288)   \   exe "normal! g'\"" |
289)   \ endif
dblume Always start on first line...

dblume authored 7 months ago

290)   " ...except for gitcommit where we always want to start at the top
291)   autocmd FileType gitcommit exe "normal! gg"
dblume Retrieve git branch only on...

dblume authored 7 months ago

292) 
dblume Only show encoding and form...

dblume authored 7 months ago

293)   autocmd BufNewFile,BufReadPost *
294)   \ let b:git_branch = GitBranch() |
295)   \ let b:enc_fmt = EncodingAndFormat()
296)   autocmd BufEnter *
297)   \ let b:git_branch = GitBranch() |
298)   \ let b:enc_fmt = EncodingAndFormat()
dblume Add Neovim configs

dblume authored 8 months ago

299) endif
300) 
301) " This requires vim to be compiled with +python
302) " Use auto complete in insert mode with ctrl-x, ctrl-o
303) " See :help new-omni-completion for more.
304) filetype plugin on
305) set omnifunc=syntaxcomplete#Complete
306) 
307) " Torn on whether I like the omni completion preview window left open or not.
308) " autocmd CompleteDone * pclose
309) 
310) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
dblume Sensibly, in neovim <C-Spac...

dblume authored 7 months ago

311) inoremap <C-Space> <C-x><C-o>