Jesse Harris IT

A blog about IT and other things I find interesting

How I Code

May 24, 2018 — Jesse Harris

Updated 17/08/2018

Coding can be fun. I've enjoyed coding from a young age, starting with GW-Basic at maybe 6, 7, or 8.

I remember my brother Alex seemed like a real genius with the computer (an IBM clone made by Acer 8086 XT). Using Basic he could make the computer do anything and was writing his own games.

Back then, editing code we would laugh at today and we take the humble text editor for granted. Take this example, you would type list to see your code:


    30 $I = INPUT

To edit a line of code you would re-write it by typing it in, line number and all.


And to insert a line, start a line with a number between existing lines

    31 $A=$I

When you ran out of in-between-lines there was a command you could run to reindex your lines which would space them all out 10 between each other.

Anyhow, when my Dad was about the same age as I am now (35), he went back to University to study Computer Science. I remember him bringing home Slackware and RedHat on floppies, which we would install and he would give me lessons on using Vi possibly vim, but I didn't know at the time. (This is probably around 1996).

Since finishing School and entering the workforce I have mostly worked in Windows environments. Even still, with the occasionaly need to touch GNU/Linux at work and often testing Distro's at home I would always feel more efficient when using Vi/m.

My feeling when using another editor is that moving around and changing text feels so lethargic when done one button at a time. This drove me in recent years to keep a copy in my home profile.

Around 2011 I switched from VBScript and the occasional perl script to writing fulltime in Powershell, so it made sense to try a few different editors which are more native to the Windows platform. I tried Visual Studio Code, Powershell ISE, Notepad++ and still kept coming back to vim.

Visual Studio Code is a great alternative, and it's Powershell extensions are very good. Hoever being an electron app, it suffers from performance and memory consumption issues. I love squeezing every drop of battery out of my PC and when you see 7mb RAM on Vim vs 500Mb+ on VSCode, you might rethink your choices.

Therefore I've resorted to delving into the world of customizing vim and setting up plugins.

One of the main things I'm trying to acheive is a cross platform configuration. You see, at work I'm on Windows and MacOs and at home I'm on Gentoo Linux. So I have written my .vimrc file to work on any platform. I usually sync it with OneDrive for Business and symlink it into my linux/mac/Windows home directory with a seperate setup script. Without further ado, here it is with some comments


if has("win32")                               " Check if on windows \
                                              " Also supports has(unix)
    source $VIMRUNTIME/mswin.vim              " Load a special vimscript \
                                              " ctrl+c and ctrl+v support
    behave mswin                              " Like above
    set ff=dos                                " Set file format to dos
    let os='win'                              " Set os var to win
    set noeol                                 " Don't add an extra line \
                                              " at the end of each file
    set nofixeol                              " Disable the fixeol : Not \
                                              " not sure why this is needed
    set backupdir=~/_vimtmp,.                 " Set backupdir rather \
                                              " than leaving backup files \
                                              " all over the fs
    set directory=~/_vimtmp,.                 " Set dir for swp files \
                                              " rather than leaving files \
                                              " all over the fs
    set undodir=$USERPROFILE/vimfiles/VIM_UNDO_FILES " Set persistent undo\
                                              " files
                                              " directory
    let plug='$USERPROFILE/.vim'              " Setup a var used later to \
                                              " store plugins
    set shell=powershell                      " Set shell to powershell \
                                              " on windows
    set shellcmdflag=-command                 " Arg for powrshell to run
    set backupdir=~/.vimtmp,.
    set directory=~/.vimtmp,.
    set undodir=$HOME/.vim/VIM_UNDO_FILES
    let uname = system('uname')               " Check variant of Unix \
                                              " running. Linux|Macos
    if uname =~ "Darwin"                      " If MacOS
        let plug='~/.vim'
        let os='mac'                          " Set os var to mac
        if isdirectory('/mnt/c/Users/jpharris')
            let plug='/mnt/c/Users/jpharris/.vim'
            let os='wsl'
            let plug='~/.vim'
            let os='lin'

execute "source " . plug . "/autoload/plug.vim"
if exists('*plug#begin')
    call plug#begin(plug . '/plugged')       " Enable the following plugins
    Plug 'tpope/vim-fugitive'
    Plug 'junegunn/gv.vim'
    Plug 'junegunn/vim-easy-align'
    Plug 'jiangmiao/auto-pairs'
    "Plug 'vim-airline/vim-airline'          " Airline disabled for perf
    Plug 'morhetz/gruvbox'
    Plug 'ervandew/supertab'
    Plug 'tomtom/tlib_vim'
    Plug 'MarcWeber/vim-addon-mw-utils'
    Plug 'PProvost/vim-ps1'
    Plug 'garbas/vim-snipmate'
    Plug 'honza/vim-snippets'
    call plug#end()
                                             " Remove menu bars
if has("gui_running")                        " Options for gvim only
    set guioptions -=m                       " Disable menubar
    set guioptions -=T                       " Disable Status bar
    set lines=50                             " Set default of lines
    set columns=80                          " Set default of columns
    if os =~ "lin"
        set guifont=Fira\ Code\ 12
    elseif os =~ "mac"
        set guifont=FiraCode-Retina:h14
        set guifont=Fira_Code_Retina:h12:cANSI:qDRAFT
        set renderoptions=type:directx
        set encoding=utf-8
    set background=dark
    colorscheme gruvbox
    set mouse=a
    if has('termguicolors')
        set termguicolors                    " Enable termguicolors for \
                                             " consoles which support 256.
        set background=dark
        colorscheme gruvbox

if has("persistent_undo")
    set undofile                             " Enable persistent undo

colorscheme evening                          " Set the default colorscheme
                                             " Attempt to start vim-plug

syntax on                                    " Enable syntax highlighting
filetype plugin indent on                    " Enable plugin based auto \
                                             " indent
set tabstop=4                                " show existing tab with 4 \
                                             " spaces width
set shiftwidth=4                             " when indenting with '>', \
                                             " use 4 spaces width
set expandtab                                " On pressing tab, insert 4 \
                                             " spaces
set number                                   " Show line numbers

" Map F5 to python.exe %=current file
nnoremap <silent> <F5> :!clear;python %<CR>
" Remap tab to auto complete 
imap <C-@> <C-Space>
" Setup ga shortcut for easyaline in visual mode
nmap ga <Plug>(EasyAlign)
" Setup ga shortcut for easyaline in normal mode
xmap ga <Plug>(EasyAlign)"

Link to vimrc on github

Tags: vim, coding, windows, linux, macos

Comments? Tweet  

Using the latest vim on Gentoo

May 22, 2018 — Jesse Harris

Most people (including myself until recently), think of Gentoo as a bleeding edge source distribution. This is pretty far from accurate as most packages marked stable are quite out of date. And even if you decide to accept all unstable packages by adding:


to your make.conf file, you will likely be a bit disappointed when you can't get the latest gnome bits.

As my last post indicated, I'm a bit of a vim user and I want to have the latest vim on all my machines (Windows at work, WSL/Ubuntu 18.04 on the Windows box, and Gentoo at home). To that end, here is the simple thing you need to do to get the latest Vim on Gentoo:


  1. Add a special keyword to vim's ACCEPT_KEYWORDS var
  2. Unmerge existing vim
  3. emerge the new vim


Newer versions of portage allow /etc/portage/package.keywords to be a directory with simple files so that you can seperate files for seperate packages. Now, lets check if it is a file or dir and convert it if it is a directory.

    cd /etc/portage
    if test -f package.keywords; then
        mv package.keywords keywords
        mkdir package.keywords
        mv keywords package.keywords/

And now, lets use the special keyword for the vim package which will allow ebuilds from github

    echo app-editors/vim "**" > package.keywords/vim
    echo app-editors/gvim "**" >> package.keywords/vim
    echo app-editors/vim-core "**" >> package.keywords/vim

Unmerge existing vim

    emerge --unmerge app-editors/vim app-editors/gvim

Merge the new vim

    emerge app-editors/vim app-editors/gvim

Final thoughts.

This is the way I did it, but thinking about it now, it may be unnessecary to unmerge vim. You could probably get away with running emerge --update vim gvim

Tags: gentoo, vim, git, ebuild

Comments? Tweet