Skip to content

railaru/nvim-typescript-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Preview

Modern Neovim setup

  • A full-featured Neovim setup for modern web development.

Features:

  • Prettier
  • TypeScript
  • Eslint
  • Fuzzy search (Telescope)
  • File tree
  • Git diff and merge conflict resolution (DiffView)

Getting started

  1. Make sure you have Neo Vim and Git installed on your system.
  2. Clone this repo: git clone https://github.com/railaru/modern-nvim-setup ~/.config/nvim
  3. Start Neo Vim in any directory on your system: nvim

Customization

Title Description
Color hex #232436
Font JetBrainsMono Nerd Font. Source: https://www.nerdfonts.com/font-downloads. I recommend one of the "nerdfonts" fonts, because the default system fonts often don't support file and folder icons.
Translucent effect If you're using iTerm on Mac, you can reduce opacity and add some background blur for a translucent effect.

Cheat sheet

Quick reminder for nvim/vim commands.

Commands

  • :w to save
  • u undo
  • K hover over a symbol to see the type definition
  • ctrl + r redo
  • g+g go to the top of the file instantly
  • g+c comment out the selected area. Works with JSX/TSX
  • ctrl + ] to go back and forth between the implementation and definition.
  • shift + : go to enter a command mode
  • shift + h go to previous editor tab
  • shift + l go to next editor tab
  • shift + > indent by a tab
  • shift + < remove indent by a tab
  • :%s/oldterm/newterm/g replace all matching references in the file. To use, first press : to open the command menu.
  • s to search for text within the same file
  • 0 go to start of a line horizontally
  • $ go to end of a line horizontally
  • o go to the line blow and enable the edit mode
  • shift + ] or [ jump between empty lines
  • ctrl + u or d scroll one full page up or down
  • ~/.config/nvim
  • :colorscheme github_dark to change theme. Full list of themes https://github.com/projekt0n/github-nvim-theme?tab=readme-ov-file#supported-colorschemes--comparisons.
  • zc, za collapse/expand code sections

You can combine commands. For example:

  • d + 3 + j will delete 3 lines below.
  • d + w will delete a word.

💡 Deleting also works as copying. You can delete a line and then type p to paste it somewhere else.

Horizontal navigation

  • vi( select everything between ()
  • vi{ select everything between {}
  • vi" select everything between ""
  • vi< select everything between <>
  • vi[ select everything between []

  • va( select everything between and around ()
  • va{ select everything between and around {}
  • va" select everything between and around ""
  • va< select everything between and around <>
  • va[ select everything between and around []

  • yi( yank everything between ()
  • yi{ yank everything between {}
  • yi" yank everything between ""
  • yi< yank everything between <>
  • yi[ yank everything between []

  • ya( yank everything between and around ()
  • ya{ yank everything between and around {}
  • ya" yank everything between and around ""
  • ya< yank everything between and around <>
  • ya[ yank everything between and around []

  • di( delete everything between ()
  • di{ delete everything between {}
  • di" delete everything between ""
  • di< delete everything between <>
  • di[ delete everything between []

  • da( delete everything between and around ()
  • da{ delete everything between and around {}
  • da" delete everything between and around ""
  • da< delete everything between and around <>
  • da[ delete everything between and around []

  • viw select the whole word, regardless of where the pointer is. By the way, while selected clicking shift + k or j will move the line up or down.

Insert mode

  • i enable insert mode
  • a enable insert mode one letter forward.
  • esc or ctrl + c or ctrl + [ leave insert mode

Visual mode:

  • v enable visual mode
  • y "yank" copy selected region. You can also type yy to automatically select the line for yanking. This is a similar action as dragging a selected region with mouse.
  • p paste the selected region
  • shift + v, "visual line mode", copy the region with the lines, not just the text.

💡 You can copy a region and select a new region, and it will delete and add the copied area to the selection.

💡 Yanking also works with numbers, for example y + 5 + j (copy 5 lines to bottom)

Custom keymaps

  • shift + f find files using the Telescope plugin. Similar to the double shift in JetBrains IDEs.

Git Integration (DiffView)

DiffView Commands

  • <leader>gd - Open DiffView to see current changes
  • <leader>gc - Close DiffView
  • <leader>gh - Open DiffView file history
  • <leader>gm - Open DiffView for merge conflicts
  • <leader>gr - Refresh DiffView

Merge Conflict Resolution

When in merge conflict resolution mode:

  • [x / ]x - Navigate between conflicts
  • <leader>co - Choose OURS version of conflict
  • <leader>ct - Choose THEIRS version of conflict
  • <leader>cb - Choose BASE version of conflict
  • <leader>ca - Choose ALL versions of conflict
  • <leader>cO - Choose OURS for entire file
  • <leader>cT - Choose THEIRS for entire file
  • dx - Delete the conflict region

DiffView Navigation

  • <tab> / <s-tab> - Navigate between files in diff
  • gf - Open file in previous tab
  • <C-w>gf - Open file in new tab
  • <leader>e - Toggle file panel

Neovim file Tree

  • up, down navigate between files.
  • enter select a file.
  • c copy a file and make a copy with a new name.
  • r rename a file
  • a add a new file in the folder
  • space + e toggle file tree

Prepending branch name for git commit messages

To automatically prepend the project and task number from your branch name into your commit messages, you can utilize a Git hook, specifically the prepare-commit-msg hook. This hook allows you to manipulate the commit message before it is finalized.

End result:

Branch name Commit name
feature/ABC-123 ABC-123: added a header

Here's a step-by-step guide to achieve this:

  1. Locate Your Git Hooks Directory: Every Git repository has a .git/hooks directory where you can place custom scripts to be executed at various stages of the Git workflow.

  2. Create a prepare-commit-msg Script: You need to create a script named prepare-commit-msg in the .git/hooks directory. This script will be executed before the commit message editor is opened.

  3. Script to Extract Information from Branch Name: The script should extract the project and task number from the branch name and prepend it to the commit message. Here's an example script in Bash:

    #!/bin/bash
    
    # The path to the file where the commit message is stored
    COMMIT_MSG_FILE=$1
    
    # Extract the branch name
    BRANCH_NAME=$(git symbolic-ref --short HEAD)
    
    # Use a regex to find the pattern 'ABC-XXX' where XXX is the task number
    if [[ $BRANCH_NAME =~ feature/(ABC-[0-9]+)-.* ]]; then
        # Prepend the extracted information to the commit message
        echo "${BASH_REMATCH[1]}: $(cat $COMMIT_MSG_FILE)" > $COMMIT_MSG_FILE
    fi

This script checks if the branch name matches the pattern and then prepends the project and task number (e.g., ABC-287) to the commit message.

Make the Script Executable: After saving the script in .git/hooks/prepare-commit-msg, make it executable:

chmod +x .git/hooks/prepare-commit-msg

Test Your Setup: Create a new commit on a branch that follows the naming convention. The script should automatically prepend the project and task number to your commit message.

Project-Wide Setup (Optional):

If you want this script to be used by anyone who clones the repository, you'll need to share it some other way, like committing it to the repository and having users set it up manually. Git doesn't clone the .git/hooks directory.

Resources & Further reading:

AI commits

Grep library for string search

💤 Built on top of LazyVim

A starter template for LazyVim. Refer to the documentation to get started.

About

Modern Neovim setup

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages