Rockstable Wiki:

vim

About

Basic Adjustments

You can override /etc/vim/vimrc with /etc/vim/vimrc.local Create a local copy of /etc/vim/vimrc to let maintainer provide more distribution vimrc, that we don't want to interact during system upgrades. Try to acomplish this in vim itself, because a simple copy will create a ugly source recursion.

   1 % sudo vim /etc/vim/vimrc
   2 ### THEN TYPE:
   3 :% yank
   4 :vsp /etc/vim/vimrc.local
   5 P
   6 /" Source
   7 VGd
   8 :w
   9 

or just simply copy it and deal with the error

   1 cp /etc/vim/vimrc{,.local}

Configure vim globally:

/etc/vim/vimrc.local

   1 " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
   2 " the call to :runtime you can find below.  If you wish to change any of those
   3 " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
   4 " will be overwritten everytime an upgrade of the vim packages is performed.
   5 " It is recommended to make changes after sourcing debian.vim since it alters
   6 " the value of the 'compatible' option.
   7 
   8 " This line should not be removed as it ensures that various options are
   9 " properly set to work with the Vim-related packages available in Debian.
  10 runtime! debian.vim
  11 
  12 " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
  13 " This happens after /etc/vim/vimrc(.local) are loaded, so it will override
  14 " any settings in these files.
  15 " If you don't want that to happen, uncomment the below line to prevent
  16 " defaults.vim from being loaded.
  17 let g:skip_defaults_vim = 1
  18 
  19 " Uncomment the next line to make Vim more Vi-compatible
  20 " NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
  21 " options, so any other options should be set AFTER setting 'compatible'.
  22 "set compatible
  23 
  24 " Vim5 and later versions support syntax highlighting. Uncommenting the next
  25 " line enables syntax highlighting by default.
  26 syntax on
  27 
  28 " If using a dark background within the editing area and syntax highlighting
  29 " turn on this option as well
  30 set background=dark
  31 
  32 " Uncomment the following to have Vim jump to the last position when
  33 " reopening a file
  34 au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  35 
  36 " Uncomment the following to have Vim load indentation rules and plugins
  37 " according to the detected filetype.
  38 filetype plugin indent on
  39 
  40 " The following are commented out as they cause vim to behave a lot
  41 " differently from regular Vi. They are highly recommended though.
  42 set showcmd             " Show (partial) command in status line.
  43 set showmatch           " Show matching brackets.
  44 "set ignorecase         " Do case insensitive matching
  45 "set smartcase          " Do smart case matching
  46 "set incsearch          " Incremental search
  47 "set autowrite          " Automatically save before commands like :next and :make
  48 "set hidden             " Hide buffers when they are abandoned
  49 "set mouse=a            " Enable mouse usage (all modes)

colorscheme

List all color profiles

   1 dpkg -L vim-runtime \
   2         |grep 'colors/.*\.vim' \
   3         |xargs -L1 basename \
   4         |sed 's/\.vim//'
   5 blue
   6 darkblue
   7 default
   8 delek
   9 desert
  10 elflord
  11 evening
  12 industry
  13 koehler
  14 morning
  15 murphy
  16 pablo
  17 peachpuff
  18 ron
  19 shine
  20 slate
  21 check_colors
  22 torte
  23 zellner

Dark, high contrast, usable in vimdiff

   1 delek, murphy, slate, zellner

Change profile in vim

   1 :colorscheme slate

I like "slate" ~/.vimrc

   1 colorscheme slate

Synchronous scrolling of two buffers

vim-pathogen

   1 aptitude install vim-pathogen

~/.vimrc

   1 execute pathogen#infect()

vim-youcompleteme

   1 aptitude install vim-youcompleteme

~/.vimrc

   1 """ youcompleteme
   2 "let g:ycm_key_list_select_completion = ['<TAB>', '<Down>']
   3 "let g:ycm_key_list_previous_completion = ['<S-TAB>', '<Up>']
   4 "let g:ycm_key_list_stop_completion = ['<C-y>']
   5 let g:ycm_key_invoke_completion = '<C-Space>'

vim-syntastic

   1 aptitude install vim-syntastic

nerdtree

   1 cd
   2 mkdir -p ~/.vim/bundle
   3 cd ~/.vim/bundle
   4 git clone https://github.com/scrooloose/nerdtree.git

~/.vimrc

   1 """ NERDTree
   2 autocmd StdinReadPre * let s:std_in=1
   3 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
   4 
   5 "map <C-n> :NERDTreeToggle<CR>
   6 map <F2> :NERDTreeToggle<CR>

nerdtree-git-plugin

   1 cd ~/.vim/bundle
   2 git clone https://github.com/Xuyuanp/nerdtree-git-plugin.git

VIM mode digraph

attachment:vim.dot.svg

vim.dot

   1 digraph vim_mode {
   2 
   3         graph   [fontname="monospace"];
   4         node    [fontname="monospace"];
   5         edge    [fontname="monospace"];
   6 
   7         labelloc="t";
   8         label="VIM MODE DIAGRAPH";
   9 
  10         SHELL -> NORMAL [label="vim",weight=100];
  11         NORMAL -> SHELL [label="ZZ"];
  12         NORMAL  [shape="box"];
  13         NORMAL -> INSERT        [label="iIaAoOsS INS",weight=105]
  14         INSERT -> NORMAL        [label="ESC"];
  15         INSERT -> REPLACE       [label="INS"];
  16         REPLACE -> INSERT       [label="INS"];
  17         NORMAL -> REPLACE       [label="rR"];
  18         REPLACE -> NORMAL       [label="ESC"];
  19         NORMAL -> VISUAL        [label="vV^v"];
  20         VISUAL -> NORMAL        [label="ESC"];
  21         VISUAL -> EXECUTE       [label=":"];
  22         VISUAL -> INSERT        [label="IA"];
  23         VISUAL -> REPLACE       [label="r"];
  24         NORMAL -> EXECUTE       [label=":",weight=100];
  25         EXECUTE -> NORMAL       [label="ESC"];
  26         EXECUTE -> SHELL        [label="x wq q q!"];
  27 }

Create svgs

   1 dot -Tsvg -O vim.dot
   2 dot -Tsvg:cairo -O vim.dot

Cheat Sheet

Source http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html

Download the zip files

Basic editing
attachment:vi-vim-tutorial-1.svg

Operators & Repetition
attachment:vi-vim-tutorial-2.svg

Yank & Paste
attachment:vi-vim-tutorial-3.svg

Searching
attachment:vi-vim-tutorial-4.svg

Marks & Macros
attachment:vi-vim-tutorial-5.svg

Various Movements
attachment:vi-vim-tutorial-6.svg

Various Commands
attachment:vi-vim-tutorial-7.svg

Modelines

:help auto-setting
:help modeline
:help 'modeline' determines whether to look for modelines
:help 'modelines' number of lines checked to find each modeline 
  1. modelines maybe disabled in the system vimrc for security
    • enable it with :set modeline in session or .?vimrc

  2. Determine the file format's comment character or sequence

    e.g. # ; -- // {* *} <!-- -->  and leave space behind

  3. Place the modeline within 5 lines close to top or bottom
  4. Two syntaxes
    1. Without "set", no text can follow the options.

      # vim: syntax=named:sw=4:ts=4:

    2. With "set", the modeline ends at the first colon not following a backslash.

      # vim: set syntax=named sw=4 ts=4:

Syntax

Nginx

   1 mkdir -p ~/.vim/syntax
   2 wget -O ~/.vim/syntax/nginx.vim \
   3         'https://www.vim.org/scripts/download_script.php?src_id=19394'

~/.vim/filetype.vim

   1 au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif 

Rockstable Wiki: vim (last edited 2020-12-27 14:25:11 by RockStable)