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

31 KiB
Raw Blame History

Vim Guide

Introduction

Vim is a powerful text editor that utilizes a modal editing approach, allowing users to perform complex text manipulations efficiently and with minimal keystrokes. By mastering Vim's modal editing paradigm, users can significantly increase their productivity and streamline their workflow.

Key benefits of using Vim include:

  • Increased efficiency through modal editing and powerful commands
  • High level of customization and extensibility
  • Ubiquity across Unix-based systems and remote development environments

This guide will cover the essential concepts and commands that form the foundation of Vim's modal editing.

Essential Vim Modes

Normal Mode

Normal mode is the default mode in Vim and is used for navigation and text manipulation. In Normal mode, keys perform different actions based on their assigned functions.

Insert Mode

Insert mode is used for entering and editing text. In Insert mode, keys function as they would in a traditional text editor, inserting characters at the cursor position.

Visual Mode

Visual mode is used for selecting text and performing operations on the selected text. There are three types of Visual mode: character-wise, line-wise, and block-wise.

Command-line Mode

Command-line mode is used for executing commands, searching, and performing ex commands. To enter Command-line mode from Normal mode, press the : key.

Key Commands and Motions

Basic Navigation

  • h, j, k, l: Move the cursor left, down, up, and right, respectively.
  • w, b, e: Move the cursor to the beginning of the next word, the beginning of the previous word, or the end of the current word.
  • 0, $: Move the cursor to the beginning or end of the line.
  • gg, G: Move the cursor to the first or last line of the file.

Text Manipulation

  • y: Yank (copy) the selected text.
  • d: Delete the selected text.
  • p, P: Paste the yanked or deleted text after or before the cursor.
  • u: Undo the last change.
  • <Ctrl-r>: Redo the last undone change.

Search and Replace

  • /pattern, ?pattern: Search forward or backward for the specified pattern.
  • n, N: Move to the next or previous occurrence of the search pattern.
  • :s/old/new/g: Replace all occurrences of "old" with "new" in the current line.
  • :%s/old/new/g: Replace all occurrences of "old" with "new" in the entire file.

Working with Multiple Files

  • :e filename: Open the specified file in a new buffer.
  • :bn, :bp: Move to the next or previous buffer.
  • :ls: List all open buffers.
  • :b<n>: Switch to the buffer with the specified number.
  • :sp, :vsp: Split the window horizontally or vertically.

Configuring Vim with .vimrc

Essential Settings

  • syntax on: Enable syntax highlighting.
  • set number: Display line numbers.
  • set ignorecase: Use case-insensitive search by default.
  • set smartcase: Override ignorecase when the search pattern contains uppercase characters.
  • set incsearch: Show search matches as you type.
  • set hlsearch: Highlight search matches.
  • set tabstop=4: Set the width of a tab character to 4 spaces.
  • set shiftwidth=4: Set the number of spaces to use for autoindentation.
  • set expandtab: Use spaces instead of tabs for indentation.

Key Mappings

  • let mapleader = ",": Set the leader key to comma (,).
  • nnoremap <leader>w :w<CR>: Map <leader>w to save the current file.
  • nnoremap <leader>q :q<CR>: Map <leader>q to quit Vim.
  • nnoremap <leader>h :nohlsearch<CR>: Map <leader>h to clear search highlighting.

Plugin Management

Vim has a rich plugin ecosystem that extends its functionality. Popular plugin managers include:

Some recommended plugins for various use cases:

Vim Cheatsheet

Command Description
h, j, k, l Move the cursor left, down, up, right
w, b, e Move to the start of the next, previous, or end of the current word
0, $ Move to the start or end of the line
gg, G Move to the first or last line of the file
y, d, p Yank (copy), delete, or paste text
u, <Ctrl-r> Undo or redo changes
/pattern, ?pattern Search forward or backward for a pattern
:s/old/new/g Replace all occurrences of "old" with "new" in the current line
:e filename Open a file in a new buffer
:bn, :bp Move to the next or previous buffer

Appendix A: Tips and Tricks for Efficiency

Combining Motions and Operators

Vim's power lies in the ability to combine motions and operators to perform complex editing tasks efficiently. Here are some examples:

  • d3w: Delete the next three words.
  • y$: Yank (copy) from the cursor to the end of the line.
  • cis: Change inside a sentence (delete the current sentence and enter Insert mode).
  • >aB: Indent a block (the current block surrounded by curly braces).

Tip: Practice combining different motions and operators to build muscle memory for common editing tasks.

Macros for Automating Repetitive Tasks

Macros allow you to record a series of keystrokes and replay them to automate repetitive tasks. Here's how to use macros:

  1. Press q followed by a register (e.g., a) to start recording a macro.
  2. Perform the desired keystrokes.
  3. Press q again to stop recording.
  4. To execute the macro, press @ followed by the register (e.g., @a).
  5. To repeat the macro multiple times, prefix the @ command with a count (e.g., 10@a).

Tip: Use macros to automate tasks like formatting, code generation, or bulk replacements.

Splits and Tabs for Working with Multiple Files

Vim allows you to split the screen and work with multiple files simultaneously using splits and tabs.

Splits:

  • :sp or :split: Split the window horizontally.
  • :vsp or :vsplit: Split the window vertically.
  • <Ctrl-w>w: Cycle through the split windows.
  • <Ctrl-w>h/j/k/l: Move the focus to the left, bottom, top, or right split.

Tabs:

  • :tabnew: Open a new tab.
  • :tabn or gt: Move to the next tab.
  • :tabp or gT: Move to the previous tab.
  • :tabclose: Close the current tab.

Tip: Use splits and tabs to view and edit related files side by side, making it easier to reference and navigate between them.

Registers for Advanced Copy/Paste Operations

Vim provides multiple registers for storing and retrieving text. Some commonly used registers include:

  • "a to "z: Named registers for storing text.
  • "0: The yank register, which stores the last yanked text.
  • "+: The system clipboard register (requires Vim compiled with clipboard support).

To use registers:

  • "ayw: Yank the current word into register a.
  • "ap: Paste the contents of register a.
  • "+p: Paste the contents of the system clipboard.

Tip: Use registers to store and recall frequently used snippets or to perform precise copy/paste operations.

Appendix D: Vim for Specific Workflows

Vim for Software Development

Vim offers various features and plugins that make it well-suited for software development tasks:

Code Navigation:

  • <Ctrl-]>: Jump to the definition of the keyword under the cursor (requires ctags).
  • <Ctrl-t>: Jump back from the definition.
  • gd: Go to the local declaration of the variable under the cursor.

Debugging:

  • Plugins like vimspector or vim-debug provide debugging capabilities within Vim.
  • Set breakpoints, step through code, and inspect variables without leaving the editor.

Integration with Build Tools:

  • Plugins like vim-dispatch or vim-make allow you to run build commands and view results within Vim.
  • Configure key mappings to quickly compile, run, or test your code.

Vim for Data Manipulation

Vim's powerful text manipulation capabilities make it suitable for working with structured data formats like CSV or JSON.

CSV Data:

  • Use :%s/,/\t/g to convert comma-separated values to tab-separated values for easier manipulation.
  • Leverage Vim's column editing features (e.g., visual block mode) to work with tabular data.
  • Plugins like csv.vim provide additional functionality for working with CSV files.

JSON Data:

  • Use :%!jq . to format and pretty-print JSON data (requires the jq command-line tool).
  • Plugins like vim-jdaddy or vim-json offer improved syntax highlighting and formatting for JSON files.

Tip: Combine Vim's text manipulation commands with external tools (e.g., sort, awk, sed) to process and transform data efficiently.


It's great to see the foundation of your Vim guide taking shape! Lets review and enrich the content with some more context and practical examples, especially focusing on programming and working with structured data. Here's a refined and expanded version based on your feedback and previous content:


Vim Guide

1. Introduction to Vim's Philosophy

Vim, renowned for its modal editing system, allows users to switch between various modes designed for specific tasks such as inserting text, navigating within files, or executing commands. This modal approach greatly enhances editing efficiency by reducing the number of keystrokes required for tasks and enabling a more intuitive control over text manipulation.

2. Quick Reference Guide

This section provides a quick lookup for the most frequently used Vim commands, categorized for easy reference:

  • Navigating
    • h, j, k, l: Move left, down, up, right (the arrow keys of Vim).
    • gg, G: Jump to the top or bottom of the document.
  • Editing
    • i, a, o: Enter insert mode at cursor, after cursor, or on a new line.
    • d, c, y: Delete, change, or yank (copy) text.
  • Searching
    • /pattern, ?pattern: Search forward or backward for a pattern.
    • n, N: Repeat search in the same or opposite direction.

3. Core Guides with Integrated Efficiency Tips

Basic Editing and File Management

Opening, Saving, and Exiting Files

  • Commands: vim filename, :w, :wq, :q!
    • Description: Open files with vim filename. Save with :w, exit with :q!, or combine both with :wq.
  • Tip: Use ZZ as a quicker alternative to :wq when you need to save and exit efficiently.

Navigating Within Files

  • Commands: h, j, k, l
    • Description: Precisely navigate within lines or across the text.
  • Tip: Pair h, j, k, l with Ctrl (e.g., Ctrl-f and Ctrl-b) for faster document scrolling.

Efficient Navigation

Word and Line Movements

  • Commands: w, b, e, 0, ^, $
    • Description: Navigate efficiently by words or to specific positions within a line.
  • Tip: 5w can save significant time by jumping five words forward, reducing repeated keystrokes.

Document Navigation

  • Commands: gg, G
    • Description: Quickly move to the beginning or end of a document, or directly to a specific line with 50G.
  • Tip: Use percentage jumps like 50% to reach the midpoint of a document quickly.

Advanced Text Manipulation

Editing Commands

  • Commands: dw, ciw, d$
    • Description: Efficient commands for deleting a word, changing inside a word, or deleting to the end of a line.
  • Tip: ci( changes content inside parentheses, a common task in programming.

Using Visual Mode for Complex Selections

  • Commands: v, V, Ctrl-v
    • Description: Select text for manipulation in various modes: character, line, or block.
  • Tip: Use > or < to indent selected blocks quickly, crucial in code formatting.

Search and Replace

Finding and Replacing Text

  • Commands: :s/old/new/g, /%s/old/new/g
    • Description: Replace 'old' text with 'new' globally or within the current line.
  • Tip: Use * to search for the word under the cursor quickly.

Navigational Searches

  • Commands: f<char>, F<char>, t<char>, T<char>
    • Description: Jump to the next or previous occurrence of a character on the line.
  • Tip: Use ; and , to repeat the last f or t search efficiently.

Enhanced Motion for Programming and Structured Data

Paragraph and Section Motions

  • Commands: {, }, [[, ]]
    • Description: Navigate quickly between paragraphs or code blocks. Ideal for structured data and code structures.

Screen Motions

  • Commands: H, M, L, Ctrl-d, Ctrl-u
    • Description: Manage on-screen text positioning and rapid scrolling effectively.

Document Motions

  • Commands: gg, G
    • Description: Essential for moving quickly through large files or to specific lines, critical in debugging and reviewing.

Tips for Using Motions in Structured Data and Programming

  • Combine motions with searches for efficient navigation within XML, JSON

, or YAML, especially useful in large data files or complex codebases.

  • Record macros for repetitive edits across similar structures, optimizing time and ensuring consistency.
  • Utilize Ctrl-v for block visual mode, particularly effective for column-based editing or configuration adjustments.

This expanded guide not only provides a comprehensive look at using Vim effectively but also integrates practical tips directly applicable to programming and structured data editing, ensuring users can leverage Vim's power to its fullest.


Certainly! Let's flesh out your Vim guide with enriched content and contextual details, structured in Markdown format. This enriched version will delve deeper into each section, offering clearer explanations and practical examples to ensure users grasp the concepts and can apply them effectively.


Vim Guide

1. Introduction to Vim's Philosophy

Vim, distinguished by its modal editing capabilities, allows users to switch between various modes for different editing tasks. This design is fundamental for increasing editing speed and efficiency as it enables users to execute commands and navigate files with minimal keystrokes. Each mode in Vim is tailored to a specific purpose—inserting text, navigating files, or executing commands—making it highly efficient once mastered.

2. Quick Reference Guide

Most Used Commands and Modes

  • Navigating
    • h, j, k, l - Move left, down, up, right
    • gg, G - Jump to the top or bottom of the document
  • Editing
    • i, a, o - Enter insert mode at cursor, after cursor, or a new line
    • d, c, y - Delete, change, or yank (copy) text
  • Searching
    • /pattern, ?pattern - Search forward or backward for a pattern
    • n, N - Repeat search in same or opposite direction

3. Core Guides with Integrated Efficiency Tips

Basic Editing and File Management

Opening, Saving, and Exiting Files

  • Commands: vim filename, :w, :wq, :q!
    • vim filename opens a file or creates a new one if it doesn't exist.
    • :w saves changes, :wq saves and quits, and :q! quits without saving.
  • Tip: Use ZZ to save and quit Vim quickly, which is a more efficient alternative to :wq.

Navigating Within Files

  • Commands: h, j, k, l
    • Navigate precisely within lines with minimal movement.
  • Tip: Combine these with Ctrl (e.g., Ctrl-f and Ctrl-b) to scroll faster through documents, balancing precise and rapid movement.

Efficient Navigation

Word and Line Movements

  • Commands: w, b, e, 0, ^, $
    • w jumps to the start of the next word, b to the beginning of the current or previous word, and e to the end of the current or next word.
    • 0, ^, and $ navigate to the start, first non-blank character, and end of the line, respectively.
  • Tip: Use 5w to jump five words forward, saving time compared to repeated presses.

Document Navigation

  • Commands: gg, G
    • gg jumps to the beginning, and G to the end of the document. Use 50G to jump directly to line 50.
  • Tip: Jump to specific percentages of your document with 50% to quickly reach the midpoint.

Advanced Text Manipulation

Editing Commands

  • Commands: dw, ciw, d$
    • dw deletes a word, ciw changes inside a word, and d$ deletes to the end of a line.
  • Tip: Use ci( to change inside parentheses, demonstrating how command combinations can cater to specific coding needs.

Using Visual Mode for Complex Selections

  • Commands: v, V, Ctrl-v
    • v starts visual mode for character selection, V for line, and Ctrl-v for a block.
  • Tip: After selecting text in Visual mode, use > or < to quickly indent blocks of code.

Search and Replace

Finding and Replacing Text

  • Commands: :s/old/new/g, /%s/old/new/g
    • Replace 'old' with 'new' in the current line or entire document.
  • Tip: Use * to search for the word under the cursor, enhancing workflow speed.

Navigational Searches

  • Commands: f<char>, F<char>, t<char>, T<char>
    • f<char> moves to the next occurrence of <char> on the line, F<char> moves to the previous.
  • Tip: Combine ; and , to repeat the last f or t search forward or backward, optimizing character searching. Absolutely, let's expand on the specific Vim motions that are especially useful for programming and working with structured data files like XML, JSON, and YAML. This additional information will seamlessly integrate into your existing guide, providing focused insights on navigating and manipulating code structures effectively.

Paragraph and Section Motions

Commands: {, }, [[, ]]

  • Description:
    • { and } allow you to move quickly between blocks of text separated by blank lines, which is common in documentation blocks within code.
    • [[ and ]] are particularly useful for jumping through sections of code delimited by braces ({}), which is a common structure in many programming languages. This makes them ideal for navigating functions, classes, and other code blocks.

Screen Motions

Commands: H, M, L, Ctrl-d, Ctrl-u

  • Description:
    • H (High) moves the cursor to the top of the screen, M (Middle) to the center, and L (Low) to the bottom. This helps in quickly relocating the visible area of your code without scrolling.
    • Ctrl-d (down) and Ctrl-u (up) scroll the view half a screen at a time. This is useful for a rapid yet controlled scan through your code, allowing you to maintain context without losing your place.

Document Motions

Commands: gg, G

  • Description:
    • gg quickly jumps to the beginning of the document, which is helpful when you need to refer to initial configurations or declarations in programming files.
    • G moves to the end of the document. You can also use G with a number, like 50G, to jump directly to a specific line, facilitating precise navigation when you're debugging or reviewing logs that reference specific lines.

Tips for Using Motions in Structured Data and Programming

  • Combining Motions with Searches: When navigating through structured data like XML or JSON, combine section or paragraph motions with searches. For example, use /tagName followed by n and { to jump directly to specific tags and then navigate around their blocks.
  • Macro Usage: Consider recording macros when performing repetitive tasks across similar structures. For instance, if you are refactoring code or need to update multiple sections of a JSON file in the same manner, record a macro of the process using q, perform the task, and then replay it with @.
  • Visual Block Mode: Utilize Ctrl-v to enter visual block mode, which can be incredibly effective for column-based editing in structured files like CSV or configuration blocks in YAML files.

Adding these specific motions and tips to your Vim guide will not only enrich the content but also enhance the practical utility for developers and data engineers, ensuring they can navigate and edit their files with greater speed and precision.


Certainly! Lets delve deeper into the modal editing philosophy of Vim, which forms the core of its operation and differentiates it from other text editors. This detailed guide will cover the primary modes—Normal, Insert, and Visual—along with a few additional modes you might encounter, such as Command-line and Replace modes. Understanding these modes and when to use them is fundamental to mastering Vim.

1. Normal Mode

Purpose: Navigation, text manipulation, and command execution.

  • Entering Normal Mode: This is the default mode when you open Vim. You can always return to Normal mode from other modes by pressing Esc.
  • Key Operations:
    • Navigation: Use h, j, k, l to move left, down, up, and right, respectively. Advanced movements include w (next word), b (beginning of word), and $ (end of line).
    • Editing: Commands like dd (delete line), cc (change line), and yy (yank or copy line) are activated here.
    • Complex Commands: Combining commands to perform complex text manipulations, like d3w (delete next three words) or 2dd (delete two lines).

2. Insert Mode

Purpose: Typing and editing text directly.

  • Entering Insert Mode: Press i to insert at the cursor, I to insert at the beginning of the line, a to append after the cursor, and A to append at the end of the line.
  • Key Operations:
    • Text Entry: Typing behaves as in conventional text editors.
    • Exiting: Press Esc to return to Normal mode.

3. Visual Mode

Purpose: Text selection for manipulation.

  • Entering Visual Mode: Press v to start character-wise selection, V for line-wise selection, or Ctrl-v for block-wise selection.
  • Key Operations:
    • Expand Selection: Move the cursor to expand the selection area.
    • Operations on Selection: Once text is selected, operations like d (delete), y (yank), and c (change) can be applied.

4. Command-Line Mode

Purpose: Entering editor commands, searching, and more.

  • Entering Command-Line Mode: Press : from Normal mode.
  • Key Operations:
    • Commands Execution: Type commands like :w (save), :q (quit), and :/pattern (search for a pattern).

5. Replace Mode

Purpose: Replace existing text without entering Insert mode.

  • Entering Replace Mode: Press R to start replacing text under the cursor until Esc is pressed.

Transitioning Between Modes

Mastering Vim involves fluidly switching between these modes as needed. Heres a quick reference on transitioning:

  • Normal to Insert: i, I, a, A, etc.
  • Normal to Visual: v, V, Ctrl-v.
  • Any to Normal: Esc or Ctrl-[.

Practical Tips

  • Mode Indicators: Many users customize their Vim status line to indicate the current mode visually.
  • Learning Tools: vimtutor is an excellent resource for beginners to practice these modes in a tutorial format.

Understanding and becoming proficient in these modes unlocks the true power of Vim, allowing you to edit and navigate with efficiency and precision that few other editors can match.


.vimrc File: Structured Guide with Documentation

Compatibility and Initial Setup

" 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
  • Checks for Vim version compatibility.
  • Prevents multiple loads of the .vimrc file in a single session.

General Settings

" Set UTF-8 encoding for text and files
set encoding=utf-8
set fileencoding=utf-8

" Use system clipboard to easily copy/paste outside of Vim
set clipboard=unnamedplus

" Enable syntax highlighting
syntax on

" Indentation settings for a consistent coding style
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent

" Line number settings for easier navigation
set number
set relativenumber

" Highlight the line cursor is on
set cursorline

" Enable mouse support across all modes
set mouse=a

" Disable swap files to avoid clutter
set noswapfile
  • Configures basic editing behaviors and preferences.
  • Sets up indentation and line number visibility for ease of reading and navigation.

Search Enhancements

" Improve search functionality
set hlsearch     " Highlight search results
set ignorecase   " Case-insensitive searching
set smartcase    " Case-sensitive if contains uppercase
set incsearch    " Incremental search
  • Enhances search functionality within Vim, making it easier to find text.

Visual Customizations

" Visual settings for a better editing experience
colorscheme desert     " Set color scheme
set t_Co=256           " Enable 256 colors
set laststatus=2       " Always display the status line
  • Customizes the appearance of Vim, including color schemes and the status bar.

Plugin Management

" Plugin management using Vim's native package loading
execute "set runtimepath^=~/.vim/pack/plugins/start"
  • Outlines the method for managing plugins with Vim 8+ or Neovim's built-in package feature.

Plugins Configuration (Examples)

" Example plugins that enhance Vim's functionality
" Plug 'tpope/vim-surround'            " Easier manipulation of surrounding characters
" Plug 'preservim/nerdtree'            " File system explorer
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }  " Fuzzy file, buffer, mru, tag, etc. finder.
  • Demonstrates how to include plugins in your .vimrc. Plugins like vim-surround, nerdtree, and fzf are popular choices for boosting productivity.

Key Bindings

" Custom key bindings for faster workflow
let mapleader=" "    " Set space as the leader key
nnoremap <leader>n :NERDTreeToggle<CR>    " Toggle NERDTree with <leader>n
  • Customizes key mappings, including setting a leader key for shortcuts.

Custom Functions and Autocommands

" Place for custom Vim functions and autocommands
autocmd vimexit * if !argc() | NERDTreeClose | endif
" Example: Auto-close NERDTree on Vim exit if it's the last window
  • A section for defining custom functions and autocommands for automating tasks.

Filetype-specific Enhancements and Quality-of-Life Improvements

" Enhancements for specific file types and additional settings
au BufRead,BufNewFile *.py,*.js,*.md,*.lua setlocal syntax=on
" Enable syntax highlighting based on file type

" Quality-of-Life Improvements
set splitright       " Vertical splits to the right
set splitbelow       " Horizontal splits below
set clipboard=unnamedplus    " Integrate Vim clipboard with the system clipboard
  • Adjusts settings for specific file types and adds general improvements to make editing more pleasant.

This guide breaks down the .vimrc file into manageable sections, making it easier to understand and customize according to your needs. Remember, the best .vimrc is one that evolves with you, fitting your workflow and preferences as they develop over time.


" Basic Vim configuration file

" Author: [Your Name]
" Last Updated: [Date]

" Prevent older Vim versions from running this config
if version < 700
  echo "Upgrade to Vim 7.0 or later."
  finish
endif

" Ensure the file is loaded only once
if exists("g:loaded_vimrc")
  finish
endif
let g:loaded_vimrc = 1

" ==============================================================================
" General Settings
" ==============================================================================
set nocompatible              " Disable Vi compatibility mode
filetype plugin indent on     " Enable filetype detection and plugin
set encoding=utf-8            " Set default encoding to UTF-8
set fileencoding=utf-8        " Set file encoding to UTF-8
set clipboard=unnamedplus     " Use system clipboard
syntax enable                 " Enable syntax highlighting
set tabstop=4                 " Set tab width to 4 spaces
set shiftwidth=4              " Set width for auto-indents
set expandtab                 " Use spaces instead of tabs
set smartindent               " Enable smart indent
set number                    " Show line numbers
set relativenumber            " Show relative line numbers
set cursorline                " Highlight current line
set mouse=a                   " Enable mouse support
set noswapfile                " Disable swap file creation
set nobackup                  " Disable backup file creation
set undofile                  " Enable persistent undo
set incsearch                 " Enable incremental search
set hlsearch                  " Highlight search results
set ignorecase                " Case insensitive searching...
set smartcase                 " ...unless there's a capital letter in the query

" ==============================================================================
" Visual Settings
" ==============================================================================
set showmatch                 " Highlight matching parentheses
colorscheme desert            " Set colorscheme
set laststatus=2              " Always display the status line
set showcmd                   " Display incomplete commands
set wildmenu                  " Visual autocomplete for command menu
set ruler                     " Show cursor position

" ==============================================================================
" Key Bindings
" ==============================================================================
let mapleader = " "           " Set <Space> as the leader key
nnoremap <leader>w :w!<CR>    " Quick save command
nnoremap <leader>q :q!<CR>    " Quick quit command

" ==============================================================================
" Plugin Management
" ==============================================================================
" Placeholder for plugin management system initialization
" e.g., vim-plug, Vundle, or native Vim 8+ package management

" ==============================================================================
" Plugins Configuration
" ==============================================================================
" Example configurations for installed plugins

" ==============================================================================
" Custom Functions and Autocommands
" ==============================================================================
" Example: Clean trailing whitespace on save
autocmd BufWritePre * %s/\s\+$//e

" ==============================================================================
" Final Touches
" ==============================================================================
" Additional custom settings and tweaks

" Ensure settings apply to all file types
filetype plugin on

" Enable spell checking for text files
autocmd FileType text setlocal spell

" End of .vimrc