vim (.vimrc)
vimrc cheio de firulas
Categoria: Vim
Software: vim
[ Hits: 9.316 ]
Por: Sérgio Luiz Araújo Silva
Tem coisas do tipo:
Atualizar data a cada vez que salvar o arquivo,
inserir número de linhas (dentro de um arquivo) e não apenas visualizar. Uma barra de status que exibe o valor decimal e hexa do caractere sob o cursor ... e muito mais :)
" ultima modificação: Ter 14 Dez 2004 15:49:44 BRST
" arquivo de configuração do vim
" ( O O )
" ====oOO==(_)==OOo=====
" Linhas comentadas são iniciadas por (") aspas duplas
" Permite recarregar o vim para que modificações no
" próprio vimrc seja ativadas com o mesmo sendo editado
nmap <F12> :<C-u>source $HOME/.vimrc <BAR> echo "Vimrc recarregado!"<CR>
" editar o .vimrc
map ,v :e ~/.vimrc<CR>
" Recarrega o .vimrc sem fecha-lo
map ,u :source ~/.vimrc<CR>
"Auto formatação para parágrafos
map <F8> gqap
" By default, go for an indent of 4
set shiftwidth=4
set softtabstop=4
set viminfo=%,'50,\"100,:100,n~/.vim/.viminfo
set undolevels=1000 " undoing 1000 changes should be enough :-)
set updatecount=100 " write swap file to disk after each 20 characters
set updatetime=6000 " write swap file to disk after 6 inactive seconds
set noerrorbells " don't make noise
set incsearch " habilita busca incremental
set ts=4 " Paradas de tabulação com 4 espaços
" Mover linhas com: Ctrl+(seta abaixo) ou (seta acima)
" tem que estar em modo normal!
map <C-Down> <esc>ddp<esc>
map <C-Up> <esc>ddkP<esc>
"-----------------------------------------------------
" se há modo gráfico ou se não (set de cores diferentes)
" este set de cores foi colocado aqui pois pode não existir
" baixe temas em: www.vi-improved.org
if has("gui_running")
" Vim color file
" Maintainer: Datila Carvalho <datila@saci.homeip.net>
" Last Change: November, 3, 2003
" Version: 0.1
" This is a VIM's version of the emacs color theme
" _Dark Blue2_ created by Chris McMahan.
""" Init stuff
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
" Vim color file
" Maintainer: Ajit J. Thakkar (ajit AT unb DOT ca)
" Last Change: 2003 Sep. 02
" Version: 1.0
" URL: http://www.unb.ca/chem/ajit/vim.htm
" This GUI-only color scheme has a blue-black background
let colors_name = "dusk"
hi Normal guifg=ivory guibg=#1f3048
" Groups used in the 'highlight' and 'guicursor' options default value.
hi ErrorMsg gui=NONE guifg=Red guibg=Linen
hi IncSearch gui=NONE guibg=LightBlue guifg=Black
hi ModeMsg gui=NONE guifg=fg guibg=bg
hi StatusLine gui=NONE guifg=DarkBlue guibg=Grey
hi StatusLineNC gui=NONE guifg=Grey50 guibg=Grey
hi VertSplit gui=NONE guifg=Grey guibg=Grey
hi Visual gui=reverse guifg=fg guibg=LightSkyBlue4
hi VisualNOS gui=underline guifg=fg guibg=bg
hi DiffText gui=NONE guifg=Yellow guibg=LightSkyBlue4
hi Cursor guibg=Green guifg=Black
hi lCursor guibg=Cyan guifg=Black
hi Directory guifg=LightGreen guibg=bg
hi LineNr guifg=MistyRose3 guibg=bg
hi MoreMsg gui=NONE guifg=SeaGreen guibg=bg
hi NonText gui=NONE guifg=Cyan4 guibg=#102848
hi Question gui=NONE guifg=LimeGreen guibg=bg
hi Search gui=NONE guifg=SkyBlue4 guibg=Bisque
hi SpecialKey guifg=Cyan guibg=bg
hi Title gui=NONE guifg=Yellow2 guibg=bg
hi WarningMsg guifg=Tomato3 guibg=Linen
hi WildMenu gui=NONE guifg=SkyBlue4 guibg=Bisque
hi Folded guifg=MistyRose2 guibg=bg
hi FoldColumn guifg=DarkBlue guibg=Grey
hi DiffAdd gui=NONE guifg=Blue guibg=LightCyan
hi DiffChange gui=NONE guifg=white guibg=LightCyan4
hi DiffDelete gui=NONE guifg=LightBlue guibg=LightCyan
" Colors for syntax highlighting
hi Constant gui=NONE guifg=MistyRose3 guibg=bg
hi String gui=NONE guifg=LightBlue3 guibg=bg
hi Special gui=NONE guifg=GoldenRod guibg=bg
hi Statement gui=NONE guifg=khaki guibg=bg
"hi Statement gui=NONE guifg=#d7cd7b guibg=bg
hi Operator gui=NONE guifg=Chartreuse guibg=bg
hi Ignore gui=NONE guifg=bg guibg=bg
hi ToDo gui=NONE guifg=DodgerBlue guibg=bg
hi Error gui=NONE guifg=Red guibg=Linen
hi Comment gui=NONE guifg=SlateGrey guibg=bg
hi Comment gui=NONE guifg=Lavender guibg=bg
hi Identifier gui=NONE guifg=BlanchedAlmond guibg=bg
hi PreProc gui=NONE guifg=#ffa0a0 guibg=bg
hi Type gui=NONE guifg=NavajoWhite guibg=bg
hi Underlined gui=underline guifg=fg guibg=bg
set gfn=Bitstream\ Vera\ Sans\ Mono\ 10
else
colo elflord
endif
" se estiver no KDE use a fonte: Bistream Vera Sans
if has("gui_kde")
set guifont=Bistream\ Vera\Sans/12/-1/5/50/0/0/0/0/0
endif
"-----------------------------------------------------
" se o sistema é um unix setar o terminal para bash
if has("unix")
let &shell="bash"
set clipboard=autoselect
" Let's be friendly :)
autocmd VimEnter * echo "Seja bem vindo ao vim. Seu sistema é Linux!"
else
autocmd VimEnter * echo "Seja bem vindo ao vim. Seu sistema é Windows!"
endif
"-----------------------------------------------------
" O trecho abaixo formata a barra de status com algumas opções interessantes!
" mostra o código ascii do caractere sob o cursor e outras coisas mais
set statusline=%F%m%r%h%w\ [FORMATO=%{&ff}]\ [TIPO=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POSIÇÃO=%04l,%04v][%p%%]\ [TAMANHO=%L]
set laststatus=2 " Sempre exibe a barra de status
"---------------- Mapeamentos ----------------------------
" make search results appear in the middle of the screen
" faz os resultados da busca aparecerem no meio da tela
nmap n nzz
nmap N Nzz
nmap * *zz
nmap # #zz
nmap g* g*zz
nmap g# g#zz
" --------------------------------------
" Seta fechamento automático para parêntese
" Set automatic expansion of parenthesis/brackets
inoremap ( ()<esc>:call BC_AddChar(")")<cr>i
inoremap { {}<esc>:call BC_AddChar("}")<cr>i
inoremap [ []<esc>:call BC_AddChar("]")<cr>i
" inoremap " ""<esc>:call BC_AddChar("\"")<cr>i
" mapeia CTRL+j para pular fora de parênteses colchetes etc...
inoremap <C-j> <esc>:call search(BC_GetChar(), "W")<cr>a
" Function for the above
function! BC_AddChar(schar)
if exists("b:robstack")
let b:robstack = b:robstack . a:schar
else
let b:robstack = a:schar
endif
endfunction
function! BC_GetChar()
let l:char = b:robstack[strlen(b:robstack)-1]
let b:robstack = strpart(b:robstack, 0, strlen(b:robstack)-1)
return l:char
endfunction
" --------------------------------------
" inserir linhas e continuar em modo normal
map ,o o<ESC>:echo<CR>
map ,O O<ESC>:echo<CR>
" windows-style key mappings
" estilo de atalhos do windows
" copy - copiar
vmap <C-C> y
" paste - colar
nmap <C-V> p
imap <C-V> <C-O>p
" cut - cortar
vmap <C-X> x
" undo - desfazer
noremap <C-Z> u
inoremap <C-Z> <C-O>u
" select all - selecionar tudo
map <C-a> <esc>ggvG
"-----------------------------------------------------
" o mapeamento abaixo coloca e retira a numeração
" o sistema alterna a numeração para ativa ou desativada
map <F11> <esc>:set nu!<cr>
map <S-F12> <esc>:dig<cr> " mostra os digrafos do tipo Word®
" mapeamento para salvar com CTRL+s
map <C-S> :w<CR>
imap <C-S> <C-O><C-S>
cmap <C-S> <C-C><C-S>
" salva com F9 (observe que é para no modo insert tem que dar <esc>)
map <F9> <esc>:w<cr>
"Word completion
"Complementação de palavras
set dictionary+=/usr/dict/words
set complete=.,w,k
set infercase
" make all windows the same size when adding/removing windows
set noequalalways
" Affiche la date au format RFC822 - ftplugin/debchangelog. Nico
function! Date822()
let savelang = v:lc_time
execute "language time C"
let dateandtime = strftime("%a, %d %b %Y %X %z")
execute "language time " . savelang
return dateandtime
endfunction
iab debdate <C-R>=Date822()<CR>
" Mapeamento para apagar com Backspace
map <BS> X
"-----------------------------------------------------
" oculta o destaque das buscas, e exibe de novo com shift+F11
" tira as cores das ocorrências de busca e recoloca (booleano)
nno <S-F11> :set hls!<bar>set hls?<CR>
" seta: numeração, indentação expansão de tab para espaços
" mostra fechamento de parêntese, mostra régua, modo em que
" está etc.
set nu ai et sm js
set showcmd showmode
set ruler
set backup
set backupdir=~/tmp
syntax enable
highlight PALAVRAS ctermbg=red
syntax keyword PALAVRAS linux Nota nota
"-----------------------------------------------------
" Destaca espaços e tabs redundantes
" caso queira usar descomente as ultimas linha e reinicie o
" vim ou pressione ,u caso etnha a função de recarregar (veja linha17)
" Highlight redundant whitespace and tabs.
highlight RedundantWhitespace ctermbg=red guibg=red
match RedundantWhitespace /\s\+$\| \+\ze\t/
" for txt, autoformat and wrap text at 70 chars.
autocmd BufNewFile,BufRead *.txt set wrapmargin=70 textwidth=70
" Habilita a detecção do tipo de arquivo
" Enable file type detection
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
"-----------------------------------------------------
" dá permissão para arquivos dos tipos descritos abaixo
" Automatically give executable permissions if filename ends in .sh, .pl or .cgi
au BufWritePost *.sh,*.pl,*.cgi :!chmod a+x <afile>
"-----------------------------------------------------
" Automatically give executable permission to scripts starting
" with #!/usr/bin/perl and #!/bin/sh
au BufWritePost * if getline(1) =~ "^#!/bin/[a-z]*sh" ||
\ getline(1) =~ "^#!/usr/bin/perl" | silent execute "!chmod a+x <afile>" | endif
"----------------- Abreviações --------------------
" abreviatura para o meu nome
ab slas Sérgio Luiz Araújo Silva
"coloca a data tipo Ter 26/Out/2004 hs 10:53 na linha atual
iab ,d <C-R>=strftime("%a %d/%b/%Y hs %H:%M")<CR>
iab ,m voyeg3r@gmail.com
" abreviações para correção ortográfica
iab tambem também
iab teh the
" a função (strftime) é predefinida pelo sistema
iab YDATE <C-R>=strftime("%a %d/%b/%Y hs %H:%M")<CR>
iab HDATE <C-R>=strftime("%a %d/%b/%Y hs %H:%M")<CR>
" Example: 1998-11-05 19:20:43 MST
" Estas linhas sao para não dar erro
" na hora de salvar arquivos
cab W w
cab Wq wq
cab wQ wq
cab WQ wq
cab Q q
" ===== DATA AUTOMÁTICA ==================
" insira na em seus arquivos = "ultima modificação:"
" em qualquer das três primeiras linhas
fun! SetDate()
mark z
if getline(1) =~ ".*ultima modificação:" ||
\ getline(2) =~ ".*ultima modificação:" ||
\ getline(3) =~ ".*ultima modificação:"
exec "1,5s/\s*ultima modificação: .*$/ultima modificação: " . strftime("%c") . "/"
endif
exec "'z"
endfun
" abaixo a chamada a função de data que é chamada toda vez que você
" salva um arquivo preexistente
fun! SetaData()
mark z
if getline(1) =~ ".*ultima alteração:" ||
\ getline(2) =~ ".*ultima alteração:" ||
\ getline(3) =~ ".*ultima alteração:"
exec "1,5s/\s*ultima alteração: .*$/ultima alteração: " . strftime("%c") . "/"
endif
exec "'z"
endfun
" coloquei duas opções (alteração e modificação), assim
" não tem perigo de você esquecer e o sistema
" não atualizar a data do salvamento, outra melhoria na função
" é que agora é válida para qualquer tipo de arquivo. se usar
" num html por exemplo insira um começo de comentário na linha
" da data e feche o comentário na próxima linha
" abaixo a chamada a função de data que é chamada toda vez que você
" salva um arquivo preexistente
au BufWritePre * call SetDate()
au BufWritePre * call SetaData()
"==== Fim da Data Automática ===============
" === Cria um registro de alterações de arquivo ========
" ChangeLog entry convenience
" Função para inserir um status do arquivo
" cirado: data de criação, alteração, autor etc
fun! InsertChangeLog()
normal(1G)
call append(0, "Arquivo")
call append(1, "Criado: " . strftime("%a %d/%b/%Y hs %H:%M"))
call append(2, "ultima modificação: " . strftime("%a %d/%b/%Y hs %H:%M"))
call append(3, "Autor: Sérgio Luiz Araújo Silva")
normal($)
endfun
map ,cl :call InsertChangeLog()<cr>A
" Cria um cabeçalho para scripts bash
fun! InsertHeadBash()
normal(1G)
call append(0, "#!bin/bash")
call append(1, "# Criado em:" . strftime("%a %d/%b/%Y hs %H:%M"))
call append(2, "# ultima modificação:" . strftime("%a %d/%b/%Y hs %H:%M"))
call append(3, "# Departamento Estadual de Trânsito - DETRAN/CE")
call append(3, "# Propósito do script")
normal($)
endfun
map ,sh :call InsertHeadBash()<cr>A
" Remove Ctrl+M do final de linhas do DOS
" get rid of
if has("user_commands")
" remove ^M from the file
com! RemoveCtrlM :%s/^M/\r/g
" change to directory of current file
com! CD cd %:p:h
endif
"-----------------------------------------------------
" HTML: Funcoes particulares para editar arquivos HTML
" Cria um esqueleto de arquivo HTML ao abrir um arquivo novo .html
" Should stop HTML Files auto-indenting
"-----------------------------------------------------
"augroup html
" au! <--> Remove all html autocommands
" au!
" au BufNewFile,BufRead *.html,*.shtml,*.htm set ft=html
" au BufNewFile,BufRead,BufEnter *.html,*.shtml,*.htm so ~/docs/vim/.vimrc-html
" au BufNewFile *.html 0r ~/docs/vim/skel.html
" au BufNewFile *.html*.shtml,*.htm /body/+
" au BufNewFile,BufRead *.html,*.shtml,*.htm set noautoindent
"augroup end
"-----------------------------------------------------
"-----------------------------------------------------
" Procure usar a função "InsertHeadBash()" com o mesmo propósito
" das linhas abaixo. A função citada insere um cabeçalho pronto
" com "change log".
" autocomandos para scripts
"augroup sh
" au!
" au BufNewFile *.sh 0r ~/docs/vim/skel.sh
" au BufNewFile,BufRead *.sh set ts=4
"augroup end
"-----------------------------------------------------
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
"
" Ao editar um arquivo será aberto no ultimo ponto em
" que foi editado
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
"
" insere número de linhas com ,n
map ,n :%s/^/\=line('.') . ' ' <cr>
Nenhum comentário foi encontrado.
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Atualizando o Fedora 42 para 43
Como saber se o seu e-mail já teve a senha vazada?
Como descobrir se a sua senha já foi vazada na internet?
Secure boot, artigo interessante, nada técnico. (1)
Preciso recuperar videos *.mp4 corrompidos (1)
\Boot sem espaço em disco (Fedora KDE Plasma 42) (6)









