Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " nvim file: ~/.config/nvim/init.vim
- " Last Change: set 04 2019 08:24
- " vim: ff=unix ai et ts=4
- " Author: Sérgio Luiz Araújo Silva
- "
- " ( O O )
- " +-----------oOO--(_)--OOo--------------+
- " | |
- " | °v° Sergio Luiz Araujo Silva |
- " | /(_)\ Linux User #423493 |
- " | ^ ^ voyeg3r ✉ gmail.com |
- " +--------------------------------------+
- "
- " _ _ _
- " | \ | | ___ _____ _(_)_ __ ___
- " | \| |/ _ \/ _ \ \ / / | '_ ` _ \
- " | |\ | __/ (_) \ V /| | | | | | |
- " |_| \_|\___|\___/ \_/ |_|_| |_| |_|
- "
- "
- " TODO: fix some indentation issuies
- "
- " As you type a substitution the results will immediately be
- " visible in the edit window. This feature is best highlighted
- " in this video: http://www.youtube.com/watch?v=sA3z6gsqOuw
- if has("nvim")
- set inccommand=nosplit
- tnoremap <Esc> <c-\><c-n>
- if executable('nvr')
- let $VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
- endif
- endif
- " Required:
- let mapleader = ','
- set shada=!,'500,<50,s10,h
- set nospell
- set nomodeline
- "set spelllang=en,pt
- "set complete+=kspell
- "set sps=8 " Quantidade de sugestões do spell
- " i_Ctrl-g_u allows us to have a better undo
- inoremap <C-s> <c-g>u<Esc>[s1z=gi<c-g>u
- " Toggles paste to insert clipboard content
- "inoremap <S-Insert> <ESC>:setl paste<CR>gi<C-R>+<ESC>:setl nopaste<CR>gi
- inoremap <S-Insert> <ESC>"+p`]a
- " Auto install vim plug
- if empty(glob('~/.dotfiles/nvim/autoload/plug.vim'))
- if !executable("curl")
- echoerr "You have to install curl or first install vim-plug yourself!"
- execute "q!"
- endif
- silent !curl -fLo ~/.dotfiles/nvim/autoload/plug.vim --create-dirs
- \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
- endif
- call plug#begin(expand(glob('~/.config/nvim/plugged')))
- "Plug 'lervag/vimtex'
- "Plug 'voldikss/vim-translate-me'
- "Plug 'mhinz/vim-startify'
- "Plug 'henrik/vim-indexed-search'
- "Plug 'coderifous/textobj-word-column.vim'
- "Plug 'mhinz/neovim-remote'
- Plug 'junegunn/limelight.vim'
- Plug 'bilalq/lite-dfm'
- Plug 'PeterRincker/vim-searchlight'
- Plug 'Yggdroot/indentLine'
- Plug 'ap/vim-buftabline'
- "Plug 'voyeg3r/vim-neatstatus'
- Plug 'nelstrom/vim-visual-star-search'
- Plug 'w0rp/ale' , { 'on': ['ALEToggle'] }
- Plug 'rking/ag.vim', { 'on': ['Ag'] }
- "Plug 'wellle/targets.vim'
- Plug 'mattn/emmet-vim' , { 'for': ['html', 'htmldjango', 'javascript.jsx', 'css'] }
- Plug 'tpope/vim-abolish', { 'on': [] } "Advanced regex Substitution
- "Plug 'tpope/vim-surround', { 'on': [] }
- Plug 'tpope/vim-surround',
- \ { 'on': ['<Plug>Dsurround', '<Plug>Csurround', '<Plug>CSurround',
- \ '<Plug>Ysurround', '<Plug>YSurround', '<Plug>Yssurround',
- \ '<Plug>YSsurround', '<Plug>VSurround', '<Plug>VgSurround'] }
- "Plug 'tpope/vim-unimpaired'
- "Plug 'godlygeek/tabular', { 'on': ['Tabularize'] }
- "Plug 'jezcope/vim-align', { 'on' : 'Align' }
- Plug 'tommcdo/vim-exchange'
- "Plug 'nelstrom/vim-visual-star-search'
- "Plug 'nelstrom/vim-markdown-folding'
- "Plug 'haya14busa/incsearch.vim'
- Plug 'timakro/vim-searchant'
- "Plug 'inside/vim-search-pulse'
- Plug 'machakann/vim-highlightedyank'
- Plug 'vim-scripts/VisIncr', { 'on': [] }
- Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
- Plug 'zchee/deoplete-jedi'
- Plug 'kshenoy/vim-signature', { 'on': [] }
- Plug 'vimwiki/vimwiki', { 'for': ['markdown', 'vimwiki'] }
- "Plug 'vimwiki/vimwiki', { 'for': [] }
- Plug 'sjl/gundo.vim', { 'on': ['GundoToggle'] }
- "Plug 'chrisbra/NrrwRgn', { 'on': ['NR', 'NrrwRgn'] }
- Plug 'chrisbra/NrrwRgn'
- Plug 'tpope/vim-speeddating'
- Plug 'jiangmiao/auto-pairs'
- "Plug 'rstacruz/vim-closer'
- Plug 'tpope/vim-commentary'
- "Plug 'tpope/vim-fugitive'
- "Plug 'tommcdo/vim-lion', { 'on': [] }
- Plug 'vim-airline/vim-airline'
- Plug 'vim-airline/vim-airline-themes'
- "Plug 'airblade/vim-gitgutter'
- Plug 'vim-scripts/grep.vim', { 'on': [] }
- Plug 'vim-scripts/CSApprox', { 'on': [] }
- "Plug 'majutsushi/tagbar'
- "Plug 'scrooloose/syntastic'
- "Plug 'Yggdroot/indentLine'
- if isdirectory('/usr/local/opt/fzf')
- Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
- else
- Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
- Plug 'junegunn/fzf.vim'
- "Plug 'junegunn/fzf', { 'on': ['FZF', 'History', 'Files' ], 'dir': '~/.fzf', 'do': './install --bin' }
- "Plug 'junegunn/fzf.vim', { 'on': ['FZF', 'History', 'Files' ] }
- endif
- Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
- "Plug 'SirVer/ultisnips', {'on': '#InsertEnter' } | Plug 'honza/vim-snippets', {'on': [] }
- "Plug 'SirVer/ultisnips', { 'on': [] }
- Plug 'SirVer/ultisnips'
- Plug 'honza/vim-snippets'
- " Color
- Plug 'sainnhe/vim-color-forest-night'
- Plug 'axvr/photon.vim'
- Plug 'morhetz/gruvbox'
- Plug 'reedes/vim-colors-pencil'
- Plug 'trevordmiller/nova-vim'
- Plug 'crusoexia/vim-monokai', { 'on': [] }
- Plug 'ayu-theme/ayu-vim'
- Plug 'drewtempelmeyer/palenight.vim'
- Plug 'endel/vim-github-colorscheme'
- Plug 'NLKNguyen/papercolor-theme'
- Plug 'icymind/NeoSolarized'
- Plug 'lifepillar/vim-solarized8'
- Plug 'tomasr/molokai'
- Plug 'nanotech/jellybeans.vim'
- Plug 'mhartington/oceanic-next'
- Plug 'sainnhe/vim-color-vanilla-cake'
- " statusline
- "Plug 'vim-scripts/Obvious-Mode'
- " Color picker
- Plug 'lilydjwg/colorizer', { 'on': [] }
- call plug#end()
- " Recover from accidental Ctrl-U
- " http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
- " use Ctrl-r . to get your text back
- "inoremap <c-u> <c-g>u<c-u>
- "inoremap <c-w> <c-g>u<c-w>
- "inoremap <c-y> <c-o>u
- inoremap <silent> <c-w> <c-\><c-o>db
- inoremap <silent> <c-u> <c-\><c-o>d0
- "inoremap <silent> <C-S-Y> <C-R>"
- " https://github.com/ryangrose/easy-pandoc-templates
- " https://vi.stackexchange.com/questions/17549/
- if !exists('*PandocMappings')
- function! PandocMappings()
- " NOTE: <F16> equals to Shift-F4
- noremap <F4> :! pandoc '%:p' -o /tmp/'%:p:t'.html --template=easy_template.html --toc && firefox /tmp/'%:p:t'.html &<CR><CR>
- noremap <F16> :! pandoc '%:p' -o /tmp/'%:p:t'.pdf --pdf-engine=pdflatex --toc && evince /tmp/'%:p:t'.pdf &<CR><CR>
- endfun
- endif
- augroup every
- autocmd!
- au InsertEnter * set norelativenumber
- au InsertLeave * set relativenumber
- augroup END
- " inserts a line below without commenting if file is modifiable &ma?
- " nnoremap <silent> <cr> :set paste<cr>o<esc>:set nopaste<cr>
- nnoremap <expr> <Enter> &ma?":set paste\<cr>\<esc>o\<esc>:set nopaste\<cr>":"\<cr>"
- " show registers
- nnoremap <Leader>r :registers<CR>
- " save with <F9> if file was modified
- nnoremap <F9> :update<cr>
- inoremap <F9> <c-o>:update<cr>
- vnoremap <F9> :<c-u>update<cr><bar>gv
- nnoremap Q :normal .<CR>
- nnoremap '. `.
- nnoremap - $
- nnoremap n nzzzv
- nnoremap N Nzzzv
- nnoremap } }zzzv
- nnoremap { {zzzv
- "nnoremap <C-M-l> :set cursorline!<CR>
- nnoremap <C-M-l> :<c-u>setlocal list! list?<CR>
- " spelling
- " nnoremap <C-s> [s1z=<C-o>
- " nnoremap <Leader>s ]s1z=<C-o>
- " nnoremap <Leader>g ]szg<C-o>
- " See more about <C-x>s
- " Below mappings allows you to toggle spelling
- " nnoremap <F7> :setlocal spell!<CR>
- " inoremap <F7> <C-o>:setlocal spell!<CR>
- " allows me to use a smarter cgn
- "nnoremap * :keepjumps normal *``<cr>
- nnoremap c* *<c-o>cgn
- nnoremap c# #<C-o>cgn
- " avoid clipboard hacking security issue
- " http://thejh.net/misc/website-terminal-copy-paste
- inoremap <C-R>+ <C-R><C-R>+
- " Auto reindent pasted text (from hacking vim p.138)
- " nnoremap p p=`]
- " cool
- "command! -nargs=0 CopyFile :%y+<CR>
- command! CloneBuffer new | 0put =getbufline('#',1,'$')
- command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor
- function! s:Registers( arguments )
- redir => l:registersOutput
- silent! execute 'registers' a:arguments
- redir END
- for l:line in split(l:registersOutput, "\n")
- if l:line !~# '^"\S\s*$'
- echo l:line
- endif
- endfor
- endfunction
- command! -nargs=? Registers call <SID>Registers(<q-args>)
- " Spell mistakes color
- "highlight SpellBad cterm=bold ctermfg=white ctermbg=red
- "highlight SpellCap cterm=bold ctermfg=red ctermbg=white
- if has("multi_byte")
- if &termencoding == ""
- let &termencoding = &encoding
- endif
- set encoding=utf-8
- setglobal fileencoding=utf-8
- set fileencodings=ucs-bom,utf-8,latin1
- endif
- set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
- \,a:blinkwait300-blinkoff200-blinkon150-Cursor/lCursor
- \,sm:block-blinkwait175-blinkoff150-blinkon175
- set laststatus=2
- set guicursor+=n:blinkon1 " not blinking cursor in normal mode
- "set guicursor+=i:blinkon1 " cursor blinkin in insert mode
- "
- "set dictionary+=~/.dotfiles/nvim/words.txt " C-x C-k C-n
- "set nrformats+=alpha " Increases/Decreases numbers with Ctrl-a/Ctrl-x correctrly
- set lazyredraw " speed up macros
- set mouse=a " enable mouse click
- set path+=.,**
- set scrolloff=1 " keep 1 line visible when scrolling
- set sidescrolloff=5
- set ai " set auto-indenting on for programming (nvim default)
- set hidden " Switch buffers without saving them
- "set autowrite
- "set autowriteall
- set display+=lastline
- "set nobackup " do not keep a backup file
- set number " show line numbers
- set showmatch " jump to matches when entering regexp
- set ignorecase " ignore case when searching
- set infercase " case inferred by default
- set smartcase " no ignorecase if Uppercase char present
- set visualbell " turn off error beep/flash
- set novisualbell " turn off visual bell
- set title " shows filename at the top
- set formatoptions=tcqj
- set expandtab " Converts tab into spaces
- set tabstop=4 " Number of spaces that a <Tab> in the file counts for
- set softtabstop=4 " number of spaces in tab when editing
- set shiftwidth=4 " indented with the reindent operations with >> and <<
- set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
- set shiftround " when at 3 spaces, and I hit > go to 4, not 5
- "set t_RV=
- let &fillchars = "vert:\u2502,diff: "
- let &listchars = "tab:\u25b8 ,extends:\u00bb,precedes:\u00ab,space:\u00b7,nbsp:\u2334,eol:\u21b2"
- let &showbreak = "\u21aa "
- set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__,*.swp,*.bak
- set wildignore+=*.so,*.pdf,*.swp,*.zip,*.pyc,*.db,*.sqlite,*.jpg,*.png,*.gif
- set wildmenu
- "set wildmode=list:longest,full
- "set wildmode=longest:full,list:full
- set wildmode=longest,list
- " making <tab> work properly on vim command line
- "set whichwrap +=<,>
- set nopaste
- set pastetoggle=<F8>
- set linebreak " Keep whole words during wrapping
- set noshowmode
- set noerrorbells visualbell
- "You can get case-insensitivity for the filename completion in Vim with the following.
- set wildignorecase
- " jump to next/previous comment
- " https://vimtricks.com/viml/2017/05/26/jump-to-next-commented-line/
- nnoremap ]c :call search('^\s*'.substitute(escape(&cms, '\.*[]^$'), '%s', '.*', '').'\s*$')<CR>
- nnoremap [c :call search('^\s*'.substitute(escape(&cms, '\.*[]^$'), '%s', '.*', '').'\s*$', 'b')<CR>
- " nvim default undodir: ~/.local/share/nvim/undo (|xdg|), auto-created
- set undofile " Maintain undo history between sessions
- let g:indentLine_char = '▏'
- " Enable airline symbols
- let g:airline_powerline_fonts = 1
- let g:airline_highlighting_cache = 1
- " if is there more than one buffer it will appear on buftabline
- let g:buftabline_show = 1
- let g:buftabline_numbers = 1
- " function! RunningInsideGit()
- " let result = system('env | grep ^GIT_')
- " if result == ""
- " return 0
- " else
- " return 1
- " endif
- " endfunction
- " many plugins are disabled by default and called by
- " this function for example: call LoadPluginFunction('vim-lion')
- " and the command LoadPlugin plugin-name (whithout quotes)
- " list unloaded plugins
- " \v^Plug[^/]*\/\zs([^']*)\ze',\s+\{\s+'on':\s+[]
- if !exists('*LoadPluginFunction')
- fun! LoadPluginFunction(pluginname)
- let l:curpos = getcurpos()
- execute plug#load(a:pluginname)
- call cursor(l:curpos[1], l:curpos[2])
- return ''
- endfun
- endif
- command! -nargs=1 LoadPlugin :call LoadPluginFunction(<q-args>)
- " augroup help_start
- " autocmd!
- " autocmd FileType help,markdown call SetHelpFiletype()
- " augroup end
- "
- " if !exists('*SetHelpFiletype')
- " fun! SetHelpFiletype()
- " augroup help_insert
- " autocmd!
- " autocmd InsertEnter <buffer> setlocal conceallevel=0 | highlight clear Ignore
- " autocmd InsertLeave <buffer> setlocal conceallevel=2
- " augroup end
- " endfun
- " endif
- " Toggle *conceallevel*
- nnoremap <Leader>c :let &l:cole=(&cole == 3) ? 0 : 3 <bar> echo 'conceallevel ' . &cole <CR>
- syntax match arrow "->" conceal cchar=→
- syntax match rcomp ">>" conceal cchar=»
- syntax match lcom "<<" conceal cchar=«
- set concealcursor=n
- set conceallevel=3
- " lazy load for ultisnips
- " https://medium.com/@saaguero/improving-performance-in-vim-9b33598c8eaf
- inoremap <silent> <C-j> <C-r>=LoadUltiSnips()<CR>
- nnoremap <silent> <C-M-u> :call LoadUltiSnips()<CR>
- " This function only runs when UltiSnips is not loaded
- if !exists('*LoadUltiSnips')
- function! LoadUltiSnips()
- call Preserve(":execute plug#load('vim-snippets')")
- call Preserve(":execute plug#load('ultisnips')")
- call UltiSnips#ExpandSnippet()
- echo "Ultisnips loaded!"
- return ""
- endfunction
- endif
- nnoremap <Leader>z :LiteDFMToggle<CR>
- nnoremap <F2> :NERDTreeToggle<cr>
- " hide old “Press ? for help”
- let NERDTreeMinimalUI = 1
- let NERDTreeDirArrows = 1
- " close nerdthree when it opens a file
- let NERDTreeQuitOnOpen = 1
- " Automatically delete the buffer of the file you just deleted with NerdTree:
- let NERDTreeAutoDeleteBuffer = 1
- inoremap <expr> <TAB> pumvisible() ? "\<C-y>" : "\<TAB>"
- let g:deoplete#sources = {}
- let g:deoplete#sources._=['omni', 'buffer', 'member', 'tag', 'ultisnips', 'file']
- let g:deoplete#enable_at_startup = 1
- let g:deoplete#enable_refresh_always = 1
- let g:deoplete#enable_ignore_case = 1
- let g:deoplete#enable_smart_case = 1
- let g:deoplete#enable_camel_case = 1
- let g:deoplete#file#enable_buffer_path = 1
- let g:deoplete#sources#jedi#python_path = '/usr/bin/python3'
- " <CR>: close popup and save indent.
- " Now each Enter creates a undo point ":h i_Ctrl-g_u"
- " inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
- "if !exists('*s:my_cr_function')
- " function! s:my_cr_function()
- " "return deoplete#mappings#smart_close_popup() . "\<C-g>u\<CR>"
- " return deoplete#mappings#smart_close_popup() . "\<CR>"
- " endfunction
- "endif
- " Trying to fix deoplete
- "set runtimepath+=~/path/to/deoplete.nvim/
- set runtimepath+=~/.config/nvim/plugged/deoplete.nvim/
- let g:deoplete#enable_at_startup = 1
- call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy'])
- set omnifunc=syntaxcomplete#Complete
- "set completeopt=longest,menuone,preview,noinsert
- set completeopt=menuone,longest,preview
- " copy until the end of line using
- nnoremap Y y$
- " Jump outside '"({
- if !exists('g:AutoPairsShortcutJump')
- let g:AutoPairsShortcutJump = '<A-l>'
- endif
- if exists('$SHELL')
- set shell=$SHELL
- else
- set shell=/bin/sh
- endif
- " Use whole "words" when opening URLs.
- " This avoids cutting off parameters (after '?') and anchors (after '#').
- " See http://vi.stackexchange.com/q/2801/1631
- let g:netrw_gx="<cWORD>"
- let g:netrw_liststyle = 3
- let g:netrw_browsex_viewer= "opera"
- " pencil is another great colorscheme
- "colo PaperColor
- "silent! colo gruvbox
- " gruvbox has a great light colorscheme, just press <Shift><F7>
- let colorscheme="PaperColor"
- if findfile("colors/" .colorscheme .".vim", &rtp) != ""
- execute "colorscheme " . colorscheme
- endif
- " https://stackoverflow.com/a/7589970/2571881
- " if strftime("%H") < 17
- " set background=light
- " else
- " set background=dark
- " endif
- " source: http://tilvim.com/2013/07/31/swapping-bg.html <F19> = Shif-F7
- " nmap <F19> :let &background = ( &background == "dark"? "light" : "dark" )<CR>
- " removed ifs because it must be used with neovim
- let $NVIM_TUI_ENABLE_TRUE_COLOR=1
- set termguicolors
- " When double click a word vim will hightlight all other ocurences
- " see CountWordFunction()
- " [I shows lines with word under the cursor
- nnoremap <silent> <2-LeftMouse> :let @/='\V\<'.escape(expand('<cword>'), '\').'\>'<cr>:set hls<cr>:CountWord<cr>
- nnoremap <Leader>* :let @/='\V\<'.escape(expand('<cword>'), '\').'\>'<cr>:set hls<cr>:CountWord<cr>
- nnoremap <F5> :GundoToggle<CR>
- let g:gundo_prefer_python3 = 1
- nnoremap <Left> :vertical resize +2<CR>
- nnoremap <Right> :vertical resize -2<CR>
- "nnoremap <Up> :resize -2<CR>
- "nnoremap <Down> :resize +2<CR>
- set wildchar=<Tab> wildmenu wildmode=full
- set wildcharm=<C-Z>
- nnoremap <F10> :b <C-Z><S-TAB>
- " list buffers and jump to a chosen one
- nnoremap <Leader>b :ls<CR>:b<Space>
- " sometimes you need to know how many opened buffers you have
- " source: https://superuser.com/a/1221514/45032
- if !exists('*CountBuffers')
- fun! CountBuffers() abort
- "let l:total = len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
- let l:total = len(getbufinfo({'buflisted':1}))
- echom "you have " . l:total . " opened buffers!"
- endfun
- endif
- command! -nargs=0 Nbufs :call CountBuffers()
- if !exists('*CloseAllBuffersButCurrent')
- function! CloseAllBuffersButCurrent()
- let curr = bufnr("%")
- let last = bufnr("$")
- if curr > 1 | silent! execute "1,".(curr-1)."bd" | endif
- if curr < last | silent! execute (curr+1).",".last."bd" | endif
- echom "All other buffers unloaded!"
- endfunction
- endif
- command! -nargs=0 Bonly :call CloseAllBuffersButCurrent()
- command! -nargs=0 Bo :call CloseAllBuffersButCurrent()
- " close the buffer
- nnoremap <C-M-d> :bd!<CR>
- nnoremap <C-M-w> :bw!<CR>
- nnoremap <C-M-o> :Bonly<CR>
- " substitute word under cursor - This map is used for spell
- " nnoremap <Leader>s :call Preserve('%s/\<<C-r><C-w>\>//g\<left><left>')
- " Scroll split window
- nnoremap <C-M-k> <c-w>w<c-y><c-w>w
- nnoremap <C-M-j> <c-w>w<c-e><c-w>w
- " resise windows
- nnoremap <M-=> <C-w>+
- nnoremap <M--> <C-w>-
- filetype on " detect type of file
- "filetype plugin indent on " neovim default (don't bother with this)
- " My font is fira mono regular stled on gnome-shell
- " line text-objects
- " vnoremap <silent> al :<c-u>norm!0v$h<cr>
- vnoremap <silent> al :<c-u>norm!0v$<cr>
- vnoremap <silent> il :<c-u>norm!_vg_<cr>
- onoremap <silent> al :norm val<cr>
- onoremap <silent> il :norm vil<cr>
- " more text objects
- for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '%', '`' ]
- execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
- execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
- execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
- execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
- endfor
- " buffer text-object
- "xnoremap i% GoggV
- "omap i% :<C-u>normal vi%<CR>
- command! -nargs=0 Reindent :call Preserve('exec "normal! gg=G"')
- command! MakeTags !ctags -R .
- " create a scratch window - rascunho
- command! Scratch new | setlocal bt=nofile bh=wipe nobl noswapfile nu
- cnoreabbrev SC Scratch
- " Now this allows me to open a scratch buffer with various options, like I could
- " call :Sedit ft=javascript and that would open a scratch buffer with filetype
- " javascript (and hence show the right syntax highlighting).
- " https://dhruvasagar.com/2014/03/11/creating-custom-scratch-buffers-in-vim
- if !exists('*ScratchEdit')
- function! ScratchEdit(cmd, options)
- exe a:cmd tempname()
- setl buftype=nofile bufhidden=wipe nobuflisted
- if !empty(a:options) | exe 'setl' a:options | endif
- endfunction
- endif
- command! -bar -nargs=* Sedit call ScratchEdit('edit', <q-args>)
- command! -bar -nargs=* Ssplit call ScratchEdit('split', <q-args>)
- command! -bar -nargs=* Svsplit call ScratchEdit('vsplit', <q-args>)
- command! -bar -nargs=* Stabedit call ScratchEdit('tabe', <q-args>)
- " select last paste in visual mode
- " https://vim.fandom.com/wiki/Selecting_your_pasted_text
- " nnoremap gp `[v`]
- nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
- if !exists('*s:setupWrapping')
- function s:setupWrapping()
- set wrap
- set wm=2
- set textwidth=78
- set formatoptions+=t
- endfunction
- endif
- " join lines keeping cursor position
- nnoremap J :call Preserve(':join')<CR>
- nnoremap <Leader>J :call Preserve(':join!')<CR>
- "noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
- "noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
- " It adds motions like 25j and 30k to the jump list, so you can cycle
- " through them with control-o and control-i.
- " source: https://www.vi-improved.org/vim-tips/
- nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
- nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
- " to insert this result: --> :put =Randnum(1000)
- if !exists('*Randnumber')
- function! Randnumber(max) abort
- return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) % a:max
- endfunction
- endif
- if !exists('*CountWordFunction')
- fun! CountWordFunction()
- try
- let l:win_view = winsaveview()
- exec "%s/" . expand("<cword>") . "//gn"
- finally
- call winrestview(l:win_view)
- endtry
- endfun
- endif
- command! -nargs=0 CountWord :call CountWordFunction()
- cnoreabbrev cw CountWord
- nnoremap <F3> :CountWord<CR>
- " Reloads vimrc after saving but keep cursor position
- if !exists('*ReloadVimrcFunction')
- function! ReloadVimrcFunction()
- call Preserve(':source $MYVIMRC')
- hi Normal guibg=NONE ctermbg=NONE
- windo redraw
- echom "Reloaded init.vim"
- endfunction
- endif
- noremap <silent> <Leader>v :e $MYVIMRC<cr>
- command! -nargs=0 ReloadVimrc :call ReloadVimrcFunction()
- " Reference: https://stackoverflow.com/posts/30552423/revisions
- augroup vimrc_todo
- autocmd!
- autocmd BufEnter * syntax match MyTodo /\v<(FIXME|NOTE|OBS|TODO|OPTIMIZE)>:/ containedin=.*Comment.*
- autocmd BufEnter * silent! syntax clear cTodo
- autocmd BufEnter * silent! syntax clear vimTodo
- augroup END
- "highlight link MyTodo Todo
- highlight def link MyTodo Todo
- augroup Reload
- autocmd!
- autocmd BufWritePost init.vim call ReloadVimrcFunction()
- augroup END
- " The PC is fast enough, do syntax highlight syncing from start unless 200 lines
- augroup vimrc-sync-fromstart
- autocmd!
- "autocmd BufEnter * syntax sync maxlines=200
- autocmd BufWinEnter,Syntax * syn sync minlines=500 maxlines=500
- augroup END
- "" Remember cursor position
- augroup vimrc-remember-cursor-position
- autocmd!
- autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
- augroup END
- augroup lcd-folder
- au!
- autocmd BufEnter * silent! lcd %:p:h
- augroup END
- augroup sh
- au!
- au! BufWritePost *.sh,*.zsh :silent !chmod a+x <afile>
- augroup END
- " trying to fix fzf behavior with <esc>
- augroup fixFzf
- au!
- autocmd! FileType fzf tnoremap <buffer> <esc> <c-c>
- augroup END
- if !exists('*SetPythonOptions')
- function! SetPythonOptions()
- set keywordprg=pydoc
- filetype plugin indent on
- set smartindent et sts=4 sw=4 tw=80 fo=croq
- let python_highlight_builtins=1
- let python_highlight_all=1
- let python_highlight_exceptions=1
- let python_highlight_numbers=1
- let python_highlight_space_errors=1
- let g:_uspy=":python3"
- let g:ultisnipsusepythonversion = 3
- let g:loaded_python_provider = 0
- let g:loaded_python3_provider = 0
- "let g:python_host_skip_check=1
- "let g:python3_host_skip_check=1
- endfunction
- endif
- let g:python_host_prog = '/usr/bin/python'
- let g:python3_host_prog = '/usr/bin/python3'
- "" txt
- augroup vimrc-wrapping
- autocmd!
- autocmd BufRead,BufNewFile *.txt,*.md,*.tex call s:setupWrapping()
- augroup END
- "" make/cmake
- augroup vimrc-make-cmake
- autocmd!
- autocmd FileType make setlocal noexpandtab
- autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake
- augroup END
- "augroup markdown
- "" autocmd FileType markdown,vimwiki setlocal textwidth=78 formatprg=par\ -w78
- " autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*} setlocal ft=markdown
- "augroup END
- "augroup spellcheck_documentation
- " autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*,txt} setlocal spell
- " " Don't mark URL-like and acronyms things as spelling errors
- " syn match UrlNoSpell "\v(https?|ftp):[^[:space:]]*" contains=@NoSpell
- " syn match AcronymNoSpell '\v\u{2,}(\d+)?' contains=@NoSpell
- " syn match myExCapitalWords '+\<[A-Z]\w*\>+' contains=@NoSpell
- "augroup END
- " autoformat html files on opening or saving them
- " this function it called only if the filetype is html
- " and pandoc is present in the system
- "function! SetHtml()
- " if executable('pandoc')
- " let pandoc_pipeline = "pandoc --from=html --to=markdown"
- " let pandoc_pipeline .= " | pandoc --from=markdown --to=html"
- " let &l:formatprg=pandoc_pipeline
- " endif
- "endfunction
- "" Set working directory
- nnoremap <Leader>. :lcd %:p:h<CR>
- " Change in next bracket
- nnoremap cinb cib
- nnoremap cinB ciB
- "" fzf.vim
- let $FZF_DEFAULT_COMMAND = "find * -path '*/\.*' -prune -o -path 'node_modules/**' -prune -o -path 'target/**' -prune -o -path 'dist/**' -prune -o -type f -print -o -type l -print 2> /dev/null"
- " The Silver Searcher
- if executable('ag')
- let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -g ""'
- set grepprg=ag\ --nogroup\ --nocolor\ --ignore-case\ --column
- set grepformat=%f:%l:%c:%m,%f:%l:%m
- endif
- " nnoremap <silent> <Leader>b :Buffers<CR>
- nnoremap <silent> <Leader>h :History<cr>
- nnoremap <silent> <c-p> :FZF -m ~/.dotfiles<CR>
- " " hide fzf statusline
- " if has('nvim') || has('gui_running')
- " autocmd! FileType fzf
- " autocmd FileType fzf set laststatus=0 noshowmode noruler
- " autocmd BufLeave <buffer> set laststatus=2 showmode ruler
- " endif
- " Most recent used files
- command! FZFMru call fzf#run({
- \ 'source': v:oldfiles,
- \ 'sink': 'e',
- \ 'options': '-m -x +s',
- \ 'down': '40%'})
- nnoremap <leader>m :FZFMru<cr>
- " Files command with preview window
- command! -bang -nargs=? -complete=dir Files
- \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
- nnoremap <leader>f :Files<CR>
- " snippets
- let g:UltiSnipsExpandTrigger="<C-j>"
- let g:UltiSnipsJumpForwardTrigger="<C-j>"
- let g:UltiSnipsJumpBackwardTrigger="<C-k>"
- let g:UltiSnipsEditSplit="vertical"
- let g:UltiSnipsListSnippets="<C-Space>"
- " syntastic
- let g:syntastic_always_populate_loc_list=1
- let g:syntastic_error_symbol='✗'
- let g:syntastic_warning_symbol='⚠'
- let g:syntastic_style_error_symbol = '✗'
- let g:syntastic_style_warning_symbol = '⚠'
- let g:syntastic_auto_loc_list=1
- let g:syntastic_aggregate_errors = 1
- " Tagbar
- "nnoremap <silent> <F4> :TagbarToggle<CR>
- "let g:tagbar_autofocus = 1
- "" Vmap for maintain Visual Mode after shifting > and <
- vnoremap < <gv
- vnoremap > >gv
- " Move lines
- vnoremap <silent><C-Up> :m-2<CR>gv
- nnoremap <silent><C-Up> <Esc>:m-2<CR>
- nnoremap <silent> <C-Down> <Esc>:m+<CR>
- inoremap <silent> <C-Down> <Esc>:m+<CR>a
- inoremap <silent> <C-Up> <Esc>:m-2<CR>a
- xnoremap <C-Up> :move '<-2<cr>gv
- xnoremap <C-Down> :move '>+<cr>gv
- " delete current till the end of line
- inoremap <C-k> <C-o>C
- nnoremap <C-k> _D
- " Interpret .md files, etc. as .markdown
- let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'}
- " vimwiki/vimwiki
- let g:vimwiki_list = [{'path': '~/.dotfiles/nvim/wiki', 'syntax': 'markdown', 'ext': '.md'}]
- "*:VimwikiSearch* /pattern/
- "*:VWS* /pattern/
- " Search for /pattern/ in all files of current wiki.
- " To display all matches use |:lopen| command.
- " To display next match use |:lnext| command.
- " To display previous match use |:lprevious| command.
- let g:vimwiki_table_mappings = 0
- " Highlight redundant whitespace and tabs.
- " This has the advantage of not highlighting each space you type at
- " the end of the line, only when you open a file or leave insert
- " mode. Very neat."
- " http://vim.wikia.com/wiki/Highlight_unwanted_spaces
- "match ExtraWhitespace /\s\+$/
- highlight ExtraWhitespace ctermbg=red guibg=red
- match ExtraWhitespace /\s\+$/
- augroup redundant-whitespaces
- au!
- autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
- autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
- autocmd InsertLeave * match ExtraWhitespace /\s\+$/
- autocmd BufWinLeave * call clearmatches()
- "autocmd BufWinLeave <buffer> call clearmatches()
- "autocmd BufWinLeave * call StripTrailingWhitespace()
- " source: https://www.vi-improved.org/recommendations/
- augroup END
- " there is a discussion here where I have commented:
- " https://vi.stackexchange.com/a/19353/7339
- " see more about range :h <line1>
- " command! -range=% Cls <line1>,<line2>call StripTrailingWhitespace()
- " if !exists('*StripTrailingWhitespace')
- " function! StripTrailingWhitespace()
- " if !&binary && &filetype != 'diff'
- " call Preserve(":%s,\\s\\+$,,e")
- " endif
- " endfunction
- " endif
- "command! Cls call StripTrailingWhitespace()
- command! Cls :call Preserve(':%s/\v\s+$//e')
- cnoreabbrev cls Cls
- cnoreabbrev StripTrailingSpace Cls
- " com! StripTrailingSpace :call StripTrailingWhitespace()
- " cnoreabbrev cls StripTrailingSpace
- " Align text by a chosen char
- " https://stackoverflow.com/questions/57093175/
- " :Align =
- " :8,$ Align =
- " if !exists('*AlignText')
- " function! AlignText(param) range
- " execute a:firstline . ',' . a:lastline . '!column -t -s' . a:param . ' -o' . a:param
- " endfunction
- " endif
- " command! -range=% -nargs=1 Align <line1>,<line2>call AlignText(<q-args>)
- " https://stackoverflow.com/questions/57093175/
- " https://vi.stackexchange.com/questions/2410/
- if !exists('*AlignText')
- function! AlignText(...) range
- if a:0 < 1
- execute a:firstline . ',' . a:lastline . '!column -t'
- else
- execute a:firstline . ',' . a:lastline . '!column -t -s' . a:1 . ' -o' . a:1
- endif
- endfunction
- endif
- command! -range=% -nargs=? Align <line1>,<line2>call AlignText(<f-args>)
- augroup removetrailingspaces
- au!
- "au! BufwritePre *.md,*.py,*.sh,*.zsh,*.txt Preserve :%s/\v\s+$//e
- au! BufwritePre *.md,*.py,*.sh,*.zsh,*.txt :call Preserve(':%s/\v\s+$//e')
- augroup END
- command! -nargs=* Wrap set wrap linebreak nolist
- cnoreabbrev wrap set wrap
- cnoreabbrev nowrap set nowrap
- " Make the 81st column stand out
- highlight ColorColumn ctermbg=magenta
- call matchadd('ColorColumn', '\%81v', 100)
- " Esta função insere um change log
- " se nelas não houver "Last Change" ele passa batido
- " ou seja não insere o cabeçalho
- " usr_41.txt
- if !exists('*InsertChangeLog')
- fun! InsertChangeLog() abort
- let l:flag=0
- for i in range(1,7)
- if getline(i) !~ '.*Last Change.*'
- let l:flag = l:flag + 1
- endif
- endfor
- if l:flag >= 5
- normal(1G)
- call append(0, "Arquivo:")
- call append(1, "Created: " . strftime("%Y %B %d hs %H:%M"))
- call append(2, "Last Change: " . strftime("%b %d %Y hs %H:%M"))
- call append(3, "autor: <+digite seu nome+>")
- call append(4, "site: <+digite o endereço de seu site+>")
- call append(5, "twitter: <+your twitter here+>")
- call append(6, "email: <+seu email+>")
- normal gg
- endif
- endfun
- endif
- " This functions clears the last search from history
- if !exists('*UndoUndoSearch')
- fun! UndoUndoSearch()
- call histdel("search", -1)
- let @/ = histget("search", -1)
- endfun
- endif
- if !exists('*ChangeHeader')
- fun! ChangeHeader() abort
- if line('$')>=7
- call Preserve(':1,7s/Last \(Change\|Modified\):\s\+\zs.*/\=strftime("%b %d %Y %H:%M")/ei')
- endif
- endfun
- endif
- command! -nargs=0 CH :call ChangeHeader()
- augroup change_header
- au!
- au! BufWritePre * :silent call ChangeHeader()
- augroup END
- " jump to next place holder
- if !exists('*JumpToNextPlaceholder')
- function! JumpToNextPlaceholder() abort
- let old_query = getreg('/')
- echo search("<+.\\++>")
- exec "norm! c/+>/e\<CR>"
- call setreg('/', old_query)
- endfunction
- endif
- nnoremap <Leader>p :keepjumps call JumpToNextPlaceholder()<CR>a
- inoremap <Leader>p <ESC>:keepjumps call JumpToNextPlaceholder()<CR>a
- noremap <F12> <Esc>:syntax sync fromstart<CR>
- inoremap <F12> <C-o>:syntax sync fromstart<CR>
- highlight ColorColumn ctermbg=magenta
- call matchadd('ColorColumn', '\%81v', 100)
- " dos2unix ^M
- if !exists('*func_name')
- fun! Dos2unixFunction() abort
- "call Preserve('%s/ $//ge')
- call Preserve(":%s/\x0D$//e")
- set ff=unix
- set bomb
- set encoding=utf-8
- set fileencoding=utf-8
- endfun
- endif
- com! Dos2Unix :call Dos2unixFunction()
- cnoreabbrev dos2unix Dos2unix
- cnoreabbrev d2u Dos2Unix
- " one liner rename file
- " source: http://stackoverflow.com/questions/1205286/renaming-the-current-file-in-vim
- command! -nargs=1 Rename try | saveas <args> | call delete(expand('#')) | bd # | endtry
- " Utility function that save last search and cursor position
- " http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
- " video from vimcasts.org: http://vimcasts.org/episodes/tidying-whitespace
- " using 'execute' command doesn't overwrite the last search pattern, so I
- " don't need to store and restore it.
- " preserve function
- if !exists('*Preserve')
- function! Preserve(command)
- try
- let l:win_view = winsaveview()
- "silent! keepjumps keeppatterns execute a:command
- silent! execute 'keeppatterns keepjumps ' . a:command
- finally
- call winrestview(l:win_view)
- endtry
- endfunction
- endif
- command! -nargs=1 Keep call Preserve(<q-args>)
- cnoreabbrev pre Keep
- " remove consecutive blank lines
- " see Preserve function definition
- " another way to remove blank lines :g/^$/,/./-j
- call Preserve(':g/^$/,/./-j')
- if !exists('*DelBlankLines')
- fun! DelBlankLines() range
- if !&binary && &filetype != 'diff'
- call Preserve(':%s/\s\+$//e')
- call Preserve(':%s/^\n\{2,}/\r/ge')
- endif
- endfun
- endif
- command! -nargs=0 DelBlank :call DelBlankLines()
- nnoremap <Leader>d :call DelBlankLines()<cr>
- " Sudo to write
- " cnoremap w!! w !sudo tee % >/dev/null
- cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
- command! SaveAsRoot w !sudo tee %
- cnoreabbrev sudow SaveAsRoot
- " bash/emacs keybindings
- imap <C-a> <C-o>0
- imap <C-e> <C-o>$
- cnoremap <c-a> <home>
- cnoremap <c-e> <end>
- " " toggles hightlight search and list with Ctrl-l
- " nnoremap <C-l> :let [&hls, &list] = [!&list, &hls+&list==1]<CR>
- " inoremap <C-l> <C-o>:let [&hls, &list] = [!&list, &hls+&list==1]<CR>
- " vnoremap <C-l> <ESC>:let [&hls, &list] = [!&list, &hls+&list==1]<CR> <bar> gv
- nnoremap <c-l> <ESC>:set hls! hls?<cr><c-l>
- inoremap <c-l> <C-o>:set hls! hls?<cr><c-l>
- vnoremap <c-l> <ESC>:set hls! hls?<cr><c-l> <bar> gv
- " undo inserting
- " https://vi.stackexchange.com/a/15246/7339
- let g=0
- inoremap <expr> <C-_> "\<C-o>".(g == 0 ? ':undo' : ':redo'). "\<CR>"
- " alternate between relative number, number and no number
- set nu rnu
- " toggles number and relative number with Ctrl-n
- nnoremap <C-n> :let [&nu, &rnu] = [!&rnu, &nu+&rnu==1]<cr>
- " a barra de espaços -- zR abre todos os folders
- nnoremap <Leader><space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
- " https://superuser.com/a/170026/45032
- set foldlevelstart=99
- nnoremap <space> /
- " the below mapping conficts with ultisnis
- "nnoremap <c-space> :
- hi Folded ctermbg=black
- let g:UltiSnipsSnippetsDir = expand("~/.dotfiles/nvim/snips/")
- let g:UltiSnipsSnippetDirectories=["snips", "UltiSnips"]
- map <Leader>u :UltiSnipsEdit<cr>
- " Snippets variables
- let g:snips_author='Sergio Araujo'
- let g:snips_site='http://vivaotux.blogspot.com'
- let g:snips_email='<voyeg3r ✉ gmail.com>'
- let g:snips_github='https://github.com/voyeg3r'
- let g:snips_twitter='@voyeg3r'
- let g:UltiSnipsEditSplit="horizontal"
- inoreabbrev fname <C-R>=expand("%:t")<CR>
- inoreabbrev Fname <C-R>=expand("%:p")<CR>
- inoreabbrev idate <C-R>=strftime("%b %d %Y %H:%M")<CR>
- inoreabbrev hdate <C-R>=strftime("%Y %B %d")<CR>
- "inoreabbrev -> →
- inoreabbrev mymail <voyeg3r ✉ gmail.com>
- inoreabbrev slas Sérgio Luiz Araújo Silva
- inoreabbrev tuiter http://www.twitter.com/voyeg3r
- inoreabbrev vivaotux http://vivaotux.blogspot.com
- cnoreabbrev ag Ag
- " Fot transparency on terminal it needs to be at the end of init.vim
- " transparency on the background
- hi Normal guibg=NONE ctermbg=NONE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement