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

8.7 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.


Enhancing your .vimrc file to support syntax highlighting for Python, JavaScript, Markdown, and Lua, alongside other quality-of-life improvements using Vim's built-in capabilities, is straightforward. Here's an updated section to include in your .vimrc file, focusing on syntax support and quality-of-life enhancements:

" Enhanced .vimrc Configuration for Syntax Support and Improvements

" ==============================================================================
" General Enhancements
" ==============================================================================

" Enable line numbers
set number

" Enable relative line numbers for easier text navigation
set relativenumber

" Enable syntax highlighting
syntax enable

" Show matching parentheses/brackets
set showmatch

" Automatically indent new lines
set autoindent
set smartindent

" Set search to be case insensitive unless capital letter is used
set ignorecase
set smartcase

" Enable mouse in all modes
set mouse=a

" Use 24-bit (true color) support
if exists('+termguicolors')
  set termguicolors
endif

" Set command line height to 2 lines for more visibility
set cmdheight=2

" Show a visual indicator for lines that exceed a certain length (e.g., 80 characters)
set colorcolumn=80

" ==============================================================================
" Filetype-specific Enhancements
" ==============================================================================

" Enable filetype plugins
filetype plugin on
filetype indent on

" Syntax highlighting for Python, JavaScript, Markdown, Lua
au BufRead,BufNewFile *.py,*.js,*.md,*.lua setlocal syntax=on

" For Python: Set tab space
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab

" For JavaScript: Set tab space
autocmd FileType javascript setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab

" For Markdown: Enable spell checking and wrap text
autocmd FileType markdown setlocal spell textwidth=80 wrap

" For Lua: Set tab space
autocmd FileType lua setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab

" ==============================================================================
" Additional Quality-of-Life Improvements
" ==============================================================================

" Use incremental search
set incsearch

" Highlight search results
set hlsearch

" Map <leader> to a space (or your preferred leader key)
let mapleader=" "

" Disable creating backup files
set nobackup
set nowritebackup

" Disable swap files
set noswapfile

" Open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright

" Enable clipboard to use system clipboard
set clipboard=unnamedplus

" Quiet startup
set shortmess+=I

" ==============================================================================
" Custom Key Bindings for Improved Navigation and Editing
" ==============================================================================

" Map <leader>w to save the current file
nnoremap <leader>w :w<CR>

" Map <leader>q to quit
nnoremap <leader>q :q<CR>

" ==============================================================================
" End of Enhancements
" ==============================================================================

This enhanced .vimrc configuration focuses on leveraging Vim's built-in features to improve the editing experience for Python, JavaScript, Markdown, and Lua, as well as general quality-of-life improvements. It sets up syntax highlighting, adjusts indentation and tab spaces according to common conventions for each language, enables spell checking for Markdown, and includes several navigation and editing conveniences.

Keep in mind, while this setup uses Vim's built-in capabilities, exploring additional plugins can further extend functionality. However, as requested, this guide focuses on what can be achieved without external tools.