Files
Vim-tutorials/.vimrc

256 lines
7.7 KiB
VimL

" c: Automatically break comments using the textwidth value.
" r: Automatically insert the comment leader when hitting <Enter> in insert mode.
" o: Automatically insert the comment leader when hitting 'o' or 'O' in normal mode.
" n: Recognize numbered lists. When hitting <Enter> in insert mode.
" m: Automatically break the current line before inserting a new comment line.
set formatoptions+=cronm
" This sets the width of a tab character to 4 spaces.
set tabstop=4
" This sets the number of spaces used when the <Tab> key is pressed in insert
" mode to 4.
set softtabstop=4
" This sets the number of spaces used for each indentation level when using
" the '>' and '<' commands, as well as the autoindent feature.
set shiftwidth=4
" This setting enables automatic indentation, which will copy the indentation
" of the current line when starting a new line.
set autoindent
set smartindent
" This disables the automatic conversion of tabs to spaces when you press the
" <Tab> key.
set expandtab
set smarttab
" Save 1,000 items in history
set history=1000
" Show the line and column number of the cursor position
set ruler
" Display the incomplete commands in the bottom right-hand side of your screen.
set showcmd
" Display completion matches on your status line
set wildmenu
" Show a few lines of context around the cursor
set scrolloff=5
" Highlight search matches
set hlsearch
" Enable incremental searching
set incsearch
" Ignore case when searching
set ignorecase
" Override the 'ignorecase' option if the search pattern contains upper case characters.
set smartcase
" This enables the use of the mouse in all modes (normal, visual, insert,
" command-line, etc.).
set mouse=a
" This displays line numbers in the left margin.
set number
" This disables the creation of backup files.
set nobackup
set hidden
" This disables the creation of swap files.
set noswapfile
" Automatically reload files when they change
set autoread
" Enable spell checking
set spell
set spelllang=en
" Highlight the current line
set cursorline
" Highlight the 100th column
set colorcolumn=100
" Set text width to 100
set textwidth=100
" This maps the '<' and '>' keys in visual mode to shift the selected text one
" shift width to the left or right and reselect the shifted text.
vnoremap < <gv
vnoremap > >gv
" The next four lines define key mappings for switching between windows using
" Ctrl + hjkl keys
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
" The next four lines define key mappings for resizing windows using Alt +
" hjkl keys:
map <a-l> :vertical res -5<CR>
map <a-h> :vertical res +5<CR>
map <a-j> :res -5<CR>
map <a-k> :res +5<CR>
" These lines define key mappings for moving the cursor 10 spaces at a time
" using Shift + arrow keys:
nmap <S-l> 10l<CR>
nmap <S-h> 10h<CR>
nmap <S-j> 10j<CR>
nmap <S-k> 10k<CR>
" Enable folding
set foldenable
" Configure fold method
set foldmethod=marker
" Set the fold level to start with all folds open
set foldlevelstart=99
" Set the fold nesting level (default is 20)
set foldnestmax=10
" Automatically close folds when the cursor leaves them
set foldclose=all
" Open folds upon all motion events
set foldopen=all
" To install vim-plug
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" To install the plugin
call plug#begin()
Plug 'dense-analysis/ale' " linting and fixing code.
"Plug 'airblade/vim-gitgutter' " a git diff in the sign colomn.
Plug 'habamax/vim-asciidoctor' " Feature-full environment for ASCII Docs.
Plug 'majutsushi/tagbar' " Utility to easily browse the tag.
Plug 'mbbill/undotree' " Utility to view undo history
Plug 'morhetz/gruvbox' " retro-inspired color scheme
Plug 'luochen1990/rainbow' " For rainbow coloring of Parentheses
Plug 'preservim/nerdtree' " A filesystem explorer
Plug 'puremourning/vimspector' " A multi-language debugging plugin
Plug 'tpope/vim-dispatch' " A plugin for async executing long-running commands
Plug 'tpope/vim-fugitive' " A popular Git Wrapper.
Plug 'tpope/vim-speeddating' " A plugin that allow you to quickly adjust dates.
Plug 'vim-airline/vim-airline' " A lightweight and customizable status line.
Plug 'vim-scripts/c.vim' " A packages of tools for C and C++.
Plug 'vimwiki/vimwiki' " A personal wiki plugin for Vim.
Plug 'voldikss/vim-floaterm' " A plugin for floating terminal inside vim.
Plug 'tpope/vim-commentary' " Commenting tool
Plug 'vim-airline/vim-airline-themes' " Themes for airline
Plug 'vim-scripts/DoxygenToolkit.vim' " Doxygen support
Plug 'vim-scripts/SpellCheck' " Spell checking
call plug#end()
" Plugin enable option
" For dense-analysis/ale - linting
" Ignore git commit when linting (highly annoying)
let g:ale_pattern_options = {
\ 'COMMIT_EDITMSG$': {'ale_linters': [], 'ale_fixers': []}
\ }
let g:ale_linters = {
\ 'yaml': ['yamllint'],
\ 'cpp': ['clangtidy'],
\ 'c': ['clangtidy'],
\ 'asciidoc': ['cspell'],
\ 'markdown': ['cspell']
\ }
let g:ale_fixers = {
\ 'cpp': ['clang-format'],
\ 'c': ['clang-format']}
" Automatic fixing
autocmd FileType c nnoremap <leader>f <Plug>(ale_fix)
" General settings
let g:ale_linters_explicit = 1
let g:ale_completion_enabled = 1
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
let g:ale_set_balloons=1
let g:ale_hover_to_floating_preview=1
let g:ale_use_global_executables = 1
let g:ale_sign_column_always = 1
let g:ale_disable_lsp = 1
" C++ linting
let g:ale_cpp_clangtidy_options = '-checks=-*,cppcoreguidelines-*'
let g:ale_cpp_clangtidy_checks = ['readability-*,performance-*,bugprone-*,misc-*']
let g:ale_cpp_clangtidy_checks += ['clang-analyzer-cplusplus-doc-comments']
" C linting
let g:ale_c_clangtidy_options = '-checks=-*,cppcoreguidelines-*'
let g:ale_c_clangtidy_checks = ['readability-*,performance-*,bugprone-*,misc-*']
let g:ale_c_clangtidy_checks += ['-readability-function-cognitive-complexity']
let g:ale_c_clangtidy_checks += ['-readability-identifier-length']
let g:ale_c_clangtidy_checks += ['-misc-redundant-expression']
let g:ale_c_build_dir_names = ['build', 'release', 'debug']
" This function searches for the first clang-tidy config in parent directories and sets it
function! SetClangTidyConfig()
let l:config_file = findfile('.clang-tidy', expand('%:p:h').';')
if !empty(l:config_file)
let g:ale_c_clangtidy_options = '--config=' . l:config_file
let g:ale_cpp_clangtidy_options = '--config=' . l:config_file
endif
endfunction
" Run this for c and c++ files
autocmd BufRead,BufNewFile *.c,*.cpp,*.h,*.hpp call SetClangTidyConfig()
" For tpope/vim-fugitive - git integration.
nnoremap <Leader>gg :Git<CR>
nnoremap <Leader>gs :Git status<CR>
nnoremap <Leader>gc :Git commit<CR>
nnoremap <Leader>gb :Git blame<CR>
nnoremap <Leader>gd :Git difftool<CR>
nnoremap <Leader>gm :Git mergetool<CR>
nnoremap <Leader>gdv :Gvdiffsplit<CR>
nnoremap <Leader>gdh :Gdiffsplit<CR>
" For airblade/vim-gitgutter - git status reporting line by line
" For preservim/nerdtree: the battle tested file explorer
let g:NERDTreeWinSize = 40
nnoremap <C-n> :NERDTreeToggle<CR>
let NERDTreeIgnore = ['\.o$', '\.obj$', '\.a$', '\.so$', '\.out$', '\.git$']
let NERDTreeShowHidden = 1
" For majutsushi/tagbar: the ultimate tag bar
nmap <F8> :TagbarToggle<CR>
" For rainbow coloring of Parentheses
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle