Vim

December 12, 2020 Application 3 minutes, 33 seconds

vimrc

:w !sudo tee %

This is the native vim way. There are plugins like FAR that will also do that for you.

In order to edit multiple files at once you need to load all of them in vim buffers by doing

:args `fd -e yaml`

You can replace the fd command that is responsible for generating the file list with any other suitable command like the regular find

Check your buffers with :buffers. Your desired files should be loaded.

Now execute a command on all openend buffers, in this case the search and replace:

:bufdo %s/SEARCH/REPLACE/ge | update
  • bufdo execute commands on all open buffers
  • % search the whole buffer
  • g globally meaning do not stop after the first hit in a line
  • e surpress warning when pattern is not found
  • update save all changes

:g/^$/d

vnoremap p "_dP

vim -b

  • SHIFT-v to select lines
  • `:norm Astring'

norm means type the following commands and the A stands for append

  • ^ to move to the start of the line
  • `CTRL-v' to block select your lines
  • SHIFT-I to insert your string (on one line)
  • ESC to insert the string on all lines

vim -p [file1] [file2] ...

vim +':w ++ff=unix' +':q' FILE

or for other endings

  • :w ++ff=dos
  • :w ++ff=mac

:map [<C-j>]
:verbose map [<C-j>]

Prints various information about vim like version, enabled features, compile flags and loaded configuration files.

:version

config using indent as fold method (see also Modeline):

set foldmethod=indent   
set foldnestmax=10
set nofoldenable
set foldlevel=2
  • za: Toogle at the current line
  • zo: Open fold
  • zc: Close fold
  • zR: Open all folds
  • zM: Close all folds
  • zm: Increases the foldlevel by one
  • zr: Decreases the foldlevel by one
  • zj Moves the cursor to the next fold
  • zk: Moves the cursor to the previous fold
  • [z: Move to start of open fold
  • ]z: Move to end of open fold
  • zf#j: Creates a fold from the cursor down # lines
  • zf/string Creates a fold from the cursor to string
  • zd: Deletes the fold at the cursor
  • zE: Deletes all folds

By setting set modeline=1 you can enable the Modeline Magic. When it is not working you can check the setting with the following command:

:verbose set modeline?

Some distros disable it with nomodeline in /etc/vimrc

Example usage folding: This line at the bottom of a file tells vim to use marker as foldmethod and fold all foldings after opening the file

" vim:foldmethod=marker:foldlevel=0

vim --startuptime vim.log

After starting vim

:profile start profile.log
:profile func *
:profile file *

Do the stuff that lags and then run :profile pause and quit vim. Inpsect profile.log

vim -D

:ccl[ose]
:cope[n]
:cp
:cn

:lcl[ose]
:lop[en]
:lp
:ln

In Linux use setxkbmap:

setxkbmap -option caps:escape # More options available
setxkbmap -option # to reset changes

In .config/nvim/init.vim (create if not existing)

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath=&runtimepath
source ~/.vimrc

  1. In insert mode
  2. C-k a question mark will appear
  3. Enter Co

Here is a cheatsheet about digraphs (how this is called)

A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.