Skip to content

Instantly share code, notes, and snippets.

@EleDiaz
Created March 2, 2019 11:12
Show Gist options
  • Select an option

  • Save EleDiaz/3a4391ec1c26234676959869c9df7b15 to your computer and use it in GitHub Desktop.

Select an option

Save EleDiaz/3a4391ec1c26234676959869c9df7b15 to your computer and use it in GitHub Desktop.
" vim:foldmethod=marker
""
"" init.vim -- Configuration
""
if &compatible
set nocompatible
endif
" {{{ Plugins
call plug#begin('~/.config/nvim/plugged')
"{{{ Plugin Utils
Plug 'lambdalisue/suda.vim'
" Close buffers without close vim
" Plug 'moll/vim-bbye'
Plug 'rbgrouleff/bclose.vim'
" A right undo redo for editing
Plug 'mbbill/undotree'
" Fast selection of things, dirs, buffers, commands
Plug 'Shougo/denite.nvim'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" A improved start screen for vim
Plug 'mhinz/vim-startify'
Plug 'tpope/vim-surround'
" Plug 'hecal3/vim-leader-guide'
Plug 'janko-m/vim-test' " No support for haskell
Plug 'tpope/vim-eunuch'
Plug 'majutsushi/tagbar'
Plug 'scrooloose/nerdtree'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'jiangmiao/auto-pairs'
" Plug 'neomake/neomake'
" Plug 'vim-syntastic/syntastic'
Plug 'w0rp/ale'
Plug 'terryma/vim-multiple-cursors'
Plug 'easymotion/vim-easymotion'
Plug 'sbdchd/neoformat'
"}}}
" {{{ Personalization
" {{{ Themes
Plug 'mkarmona/materialbox'
Plug 'ajmwagar/vim-deus'
Plug 'challenger-deep-theme/vim'
Plug 'chriskempson/base16-vim'
Plug 'NLKNguyen/papercolor-theme'
Plug 'altercation/vim-colors-solarized'
" }}}
Plug 'osyo-manga/vim-over' " Visual Replace
Plug 'itchyny/vim-cursorword'
Plug 'kshenoy/vim-signature'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"Plug 'airblade/vim-gitgutter'
" Shows lines to align with same indentation
" Plug 'Yggdroot/indentLine'
" Plug 'nathanaelkane/vim-indent-guides'
Plug 'junegunn/rainbow_parentheses.vim'
"Plug 'ap/vim-css-color'
Plug 'chrisbra/Colorizer'
Plug 'ryanoasis/vim-devicons' " Last to change icons over other plugins
" }}}
"{{{ Language Plugins
"
Plug 'vim-pandoc/vim-pandoc-syntax'
Plug 'vim-pandoc/vim-pandoc'
"" Haskell Bundle
"Plug 'itchyny/vim-haskell-indent', { 'for': 'haskell'}
"Plug 'parsonsmatt/intero-neovim', { 'for': 'haskell'}
" Plug 'ndmitchell/ghcid', { 'rtp': 'plugins/nvim' }
Plug 'neovimhaskell/haskell-vim', { 'for': 'haskell' }
" Plug 'eagletmt/ghcmod-vim', { 'for': 'haskell' }
" Plug 'eagletmt/neco-ghc', { 'for': 'haskell' }
"Plug 'Twinside/vim-hoogle', { 'for': 'haskell' }
"Plug 'mpickering/hlint-refactor-vim', { 'for': 'haskell' }
"" Python Bundle
Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }
"" Ruby
Plug 'vim-ruby/vim-ruby', { 'for': 'ruby' }
Plug 'tbastos/vim-lua', { 'for': 'lua' }
"" Rust bundle
Plug 'rust-lang/rust.vim'
Plug 'rhysd/vim-rustpeg'
"" Debug
Plug 'dbgx/lldb.nvim'
"" Shells things
Plug 'dag/vim-fish'
"" LSP
" Plug 'autozimu/LanguageClient-neovim', {
" \ 'branch': 'next',
" \ 'do': 'bash install.sh',
" \ }
" Plug 'neoclide/coc.nvim', {'tag': '*', 'do': { -> coc#util#install()}}
"" C++
Plug 'octol/vim-cpp-enhanced-highlight'
" Plug 'zchee/deoplete-clang'
" Plug 'JBakamovic/cxxd-vim'
"" Others languages common
Plug 'vhdirk/vim-cmake'
Plug 'peterhoeg/vim-qml'
Plug 'cespare/vim-toml'
Plug 'digitaltoad/vim-pug'
Plug 'lervag/vimtex'
""" Custom Plugins
Plug '~/Projects/letter-plugin'
"}}}
call plug#end()
if exists('g:GtkGuiLoaded')
call rpcnotify(1, 'Gui', 'Font', 'Fira Code 14')
call rpcnotify(1, 'Gui', 'Option', 'Cmdline', 0)
command! NGToggleSidebar call rpcnotify(1, 'Gui', 'Command', 'ToggleSidebar')
command! -nargs=+ NGTransparency call rpcnotify(1, 'Gui', 'Command', 'Transparency', <f-args>)
command! -nargs=1 NGPreferDarkTheme call rpcnotify(1, 'Gui', 'Command', 'PreferDarkTheme', <q-args>)
endif
"
" }}}
" Basic Setup{{{
" Required:
syntax on
filetype on
filetype plugin indent on
" Encoding
"set encoding=utf-8 " Give a error on :source %
set fileencoding=utf-8
set fileencodings=utf-8
"" Fix backspace indent
set backspace=indent,eol,start
"" Spaces. May be overriten by autocmd rules
set tabstop=4
set softtabstop=0
set expandtab
set shiftwidth=4
set smarttab
"" Map leader to ' '
let mapleader="\<Space>"
"" Enable hidden buffers
set hidden
"" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
"" Encoding
" set bomb " dangerous
set binary
"" Directories for swp files
" set nobackup
" set noswapfile
set directory^=$HOME/.vim/tmp//
set fileformats=unix,dos,mac
set showcmd
set shell=/usr/bin/fish
set foldmethod=indent
set foldlevel=0
"let anyfold_activate=1
" Allow specific configuration by file
set modeline
set modelines=5
"" Copy/Paste/Cut
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
if has("persistent_undo")
set undodir=~/.undodir/
set undofile
endif
"}}}
" Visual Settings{{{
set ruler
" set number
" set relativenumber
set showtabline=0
" normal move with cursors in end and start of line
set whichwrap+=<,>,h,l,[,]
" NOTE To Future: Don't set guifg it remove colors in current line
" dark
" autocmd BufEnter * highlight CursorLine guibg=#250025
" autocmd InsertEnter * highlight CursorLine guibg=#002300
" autocmd InsertLeave * highlight CursorLine guibg=#250025
" " Light
" autocmd BufEnter * highlight CursorLine guibg=#e3c6f7
" autocmd InsertEnter * highlight CursorLine guibg=#a8ffd5
" autocmd InsertLeave * highlight CursorLine guibg=#080808
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
" Transparent background
" NOTE If Problems: au ColorScheme * hi NonText ctermbg=none guibg=none
" au ColorScheme * hi Normal ctermbg=none guibg=none
" au ColorScheme * hi NonText ctermbg=none guibg=none
" Disable visualbell
set visualbell t_vb=
set termguicolors
set mousemodel=popup
set t_Co=256
set guioptions=egmrti
set mouse=a
if &term =~ '256color'
set t_ut=
endif
"\ 'color00': ['none'],
let g:PaperColor_Theme_Options = {
\ 'theme': {
\ 'default.light': {
\ 'transparent_background': 0,
\ 'override' : {
\ 'linenumber_bg' : ['#eededa']
\ }
\ },
\ 'default.dark': {
\ 'transparent_background': 0,
\ 'override' : {
\ 'linenumber_bg' : ['#000000', '232']
\ }
\ }
\ }
\ }
" \ 'transparent_background': 1,
" \ 'statusline_active_fg': ['#080808', ''],
" \ 'statusline_active_bg': ['#080808', ''],
" \ 'statusline_inactive_fg': ['#080808', ''],
" \ 'statusline_inactive_bg': ['#080808', ''],
colorscheme PaperColor
set background=light
"let base16colorspace=256 " Access colors present in 256 colorspace
" colorscheme base16-default-dark
" colorscheme base16-irblack
" colorscheme base16-oceanicnext
"" Let change cursor shape to ibeam or block depends of mode
"let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
" Scroll offset
set scrolloff=5
"" Status bar
set laststatus=2
set title
auto SessionLoadPost * let &titlestring = "Neovim " . fnamemodify(v:this_session, ':t:r')
set completeopt-=preview
"}}}
" Terminal{{{
au TermOpen * setlocal nonumber norelativenumber
" Terminal easy exit
tnoremap <C-q> <C-\><C-n>
"tnoremap <leader><Esc> <C-\><C-n>
" }}}
"{{{ AutoCmd Rules
"
" TODO: Just highlight code, avoid tagbar, terminal, nerdtree
" augroup BgHighlight
" autocmd!
" autocmd WinEnter * set number
" autocmd WinLeave * set nonumber
" augroup END
" Set augroup
augroup MyAutoCmd
autocmd!
autocmd CursorHold *? syntax sync minlines=300
augroup END
"" The PC is fast enough, do syntax highlight syncing from start
augroup vimrc-sync-fromstart
autocmd!
autocmd BufEnter * :syntax sync fromstart
augroup END
"" Remember cursor position
augroup vimrc-remember-cursor-position
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END
"" make/cmake
augroup vimrc-make-cmake
autocmd!
autocmd FileType make setlocal noexpandtab
autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake
augroup END
"}}}
"{{{ Startify
" session management
let g:session_directory = "~/.config/nvim/session"
let g:session_autoload = "no"
let g:session_autosave = "no"
let g:session_command_aliases = 1
let g:startify_bookmarks =
\ [ {'v': '~/.config/nvim/init.vim'}
\ , {'f': '~/.config/fish/config.fish'}
\ , {'n': '~/notes.md'}
\ , {'x': '~/.xmonad/xmonad.hs'}
\ , {'t': '~/.tmux.conf'}
\ , {'a': '~/.config/alacritty/alacritty.yml'}
\ , {'l': '~/.config/lang/lang.yaml'}
\ ]
" \ , {'k': '~/.config/kitty/kitty.conf'}
"\ [' Recently Used Files'],
"\ 'files',
let g:startify_list_order = [
\ [' Sessions'],
\ 'sessions',
\ [' Bookmarks'],
\ 'bookmarks',
\ [' Commands'],
\ 'commands',
\ ]
autocmd User Startified setlocal cursorline
let g:startify_fortune_use_unicode = 1
let g:startify_enable_special = 0
function! s:filter_header(lines) abort
let longest_line = max(map(copy(a:lines), 'strwidth(v:val)'))
let centered_lines = map(copy(a:lines),
\ 'repeat(" ", (&columns / 2) - (longest_line / 2)) . v:val')
return centered_lines
endfunction
let g:ascii = [
\ '',
\ ' | 1 | 2 3 | 4 5 6 7 | 8 9 10 11 12 13 14 15 |',
\ ' ø 1 1 2 2 3 3 4 4 5 5 6 6 7 7',
\ '',
\ ' |1|',
\ ' |2| |3|',
\ ' |4| |5| |6| |7|',
\ '',
\ ' * Naming: Nomen est omen',
\ ''
\]
let g:startify_custom_header = g:ascii
let g:startify_session_dir = '~/.config/nvim/session'"}}}
" Other {{{
let g:deoplete#sources#clang#libclang_path = "/usr/lib/libclang.so"
let g:deoplete#sources#clang#clang_header = "/usr/lib/clang"
let g:ale_fixers = {
\ 'c': ['cppcheck'],
\ 'cpp': ['cppcheck'],
\ 'rust': ['rls', 'cargo'],
\}
" let g:indent_guides_enable_on_vim_startup = 1
" let g:indent_guides_start_level = 2
" let g:indent_guides_exclude_filetypes = ['help', 'nerdtree', 'startify', 'rust', 'haskell']
" }}}
" Utils{{{
function! TextEnableCodeSnip(filetype,start,end,textSnipHl) abort
let ft=toupper(a:filetype)
let group='textGroup'.ft
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
" Remove current syntax definition, as some syntax files (e.g. cpp.vim)
" do nothing if b:current_syntax is defined.
unlet b:current_syntax
endif
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
try
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch
endtry
if exists('s:current_syntax')
let b:current_syntax=s:current_syntax
else
unlet b:current_syntax
endif
execute 'syntax region textSnip'.ft.'
\ matchgroup='.a:textSnipHl.'
\ start="'.a:start.'" end="'.a:end.'"
\ contains=@'.group
endfunction
"}}}
" Ale{{{
" function! GetHaskellProjectRoot(buffer) abort
" let l:stack_file = ale#path#FindNearestFile(a:buffer, 'package.yaml')
" return !empty(l:stack_file) ? fnamemodify(l:stack_file, ':h') : ''
" endfunction
" call ale#linter#Define('haskell', {
" \ 'name': 'hie',
" \ 'lsp': 'stdio',
" \ 'executable': 'hie',
" \ 'command': 'hie-wrapper --lsp',
" \ 'project_root_callback': 'GetHaskellProjectRoot',
" \ 'language': 'haskell',
" \})
" let g:ale_linters = {'haskell': []}
" " let g:ale_linters = {'haskell': ['hie']}
" " ['hie', 'brittany', 'stack-ghc', 'stack-build', 'stack-ghc-mod', 'hlint', 'hdevtools', 'hfmt']}
" highlight clear ALEWarning
" let g:ale_sign_error = ''
" let g:ale_sign_warning = ''
let g:airline#extensions#ale#error_symbol = ''
let g:airline#extensions#ale#warning_symbol = ''"}}}
"{{{ Haskell
" Show types in completion suggestions
let g:necoghc_enable_detailed_browse = 1
let g:haskell_indent_disable = 1
"let g:haskell_classic_highlighting = 0
let g:haskell_enable_quantification = 1 " to enable highlighting of `forall`
let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec`
let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc`
let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern`
let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles
let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static`
let g:haskell_backpack = 1 " to enable highlighting of backpack keywords
" Resolve ghcmod base directory
" au FileType haskell let g:ghcmod_use_basedir = getcwd()
augroup haskell
autocmd!
set expandtab
set tabstop=2
set softtabstop=0
set shiftwidth=2
set smarttab
" set formatprg=stylish-haskell
autocmd BufWritePre * %s/\s\+$//e
"call TextEnableCodeSnip('sql', '\[sql|', '\]', 'SpecialComment')
"autocmd! BufWritePost,BufEnter *.hs GhcModCheckAsync
autocmd BufWritePre *.hs Neoformat
"autocmd FileType haskell map <silent> <leader><cr> :noh<cr>:GhcModTypeClear<cr>
"autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
"
" set foldmethod=expr
augroup END
"}}}
" Rust {{{
let g:cm_auto_popup = 0
let g:deoplete#sources#rust#racer_binary='/home/eleazardd/.cargo/bin/racer'
let g:deoplete#sources#rust#rust_source_path='/home/eleazardd/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src'
let g:rustfmt_autosave = 1
let g:ale_rust_cargo_use_check = 0
augroup rust
autocmd!
set foldmethod=syntax
augroup END
" }}}
" Python{{{
augroup vimrc-python
autocmd!
autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=8 colorcolumn=79
\ formatoptions+=croq softtabstop=4 smartindent
\ cinwords=if,elif,else,for,while,try,except,finally,def,class,with
augroup END
let g:pymode_lint_cwindow = 0
"}}}
" Vim-Airline{{{
let g:webdevicons_enable_airline_statusline = 1
let g:airline_extensions = ['branch', 'ale']
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : '',
\ 'i' : '',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : '',
\ 'V' : 'L',
\ '' : 'B',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ 't': '',
\ }
let g:airline_powerline_fonts = 0
let g:airline_section_c = "%f\ %{WebDevIconsGetFileTypeSymbol()}\ %h%w%m%r\ %=%"
let g:airline_section_z = " Line %l:%cC"
let g:airline_section_x = ""
let g:airline#extensions#quickfix#quickfix_text = 'Quickfix'
let g:airline#extensions#default#layout = [
\ [ 'a', 'c' ],
\ [ 'b', 'z', 'error', 'warning' ]
\ ]
"let g:airline_theme = 'base16'
"let g:airline_theme = 'aurora'
let g:airline_theme = 'hybrid'
let g:airline#parts#ffenc#skip_expected_string='utf-8[unix]'
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline#extensions#bufferline#enabled = 0
let g:airline#extensions#tabline#enabled = 0
"}}}
" Syntastic{{{
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
"}}}
" Deoplete{{{
let g:deoplete#enable_at_startup = 1
let g:deoplete#max_abbr_width = 80
let g:deoplete#max_menu_width = 40
let g:deoplete#max_list = 1000
let g:deoplete#auto_complete_delay = 100
"let g:deoplete#disable_auto_complete = 1
"}}}
" NERDTree configuration{{{
let g:NERDTreeChDirMode=2
let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$','__pycache__', 'target', '.stack-work', 'node_modules', 'typings', '.git']
let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
let g:NERDTreeShowBookmarks=0
let NERDTreeMinimalUI=1
let g:nerdtree_tabs_focus_on_files=1
let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
let g:NERDTreeWinSize = 40
"let g:NERDTreeWinPos = "right"
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
if exists('g:GtkGuiLoaded')
noremap <F3> :NGToggleSidebar<CR>
else
noremap <F3> :NERDTreeToggle<CR>
endif
"}}}
" Tagbar{{{
nmap <silent> <F5> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
"}}}
"{{{ LSP
let g:LanguageClient_serverCommands = {
\ 'javascript': ['/home/eleazardd/.npm-global/bin/javascript-typescript-stdio'],
\ 'rust': ['rustup', 'run', 'stable', 'rls'],
\ }
" \ 'haskell': ['hie-wrapper', '--lsp'],
hi link ALEError Error
" hi Warning term=underline cterm=underline ctermfg=Yellow gui=undercurl guisp=Gold
hi link ALEWarning Warning
hi link ALEInfo SpellCap
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
let g:LanguageClient_diagnosticsDisplay = {
\ 1: {
\ "name": "Error",
\ "texthl": "ALEError",
\ "signText": "✖",
\ "signTexthl": "ErrorMsg",
\ },
\ 2: {
\ "name": "Warning",
\ "texthl": "ALEWarning",
\ "signText": "⚠",
\ "signTexthl": "ALEWarningSign",
\ },
\ 3: {
\ "name": "Information",
\ "texthl": "ALEInfo",
\ "signText": "ℹ",
\ "signTexthl": "ALEInfoSign",
\ },
\ 4: {
\ "name": "Hint",
\ "texthl": "ALEInfo",
\ "signText": "➤",
\ "signTexthl": "ALEInfoSign",
\ },
\ }
" Automatically start language servers.
let g:LanguageClient_autoStart = 1
"}}}
"{{{ Rainbow
let g:rainbow#pairs = [['(', ')'], ['[', ']']]
" Activation based on file type
augroup rainbow_files
autocmd!
autocmd FileType lisp,clojure,scheme,rust,haskell RainbowParentheses
augroup END
" if executable('lushtags')
" let g:tagbar_type_haskell = {
" \ 'ctagsbin' : 'lushtags',
" \ 'm:module:0',
" \ 'e:exports:1',
" \ 'i:imports:1',
" \ 't:declarations:0',
" \ 'd:declarations:1',
" \ 'n:declarations:1',
" \ 'f:functions:0',
" \ 'c:constructors:0'
" \ ],
" \ 'sro' : '.',
" \ 'kind2scope' : {
" \ 'd' : 'data',
" \ 'n' : 'newtype',
" \ 'c' : 'constructor',
" \ 't' : 'type'
" \ },
" \ 'scope2kind' : {
" \ 'data' : 'd',
" \ 'newtype' : 'n',
" \ 'constructor' : 'c',
" \ 'type' : 't'
" \ }
" \ }
" endif
"}}}
"{{{ Files + devicons
function! Fzf_dev()
function! s:files()
let l:files = split(system($FZF_DEFAULT_COMMAND), '\n')
" return s:prepend_icon(l:files)
return l:files
endfunction
" No Useful
function! s:prepend_icon(candidates)
let l:result = []
for l:candidate in a:candidates
let l:filename = fnamemodify(l:candidate, ':p:t')
let l:icon = WebDevIconsGetFileTypeSymbol(l:filename, isdirectory(l:filename))
call add(l:result, printf('%s %s', l:icon, l:candidate))
endfor
return l:result
endfunction
function! s:edit_file(item)
let l:pos = stridx(a:item, ' ')
let l:file_path = a:item[pos+1:-1]
execute 'silent e' l:file_path
endfunction
" let l:fzf_files_options = '--preview "file --mime {2..-1} | grep -qE binary; and echo {2..-1} is a binary file; or begin; highlight -O ansi {2..-1}; or cat {2..-1}; end 2> /dev/null | head -'.&lines.'"'
let l:fzf_files_options = '--preview "file --mime {} | grep -qE binary; and echo {} is a binary file; or begin; highlight -O ansi {}; or cat {}; end 2> /dev/null | head -'.&lines.'"'
call fzf#run({
\ 'source': <sid>files(),
\ 'sink': function('s:edit_file'),
\ 'options': '-m ' . l:fzf_files_options,
\ 'down': '30%' })
endfunction
nnoremap <leader>e :call Fzf_dev()<CR>
function! Fzf_tags()
function! s:tags()
" -------1 -------2 -------3 ------4
" name path line others
let l:sed_tags = 'sed -e ''s/^\([^\t]*\)\t\([^\t]*\)\t\([0-9]*\);\"\t\([a-zA-Z]\)/\4\t\1\t\3:\2/g'' | column -t -s \t'
"'sed -e "s/^\([^\t]*\)\t\([^\t]*\)\t\([0-9]+\);\"\t\([a-zA-Z]\)/\4\t\1\t\3:\2/g"'
""| column -t -s \t'
if &filetype == 'haskell'
" Format Ex: Types.newVarWithName Types.hs 58;" f
" Final Format: f main 4:build.rs
"let l:tags = split(system('fast-tags --qualified -o - ' . expand('%:@') . ' | ' . l:sed_tags), '\n')
let l:tags = split(system('fast-tags -o - -R . | ' . l:sed_tags), '\n')
else
"let l:tags = split(system("ctags --fields=k -f - -u --excmd=number --language-force=" . expand(&filetype) . " " . expand('%:@') . ' | ' . l:sed_tags), '\n')
let l:tags = split(system("ag -l | ctags --links=no -L- --fields=k -f - -u --excmd=number --language-force=" . expand(&filetype) . ' | ' . l:sed_tags), '\n')
endif
return l:tags
endfunction
function! s:edit_file(item)
let l:temp = matchstr(a:item, '\d\+:.*$')
let l:pos = stridx(l:temp, ':')
let l:file_path = l:temp[l:pos+1:-1]
let l:pos_tag = l:temp[0:l:pos]
execute 'silent e ' . l:file_path . '| :' . l:pos_tag
endfunction
let l:fzf_files_options = '--preview "highlight -O ansi (echo {} | sed -e \"s/.* \([0-9]\+\):\([^ ]*\)\\$/\2/\") 2> /dev/null | tail -n +(echo {} | sed -e \"s/.* \([0-9]\+\):\([^ ]*\)\\$/\1/\")"'
"let l:fzf_files_options = '--preview "[[ \$(file --mime \$(sed -e \"s/.* \\([0-9]\\+\\):\\([^ ]*\\)\\$/\\2/\" {})) =~ binary ]] && echo It is a binary file || (highlight -O ansi -l \$(sed -e \"s/.* \\([0-9]\\+\\):\\([^ ]*\\)\\$/\\2/\" {}) || cat {}) 2> /dev/null | less +\$(sed -e \"s/.* \\([0-9]\\+\\):\\([^ ]*\\)\\$/\\1/\" ) -R -N -j 5'
call fzf#run({
\ 'source': <sid>tags(),
\ 'sink': function('s:edit_file'),
\ 'options': '-m ' . l:fzf_files_options,
\ 'down': '30%' })
endfunction
command! FZFTagFile call Fzf_tags()
nnoremap <leader>t :call Fzf_tags()<CR>
"}}}
"{{{ Keymaps
" Non-standard {{{
" ------------
inoremap <M-x> <Esc>:
nnoremap <M-x> <Esc>:
" Remove Ex-mode
" Switch between buffers
map q: <Nop>
nnoremap Q <nop>
noremap <A-Tab> :bn<cr>
noremap <A-S-Tab> :bp<cr>
" Emacs switch to visual faster
imap <C-Space> <Esc>v
nmap <C-Space> <Esc>v
" nmap <C-k> <Esc>Da
" Exits from insert mode
inoremap jk <Esc>
" inoremap <esc> <nop>
"inoremap <S><S> <Esc>:
" Replace highlight text
nnoremap <C-c> :%s///g<left><left>
" Find selected text (use * for find words)
vnoremap // y/<C-R>"<CR>
"" Move visual block
vmap J :m '>+1<CR>gv=gv
vmap K :m '<-2<CR>gv=gv
" Disable arrow movement, resize splits instead.
" nnoremap <Up> :resize +2<CR>
" nnoremap <Down> :resize -2<CR>
" nnoremap <Left> :vertical resize +2<CR>
" nnoremap <Right> :vertical resize -2<CR>
" Change current word in a repeatable manner -- TODO: Revisar utilidad
nnoremap cn *``cgn
nnoremap cN *``cgN
" Change selected word in a repeatable manner
vnoremap <expr> cn "y/\\V\<C-r>=escape(@\", '/')\<CR>\<CR>" . "``cgn"
vnoremap <expr> cN "y/\\V\<C-r>=escape(@\", '/')\<CR>\<CR>" . "``cgN"
nnoremap <silent> <S-Tab> :call <SID>previous_window()<cr>
nnoremap <silent> <Tab> :call <SID>next_window()<cr>
function! s:next_window() abort
let second_pass = 0
let next_win = winnr()
while 1
let next_win = next_win + 1
if !((exists('t:NERDTreeBufName') && bufwinnr(t:NERDTreeBufName) == next_win) || (exists('g:term_buf') && bufwinnr(g:term_buf) == next_win) || (exists('t:tagbar_buf_name') && bufwinnr(t:tagbar_buf_name) == next_win)) && next_win <= winnr('$')
exe next_win . 'wincmd w'
break
else
if next_win > winnr('$')
if second_pass == 1
exe 1 . 'wincmd w'
break
else
let second_pass = 1 " cycle
let next_win = 0
endif
endif
endif
endwhile
endfunction
function! s:previous_window() abort
try
if winnr() == 1
exe winnr('$') . 'wincmd w'
else
exe (winnr() - 1 ) . 'wincmd w'
endif
catch
exe winnr('$') . 'wincmd w'
endtry
endfunction
" Prev and next windows
" nmap <Tab> <C-w>w
" nmap <S-Tab> <C-w>W
"}}}
" Global niceties {{{
" ---------------
" Start an external command with a single bang
nnoremap ! :!
" Allow misspellings
cnoreabbrev W! w!
cnoreabbrev Q! q!
cnoreabbrev Qall! qall!
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev Qall qall
cnoreabbrev qw wq
cnoreabbrev Wq wq
cnoreabbrev WQ wq
cnoreabbrev Qa qa
cnoreabbrev Bd bd
cnoreabbrev bD bd
" Start new line from any cursor position -- TODO:
inoremap <S-Return> <C-o>o
" Quick substitute within selected area
" xnoremap s :s//g<Left><Left>
" Improve scroll, credits: https://github.com/Shougo
nnoremap <expr> zz (winline() == (winheight(0)+1) / 2) ?
\ 'zt' : (winline() == 1) ? 'zb' : 'zz'
noremap <expr> <C-f> max([winheight(0) - 2, 1])
\ ."\<C-d>".(line('w$') >= line('$') ? "L" : "M")
noremap <expr> <C-b> max([winheight(0) - 2, 1])
\ ."\<C-u>".(line('w0') <= 1 ? "H" : "M")
noremap <expr> <C-e> (line("w$") >= line('$') ? "j" : "3\<C-e>")
noremap <expr> <C-y> (line("w0") <= 1 ? "k" : "3\<C-y>")
" Select blocks after indenting
xnoremap < <gv
xnoremap > >gv|
" Use tab for indenting in visual mode
vnoremap <Tab> >gv|
vnoremap <S-Tab> <gv
nnoremap > >>_
nnoremap < <<_
" Select last paste
" nnoremap <expr> gp '`['.strpart(getregtype(), 0, 1).'`]'
" }}}
" File operations {{{
" ---------------
" When pressing <leader>cd switch to the directory of the open buffer
map <Leader>cd :lcd %:p:h<CR>:pwd<CR>
" Save a file with sudo
" cnoremap w!! w !sudo tee > /dev/null %
cnoremap w!! w suda://%
" }}}
" Editor UI {{{
" ---------
" Show highlight names under cursor
nmap <silent> gh :echo 'hi<'.synIDattr(synID(line('.'), col('.'), 1), 'name')
\.'> trans<'.synIDattr(synID(line('.'), col('.'), 0), 'name').'> lo<'
\.synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name').'>'<CR>
" }}}
" Totally Custom {{{
" --------------
" Remove spaces at the end of lines
nnoremap <silent> ,<Space> :<C-u>silent! keeppatterns %substitute/\s\+$//e<CR>
" C-r: Easier search and replace
xnoremap <C-r> :<C-u>call <SID>get_selection('/')<CR>:%s/\V<C-R>=@/<CR>//gc<Left><Left><Left>
" Returns visually selected text
function! s:get_selection(cmdtype) "{{{
let temp = @s
normal! gv"sy
let @/ = substitute(escape(@s, '\'.a:cmdtype), '\n', '\\n', 'g')
let @s = temp
endfunction "}}}
" Use Zeal on Linux for context help
" autocmd MyAutoCmd FileType ansible,go,php,css,less,html,markdown
" \ nmap <silent><buffer> K :!zeal --query "<C-R>=split(&ft, '\.')[0]<CR>:<cword>"&<CR><CR>
" autocmd MyAutoCmd FileType javascript,javascript.jsx,sql,ruby,conf,sh
" \ nmap <silent><buffer> K :!zeal --query "<cword>"&<CR><CR>
" }}}
let g:pandoc#syntax#conceal#use=0
" QuickFix {{{
" ------------
nnoremap <F2> :QFix<CR>
command -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
unlet g:qfix_win
else
botright copen 10
let g:qfix_win = bufnr("$")
endif
endfunction
" }}}
" Terminal Drop {{{
" Crea un terminal scracthpad.
" ------------
function! Term_toggle()
if exists("g:term_buf") && bufnr(g:term_buf) != -1
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
if bufwinnr(g:term_buf) == -1
" No usar new crea búferes vacios
botright split
resize 10
exec "buffer" . g:term_buf
else
exec bufwinnr(g:term_buf) . "wincmd w"
endif
startinsert!
endif
else
" Se crea un nuevo buffer
botright new
resize 10
try
exec "buffer ".g:term_buf
catch
terminal
"call termopen($SHELL, {"detach": 0})
let g:term_buf = bufnr("")
autocmd BufDelete <buffer> unlet g:term_buf
endtry
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
tnoremap <f4> <C-\><C-n>:call Term_toggle()<cr>
" }}}
"*****************************************************************************
" Mappings
"*****************************************************************************
" " Buffer nav
" noremap <leader>z :bp<cr>
" let g:lmap.z = ['bp', 'prev buffer']
" noremap <leader>x :bn<cr>
" let g:lmap.x = ['bn', 'next buffer']
"" Close buffer
nnoremap <Leader>c :Bclose<CR>
nnoremap <Leader>q :Bclose<CR>
let g:no_plugin_maps = 1 " Remove leader bd map
" "" Clean search (highlight)
nnoremap <silent> <leader><space> :noh<cr>
" "" Split
noremap <Leader>h :<C-u>split<CR>
noremap <Leader>v :<C-u>vsplit<CR>
" session management
nnoremap <leader>so :SLoad<Space>
nnoremap <leader>s :SSave<Space>
nnoremap <leader>S :SSave!<CR>
nnoremap <leader>q :SClose<CR>
" Set working directory
nnoremap <leader>. :lcd %:p:h<CR>
nmap <leader>y "*y
vmap <leader>y "*y
nmap <leader>d "*d
vmap <leader>d "*d
nmap <leader>p "*p
vmap <leader>p "*p
map <F9> :let &background = ( &background == "dark"? "light" : "dark" )<CR>
" Visual Replace
nnoremap <leader>r :OverCommandLine<cr>%s/
"*****************************************************************************
" Coc
"*****************************************************************************
inoremap <expr> <TAB> pumvisible() ? "\<C-y>" : "\<TAB>"
let g:coc_snippet_next = '<TAB>'
let g:coc_snippet_prev = '<S-TAB>'
"*****************************************************************************
" CtrlP Config
"*****************************************************************************
noremap <leader>b :Buffers<CR>
" noremap <leader>pf :GFiles<CR>
" noremap <leader>f :Files<CR>
"noremap <leader>t :Tags<CR>
" noremap <leader>bt :BTags<CR>
" noremap <silent> <ScrollWheelDown> :call comfortable_motion#flick(40)<CR>
" noremap <silent> <ScrollWheelUp> :call comfortable_motion#flick(-40)<CR>
"" LSP
"let g:lmap.r = ['LSPRename', 'Refactor Rename']
"noremap <Leader>r :call LanguageClient_textDocument_rename()<CR>
""let g:lmap.t = ['LSPHover', 'Hover info']
"noremap <Leader>t :call LanguageClient_textDocument_hover()<CR>
""let g:lmap.d = ['LSPDefinition', 'Docs']
"noremap <Leader>d :call LanguageClient_textDocument_definition()<CR>
""let g:lmap.sym = ['LSPDefinition', 'Docs']
" nnoremap <F12> :call LanguageClient_contextMenu()<CR>
"noremap <Leader>ref :call LanguageClient_textDocument_references()<CR>
"noremap <Leader>wsym :call LanguageClient_workspace_symbol()<CR>
"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment