Advertisement
gooseyard

Untitled

Sep 25th, 2023
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 12.40 KB | None | 0 0
  1. set laststatus=2
  2. set expandtab
  3. set shiftwidth=4
  4. set softtabstop=4
  5. set smarttab
  6. set expandtab
  7. set nojoinspaces
  8. set modeline
  9. set incsearch
  10. set hlsearch
  11.  
  12. " opening a new file when the current buffer has unsaved changes causes files to be hidden instead of closed
  13. set hidden
  14. set iskeyword-=_
  15. set ttyfast
  16. set backup
  17.  
  18. " in modes with folding, expand everything as much as possible
  19. set foldlevel=99
  20. set conceallevel=0
  21.  
  22. " controls where new splits appear relative to the current window
  23. set splitbelow
  24. set splitright
  25.  
  26. set lazyredraw
  27. set showmatch
  28.  
  29. " I hit this a lot
  30. noremap :W :w
  31.  
  32. " switch windows
  33. nnoremap <C-J> <C-W><C-J>
  34. nnoremap <C-K> <C-W><C-K>
  35. nnoremap <C-L> <C-W><C-L>
  36. nnoremap <C-H> <C-W><C-H>
  37.  
  38. nnoremap <leader>D "=strftime("%c")<CR>P
  39. inoremap <leader>D <C-R>=strftime("%c")<CR>
  40.  
  41. autocmd BufRead * let &l:modifiable = !&readonly
  42.  
  43. " nmap <leader>bq :bp <BAR> bd #<CR>
  44.  
  45. set tags=./TAGS;/
  46.  
  47. " Bd works like bd without touching window splits
  48. command Bd bp | sp | bn | bd
  49.  
  50. " remember where I was when reopening the file
  51. if has("autocmd")
  52.       au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  53. endif
  54.  
  55. nmap <F1> :TagbarToggle<CR>
  56.  
  57. call plug#begin()
  58. Plug 'rbgrouleff/bclose.vim'
  59. Plug 'ctrlpvim/ctrlp.vim'
  60. Plug 'chrisbra/Recover.vim'
  61. Plug 'tpope/vim-fugitive'
  62. " Plug 'Vimjas/vim-python-pep8-indent'
  63. Plug 'majutsushi/tagbar'
  64. Plug 'vim-scripts/DeleteTrailingWhitespace'
  65. Plug 'haya14busa/incsearch.vim'
  66. Plug 'SirVer/ultisnips'
  67. Plug 'tpope/vim-sensible'
  68. Plug 'ntpeters/vim-better-whitespace'
  69. Plug 'stephpy/vim-yaml'
  70. Plug 'jeetsukumaran/vim-buffergator'
  71. Plug 'psf/black'
  72. Plug 'machakann/vim-highlightedyank'
  73. Plug 'sheerun/vim-polyglot'
  74. " Plug 'vim-scripts/indentpython.vim'
  75. Plug 'lukhio/vim-mapping-conflicts'
  76. Plug 'AndrewRadev/splitjoin.vim'
  77. Plug 'fisadev/vim-isort'
  78. Plug 'ngemily/vim-vp4'
  79. Plug 'airblade/vim-gitgutter'
  80. Plug 'heavenshell/vim-pydocstring'
  81. Plug 'neovim/nvim-lspconfig'
  82. call plug#end()
  83.  
  84.  
  85. syntax on
  86. filetype plugin indent on
  87.  
  88. autocmd BufEnter * set mouse=
  89.  
  90. if !has('nvim')
  91. set ttymouse=sgr
  92. else
  93. set nofsync
  94. endif
  95.  
  96.  
  97. """" tmux-related settings
  98. " allows cursor change in tmux mode
  99. if exists('$TMUX')
  100.     let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
  101.     let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
  102. else
  103.     let &t_SI = "\<Esc>]50;CursorShape=1\x7"
  104.     let &t_EI = "\<Esc>]50;CursorShape=0\x7"
  105. endif
  106.  
  107. function! WrapForTmux(s)
  108.   if !exists('$TMUX')
  109.     return a:s
  110.   endif
  111.  
  112.   let tmux_start = "\<Esc>Ptmux;"
  113.   let tmux_end = "\<Esc>\\"
  114.  
  115.   return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
  116. endfunction
  117.  
  118. let g:pydocstring_doq_path = "/home/bailey/.pyenv/shims/doq"
  119.  
  120. let &t_SI .= WrapForTmux("\<Esc>[?2004h")
  121. let &t_EI .= WrapForTmux("\<Esc>[?2004l")
  122.  
  123. autocmd VimResized * wincmd =
  124.  
  125. let g:loaded_python_provider = 0
  126. let g:python3_host_prog = "/home/bailey/.pyenv/shims/python3"
  127.  
  128.  
  129. augroup syntax
  130.   autocmd!
  131.   autocmd FileType ruby setlocal shiftwidth=2 softtabstop=2
  132.   autocmd FileType make setlocal noexpandtab tabstop=8 softtabstop=8 shiftwidth=8 autoindent
  133.   autocmd FileType text setlocal wrap linebreak nolist textwidth=80 wrapmargin=0 autoindent
  134.   autocmd FileType python setlocal tabstop=4 softtabstop=4 shiftwidth=4 colorcolumn=89 textwidth=0 wrapmargin=0 expandtab autoindent fileformat=unix
  135.   autocmd FileType markdown setlocal wrap linebreak textwidth=78 wrapmargin=2 autoindent
  136.   autocmd FileType c setlocal cindent cinoptions=>4,(0,W4
  137.   autocmd FileType c setlocal comments=s1:/*,ex:*/
  138.   autocmd FileType cpp setlocal cindent cinoptions=>4,(0,W4
  139.   autocmd FileType cpp setlocal comments=s1:/*,ex:*/
  140.   autocmd FileType gitcommit setlocal autoindent
  141. augroup END
  142.  
  143. augroup filetypes
  144.   autocmd!
  145.   autocmd BufNewFile,BufRead akamake set filetype=make
  146.   autocmd BufNewFile,BufRead host.lib set filetype=perl
  147.   autocmd BufNewFile,BufRead *.mak.in set filetype=make
  148.   autocmd BufNewFile,BufRead *.mak set filetype=make
  149.   autocmd BufNewFile,BufRead akamake.m.* set filetype=make
  150.   autocmd BufNewFile,BufRead akamake-env.mak.* set filetype=make
  151.   autocmd BufNewFile,BufRead akamake*template* set filetype=make
  152.   autocmd BufNewFile,BufRead akamake-bootstrap set filetype=make
  153.   autocmd BufNewFile,BufRead .akamake.conf set filetype=make
  154.   autocmd BufNewFile,BufRead r2.m4 set filetype=make
  155.   autocmd BufNewFile,BufRead *.ronn set filetype=markdown
  156.   autocmd BufNewFile,BufRead /home/bailey/.p4temp/* set filetype=perforce
  157.   autocmd BufNewFile,BufRead .dbattery-profiles  set filetype=json
  158. augroup END
  159.  
  160. " automatically set paste when pasting via terminal
  161. function! XTermPasteBegin()
  162.   set pastetoggle=<Esc>[201~
  163.   set paste
  164.   return ""
  165. endfunction
  166.  
  167. inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
  168.  
  169. highlight ExtraWhitespace ctermbg=red guibg=red
  170. hi Visual term=reverse cterm=reverse guibg=Grey
  171.  
  172. match ExtraWhitespace /\s\+$/
  173. autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
  174. autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  175. autocmd InsertLeave * match ExtraWhitespace /\s\+$/
  176. autocmd BufWinLeave * call clearmatches()
  177.  
  178.  
  179. """" ctrl-p settings
  180. set runtimepath^=~/.vim/plugged/ctrlp.vim
  181. let g:ctrlp_map = '<c-p>'
  182. let g:ctrlp_cmd = 'CtrlP'
  183. " let g:ctrlp_custom_ignore = '\Vvenv\|build/\|~$'
  184.  
  185. let g:ctrlp_custom_ignore = {
  186.   \ 'dir':  '\.git$\|.tox\|\venv\|build$|debian$|log\|tmp$',
  187.   \ 'file': '\~$\|\.dat$|\.DS_Store$'
  188.   \ }
  189.  
  190. let g:ctrlp_mruf_default_order = 1
  191.  
  192. " close quickfix automatically if its the last window
  193. au BufEnter * call MyLastWindow()
  194. function! MyLastWindow()
  195.   " if the window is quickfix go on
  196.   if &buftype=="quickfix"
  197.     " if this window is last on screen quit without warning
  198.     " if winbufnr(2) == -1
  199.     if winnr('$') < 2
  200.       quit
  201.     endif
  202.   endif
  203. endfunction
  204.  
  205.  
  206. function! s:Diff_fn()
  207.   let filetype=&ft
  208.   diffthis
  209.   vnew | r # | normal! 1Gdd
  210.   diffthis
  211.   exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  212. endfunction
  213. com! Diff call s:Diff_fn()
  214.  
  215.  
  216. if v:version > 703 || v:version == 703 && has('patch541')
  217.   set formatoptions+=j
  218. endif
  219.  
  220. vnoremap < <gv
  221. vnoremap > >gv
  222.  
  223. function! GitBranch()
  224.   return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
  225. endfunction
  226.  
  227. function! StatuslineGit()
  228.   let l:branchname = GitBranch()
  229.   return strlen(l:branchname) > 0?'  '.l:branchname.' ':''
  230. endfunction
  231.  
  232. function! InsertStatuslineColor(mode)
  233.   if a:mode == 'i'
  234.     hi statusline guibg=Cyan ctermfg=6 guifg=Black ctermbg=0
  235.   elseif a:mode == 'r'
  236.     hi statusline guibg=Purple ctermfg=5 guifg=Black ctermbg=0
  237.   else
  238.     hi statusline guibg=DarkRed ctermfg=1 guifg=Black ctermbg=0
  239.   endif
  240. endfunction
  241.  
  242. au InsertEnter * call InsertStatuslineColor(v:insertmode)
  243. au InsertLeave * hi statusline guibg=DarkGrey ctermfg=8 guifg=White ctermbg=15
  244.  
  245. " default the statusline to green when entering Vim
  246. hi statusline guibg=DarkGrey ctermfg=8 guifg=White ctermbg=15
  247.  
  248. " Formats the statusline
  249. set statusline=%f                           " file name
  250. set statusline+=[%{strlen(&fenc)?&fenc:'none'}, "file encoding
  251. set statusline+=%{&ff}] "file format
  252. set statusline+=%y      "filetype
  253. set statusline+=%h      "help file flag
  254. set statusline+=%m      "modified flag
  255. set statusline+=%r      "read only flag
  256.  
  257. " Puts in the current git status
  258. set statusline+=%{fugitive#statusline()}
  259.  
  260. set statusline+=\ %=                        " align left
  261. set statusline+=Line:%l/%L[%p%%]            " line X of Y [percent of file]
  262. set statusline+=\ Col:%c                    " current column
  263. set statusline+=\ Buf:%n                    " Buffer number
  264. set statusline+=\ [%b][0x%B]\               " ASCII and byte code under cursor
  265.  
  266. filetype plugin indent on
  267. let g:UltiSnipsExpandTrigger="<tab>"
  268. let g:UltiSnipsSnippetDirectories=["/home/bailey/.config/nvim/UltiSnips"]
  269.  
  270.  
  271. " for yaml
  272. au! BufNewFile,BufReadPost *.{yaml,yml} set filetype=yaml foldmethod=indent
  273. au! BufNewFile,BufReadPost Kptfile set filetype=yaml foldmethod=indent
  274. autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
  275.  
  276. function! SplitLineNicely()
  277.     " Save previous value of last search register
  278.     let saved_last_search_pattern = @/
  279.  
  280.     " :substitute replaces the content of the search register with the `\s\+`
  281.     " pattern highlighting all whitespaces in the file
  282.     substitute /\s\+/\r/g
  283.  
  284.     " Restore previous search register
  285.     let @/ = saved_last_search_pattern
  286. endfunction
  287.  
  288.  
  289. nmap <Leader>c :set cursorline! cursorcolumn!<CR>
  290. nnoremap <leader>q :execute "set colorcolumn=" . (&colorcolumn == "" ? "88" : "")<CR>
  291. nmap <Leader>h :nohlsearch<CR>
  292. nmap <Leader>n :set number relativenumber!<CR>
  293. nmap <Leader>t :TagbarToggle<CR>
  294. map <Leader>s :call SplitLineNicely<CR>
  295. nnoremap <Leader>s :<C-U>call SplitLineNicely()<CR>
  296. nmap <Leader>p :set paste!<CR>:set paste?<CR>
  297.  
  298. " Reflow paragraph
  299. nnoremap <Leader>f gqip<CR>
  300.  
  301. let g:bclose_no_plugin_maps = 1
  302. nmap <Leader>x :Bclose<CR>
  303.  
  304. let g:buffergator_suppress_keymaps = 1
  305. let g:buffergator_autoexpand_on_split = 0
  306. let g:buffergator_display_regime = 'parentdir'
  307. let g:buffergator_vsplit_size = 60
  308. nmap <silent> <Leader>b :BuffergatorOpen<CR>
  309. nmap <silent> <Leader>B :BuffergatorClose<CR>
  310.  
  311. "Remove all trailing whitespace by pressing F5
  312. nnoremap <leader>W :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
  313.  
  314. """" Python
  315.  
  316. " python set omnifunc=pythoncomplete#Complete
  317.  
  318. au BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
  319.  
  320. " Run when saving py files
  321. autocmd BufWritePre *.py :%s/\s\+$//e
  322. autocmd BufWritePre * :%s#\($\n\s*\)\+\%$##e
  323.  
  324. " Ignore these files when completing
  325. set wildignore+=*.o,*.obj,.git,*.pyc
  326. set wildignore+=eggs/**
  327. set wildignore+=*.egg-info/**
  328.  
  329. " Add the virtualenv's site-packages to vim path
  330. " if has('python')
  331. "py << EOF
  332. "import os.path
  333. "import sys
  334. "import vim
  335. "if 'VIRTUAL_ENV' in os.environ:
  336. "    project_base_dir = os.environ['VIRTUAL_ENV']
  337. "    sys.path.insert(0, project_base_dir)
  338. "    activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  339. "    execfile(activate_this, dict(__file__=activate_this))
  340. "EOF
  341. "endif
  342.  
  343. " Load up virtualenv's vimrc if it exists
  344. "if filereadable($VIRTUAL_ENV . '/.vimrc')
  345. "    source $VIRTUAL_ENV/.vimrc
  346. "endif
  347.  
  348. let g:go_version_warning = 0
  349.  
  350.  
  351. lua <<EOF
  352. -- See: https://github.com/neovim/nvim-lspconfig/tree/54eb2a070a4f389b1be0f98070f81d23e2b1a715#suggested-configuration
  353. local opts = { noremap=true, silent=true }
  354. vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  355. vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  356. vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  357. vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
  358.  
  359. -- Use an on_attach function to only map the following keys
  360. -- after the language server attaches to the current buffer
  361. local on_attach = function(client, bufnr)
  362.   -- Enable completion triggered by <c-x><c-o>
  363.   vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
  364.  
  365.   -- Mappings.
  366.   -- See `:help vim.lsp.*` for documentation on any of the below functions
  367.   local bufopts = { noremap=true, silent=true, buffer=bufnr }
  368.   vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
  369.   vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
  370.   vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
  371.   vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
  372.   vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
  373.   vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
  374.   vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
  375.   vim.keymap.set('n', '<space>wl', function()
  376.     print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  377.   end, bufopts)
  378.   vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
  379.   vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
  380.   vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
  381.   vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
  382.   vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
  383. end
  384.  
  385. -- Configure `ruff-lsp`.
  386. -- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ruff_lsp
  387. -- For the default config, along with instructions on how to customize the settings
  388. require('lspconfig').ruff_lsp.setup {
  389.   on_attach = on_attach,
  390.   init_options = {
  391.     settings = {
  392.       -- Any extra CLI arguments for `ruff` go here.
  393.       args = {},
  394.     }
  395.   }
  396. }
  397.  
  398. EOF
  399.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement