vim - Howto's | vitrubio.net

vim

vim editor

howto personalize

edit ~/.vimrc to add options

" edited on 2022 12 29
" https://www.freecodecamp.org/news/vimrc-configuration-guide-customize-your-vim-editor/
" apply changes do
" :soruce ~/.vimrc
"
set encoding=utf-8
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set autoindent
set number
set cursorline
set cursorcolumn
set showcmd
set showmode
set hlsearch
set incsearch
set showmatch

organize .vimrc

at the bottom add to .vimrc

"
" PLUGINS ---------------------------------------------------------------- {{{

" Plugin code goes here.

" }}}


" MAPPINGS --------------------------------------------------------------- {{{

" Mappings code goes here.

" }}}


" VIMSCRIPT -------------------------------------------------------------- {{{

" More Vimscripts code goes here.

" }}}


" STATUS LINE ------------------------------------------------------------ {{{

" Status bar code goes here.

" }}}

folding lines

https://www.freecodecamp.org/news/vimrc-configuration-guide-customize-your-vim-editor#how-to-fold-long-files-in-vim

in the VIMSCRIPT section add:

" This will enable code folding.
" Use the marker method of folding.
augroup filetype_vim
    autocmd!
    autocmd FileType vim setlocal foldmethod=marker
augroup END

save file :w and load changes :source ~/.vimrc then:

  • zo to open a single fold under the cursor.
  • zc to close the fold under the cursor.
  • zR to open all folds.
  • zM to close all folds.

plugins

case of vim-plug

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

then edit .vimrc add in section PLUGINS:

call plug#begin('~/.vim/plugged')

call plug#end()

add the github repositorys in short form as Plug 'username/plugin-name' in between the call plug ex:

" PLUGINS ------------------------------------------- {{{
call plug#begin('~/.vim/plugged')
  Plug 'dense-analysis/ale'
  Plug 'preservim/nerdtree'
call plug#end()
" }}}

save file :w and load changes :source ~/.vimrc then:

  • :PlugInstall to dwonload and install the listed plugins.

commands

auto indent

do this commands esc then gg=G

search replace regex

between brackets special characters

having <foo what ever s&imbol some 234 and something> searching from firts < until first >

need to match anything using * except the first > sot it will stop, and then find the >

/\<foo[^>]*\>

this means

  • / seach
  • starting with\<foo\
  • anything but > [^>]* so it finds > everything but the last >
  • then find next > using \>

delete everythin between brackest and them too

search the previous metod and repace with nothing

:%s/\<foo[^>]*\>//g