Skip to content

Instantly share code, notes, and snippets.

@mfurquimdev
Last active May 25, 2021 16:12
Show Gist options
  • Select an option

  • Save mfurquimdev/3f3579c88253d7506c877f520aeac632 to your computer and use it in GitHub Desktop.

Select an option

Save mfurquimdev/3f3579c88253d7506c877f520aeac632 to your computer and use it in GitHub Desktop.
set nocompatible " be iMproved, required
filetype off " required
" Remove all autocmds
autocmd!
let $VIM='~/.vim/'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin stuff
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'arcticicestudio/nord-vim'
Plugin 'wesQ3/vim-windowswap'
Plugin 'mhinz/vim-signify'
Plugin 'drzel/vim-line-no-indicator'
Plugin 'tpope/vim-obsession'
Plugin 'scrooloose/nerdtree'
Plugin 'ctrlpvim/ctrlp.vim'
"Plugin 'mattn/emmet-vim'
"Plugin 'dense-analysis/ale'
Plugin 'sheerun/vim-polyglot'
"Plugin 'rhysd/git-messenger.vim'
"Plugin 'davidhalter/jedi-vim'
Plugin 'wakatime/vim-wakatime'
"Plugin 'mileszs/ack.vim'
"Plugin 'prabirshrestha/vim-lsp'
"Plugin 'mattn/vim-lsp-settings'
"Plugin 'prabirshrestha/asyncomplete.vim'
"Plugin 'prabirshrestha/asyncomplete-lsp.vim'
Plugin 'davidhalter/jedi'
Plugin 'davidhalter/jedi-vim'
Plugin 'tpope/vim-characterize'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
call vundle#end()
filetype plugin indent on
let g:nord_bold = 1
let g:nord_bold_vertical_split_line = 1
let g:nord_cursor_line_number_background = 1
let g:nord_italic = 1
let g:nord_italic_comments = 1
let g:nord_underline = 1
let g:nord_uniform_diff_background = 1
colorscheme nord
let g:user_emmet_leader_key=','
let g:ale_sign_error = '>'
let g:ale_sign_warning = '-'
" Write this in your vimrc file
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_insert_leave = 0
" You can disable this option too
" if you don't want linters to run on opening a file
let g:ale_lint_on_enter=0
let g:ale_python_pylint_options='--rcfile /home/mfkn/.vim/lint/pylintrc'
let g:ale_echo_msg_format='[%linter%] [%severity%] %code% %s'
let g:NERDTreeIgnore = ['^build$', '^venv$', '^__pycache__$', '^Session.vim$']
let g:jedi#popup_on_dot = 0
let g:jedi#show_call_signatures = "2"
let g:jedi#show_call_signatures_delay = 1250
let g:jedi#smart_auto_mappings = 1
let g:jedi#use_tag_stack = 1
let g:jedi#use_tabs_not_buffers = 0
"let g:jedi#use_splits_not_buffers = ""
"let g:jedi#use_splits_not_buffers = "winwidth"
" <= Plugin stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
set undodir=~/.vim/undodir
set directory=~/.vim/swpdir
" https://stackoverflow.com/questions/5700389/using-vims-persistent-undo
" Put plugins and dictionaries in this dir (also on Windows)
let vimDir = '$HOME/.vim'
let &runtimepath.=','.vimDir
" Keep undo history across sessions by storing it in a file
if has('persistent_undo')
let myUndoDir = expand(vimDir . '/undodir')
let mySwpDir = expand(vimDir . '/swpdir')
" Create dirs
call system('mkdir ' . vimDir)
call system('mkdir ' . myUndoDir)
call system('mkdir ' . mySwpDir)
let &undodir = myUndoDir
set undofile
endif
" <= Files, backups and undo
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type when creating new files
set ffs=unix,dos,mac
set t_Co=256
" Enable syntax highlighting
syntax enable
set background=dark
" how to change vim background color in hex code or rgb color code?
" https://vi.stackexchange.com/questions/9754/how-to-change-vim-background-color-in-hex-code-or-rgb-color-code
" for i in {0..255} ; do printf "\x1b[38;5;${i}mcolour${i} "; done
highlight clear CursorLine
highlight clear CursorColumn
"highlight CursorLine ctermfg=4
"highlight CursorColumn ctermbg=0
highlight CursorLine ctermbg=0
highlight CursorColumn ctermbg=0
"highlight CursorLineNR ctermbg=234
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au VimEnter,WinEnter,BufWinEnter * setlocal cursorcolumn
au WinLeave * setlocal nocursorline
au WinLeave * setlocal nocursorcolumn
augroup END
" <= Colors and Fonts
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Heads Up Display, and Status line
" Highlight current line
set cursorline
" Highligh current column
set cursorcolumn
" Do not add a bit extra margin to the left
set foldcolumn=0
set number
set norelativenumber
" Time, in milliseconds, to update signify symbols on the left
set updatetime=100
" When wrapping, use the space b/w realtive numbers
set cpoptions+=n
" Height of the command bar
set cmdheight=1
set showcmd
function! GitBranch()
return system("git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'")
" return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
"
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
function! CharUnderCursor()
let l:char = matchstr(getline('.'), '\%' . col('.') . 'c.')
let l:dec = char2nr(l:char)
let l:hex = printf('%x', l:dec)
return l:dec.' #'.l:hex.' ['.l:char.']'
endfunction
" Always show the status line
set laststatus=2
" Format the status line
set statusline=
set statusline+=%#StatusLineNC#%*
"set statusline+=%{StatuslineGit()}
" Relative position in file (not as percent, but a sliding bar
set statusline+=\ %{LineNoIndicator()}
" Read only flag
set statusline+=\ %r
set statusline+=%#StatusLineNC#%*
set statusline+=%{&buftype!='terminal'?expand('%:p:h:h:t').'\/'.expand('%:p:h:t').'\/'.expand('%:t'):expand('%')} " dir/dir/filename.ext
" Modified flag
set statusline+=\ %m
" Fill horizontal space
set statusline+=%=
" Formatoptions
set statusline+=[%{&fo}]
" Tracking session flag
set statusline+=\ %{ObsessionStatus()}
" Character under cursor
set statusline+=\ %{CharUnderCursor()}
" Current line and column
set statusline+=\ %l:%c
" <= Heads Up Display, and Status line
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Movement and navigation
" Up is actually go one line up
nnoremap k gk
nnoremap j gj
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Disable mouse
" https://vi.stackexchange.com/questions/13566/fully-disable-mouse-in-console-vim
set mouse=
set ttymouse=
map <C-n> :NERDTreeToggle<CR>
" <= Movement and navigation
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => User Experience
" With a map leader it's possible to do extra key combinations
let mapleader = ","
" Do not Linebreak on any number of characters
set lbr
set tw=0
" noWrap lines
set nowrap
set showbreak=↪
" :help fo-table
" Do not auto-wrap text using textwidth
set fo-=t
" Do not auto-wrap comments using textwidth
set fo-=c
" Automatically insert the current comment leader after hitting <Enter> in Insert mode AND 'o' or 'O' in Normal mode
set fo+=ro
" Ignore case when searching
set ignorecase
" When searching, if using uppercase, do not ignorecase
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set matchtime=2
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Set 6 lines to the cursor - when moving vertically using j/k
set so=6
" Enabling this will make the tab key (in insert mode) insert spaces or tabs to go to the next indent of the next tabstop when the cursor is at the beginning of a line (i.e. the only preceding characters are whitespace)
set smarttab
" 1 tab == 4 spaces
set tabstop=4
set shiftwidth=4
" Use spaces instead of tabs
set expandtab
" Auto indent
set autoindent
" Smart indent
set smartindent
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>
" https://stackoverflow.com/questions/12814647/showing-single-space-invisible-character-in-vim
set list
" ⸱ U+2E31 WORD SEPARATOR MIDDLE DOT
" ╴ U+2574 BOX DRAWINGS LIGHT LEFT
set listchars=tab:╴\ ,space:⸱
highlight clear Tabs
highlight clear Whitespace
highlight clear TrailingWhitespace
highlight Tabs ctermfg=0
highlight Whitespace ctermfg=0
highlight TrailingWhitespace ctermbg=0 ctermfg=1
match Tabs /\t/
match Whitespace /\s/
match TrailingWhitespace /\s\+$/
" :WW sudo saves the file
" (useful for handling the permission-denied error)
cnoremap WW w !sudo tee % > /dev/null<cr>
" Return to last edit position when opening files (You want this!)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
map <silent> <leader><cr> :noh<cr>
function! s:MakeRun()
let logjob = job_start('make', {'in_io': "null", 'out_io': "null", 'err_io': "null"})
" let logjob = job_start('make', {'out_io': 'buffer', 'out_name': 'makelog'})
" vsplit | buffer makelog
endfunction
autocmd BufWritePost *.tex call s:MakeRun()
autocmd BufWritePost *.cls call s:MakeRun()
"function! <SID>StripTrailingWhitespaces()
" let save_cursor = getpos(".")
" %s/\s\+$//e
" call setpos('.', save_cursor)
"endfun
"
"autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
" https://stackoverflow.com/a/38669419/3832827
vnoremap <silent> ;/ :call ToggleComment()<cr>
function! ToggleComment()
if matchstr(getline(line(".")),'^\s*#.*$') == ''
:execute "s:^:#:"
else
:execute "s:^\s*#::"
endif
endfunction
"function! ToggleComment()
" if matchstr(getline(line(".")),'^\s*\/\/.*$') == ''
" :execute "s:^://:"
" else
" :execute "s:^\s*//::"
" endif
"endfunction
"set mouse=a
"set ttymouse=xterm2
"nnoremap <LeftMouse> :set invnumber list!<cr>v
"vnoremap <LeftMouse> <esc>:set invnumber list!<cr>
nnoremap <C-c> :set invnumber list!<cr>:SignifyToggle<cr>
" <= User Experience
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Show the syntax highlight group under cursor
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
set lazyredraw " Do not redraw the screen while
" executing macros, registers
" and other commands that have
" not been typed
" https://www.reddit.com/r/vim/comments/96rd39/a_mapping_i_came_up_to_remove_surrounding/
"nnoremap <leader>d j<i{k$%dd<c-o>dd
"" Sets how many lines of history VIM has to remember
"set history=500
" Disable mouse scrollwheel
" https://stackoverflow.com/questions/24684483/completely-disable-mouse-in-console-vim
"map <Esc>Oa <Nop>
"map <Esc>Ob <Nop>
"map <Esc>[1;2a <Nop>
"map <Esc>[1;2b <Nop>
"map! <Esc>Oa <Nop>
"map! <Esc>Ob <Nop>
"map! <Esc>[1;2a <Nop>
"map! <Esc>[1;2b <Nop>
"
"" Set to auto read when a file is changed from the outside
"set autoread
"
"" With a map leader it's possible to do extra key combinations
"" like <leader>w saves the current file
"let mapleader = ","
"
"" :WW sudo saves the file
"" (useful for handling the permission-denied error)
"cnoremap WW w !sudo tee % > /dev/null<cr>
"
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => VIM user interface
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Ignore compiled files
"set wildignore=*.o,*~,*.pyc
"set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
"
"" A buffer becomes hidden when it is abandoned
"set hid
"
"
"
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => Text, tab and indent related
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" This will trigger a set nowrap on a window you enter and a set wrap on a window you leave
"" https://stackoverflow.com/questions/13386295/how-to-activate-word-wrap-on-all-unfocused-windows-in-vim
""autocmd BufEnter * set wrap
""autocmd BufLeave * set nowrap
"
"" how to change vim background color in hex code or rgb color code?
"" https://vi.stackexchange.com/questions/9754/how-to-change-vim-background-color-in-hex-code-or-rgb-color-code
"" for i in {0..255} ; do printf "\x1b[38;5;${i}mcolour${i} "; done
"highlight CursorLine ctermbg=234
"highlight CursorLineNR ctermbg=234
"augroup CursorLine
" au!
" au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
" au WinLeave * setlocal nocursorline
"augroup END
"
"" This will highlight all characters past 175 columns
"" http://blog.ezyang.com/2010/03/vim-textwidth/
"augroup vimrc_autocmds
" "autocmd BufEnter * highlight OverLength ctermbg=237
" autocmd BufEnter * highlight OverLength cterm=bold
" autocmd BufEnter * match OverLength /\%175v.*/
"augroup END
"
"
"" https://vim.fandom.com/wiki/Highlight_current_word_to_find_cursor
""nnoremap <C-K> :call HighlightNearCursor()<CR>
""function HighlightNearCursor()
"" if !exists("s:highlightcursor")
"" match Todo /\k*\%#\k*/
"" let s:highlightcursor=1
"" else
"" match None
"" unlet s:highlightcursor
"" endif
""endfunction
"
""https://stackoverflow.com/questions/1919028/how-to-show-vertical-line-to-wrap-the-line-in-vim
""nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
""highlight OverLength ctermbg=none cterm=none
""match OverLength /\%>175v/
""fun! s:LongLineHLToggle()
"" if !exists('w:longlinehl')
"" autocmd BufEnter * highlight OverLength cterm=underline
"" let w:longlinehl = matchadd('OverLength', '.\%>175v', 0)
"" echo "Long lines highlighted"
"" else
"" call matchdelete(w:longlinehl)
"" unl w:longlinehl
"" echo "Long lines unhighlighted"
"" endif
""endfunction
"
"" https://stackoverflow.com/questions/8450919/how-can-i-delete-all-hidden-buffersc
""function! DeleteHiddenBuffers()
"" let tpbl=[]
"" let closed = 0
"" call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
"" for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
"" if getbufvar(buf, '&mod') == 0
"" silent execute 'bwipeout' buf
"" let closed += 1
"" endif
"" endfor
"" echo "Closed ".closed." hidden buffers"
""endfunction
"
"" Code folds are saved and restored:
"" https://www.freecodecamp.org/news/learn-linux-vim-basic-features-19134461ab85/#9b6b
"autocmd BufWinLeave *.* mkview
"autocmd BufWinEnter *.* silent loadview
"
"" Fold at matching braces
"nnoremap <leader>f /{<CR>mf%zf'f:noh<cr>
"
"" Indent correctly at inner object of braces
"nnoremap <leader>i =i{
"
"" F8 para indentar todo o codigo
"noremap <F8> mzgg=G'z
"
"""""""""""""""""""""""""""""""
"" => Visual mode related
"""""""""""""""""""""""""""""""
"" Visual mode pressing * or # searches for the current selection
"" Super useful! From an idea by Michael Naumann
""vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
""vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
"
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => Moving around, tabs, windows and buffers
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
"map <space> /
"map <c-space> ?
"
"" Disable highlight when <leader><cr> is pressed
"map <silent> <leader><cr> :noh<cr>:redraw!<cr>:syntax sync fromstart<cr>
"
"nnoremap <C-d> <C-d>
"
"" Open new split panes to right and bottom, which feels more natural than Vim’s default:
"set splitbelow
"set splitright
"
"" Close all the buffers
"map <leader>ba :bufdo bd<cr>
"
"map <leader>l :bnext<cr>
"map <leader>h :bprevious<cr>
"
"" Useful mappings for managing tabs
"map <leader>tn :tabnew<cr>
"map <leader>to :tabonly<cr>
"map <leader>tc :tabclose<cr>
"map <leader>tm :tabmove
"map <leader>t<leader> :tabnext
"
"" Let 'tl' toggle between this and the last accessed tab
"let g:lasttab = 1
"nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
"au TabLeave * let g:lasttab = tabpagenr()
"
"
"" Opens a new tab with the current buffer's path
"" Super useful when editing files in the same directory
"map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
"
"" Switch CWD to the directory of the open buffer
"map <leader>cd :cd %:p:h<cr>:pwd<cr>
"
"" Specify the behavior when switching between buffers
"try
" set switchbuf=useopen,usetab,newtab
" set stal=2
"catch
"endtry
"
"
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => Editing mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Remap VIM 0 to first non-blank character
""map 0 ^
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Remove the Windows ^M - when the encodings gets messed up
"noremap <Leader>mw mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
"
"" Quickly open a buffer for scribble
"map <leader>q :e ~/buffer<cr>
"
"" Quickly open a markdown buffer for scribble
"map <leader>x :e ~/buffer.md<cr>
"
"" Toggle paste mode on and off
"map <leader>pp :setlocal paste!<cr>
"
"map <C-n> :NERDTreeToggle<CR>
"
"
"" VIMRC de FELIPE JALES
""
"set cinoptions=g0,:s,b1,=0,(0,0{,is " opcoes de indentacao... ':help cinoptions'
"set title
"
"" incluindo path do projeto nas tags
"set tags=./tags,./TAGS,tags,TAGS,~/projetos/tags,~/projetos/TAGS
"
"" Copia e cola entre instâncias diferentes do vim sem usar o clipboard do " S.O.,
"" além disso evitando problemas com a autoidentação ao colar
"vmap <silent> ,y y:sp! ~/.vim/clipboard<CR>eggdG"0p:x!<CR>
"nmap <silent> ,y :new<CR>:call setline(1,getregtype())<CR>o<Esc>P:wq! ~/.vim/clipboard<CR>
"map <silent> ,p :r ~/.vim/clipboard<CR>
"
"
""""""
"" Funcao grep melhorada
"
"let &path = getcwd() . '/**'
"
"function! Grep(args)
" let l:lista = split(a:args)
" if len(l:lista) == 3
" let l:_arg = l:lista[0]
" let l:_name = substitute(l:lista[1], "\\s", "*", "g")
" let l:_path = simplify(l:lista[2])
" elseif len(l:lista) == 2
" let l:_arg = "-RIn"
" let l:_name = substitute(l:lista[0], "\\s", "*", "g")
" let l:_path = simplify(l:lista[1])
" elseif len(l:lista) == 1
" let l:_arg = "-RIn"
" let l:_name = substitute(l:lista[0], "\\s", "*", "g")
" let l:_path = "."
" else
" echo "Invalid Arguments!"
" return
" endif
"
" let l:string = "grep " . l:_arg . " " . l:_name . " " . l:_path . " |grep -v /.dep/ |grep -v /.cross-dep/ |grep -v /.ppc-dep/ |grep -v /.arm-dep/ |grep -v /doc/ 2>/dev/null"
" let l:list = system(l:string)
" let l:num = strlen(substitute(l:list, "[^\n]", "", "g"))
"
" if l:num < 1
" echo "Not Found"
" return
" endif
"
" let l:count = 0
"
" let l:_listNum = split(l:list, "\n")
" let l:_list = split(l:list, "\n")
" for line in l:_list
" echo l:count + 1 . " " . l:line
" let l:_listNum[l:count] = strpart(l:_list[l:count], stridx(l:_list[l:count], ":") + 1)
" let l:_listNum[l:count] = strpart(l:_listNum[l:count], 0, stridx(l:_listNum[l:count], ":"))
" let l:_list[l:count] = strpart(l:_list[l:count], 0, stridx(l:_list[l:count], ":"))
" let l:count += 1
" endfor
"
" let l:input = input("Which ? (<enter>=nenhum)\n")
"
" if strlen(substitute(l:input, "[0-9]", "", "g"))>0
" echo "Not a number"
" return
" endif
"
" if strlen(l:input)==0
" return
" endif
"
" execute ":vsplit". "+" . l:_listNum[l:input - 1] . " " . l:_list[l:input - 1]
"endfunction
"command! -nargs=1 Grep :call Grep("<args>")
"
"map <C-g> :Grep
"
"""Spell to git commits
""set spelllang=pt
""au FileType gitcommit set spell
"
"
""au BufRead,BufNewFile * let b:timelyRedrawn = localtime()
"
"au! CursorHold
""au CursorHold * call UpdateTimely()
""
""let g:redraw_time = 20
""
""function! UpdateTimely()
"" if((localtime() - b:timelyRedrawn) >= g:redraw_time)
"" redraw!
"" syntax sync fromstart
"" let b:timelyRedrawn = localtime()
"" endif
"" echo strftime("%a, %b %d - %H:%M:%S")
""endfunction
""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment