Vim

10:12AMAugust 19 2020Daniel Tompkins

Archive KB

Com­mands

Toggle Wrapped Lines

Same func­tion in Lua (for Neovim)

noremap <silent> <Leader>tw :call ToggleWrap()<CR> function ToggleWrap() if &wrap echo "Wrap OFF" setlocal nowrap set virtualedit=all else echo "Wrap ON" setlocal wrap linebreak nolist set virtualedit= setlocal display+=lastline endif endfunction
vimscript

Char­acter Ma­nip­u­la­tion

Concatenate lines of text with yanked lines
:5,8del | let x=split(@") | 1,4s/$/\=remove(x,0)/
vimscript
Remove characters after match on every line
:%s/[^total:]*$//g
vimscript
Remove characters before match on every line
:%s/[^total:]*$//g
vimscript

Se­lect vi­sual block from start to "foo"

Pressing down Shift or Ctrl, fol­lowed by v (so that two key are de­pressed at the same time) will vi­su­ally se­lect a row or a cell, re­spec­tively.

Now, press / and type foo to se­lect from this cur­rent se­lec­tion until the first in­stance of foo.

Hit Return (or Enter) to ac­cept. Press n to ad­vance to the next in­stance, or hold Shift and press n to go back to a pre­vious in­stance.