.vimrc config file

Published on Jun 13, 2024

  1" Enable Vundle: Vim plugin manager
  2set rtp+=~/.vim/bundle/Vundle.vim
  3call vundle#begin()
  4Plugin 'VundleVim/Vundle.vim'
  5Plugin 'scrooloose/nerdtree'       " File tree explorer with Ctrl+N
  6Plugin 'vim-airline/vim-airline'   " Stylish status bar
  7Plugin 'jiangmiao/auto-pairs'      " Automatic insertion of brackets, quotes, etc.
  8Plugin 'w0rp/ale'                  " Syntax checking and linting
  9Plugin 'honza/vim-snippets'        " Collection of useful snippets
 10Plugin 'garbas/vim-snipmate'       " Snippet management (deprecated, consider using UltiSnips or vim-snippets instead)
 11Plugin 'tomtom/tlib_vim'           " Required for some plugins
 12Plugin 'MarcWeber/vim-addon-mw-utils' " More utilities for Vim
 13Plugin 'sainnhe/sonokai'           " Beautiful colorscheme
 14Plugin 'neoclide/coc.nvim'         " Intellisense engine
 15call vundle#end()
 17" INSTALL PLUGINS WITH :PluginInstall
 19" Basic Behavior and Interface
 20set number              " Show line numbers
 21set wrap                " Wrap lines
 22set encoding=utf-8      " Use UTF-8 encoding
 23set mouse=a             " Enable mouse support
 24set wildmenu            " Visual autocomplete for command menu
 25set lazyredraw          " Redraw screen only when needed
 26set showmatch           " Highlight matching parentheses / brackets [{()}]
 27set laststatus=2        " Always show statusline
 28set ruler               " Show line and column number of the cursor
 29set signcolumn=yes      " Show sign column for LSP diagnostics
 30set clipboard=unnamedplus  " Use system clipboard
 32" Key Bindings
 33nnoremap j gj           " Move down by visual line (don't skip wrapped lines)
 34nnoremap k gk           " Move up by visual line (don't skip wrapped lines)
 35nnoremap <C-d> <C-d>zz  " Scroll down half screen
 36nnoremap <C-u> <C-u>zz  " Scroll up half screen
 37nnoremap Q <nop>        " Disable Ex mode
 38nnoremap <C-a> ggVG     " Select all text
 39nnoremap <C-c> <cmd>%y<CR> " Copy all text
 41vnoremap J :m '>+1<CR>gv=gv
 42vnoremap K :m '<-2<CR>gv=gv
 44" Toggle NERDTree file tree
 45nnoremap <C-n> :NERDTreeToggle<CR>
 47" Find and replace in all files with CTRL+S in normal mode
 48nnoremap <C-s> :%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>
 50" Vim Appearance
 51colorscheme sonokai     " Set colorscheme
 52set termguicolors       " Enable true colors support
 53autocmd vimenter * hi Normal guibg=NONE ctermbg=NONE  " Set background to transparent
 55" Use filetype-based settings
 56syntax enable           " Enable syntax highlighting
 57filetype plugin indent on  " Enable filetype-specific plugins and indentation
 59" Tab Settings
 60set tabstop=4           " Set tab width to 4 spaces
 61set expandtab           " Use spaces instead of <TAB>
 62set shiftwidth=4        " Number of spaces to use for (auto)indent
 63set softtabstop=4       " Backspace deletes up to 4 spaces
 65" Search Settings
 66set incsearch           " Highlight matches as characters are entered
 67set hlsearch            " Highlight all matches
 69" Turn off search highlighting with <CR> (carriage-return)
 70nnoremap <CR> :nohlsearch<CR><CR>
 72" Miscellaneous Settings
 73set background=dark     " Use dark background
 74set autoread            " Autoread files changed outside Vim
 75set scrolloff=8         " Minimum lines to keep above/below cursor
 76set colorcolumn=80      " Highlight column 80
 77set hidden              " Allow hiding buffers with unsaved changes
 78set undofile            " Save undo history to file
 79set undodir=$HOME/.vimundo/  " Directory for undo files
 80set backspace=eol,start,indent  " Allow backspace in insert mode
 81set whichwrap+=<,>,h,l  " Allow <BS>, <Del>, etc. in insert mode
 82set lazyredraw          " Don't redraw while executing macros
 83set magic               " Enable magic in regular expressions
 84set showmatch           " Show matching brackets when text indicator is over them
 86" Files, Backups, and Undo
 87set nobackup            " No backup files
 88set nowb                " No write backup files
 89set noswapfile          " No swap files
 91let g:snipMate = { 'snippet_version' : 1 }
 92nnoremap <SPACE> <Nop>
 93let mapleader=" "
 94set ph=10               " Max height of windows appearing
 96" CoC.nvim configuration
 97" Autocomplete and diagnostics settings
 98inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
 99inoremap <silent><expr> <C-j> coc#pum#visible() ? coc#pum#next(1) : "\<C-j>"
100inoremap <silent><expr> <C-k> coc#pum#visible() ? coc#pum#prev(1) : "\<C-k>"
102" GoTo code navigation.
103nmap <silent> gd <Plug>(coc-definition)
104nmap <silent> gy <Plug>(coc-type-definition)
105nmap <silent> gi <Plug>(coc-implementation)
106nmap <silent> gr <Plug>(coc-references)
108" Use K to show documentation in preview window.
109nnoremap <silent> K :call <SID>show_documentation()<CR>
111function! s:show_documentation()
112  if CocAction('hasProvider', 'hover')
113    call CocActionAsync('doHover')
114  else
115    call feedkeys('K', 'in')
116  endif
119" Highlight the symbol and its references when holding the cursor.
120" autocmd CursorHold * silent call CocActionAsync('highlight')
122" Symbol renaming.
123nmap <leader>rn <Plug>(coc-rename)
125" Formatting selected code.
126xmap <leader>f  <Plug>(coc-format-selected)
127nmap <leader>f  <Plug>(coc-format-selected)
128nnoremap <silent> <C-f> :call CocAction('format')<CR>
130" Update signature help on jump placeholder.
131autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
133" Applying code actions to the selected code block.
134nmap <leader>ac  <Plug>(coc-codeaction-selected)
135xmap <leader>ac  <Plug>(coc-codeaction-selected)
136" Remap keys for applying code actions at the current cursor position.
137nmap <leader>ca  <Plug>(coc-codeaction)
139" Remap keys for applying code actions for the current buffer.
140nmap <leader>cA  <Plug>(coc-codeaction-all)
142" Use `[g` and `]g` to navigate diagnostics
143" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
144nmap <silent> [g <Plug>(coc-diagnostic-prev)
145nmap <silent> ]g <Plug>(coc-diagnostic-next)