Vim como IDE de Múltiplas Linguagens - Inclusive AEL (Asterisk)

Publicado por Felipe em 23/02/2020

[ Hits: 2.855 ]

 


Vim como IDE de Múltiplas Linguagens - Inclusive AEL (Asterisk)



O Vim é, sem dúvidas, um dos melhores editores de texto que existe. Abaixo, segue como através de plugins e algumas configurações, como transforma-lo numa verdadeira IDE.

Instalação do Vim e Ctags:

apt-get install vim ctags -fy

Instalação do gerenciador de plugins para Vim:

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Criação da pasta "ctags", onde ficará o arquivo para reconhecer AEL:

mkdir /usr/share/ctags

Criar arquivo com nome "syntax" como abaixo, dentro de ~/.vim/:

touch ~/.vim/syntax
vim ~/.vim/syntax

" Vim syntax file
" Language: AEL (Asterisk Extension Language)
" Maintainer:   C. Chad Wallace <cmdrwalrus@gmail.com>
" Last Change:  2010 January 27
" Version:  0.3

" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
  finish
endif

" Top-level blocks

" globals block
syn match   aelGlobalsKeyword   "\<globals\>" nextgroup=aelGlobalsBlock skipwhite
syn region  aelGlobalsBlock     start="{" end="};\=" contained contains=aelGlobalVar,aelComment
syn match   aelGlobalVar        "\<\h*\ze=" contained nextgroup=aelGlobalVarExpression
syn match   aelGlobalVarExpression  ".*;" contained contains=aelInterpol,aelExpr,aelString

" macro blocks
syn match   aelMacroKeyword     "\<macro\>" nextgroup=aelMacroName skipwhite
syn match   aelMacroName        "\<\h*" contained nextgroup=aelMacroParms skipwhite
syn match   aelMacroParms       "(\(\s*\h\w*\(\s*,\s*\h\w*\)*\)\=\s*)" contained contains=aelMacroParm nextgroup=aelMacroBlock skipwhite
syn match   aelMacroParm        "\<\h\w*\>" contained
syn region  aelMacroBlock       start="{" end="};\=" contained contains=@aelStatement,aelCatch,aelLabel,aelComment

" Things you'll find inside a macro
syn match   aelCatch        "\<catch\>" nextgroup=aelCatchName skipwhite
syn match   aelCatchName        "\<\w\+\>" contained nextgroup=aelCatchBlock skipwhite
syn region  aelCatchBlock       start="{" end="};\=" contained contains=@aelStatement,aelLabel,aelComment

" context blocks
syn match   aelContextKeyword   "\<context\>" nextgroup=aelContextName skipwhite
syn match   aelContextName      "\<\h*\>" contained nextgroup=aelContextBlock skipwhite
syn region  aelContextBlock     start="{" end="};\=" contained contains=aelIncludes,aelIgnorepat,aelExtension,aelComment

" Things you'll find inside a context
syn match   aelIncludes     "\<includes\>" contained nextgroup=aelIncludesBlock skipwhite
syn region  aelIncludesBlock    start="{" end="};\=" contained contains=aelIncludeContext,aelComment
syn match   aelIncludeContext   "\<\h*\ze;" contained contains=aelComment

syn match   aelIgnorepat        "\<ignorepat\(\s*=>\s*\)\@=" contained nextgroup=aelIgnorepatNeck skipwhite
syn match   aelIgnorepatNeck    "=>" contained nextgroup=aelIgnorepatPattern skipwhite
syn match   aelIgnorepatPattern "\<*[.!]\=" contained contains=aelComment

syn match   aelExtension        "\(ignorepat\)\@!\(_*[.!]\=\|\+\)\(/\(_*[.!]\=\|\+\)\)\=\(\s*=>\s*\)\@=" contained nextgroup=aelExtensionNeck skipwhite
syn match   aelExtensionNeck    "=>" contained nextgroup=aelExtensionBlock,aelExtensionSingle skipwhite
syn region  aelExtensionBlock   start="{" end="};\=" contained contains=@aelStatement,aelLabel,aelComment
syn match   aelExtensionSingle  ".*;" contained contains=@aelStatement skipwhite

" Dialplan Statements (priorities)
syn cluster aelStatement        contains=aelSet,aelApplication,aelIfWhile,aelFor,aelElse,aelSwitch,aelGoto,aelMacroCall

syn match   aelSet          "\<Set\ze\s*(" contained nextgroup=aelSetOpenParen skipwhite
syn match   aelSetOpenParen     "(" contained nextgroup=aelSetVariable skipwhite
syn match   aelSetVariable      "\+\((\+)\)\=\ze=" contained nextgroup=aelSetExpression skipwhite
syn match   aelSetExpression    ".*\ze)" contained contains=aelInterpol,aelExpr,aelString

syn match   aelApplication      "\<\(Set\)\@!\h\w*\ze\s*(" contained nextgroup=aelAppOpenParen skipwhite
syn match   aelAppOpenParen     "(" contained nextgroup=aelAppExpression skipwhite
syn match   aelAppExpression    ".*\ze)" contained contains=aelInterpol,aelExpr,aelString

syn match   aelIfWhile      "\<if\|while\>" contained nextgroup=aelIfWhileCond skipwhite
syn match   aelIfWhileCond      "(.*)" contained contains=aelInterpol,aelExpr,aelString,aelOperator nextgroup=aelIfWhileBlock,aelIfElseBlock skipwhite
syn region  aelIfWhileBlock     start="{" end="};\=" contained contains=@aelStatement,aelLabel,aelComment
syn region  aelIfElseBlock      start="{" end="}" contained contains=@aelStatement,aelLabel,aelComment nextgroup=aelElse skipwhite skipnl
syn match   aelElse         "\<else\>" contained nextgroup=aelElseBlock skipwhite
syn region  aelElseBlock        start="{" end="};\=" contained contains=@aelStatement,aelLabel,aelComment

syn match   aelFor          "\<for\>" contained nextgroup=aelForInit skipwhite
syn match   aelForInit      "(.\{-};" contained contains=aelInterpol,aelExpr,aelString,aelOperator nextgroup=aelForCond skipwhite
syn match   aelForCond      ".\{-};" contained contains=aelInterpol,aelExpr,aelString,aelOperator nextgroup=aelForAction skipwhite
syn match   aelForAction        ".*)" contained contains=aelInterpol,aelExpr,aelString,aelOperator nextgroup=aelForBlock skipwhite
syn region  aelForBlock     start="{" end="};\=" contained contains=@aelStatement,aelLabel,aelComment

syn match   aelSwitch       "\<switch\>" contained nextgroup=aelSwitchCond skipwhite
syn match   aelSwitchCond       "(.*)" contained contains=aelInterpol,aelExpr,aelString nextgroup=aelSwitchBlock skipwhite
syn region  aelSwitchBlock      start="{" end="};\=" contained contains=@aelStatement,aelSwitchBreak,aelSwitchCase,aelSwitchDefault,aelComment
syn match   aelSwitchCase       "\<case\>" contained nextgroup=aelSwitchCaseVal skipwhite
syn match   aelSwitchCaseVal    "\s*\zs.*\ze:" contained contains=aelInterpol,aelExpr
syn match   aelSwitchDefault    "\<default\ze:" contained
syn keyword aelSwitchBreak      break contained

syn match   aelGoto         "\<goto\>" contained nextgroup=aelGotoTarget skipwhite
syn match   aelGotoTarget       "\(\(\+|\)\=\+|\)\=\+" contained contains=aelInterpol,aelGotoPipe
syn match   aelGotoPipe     "|" contained

syn match   aelMacroCall        "&\h*\>" contained nextgroup=aelMacroCallParms skipwhite
syn match   aelMacroCallParms   "(.*)" contained contains=aelInterpol,aelString,aelExpr skipwhite

" Generic
syn match   aelLabel        "\<\h*\ze:" contained
syn match   aelComment      "//.*$"
syn region  aelMlComment        start=/\/\*/ end=/\*\//
syn region  aelString       start=/"/ skip=/\\"/ end=/"/ contained contains=aelInterpol,aelExpr
syn region  aelInterpol     start="${" end="}" contained contains=aelInterpol,aelExpr
syn region  aelExpr         matchgroup=aelOperator start="$\[" end="\]" contained contains=aelInterpol,aelString,aelOperator
syn match   aelOperator     "=\~\|" contained

" Synchronization
syn sync    minlines=150
syn sync match  aelMacroSync        grouphere aelMacroBlock "\<macro\>\s*\<\h*\>\s*(\(\s*\h\w*\(\s*,\s*\h\w*\)*\)\=\s*)\s*{"
syn sync match  aelContextSync      grouphere aelContextBlock "\<context\>\s*\<\h*\>\s*{"
syn sync match  aelGlobalsSync      grouphere aelGlobalsBlock "\<globals\>\s*{"

" Highlighting

" Keywords
hi def link aelGoto         aelStatement
hi def link aelStatement        Statement
hi def link aelIfWhile      aelConditional
hi def link aelElse         aelConditional
hi def link aelFor          aelConditional
hi def link aelSwitch       aelConditional
hi def link aelConditional      Conditional
hi def link aelSwitchCase       aelLabel
hi def link aelSwitchDefault    aelLabel
hi def link aelCase         aelLabel
hi def link aelLabel        Label
hi def link aelCatch        aelException
hi def link aelException        Exception

hi def link aelIncludes     aelKeyword
hi def link aelIgnorepat        aelKeyword
hi def link aelGlobalsKeyword   aelKeyword
hi def link aelMacroKeyword     aelKeyword
hi def link aelContextKeyword   aelKeyword
hi def link aelSwitchBreak      aelKeyword
hi def link aelKeyword      Keyword

hi def link aelIgnorepatNeck    Operator
hi def link aelExtensionNeck    Operator
hi def link aelGotoPipe     Operator
hi def link aelOperator     Operator

" Literals
hi def link aelSwitchCaseVal    String
hi def link aelIgnorepatPattern String
hi def link aelExtension        String
hi def link aelString       String

" Identifiers
hi def link aelGotoTarget       aelIdentifier
hi def link aelIncludeContext   aelIdentifier
hi def link aelGlobalVar        aelIdentifier
hi def link aelContextName      aelIdentifier
hi def link aelMacroParm        aelIdentifier
hi def link aelSetVariable      aelIdentifier
hi def link aelInterpol     aelIdentifier
hi def link aelIdentifier       Identifier
hi def link aelMacroCall        aelFunction
hi def link aelMacroName        aelFunction
hi def link aelApplication      aelFunction
hi def link aelSet          aelFunction
hi def link aelFunction     Function

hi def link aelComment      Comment
hi def link aelMlComment        Comment

Download: syntax.txt

Alterar arquivo /etc/vim/vimrc, para:

" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below.  If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
syntax on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd        " Show (partial) command in status line.
"set showmatch      " Show matching brackets.
"set ignorecase     " Do case insensitive matching
"set smartcase      " Do smart case matching
"set incsearch      " Incremental search
"set autowrite      " Automatically save before commands like :next and :make
"set hidden     " Hide buffers when they are abandoned
"set mouse=a        " Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

set number
set tabstop=4
set list
set listchars=tab:>-
set nocompatible
filetype on
filetype plugin on
set background=dark
set guifont=Monaco
set foldenable

filetype plugin indent on " required
syntax on                 " required

autocmd Filetype * AnyFoldActivate               " activate for all filetypes
    " or
autocmd Filetype <your-filetype> AnyFoldActivate " activate for a
    "  specific filetype
    "
set foldlevel=0  " close all folds
    "    " or
set foldlevel=99 " Open all folds

" Vundle
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
filetype plugin indent on     " required!
" End Vundle
Plugin 'pseewald/vim-anyfold'
Plugin 'morhetz/gruvbox'
Plugin 'altercation/vim-colors-solarized'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'shougo/neocomplete.vim'
Plugin 'shougo/neocomplcache.vim'
Plugin 'shougo/vimshell.vim'
Plugin 'dzeban/vim-log-syntax'
Plugin 'txt.vim'
Plugin 'mtdl9/vim-log-highlighting'
Plugin 'pangloss/vim-javascript'
Plugin 'mbbill/undotree'
Plugin 'xolox/vim-notes'
Plugin 'xolox/vim-misc'
Plugin 'mattn/emmet-vim'
Plugin 'ael.vim'
Plugin 'sheerun/vim-polyglot'
Plugin 'shougo/neossh.vim'
Plugin 'haya14busa/incsearch.vim'
"PROCURAR SOBRE
Plugin 'paroxayte/vwm.vim'
let g:neocomplcache_enable_at_startup = 1
nmap <C-t> :TagbarToggle<CR>
nmap <C-a> :setf ael<CR>
map <C-n> :NERDTreeToggle<CR>
map <C-u> :UndotreeToggle<CR>
map <C-l> :set filetype=log<CR>
map <F5> <Esc>:w<CR>:! %:p<CR>
map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
nnoremap <space> za foldclosed(".") == -1 ? 'zc' : 'zv'
let g:notes_suffix = '.txt'
colorscheme gruvbox

let g:tagbar_type_ael = {
          \ 'ctagstype':'ael'
          \,'kinds':[
          \          'c:Contextos:1:0',
          \          'v:Variaveis:1:0',
          \          'm:Macros:1:0'
          \],
          \ 'deffile' : expand('<sfile>:p:h:h') . '/ctags/ael.cnf'
          \ }

autocmd Filetype * AnyFoldActivate
let g:anyfold_fold_comments=1
set foldlevel=0
"hi Folded term=NONE cterm=NONE
hi Folded term=underline

Download: vimrc.txt

Criar arquivo com nome "ael.cnf" como abaixo, dentro de /usr/share/ctags:

touch /usr/share/ctags/ael.cnf
vim /usr/share/ctags/ael.cnf

--langdef=ael
--langmap=ael:.ael
--regex-ael=/context[ \t]+([^ \t]+)[ \t]\{/\1/c/Contexts/
--regex-ael=/macro[ \t]+([^ \t]+)[ \t]\{/\1/m/Macros/
--regex-ael=/macro[ \t]+([^ \t]+)\{/\1/m/Macros/
--regex-ael=//v/Variaveis/

Após essas configurações, abrir o Vim e digitar:

:PluginInstall

Algumas funcionalidades:
  • crtl+l :: para arquivos de log
  • crtl+a :: para arquivos em AEL(asterisk)
  • crtl+n :: arvore de diretorios
  • crtl+t :: arvore de funções, metodos e variaveis
  • crtl+u :: arvore de alterações feitas enquanto arquivo aberto
  • , :: abre e fecha blocos de codigos
  • / e ? :: procura por termos
  • F5 :: salva e executa o codigo apenas para Bash, podendo ser alterado para qualquer linguagem alterando a linha 122 do vimrc
  • :Note :: abre o bloco de notas do Vim muito útil para anotações importantes

Outras dicas deste autor
Nenhuma dica encontrada.
Leitura recomendada

Acesso Remoto open-source com XRDP

Virtualização no Fedora 30

DIRF 2013 no Wine - Acertando formato da data

Configurando teclado em notebook Lenovo T400

Ubuntu 10.10: Resolvendo problema com Empathy

  

Comentários
[1] Comentário enviado por cizordj em 04/03/2020 - 23:13h

O Vim é muito top! Mas nunca consigo deixar ele igual uma IDE.

________________________________________________
O programador tem a mania de achar que tudo é objeto



Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts