VIM outil indispensable

Installation de VIM

VIM est l'éditeur ultime indispensable sur un serveur linux. Il est presque aussi indispensable d'installer NERDTREE qui vous permet de remplacer un IDE comme VisualCode au travers d'une simple console SSH:

apt-get install vim
mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
git clone https://github.com/pangloss/vim-javascript.git ~/.vim/bundle/vim-javascript

Voici un exemple de fichier vimrc:

~$ cat ~/.vimrc
" General Config
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
autocmd vimenter * silent! lcd %:p:h
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
set showmatch                                     " vérification présence ([ ou { à la frappe de )] ou }
set shiftwidth=4                                  " nombre de tabulation pour l'indentation
set showcmd                                       " affiche la commande en cours
set backspace=indent,eol,start                    " autorisation du retour arrière
autocmd FileType text setlocal textwidth=72       " les fichiers de type .txt sont limites à 72 caractères par ligne
set fileformats=unix,mac,dos                      " gestion des retours chariot en fonction du type de fichier
set ignorecase                                    " ne pas prendre en compte la casse pour les recherches
set nolist                                        " on n'affiche pas les caractères non imprimables
set listchars=eol:¶,tab:..,trail:~                " paramétrage des caractères non imprimables
"Mapping pour désactiver le surlignage des résultats d'une recherche
nnoremap <silent> <C-N> :noh<CR>
set nocompatible
syntax on
set autoindent
set cindent
execute pathogen#infect()
noremap <F9> :bp<cr>:bd #<cr>
map <F12> :bn<CR>
map <F2> :NERDTreeToggle<CR>
map <F5> :NERDTreeToggle %<CR>
" Open NERDTree in the directory of the current file (or /home if no file is open)
nmap <silent> <F4> :call NERDTreeToggleInCurDir()<cr>
function! NERDTreeToggleInCurDir()
  " If NERDTree is open in the current buffer
  if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
    exe ":NERDTreeClose"
  else
    exe ":NERDTreeFind"
  endif
endfunction
"noremap <C-w>n :NERDTreeToggle<cr>
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists(“s:std_in”) | NERDTree | endif
"map <F3> :NERDTreeFind<CR>
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"autocmd vimenter * NERDTree
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
let g:NERDTreeMouseMode=3
" Run NERDTreeTabs on console vim startup.
" " When set to 2, open only if directory was given as startup argument.
let g:nerdtree_tabs_open_on_console_startup = 2
" " On startup, focus NERDTree if opening a directory, focus file if opening a
" file.
let g:nerdtree_tabs_smart_startup_focus = 1
" " Open NERDTree Tabs on new tab
let g:nerdtree_tabs_open_on_new_tab = 1
" " Make sure that Focus is on the file window when switching into a tab
let g:nerdtree_tabs_focus_on_files = 1
" " Automatically find and select currently opened file in NERDTree.
let g:nerdtree_tabs_autofind = 1
let NERDTreeMouseMode=2
augroup MouseInNERDTreeOnly
    autocmd!
    autocmd BufEnter NERD_tree_* set mouse=a
    autocmd BufLeave NERD_tree_* set mouse=
augroup END
set mouse=
set number                      "Line numbers are good
set backspace=indent,eol,start  "Allow backspace in insert mode
set history=1000                "Store lots of :cmdline history
set showcmd                     "Show incomplete cmds down the bottom
set showmode                    "Show current mode down the bottom
set gcr=a:blinkon0              "Disable cursor blink
set visualbell                  "No sounds
set autoread                    "Reload files changed outside vim
set hidden
set noswapfile
set nobackup
set nowb
if has('persistent_undo')
    silent !mkdir ~/.vim/backups > /dev/null 2>&1
    set undodir=~/.vim/backups
    set undofile
endif
set autoindent
set smartindent
set smarttab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set expandtab
" Auto indent pasted text
nnoremap p p=`]<C-o>
nnoremap P P=`]<C-o>
let g:solarized_termtrans = 1
set background=light
colorscheme desert
set hlsearch
set incsearch
nmap j gj
nmap k gk
autocmd BufReadPre,FileReadPre *.md :set wrap
autocmd FocusLost * silent! wa " Automatically save file
set scrolloff=5 " Keep 5 lines below and above the cursor
set cursorline
set statusline=%t%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [FENC=%{&fileencoding}]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v]\ [%p%%]\ [LEN=%L]\
set laststatus=2

Previous Post Next Post