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

765 lines
23 KiB
VimL

" Important stuff {{{
scriptencoding utf-8 " Set utf-8 as default script encoding
let g:loaded_python_provider=1 " Disable python 2 interface
let g:python_host_skip_check=1 " Skip python 2 host check
let g:python3_host_prog = '/usr/bin/python3'
let g:tagbar_ctags_bin = '/usr/bin/ctags'
set inccommand=nosplit " Live preview of substitutes and other similar commands
let python_highlight_all=1
" Plug updates itself automatically
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
if executable('rg')
set grepprg=rg\ --vimgrep\ --hidden\ --no-heading
set grepformat=%f:%l:%c:%m,%f:%l:%m
elseif executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
endif
" }}}
" Plugins {{{
call plug#begin('~/.config/nvim/plugged')
Plug 'junegunn/vim-plug'
" Languages
Plug 'lervag/vimtex', { 'for': 'tex' }
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }
" Formatting
Plug 'w0rp/ale'
Plug 'sbdchd/neoformat', {'on': 'Neoformat'}
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/neco-syntax'
Plug 'Shougo/neco-vim'
" Navigation
Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeFind', 'NERDTreeToggle'] }
Plug 'christoomey/vim-tmux-navigator'
Plug '/usr/bin/fzf'
Plug 'junegunn/fzf.vim'
" Modes
Plug 'junegunn/goyo.vim', { 'on': 'Goyo' }
Plug 'reedes/vim-pencil', { 'for': ['tex', 'markdown', 'text'] }
Plug 'chrisbra/vim-diff-enhanced'
" UI
Plug 'NLKNguyen/papercolor-theme'
Plug 'zefei/vim-wintabs'
Plug 'jiangmiao/auto-pairs'
" Python
Plug 'numirias/semshi', {'do': ':UpdateRemotePlugins'}
Plug 'hkupty/iron.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'zchee/deoplete-jedi'
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\ }
call plug#end()
let g:plug_window = 'rightbelow topleft new'
nnoremap <leader>pi :PlugInstall<CR>
nnoremap <leader>pu :PlugUpdate<CR>
nnoremap <leader>pU :PlugUpgrade<CR>
nnoremap <leader>pc :PlugClean<CR>
" }}}
" Options {{{
" Search down into subfolders
" Provides tab-completion for all file-related tasks
" - :b lets you autocomplete any open buffer
set path+=**
set binary
set clipboard^=unnamedplus " system clipboard (requires +clipboard)
set encoding=utf-8 " The encoding displayed.
set fileencoding=utf-8 " The encoding written to file.
set shell=/bin/zsh " Setting shell to zsh
set number " Line numbers on
set showmode " Always show mode
set mousemodel=popup
set breakindent
set textwidth=120 " Text width is 120 characters
set cmdheight=1 " Command line height
set cmdwinheight=5 " Command-line lines
set pumheight=20 " Completion window max size
set helpheight=12 " Minimum help window height
set previewheight=12 " Completion preview height
set noswapfile " New buffers will be loaded without creating a swapfile
set hidden " Enables to switch between unsaved buffers and keep undo history
set lazyredraw " Don't redraw while executing macros (better performance)
set showmatch " Show matching brackets when text indicator is over them
set matchtime=2 " How many tenths of a second to blink when matching brackets
set nojoinspaces " No extra space when joining a line which ends with . ? !
set updatetime=1000 " Update time used to create swap file or other things
set synmaxcol=220 " Don't try to syntax highlight minified files
set splitbelow " Splitting a window will put the new window below the current
set splitright " Splitting a window will put the new window right of the current
set notimeout " Time out on key codes but not mappings.
set ttimeout
set ttimeoutlen=10
set ignorecase " Ignore case by default
set smartcase " Make search case sensitive only if it contains uppercase letters
set wrapscan " Search again from top when reached the bottom
set cursorline " Hightlight the screen line of the cursor
set numberwidth=5 " Minimal number of columns to use for line numbers
set nobackup
set nowritebackup
set wrap " Wrap lines longer than the width of the window
set visualbell " Use visual bell instead of beeping
set selectmode=key
set keymodel=startsel
set foldenable " Fold by default
set foldlevelstart=10
set foldnestmax=10 " Deepest fold is 10 levels
set foldmethod=marker " Markers are used to specify folds.
set completeopt=noinsert,menuone,preview,noselect
"set completefunc=LanguageClient#complete
set formatexpr=LanguageClient#textDocument_rangeFormatting_sync()
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 foldclose=all
set nostartofline
set nosmartindent
set laststatus=1 " Status line on 2 or more files
set nosmarttab
set modeline
set modelines=2
set scrolloff=7 " Keep this many lines padding when scrolling
set title
set undofile
set undolevels=1000
set undoreload=10000
set undodir=$HOME/.config/nvim/undo
set nrformats-=octal
set pastetoggle=<F12>
set shortmess=aoOtIWcFs " Shorten messages and don't show intro
set omnifunc=syntaxcomplete#Complete
set complete+=]
set completeopt-=preview
set completeopt+=noinsert,longest,noselect,menuone
set formatoptions+=n
"set matchpairs=(:),{:},[:],<:>
" Display all matching files when we tab complete
set wildmenu
set wildignorecase
set wildoptions=tagfile
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 wildignore+=.stversions,*.pyc,*.spl,*.o,*.out,*~,%*
set wildignore+=*vim/backups*
set wildignore+=tmp/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=*cache*
set wildignore+=*logs*
set wildignore+=*node_modules/**
set wildignore+=__pycache__,*.egg-info
set wildmode=longest:list,full
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
let mapleader="\<SPACE>"
let localleader=","
let formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[*-][\t ]\)\s*'
" }}}
" Statusline {{{
function! GitBranch()
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! HasPaste()
let paste_status = &paste
if paste_status == 1
return " [paste] "
else
return ""
endif
endfunction
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf(
\ '%dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
set statusline+=%#Keyword#
set statusline+=%{StatuslineGit()}
set statusline+=%#CursorLineNr#
set statusline+=\ %{LinterStatus()}
set statusline+=\ %{HasPaste()}
set statusline+=\ %F%h%r%w%q
set statusline+=%=
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\ [%{&fileformat}\]
set statusline+=\ %l:%c\ (%p%%)
set statusline+=%#Keyword#
set statusline+=\ %{winnr()}
" }}}
" AutoCommands {{{
if !exists("autocommands_loaded") && has("autocmd")
let autocommands_loaded = 1
" Auto remove all trailing whitespace on :w
autocmd BufWritePre * :%s/\s\+$//e
" Disables automatic commenting on newline
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" Python file template
autocmd BufNewFile *.py 0r ~/.config/nvim/templates/py.skeleton
aug terminal_stuff
au BufWinEnter,WinEnter term://* startinsert
au BufEnter * if &buftype == 'terminal' | setlocal statusline=%{b:term_title}
au BufLeave term://* stopinsert
au TermOpen * setlocal nonumber norelativenumber
au TermOpen * setlocal statusline=%{b:term_title}
aug END
autocmd FileType fzf set noshowmode noruler
\| autocmd BufLeave <buffer> set showmode ruler
" 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
aug END
aug mutt_settings
autocmd BufRead,BufNewFile /tmp/neomutt* let g:goyo_width=80
autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo
autocmd BufEnter /tmp/neomutt* :exe "normal! 9j\<cr>o"
autocmd BufEnter /tmp/neomutt* setl spelllang=es
aug END
endif
" }}}
" Read-Only files {{{
if &readonly
set laststatus=0
set ruler
set cmdheight=1
set nonumber
set noshowmode
set colorcolumn=0
endif
" }}}
" 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
" }}}
" Ranger {{{
function! <SID>ranger()
let l:temp = tempname()
execute 'silent !st -e ranger --choosefiles='.shellescape(l:temp).' $PWD'
if !filereadable(temp)
redraw!
return
endif
let l:names = readfile(l:temp)
if empty(l:names)
redraw!
return
endif
execute 'edit '.fnameescape(l:names[0])
for l:name in l:names[1:]
execute 'argadd '.fnameescape(l:name)
endfor
redraw!
endfunction
nnoremap <leader>R :call <SID>ranger()<CR>
" }}}
" {{{ Ale
let g:ale_linters_explicit = 1
let g:ale_echo_msg_format = '[%linter%] %s% (code)% [%severity%]'
let g:ale_lint_delay = 500 " relint max once per [amount] milliseconds
let g:ale_pattern_options = {
\ '\.min\.js$': {'ale_linters': [], 'ale_fixers': []},
\ '\.min\.css$': {'ale_linters': [], 'ale_fixers': []},
\}
highlight ALEError cterm=undercurl ctermfg=196
highlight ALEInfo cterm=undercurl ctermfg=14
hi ALEErrorSign ctermfg=red ctermbg=none
hi ALEWarningSign ctermfg=yellow ctermbg=none
nmap <silent> <F10> <Plug>(ale_previous_wrap)
nmap <silent> <F11> <Plug>(ale_next_wrap)
" }}}
" Deoplete {{{
let g:deoplete#enable_at_startup = 1
"set completeopt-=preview
call deoplete#custom#option('max_list', 100000)
call deoplete#custom#option('min_pattern_length', 2)
call deoplete#custom#source('LanguageClient',
\ 'min_pattern_length',
\ 2)
if !exists('g:deoplete#omni#input_patterns')
let g:deoplete#omni#input_patterns = {}
endif
let g:deoplete#sources#jedi#server_timeout = 120
let g:deoplete#sources#jedi#show_docstring = 1
let g:deoplete#enable_ignore_case = 1
let g:deoplete#enable_smart_case = 1
let g:context_filetype#same_filetypes = {}
let g:context_filetype#same_filetypes._ = '_'
"}}}
" NerdTree {{{
autocmd StdinReadPre * let s:std_in=1
let NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.pyo$', '\.db$', '\.sqlite$', '.o$', 'bower_components', 'node_modules', '__pycache__']
let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
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
let g:NERDTreeDirArrowExpandable = '↠'
let g:NERDTreeDirArrowCollapsible = '↡'
nnoremap <silent> <F2> :NERDTreeToggle<CR>
nnoremap <silent> <F3> :NERDTreeFind<CR>
" }}}
" 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>
" }}}
" Fzf {{{
" use bottom positioned 30% height bottom split
let g:fzf_layout = { 'down': '~30%' }
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Clear'],
\ 'hl': ['fg', 'String'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --hidden --ignore-case --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')
\ : fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'right:50%:hidden', '?'),
\ <bang>0)
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" only use FZF shortcuts in non diff-mode
if !&diff
nnoremap <C-p> :Files<Cr>
nnoremap <C-g> :Rg<Cr>
nnoremap <C-h> :History<CR>
nnoremap <C-b> :Buffers<CR>
endif
" }}}
" Goyo {{{
function! s:goyo_enter()
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()
" 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()
" }}}
" Enhanced Diff {{{
" started In Diff-Mode set diffexpr (plugin not loaded yet)
if &diff
let &diffexpr='EnhancedDiff#Diff("git diff", "--diff-algorithm=patience")'
endif
" }}}
" Papercolor {{{
set background=dark
let g:PaperColor_Theme_Options = {
\ 'theme': {
\ 'default.dark': {
\ 'transparent_background': 1,
\ 'allow_italic': 1
\ }
\ }
\ }
colorscheme PaperColor
" }}}
" Wintabs {{{
let g:wintabs_ui_active_higroup = 'TabLineSel'
let g:wintabs_switchbuf='useopen,usetab'
let g:wintabs_display='statusline'
let intertabSpace= ''
let activeVimTabChar = '┃ '
let g:wintabs_ui_sep_leftmost=activeVimTabChar
let g:wintabs_ui_sep_inbetween=' '
let g:wintabs_ui_sep_rightmost=' '
let g:wintabs_ui_active_vimtab_left=activeVimTabChar
let g:wintabs_ui_active_vimtab_right=' '
let g:wintabs_ui_active_left=activeVimTabChar
let g:wintabs_ui_active_right=' '
let g:wintabs_ui_buffer_name_format='%t'
let g:wintabs_ui_vimtab_name_format='%n'
let g:wintabs_ui_arrow_left='«'
let g:wintabs_ui_arrow_right='»'
nnoremap <silent> <C-,> :bnew<CR>
nnoremap <silent> <M-,> :WintabsClose<CR>
nnoremap <silent> <C-l> :WintabsNext<CR>
nnoremap <silent> <C-h> :WintabsPrevious<CR>
" }}}
" Semshi {{{
let g:semshi#mark_selected_nodes = 2
let g:semshi#error_sign = v:false
" }}}
" Iron {{{
nnoremap <leader>ir :IronRepl<CR>
let g:iron_repl_open_cmd = '10split'
let g:iron_map_defaults = 0
nmap + <S-v><Plug>(iron-send-motion)
vmap + <Plug>(iron-send-motion)
nmap rr <Plug>(iron-repeat-cmd)
" }}}
" LSP {{{
let g:LanguageClient_serverCommands = {
\ 'python': ['/usr/bin/pyls'],
\ 'cpp': ['clangd'],
\ 'bash': ['/usr/bin/shellcheck'],
\ }
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
" }}}
"Mappings {{{
" Spell checking
nnoremap <F6> :setlocal spell! spelllang=es<CR>
nnoremap <F7> :setlocal spell! spelllang=en<CR>
nnoremap <F8> :set nospell<CR>
nnoremap <F9> :!w<Enter>:!pdflatex <C-r>%<Enter>
" Neoformat
nnoremap <leader>f :Neoformat<CR>
vnoremap <leader>f :Neoformat<CR>
" Super quick search and replace
nnoremap <Space>' :'{,'}s/\<<C-r>=expand("<cword>")<CR>\>/
nnoremap <Space>¿ :%s/\<<C-r>=expand("<cword>")<CR>\>/
" Visual mode pressing * or # searches for the current selection
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" Learn vim keys the hard way
nnoremap <silent> <Left> :vertical resize -2<CR>
nnoremap <silent> <Right> :vertical resize +2<CR>
nnoremap <silent> <Up> :resize -1<CR>
nnoremap <silent> <Down> :resize +1<CR>
inoremap jk <esc>
cnoremap jk <C-c>
" Edit and source config file
nnoremap <silent> <leader>ev :vsplit $MYVIMRC<CR>
nnoremap <silent> <leader>sv :source $MYVIMRC<CR>
" Fast saves
nnoremap <leader>w :w!<CR>
" Exit quickly
nnoremap <leader>q :q!<CR>
" Splits
nnoremap <leader>T :terminal<CR>
nnoremap <leader>s :split<CR>
nnoremap <leader>v :vsplit<CR>
nnoremap <leader>nv :vnew<CR>
nnoremap <leader>ns :new<CR>
" Ensure that ctrl+u in insert mode can be reversed
" http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" My vim wants to enter all the time, enter all the time
nnoremap <silent> <CR> i<CR><ESC>
" Fix indentation
nnoremap <leader>i mzgg=G`z<CR>
" Deedee
nnoremap - dd<CR>p
inoremap <c-d> <esc>ddi
" LOUD
inoremap <m-u> <esc>viwUi
nnoremap <m-u> viwU
" Quote words under cursor
nnoremap <leader>" viW<esc>a"<esc>gvo<esc>i"<esc>gvo<esc>3l
nnoremap <leader>' viW<esc>a'<esc>gvo<esc>i'<esc>gvo<esc>3l
" Move a line of text using Shift+[jk]
nnoremap <S-j> mz:m+<cr>`z
nnoremap <S-k> mz:m-2<cr>`z
vnoremap <S-j> :m'>+<cr>`<my`>mzgv`yo`z
vnoremap <S-k> :m'<-2<cr>`>my`<mzgv`yo`z
" Unhighlight search terms
nnoremap <silent> <leader><space> :noh<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" What about the Q
nnoremap Q <nop>
map q <nop>
" j = gj :: k = gk while preserving numbered jumps ie. 12j or 30k
nnoremap <buffer><silent><expr>j v:count ? 'j' : 'gj'
nnoremap <buffer><silent><expr>k v:count ? 'k' : 'gk'
vnoremap <buffer><silent><expr>j v:count ? 'j' : 'gj'
vnoremap <buffer><silent><expr>k v:count ? 'k' : 'gk'
" Use tab for indenting
vnoremap <Tab> >gv|
vnoremap <S-Tab> <gv
nnoremap <Tab> v>gv|
nnoremap <S-Tab> v<gv
" Line movements
noremap <silent> <Home> g<Home>
noremap <silent> <End> g<End>
inoremap <silent> <Home> <C-o>g<Home>
inoremap <silent> <End> <C-o>g<End>
nnoremap H 0
nnoremap L $
vnoremap H 0
vnoremap L $
noremap Y 0y$
noremap <leader>y y$
" Center screen when jumping and moving
nnoremap <silent> n :norm! nzz<CR>
nnoremap <silent> N :norm! Nzz<CR>
vnoremap <silent> n :norm! nzz<CR>
vnoremap <silent> N :norm! Nzz<CR>
" Alt to switch windows
nnoremap <M-j> <C-W><C-J>
nnoremap <M-k> <C-W><C-K>
nnoremap <M-l> <C-W><C-L>
nnoremap <M-h> <C-W><C-H>
inoremap <A-h> <Esc><C-w>h
inoremap <A-j> <Esc><C-w>j
inoremap <A-k> <Esc><C-w>k
inoremap <A-l> <Esc><C-w>l
" CTRL-C doesn't trigger the InsertLeave autocmd . map to <ESC> instead.
inoremap <c-c> <ESC>
" When the <Enter> key is pressed while the popup menu is visible, it only
" hides the menu. Use this mapping to close the menu and also start a new
" line.
inoremap <expr> <CR> (pumvisible() ? "\<c-y>\<cr>" : "\<CR>")
" Use <TAB> to select the popup menu:
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Terminal movement
tnoremap <Esc> <C-\><C-n>
tnoremap <M-h> <C-\><C-n><C-w>h
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
" Shift butterfinger
:command! WQ wq
:command! Wq wq
:command! Wqa wqa
:command! Wa wa
:command! WA wa
:command! W w
:command! Q q
:command! Qa qa
:command! QA qa
" }}}
" Stuff i'll probably use if i remember to {{{
" Don't close window when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
function! CmdLine(str)
call feedkeys(":" . a:str)
endfunction
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'gv'
call CmdLine("Ack '" . l:pattern . "' " )
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" global replace
vnoremap <Leader>sw "hy
\ :let b:sub = input('global replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
\ execute '%s/'.b:rep."/".b:sub.'/g' <Bar>
\ unlet b:sub b:rep <Bar>
\ endif <CR>
nnoremap <Leader>sw
\ :let b:sub = input('global replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ execute "%s/<C-r><C-w>/".b:sub.'/g' <Bar>
\ unlet b:sub <Bar>
\ endif <CR>
" prompt before each replace
vnoremap <Leader>cw "hy
\ :let b:sub = input('interactive replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
\ execute '%s/'.b:rep.'/'.b:sub.'/gc' <Bar>
\ unlet b:sub b:rep <Bar>
\ endif <CR>
nnoremap <Leader>cw
\ :let b:sub = input('interactive replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ execute "%s/<C-r><C-w>/".b:sub.'/gc' <Bar>
\ unlet b:sub <Bar>
\ endif <CR>
" highlight long lines
let w:longlines = matchadd('ColorColumn', '\%'.&tw.'v', &tw)
nnoremap <silent> <Leader>ll
\ :if exists('w:longlines') <Bar>
\ silent! call matchdelete(w:longlines) <Bar>
\ unlet w:longlines <Bar>
\ elseif &textwidth > 0 <Bar>
\ let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth) <Bar>
\ else <Bar>
\ let w:longlines = matchadd('ColorColumn', '\%80v', 80) <Bar>
\ endif <CR>
" local keyword jump
nnoremap <Leader>fw
\ [I:let b:jump = input('Go To: ') <Bar>
\ if b:jump !=? '' <Bar>
\ execute "normal! ".b:jump."[\t" <Bar>
\ unlet b:jump <Bar>
\ endif <CR><Paste>
" }}}
" vim:foldmethod=marker:foldlevel=0