When you can't save a read-only file, the command below can.
:w !sudo tee % >/dev/null
: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"
To create an alias for this command put the content below inside ~/.vimrc
file:
cnoremap sudow w !sudo tee % >/dev/null
To use the new alias, type :sudow
inside Vim editor
sudo update-alternatives --config editor
Set to global context:
export VISUAL=vim
export EDITOR="$VISUAL"
Set core.editor in your Git config:
git config --global core.editor "vim"
Set the GIT_EDITOR environment variable:
export GIT_EDITOR=vim
dw ---> Delete the word from your cursor to the end of the word
diw ---> Delete inside word.
daw ---> Delete all words from your cursor
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.
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
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.