diff --git a/modules/qualifying/assets/vimrc_vundle_ide b/modules/qualifying/assets/vimrc_vundle_ide new file mode 100644 index 0000000..2136a17 --- /dev/null +++ b/modules/qualifying/assets/vimrc_vundle_ide @@ -0,0 +1,224 @@ +" ---------------------------------------------------------------------------- +" vundle essentials +" ---------------------------------------------------------------------------- + +set nocompatible +filetype off + +" set the runtime path to include Vundle and initialize +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() + +" let vundle manage vundle... +Plugin 'VundleVim/Vundle.vim' + +" Basic plugins +Plugin 'jiangmiao/auto-pairs' +Plugin 'preservim/nerdtree' +Plugin 'jeetsukumaran/vim-buffergator' + +" IDE like plugins +Plugin 'prabirshrestha/asyncomplete.vim' +Plugin 'prabirshrestha/vim-lsp' +Plugin 'prabirshrestha/asyncomplete-lsp.vim' +Plugin 'mattn/vim-lsp-settings' +Plugin 'yami-beta/asyncomplete-omni.vim' +Plugin 'prabirshrestha/asyncomplete-file.vim' + +" Language autocomplete for English +Plugin 'htlsne/asyncomplete-look' + +" an additional colorscheme I like +Plugin 'altercation/vim-colors-solarized' + +call vundle#end() + +filetype plugin indent on + +" ---------------------------------------------------------------------------- +" basic essentials +" ---------------------------------------------------------------------------- + +" don't make vim vi compatible (if not set you miss out on a lot of features!) +" you'll see this option set in most configuration files found online +set nocompatible + +" enable filetype recognition plus indent and plugin (pretty much mandatory) +filetype plugin indent on " required + +" enable syntax highlighting +syntax on + +" backspace can be a tricky thing and this setting make it work a lot better +set backspace=indent,eol,start + +" when tab completing on the expert line you don't want to miss out on EDIT vs +" edit or nerdtree vs NERDTree and this setting ignores case completely +set ignorecase + +" highlight your search patterns (very handy when building regexes) +set hlsearch + +" highlight the search pattern as-you-go (tremendously helpful when +" constructing regexes) +set incsearch + +" always show a status line at the bottom of your vim which shows some basic +" information about the file, which line you're at etc +set laststatus=2 + +" show files in statusbar when opening via expert mode +set wildmenu + +" also show all possible expert mode commands in the statusline +set wildmode=full + +" reverse numbering (in the sideline) so you don't have to manually count how +" many lines you have to yank +set rnu + +" it's also nice to still have your absolute line number in the sideline +set nu + +" can do copy paste from the clipboard +set clipboard=unnamedplus + +" automatically save buffers +set autowrite +set autowriteall + +" spaces not tabs for coding purposes +set sw=4 +set ts=4 +set sts=4 + +" mouse usage can be handy, especially when using LspPeekDefinition +set mouse=a + +" enable code folding +set foldmethod=indent + +" set SPACE to toggle a fold +nnoremap za + +" set the leader key for shortcuts (uncomment if you don't want it to be the +" default \ key +"let mapleader=";" + +" ---------------------------------------------------------------------------- +" plugin configuration +" ---------------------------------------------------------------------------- + +" NERDTree +" -------- + +" map a keyboard shortcut to show and hide NERDTree +nnoremap :NERDTreeToggle + +" Exit Vim if NERDTree is the only window remaining in the only tab. +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif + +" vim-lsp +" ------- + +" general vim-lsp settings +" ------------------------ + +" maps quite q few keyboad shortcuts +" this is taken staight off the github page with one added shortcut to peak at +" the definition of a function or class +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=yes + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap gd (lsp-definition) + nmap gpd (lsp-peek-definition) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap gt (lsp-type-definition) + nmap rn (lsp-rename) + nmap [g (lsp-previous-diagnostic) + nmap ]g (lsp-next-diagnostic) + nmap K (lsp-hover) + inoremap lsp#scroll(+4) + inoremap lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 2000 + autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') +endfunction + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END + +" asyncomplete +" ------------ + +" make tab complete work +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? asyncomplete#close_popup() : "\" + +" force refresh with CTRL-SPACE +imap (asyncomplete_force_refresh) + +" asyncomplete-file +" ----------------- + +au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({ + \ 'name': 'file', + \ 'allowlist': ['*'], + \ 'priority': 10, + \ 'completor': function('asyncomplete#sources#file#completor') + \ })) + +" asyncomplete-omni +" ----------------- + +autocmd User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({ + \ 'name': 'omni', + \ 'allowlist': ['*'], + \ 'blocklist': ['c', 'cpp', 'html'], + \ 'completor': function('asyncomplete#sources#omni#completor'), + \ 'config': { + \ 'show_source_kind': 1, + \ }, + \ })) + +" asyncomplete-look +" ----------------- + +au User asyncomplete_setup call asyncomplete#register_source({ + \ 'name': 'look', + \ 'allowlist': ['text', 'markdown'], + \ 'completor': function('asyncomplete#sources#look#completor'), + \ }) + +" ---------------------------------------------------------------------------- +" visual configuration +" ---------------------------------------------------------------------------- + +" set a colorscheme +colorscheme solarized +set background=dark + +" do soft wrap of text but not in the middle of words +set wrap linebreak nolist + +" don't do hard wraps in any files +set textwidth=0 + +" add a color column at the 80 char +set colorcolumn=80 + +" spelling highlight needs to be done after the colorscheme load +highlight SpellBad term=underline cterm=underline + +" enable English spellchecking in markdown files +autocmd FileType markdown setlocal spell +autocmd FileType markdown setlocal spelllang=en diff --git a/modules/qualifying/learning_vim_configuration.md b/modules/qualifying/learning_vim_configuration.md index d1d4c8e..6c17e9a 100644 --- a/modules/qualifying/learning_vim_configuration.md +++ b/modules/qualifying/learning_vim_configuration.md @@ -58,7 +58,7 @@ For graphical vim you'll invoke `gvim`. You'll probably always want to include the following in your vimrc. You can [download](./assets/vimrc_basic) the file if you want to try it out but do take the time to read the comments. -``` +```vimscript " ---------------------------------------------------------------------------- " basic essentials " ---------------------------------------------------------------------------- @@ -164,7 +164,7 @@ As for window navigation I add the following to my vimrc but you will probably n This remaps the arrow keys, which you should **not** be using for navigation text anyway, to window navigation. If the `nnoremap` makes no sense try `:help mapping`. -``` +```vimscript " use the arrows for buffer navigation nnoremap nnoremap @@ -178,7 +178,7 @@ A lot of information about vim online is geared towards programmers and not syst You have to get comfortable with opening and navigating buffers first so a quick rundown on the basics. To do this exercise properly first prepare the following files by executing the commands below. -``` +```bash echo "I am a first file" > ~/first_file.txt echo "[unit]\nDescription=looks like a config file\nManual=maybe systemd\n" > ~/test.service echo "import datetime\n\nd = datetime.datetime.now()\nprint(d)" >python_test.py @@ -195,7 +195,7 @@ You have now opened up all three files in one vim but how do you switch from one They are loaded in memory and are called buffers. To list all buffers currently opened in vim you type `:buffers` and you should see a list like the one below. -``` +```vimscript :buffers 1 "first_file.txt" line 1 2 # "test.service" line 1 @@ -209,7 +209,7 @@ As you are opening and editing files in the same instance of vim you can yank an Try playing around with this and make some changes to some files. At some point you'll be confronted with the following message. -``` +```vimscript E37: No write since last change (add ! to override) ``` @@ -217,7 +217,7 @@ This means you're trying to switch to an other buffer but you have unsaved chang I like to add the following to my vimrc to automatically save a buffer upon leaving. Do keep in mind it can be a bit dangerous to overwrite files you're not too certain about. -``` +```vimscript " automatically save buffers set autowrite set autowriteall @@ -263,7 +263,7 @@ I personally don't like the documentation jumping up and down on my screen so yo Now to be able to view the documentation we'll need to install some plugins. I have not found a clean way of hiding the preview window *and* adding a shortcut to show documentation. -``` +```vimscript set completeopt-=preview ``` @@ -272,7 +272,7 @@ set completeopt-=preview Vim can do a lot more than just complete python code. When you press `` you'll see a menu at the bottom along these lines. -``` +```vimscript -- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y) ``` @@ -280,7 +280,7 @@ Every `^CHARACTER` is a different mode of autocomplete! Try out the `^K` one just for fun. It will probably say this the following. -``` +```vimscript 'dictionary' option is empty ``` @@ -311,7 +311,7 @@ First we'll need to install Vundle itself. This is done by cloning the repository. Make sure you have `git` and `curl` installed on your machine! -``` +```bash ➜ ~ git:(master) ✗ sudo apt install git curl Reading package lists... Done Building dependency tree... Done @@ -325,7 +325,7 @@ git is already the newest version (1:2.30.2-1). If this is the case you can go ahead and clone Vundle! This will install Vundle to your home directory in a `~/.vim/bundle` folder. -``` +```bash git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` @@ -334,7 +334,7 @@ Without this Vundle won't work! Notice the `" ADD PLUGINS HERE`; this is where we will put links to the github plugins we want to install. Vundle will take care of the installation with the `:VundleInstall` command. -``` +```vimscript " ---------------------------------------------------------------------------- " vundle essentials " ---------------------------------------------------------------------------- @@ -388,7 +388,7 @@ I tend to have three basic blocks in my vimrc and I would advise you to do the s So all the way at the bottom of my vimrc I would add the following. -``` +```vimscript " map a keyboard shortcut to show and hide NERDTree nnoremap :NERDTreeToggle ``` @@ -396,14 +396,14 @@ nnoremap :NERDTreeToggle It's also nice to automatically close NERDTree when it's the last window left. To do this we add the following (taken from the github documentation). -``` +```vimscript " Exit Vim if NERDTree is the only window remaining in the only tab. autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif ``` Our full vimrc config now looks like this and can be downloaded [here](./assets/vimrc_vundle). -``` +```vimscript " ---------------------------------------------------------------------------- " vundle essentials " ---------------------------------------------------------------------------- @@ -494,6 +494,274 @@ nnoremap :NERDTreeToggle autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif ``` +## Going full power + +There is a lot of online debate on which plugins to use, which autocomplete engine is the best, if you even need anything beyond vanilla vim, etc. +From here on out I'll just list my current personal preferences. +I've done quite a bit of tweaking an testing over the years and this list can be a shortcut for you to not having to debug as much. + +For me, autocomplete is essential. +I don't really understand *how* you can learn how to code without. +This being said, I use autocomplete for all sorts of things ranging from email to code and configuration files. +The modern way of doing autocomplete is to do it *asynchronous* meaning vim won't freeze when it's waiting on a list of possible candidates. +I'm a pretty big fan of the [Language Server Protocol](https://en.wikipedia.org/wiki/Language_Server_Protocol) and the world seems to agree it's the way to go. + +For vim I use the following plugins as a bare minimum. + +* [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim) to offer async completion +* [vim-lsp](https://github.com/prabirshrestha/vim-lsp) which is a LSP client written in vimscript +* [asyncomplete-lsp.vim](https://github.com/prabirshrestha/asyncomplete-lsp.vim) +* [mattn/vim-lsp-settings](https://github.com/mattn/vim-lsp-settings) which makes it *super* easy to install new language servers +* [yami-beta/asyncomplete-omni.vim](https://github.com/yami-beta/asyncomplete-omni.vim) to offer omni complete async +* [prabirshrestha/asyncomplete-file.vim](https://github.com/prabirshrestha/asyncomplete-file.vim) adds file path autocomplete + +This might seem like a lot but they are all pretty neat plugins that work super well together. +With this installed vim becomes a language server client and a client is nothing without a server. +You can see a list of suppored servers [here](https://github.com/mattn/vim-lsp-settings) and mattn/vim-lsp-settings makes it super easy to install one. +In order for it all to work, for python and bash, you should do a systemwide installation of python3-pip, python3-venv and npm with the following command. + +```bash +sudo apt install -y python3-pip python3-venv npm +``` + +For python just install the above mentioned plugins and open up a python file. +You'll be prompted to install [pyls](https://github.com/palantir/python-language-server) which is a very good language server. +Type `:LspInstallServer pyls-all`, wait for it to finish and you're good to go! +It might take some time to get everything initialized properly the first time you launch it, but that's quite normal. + +For bash you'll need the npm package installed. +If that's the case you just open up a script and you'll be prompted to install the server. +Type `:LspInstallServer bash-language-server`, wait a bit and you're good to go! + +The full configuration file can be seen below and downloaded [here](./assets/vimrc_vundle_ide) + +```vimscript +" ---------------------------------------------------------------------------- +" vundle essentials +" ---------------------------------------------------------------------------- + +set nocompatible +filetype off + +" set the runtime path to include Vundle and initialize +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() + +" let vundle manage vundle... +Plugin 'VundleVim/Vundle.vim' + +" Basic plugins +Plugin 'jiangmiao/auto-pairs' +Plugin 'preservim/nerdtree' +Plugin 'jeetsukumaran/vim-buffergator' + +" IDE like plugins +Plugin 'prabirshrestha/asyncomplete.vim' +Plugin 'prabirshrestha/vim-lsp' +Plugin 'prabirshrestha/asyncomplete-lsp.vim' +Plugin 'mattn/vim-lsp-settings' +Plugin 'yami-beta/asyncomplete-omni.vim' +Plugin 'prabirshrestha/asyncomplete-file.vim' + +" Language autocomplete for English +Plugin 'htlsne/asyncomplete-look' + +" an additional colorscheme I like +Plugin 'altercation/vim-colors-solarized' + +call vundle#end() + +filetype plugin indent on + +" ---------------------------------------------------------------------------- +" basic essentials +" ---------------------------------------------------------------------------- + +" don't make vim vi compatible (if not set you miss out on a lot of features!) +" you'll see this option set in most configuration files found online +set nocompatible + +" enable filetype recognition plus indent and plugin (pretty much mandatory) +filetype plugin indent on " required + +" enable syntax highlighting +syntax on + +" backspace can be a tricky thing and this setting make it work a lot better +set backspace=indent,eol,start + +" when tab completing on the expert line you don't want to miss out on EDIT vs +" edit or nerdtree vs NERDTree and this setting ignores case completely +set ignorecase + +" highlight your search patterns (very handy when building regexes) +set hlsearch + +" highlight the search pattern as-you-go (tremendously helpful when +" constructing regexes) +set incsearch + +" always show a status line at the bottom of your vim which shows some basic +" information about the file, which line you're at etc +set laststatus=2 + +" show files in statusbar when opening via expert mode +set wildmenu + +" also show all possible expert mode commands in the statusline +set wildmode=full + +" reverse numbering (in the sideline) so you don't have to manually count how +" many lines you have to yank +set rnu + +" it's also nice to still have your absolute line number in the sideline +set nu + +" can do copy paste from the clipboard +set clipboard=unnamedplus + +" automatically save buffers +set autowrite +set autowriteall + +" spaces not tabs for coding purposes +set sw=4 +set ts=4 +set sts=4 + +" mouse usage can be handy, especially when using LspPeekDefinition +set mouse=a + +" enable code folding +set foldmethod=indent + +" set SPACE to toggle a fold +nnoremap za + +" set the leader key for shortcuts (uncomment if you don't want it to be the +" default \ key +"let mapleader=";" + +" ---------------------------------------------------------------------------- +" plugin configuration +" ---------------------------------------------------------------------------- + +" NERDTree +" -------- + +" map a keyboard shortcut to show and hide NERDTree +nnoremap :NERDTreeToggle + +" Exit Vim if NERDTree is the only window remaining in the only tab. +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif + +" vim-lsp +" ------- + +" general vim-lsp settings +" ------------------------ + +" maps quite q few keyboad shortcuts +" this is taken staight off the github page with one added shortcut to peak at +" the definition of a function or class +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=yes + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap gd (lsp-definition) + nmap gpd (lsp-peek-definition) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap gt (lsp-type-definition) + nmap rn (lsp-rename) + nmap [g (lsp-previous-diagnostic) + nmap ]g (lsp-next-diagnostic) + nmap K (lsp-hover) + inoremap lsp#scroll(+4) + inoremap lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 2000 + autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') +endfunction + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END + +" asyncomplete +" ------------ + +" make tab complete work +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? asyncomplete#close_popup() : "\" + +" force refresh with CTRL-SPACE +imap (asyncomplete_force_refresh) + +" asyncomplete-file +" ----------------- + +au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({ + \ 'name': 'file', + \ 'allowlist': ['*'], + \ 'priority': 10, + \ 'completor': function('asyncomplete#sources#file#completor') + \ })) + +" asyncomplete-omni +" ----------------- + +autocmd User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({ + \ 'name': 'omni', + \ 'allowlist': ['*'], + \ 'blocklist': ['c', 'cpp', 'html'], + \ 'completor': function('asyncomplete#sources#omni#completor'), + \ 'config': { + \ 'show_source_kind': 1, + \ }, + \ })) + +" asyncomplete-look +" ----------------- + +au User asyncomplete_setup call asyncomplete#register_source({ + \ 'name': 'look', + \ 'allowlist': ['text', 'markdown'], + \ 'completor': function('asyncomplete#sources#look#completor'), + \ }) + +" ---------------------------------------------------------------------------- +" visual configuration +" ---------------------------------------------------------------------------- + +" set a colorscheme +colorscheme solarized +set background=dark + +" do soft wrap of text but not in the middle of words +set wrap linebreak nolist + +" don't do hard wraps in any files +set textwidth=0 + +" add a color column at the 80 char +set colorcolumn=80 + +" spelling highlight needs to be done after the colorscheme load +highlight SpellBad term=underline cterm=underline + +" enable English spellchecking in markdown files +autocmd FileType markdown setlocal spell +autocmd FileType markdown setlocal spelllang=en +``` + ### Notes `man systemd.unit 2>/dev/null| grep --color -P "^[[:space:]]{2,}[[:<:]][A-Z]\w+[=]{0,1}$" | sed -e 's/[[:space:]]//g'`