diff --git a/modules/qualifying/assets/vim_03.png b/modules/qualifying/assets/vim_03.png index 7cd20e1..695cfc6 100644 Binary files a/modules/qualifying/assets/vim_03.png and b/modules/qualifying/assets/vim_03.png differ diff --git a/modules/qualifying/assets/vimrc_vundle b/modules/qualifying/assets/vimrc_vundle new file mode 100644 index 0000000..3791408 --- /dev/null +++ b/modules/qualifying/assets/vimrc_vundle @@ -0,0 +1,88 @@ +" ---------------------------------------------------------------------------- +" vundle essentials +" ---------------------------------------------------------------------------- + +set nocompatible +filetype off + +" set the runtime path to include Vundle and initialize +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() +Plugin 'VundleVim/Vundle.vim' + +" ADD PLUGINS HERE +Plugin 'jiangmiao/auto-pairs' +Plugin 'preservim/nerdtree' + +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 + +" hide the documentation popup +set completeopt-=preview + +" ---------------------------------------------------------------------------- +" 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 diff --git a/modules/qualifying/learning_vim_configuration.md b/modules/qualifying/learning_vim_configuration.md index 122ca0e..d1d4c8e 100644 --- a/modules/qualifying/learning_vim_configuration.md +++ b/modules/qualifying/learning_vim_configuration.md @@ -295,8 +295,205 @@ Let me walk you through an example. 6. Go into **insert** moder after `hipp` and type `` again. Nice no? - +You can set this dictionary file to any text file you want and it will autocomplete from it. ## Beyond vanilla vim -TODO +You can extend vim's behavior by installing plugins. +There are to ways to do this, either manually by telling vim to source the plugin files, or to use a **plugin manager**. +I *highly* advise you to use a plugin manager. +There are multiple to choose from but I always go with [Vundle](https://github.com/VundleVim/Vundle.vim), mostly out of habit. +You're of coarse free to use any plugin manager you want but from here on out I assume you're using Vundle. + +### Installing Vundle + +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! + +``` +➜ ~ git:(master) ✗ sudo apt install git curl +Reading package lists... Done +Building dependency tree... Done +Reading state information... Done +curl is already the newest version (7.74.0-1.3+b1). +git is already the newest version (1:2.30.2-1). +0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded. +➜ ~ git:(master) ✗ +``` + +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. + +``` +git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim +``` + +Next we need to add a few **essential** lines to the vimrc. +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. + +``` +" ---------------------------------------------------------------------------- +" vundle essentials +" ---------------------------------------------------------------------------- + +set nocompatible +filetype off + +" set the runtime path to include Vundle and initialize +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() +Plugin 'VundleVim/Vundle.vim' + +" ADD PLUGINS HERE + +call vundle#end() + +filetype plugin indent on +``` + +### Adding some basic plugins + +We'll install a few basic plugins first. +The following projects are some I deem pretty essential but your milage may vary. + +* [autopairs](https://github.com/jiangmiao/auto-pairs) to autmatically add matching closing brackets etc +* [NERDTree](https://github.com/preservim/nerdtree) to add a file browser to vim + +You can find installation instructions on their git pages but it's most of the time pretty simple. +Between the `call vundle#begin()` and the `call vundle#end()` functions we'll add the plugins on separate lines. +Each plugin is a path to the github `$USERNAME/$REPOSITORYNAME`. +Once they are added we need to install them and this is done by calling `:VundleInstall`. + +![installing plugins](./assets/vim_03.png) + +It's done! +To close this window we can call `:close` and try out our plugins. +Open up a new text file with `:edit plugintest.md` and try the autopairs by typing any brackets you want. +The corresponding closing bracket will insert automatically. +To open up the NERDTree plugin type `:NERDTreeToggle` to show and hide the file browser. + +### Configuring the plugins + +To show and hide NERDTree a lot of people *map* a keyboard shortcut to the `:NERDTreeToggle` command. +This can be done by adding a configuration line **after** the plugin is loaded. +I tend to have three basic blocks in my vimrc and I would advise you to do the same. + +1. load vundle and the plugins +2. my basic modifications +3. plugin configuration + +So all the way at the bottom of my vimrc I would add the following. + +``` +" map a keyboard shortcut to show and hide NERDTree +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). + +``` +" 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). + +``` +" ---------------------------------------------------------------------------- +" vundle essentials +" ---------------------------------------------------------------------------- + +set nocompatible +filetype off + +" set the runtime path to include Vundle and initialize +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() +Plugin 'VundleVim/Vundle.vim' + +" ADD PLUGINS HERE +Plugin 'jiangmiao/auto-pairs' +Plugin 'preservim/nerdtree' + +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 + +" hide the documentation popup +set completeopt-=preview + +" ---------------------------------------------------------------------------- +" 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 +``` + +### Notes + +`man systemd.unit 2>/dev/null| grep --color -P "^[[:space:]]{2,}[[:<:]][A-Z]\w+[=]{0,1}$" | sed -e 's/[[:space:]]//g'`