diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..5faa983 --- /dev/null +++ b/init.lua @@ -0,0 +1,87 @@ +local cmd = vim.cmd -- to execute Vim commands e.g. cmd('pwd') +local fn = vim.fn -- to call Vim functions e.g. fn.bufnr() +local g = vim.g -- a table to access global variables +local opt = vim.opt -- to set options + +local fn = vim.fn + +-- Auto install packer.nvim if not exists +local fn = vim.fn +local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' +if fn.empty(fn.glob(install_path)) > 0 then + fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.cmd 'packadd packer.nvim' +end +vim.cmd [[packadd packer.nvim]] +vim.cmd 'autocmd BufWritePost plugins.lua PackerCompile' -- Auto compile when there are changes in plugins.lua + +local utils = require('utils') +-- Install plugins +require('plugins') +require('keymappings') +-------------------- OPTIONS ------------------------------- +cmd 'colorscheme gruvbox-material' -- Put your favorite colorscheme here +cmd 'syntax enable' +cmd 'filetype plugin indent on' +--opt.noswapfile = true +-- opt.nobackup = true +opt.spelllang = 'en,de' +local indent = 4 +utils.opt('b', 'expandtab', true) +utils.opt('b', 'shiftwidth', indent) +utils.opt('b', 'smartindent', true) +utils.opt('b', 'tabstop', indent) +utils.opt('o', 'hidden', true) +utils.opt('o', 'ignorecase', true) +utils.opt('o', 'scrolloff', 4 ) +utils.opt('o', 'shiftround', true) +utils.opt('o', 'relativenumber', true) +utils.opt('o', 'smartcase', true) +utils.opt('o', 'splitbelow', true) +utils.opt('o', 'splitright', true) +utils.opt('o', 'wildmode', 'list:longest') +utils.opt('w', 'number', true) +utils.opt('w', 'relativenumber', true) +utils.opt('o', 'clipboard', 'unnamed,unnamedplus') +utils.opt('o', 'mouse', 'a') +utils.opt('o', 'wrap', false) +utils.opt('o', 'termguicolors', true) +utils.opt('o', 'splitbelow', true) +utils.opt('o', 'splitright', true) +utils.opt('o', 'list', true) + +-- Highlight on yank +vim.cmd 'au TextYankPost * lua vim.highlight.on_yank {on_visual = false}' + +-------------------- MAPPINGS ------------------------------ +-- to navigate the completion menu +utils.map('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true}) +utils.map('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true}) +-------------------- TREE-SITTER --------------------------- +local ts = require 'nvim-treesitter.configs' +ts.setup {ensure_installed = 'maintained', highlight = {enable = true}} + +-------------------- FZF ----------------------------------- +utils.map('n', '', ':FZF') +-------------------- LSP ----------------------------------- +local lsp = require 'lspconfig' + +-- We use the default settings for ccls and pylsp: the option table can stay empty +lsp.ccls.setup {} +lsp.pyright.setup{} +lsp.clangd.setup{} + +utils.map('n', ',', 'lua vim.lsp.diagnostic.goto_prev()') +utils.map('n', ';', 'lua vim.lsp.diagnostic.goto_next()') +utils.map('n', 'a', 'lua vim.lsp.buf.code_action()') +utils.map('n', 'd', 'lua vim.lsp.buf.definition()') +utils.map('n', 'f', 'lua vim.lsp.buf.formatting()') +utils.map('n', 'h', 'lua vim.lsp.buf.hover()') +utils.map('n', 'm', 'lua vim.lsp.buf.rename()') +utils.map('n', 'r', 'lua vim.lsp.buf.references()') +utils.map('n', 's', 'lua vim.lsp.buf.document_symbol()') + +-------------------- GITSIGNS ------------------------------ +require('gitsigns').setup() +-------------------- LIGHTBULB ----------------------------- +require('nvim-lightbulb').update_lightbulb() diff --git a/init.vim b/init.vim deleted file mode 100644 index 1adef2b..0000000 --- a/init.vim +++ /dev/null @@ -1,305 +0,0 @@ -let HOSTNAME = substitute(system('hostname'), '\n', '', '') -" =============Plugins================== -call plug#begin() -Plug 'morhetz/gruvbox' -Plug 'Shougo/denite.nvim', { 'do': ':UpdateRemotePlugins' } -Plug 'chemzqm/denite-git' -Plug 'tomtom/tcomment_vim' -Plug 'bling/vim-airline' -Plug 'vim-airline/vim-airline-themes' -" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } -Plug 'tpope/vim-fugitive' -Plug 'airblade/vim-gitgutter' -Plug 'SirVer/ultisnips' -Plug 'honza/vim-snippets' -Plug 'vim-scripts/a.vim' -Plug 'luochen1990/rainbow' -if has("win32") - Plug 'autozimu/LanguageClient-neovim', { - \ 'branch': 'next', - \ 'do': 'powershell -executionpolicy bypass -File install.ps1', - \ } -else - Plug 'autozimu/LanguageClient-neovim', { - \ 'branch': 'next', - \ 'do': 'bash install.sh', - \ } -end -Plug 'Shougo/echodoc.vim' -Plug 'arakashic/chromatica.nvim', { 'do': ':UpdateRemotePlugins' } -Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}} -Plug 'neoclide/coc-json', {'do': 'yarn install --frozen-lockfile'} -Plug 'neoclide/coc-python', {'do': 'yarn install --frozen-lockfile'} -Plug 'neoclide/coc-yaml', {'do': 'yarn install --frozen-lockfile'} -Plug 'neoclide/coc-highlight', {'do': 'yarn install --frozen-lockfile'} -Plug 'neoclide/coc-snippets', {'do': 'yarn install --frozen-lockfile'} -Plug 'neoclide/coc-lists', {'do': 'yarn install --frozen-lockfile'} -Plug 'kkoomen/vim-doge' -call plug#end() - -" =============Paths===================== -exec "source " . stdpath('config') . "/" . hostname() . ".vim" -" =============Settings================== -filetype plugin on -filetype indent on -set nocompatible -set ignorecase " Case sensitive off -set incsearch -set encoding=utf-8 -set nobackup -set noswapfile -set mouse=a -set spelllang=en,de -set spellsuggest=double,10 -set list -set icon -set listchars=tab:>.,trail:.,extends:#,nbsp:. -set showmatch " Show pair braces -set hlsearch "Highlight search -syntax on -set number -set scrolloff=2 -set autochdir " Always switch to directory of current buffer -let mapleader = "," - -set title - -if has("win32") - " set rop=type:directx - let g:loaded_matchparen = 1 -end - -set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣ -set listchars=eol:⏎,tab:␉·,trail:␠,nbsp:⎵ -set listchars=tab:>.,trail:.,extends:#,nbsp:. - -" set clipboard+=unnamedplus " use system clipboard -" " Copy to clipboard -vnoremap y "+y -nnoremap Y "+yg_ -nnoremap y "+y -nnoremap yy "+yy - -" " Paste from clipboard -nnoremap p "+p -nnoremap P "+P -vnoremap p "+p -vnoremap P "+P - -autocmd BufEnter,FocusGained * checktime " Check for file modifications - -" =================Look and feel======================= -set termguicolors -set background=dark -colorscheme gruvbox -" =================Filetypes=========================== -au BufRead,BufNewFile *.simvis set filetype=xml -au BufRead,BufNewFile *.simcfg set filetype=cfg -au BufRead,BufNewFile *.simcon set filetype=cfg -au BufRead,BufNewFile *.simudex set filetype=cfg -au BufRead,BufNewFile Jenkinsfile* set filetype=groovy -autocmd BufNewFile,BufRead *.manifest set filetype=xml -autocmd BufNewFile,BufReadPre SConstruct set filetype=python -autocmd BufNewFile,BufReadPre SConscript set filetype=python -autocmd FileType xml nnoremap :% !xmllint.exe "%" --format -autocmd FileType json syntax match Comment +\/\/.\+$+ -" =================Windows and Tabs==================== -" Open a new tab with F2 -map :tabnew :Explore -imap :tabnew :Explore -map :tabnext -map :tabprevious -nmap :wincmd k -nmap :wincmd j -nmap :wincmd h -nmap :wincmd l -" Open a new vertical split window with Ctrl - F2 -map :vsplit . -imap :vsplit . -" Open a new horizontal split window with Shift - F2 -map :split . -imap :split . - -" ========================Codestyle======================== -set tabstop=2 " Size of a tab -set shiftwidth=2 " Die Einrückung -set expandtab "Tabs get spaces when inserting -set softtabstop=0 -"set autoindent -"alignment ansi style (astyle) -set cindent " C-Code Style / Automatische Einrückung -set cinoptions=(0,u0,U0,:0,=0 "Einrückung wie bei astyle: :0 (switch), =0 (case), (0 (unclosed parentheses), -set modeline "Read indent comments (at end of file) - -" ======================shortcut======================= -map :wa -imap :wa -"Jump to last modification line -map ö `. -nnoremap ü :let @/='\<=expand("")\>':set hls -vnoremap ü : - \let old_reg=getreg('"')let old_regtype=getregtype('"') - \gvy:let @/=substitute( - \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g') - \gV:call setreg('"', old_reg, old_regtype):set hls - -"map jump back to ctrl+- -nnoremap -"===================Reselect visual block after indent/outdent============ -vnoremap < >gv - -" ===========Linewrap and jumping============================= -setlocal wrap linebreak nolist -set virtualedit= -setlocal display+=lastline -nnoremap k gk -nnoremap j gj -nnoremap 0 g0 -nnoremap $ g$ -nnoremap gk -nnoremap gj -nnoremap g -nnoremap g -vnoremap gk -vnoremap gj -vnoremap g -vnoremap g - -" =================Comments============================ -map :TComment - -" =========================Deoplete==================== -let g:deoplete#enable_at_startup = 1 -let g:deoplete#auto_complete_start_length = 1 -let g:deoplete#enable_smart_case = 1 -" =====================A====================== -" Function for switching between header and c* files -map :wa :A -imap :wa:Ai -map :AV -imap :AVi -map :AT -imap :ATi -let g:alternateSearchPath = 'sfr:../source,sfr:../src,sfr:../include,../../include,sfr:../inc,sfr:../h' -" Dont create the file if the .cpp or .h is not found -let g:alternateNoDefaultAlternate = 1 - -" ===================UltiSnips================ -let g:UltiSnipsExpandTrigger = "(ultisnips_expand)" -let g:UltiSnipsJumpForwardTrigger = "" -let g:UltiSnipsJumpBackwardTrigger = "" -" ===========RAINBOW==================== -let g:rainbow_active = 1 -let g:rainbow_conf = { - \ 'guifgs': ['lightblue', 'darkorange3', 'seagreen3', 'firebrick'], - \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], - \ 'operators': '_,_', - \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], - \ 'separately': { - \ '*': {}, - \ 'tex': { - \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'], - \ }, - \ 'cpp': { - \ 'parentheses': [ - \ 'start=/(/ end=/)/ fold', - \ 'start=/\[/ end=/\]/ fold', - \ 'start=/{/ end=/}/ fold', - \ 'start=/\(\(\\)\@/'] - \ }, - \ 'cmake': { - \ 'parentheses': [], - \ }, - \ 'lisp': { - \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], - \ }, - \ 'vim': { - \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'], - \ }, - \ 'html': { - \ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold'], - \ }, - \ 'css': 0, - \ } - \} - -" ===================LanguageServer================== -if has("win32") - let g:LanguageClient_serverCommands = { - \ 'cpp': ['clangd'], - \ } -else - let g:LanguageClient_serverCommands = { - \ 'cpp': ['cquery', - \ '--log-file=/tmp/cq.log', - \ '--init={"cacheDirectory":"/tmp/cquery/"}'] - \ } -end -nnoremap K :call LanguageClient#textDocument_hover() -nnoremap gd :call LanguageClient#textDocument_definition({'gotoCmd': 'tabedit'}) -nnoremap :call LanguageClient_contextMenu() -vnoremap :call LanguageClient_contextMenu() -nnoremap :call LanguageClient_textDocument_documentSymbol() - -let g:LanguageClient_hasClientSupport = 0 -" ===================EchoDoc========================= -set cmdheight=2 -let g:echodoc#enable_at_startup = 1 -let g:echodoc#type = 'signature' -" ===================FZF============================= -nnoremap :FZF -let g:fzf_action = { - \ 'enter': 'tab split', - \ 'ctrl-x': 'split', - \ 'ctrl-v': 'vsplit' } -" ===================Chromatica====================== -let g:chromatica#enable_at_startup=1 - -" ===================COC============================= -inoremap coc#refresh() -autocmd CursorHold * silent call CocActionAsync('highlight') -set updatetime=500 " After ms should CursorHold trigger -" Remap for format selected region -vmap f (coc-format-selected) -nmap f (coc-format-selected) - -nmap r (coc-rename) -" Use `:Format` for format current buffer -command! -nargs=0 Format :call CocAction('format') -" Shortcuts for denite interface -" Show extension list -nnoremap e :CocList extensions -" Show symbols of current buffer -nnoremap o :CocList outline -" Search symbols of current workspace -nnoremap t :CocList symbols -" Show diagnostics of current workspace -nnoremap a :CocList diagnostics -" Show available commands -nnoremap c :CocList commands -" Show available services -nnoremap s :CocList services -" Show links of current buffer -nnoremap l :CocList link -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) -" Use K for show documentation in preview window -nnoremap K :call show_documentation() -function! s:show_documentation() - if &filetype == 'vim' - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction - -nnoremap y :CocList -A --normal yank -" ===================Denite========================== -call denite#custom#map('insert', '', '', 'noremap') -call denite#custom#map('insert', '', '', 'noremap') - -nnoremap :Denite -default-action=tabopen file/rec -nnoremap :Denite buffer diff --git a/lua/keymappings.lua b/lua/keymappings.lua new file mode 100644 index 0000000..b367f5e --- /dev/null +++ b/lua/keymappings.lua @@ -0,0 +1,16 @@ +local utils = require('utils') +vim.g.mapleader = ',' +-- Paste from clipboard +utils.map('n', 'p', '"+p') +utils.map('n', 'P', '"+P') +utils.map('v', 'p', '"+p') +utils.map('v', 'P', '"+P') + +-- Yank to clipboard +utils.map('v', 'y', '"+y') +utils.map('n', 'Y', '"+yg_') +utils.map('n', 'y', '"+y') +utils.map('n', 'yy', '"+yy') +-- Tabs and Split + +utils.map('n', 'F2', ':tabnew .') diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..068bb39 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,16 @@ +return require('packer').startup(function() + + -- Packer can manage itself as an optional plugin + use {'wbthomason/packer.nvim', opt = true} + use {'neovim/nvim-lspconfig'} + use {'nvim-treesitter/nvim-treesitter'} + use { + 'nvim-telescope/telescope.nvim', + requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}} + } + use {'sainnhe/gruvbox-material'} + use {'lukas-reineke/indent-blankline.nvim'} + use {'nvim-lua/plenary.nvim'} + use {'lewis6991/gitsigns.nvim'} + use {'kosayoda/nvim-lightbulb'} +end) diff --git a/lua/utils/init.lua b/lua/utils/init.lua new file mode 100644 index 0000000..2d1f40b --- /dev/null +++ b/lua/utils/init.lua @@ -0,0 +1,16 @@ +local utils = { } + +local scopes = {o = vim.o, b = vim.bo, w = vim.wo} + +function utils.opt(scope, key, value) + scopes[scope][key] = value + if scope ~= 'o' then scopes['o'][key] = value end +end + +function utils.map(mode, lhs, rhs, opts) + local options = {noremap = true} + if opts then options = vim.tbl_extend('force', options, opts) end + vim.api.nvim_set_keymap(mode, lhs, rhs, options) +end + +return utils \ No newline at end of file