Vim
Save read-only files
When you can't save a read-only file, the command below can.
:w !sudo tee % >/dev/nullCreate a directory and save a read-only file
:w !sudo mkdir ~/test && sudo tee %The output will appear:
W13: Warning: file "test/.file" was created by another program since the last edition
[O]K, (L)oad file:Then press "O"
Create alias
To create an alias for this command put the content below inside ~/.vimrc file:
cnoremap sudow w !sudo tee % >/dev/nullTo use the new alias, type :sudow inside Vim editor
Set vim as default editor
Alternative 1:
Alternative 2: Global Context
Set to global context:
Git
Set core.editor in your Git config:
Set the GIT_EDITOR environment variable:
Commands
Deleting words
The following mappings in your vimrc provide a quick way to move lines of text up or down. The mappings work in normal, insert and visual modes, allowing you to move the current line, or a selected block of lines.
In normal mode or in insert mode, press Alt-j to move the current line down, or press Alt-k to move the current line up.
After visually selecting a block of lines (for example, by pressing V then moving the cursor down), press Alt-j to move the whole block down, or press Alt-k to move the block up.
Last updated
Was this helpful?