" basic settings -------------------------------------------------------- {{{ " reworked for usage with Vim 8, True Colors (24 bits) and tmux set nocompatible set termguicolors " :se t_Co should give 256, otherwise uncomment: " se t_Co=256 " to enable true colors inside Byoby/Tmux let &t_8f = "\[38;2;%lu;%lu;%lum" let &t_8b = "\[48;2;%lu;%lu;%lum" set viminfo=%,!,'1000,:1000,n~/.vim/viminfo set tw=0 se noru autocmd InsertEnter * set timeoutlen=200 autocmd InsertLeave * set timeoutlen=1000 let g:netrw_altv=1 let g:netrw_preview=1 set virtualedit=all runtime! ftplugin/man.vim set mouse=a call pathogen#infect() filetype plugin indent on syntax enable " syntax on set encoding=utf-8 set scrolloff=3 set autoindent set number set showcmd set wrap set spell spelllang=en_us set nospell set wildmenu set relativenumber " same as :set backspace=indent,eol,start set backspace=2 set history=1000 " remember more commands and search history set undolevels=1000 " use many muchos levels of undo set wildignore=*.swp,*.bak,*.pyc,*.class set visualbell " don't beep " set nobackup " set noswapfile set listchars=tab:>-,trail:.,extends:#,nbsp:*,eol:$ " useful if * and + registers don't work properly " set clipboard=unnamedplus " set clipboard=unnamed set hlsearch incsearch set bg=dark colorscheme gruvbox let maplocalleader = "\\\\" let mapleader = "\\" augroup vimrcEx au! " restore-cursor, usr-05.txt autocmd BufReadPost * \ if line("'\"") >= 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif augroup END nnoremap z :call ExtremeFolding() function! ExtremeFolding() if &foldopen == 'all' set foldopen& set foldclose& else set foldopen=all set foldclose=all endif endfunction " statusline --- {{{ set laststatus=0 " always show statusbar set statusline=%-5.3n\ " buffer number set statusline+=%f\ " filename set statusline+=%h%m%r%w " status flags set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type set statusline+=%= " right align remainder " uncomment to add time and date to statusline (disabled because using byobu) " set statusline+=%{strftime(\"%l:%M:%S,\ %a\ %b\ %d,\ %Y,\ \ \ \ \ \ \")} set statusline+=0x%-8B " character value set statusline+=%-14(%l/%L,%P,%c%V%) " line, character " set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P " }}} " }}} " filetype settings --- {{{ " Vimscript file settings ---------------------- {{{ augroup filetype_vim autocmd! autocmd FileType vim setlocal foldmethod=marker softtabstop=2 shiftwidth=2 expandtab augroup END " }}} " Help file settings ---------------------- {{{ augroup filetype_help autocmd! autocmd FileType help setlocal iskeyword+=-,.,(,) augroup END " }}} " Python file settings ---------------------- {{{ augroup pythonaus " let python_highlight_all=1 autocmd! " TTM removed tabstop=4 autocmd BufNewFile,BufRead *.py set softtabstop=4 shiftwidth=4 textwidth=0 expandtab autoindent fileformat=unix autocmd BufNewFile,BufRead *.py nnoremap cd /\ autocmd BufNewFile,BufRead *.py nnoremap cD ?\ autocmd BufNewFile,BufRead *.py nnoremap cc /\ autocmd BufNewFile,BufRead *.py nnoremap cC ?\ " autocmd FileType python :iabbrev def def ():=return?()hxi " autocmd FileType python :iabbrev class class:__id = 0def __init__(self):__id_ = 0def ():return nnoremap R :call PythonShowRun() " validade this (from usr_05.txt): vnoremap _g y:exe "grep /" . escape(@", '\\/') . "/ *.py" augroup END function! PythonShowRun() let pout = system("python3 " . bufname("%") . " 2>&1") " Open a new split and set it up. vsplit __Python_output__ normal! ggdG setlocal buftype=nofile " Insert the bytecode. call append(0, split(pout, '\v\n')) endfunction " }}} " }}} " hacks ------------------------------------ {{{ " WWW navigation ------------------------------------ {{{ function! ViewHtmlText(url) if !empty(a:url) new setlocal buftype=nofile bufhidden=hide noswapfile let g:ttmurl=a:url execute 'r !elinks ' . a:url . ' -dump -dump-width ' . winwidth(0) 1d endif endfunction " Save and view text for current html file. nnoremap H :updatecall ViewHtmlText(expand('%:p')) " View text for visually selected url. vnoremap h y:call ViewHtmlText(@@) nnoremap h :call ViewHtmlText(@+) " View text for URL from clipboard. " On Linux, use @* for current selection or @+ for text in clipboard. " }}} " verbose vim usage for hacking ------------------------------------ {{{ " had to add "set nocp" to use "ToggleVerbose()" function when run in root " because of &verbose function! ToggleVerbose() if !&verbose set verbosefile=~/.vim/verbose.log set verbose=15 :vs ~/.vim/verbose.log :setlocal autoread else set verbose=0 set verbosefile= endif endfunction " nnoremap l :call ToggleVerbose() set verbosefile=~/.vim/verbose.log set verbose=0 nnoremap L :call ToggleVerbose() " }}} " persistent undo, make /.vim/undo dir ----- {{{ set undofile set undodir=$HOME/.vim/undo set undolevels=1000 set undoreload=10000 " }}} " quickfix toogle ----- {{{ " nnoremap i :call QuickfixToggle() let g:quickfix_is_open = 0 function! s:QuickfixToggle() if g:quickfix_is_open cclose let g:quickfix_is_open = 0 execute g:quickfix_return_to_window . "wincmd w" else let g:quickfix_return_to_window = winnr() copen let g:quickfix_is_open = 1 endif endfunction " }}} " }}} " notes for movements and usage : ------------------------------------------------- {{{ "" the general strategy is to choose invalid commands "" (e.g. operation1+operation2 or operation1+non-movement) "" and commands that don't doo anything (e.g. up+down) "" E.g. cl is the same as s "" 'escape keys are lame' "" good combinations giving movements already in better combinations "" are also registered. Ideally, any of such movements "" should perform something or echo 'Non used combination'. "" I should make option work for this to be really useful. "" and to try to keep navigation inside keyboard. E.g.: "" sdfghjkl toolkit **** " --> H, L, , , and do things that you almost never need " --> show buffers of clipboard and search " :echo @" . @/ """" put in .bashrc: " alias v='vim3 --servername mvimserver --remote-tab-silent' " }}} " mappings and abbrevs --- {{{ " leader mappings ---------------------- {{{ nnoremap " ea"hbi"lel vnoremap " `>a"` vnoremap ' `>a'` nnoremap a :exec "normal li".nr2char(getchar())."\e" nnoremap A :call InsertAfterAfter() nnoremap b :SexT nnoremap B :Sex nnoremap c : nnoremap C :call ListSessions() " nnoremap d :args ~/repos/percolation/**/*.py nnoremap d :call SaveSession() nnoremap D :call SaveNewSession() " assert latest is saved as a user practice nnoremap e :call LoadSession() nnoremap E :call InsertSession() " nnoremap r :set shiftround! " make the f mappings usable by using the paths correctly nnoremap f :term ++hidden ++close pdflatex % nnoremap F :term ++hidden ++open pdflatex % nnoremap g :source % nnoremap G :echo "BANANA" nnoremap i :exec "normal i".nr2char(getchar())."\e" nnoremap I :call InsertBeforeAfter() nnoremap f :set hlsearch! nnoremap j :s/=/ = /g nnoremap J :jumps nnoremap k :s/,/, /g nnoremap l :ls nnoremap L :set list! " :bn to choose file n nnoremap n :set number! nnoremap N :set relativenumber! nnoremap p :reg nnoremap P :vs ~/.vim/notes.md nnoremap q :q nnoremap r :we % "-> nnoremap R :call PythonShowRun() nnoremap s :mapclear :source $MYVIMRC nnoremap S :source $MYVIMRC nnoremap t :vs.T nnoremap T :vs. nnoremap w :w noremap x :execute getline('.') noremap X :execute getline('.') "-> nnoremap z :call ExtremeFolding() function! InsertBeforeAfter() let a = nr2char(getchar()) :exec "normal i".a."\e" :exec "normal lli".a."\e" endfunction function! InsertAfterAfter() let a = nr2char(getchar()) :exec "normal a".a."\e" :exec "normal lla".a."\e" endfunction function! SaveSession() if !exists("g:msession") :call ListSessions() let g:msession = input("Enter session name: ") endif execute 'mksession! ~/.vim/sessions/' . g:msession endfunction function! SaveNewSession() :call ListSessions() let g:msession = input("Enter session name: ") execute 'mksession! ~/.vim/sessions/' . g:msession endfunction function! LoadSession() :call ListSessions() let g:msession = input("Enter session name: ") execute 'only' execute 'tabonly' execute 'so ~/.vim/sessions/' . g:msession endfunction function! InsertSession() :call ListSessions() execute 'tabe' let g:msession = input("Enter session name: ") execute 'so ~/.vim/sessions/' . g:msession endfunction function! ListSessions() execute '!ls ~/.vim/sessions/' endfunction " }}} " localleader mappings ---------------------- {{{ hi CursorLine cterm=NONE ctermbg=235 hi CursorColumn cterm=NONE ctermbg=235 nnoremap ' :s/"/'/g nnoremap c :set cursorline! cursorcolumn! nnoremap b :execute 'rightbelow vs ' . bufname('#') nnoremap B :call ToggleStatusbar() nnoremap g :call ChangeBackground() " nnoremap h :tabe:h nnoremap h :call Help() nnoremap i :call ShowImg() " keymap= nnoremap k :se keymap=accents nnoremap l :set invhlsearch \| set hlsearch? "-> nnoremap L nnoremap p :setlocal spell! nnoremap s :e $MYVIMRC nnoremap S :tabe $MYVIMRC nnoremap t :args /home/r/repos/tokipona/**/*.py nnoremap T :call ToggleTabLine() nnoremap w :match Error /\v[ ]+$/ nnoremap W :match none function! ShowImg() exec "normal! viWy" silent exec '!eog -f ' getreg('0') exec 'colorscheme gruvbox' endfunction function! Help() let token = input('what? ') :tabe exec ':h ' . token execute "normal! \\" :q endfunction function! ChangeBackground() if &bg == 'dark' set bg=light else set bg=dark endif endfunction function! ToggleStatusbar() if &ls == 2 set ls=0 else set ls=2 endif endfunction function! ToggleTabLine() if &showtabline == 2 set showtabline=0 else set showtabline=2 endif endfunction " l and L are used for verbose " }}} " abbrev ---------------------- {{{ iabbrev clssa class iabbrev clas class iabbrev clss class iabbrev edf def iabbrev efd def iabbrev remail renato.fabbri@gmail.com iabbrev rwebsite http://openlinkedsocialdata.github.io iabbrev rsignature -- Renato Fabbri iabbrev pimp from percolation.rdf import NS, po, a, cimport percolation as P iabbrev pimp_ import percolation as Pimport social as Simport participation as Paimport gmane as Gimport music as Mimport visuals as V iabbrev pmain if __name__ == "__main__": " }}} " other mappings ---------------------- {{{ vnoremap . :norm . " nnoremap ; : " nnoremap : ; inoremap viW~i nnoremap nnoremap nnoremap nnoremap tnoremap tnoremap tnoremap tnoremap nnoremap za inoremap jj :w inoremap :w " inoremap kk " inoremap kj kyypi " inoremap jk jyyPi " inoremap fd " inoremap df " inoremakjp kj " nnoremap jk o " nnoremap kj O " nnoremap ge nnoremap gr gT tnoremap gr :tabp tnoremap gt :tabn " }}} " experimental mappings ---------------------- {{{ " for walking through wrapped lines: " nnoremap j gj " nnoremap j gj " nnoremap k gk " set autoread onoremap in( :normal! f(vi( onoremap iN( :normal! F)vi( onoremap in[ :normal! f[vi[ onoremap iN[ :normal! F]vi[ onoremap in{ :normal! f{vi{ onoremap iN{ :normal! F}vi{ " }}} " }}} " autocommands --- {{{ function! RotateRegisters() let @h=@j let @j=@k let @k=@l let @l=@. endfunction au InsertLeave * call RotateRegisters() autocmd CmdwinEnter * map q: autocmd CmdwinEnter * map input("")q: " }}} " Useful commands which I might need to recall: " C-A, C-X to add and subtract from number " check on usage of bracket commands in Python " start using tags seriously (and find that video from Bram) " i_C-R to paste register " i_C-NP to next-previous word completion " i_C-UTY " C-W_orR " Review the '`commands " g#* " ensure the autocommands are loaded only once or removed before being added again. " :runtime syntax/hitest.vim " :so $VIMRUNTIME/syntax/hitest.vim " :exec getline('.') " Y:@" " Highlighting notes ------------------ {{{ " " :echo synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") " should give you the highlighting group you need to change " to change the colors of the char in cursor position. " hi " will output the settings, which can be changed by appending to the same command " highlight, syntax and colorcheme " " " found in: " http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor " map :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> " trans<' " \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" " \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" " }}} " " Spell bad and other groups are bot being shown " " Make a mapping for saving current highlighting settings. Just redir " " :redir @a " :set all " :redir END " function! TabMessage(cmd) " use like :TabMessage highlight redir => message silent execute a:cmd redir END if empty(message) echoerr "no output" else " use "new" instead of "tabnew" below if you prefer split windows instead of tabs tabnew setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified silent put=message endif endfunction command! -nargs=+ -complete=command Tab call TabMessage() function! OutputSplitWindow(...) " this function output the result of the Ex command into a split scratch buffer let cmd = join(a:000, ' ') let temp_reg = @" redir @" silent! execute cmd redir END let output = copy(@") let @" = temp_reg if empty(output) echoerr "no output" else new setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted put! =output endif endfunction command! -nargs=+ -complete=command Split call OutputSplitWindow() function! HiFile() " run to hightlight the buffer with the highlight output " e.g. after :Split sy or :Split hi let i = 1 while i <= line("$") if strlen(getline(i)) > 0 && len(split(getline(i))) > 2 let w = split(getline(i))[0] exe "syn match " . w . " /\\(" . w . "\\s\\+\\)\\@<=xxx/" endif let i += 1 endwhile endfunction " :colo koehler " :highlight SpellBad term=reverse ctermbg=9 gui=undercurl guisp=Red guifg=blue guibg=yellow " :highlight Normal term=reverse ctermbg=9 gui=undercurl guisp=Red guifg=black guibg=red " https://en.wikipedia.org/wiki/Blood_red and http://rgb.to/color/2845/blood-red " """""""""""""""""""""""""""" " End of vimrc, last commands se verbose=2 let g:vimscript_vars = s: