šŸ”“
PURPLEBYTEONE
  • main
  • Notes
    • Education
      • Base
        • Information Technology
          • OpenText
            • Courses
              • Security and Forensics
                • EnCaseā„¢ eDiscovery Series
                  • ED290 - eDiscovery Training with EnCase Information Assurance
                • EnCaseā„¢ Crossover Series
                  • DFIR450 - EnCase EnScript Programming
                  • DFIR370 - Host Intrusion Methodology and Investigation
                  • DFIR350 - Internet-based Investigations
                  • DFIR130 - EnCase Endpoint Investigator
                • EnCaseā„¢ Incident Response Series
                  • IR280 - EnCase Endpoint Security
                  • IR250 - Incident Investigation
                • EnCaseā„¢ Digital Forensics Series
                  • DF420 - Mac Examinations
                  • DF410 - NTFS Examinations
                  • DF320 - Advanced Analysis of Windows Artifacts
                  • DF310 - EnCase Certified Examiner
                  • DF210 - Building an Investigation
                  • DF125 - Mobile Device Examinations
                  • DF120 - Foundations in Digital Forensics
              • Business Network
              • Digital Process Automation
              • Platform Solutions
              • Discovery
              • Digital Experience
              • Analytics
              • Enterprise Content Management
          • Harvard University
            • CS 50
          • LPI
            • Courses
              • Essentials
                • Linux Essentials: 010
                • Security Essentials: 020
                • Web Development Essentials: 030
              • Professional
                • LPIC-1
                  • 101
                  • 102
                • LPIC-2
                  • 201
                  • 202
                • LPIC-3
                  • 300
                  • 303
                  • 305
                  • 306
          • Cloud Orchestration
            • Docker
            • Kubernetes
              • KCNA
              • CKA
              • CKS
          • Google Cloud
            • Path
              • Google Cloud Computing Foundations
              • Network Engineer Learning Path
              • Database Engineer Learning Path
              • Cloud Engineer Learning Path
              • Security Engineer Learning Path
              • Cloud Architect Learning Path
              • Cloud Developer Learning Path
          • VMware
            • Courses
              • Carbon Black
                • Professional
                  • Endpoint Security: Core Technical Skills
                  • App Control Administrator
                  • EDR Administrator
                • Advanced
                  • App Control Advanced Administrator
                  • Advanced Operations and Troubleshooting
                  • Audit and Remediation
                  • Endpoint Standard
                  • Enterprise EDR
                  • EDR Advanced Administrator
                  • EDR Advanced Analyst
          • Amazon
            • Courses
              • Foundation
                • AWS Certified Cloud Practitioner
              • Associate
                • AWS Certified Solutions Architect
              • Professional
                • AWS Certified Solutions Architect
              • Speciality
                • AWS Certified Advanced Networking
                • AWS Certified Security – Specialty
          • Microsoft
            • Courses
              • Azure
                • AZ - 900
                • AZ - 104
                • AZ - 305
                • SC - 900
                • SC - 200
                • SC - 300
                • AZ - 500
                • MS-500
                • SC - 400
                • SC - 100
          • The Code
            • Platform
              • FreeCodeCamp
              • W3
            • Language
              • Python
              • PowerShell
              • JavaScript
              • PHP
              • SQL
              • GO
              • Java
              • Perl
              • Ruby
              • Scala
              • C
              • C#
              • C++
              • Brainfuck
              • CSS
              • JSON
              • Kotlin
              • LOLCODE
              • MISP
              • MongoDB
              • Objective-C
              • Perl
              • Rust
              • SAAS
              • Scala
              • Solidity
              • SWIFT
              • TypeScript
              • WebAssembly
              • XML
              • YAML
              • AngularJS
              • Ansible
              • BASH
              • Docker
              • GIT
              • jQuery
              • VIM
          • OKTA
        • Purple Team
          • Splunk
            • Courses
              • Udemy
            • Notes
          • Security Team Blue
            • Courses
              • BTL v1
              • BTL v2
          • ISC2
            • CC
              • Introduction
              • Security Principles
                • Security Concepts of Information Assurance
                • Risk Management Process
                • Security Controls
                • Governance Elements and Processes
                • Terms and Definitions
              • Incident Response
                • Understand Incident Response
                • Business Continuity
                • Disaster Recovery
              • Access Control Concepts
                • Access Control Concepts
                • Physical Access Controls
                • Logical Access Controls
              • Network Security
                • Computer Networking
                • Threats and Attacks
                • Network Security Infrastructure
              • Security Operations
            • SSCP
            • CISSP
            • CCSP
          • TCM Security
            • Courses
              • Python 101
              • Python 201
              • Linux 101
              • External Pentest Playbook
              • Windows Privilege Escalation
              • Linux Privilege Escalation
              • Movement, Pivoting and Persistence
              • Practical Phishing Assessments
              • Practical Web Application Security
              • Practical Malware Analysis
              • Mobile
              • (OSINT) Fundamentals
              • PEH
            • Certification
              • PNPT
              • PJMR
          • Coursera
            • Courses
              • NYU
                • Introduction to Cyber Security Specialization
              • Google
                • Google Cybersecurity Professional
                  • Foundations of Cybersecurity
                  • Play It Safe: Manage Security Risks
                  • Connect and Protect: Networks and Network Security
                  • Tools of the Trade: Linux and SQL
                  • Assets, Threats, and Vulnerabilities
                  • Sound the Alarm: Detection and Response
                  • Automate Cybersecurity Tasks with Python
                  • Put It to Work: Prepare for Cybersecurity Jobs
          • ICSI Global
          • OccupyTheWeb
            • Courses
              • GSBMH
              • NBFH
              • LBFH
          • CompTIA
            • Courses
              • Core Base
                • A+
                  • Chapter 1
                • Network+
                  • Chapter 1
                • Linux+
                  • Chapter 1
                  • Chapter 2
                • Cloud+
                  • Chapter 1
              • Security
                • Security+
                  • Chapter 1
                    • Risk Terminology
                • Pentest+
                  • Chapter 1
                • CySA+
                  • Chapter 1
                • CSA+
                  • Defending Against Cybersecurity Threats
          • EC-Council
            • Courses
              • CEH
              • CHFI
              • CSA
          • Intel Techniques
            • Courses
              • OSINT Techniques
              • Privacy & Security
          • SANS
            • Courses
              • SEC
                • SEC 401 - Security Essentials
                • SEC 450 - Blue Team Fundamentals
                • SEC 502 - Perimeter Protection In-Depth
                • SEC 503 - Network Monitoring and Threat Detection In-Depth
                • SEC 504 - Hackers Tools, Techniques And Incident Handling
                • SEC 505 - Securing Windows and PowerShell Automation
                • SEC 506 - Securing Linux & UNIX
                • SANS 509 - Securing Oracle Database
                • SEC 511 - Continuous Monitoring and Security Operations
                • SEC 517 - Cutting Edge Hacking Techniques
                • SEC 524 - Cloud Security Fundamentals
                • SEC 531 - Windows Command Line Kung Fu
                • SEC 542 - Web App Penetration Testing
                • SEC 560 - Enterprise Penetration Testing
                • SEC 565 - Red Team Operations and Adversary Emulation
                • SEC 566 - Implementing and Auditing Security Frameworks
                • SEC 573 - Automating Information Security with Python
                • SEC 575: Mobile Device Security
                • SEC 580 - Metasploit for Enterprise Penetration Testing
                • SEC 587 - Advanced Open Source Intelligence
                • SEC 599 - Defeating Advanced Adversaries - Purple Team Tactics & Kill Chain Defenses
                • SEC 617 - Wireless Penetration Testing and Ethical Hacking
                • SEC 642 - Advanced Web App Penetration Testing
                • SEC 660 - Advanced Penetration Testing
                • SEC 760 - Advanced Exploit Development
                • SEC 554: Blockchain and Smart Contract Security
              • FOR
                • FOR 408 - Windows Forensic Analysis
                • FOR 500 - Windows Forensic Analysis
                • FOR 508 - Advanced Digital Forensics and Incident Response
                • FOR 518 - Mac and iOS Forensic Analysis
                • FOR 526 - Memory Forensics In-Depth
                • FOR 572 - Advanced Network Forensics
                • FOR 577 - Virtualization Security Fundamentals
                • FOR 578 - Cyber Threat Intelligence
                • FOR 610 - Reverse-Engineering Malware
                • FOR 710 - Reverse-Engineering Malware: Advanced Code Analysis
              • AUD
                • AUD 507 - Auditing Systems, Applications, and the Cloud
              • ICS
                • ICS 410 - ICS/SCADA Security Essentials
              • MGT
                • MGT 512 - Security Leadership Essentials for Managers
          • IBM
            • Courses
              • Cybersecurity Analyst Professional
                • Introduction to Cybersecurity Tools & Cyber Attacks
                  • Week 1
                  • Week 2
                  • Week 3
                  • Week 4
          • Cybrary
            • Courses
              • SOC L1
              • SOC L2
              • SOC L3
              • Become an Incident Handler
          • Zero Point Security
            • Courses
              • Red Team Ops [CRTO]
              • C2 Development in C#
          • Web Security Academy
            • Courses
              • Burp Suite Certified Practitioner
          • INE
            • Courses
              • eJPT
                • Blue Team
                  • ePND
                  • eCIR
                  • eCRE
                  • ePWD
                  • eCTHPv2
                  • eCDFP
                  • eCMAP
                • Red Team
                  • eMAPT
                  • eWPT
                  • eCPPTv2
                  • eCXD
                  • eWPTXv2
                  • eCPTXv2
          • Pentester Lab
          • Pentester Academy
            • Courses
              • Pentesting with Metasploit: Beginner Edition
              • Linux Privilege Escalation
          • Offensive Security
            • Courses
              • Fundamental
                • Introduction to Secure Software Development
                • Introduction to Cloud Security
                • Exploit Development Essentials
                • Web Application Assessment Essentials
                • Security Operations Essentials
                • Network Penetration Testing Essentials
              • Security Operations
                • SOC-200: Foundational Security Operations and Defensive Analysis (OSDA)
              • Penetration Testing
                • PEN - 200
                • PEN - 210
                • PEN - 300
              • Web Application
                • WEB-200: Foundational Web Application Assessments with Kali Linux (OSWA)
                • WEB-300: Advanced Web Attacks and Exploitation (OSWE)
              • Exploit Development
                • EXP-301: Windows User Mode Exploit Development (OSED)
                • EXP-312: Advanced macOS Control Bypasses (OSMR)
                • EXP-401: Advanced Windows Exploitation (OSEE)
          • Sektor7
            • Courses
              • Windows Privilege Escalation
              • Windows Persistence
              • Malware Development Essentials
              • Evasion Windows Red Team Ops
          • Black Hat
            • Courses
              • BlackHat - Malware Analysis And Memory Forensics
          • Fortinet
          • VHL
          • DFIRdiva
          • YouTube
            • Channels
          • Udemy
            • Certified in Cybersecurity (CC)
            • CompTIA Security+
          • AntiSyphon
          • THM
            • Room
              • SPLUNK
                • Introduction to SIEM
                • Basics
                • Incident handling
                • Investigating
                • Benign
                • ELK 101
                • PS Eclipse
                • New Hire Old Artifacts
                • Conti
                • BOTS
                  • v1
                  • v2
                  • v3
                • ItsyBitsy
            • Learning Paths
              • Introduction to Cyber Security
                • Introduction to Cyber Security
                  • Intro to Offensive Security
                  • Intro to Defensive Security
                • Introduction to Offensive Security
                • Introduction to Defensive Security
          • HTB
            • HTB Academy
              • Job Role Path
                • Penetration Tester
                  • Getting Started
                    • Infosec Overview
                    • Getting Started with a Pentest Distro
                    • Staying Organized
                    • Connecting Using VPN
                    • Common Terms
                  • Machines
                    • Nibbles
                • SOC Analyst
                  • Incident Handling Process
                    • Incident Handling
                    • Cyber Kill Chain
                    • Incident Handling Process Overview
                      • Preparation Stage
                      • Detection & Analysis Stage
                      • Containment, Eradication, & Recovery Stage
                      • Post-Incident Activity Stage
                  • Security Monitoring & SIEM Fundamentals
                  • Windows Event Logs & Finding Evil
                  • Introduction to Threat Hunting & Hunting With Elastic
                  • Understanding Log Sources & Investigating with Splunk
                  • Windows Attacks & Defense
                  • Intro to Network Traffic Analysis
                  • Intermediate Network Traffic Analysis
                  • Working with IDS/IPS
                  • Introduction to Malware Analysis
                  • JavaScript Deobfuscation
                  • YARA & Sigma for SOC Analysts
                  • Introduction to Digital Forensics
                  • Detecting Windows Attacks with Splunk
                  • Security Incident Reporting
            • Challenges
              • Retired
                • Challenges
                  • Hardware
                    • Very Easy
                      • Gawk
                      • Secure Digital
                  • Web
                    • Very Easy
                      • Trapped Source
                  • Mobile
                    • Very Easy
                      • Don't Overreact
                  • Pwn
                    • Very Easy
                      • Getting Started
                      • Questionnaire
                      • Vault-breaker
                  • Crypto
                    • Very Easy
                      • Ancient Encodings
                  • Reverse
                    • Very Easy
                      • WIDE
                      • Shattered Tablet
                      • Hunting License
                      • Gonna-Lift-Em-All
                  • Misc
                    • Very Easy
                      • Compressor
                  • Forensics
                    • Very Easy
                      • Extraterrestrial Persistence
                      • Alien Cradle
                      • Wrong Spooky Season
                  • OSINT
                  • GamePwn
                  • Blockchain
            • Machines
              • Retired
                • Windows
                  • Easy
                    • Blue
          • Blueteamlabs.online
          • LetsDefend.io
          • CyberDefenders.org
      • Infinity
        • c0//53
          • Leet Code
          • Hacker Rank
        • Tools
          • Red Team
            • OSINT
            • Enumeration
            • Web
            • Exploit Base
              • Linux
            • Post-exploitation
              • Backdoor
          • Blue Team
            • Forensics
            • My scripts
        • Bookmarks
          • Cybersecurity
            • Reverse Engineering
            • Telegram
          • MindHub
            • Job Boards
          • GitHub
          • AI
            • Free
          • Books
            • Cybersecurity
              • Linux
                • Linux Essentials For Cybersecurity
                • The Linux Command Line, 2nd Edition: A Complete Introduction
                • How Linux Works, 3rd Edition: What Every Superuser Should Know
              • OSINT
                • Deep Dive: Exploring the Real-world Value of Open Source Intelligence
              • Networking
                • Wireshark for Security Professionals
              • Social Engineering
                • Practical Social Engineering
          • Writeups
    • Carrier
      • Interview Questions
        • General HR questions
        • Cybersecurity
          • Junior Positions
            • SOC L1
            • Junior Malware Analyst
            • Junior Penetration Tester
            • Junior Red Teamer
            • Junior Forensic Analyst
            • Junior Incident responder
            • Junior Threat hunter
            • Junior Security Analyst
          • Specialist Positions
            • SOC L2
            • Malware Analyst
            • Penetration Tester
            • Red Teamer
            • Forensic Analyst
            • Incident responder
            • Threat hunter
            • Security Analyst
          • Senior Positions
            • SOC L3
            • Senior Malware Analyst
            • Senior Penetration Tester
            • Senior Red Teamer
            • Senior Forensic Analyst
            • Senior Incident responder
            • Senior Threat hunter
            • Senior Security Analyst
          • Random questions
            • PT.1
            • PT.2
            • PT.3
            • PT.4
            • PT.5
            • PT.6
    • Note
      • Read
      • Interview
      • Cheat Sheet
        • Penetration Testing
          • Enumeration
  • Roadmap
    • CTF Track
Powered by GitBook
On this page
  • Basics of navigating Vim
  • Help docs:
  • Modes:
  • The ā€˜Grammar’ of vim
  • Some shortcuts and tricks
  • Macros
  1. Notes
  2. Education
  3. Base
  4. Information Technology
  5. The Code
  6. Language

VIM

Last updated 1 year ago

(Vi IMproved) is a clone of the popular vi editor for Unix. It is a text editor designed for speed and increased productivity, and is ubiquitous in most unix-based systems. It has numerous keybindings for speedy navigation to specific points in the file, and for fast editing.

vimtutor is a an excellent application that teaches you how to use Vim. It comes with the vim package during installation. You should be able to just run ā€œvimtutorā€ on the command line to open this tutor. It will guide you through all the major features in vim.

Basics of navigating Vim

    vim <filename>    # Open <filename> in vim
    :help <topic>     # Open up built-in help docs about <topic> if any exists
    :q                # Quit vim
    :w                # Save current file
    :wq               # Save file and quit vim
    ZZ                # Save file and quit vim
    :q!               # Quit vim without saving file
                      # ! *forces* :q to execute, hence quitting vim without saving
    ZQ                # Quit vim without saving file
    :x                # Save file(only when the file is modified) and quit vim

    u                 # Undo
    CTRL+R            # Redo

    h                 # Move left one character
    j                 # Move down one line
    k                 # Move up one line
    l                 # Move right one character

    Ctrl+B            # Move back one full screen
    Ctrl+F            # Move forward one full screen
    Ctrl+D            # Move forward 1/2 a screen
    Ctrl+U            # Move back 1/2 a screen

    # Moving within the line

    0                 # Move to beginning of line
    $                 # Move to end of line
    ^                 # Move to first non-blank character in line

    # Searching in the text

    /word             # Highlights all occurrences of word after cursor
    ?word             # Highlights all occurrences of word before cursor
    n                 # Moves cursor to next occurrence of word after search
    N                 # Moves cursor to previous occurrence of word

    :%s/foo/bar/g     # Change 'foo' to 'bar' on every line in the file
    :s/foo/bar/g      # Change 'foo' to 'bar' on the current line
    :%s/\n/\r/g       # Replace new line characters with new line characters
    :'<,'>s/foo/bar/g # Change 'foo' to 'bar on every line in the current visual selection

    # Jumping to characters

    f<character>      # Jump forward and land on <character>
    t<character>      # Jump forward and land right before <character>

    # For example,
    f<                # Jump forward and land on <
    t<                # Jump forward and land right before <

    # Moving by word

    w                 # Move forward by one word
    b                 # Move back by one word
    e                 # Move to end of current word

    # Other characters for moving around

    gg                # Go to the top of the file
    G                 # Go to the bottom of the file
    :NUM              # Go to line number NUM (NUM is any number)
    H                 # Move to the top of the screen
    M                 # Move to the middle of the screen
    L                 # Move to the bottom of the screen

Help docs:

Vim has built in help documentation that can accessed with :help <topic>. For example :help navigation will pull up documentation about how to navigate your workspace!

:help can also be used without an option. This will bring up a default help dialog that aims to make getting started with vim more approachable!

Modes:

Vim is based on the concept on modes.

  • Command Mode - vim starts up in this mode, used to navigate and write commands

  • Insert Mode - used to make changes in your file

  • Visual Mode - used to highlight text and do operations to them

  • Ex Mode - used to drop down to the bottom with the ā€˜:’ prompt to enter commands

    i                 # Puts vim into insert mode, before the cursor position
    a                 # Puts vim into insert mode, after the cursor position
    v                 # Puts vim into visual mode
    :                 # Puts vim into ex mode
    <esc>             # 'Escapes' from whichever mode you're in, into Command mode

    # Copying and pasting text
                      # Operations use the vim register by default
                      # Think of it as vim's private clipboard

                      # Yank ~ copy text into vim register
    y                 # Yank whatever is selected
    yy                # Yank the current line

                      # Delete ~ yank text and delete from file
    d                 # Delete whatever is selected
    dd                # Delete the current line

    p                 # Paste text in vim register after the current cursor position
    P                 # Paste text in vim register before the current cursor position

    x                 # Delete character under current cursor position

The ā€˜Grammar’ of vim

Vim can be thought of as a set of commands in a ā€˜Verb-Modifier-Noun’ format, where:

  • Verb - your action

  • Modifier - how you’re doing your action

  • Noun - the object on which your action acts on

A few important examples of ā€˜Verbs’, ā€˜Modifiers’, and ā€˜Nouns’:

    # 'Verbs'

    d                 # Delete
    c                 # Change
    y                 # Yank (copy)
    v                 # Visually select

    # 'Modifiers'

    i                 # Inside
    a                 # Around
    NUM               # Number (NUM is any number)
    f                 # Searches for something and lands on it
    t                 # Searches for something and stops before it
    /                 # Finds a string from cursor onwards
    ?                 # Finds a string before cursor

    # 'Nouns'

    w                 # Word
    s                 # Sentence
    p                 # Paragraph
    b                 # Block

    # Sample 'sentences' or commands

    d2w               # Delete 2 words
    cis               # Change inside sentence
    yip               # Yank inside paragraph (copy the para you're in)
    ct<               # Change to open bracket
                      # Change the text from where you are to the next open bracket
    d$                # Delete till end of line

Some shortcuts and tricks

    <!--TODO: Add more!-->
    >                 # Indent selection by one block
    <                 # Dedent selection by one block
    :earlier 15m      # Reverts the document back to how it was 15 minutes ago
    :later 15m        # Reverse above command
    ddp               # Swap position of consecutive lines, dd then p
    .                 # Repeat previous action
    :w !sudo tee %    # Save the current file as root
    :set syntax=c     # Set syntax highlighting to 'c'
    :sort             # Sort all lines
    :sort!            # Sort all lines in reverse
    :sort u           # Sort all lines and remove duplicates
    ~                 # Toggle letter case of selected text
    u                 # Selected text to lower case
    U                 # Selected text to upper case
    J                 # Join the current line with the next line

    # Fold text
    zf                # Create fold from selected text
    zd                # Delete fold on the current line
    zD                # Recursively delete nested or visually selected folds
    zE                # Eliminate all folds in the window
    zo                # Open current fold
    zO                # Recursively open nested or visually selected folds
    zc                # Close current fold
    zC                # Recursively close nested or visually selected folds
    zR                # Open all folds
    zM                # Close all folds
    za                # Toggle open/close current fold
    zA                # Recursively toggle open/close nested fold
    [z                # Move to the start of the current fold
    ]z                # Move to the end of the current fold
    zj                # Move to the start of the next fold
    zk                # Move to the end of the previous fold

Macros

Macros are basically recordable actions. When you start recording a macro, it records every action and command you use, until you stop recording. On invoking a macro, it applies the exact same sequence of actions and commands again on the text selection.

    qa                # Start recording a macro named 'a'
    q                 # Stop recording
    @a                # Play back the macro

Configuring ~/.vimrc

The .vimrc file can be used to configure Vim on startup.

Here’s a sample ~/.vimrc file:

" Example ~/.vimrc
" 2015.10

" Required for vim to be iMproved
set nocompatible

" Determines filetype from name to allow intelligent auto-indenting, etc.
filetype indent plugin on

" Enable syntax highlighting
syntax on

" Better command-line completion
set wildmenu

" Use case insensitive search except when using capital letters
set ignorecase
set smartcase

" When opening a new line and no file-specific indenting is enabled,
" keep same indent as the line you're currently on
set autoindent

" Display line numbers on the left
set number

" Indentation options, change according to personal preference

" Number of visual spaces per TAB
set tabstop=4

" Number of spaces in TAB when editing
set softtabstop=4

" Number of spaces indented when reindent operations (>> and <<) are used
set shiftwidth=4

" Convert TABs to spaces
set expandtab

" Enable intelligent tabbing and spacing for indentation and alignment
set smarttab

References

$ vimtutor

Vim
Vim | Home
A vim Tutorial and Primer
What are the dark corners of Vim your mom never told you about? (Stack Overflow thread)
Arch Linux Wiki