From 5e7d4b68f52e42c64edda9c50fe86d77eaa38c65 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Sat, 6 Jun 2020 19:11:34 +0200 Subject: [PATCH] configure vim with completion, code navigation, linting --- .gitmodules | 3 + Makefile | 8 +- docker/.vim/ftplugin/cpp.vim | 4 + docker/.vim/pack/git-plugins/start/ale | 1 + .../git-plugins/start/spacemacs-theme.vim | 1 + docker/.vimrc | 143 ++++++++++++++++++ docker/Dockerfile | 10 +- 7 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 100644 docker/.vim/ftplugin/cpp.vim create mode 160000 docker/.vim/pack/git-plugins/start/ale create mode 160000 docker/.vim/pack/git-plugins/start/spacemacs-theme.vim create mode 100644 docker/.vimrc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cde8c9c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "docker/.vim/pack/git-plugins/start/spacemacs-theme.vim"] + path = docker/.vim/pack/git-plugins/start/spacemacs-theme.vim + url = https://github.com/colepeters/spacemacs-theme.vim.git diff --git a/Makefile b/Makefile index 93b0196..821a510 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: configure build docker-build-image all build configure clean test +.PHONY: configure build docker-build-image all build configure clean test compile_commands shell DOCKER_RUN=docker run -it --mount type=bind,source="$(PWD)"/bake,target=/usr/bake ns-3-leo @@ -23,3 +23,9 @@ clean: docker-build-image test: docker-build-image $(DOCKER_RUN) /bin/bash -c 'cd source/ns-3-leo/ && ./test.py' + +compile_commands: docker-build-image + $(DOCKER_RUN) /bin/bash -c "bear ./bake.py build" + +shell: + $(DOCKER_RUN) /bin/bash diff --git a/docker/.vim/ftplugin/cpp.vim b/docker/.vim/ftplugin/cpp.vim new file mode 100644 index 0000000..f7f54de --- /dev/null +++ b/docker/.vim/ftplugin/cpp.vim @@ -0,0 +1,4 @@ +let b:ale_fixers = ['clang-format', 'remove_trailing_lines', 'trim_whitespace'] +let b:ale_linters = ['clangd'] + +setlocal tabstop=8 expandtab shiftwidth=2 smarttab diff --git a/docker/.vim/pack/git-plugins/start/ale b/docker/.vim/pack/git-plugins/start/ale new file mode 160000 index 0000000..7265ceb --- /dev/null +++ b/docker/.vim/pack/git-plugins/start/ale @@ -0,0 +1 @@ +Subproject commit 7265ceb6d050d1a4642741d248f11e4f2abd37e1 diff --git a/docker/.vim/pack/git-plugins/start/spacemacs-theme.vim b/docker/.vim/pack/git-plugins/start/spacemacs-theme.vim new file mode 160000 index 0000000..056bba9 --- /dev/null +++ b/docker/.vim/pack/git-plugins/start/spacemacs-theme.vim @@ -0,0 +1 @@ +Subproject commit 056bba9bd05a2c97c63c28216a1c232cfb91529e diff --git a/docker/.vimrc b/docker/.vimrc new file mode 100644 index 0000000..f675ea7 --- /dev/null +++ b/docker/.vimrc @@ -0,0 +1,143 @@ +filetype plugin on +filetype indent on + +set autoread +" :W sudo saves the file +" (useful for handling the permission-denied error) +command W w !sudo tee % > /dev/null + +" no command execution from modeline +set nomodeline + +" Turn on the Wild menu +set wildmenu + +" Enable hidden buffers +set hidden + +" Clipboard copy & paste +"set clipboard=unnamedplus + +" Always show current position +set ruler + +" When searching try to be smart about cases +set smartcase + +" Highlight search results +set hlsearch + +" Inenteremental search +set incsearch + +" Don't redraw while executing macros (good performance config) +set lazyredraw + +" Do not show matching brackets when text indicator is over them +" set noshowmatch +" let loaded_matchparen = 1 + +" No annoying sound on errors +set noerrorbells +set novisualbell + +set wrap +set linebreak +set nolist " list disables linebreak + +" Enable syntax highlighting +syntax enable + +if (has("termguicolors")) + set termguicolors +endif + +set t_Co=256 + +set background=dark +colorscheme spacemacs-theme + +" Use tabs for indent +set smarttab +set smartindent +set autoindent +set copyindent +set preserveindent + +set wildmode=longest,list,full +set wildmenu + +set cursorline +set number +set relativenumber + +" Transparency +"hi Normal guibg=NONE ctermbg=NONE + +"set list! +"set listchars=trail:⛤,extends:⟩,precedes:⟨,nbsp:␣,conceal:… + +" Map leader to do extra key combinations +let mapleader = " " + +" Toggle paste mode on and off +map pp :setlocal paste! + +" Fast saving +nmap w :w! + +" Buffer switching +nmap bb :Buffers +nmap bl :Buffers +nmap bn :bnext +nmap bp :bprevious + +nmap ll :Lines +nmap mm :Marks +nmap ww :Windows +nmap hh :History/ +nmap rr :reg + +" finding files +nmap ff :Files +nmap pp :FufDir + +set statusline+=%#warningmsg# +set statusline+=%{SyntasticStatuslineFlag()} +set statusline+=%* + +"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 +nmap sp :ALEFindReferences +nmap ss :ALESymbolSearch +nmap gd :ALEGoToDefinitionInTab +nmap ?? :ALEHover + +" Enable completion where available. +" This setting must be set before ALE is loaded. +let g:ale_completion_enabled = 1 + +let g:ale_fix_on_save = 1 + +let g:ale_warn_about_trailing_whitespace = 1 +let g:ale_warn_about_trailing_lines = 1 +let g:ale_completion_tsserver_autoimport = 1 + +"let g:ale_lint_on_text_changed = 'never' +" You can disable this option too +" if you don't want linters to run on opening a file +"let g:ale_lint_on_enter = 0 + +" Set airline theme +let g:airline_theme='base16_spacemacs' + +" Load all plugins now. +" Plugins need to be added to runtimepath before helptags can be generated. +packloadall +" Load all of the helptags now, after plugins have been loaded. +" All messages and errors will be ignored. +silent! helptags ALL + +set omnifunc=ale#completion#OmniFunc diff --git a/docker/Dockerfile b/docker/Dockerfile index 6295e97..7c6accf 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,6 +7,7 @@ RUN apt-get update # General dependencies RUN apt-get install -y \ + bear \ make \ git \ mercurial \ @@ -32,7 +33,8 @@ RUN apt-get install -y \ libxml2-dev \ vtun \ unzip \ - lxc + lxc \ + clangd # QT components RUN apt-get install -y \ @@ -74,3 +76,9 @@ WORKDIR /usr/bake RUN apt-get clean && \ rm -rf /var/lib/apt +RUN useradd -ms /bin/bash user + +USER user + +ADD --chown=user:user ./.vimrc /home/user/.vimrc +ADD --chown=user:user ./.vim /home/user/.vim