88066908d6543770f7ffa1071f9abc12a720552f
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) 
64) au InsertEnter * hi statusline guibg=Cyan ctermfg=20 guifg=Black ctermbg=248
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) 
80) function! Current_mode()
81)   let l:currentmode={
82)     \ 'n'  : 'NORMAL',
83)     \ 'v'  : 'VISUAL',
84)     \ 'V'  : 'V·LINE',
85)     \ '' : 'V·BLOCK',
86)     \ 's'  : 'SELECT',
87)     \ 'S'  : 'S·LINE',
88)     \ 'i'  : 'INSERT',
89)     \ 'r'  : 'I·REPLACE',
90)     \ 'R'  : 'REPLACE',
91)     \ 'Rv' : 'V·REPLACE',
92)     \ 'c'  : 'COMMAND',
93)     \}
94)     return get(l:currentmode, mode(), mode())
95) endfunction
96) 
97) function! Trim_brackets(fn)
98)   if v:version > 800
99)     return trim(a:fn, "[]")
100)   else
101)     return a:fn
102)   endif
103) endfunction
104) 
105) set statusline=\ %{Current_mode()}
106) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
dblume Retrieve git branch only on...

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

268)   " I toggle out of relative number when Vim's focus is lost, because
269)   " if I'm not editing, then I may be referring to errors with line numbers.
270)   autocmd FocusLost * if &relativenumber | set number | endif
271)   autocmd FocusGained * if &number | set relativenumber | endif
dblume Add Neovim configs

dblume authored 8 months ago

272) 
273)   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
274)   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
275)   autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
276) 
277)   " When editing a file, always jump to the last cursor position
278)   autocmd BufReadPost *
279)   \ if &ft != "p4changelist" && &ft != "gitcommit" && line("'\"") > 0 && line ("'\"") <= line("$") |
280)   \   exe "normal! g'\"" |
281)   \ endif
dblume Retrieve git branch only on...

dblume authored 7 months ago

282) 
283)   autocmd BufNewFile,BufReadPost * let b:git_branch = GitBranch()
284)   autocmd BufEnter * let b:git_branch = GitBranch()