Useful snippets

    Undo soft reset

    Mon 20. May 2024 | 2024-05-20

    git reflog

    copy hash (ex: 56e2f8f)

    git checkout main/develop
    git merge 56e2f8f

    Vim read path commands

    Thu 29. February 2024 | 2024-02-29

    Vim read path commands

    Print path til project

    :pwd
    

    Print path til åpen vim buffer

    :echo expand('%:p')
    

    lazygit issues

    Tue 20. February 2024 | 2024-02-20

    • kan ikke alltid pulle eller pushe fra branch window.
    • rename branch usynliggjør tekst mens man beveger markøren bakover, men kommer tilbake igjen når man skriver igjen
    • åpne lazygit stash og så klikke _ (underscore). Så ser man ikke innholdet i den stashen. MAn må bevege seg ned og opp igjen først

    Neovim reference manual - clipboard

    Sat 17. February 2024 | 2024-02-17

    provider.txt Nvim

    NVIM REFERENCE MANUAL by Thiago de Arruda

    Providers provider

    Nvim delegates some features to dynamic "providers". This document describes the providers and how to install them. E319 Use of a feature requiring a missing provider is an error:

    E319: No "foo" provider found. Run ":checkhealth provider"

    Run the |:checkhealth| command, and review the sections below.

    [...]

    ============================================================================== Clipboard integration provider-clipboard clipboard

    Nvim has no direct connection to the system clipboard. Instead it depends on a |provider| which transparently uses shell commands to communicate with the system clipboard or any other clipboard "backend".

    To ALWAYS use the clipboard for ALL operations (instead of interacting with the "+" and/or "*" registers explicitly): >vim set clipboard+=unnamedplus

    See 'clipboard' for details and options.

    clipboard-tool The presence of a working clipboard tool implicitly enables the '+' and '*' registers. Nvim looks for these clipboard tools, in order of priority:

    • |g:clipboard|

    • pbcopy, pbpaste (macOS)

    • wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)

    • waycopy, waypaste (if $WAYLAND_DISPLAY is set)

    • xclip (if $DISPLAY is set)

    • xsel (if $DISPLAY is set)

    • lemonade (for SSH) https://github.com/pocke/lemonade

    • doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/

    • win32yank (Windows)

    • termux (via termux-clipboard-set, termux-clipboard-set)

    • tmux (if $TMUX is set)

      g:clipboard To configure a custom clipboard tool, set g:clipboard to a dictionary. For example this configuration integrates the tmux clipboard: >vim

        let g:clipboard = {
              \   'name': 'myClipboard',
              \   'copy': {
              \      '+': ['tmux', 'load-buffer', '-'],
              \      '*': ['tmux', 'load-buffer', '-'],
              \    },
              \   'paste': {
              \      '+': ['tmux', 'save-buffer', '-'],
              \      '*': ['tmux', 'save-buffer', '-'],
              \   },
              \   'cache_enabled': 1,
              \ }
    

    If "cache_enabled" is |TRUE| then when a selection is copied Nvim will cache the selection until the copy command process dies. When pasting, if the copy process has not died the cached selection is applied.

    g:clipboard can also use functions (see |lambda|) instead of strings. For example this configuration uses the g:foo variable as a fake clipboard:

    vim

        let g:clipboard = {
              \   'name': 'myClipboard',
              \   'copy': {
              \      '+': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
              \      '*': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
              \    },
              \   'paste': {
              \      '+': {-> get(g:, 'foo', [])},
              \      '*': {-> get(g:, 'foo', [])},
              \   },
              \ }
    

    The "copy" function stores a list of lines and the register type. The "paste" function returns the clipboard as a [lines, regtype] list, where lines is a list of lines and regtype is a register type conforming to |setreg()|.

    clipboard-wsl For Windows WSL, try this g:clipboard definition:

    vim

        let g:clipboard = {
                    \   'name': 'WslClipboard',
                    \   'copy': {
                    \      '+': 'clip.exe',
                    \      '*': 'clip.exe',
                    \    },
                    \   'paste': {
                    \      '+': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
                    \      '*': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
                    \   },
                    \   'cache_enabled': 0,
                    \ }
    

    ============================================================================== Paste provider-paste paste

    "Paste" is a separate concept from |clipboard|: paste means "dump a bunch of text to the editor", whereas clipboard provides features like |quote+| to get and set the OS clipboard directly. For example, middle-click or CTRL-SHIFT-v (macOS: CMD-v) in your terminal is "paste", not "clipboard": the terminal application (Nvim) just gets a stream of text, it does not interact with the clipboard directly.

    bracketed-paste-mode Pasting in the |TUI| depends on the "bracketed paste" terminal capability, which allows terminal applications to distinguish between user input and pasted text. https://cirw.in/blog/bracketed-paste This works automatically if your terminal supports it.

    ui-paste GUIs can paste by calling |nvim_paste()|.

    PASTE BEHAVIOR

    Paste inserts text after the cursor. Lines break at , , and . When pasting a huge amount of text, screen-updates are throttled and the message area shows a "..." pulse.

    In cmdline-mode only the first line is pasted, to avoid accidentally executing many commands. Use the |cmdline-window| if you really want to paste multiple lines to the cmdline.

    You can implement a custom paste handler by redefining |vim.paste()|. Example: >lua

    vim.paste = (function(lines, phase) vim.api.nvim_put(lines, 'c', true, true) end)

    ============================================================================== X11 selection mechanism clipboard-x11 x11-selection

    X11 clipboard providers store text in "selections". Selections are owned by an application, so when the application gets closed, the selection text is lost. The contents of selections are held by the originating application (e.g., upon a copy), and only passed to another application when that other application requests them (e.g., upon a paste).

    primary-selection quotestar quoteplus quote+

    There are three documented X11 selections: PRIMARY, SECONDARY, and CLIPBOARD. CLIPBOARD is typically used in X11 applications for copy/paste operations (CTRL-c/CTRL-v), while PRIMARY is used for the last selected text, which is generally inserted with the middle mouse button.

    Nvim's X11 clipboard providers only use the PRIMARY and CLIPBOARD selections, for the "*" and "+" registers, respectively.

    ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl:

    Neovim WSL copy to Windows system clipboard

    Tue 13. February 2024 | 2024-02-13

    EDIT:

    unnamedplus funker for WSL. men bare ikke i windows 11 ser det ut som?

    See if Neovim lacks Clipboard

    :CheckHealth
    
    Clipboard (optional) ~
    - WARNING No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.
      - ADVICE:
        - :help |clipboard|
    

    Clipboard help: https://useful-snippets.netlify.app/posts/neovim-reference-manual/

    Copy entire line

    1. Select entire line visual mode
    2. Enter command:
    :'<,'>w !clip.exe

    https://stackoverflow.com/questions/61550552/how-to-copy-paste-from-vim-in-wsl

    Click & drag method

    1. :set mouse= Neovim config already has this set as default
    2. Click & drag
    3. Ctrl C

    Should be able to paste text content anywhere else

    copy from vim wsl

    Image: Copy paste " - Javascript" to OS system clipboard


    set clipboard+=unnamed funker for Ideavim (.ideavimrc). Neovim gjennom WSL trenger kanskje mer verktøy for å funke

    Repeatedly run same command

    Tue 06. February 2024 | 2024-02-06

    Run "npm run build" 10 times

    for i in {1..10}; do npm run build; done

    Wait beetween commands

    for i in {1..10}; do npm run build && sleep 1; done