set mouse=a
"Linha no cursors
set cursorline
"highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
hi CursorLine cterm=bold ctermbg=darkred ctermfg=white guibg=darkred guifg=white
hi CursorColumn cterm=bold ctermbg=darkred ctermfg=white guibg=darkred guifg=white
"Mostra numeros das linhas do lado esquerdo
set nu
"Mostra dados na barra de status - Ex Nome do arquivo, linha e coluna
set statusline=%F%m%r%h%w\ -\ %{&ff}\ -\ {%Y}\ \ [Linha:\ %l,\ Coluna:\ %v][%p%%]\ %=%{strftime(\"%d/%m/%y\ -\ %H:%M\")}
set laststatus=2
"set statusline=%F " Path to the file
"set statusline+=%= " Switch to the right side
"set statusline+=%l " Current line
"set statusline+=/ " Separator
"set statusline+=%L " Total lines
"Mapea dados para autocomplete
source ~/.vim/plugin/cscope_maps.vim
set omnifunc=syntaxcomplete#Complete
set tags+=~/.vim/systags
"Liga identacao automatica de codigo
filetype plugin on
filetype plugin indent on
set tabstop=4 " The width of a TAB is set to 4.
set shiftwidth=4 " Indents will have a width of 4.
set softtabstop=4 " Sets the number of columns for a TAB.
set expandtab " Expand TABs to spaces.
"Alterar tamanho das janelas
nmap <A-S-Up> :wincmd +<CR>
nmap <A-S-Down> :wincmd -<CR>
nmap <A-S-Left> :wincmd <<CR>
nmap <A-S-Right> :wincmd ><CR>
"Mover entre as janelas
nmap <A-Up> :wincmd k<CR>
nmap <A-Down> :wincmd j<CR>
nmap <A-Left> :wincmd h<CR>
nmap <A-Right> :wincmd l<CR>
nmap <C-N><C-N> :set invnumber<CR><Esc>
nmap <F7> :set invnumber <Bar>
\if exists("g:syntax_on") <Bar>
\ syntax off <Bar>
\ else <Bar>
\ syntax on <Bar>
\ endif <CR>
set lcs=tab:>-,trail:.,eol:$
nmap <F8> :set list!<CR>
"Procurar pelo texto selecionado
noremap // y/<C-R>"<CR>
"Mover texto selecionado
nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
inoremap <C-j> <Esc>:m .+1<CR>==gi
inoremap <C-k> <Esc>:m .-2<CR>==gi
vnoremap <C-j> :m '>+1<CR>gv=gv
vnoremap <C-k> :m '<-2<CR>gv=gv
function! s:DiffWithGITCheckedOut()
let filetype=&ft
diffthis
vnew | exe "%!git diff " . expand("#:p:h") . "| patch -p 1 -Rs -o /dev/stdout"
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
diffthis
endfunction
com! DiffGIT call s:DiffWithGITCheckedOut()
au BufNewFile,BufRead *.cpp,*.c,*.h,*.java syn region myCComment start="/\*" end="\*/" fold keepend transparent
"#tab navigation like firefox
nnoremap <C-t> :tabnew<CR>
inoremap <C-t> <Esc>:tabnew<CR>
nnoremap <C-w> :tabclose<CR>
nmap <A-1> 1gt
nmap <A-2> 2gt
nmap <A-3> 3gt
nmap <A-4> 4gt
nmap <A-5> 5gt
nmap <A-6> 6gt
nmap <A-7> 7gt
nmap <A-8> 8gt
nmap <A-9> 9gt
nmap <A-0> 10gt
"abrir arquivos em nova tab
"autocmd VimEnter * tab all
"autocmd BufAdd * exe 'tablast | tabe "' . expand( "<afile") .'"' ]
c$ - change (replace) to the end of line
r - replace character at cursors by another
s - delete character at cursor and subsitute text
S - delete line at cursor and substitute text (same as cc)
xp - transpose two letters (delete and paste, technically)
u - undo
Ctrl+r - redo
. - repeat last command
Marking text (visual mode)
v - start visual mode, mark lines, then do command (such as y-yank)
V - start Linewise visual mode
o - move to other end of marked area
Ctrl+v - start visual block mode
O - move to Other corner of block
aw - mark a word
ab - a () block (with braces)
aB - a {} block (with brackets)
ib - inner () block
iB - inner {} block
Esc - exit visual mode
Visual commands
> - shift right
< - shift left
y - yank (copy) marked text
d - delete marked text
~ - switch case
Cut and Paste
yy - yank (copy) a line
2yy - yank 2 lines
yw - yank word
y$ - yank to end of line
p - put (paste) the clipboard after cursor
P - put (paste) before cursor
dd - delete (cut) a line
dw - delete (cut) the current word
x - delete (cut) current character
Exiting
:w - write (save) the file, but don't exit
:wq or :x or shitf zz - write (save) and quit
:q - quit (fails if anything has changed)
:q! - quit and throw away changes
Search/Replace
/pattern - search for pattern
?pattern - search backward for pattern
n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new throughout file
:%s/old/new/gc - replace all old with new throughout file with confirmations
search or replace beginign with patern
/^patern
:%s/^patern/new/g
search or replace ending with patern
/patern$
:%s/pattern$/new/g
Sort and remove duplicates
:sort
:sort u
Registers in Vim let you run actions or commands on text stored within them. To access a register, you type "a before a command, where a is the name of a register. If you want to copy the current line into register k, you can type
"kyy
Or you can append to a register by using a capital letter
"Kyy
You can then move through the document and paste it elsewhere using
"kp
To paste from system clipboard on Linux
"+p
To paste from system clipboard on Windows (or from "mouse highlight" clipboard on Linux)
"*p
To access all currently defined registers type
:reg
Copy to clipboard
"+y
ora
"*y
in search mode
Ctrl + r, Ctrl +w - paste current word under cursor
Ctrl + r, " - paste current yanked text
Working with multiple files
:e filename - Edit a file in a new buffer
:bnext (or :bn) - go to next buffer
:bprev (of :bp) - go to previous buffer
:bd - delete a buffer (close a file)
:sp filename - Open a file in a new buffer and split window
ctrl+ws - Split windows
ctrl+ww - switch between windows
ctrl+wq - Quit a window
ctrl+wv - Split windows vertically
Retirado do site www.worldtimzone.com/res/vi.html
outra boa referencia
www.fprintf.net/vimCheatSheet.html
Ctrl+w _ - Minimize vertical split
Ctrl+w | - Minimize horizontal split
Ctrl+w = - Resize all split to same size
Ctrl+w T - Move all split to a different tab
Ctrl+w o - Close all other split but not the current
sudo apt install vim-gtk - Enable copy to clipboard with ("+y")
g Ctrl+a - increment numbers in sequence Select with Ctr+v
:%s/pattern//gn - Number of matchs of a pattern
:%s/pattern//n - Number of lines that contains matchs of a pattern