Files
the_information_nexus/docs/tech_docs/linux/vim.md

4.9 KiB

Here's a basic .vimrc file structured with documentation and functionality, including some commonly used settings and plugins. This example assumes you're using Vim 8+ or Neovim, which has built-in package management capabilities. You can further customize it according to your preferences.

" .vimrc - Basic Configuration
" Author: [Your Name]
" Last Modified: [Date]

" Ensure compatibility with older Vim versions
if version < 700
  echo "You need Vim 7.0 or greater"
  finish
endif

" Prevent loading this file more than once
if exists("g:loaded_vimrc")
  finish
endif
let g:loaded_vimrc = 1

" ==============================================================================
" General Settings
" ==============================================================================

" Set UTF-8 encoding
set encoding=utf-8
set fileencoding=utf-8

" Use system clipboard
set clipboard=unnamedplus

" Enable syntax highlighting
syntax on

" Set tabs and spaces preferences for indentation
set tabstop=4       " Number of visual spaces per TAB
set softtabstop=4   " Number of spaces in tab when editing
set shiftwidth=4    " Number of spaces to use for autoindent
set expandtab       " Convert tabs to spaces

" Enable line numbers
set number

" Enable relative line numbers
set relativenumber

" Highlight current line
set cursorline

" Enable mouse support
set mouse=a

" Disable swap files
set noswapfile

" ==============================================================================
" Search Settings
" ==============================================================================

" Highlight search results
set hlsearch

" Case-insensitive searching
set ignorecase

" Case-sensitive if contains uppercase
set smartcase

" Incremental search
set incsearch

" ==============================================================================
" Visual Settings
" ==============================================================================

" Set color scheme
colorscheme desert

" Enable 256 colors
set t_Co=256

" Set status bar
set laststatus=2

" ==============================================================================
" Plugin Management (Using Vim 8+ package feature)
" ==============================================================================

" Specify directory for plugins (change '~/.vim' to '~/.config/nvim' for Neovim)
execute "set runtimepath^=~/.vim/pack/plugins/start"

" Plug: vim-plug installation and setup
" Note: For automatic installation, refer to vim-plug documentation

" ==============================================================================
" Plugins Configuration
" ==============================================================================

" Plug 'tpope/vim-surround'            " Surround text with characters
" Plug 'preservim/nerdtree'            " File system explorer
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }  " Fuzzy finder

" ==============================================================================
" Key Bindings
" ==============================================================================

" Map leader key to space
let mapleader=" "

" NERDTree toggle
nnoremap <leader>n :NERDTreeToggle<CR>

" ==============================================================================
" Custom Functions
" ==============================================================================

" Add your custom Vim functions here

" ==============================================================================
" Autocommands
" ==============================================================================

" Auto-close NERDTree on closing Vim if it's the last window
autocmd vimexit * if !argc() | NERDTreeClose | endif

" ==============================================================================
" Final Touches
" ==============================================================================

" Filetype plugin indent on
filetype plugin indent on

" Enable spell checking for certain file types
autocmd FileType gitcommit,markdown setlocal spell

" ==============================================================================
" End of .vimrc
" ==============================================================================

This .vimrc example includes essential configurations for a smooth and efficient Vim experience, such as UTF-8 encoding, tab settings, line numbering, and search behaviors. It also outlines the use of Vim's package feature for plugin management, though the actual installation of plugins like vim-plug would require additional steps not covered directly in this file.

For each plugin listed (e.g., vim-surround, nerdtree, fzf), you would typically clone the plugin's repository into the specified directory or use a plugin manager like vim-plug to automate their installation and updates.

Remember, this is a starting point. As you grow more comfortable with Vim and your personal workflow evolves, you'll likely add, remove, or tweak these settings to better suit your needs.