Useful snippets

    Tmux

    Wed 24. January 2024 | 2024-01-24

    Enter copy mode

    Ctrl [ eller begynn å scrolle

    Quit copy mode

    Ctrl c eller q

    https://stackoverflow.com/questions/67360866/tmux-exit-ctrl-b-and-stay-observing-the-session

    detach og tmux-attach:

    https://askubuntu.com/questions/824496/how-do-i-access-tmux-session-after-i-leave-it

    List sessions

    Navigate between sessions in tmux

    Ctrl b s

    Just list sessions

    tmux ls

    Med christoomey/vim-tmux-navigator package og instrukser fra https://www.josean.com/posts/tmux-setup / https://www.youtube.com/watch?v=U-omALWIBos&t=584s

    Resize pane

    Ctrl b h eller j eller k eller l

    Move between panes

    Ctrl h eller j eller k eller l

    Vim

    Wed 24. January 2024 | 2024-01-24

    https://vim.rtorr.com/

    Webstorm IdeaVim Shortcut settings

    Sun 21. January 2024 | 2024-01-21

    Setup

    Install IdeaVim plugin

    Setup ctrl Q for toggling Vim on/off

    Keymaps

    Settings

    Turn Vim on

    reserve certain shortcuts to IDE

    like:

    • ctrl Q so we can toggle Vim efficiently
    • ctrl C to enable copying to OS registry
    • ctrl V to enable pasting from OS registry

    settings

    Rocket

    Sat 13. January 2024 | 2024-01-13

    ^
    / _ \
    |   : |
    | 0. |
    /]   : [\
    /_] _. [_\
    |   |
    | |
    |
    |

    Rename React component

    Sat 13. January 2024 | 2024-01-13

    
    # ask in what path the component resides in
    # if no answer is provided, use default value
    # -e flag is for giving `cd`-code completion while answering the question
    
    defaultValue=src/components/
    
    read -e -p "Where is component located? (default: $defaultValue): " location
    location=${location:-$defaultValue}
    
    cd $location
    
    read -e -p "Enter component name you want to rename: " currentName
    
    cd $currentName
    
    # if component ends with a trailing slash
    if [[ "$currentName" == */ ]]; then
      # remove trailing slash
      currentName=${currentName%/}
    fi
    
    indexFile=index.ts
    componentFile=$currentName.tsx
    storyFile=$currentName.stories.tsx
    stylesheetFile=$currentName.module.css
    stylesheetScssFile=$currentName.module.scss
    
    if [[ $currentName != "" ]]; then
        echo
        echo "This will try and rename:"
        echo "---- folder -----"
        echo $currentName
        echo
        echo "---- files -----"
        echo - $indexFile
        echo - $componentFile
        echo - $storyFile
        echo - $stylesheetFile
        echo - $stylesheetScssFile
        echo
    
        read -p "Enter new name: " newName
        if [[ $newName != "" ]]; then
            echo
            echo "search replace in files"
            echo
    
            sed -i "s/$currentName/$newName/g" $indexFile
            sed -i "s/$currentName/$newName/g" $componentFile
            sed -i "s/$currentName/$newName/g" $storyFile
            sed -i "s/$currentName/$newName/g" $stylesheetFile
            sed -i "s/$currentName/$newName/g" $stylesheetScssFile
    
            echo
            echo "rename files and folders"
            echo
    
            mv $componentFile $newName.tsx
            mv $storyFile $newName.stories.tsx
            mv $stylesheetFile $newName.module.css
            mv $stylesheetScssFile $newName.module.scss
    
            cd ..
    
            mv $currentName $newName/
        fi
    fi
    
    

    IDE functionalities deactivated by Vim

    Sat 13. January 2024 | 2024-01-13

    hvor mye er deaktivert/ufordel i Webstorm/VSCode når du har på Vim plugin?

    Webstorm IdeaVim

    • IDE's multi-select with Ctrl D doesn't work with entering insert mode using eg. using a
    • but c works
    • Annoying to save file that is edited in commit changes window
      • if in normal mode, pressing "Esc" will exit "commit changes"-window
      • unlike when terminal is focused, you can't disable the "Esc-> focus normal file view"
    • paste from OS registry (copy paste from UI app into Webstorm in IdeaVim) Kan fikses ved å registrere ctrl C og ctrl V som IDE-shortcuts (se https://useful-snippets.netlify.app/posts/webstorm-ideavim-shortcut-settings/)
    • vim search not as good as built-in search
      • vim won't highlight/preview as you search/replace
      • to activate built-in search you would have to give up ctrl F and ctrl H to IDE

    VSCode's Vim

    • Fuzzy finder
    • Search?
    • Search in files?