Skip to content

Instantly share code, notes, and snippets.

@MDeiml
Last active April 30, 2021 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MDeiml/c35eec96e3693d7241f9dd24adec7160 to your computer and use it in GitHub Desktop.
Save MDeiml/c35eec96e3693d7241f9dd24adec7160 to your computer and use it in GitHub Desktop.
call plug#begin('~/.config/nvim/plugged/')
if exists('g:vscode')
else
" General Plugins
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'ctrlpvim/ctrlp.vim'
" Aesthetics
Plug 'bling/vim-airline'
Plug 'rakr/vim-one'
" Autocompletion
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'deoplete-plugins/deoplete-lsp'
Plug 'neovim/nvim-lspconfig'
" Git
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" php
Plug 'StanAngeloff/php.vim'
" java
Plug 'tfnico/vim-gradle'
" javascript
Plug 'leafgarland/typescript-vim'
" latex
Plug 'lervag/vimtex'
" haskell
Plug 'neovimhaskell/haskell-vim'
Plug 'ndmitchell/ghcid', { 'rtp': 'plugins/nvim' }
" rust
Plug 'rust-lang/rust.vim'
" kotlin
Plug 'udalov/kotlin-vim'
endif
call plug#end()
imap jj <esc>
tmap jj <C-\><C-n>
autocmd BufEnter term://* startinsert
autocmd BufLeave term://* stopinsert
augroup TerminalStuff
au!
autocmd TermOpen * setlocal nonumber norelativenumber
augroup END
set number
set cursorline
set splitbelow
set splitright
if (empty($TMUX))
if (has("nvim"))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
if (has("termguicolors"))
set termguicolors
endif
endif
if exists('g:vscode')
else
colorscheme one
let g:airline_theme='one'
endif
if exists('g:gnvim')
set guifont=Iosevka\ Nerd\ Font:h14
endif
nnoremap <A-1> 1gt
nnoremap <A-2> 2gt
nnoremap <A-3> 3gt
nnoremap <A-4> 4gt
nnoremap <A-5> 5gt
nnoremap <A-6> 6gt
nnoremap <A-7> 7gt
nnoremap <A-8> 8gt
nnoremap <A-9> 9gt
imap <A-1> <esc>1gt
imap <A-2> <esc>2gt
imap <A-3> <esc>3gt
imap <A-4> <esc>4gt
imap <A-5> <esc>5gt
imap <A-6> <esc>6gt
imap <A-7> <esc>7gt
imap <A-8> <esc>8gt
imap <A-9> <esc>9gt
tmap <A-1> <C-\><C-n>1gt
tmap <A-2> <C-\><C-n>2gt
tmap <A-3> <C-\><C-n>3gt
tmap <A-4> <C-\><C-n>4gt
tmap <A-5> <C-\><C-n>5gt
tmap <A-6> <C-\><C-n>6gt
tmap <A-7> <C-\><C-n>7gt
tmap <A-8> <C-\><C-n>8gt
tmap <A-9> <C-\><C-n>9gt
set history=500
filetype plugin on
filetype indent on
set autoread
let mapleader = ","
let g:mapleader = ","
command W w !sudo tee % > /dev/null
set so=7
let $LANG='en'
set langmenu=en
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set wildmenu
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=.git\*,.hg\*,.svn\*
else
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
endif
set ruler
set cmdheight=2
set hid
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" search
set ignorecase
set smartcase
set hlsearch
set incsearch
set lazyredraw
set magic
" matching brackets
set showmatch
set mat=2
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Add a bit extra margin to the left
set foldcolumn=1
" Enable syntax highlighting
syntax enable
" Enable 256 colors palette in Gnome Terminal
if $COLORTERM == 'gnome-terminal'
set t_Co=256
endif
set background=dark
" Set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T
set guioptions-=e
set t_Co=256
set guitablabel=%M\ %t
endif
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
set nobackup
set nowb
set noswapfile
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
map <space> /
map <c-space> ?
map <silent> <leader><cr> :noh<cr>
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
map <leader>ä :bnext<cr>
map <leader>ö :bprevious<cr>
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>tb :tabedit term://bash<CR>
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" 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()
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
map 0 ^
" Move a line of text using ALT+[jk] or Command+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
if has("mac") || has("macunix")
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif
" Delete trailing white space on save, useful for some filetypes ;)
fun! CleanExtraSpaces()
let save_cursor = getpos(".")
let old_query = getreg('/')
silent! %s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfun
if has("autocmd")
autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
endif
if exists('g:vscode')
else
" 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)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
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
" Autocompletion
let g:deoplete#enable_at_startup=1
call deoplete#custom#source('_', 'max_menu_width', 0)
inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
set completeopt=longest,menuone
" LSP
lua require'lspconfig'.rust_analyzer.setup({})
nnoremap <leader>la :lua vim.lsp.buf.code_action()<CR>
nnoremap <leader>lh <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <leader>ln <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
let g:deoplete#lsp#use_icons_for_candidates=v:true
" rust
let g:rustfmt_autosave = 1
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment