Advertisement
voyeg3r

init.vim

Sep 4th, 2019
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 36.94 KB | None | 0 0
  1. "   nvim file: ~/.config/nvim/init.vim
  2. " Last Change: set 04 2019 08:24
  3. "         vim: ff=unix ai et ts=4
  4. "      Author: Sérgio Luiz Araújo Silva
  5. "
  6. "                      ( O O )
  7. "       +-----------oOO--(_)--OOo--------------+
  8. "       |                                      |
  9. "       |    °v°   Sergio Luiz Araujo Silva    |
  10. "       |   /(_)\  Linux User #423493          |
  11. "       |    ^ ^   voyeg3r ✉ gmail.com         |
  12. "       +--------------------------------------+
  13. "
  14. "        _   _                 _
  15. "       | \ | | ___  _____   _(_)_ __ ___
  16. "       |  \| |/ _ \/ _ \ \ / / | '_ ` _ \
  17. "       | |\  |  __/ (_) \ V /| | | | | | |
  18. "       |_| \_|\___|\___/ \_/ |_|_| |_| |_|
  19. "
  20. "
  21. " TODO: fix some indentation issuies
  22. "
  23. " As you type a substitution  the results will immediately be
  24. " visible in the edit window. This feature is best highlighted
  25. " in this video: http://www.youtube.com/watch?v=sA3z6gsqOuw
  26. if has("nvim")
  27.     set inccommand=nosplit
  28.     tnoremap <Esc> <c-\><c-n>
  29.     if executable('nvr')
  30.         let $VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
  31.     endif
  32. endif
  33.  
  34. " Required:
  35. let mapleader = ','
  36. set shada=!,'500,<50,s10,h
  37. set nospell
  38.  
  39. set nomodeline
  40.  
  41. "set spelllang=en,pt
  42. "set complete+=kspell
  43. "set sps=8              " Quantidade de sugestões do spell
  44. " i_Ctrl-g_u allows us to have a better undo
  45. inoremap <C-s> <c-g>u<Esc>[s1z=gi<c-g>u
  46.  
  47. " Toggles paste to insert clipboard content
  48. "inoremap <S-Insert> <ESC>:setl paste<CR>gi<C-R>+<ESC>:setl nopaste<CR>gi
  49. inoremap <S-Insert> <ESC>"+p`]a
  50.  
  51. " Auto install vim plug
  52. if empty(glob('~/.dotfiles/nvim/autoload/plug.vim'))
  53.  if !executable("curl")
  54.    echoerr "You have to install curl or first install vim-plug yourself!"
  55.    execute "q!"
  56.  endif
  57.  silent !curl -fLo ~/.dotfiles/nvim/autoload/plug.vim --create-dirs
  58.    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  59.  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
  60. endif
  61.  
  62. call plug#begin(expand(glob('~/.config/nvim/plugged')))
  63. "Plug 'lervag/vimtex'
  64. "Plug 'voldikss/vim-translate-me'
  65. "Plug 'mhinz/vim-startify'
  66. "Plug 'henrik/vim-indexed-search'
  67. "Plug 'coderifous/textobj-word-column.vim'
  68. "Plug 'mhinz/neovim-remote'
  69. Plug 'junegunn/limelight.vim'
  70. Plug 'bilalq/lite-dfm'
  71. Plug 'PeterRincker/vim-searchlight'
  72. Plug 'Yggdroot/indentLine'
  73. Plug 'ap/vim-buftabline'
  74. "Plug 'voyeg3r/vim-neatstatus'
  75. Plug 'nelstrom/vim-visual-star-search'
  76. Plug 'w0rp/ale' , { 'on': ['ALEToggle'] }
  77. Plug 'rking/ag.vim', { 'on':  ['Ag'] }
  78. "Plug 'wellle/targets.vim'
  79. Plug 'mattn/emmet-vim' , { 'for': ['html', 'htmldjango', 'javascript.jsx', 'css'] }
  80. Plug 'tpope/vim-abolish', { 'on': [] } "Advanced regex Substitution
  81. "Plug 'tpope/vim-surround', { 'on': [] }
  82. Plug 'tpope/vim-surround',
  83.      \ { 'on': ['<Plug>Dsurround', '<Plug>Csurround', '<Plug>CSurround',
  84.      \ '<Plug>Ysurround',  '<Plug>YSurround', '<Plug>Yssurround',
  85.      \ '<Plug>YSsurround', '<Plug>VSurround', '<Plug>VgSurround'] }
  86. "Plug 'tpope/vim-unimpaired'
  87. "Plug 'godlygeek/tabular', { 'on': ['Tabularize'] }
  88. "Plug 'jezcope/vim-align', { 'on' : 'Align' }
  89. Plug 'tommcdo/vim-exchange'
  90. "Plug 'nelstrom/vim-visual-star-search'
  91. "Plug 'nelstrom/vim-markdown-folding'
  92. "Plug 'haya14busa/incsearch.vim'
  93. Plug 'timakro/vim-searchant'
  94. "Plug 'inside/vim-search-pulse'
  95. Plug 'machakann/vim-highlightedyank'
  96. Plug 'vim-scripts/VisIncr', { 'on': [] }
  97. Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
  98. Plug 'zchee/deoplete-jedi'
  99. Plug 'kshenoy/vim-signature', { 'on': [] }
  100. Plug 'vimwiki/vimwiki', { 'for': ['markdown', 'vimwiki'] }
  101. "Plug 'vimwiki/vimwiki', { 'for': [] }
  102. Plug 'sjl/gundo.vim', { 'on': ['GundoToggle'] }
  103. "Plug 'chrisbra/NrrwRgn', { 'on': ['NR', 'NrrwRgn'] }
  104. Plug 'chrisbra/NrrwRgn'
  105. Plug 'tpope/vim-speeddating'
  106. Plug 'jiangmiao/auto-pairs'
  107. "Plug 'rstacruz/vim-closer'
  108. Plug 'tpope/vim-commentary'
  109. "Plug 'tpope/vim-fugitive'
  110. "Plug 'tommcdo/vim-lion', { 'on': [] }
  111. Plug 'vim-airline/vim-airline'
  112. Plug 'vim-airline/vim-airline-themes'
  113. "Plug 'airblade/vim-gitgutter'
  114. Plug 'vim-scripts/grep.vim', { 'on': [] }
  115. Plug 'vim-scripts/CSApprox', { 'on': [] }
  116. "Plug 'majutsushi/tagbar'
  117. "Plug 'scrooloose/syntastic'
  118. "Plug 'Yggdroot/indentLine'
  119.  
  120. if isdirectory('/usr/local/opt/fzf')
  121.  Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
  122. else
  123.    Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
  124.    Plug 'junegunn/fzf.vim'
  125.    "Plug 'junegunn/fzf', { 'on': ['FZF', 'History', 'Files' ], 'dir': '~/.fzf', 'do': './install --bin' }
  126.    "Plug 'junegunn/fzf.vim', { 'on': ['FZF', 'History', 'Files' ] }
  127. endif
  128.  
  129. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  130. "Plug 'SirVer/ultisnips', {'on': '#InsertEnter' } | Plug 'honza/vim-snippets', {'on': [] }
  131. "Plug 'SirVer/ultisnips', { 'on': [] }
  132. Plug 'SirVer/ultisnips'
  133. Plug 'honza/vim-snippets'
  134.  
  135. " Color
  136. Plug 'sainnhe/vim-color-forest-night'
  137. Plug 'axvr/photon.vim'
  138. Plug 'morhetz/gruvbox'
  139. Plug 'reedes/vim-colors-pencil'
  140. Plug 'trevordmiller/nova-vim'
  141. Plug 'crusoexia/vim-monokai', { 'on': [] }
  142. Plug 'ayu-theme/ayu-vim'
  143. Plug 'drewtempelmeyer/palenight.vim'
  144. Plug 'endel/vim-github-colorscheme'
  145. Plug 'NLKNguyen/papercolor-theme'
  146. Plug 'icymind/NeoSolarized'
  147. Plug 'lifepillar/vim-solarized8'
  148. Plug 'tomasr/molokai'
  149. Plug 'nanotech/jellybeans.vim'
  150. Plug 'mhartington/oceanic-next'
  151. Plug 'sainnhe/vim-color-vanilla-cake'
  152. " statusline
  153. "Plug 'vim-scripts/Obvious-Mode'
  154. " Color picker
  155. Plug 'lilydjwg/colorizer', { 'on': [] }
  156. call plug#end()
  157.  
  158. " Recover from accidental Ctrl-U
  159. " http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
  160. " use Ctrl-r . to get your text back
  161. "inoremap <c-u> <c-g>u<c-u>
  162. "inoremap <c-w> <c-g>u<c-w>
  163. "inoremap <c-y> <c-o>u
  164. inoremap <silent> <c-w> <c-\><c-o>db
  165. inoremap <silent> <c-u> <c-\><c-o>d0
  166. "inoremap <silent> <C-S-Y> <C-R>"
  167.  
  168. " https://github.com/ryangrose/easy-pandoc-templates
  169. " https://vi.stackexchange.com/questions/17549/
  170. if !exists('*PandocMappings')
  171.    function! PandocMappings()
  172.        " NOTE: <F16> equals to Shift-F4
  173.        noremap <F4> :! pandoc '%:p' -o /tmp/'%:p:t'.html --template=easy_template.html --toc && firefox /tmp/'%:p:t'.html &<CR><CR>
  174.        noremap <F16> :! pandoc '%:p' -o /tmp/'%:p:t'.pdf --pdf-engine=pdflatex --toc && evince /tmp/'%:p:t'.pdf &<CR><CR>
  175.    endfun
  176. endif
  177.  
  178. augroup every
  179.  autocmd!
  180.  au InsertEnter * set norelativenumber
  181.  au InsertLeave * set relativenumber
  182. augroup END
  183.  
  184. " inserts a line below without commenting if file is modifiable &ma?
  185. " nnoremap <silent> <cr> :set paste<cr>o<esc>:set nopaste<cr>
  186. nnoremap <expr> <Enter> &ma?":set paste\<cr>\<esc>o\<esc>:set nopaste\<cr>":"\<cr>"
  187.  
  188. " show registers
  189. nnoremap <Leader>r :registers<CR>
  190.  
  191. " save with <F9> if file was modified
  192. nnoremap <F9> :update<cr>
  193. inoremap <F9> <c-o>:update<cr>
  194. vnoremap <F9> :<c-u>update<cr><bar>gv
  195.  
  196. nnoremap Q :normal .<CR>
  197.  
  198. nnoremap '. `.
  199. nnoremap - $
  200.  
  201. nnoremap n nzzzv
  202. nnoremap N Nzzzv
  203. nnoremap } }zzzv
  204. nnoremap { {zzzv
  205. "nnoremap <C-M-l> :set cursorline!<CR>
  206. nnoremap <C-M-l> :<c-u>setlocal list! list?<CR>
  207.  
  208. " spelling
  209. " nnoremap <C-s> [s1z=<C-o>
  210. " nnoremap <Leader>s ]s1z=<C-o>
  211. " nnoremap <Leader>g ]szg<C-o>
  212. " See more about <C-x>s
  213. " Below mappings allows you to toggle spelling
  214. " nnoremap <F7> :setlocal spell!<CR>
  215. " inoremap <F7> <C-o>:setlocal spell!<CR>
  216.  
  217. " allows me to use a smarter cgn
  218. "nnoremap * :keepjumps normal *``<cr>
  219. nnoremap c* *<c-o>cgn
  220. nnoremap c# #<C-o>cgn
  221.  
  222. " avoid clipboard hacking security issue
  223. " http://thejh.net/misc/website-terminal-copy-paste
  224. inoremap <C-R>+ <C-R><C-R>+
  225. " Auto reindent pasted text (from hacking vim p.138)
  226. " nnoremap p p=`]
  227. " cool
  228.  
  229. "command! -nargs=0 CopyFile :%y+<CR>
  230. command! CloneBuffer new | 0put =getbufline('#',1,'$')
  231.  
  232. command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor
  233.  
  234. function! s:Registers( arguments )
  235.     redir => l:registersOutput
  236.         silent! execute 'registers' a:arguments
  237.     redir END
  238.     for l:line in split(l:registersOutput, "\n")
  239.         if l:line !~# '^"\S\s*$'
  240.             echo l:line
  241.         endif
  242.     endfor
  243. endfunction
  244. command! -nargs=? Registers call <SID>Registers(<q-args>)
  245.  
  246. " Spell mistakes color
  247. "highlight SpellBad cterm=bold ctermfg=white ctermbg=red
  248. "highlight SpellCap cterm=bold ctermfg=red ctermbg=white
  249. if has("multi_byte")
  250.   if &termencoding == ""
  251.     let &termencoding = &encoding
  252.   endif
  253.   set encoding=utf-8
  254.   setglobal fileencoding=utf-8
  255.   set fileencodings=ucs-bom,utf-8,latin1
  256. endif
  257.  
  258. set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
  259.   \,a:blinkwait300-blinkoff200-blinkon150-Cursor/lCursor
  260.   \,sm:block-blinkwait175-blinkoff150-blinkon175
  261.  
  262. set laststatus=2
  263. set guicursor+=n:blinkon1 " not blinking cursor in normal mode
  264. "set guicursor+=i:blinkon1 " cursor blinkin in insert mode
  265. "
  266. "set dictionary+=~/.dotfiles/nvim/words.txt     " C-x C-k C-n
  267. "set nrformats+=alpha  " Increases/Decreases numbers with Ctrl-a/Ctrl-x correctrly
  268. set lazyredraw        " speed up macros
  269. set mouse=a           " enable mouse click
  270. set path+=.,**
  271. set scrolloff=1       " keep 1 line visible when scrolling
  272. set sidescrolloff=5
  273. set ai                " set auto-indenting on for programming (nvim default)
  274. set hidden            " Switch buffers without saving them
  275. "set autowrite
  276. "set autowriteall
  277. set display+=lastline
  278. "set nobackup         " do not keep a backup file
  279. set number            " show line numbers
  280. set showmatch         " jump to matches when entering regexp
  281. set ignorecase        " ignore case when searching
  282. set infercase         " case inferred by default
  283. set smartcase         " no ignorecase if Uppercase char present
  284. set visualbell        " turn off error beep/flash
  285. set novisualbell      " turn off visual bell
  286. set title             " shows filename at the top
  287. set formatoptions=tcqj
  288. set expandtab         " Converts tab into spaces
  289. set tabstop=4         " Number of spaces that a <Tab> in the file counts for
  290. set softtabstop=4     " number of spaces in tab when editing
  291. set shiftwidth=4      " indented with the reindent operations with >> and <<
  292. set nojoinspaces      " Prevents inserting two spaces after punctuation on a join (J)
  293. set shiftround        " when at 3 spaces, and I hit > go to 4, not 5
  294. "set t_RV=
  295.  
  296. let &fillchars = "vert:\u2502,diff: "
  297. let &listchars = "tab:\u25b8 ,extends:\u00bb,precedes:\u00ab,space:\u00b7,nbsp:\u2334,eol:\u21b2"
  298. let &showbreak = "\u21aa "
  299.  
  300. set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__,*.swp,*.bak
  301. set wildignore+=*.so,*.pdf,*.swp,*.zip,*.pyc,*.db,*.sqlite,*.jpg,*.png,*.gif
  302. set wildmenu
  303. "set wildmode=list:longest,full
  304. "set wildmode=longest:full,list:full
  305. set wildmode=longest,list
  306. " making <tab> work properly on vim command line
  307. "set whichwrap +=<,>
  308. set nopaste
  309. set pastetoggle=<F8>
  310. set linebreak                  " Keep whole words during wrapping
  311. set noshowmode
  312. set noerrorbells visualbell
  313.  
  314. "You can get case-insensitivity for the filename completion in Vim with the following.
  315. set wildignorecase
  316.  
  317. " jump to next/previous comment
  318. " https://vimtricks.com/viml/2017/05/26/jump-to-next-commented-line/
  319. nnoremap ]c :call search('^\s*'.substitute(escape(&cms, '\.*[]^$'), '%s', '.*', '').'\s*$')<CR>
  320. nnoremap [c :call search('^\s*'.substitute(escape(&cms, '\.*[]^$'), '%s', '.*', '').'\s*$', 'b')<CR>
  321.  
  322. " nvim default undodir: ~/.local/share/nvim/undo (|xdg|), auto-created
  323. set undofile " Maintain undo history between sessions
  324.  
  325. let g:indentLine_char = '▏'
  326.  
  327. " Enable airline symbols
  328. let g:airline_powerline_fonts = 1
  329. let g:airline_highlighting_cache = 1
  330.  
  331. " if is there more than one buffer it will appear on buftabline
  332. let g:buftabline_show = 1
  333. let g:buftabline_numbers = 1
  334.  
  335. " function! RunningInsideGit()
  336. "   let result = system('env | grep ^GIT_')
  337. "   if result == ""
  338. "     return 0
  339. "   else
  340. "     return 1
  341. "   endif
  342. " endfunction
  343.  
  344. " many plugins are disabled by default and called by
  345. " this function for example: call LoadPluginFunction('vim-lion')
  346. " and the command LoadPlugin plugin-name (whithout quotes)
  347. " list unloaded plugins
  348. " \v^Plug[^/]*\/\zs([^']*)\ze',\s+\{\s+'on':\s+[]
  349. if !exists('*LoadPluginFunction')
  350.     fun! LoadPluginFunction(pluginname)
  351.         let l:curpos = getcurpos()
  352.         execute plug#load(a:pluginname)
  353.         call cursor(l:curpos[1], l:curpos[2])
  354.         return ''
  355.     endfun
  356. endif
  357. command! -nargs=1 LoadPlugin :call LoadPluginFunction(<q-args>)
  358.  
  359. " augroup help_start
  360. "     autocmd!
  361. "     autocmd FileType help,markdown call SetHelpFiletype()
  362. " augroup end
  363. "
  364. " if !exists('*SetHelpFiletype')
  365. "     fun! SetHelpFiletype()
  366. "         augroup help_insert
  367. "             autocmd!
  368. "             autocmd InsertEnter <buffer> setlocal conceallevel=0 | highlight clear Ignore
  369. "             autocmd InsertLeave <buffer> setlocal conceallevel=2
  370. "         augroup end
  371. "     endfun
  372. " endif
  373.  
  374. " Toggle *conceallevel*
  375. nnoremap <Leader>c :let &l:cole=(&cole == 3) ? 0 : 3 <bar> echo 'conceallevel ' . &cole <CR>
  376. syntax match arrow "->" conceal cchar=→
  377. syntax match rcomp ">>" conceal cchar=»
  378. syntax match lcom "<<" conceal cchar=«
  379. set concealcursor=n
  380. set conceallevel=3
  381.  
  382. " lazy load for ultisnips
  383. " https://medium.com/@saaguero/improving-performance-in-vim-9b33598c8eaf
  384. inoremap <silent> <C-j> <C-r>=LoadUltiSnips()<CR>
  385. nnoremap <silent> <C-M-u> :call LoadUltiSnips()<CR>
  386. " This function only runs when UltiSnips is not loaded
  387. if !exists('*LoadUltiSnips')
  388.     function! LoadUltiSnips()
  389.         call Preserve(":execute plug#load('vim-snippets')")
  390.         call Preserve(":execute plug#load('ultisnips')")
  391.         call UltiSnips#ExpandSnippet()
  392.         echo "Ultisnips loaded!"
  393.         return ""
  394.     endfunction
  395. endif
  396.  
  397. nnoremap <Leader>z :LiteDFMToggle<CR>
  398.  
  399. nnoremap <F2> :NERDTreeToggle<cr>
  400. " hide old “Press ? for help”
  401. let NERDTreeMinimalUI = 1
  402. let NERDTreeDirArrows = 1
  403. " close nerdthree when it opens a file
  404. let NERDTreeQuitOnOpen = 1
  405. " Automatically delete the buffer of the file you just deleted with NerdTree:
  406. let NERDTreeAutoDeleteBuffer = 1
  407.  
  408. inoremap <expr> <TAB> pumvisible() ? "\<C-y>" : "\<TAB>"
  409. let g:deoplete#sources = {}
  410. let g:deoplete#sources._=['omni', 'buffer', 'member', 'tag', 'ultisnips', 'file']
  411. let g:deoplete#enable_at_startup = 1
  412. let g:deoplete#enable_refresh_always = 1
  413. let g:deoplete#enable_ignore_case = 1
  414. let g:deoplete#enable_smart_case = 1
  415. let g:deoplete#enable_camel_case = 1
  416. let g:deoplete#file#enable_buffer_path = 1
  417. let g:deoplete#sources#jedi#python_path = '/usr/bin/python3'
  418.  
  419. " <CR>: close popup and save indent.
  420. " Now each Enter creates a undo point ":h i_Ctrl-g_u"
  421. " inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
  422. "if !exists('*s:my_cr_function')
  423. "    function! s:my_cr_function()
  424. "      "return deoplete#mappings#smart_close_popup() . "\<C-g>u\<CR>"
  425. "      return deoplete#mappings#smart_close_popup() . "\<CR>"
  426. "    endfunction
  427. "endif
  428.  
  429. " Trying to fix deoplete
  430. "set runtimepath+=~/path/to/deoplete.nvim/
  431. set runtimepath+=~/.config/nvim/plugged/deoplete.nvim/
  432. let g:deoplete#enable_at_startup = 1
  433.  
  434. call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy'])
  435. set omnifunc=syntaxcomplete#Complete
  436. "set completeopt=longest,menuone,preview,noinsert
  437. set completeopt=menuone,longest,preview
  438.  
  439. " copy until the end of line using
  440. nnoremap Y y$
  441.  
  442. " Jump outside '"({
  443. if !exists('g:AutoPairsShortcutJump')
  444.   let g:AutoPairsShortcutJump = '<A-l>'
  445. endif
  446.  
  447. if exists('$SHELL')
  448.     set shell=$SHELL
  449. else
  450.     set shell=/bin/sh
  451. endif
  452.  
  453. " Use whole "words" when opening URLs.
  454. " This avoids cutting off parameters (after '?') and anchors (after '#').
  455. " See http://vi.stackexchange.com/q/2801/1631
  456. let g:netrw_gx="<cWORD>"
  457. let g:netrw_liststyle = 3
  458. let g:netrw_browsex_viewer= "opera"
  459.  
  460. " pencil is another great colorscheme
  461. "colo PaperColor
  462. "silent! colo gruvbox
  463. " gruvbox has a great light colorscheme, just press <Shift><F7>
  464. let colorscheme="PaperColor"
  465. if findfile("colors/" .colorscheme .".vim", &rtp) != ""
  466.     execute "colorscheme " . colorscheme
  467. endif
  468.  
  469. " https://stackoverflow.com/a/7589970/2571881
  470. " if strftime("%H") < 17
  471. "   set background=light
  472. " else
  473. "   set background=dark
  474. " endif
  475.  
  476. " source: http://tilvim.com/2013/07/31/swapping-bg.html <F19> = Shif-F7
  477. " nmap <F19> :let &background = ( &background == "dark"? "light" : "dark" )<CR>
  478.  
  479. " removed ifs because it must be used with neovim
  480. let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  481. set termguicolors
  482.  
  483. " When double click a word vim will hightlight all other ocurences
  484. " see CountWordFunction()
  485. " [I shows lines with word under the cursor
  486. nnoremap <silent> <2-LeftMouse> :let @/='\V\<'.escape(expand('<cword>'), '\').'\>'<cr>:set hls<cr>:CountWord<cr>
  487. nnoremap <Leader>* :let @/='\V\<'.escape(expand('<cword>'), '\').'\>'<cr>:set hls<cr>:CountWord<cr>
  488.  
  489. nnoremap <F5> :GundoToggle<CR>
  490. let g:gundo_prefer_python3 = 1
  491.  
  492. nnoremap <Left> :vertical resize +2<CR>
  493. nnoremap <Right> :vertical resize -2<CR>
  494. "nnoremap <Up> :resize -2<CR>
  495. "nnoremap <Down> :resize +2<CR>
  496.  
  497. set wildchar=<Tab> wildmenu wildmode=full
  498. set wildcharm=<C-Z>
  499. nnoremap <F10> :b <C-Z><S-TAB>
  500. " list buffers and jump to a chosen one
  501. nnoremap <Leader>b :ls<CR>:b<Space>
  502.  
  503. " sometimes you need to know how many opened buffers you have
  504. " source: https://superuser.com/a/1221514/45032
  505. if !exists('*CountBuffers')
  506.    fun! CountBuffers() abort
  507.        "let l:total = len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
  508.        let l:total = len(getbufinfo({'buflisted':1}))
  509.        echom "you have " . l:total . " opened buffers!"
  510.    endfun
  511. endif
  512. command! -nargs=0 Nbufs :call CountBuffers()
  513.  
  514. if !exists('*CloseAllBuffersButCurrent')
  515.    function! CloseAllBuffersButCurrent()
  516.        let curr = bufnr("%")
  517.        let last = bufnr("$")
  518.        if curr > 1    | silent! execute "1,".(curr-1)."bd"     | endif
  519.        if curr < last | silent! execute (curr+1).",".last."bd" | endif
  520.        echom "All other buffers unloaded!"
  521.    endfunction
  522. endif
  523. command! -nargs=0 Bonly :call CloseAllBuffersButCurrent()
  524. command! -nargs=0 Bo :call CloseAllBuffersButCurrent()
  525.  
  526. " close the buffer
  527. nnoremap <C-M-d> :bd!<CR>
  528. nnoremap <C-M-w> :bw!<CR>
  529. nnoremap <C-M-o> :Bonly<CR>
  530.  
  531. " substitute word under cursor - This map is used for spell
  532. " nnoremap <Leader>s :call Preserve('%s/\<<C-r><C-w>\>//g\<left><left>')
  533.  
  534. " Scroll split window
  535. nnoremap <C-M-k> <c-w>w<c-y><c-w>w
  536. nnoremap <C-M-j> <c-w>w<c-e><c-w>w
  537.  
  538. " resise windows
  539. nnoremap <M-=> <C-w>+
  540. nnoremap <M--> <C-w>-
  541. filetype on                " detect type of file
  542. "filetype plugin indent on " neovim default (don't bother with this)
  543. " My font is fira mono regular stled on gnome-shell
  544.  
  545. " line text-objects
  546. " vnoremap <silent> al :<c-u>norm!0v$h<cr>
  547. vnoremap <silent> al :<c-u>norm!0v$<cr>
  548. vnoremap <silent> il :<c-u>norm!_vg_<cr>
  549. onoremap <silent> al :norm val<cr>
  550. onoremap <silent> il :norm vil<cr>
  551.  
  552. " more text objects
  553. for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '%', '`' ]
  554.     execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
  555.     execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
  556.     execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
  557.     execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
  558. endfor
  559.  
  560. " buffer text-object
  561. "xnoremap i% GoggV
  562. "omap i% :<C-u>normal vi%<CR>
  563.  
  564. command! -nargs=0 Reindent :call Preserve('exec "normal! gg=G"')
  565. command! MakeTags !ctags -R .
  566.  
  567. " create a scratch window - rascunho
  568. command! Scratch new | setlocal bt=nofile bh=wipe nobl noswapfile nu
  569. cnoreabbrev SC Scratch
  570.  
  571. " Now this allows me to open a scratch buffer with various options, like I could
  572. " call :Sedit ft=javascript and that would open a scratch buffer with filetype
  573. " javascript (and hence show the right syntax highlighting).
  574. " https://dhruvasagar.com/2014/03/11/creating-custom-scratch-buffers-in-vim
  575.  
  576. if !exists('*ScratchEdit')
  577.     function! ScratchEdit(cmd, options)
  578.         exe a:cmd tempname()
  579.         setl buftype=nofile bufhidden=wipe nobuflisted
  580.         if !empty(a:options) | exe 'setl' a:options | endif
  581.     endfunction
  582. endif
  583.  
  584. command! -bar -nargs=* Sedit call ScratchEdit('edit', <q-args>)
  585. command! -bar -nargs=* Ssplit call ScratchEdit('split', <q-args>)
  586. command! -bar -nargs=* Svsplit call ScratchEdit('vsplit', <q-args>)
  587. command! -bar -nargs=* Stabedit call ScratchEdit('tabe', <q-args>)
  588.  
  589. " select last paste in visual mode
  590. " https://vim.fandom.com/wiki/Selecting_your_pasted_text
  591. " nnoremap gp `[v`]
  592. nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
  593.  
  594. if !exists('*s:setupWrapping')
  595.   function s:setupWrapping()
  596.     set wrap
  597.     set wm=2
  598.     set textwidth=78
  599.     set formatoptions+=t
  600.   endfunction
  601. endif
  602.  
  603. " join lines keeping cursor position
  604. nnoremap J :call Preserve(':join')<CR>
  605. nnoremap <Leader>J :call Preserve(':join!')<CR>
  606. "noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
  607. "noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
  608. " It adds motions like 25j and 30k to the jump list, so you can cycle
  609. " through them with control-o and control-i.
  610. " source: https://www.vi-improved.org/vim-tips/
  611. nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
  612. nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
  613.  
  614. " to insert this result: --> :put =Randnum(1000)
  615. if !exists('*Randnumber')
  616.     function! Randnumber(max) abort
  617.       return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) % a:max
  618.     endfunction
  619. endif
  620.  
  621. if !exists('*CountWordFunction')
  622.     fun! CountWordFunction()
  623.         try
  624.             let l:win_view = winsaveview()
  625.             exec "%s/" . expand("<cword>") . "//gn"
  626.         finally
  627.             call winrestview(l:win_view)
  628.         endtry
  629.     endfun
  630. endif
  631.  
  632. command! -nargs=0 CountWord :call CountWordFunction()
  633. cnoreabbrev cw CountWord
  634. nnoremap <F3> :CountWord<CR>
  635.  
  636. " Reloads vimrc after saving but keep cursor position
  637. if !exists('*ReloadVimrcFunction')
  638.     function! ReloadVimrcFunction()
  639.         call Preserve(':source $MYVIMRC')
  640.         hi Normal guibg=NONE ctermbg=NONE
  641.         windo redraw
  642.         echom "Reloaded init.vim"
  643.     endfunction
  644. endif
  645. noremap <silent> <Leader>v :e $MYVIMRC<cr>
  646. command! -nargs=0 ReloadVimrc :call ReloadVimrcFunction()
  647.  
  648. " Reference: https://stackoverflow.com/posts/30552423/revisions
  649. augroup vimrc_todo
  650.   autocmd!
  651.   autocmd BufEnter * syntax match MyTodo /\v<(FIXME|NOTE|OBS|TODO|OPTIMIZE)>:/ containedin=.*Comment.*
  652.   autocmd BufEnter * silent! syntax clear cTodo
  653.   autocmd BufEnter * silent! syntax clear vimTodo
  654. augroup END
  655. "highlight link MyTodo Todo
  656. highlight def link MyTodo Todo
  657.  
  658. augroup Reload
  659.     autocmd!
  660.     autocmd BufWritePost init.vim call ReloadVimrcFunction()
  661. augroup END
  662.  
  663. " The PC is fast enough, do syntax highlight syncing from start unless 200 lines
  664. augroup vimrc-sync-fromstart
  665.   autocmd!
  666.   "autocmd BufEnter * syntax sync maxlines=200
  667.   autocmd BufWinEnter,Syntax * syn sync minlines=500 maxlines=500
  668. augroup END
  669.  
  670. "" Remember cursor position
  671. augroup vimrc-remember-cursor-position
  672.   autocmd!
  673.   autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  674. augroup END
  675.  
  676. augroup lcd-folder
  677.     au!
  678.     autocmd BufEnter * silent! lcd %:p:h
  679. augroup END
  680.  
  681. augroup sh
  682.     au!
  683.     au! BufWritePost *.sh,*.zsh :silent !chmod a+x <afile>
  684. augroup END
  685.  
  686. " trying to fix fzf behavior with <esc>
  687. augroup fixFzf
  688.     au!
  689.     autocmd! FileType fzf tnoremap <buffer> <esc> <c-c>
  690. augroup END
  691.  
  692. if !exists('*SetPythonOptions')
  693.     function! SetPythonOptions()
  694.         set keywordprg=pydoc
  695.         filetype plugin indent on
  696.         set smartindent et sts=4 sw=4 tw=80 fo=croq
  697.         let python_highlight_builtins=1
  698.         let python_highlight_all=1
  699.         let python_highlight_exceptions=1
  700.         let python_highlight_numbers=1
  701.         let python_highlight_space_errors=1
  702.         let g:_uspy=":python3"
  703.         let g:ultisnipsusepythonversion = 3
  704.         let g:loaded_python_provider = 0
  705.         let g:loaded_python3_provider = 0
  706.         "let g:python_host_skip_check=1
  707.         "let g:python3_host_skip_check=1
  708.     endfunction
  709. endif
  710.  
  711. let g:python_host_prog = '/usr/bin/python'
  712. let g:python3_host_prog = '/usr/bin/python3'
  713.  
  714. "" txt
  715. augroup vimrc-wrapping
  716.   autocmd!
  717.   autocmd BufRead,BufNewFile *.txt,*.md,*.tex call s:setupWrapping()
  718. augroup END
  719.  
  720. "" make/cmake
  721. augroup vimrc-make-cmake
  722.   autocmd!
  723.   autocmd FileType make setlocal noexpandtab
  724.   autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake
  725. augroup END
  726.  
  727. "augroup markdown
  728. ""    autocmd FileType markdown,vimwiki setlocal textwidth=78 formatprg=par\ -w78
  729. "     autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*} setlocal ft=markdown
  730. "augroup END
  731.  
  732. "augroup spellcheck_documentation
  733. "     autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*,txt} setlocal spell
  734. "    " Don't mark URL-like and acronyms things as spelling errors
  735. "    syn match UrlNoSpell "\v(https?|ftp):[^[:space:]]*" contains=@NoSpell
  736. "    syn match AcronymNoSpell '\v\u{2,}(\d+)?' contains=@NoSpell
  737. "    syn match myExCapitalWords '+\<[A-Z]\w*\>+' contains=@NoSpell
  738. "augroup END
  739.  
  740. " autoformat html files on opening or saving them
  741. " this function it called only if the filetype is html
  742. " and pandoc is present in the system
  743. "function! SetHtml()
  744. "    if executable('pandoc')
  745. "        let pandoc_pipeline  = "pandoc --from=html --to=markdown"
  746. "        let pandoc_pipeline .= " | pandoc --from=markdown --to=html"
  747. "        let &l:formatprg=pandoc_pipeline
  748. "    endif
  749. "endfunction
  750.  
  751. "" Set working directory
  752. nnoremap <Leader>. :lcd %:p:h<CR>
  753. " Change in next bracket
  754. nnoremap cinb cib
  755. nnoremap cinB ciB
  756. "" fzf.vim
  757. 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"
  758. " The Silver Searcher
  759. if executable('ag')
  760.    let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -g ""'
  761.    set grepprg=ag\ --nogroup\ --nocolor\ --ignore-case\ --column
  762.    set grepformat=%f:%l:%c:%m,%f:%l:%m
  763. endif
  764.  
  765. " nnoremap <silent> <Leader>b :Buffers<CR>
  766. nnoremap <silent> <Leader>h :History<cr>
  767. nnoremap <silent> <c-p> :FZF -m ~/.dotfiles<CR>
  768.  
  769. " " hide fzf statusline
  770. " if has('nvim') || has('gui_running')
  771. "     autocmd! FileType fzf
  772. "     autocmd  FileType fzf set laststatus=0 noshowmode noruler
  773. "     autocmd BufLeave <buffer> set laststatus=2 showmode ruler
  774. " endif
  775.  
  776. " Most recent used files
  777. command! FZFMru call fzf#run({
  778. \ 'source':  v:oldfiles,
  779. \ 'sink':    'e',
  780. \ 'options': '-m -x +s',
  781. \ 'down':    '40%'})
  782. nnoremap <leader>m :FZFMru<cr>
  783.  
  784. " Files command with preview window
  785. command! -bang -nargs=? -complete=dir Files
  786.  \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
  787.  
  788. nnoremap <leader>f :Files<CR>
  789.  
  790. " snippets
  791. let g:UltiSnipsExpandTrigger="<C-j>"
  792. let g:UltiSnipsJumpForwardTrigger="<C-j>"
  793. let g:UltiSnipsJumpBackwardTrigger="<C-k>"
  794. let g:UltiSnipsEditSplit="vertical"
  795. let g:UltiSnipsListSnippets="<C-Space>"
  796. " syntastic
  797. let g:syntastic_always_populate_loc_list=1
  798. let g:syntastic_error_symbol=''
  799. let g:syntastic_warning_symbol=''
  800. let g:syntastic_style_error_symbol = ''
  801. let g:syntastic_style_warning_symbol = ''
  802. let g:syntastic_auto_loc_list=1
  803. let g:syntastic_aggregate_errors = 1
  804.  
  805. " Tagbar
  806. "nnoremap <silent> <F4> :TagbarToggle<CR>
  807. "let g:tagbar_autofocus = 1
  808.  
  809. "" Vmap for maintain Visual Mode after shifting > and <
  810. vnoremap < <gv
  811. vnoremap > >gv
  812.  
  813. " Move lines
  814. vnoremap <silent><C-Up> :m-2<CR>gv
  815. nnoremap <silent><C-Up> <Esc>:m-2<CR>
  816. nnoremap <silent> <C-Down> <Esc>:m+<CR>
  817. inoremap <silent> <C-Down> <Esc>:m+<CR>a
  818. inoremap <silent> <C-Up> <Esc>:m-2<CR>a
  819. xnoremap <C-Up> :move '<-2<cr>gv
  820. xnoremap <C-Down> :move '>+<cr>gv
  821.  
  822. " delete current till the end of line
  823. inoremap <C-k> <C-o>C
  824. nnoremap <C-k> _D
  825.  
  826. " Interpret .md files, etc. as .markdown
  827. let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'}
  828.  
  829. " vimwiki/vimwiki
  830. let g:vimwiki_list = [{'path': '~/.dotfiles/nvim/wiki', 'syntax': 'markdown', 'ext': '.md'}]
  831.  
  832. "*:VimwikiSearch* /pattern/
  833. "*:VWS* /pattern/
  834. "    Search for /pattern/ in all files of current wiki.
  835. "    To display all matches use |:lopen| command.
  836. "    To display next match use |:lnext| command.
  837. "    To display previous match use |:lprevious| command.
  838. let g:vimwiki_table_mappings = 0
  839.  
  840. " Highlight redundant whitespace and tabs.
  841. " This has the advantage of not highlighting each space you type at
  842. " the end of the line, only when you open a file or leave insert
  843. " mode. Very neat."
  844. " http://vim.wikia.com/wiki/Highlight_unwanted_spaces
  845. "match ExtraWhitespace /\s\+$/
  846. highlight ExtraWhitespace ctermbg=red guibg=red
  847. match ExtraWhitespace /\s\+$/
  848.  
  849. augroup redundant-whitespaces
  850.    au!
  851.    autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
  852.    autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  853.    autocmd InsertLeave * match ExtraWhitespace /\s\+$/
  854.    autocmd BufWinLeave * call clearmatches()
  855.    "autocmd BufWinLeave <buffer> call clearmatches()
  856.    "autocmd BufWinLeave * call StripTrailingWhitespace()
  857.    " source: https://www.vi-improved.org/recommendations/
  858. augroup END
  859.  
  860. " there is a discussion here where I have commented:
  861. " https://vi.stackexchange.com/a/19353/7339
  862. " see more about range :h <line1>
  863. " command! -range=% Cls <line1>,<line2>call StripTrailingWhitespace()
  864. " if !exists('*StripTrailingWhitespace')
  865. "     function! StripTrailingWhitespace()
  866. "         if !&binary && &filetype != 'diff'
  867. "             call Preserve(":%s,\\s\\+$,,e")
  868. "         endif
  869. "     endfunction
  870. " endif
  871. "command! Cls call StripTrailingWhitespace()
  872. command! Cls :call Preserve(':%s/\v\s+$//e')
  873. cnoreabbrev cls Cls
  874. cnoreabbrev StripTrailingSpace Cls
  875. " com! StripTrailingSpace :call StripTrailingWhitespace()
  876. " cnoreabbrev cls StripTrailingSpace
  877.  
  878. " Align text by a chosen char
  879. " https://stackoverflow.com/questions/57093175/
  880. " :Align =
  881. " :8,$ Align =
  882. " if !exists('*AlignText')
  883. "     function! AlignText(param) range
  884. "         execute a:firstline . ',' . a:lastline . '!column -t -s' . a:param . ' -o' . a:param
  885. "     endfunction
  886. " endif
  887. " command! -range=% -nargs=1 Align <line1>,<line2>call AlignText(<q-args>)
  888.  
  889. " https://stackoverflow.com/questions/57093175/
  890. " https://vi.stackexchange.com/questions/2410/
  891. if !exists('*AlignText')
  892.    function! AlignText(...) range
  893.        if a:0 < 1
  894.            execute a:firstline . ',' . a:lastline . '!column -t'
  895.  
  896.        else
  897.            execute a:firstline . ',' . a:lastline . '!column -t -s' . a:1 . ' -o' . a:1
  898.        endif
  899.    endfunction
  900. endif
  901. command! -range=% -nargs=? Align <line1>,<line2>call AlignText(<f-args>)
  902.  
  903. augroup removetrailingspaces
  904.    au!
  905.    "au! BufwritePre *.md,*.py,*.sh,*.zsh,*.txt Preserve :%s/\v\s+$//e
  906.    au! BufwritePre *.md,*.py,*.sh,*.zsh,*.txt :call Preserve(':%s/\v\s+$//e')
  907. augroup END
  908.  
  909. command! -nargs=* Wrap set wrap linebreak nolist
  910. cnoreabbrev wrap set wrap
  911. cnoreabbrev nowrap set nowrap
  912.  
  913. " Make the 81st column stand out
  914. highlight ColorColumn ctermbg=magenta
  915. call matchadd('ColorColumn', '\%81v', 100)
  916. " Esta função insere um change log
  917. " se nelas não houver "Last Change" ele passa batido
  918. " ou seja não insere o cabeçalho
  919. " usr_41.txt
  920.  
  921. if !exists('*InsertChangeLog')
  922.    fun! InsertChangeLog() abort
  923.        let l:flag=0
  924.        for i in range(1,7)
  925.            if getline(i) !~ '.*Last Change.*'
  926.                let l:flag = l:flag + 1
  927.            endif
  928.        endfor
  929.        if l:flag >= 5
  930.            normal(1G)
  931.            call append(0, "Arquivo:")
  932.            call append(1, "Created: " . strftime("%Y %B %d hs %H:%M"))
  933.            call append(2, "Last Change: " . strftime("%b %d %Y hs %H:%M"))
  934.            call append(3, "autor: <+digite seu nome+>")
  935.            call append(4, "site: <+digite o endereço de seu site+>")
  936.            call append(5, "twitter: <+your twitter here+>")
  937.            call append(6, "email: <+seu email+>")
  938.            normal gg
  939.        endif
  940.    endfun
  941. endif
  942.  
  943. " This functions clears the last search from history
  944. if !exists('*UndoUndoSearch')
  945.    fun! UndoUndoSearch()
  946.        call histdel("search", -1)
  947.        let @/ = histget("search", -1)
  948.    endfun
  949. endif
  950.  
  951. if !exists('*ChangeHeader')
  952.    fun! ChangeHeader() abort
  953.        if line('$')>=7
  954.            call Preserve(':1,7s/Last \(Change\|Modified\):\s\+\zs.*/\=strftime("%b %d %Y %H:%M")/ei')
  955.        endif
  956.    endfun
  957. endif
  958.  
  959. command! -nargs=0 CH :call ChangeHeader()
  960. augroup change_header
  961.    au!
  962.    au! BufWritePre * :silent call ChangeHeader()
  963. augroup END
  964.  
  965. " jump to next place holder
  966. if !exists('*JumpToNextPlaceholder')
  967.    function! JumpToNextPlaceholder() abort
  968.        let old_query = getreg('/')
  969.        echo search("<+.\\++>")
  970.        exec "norm! c/+>/e\<CR>"
  971.        call setreg('/', old_query)
  972.    endfunction
  973. endif
  974.  
  975. nnoremap <Leader>p :keepjumps call JumpToNextPlaceholder()<CR>a
  976. inoremap <Leader>p <ESC>:keepjumps call JumpToNextPlaceholder()<CR>a
  977.  
  978. noremap <F12> <Esc>:syntax sync fromstart<CR>
  979. inoremap <F12> <C-o>:syntax sync fromstart<CR>
  980.  
  981. highlight ColorColumn ctermbg=magenta
  982. call matchadd('ColorColumn', '\%81v', 100)
  983.  
  984. " dos2unix ^M
  985. if !exists('*func_name')
  986.    fun! Dos2unixFunction() abort
  987.        "call Preserve('%s/ $//ge')
  988.        call Preserve(":%s/\x0D$//e")
  989.        set ff=unix
  990.        set bomb
  991.        set encoding=utf-8
  992.        set fileencoding=utf-8
  993.    endfun
  994. endif
  995. com! Dos2Unix :call Dos2unixFunction()
  996. cnoreabbrev dos2unix Dos2unix
  997. cnoreabbrev d2u Dos2Unix
  998. " one liner rename file
  999. " source: http://stackoverflow.com/questions/1205286/renaming-the-current-file-in-vim
  1000. command! -nargs=1 Rename try | saveas <args> | call delete(expand('#')) | bd # | endtry
  1001.  
  1002. " Utility function that save last search and cursor position
  1003. " http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
  1004. " video from vimcasts.org: http://vimcasts.org/episodes/tidying-whitespace
  1005. " using 'execute' command doesn't overwrite the last search pattern, so I
  1006. " don't need to store and restore it.
  1007. " preserve function
  1008. if !exists('*Preserve')
  1009.     function! Preserve(command)
  1010.         try
  1011.             let l:win_view = winsaveview()
  1012.              "silent! keepjumps keeppatterns execute a:command
  1013.             silent! execute 'keeppatterns keepjumps ' . a:command
  1014.         finally
  1015.             call winrestview(l:win_view)
  1016.         endtry
  1017.     endfunction
  1018. endif
  1019.  
  1020. command! -nargs=1 Keep call Preserve(<q-args>)
  1021. cnoreabbrev pre Keep
  1022.  
  1023. " remove consecutive blank lines
  1024. " see Preserve function definition
  1025. " another way to remove blank lines :g/^$/,/./-j
  1026. call Preserve(':g/^$/,/./-j')
  1027. if !exists('*DelBlankLines')
  1028.     fun! DelBlankLines() range
  1029.         if !&binary && &filetype != 'diff'
  1030.             call Preserve(':%s/\s\+$//e')
  1031.             call Preserve(':%s/^\n\{2,}/\r/ge')
  1032.         endif
  1033.     endfun
  1034. endif
  1035.  
  1036. command! -nargs=0 DelBlank :call DelBlankLines()
  1037. nnoremap <Leader>d :call DelBlankLines()<cr>
  1038.  
  1039. " Sudo to write
  1040. " cnoremap w!! w !sudo tee % >/dev/null
  1041. cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
  1042. command! SaveAsRoot w !sudo tee %
  1043. cnoreabbrev sudow SaveAsRoot
  1044.  
  1045. " bash/emacs keybindings
  1046. imap <C-a> <C-o>0
  1047. imap <C-e> <C-o>$
  1048. cnoremap <c-a> <home>
  1049. cnoremap <c-e> <end>
  1050.  
  1051. " " toggles hightlight search and list with Ctrl-l
  1052. " nnoremap <C-l> :let [&hls, &list] = [!&list, &hls+&list==1]<CR>
  1053. " inoremap <C-l> <C-o>:let [&hls, &list] = [!&list, &hls+&list==1]<CR>
  1054. " vnoremap <C-l> <ESC>:let [&hls, &list] = [!&list, &hls+&list==1]<CR> <bar> gv
  1055.  
  1056. nnoremap <c-l> <ESC>:set hls! hls?<cr><c-l>
  1057. inoremap <c-l> <C-o>:set hls! hls?<cr><c-l>
  1058. vnoremap <c-l> <ESC>:set hls! hls?<cr><c-l> <bar> gv
  1059.  
  1060. " undo inserting
  1061. " https://vi.stackexchange.com/a/15246/7339
  1062. let g=0
  1063. inoremap <expr> <C-_> "\<C-o>".(g == 0 ? ':undo' : ':redo'). "\<CR>"
  1064.  
  1065. " alternate between relative number, number and no number
  1066. set nu rnu
  1067. " toggles number and relative number with Ctrl-n
  1068. nnoremap <C-n> :let [&nu, &rnu] = [!&rnu, &nu+&rnu==1]<cr>
  1069.  
  1070. " a barra de espaços -- zR abre todos os folders
  1071. nnoremap <Leader><space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
  1072. " https://superuser.com/a/170026/45032
  1073. set foldlevelstart=99
  1074.  
  1075. nnoremap <space> /
  1076. " the below mapping conficts with ultisnis
  1077. "nnoremap <c-space> :
  1078.  
  1079. hi Folded ctermbg=black
  1080.  
  1081. let g:UltiSnipsSnippetsDir = expand("~/.dotfiles/nvim/snips/")
  1082. let g:UltiSnipsSnippetDirectories=["snips", "UltiSnips"]
  1083. map <Leader>u :UltiSnipsEdit<cr>
  1084. " Snippets variables
  1085. let g:snips_author='Sergio Araujo'
  1086. let g:snips_site='http://vivaotux.blogspot.com'
  1087. let g:snips_email='<voyeg3r ✉ gmail.com>'
  1088. let g:snips_github='https://github.com/voyeg3r'
  1089. let g:snips_twitter='@voyeg3r'
  1090. let g:UltiSnipsEditSplit="horizontal"
  1091.  
  1092. inoreabbrev fname <C-R>=expand("%:t")<CR>
  1093. inoreabbrev Fname <C-R>=expand("%:p")<CR>
  1094. inoreabbrev idate <C-R>=strftime("%b %d %Y %H:%M")<CR>
  1095. inoreabbrev hdate <C-R>=strftime("%Y %B %d")<CR>
  1096. "inoreabbrev -> →
  1097. inoreabbrev mymail <voyeg3r ✉ gmail.com>
  1098. inoreabbrev slas Sérgio Luiz Araújo Silva
  1099. inoreabbrev tuiter http://www.twitter.com/voyeg3r
  1100. inoreabbrev vivaotux http://vivaotux.blogspot.com
  1101. cnoreabbrev ag Ag
  1102.  
  1103. " Fot transparency on terminal it needs to be at the end of init.vim
  1104. " transparency on the background
  1105. hi Normal guibg=NONE ctermbg=NONE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement