dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/nvim/init.vim

516 lines
16 KiB
VimL
Raw Normal View History

2017-12-28 13:49:45 +00:00
" Important stuff {{{
set nocompatible
2017-12-28 13:49:45 +00:00
let g:python_host_prog = '/usr/bin/python2'
let g:python3_host_prog = '/usr/bin/python3'
let g:tagbar_ctags_bin = '/usr/bin/ctags'
" Plug updates itself automatically
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
2017-12-28 13:49:45 +00:00
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" }}}
" Plugins {{{
2017-12-28 13:49:45 +00:00
call plug#begin('~/.config/nvim/plugged')
Plug 'junegunn/vim-plug'
Plug 'junegunn/goyo.vim'
Plug 'ryanoasis/vim-devicons'
Plug 'itchyny/lightline.vim'
Plug 'mgee/lightline-bufferline'
2017-12-28 13:49:45 +00:00
Plug 'flazz/vim-colorschemes'
Plug 'vim-scripts/CSApprox'
2017-12-28 13:49:45 +00:00
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'hecal3/vim-leader-guide'
Plug 'christoomey/vim-tmux-navigator'
Plug 'Shougo/vinarise.vim'
Plug 'lervag/vimtex', { 'for': 'tex' }
Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' }
Plug '/usr/bin/fzf'
2017-12-28 13:49:45 +00:00
call plug#end()
let g:plug_window = 'rightbelow topleft new'
" }}}
" Basic config stuff {{{
" Search down into subfolders
" Provides tab-completion for all file-related tasks
" - :b lets you autocomplete any open buffer
set path+=**
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
" Options
set background = "dark"
filetype plugin on
filetype indent on
syntax on
let mapleader="\<SPACE>"
"set t_Co=256
set termguicolors
set ttimeout
set timeoutlen=300 " Timeout for key sequences in milliseconds
set ttimeoutlen=100
set cursorline " Hightlight the screen line of the cursor
set hidden " Hide buffers when they are abandoned
set lazyredraw
set number " Print the line number
set numberwidth=5 " Minimal number of columns to use for line numbers
set showmatch " Show matching brackets
set noswapfile
set nobackup
set nowritebackup
set showcmd " Show the current command
set ruler
set wrap " Wrap lines longer than the width of the window
set visualbell " Use visual bell instead of beeping
set slm=mouse
set mousehide
set noexpandtab " Do not turn tabs into spaces
set tabstop=4 " Number of spaces a <Tab> equals
set softtabstop=4
set shiftwidth=4 " Number of spaces for each (auto)indent step
set fcl=all
set smartindent
set ttyfast
set noshowmode " Hide mode, it's on the statusbar anyway
set laststatus=2 " Always see the status line
set splitright
set splitbelow
set hlsearch " Highlight search matches
set incsearch " Incrementally match the search
set ignorecase " Set the search scan so that it ignores case
set smartcase " But acknowledge it if it matters
set wrapscan " Set the search scan to wrap lines
set complete-=i
set smarttab
set display+=lastline
set nostartofline
set foldenable " Fold by default
set foldlevelstart=10
set foldnestmax=10 " Deepest fold is 10 levels
set foldmethod=indent " Fold based on indent
set modelines=2
set modeline
set scrolloff=7 " Keep this many lines padding when scrolling
set showtabline=2
set undofile
set undolevels=1000
set undoreload=10000
set undodir=$HOME/.config/nvim/undo
" Display all matching files when we tab complete
set wildmenu
set wildignore+=.git,.hg,.svn
set wildignore+=*.aux,*.out,*.toc
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest,*.rbc,*.class
set wildignore+=*.ai,*.bmp,*.gif,*.ico,*.jpg,*.jpeg,*.png,*.psd,*.webp
set wildignore+=*.avi,*.divx,*.mp4,*.webm,*.mov,*.m2ts,*.mkv,*.vob,*.mpg,*.mpeg
set wildignore+=*.mp3,*.oga,*.ogg,*.wav,*.flac
set wildignore+=*.eot,*.otf,*.ttf,*.woff
set wildignore+=*.doc,*.pdf,*.cbr,*.cbz
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz,*.kgb
set wildignore+=*.swp,.lock,.DS_Store,._*
set wildmode=longest:list,full
set formatoptions+=w
function! MyLineNumber()
return substitute(line('.'), '\d\@<=\(\(\d\{3\}\)\+\)$', ',&', 'g'). ' | '.
\ substitute(line('$'), '\d\@<=\(\(\d\{3\}\)\+\)$', ',&', 'g')
endfunction
2017-12-28 13:49:45 +00:00
" }}}
" Tweaks for browsing {{{
" - :edit a folder to open a file browser
" - <CR>/v/t to open in an h-split/v-split/tab
let g:netrw_banner=0 " disable annoying banner
let g:netrw_browse_split=4 " open in prior window
let g:netrw_altv=1 " open splits to the right
let g:netrw_liststyle=3 " tree view
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
let g:netrw_winsize=25
" }}}
" fzf {{{
" An action can be a reference to a function that processes selected lines
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" Default fzf layout: - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" You can set up fzf window using a Vim command (Neovim or latest Vim 8 required)
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' }
" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Enable per-command history.
" CTRL-N and CTRL-P will be automatically bound to next-history and
" previous-history instead of down and up. If you don't like the change,
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.local/share/fzf-history'
function! s:fzf_statusline()
" Override statusline as you like
highlight fzf1 ctermfg=161 ctermbg=251
highlight fzf2 ctermfg=23 ctermbg=251
highlight fzf3 ctermfg=237 ctermbg=251
setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f
endfunction
autocmd! User FzfStatusLine call <SID>fzf_statusline()
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 12
" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
" Override Colors command. You can safely do this in your .vimrc as fzf.vim
" will not override existing commands.
command! -bang Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
" :Ag! - Start fzf in fullscreen and display the preview window above
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" Insert mode completion
imap <c-x><c-k> <plug>(fzf-complete-word)
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
imap <c-x><c-l> <plug>(fzf-complete-line)
" Advanced customization using autoload functions
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'})
" }}}
" Goyo {{{
function! s:goyo_enter()
set showmode
let b:quitting = 0
let b:quitting_bang = 0
autocmd QuitPre <buffer> let b:quitting = 1
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction
function! s:goyo_leave()
set noshowmode
" Quit Vim if this is the only remaining buffer
if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting_bang
qa!
else
qa
endif
endif
endfunction
autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()
"}}}
" Lightline {{{
let g:lightline = {
\ 'colorscheme': 'one',
\ }
let g:lightline.tabline = {'left': [['buffers']], 'right': [['']]}
let g:lightline.component_expand = {'buffers': 'lightline#bufferline#buffers'}
let g:lightline.component_type = {'buffers': 'tabsel'}
let g:lightline#bufferline#show_number = 2
let g:lightline#bufferline#unicode_symbols = 1
let g:lightline#bufferline#min_buffer_count = 2
let g:lightline#bufferline#shorten_path = 0
nmap <Leader>1 <Plug>lightline#bufferline#go(1)
nmap <Leader>2 <Plug>lightline#bufferline#go(2)
nmap <Leader>3 <Plug>lightline#bufferline#go(3)
nmap <Leader>4 <Plug>lightline#bufferline#go(4)
nmap <Leader>5 <Plug>lightline#bufferline#go(5)
nmap <Leader>6 <Plug>lightline#bufferline#go(6)
nmap <Leader>7 <Plug>lightline#bufferline#go(7)
nmap <Leader>8 <Plug>lightline#bufferline#go(8)
nmap <Leader>9 <Plug>lightline#bufferline#go(9)
nmap <Leader>0 <Plug>lightline#bufferline#go(10)
2017-12-28 13:49:45 +00:00
" }}}
" NerdTree {{{
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
let NERDTreeIgnore=['\~$', '.o$', 'bower_components', 'node_modules', '__pycache__']
2017-12-28 13:49:45 +00:00
let NERDTreeNaturalSort = 1
let NERDTreeShowHidden=1
let NERDTreeWinPos=1
let NERDTreeRespectWildIgnore = 1
let NERDTreeMinimalUI=1
let NERDTreeDirArrows = 1
let NERDTreeCascadeSingleChildDir=1
let NERDTreeCascadeOpenSingleChildDir=1
let NERDTreeQuitOnOpen = 1
let NERDTreeHijackNetrw = 0
let NERDTreeAutoCenter = 1
" }}}
" Tmux navigator {{{
let g:tmux_navigator_no_mappings = 1
let g:tmux_navigator_save_on_switch = 1
nnoremap <silent> M-left :TmuxNavigateLeft<cr>
nnoremap <silent> M-Down :TmuxNavigateDown<cr>
nnoremap <silent> M-Up :TmuxNavigateUp<cr>
nnoremap <silent> M-Right :TmuxNavigateRight<cr>
nnoremap <silent> M-Tab :TmuxNavigatePrevious<cr>
" }}}
" Leader guide {{{
let g:lmap = get(g:, 'lmap', {})
let g:lmap.a = { 'name': 'applications' }
let g:lmap.f = { 'name': 'files' }
let g:lmap.t = { 'name': 'terminal' }
let g:lmap.w = { 'name': 'windows' }
let g:lmap.b = { 'name': 'buffers' }
let s:value_lookup = {
\ '<SID>nerdtree-toggle': 'NERDTree',
\ '<SID>live-preview': 'LaTeX Live Preview',
\ '<SID>quit': 'exit nvim',
\ '<SID>open-vimrc': 'open init.vim',
\ '<SID>source': 'source file',
\ '<SID>save': 'save file',
\ '<SID>open-term': 'open terminal',
\ '<SID>term-down': 'move down',
\ '<SID>term-up': 'move up',
\ '<SID>term-right': 'move right',
\ '<SID>term-left': 'move left',
\ '<SID>split': 'split down',
\ '<SID>vert-split': 'split right',
\ '<SID>new': 'new window down',
\ '<SID>vert-new': 'new window right',
\ '<SID>move-down': 'move down',
\ '<SID>move-up': 'move up',
\ '<SID>move-right': 'move right',
\ '<SID>move-left': 'move left',
\ '<SID>prev': 'last used window',
\ '<SID>next-buffer': 'next buffer',
\ '<SID>prev-buffer': 'previous buffer',
\ '<SID>list-buffer': 'list current buffers',
\ '<SID>copy-buffer': 'copy buffer content',
\ '<SID>close-buffer': 'close buffer',
\ }
2017-12-28 13:49:45 +00:00
function! s:my_displayfunc()
let g:leaderGuide#displayname =
\get(s:value_lookup, g:leaderGuide#displayname,
\g:leaderGuide#displayname)
endfunction
let g:leaderGuide_displayfunc = [function("s:my_displayfunc")]
" Applications {{{
2017-12-28 13:49:45 +00:00
nnoremap <SID>nerdtree-toggle :NERDTreeToggle<CR>
nmap <leader>at <SID>nerdtree-toggle
nnoremap <SID>live-preview :LLPStartPreview<CR>
nmap <leader>ap <SID>live-preview
nnoremap <SID>quit :q<CR>
nmap <leader>aq <SID>quit
" }}}
2017-12-28 13:49:45 +00:00
" Files {{{
2017-12-28 13:49:45 +00:00
nnoremap <SID>open-vimrc :e $MYVIMRC<CR>
nmap <leader>fi <SID>open-vimrc
nnoremap <SID>source :so %<CR>
nmap <leader>fr <SID>source
nnoremap <SID>save :w!<CR>
nmap <leader>fs <SID>save
" }}}
2017-12-28 13:49:45 +00:00
" Terminal {{{
2017-12-28 13:49:45 +00:00
nnoremap <SID>open-term :terminal<CR>
nmap <leader>tt <SID>open-term
tnoremap <SID>term-down <C-\><C-n><C-w>j
nmap <leader>td <SID>term-down
tnoremap <SID>term-up <C-\><C-n><C-w>k
nmap <leader>tu <SID>term-up
tnoremap <SID>term-right <C-\><C-n><C-w>l
nmap <leader>tr <SID>term-right
tnoremap <SID>term-left <C-\><C-n><C-w>h
nmap <leader>tl <SID>term-left
" }}}
2017-12-28 13:49:45 +00:00
" Windows {{{
2017-12-28 13:49:45 +00:00
nnoremap <SID>split :split<CR>
nmap <leader>ws <SID>split
nnoremap <SID>vert-split :vsplit<CR>
nmap <leader>wv <SID>vert-split
nnoremap <SID>new :new<CR>
nmap <leader>wn <SID>new
nnoremap <SID>vert-new :vnew<CR>
nmap <leader>wv <SID>vert-new
nnoremap <SID>move-down <C-W><C-J>
nmap <leader>wd <SID>move-down
nnoremap <SID>move-up <C-W><C-K>
nmap <leader>wu <SID>move-up
nnoremap <SID>move-right <C-W><C-L>
nmap <leader>wr <SID>move-right
nnoremap <SID>move-left <C-W><C-H>
nmap <leader>wl <SID>move-left
nnoremap <SID>prev <C-W><C-P>
nmap <leader>wp <SID>prev
" }}}
2017-12-28 13:49:45 +00:00
" Buffers {{{
2017-12-28 13:49:45 +00:00
nnoremap <SID>next-buffer :bnext!<CR>
nmap <leader>bn <SID>next-buffer
nnoremap <SID>prev-buffer :bprevious!<CR>
nmap <leader>bp <SID>prev-buffer
nnoremap <SID>list-buffer :ls<CR>
nmap <leader>bl <SID>list-buffer
nnoremap <SID>close-buffer :bd!<CR>
nmap <leader>bx <SID>close-buffer
2017-12-28 13:49:45 +00:00
vnoremap <SID>copy-buffer "*y
nmap <leader>bc <SID>copy-buffer
" }}}
2017-12-28 13:49:45 +00:00
call leaderGuide#register_prefix_descriptions("<Space>", "g:lmap")
nnoremap <silent> <leader> :<c-u>LeaderGuide '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>LeaderGuideVisual '<Space>'<CR>
let g:leaderGuide_max_size = 5
let g:leaderGuide_submode_mappings = { '<C-F>': 'page_down', '<C-B>': 'page_up'}
" }}}
" LaTeX {{{
let g:livepreview_previewer = 'mupdf'
let g:vimtex_view_method = 'zathura'
" }}}
" Mappings {{{
map <F5> :!w<Enter>:!pdflatex <C-r>%<Enter>
map <F6> :setlocal spell! spelllang=es_ar<CR>
map <F7> :setlocal spell! spelllang=en_us<CR>
nnoremap Q <nop> " What about the Q
2017-12-28 13:49:45 +00:00
map q <nop>
nnoremap j gj " Move vertically by visual line
2017-12-28 13:49:45 +00:00
nnoremap k gk
nnoremap <C-n> :tabnew<CR> " New tab
nnoremap <Tab> :bnext!<CR> " Buffer navigation using tab and shift+tab
2017-12-28 13:49:45 +00:00
nnoremap <S-Tab> :bprev!<CR><Paste>
nnoremap <M-j> <C-W><C-J> " Switch between windows with Alt
2017-12-28 13:49:45 +00:00
nnoremap <M-k> <C-W><C-K>
nnoremap <M-l> <C-W><C-L>
nnoremap <M-h> <C-W><C-H>
tnoremap <Esc> <C-\><C-n> " Use <Esc> to escape terminal insert mode
tnoremap <M-h> <C-\><C-n><C-w>h " Make terminal split moving behave like normal neovim
2017-12-28 13:49:45 +00:00
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
" }}}
" AutoCommands {{{
if !exists("autocommands_loaded") && has("autocmd")
let autocommands_loaded = 1
autocmd BufWritePre * :%s/\s\+$//e " Auto remove all trailing whitespace on :w
:au FocusLost * :wa " Autosave files when focus is lost
" Automatic syntax highlighting for files
aug set_file_types
au BufRead,BufNewFile *.txt set filetype=markdown
au BufRead,BufNewFile *.md set filetype=markdown
au BufRead,BufNewFile *.conf set filetype=dosini
au BufRead,BufNewFile *.bash* set filetype=sh
au BufRead,BufNewFile todo* set filetype=todo
aug END
" Settings for these file types
aug file_types_settings
au FileType python setl ts=4 sts=4 sw=4 et tw=80
au FileType ruby setl ts=2 sts=2 sw=2 et tw=80
au FileType markdown setl ts=2 sts=2 sw=2 et tw=80
au FileType csh,sh,zsh setl ts=4 sts=4 sw=4 noet tw=90
au FileType csh,sh,zsh if !exists("b:sh_indent_options") |
\ let b:sh_indent_options = {} |
\ endif |
\ let b:sh_indent_options['continuation-line'] = 4
aug END
aug mutt_settings
autocmd BufRead,BufNewFile /tmp/neomutt* let g:goyo_width=90
autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo
autocmd BufEnter /tmp/neomutt* :exe "normal! 7j\<cr>I"
au BufEnter neomutt-* setl filetype=mail
au BufRead neomutt-* set spell
aug END
endif
2017-12-28 13:49:45 +00:00
"}}}
" Read-Only files {{{
if &readonly
set laststatus=0
set ruler
set cmdheight=1
set nonumber
set colorcolumn=0
endif
2017-12-28 13:49:45 +00:00
" }}}
colorscheme turtles
2017-12-28 13:49:45 +00:00
" vim:foldmethod=marker:foldlevel=0