Vim

Vim is an improved version of one of Linux’s original text editors, vi. I highly recommend that you make the effort to learn how to use this very powerful tool. Getting used to moving around and editing your text is an odd adventure. Take your time. It is complicated and well worth the effort.

Remember to use the esc key to get back into normal mode, whenever you finish editing something. There are a lot of two handed operations. You click on a key while pressing the shift, ctrl, fn, win or alt key. Sometimes you press shift and ctrl or ctrl and win at the same time you press another operation key or an arrow key. It’s keyboard gymnastics for sure.

In Normal mode enter :q to quit Vim. Use :w to write what you have changed. You can enter :wq to save your changes while exiting. Use :q! to exit without saving your changes.

Remember to write your changes often, so you can force quit a file if you mess it up some how and not lose all your previous work.

Once you get Vim installed, create your .vimrc file in your home directory. Make sure you keep an up to date copy of it, so when ever you get a new Linux installation, you can paste your .vimrc settings in.

Same with all your other apps. Save a copy of all your “dot files” in a directory of your external hard drive, so that you can easily paste them into new Linux installations.

Plugins

When I first started using Vim in 2004, Vundle was the latest greatest plugin manager for Vim. And it’s the only one I’ve always used. Go to https://github.com/VundleVim/Vundle.vim and read the README file and follow the instructions to install Vundle.

Spend some time investigating the Vim plugins. The plugins make Vim the powerful tool it is. I’ve spent many hours and days reading up on and experimenting with Vim plugins.

I’m pretty sure there is some redundancy in my plugins. I’ve got more than one plugin that does pretty much the same thing. All I know is it’s working. I’m using Vim more and more and slowly learning how it works.

When you find a plugin you want to use, just type it into your list. Then, use the :PluginInstall command to install new plugins and :PluginUpdate to keep them up to date.

Here’s my current list of plugins that you can use as an example, to get started. Pick and choose the ones you like. Edit your list every once in a while. Keep it up to date and clean, which I’m not sure mine is a very good example of. There’s probably some redundancy and unnecessary clutter in it. Keep working on understanding it and cleaning it up.

” Bob Mccoy .vimrc
” Started 9/15/2018
” Last updated 5/20/2020
” ————————————————————
set nocompatible ” be iMproved, required
filetype off ” required

” set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

” let Vundle manage Vundle, required
Plugin ‘VundleVim/Vundle.vim’
Plugin ‘tpope/vim-fugitive’
Plugin ‘tpope/vim-surround’
Plugin ‘L9’
Plugin ‘airblade/vim-gitgutter’
Plugin ‘editorconfig/editorconfig-vim’
Plugin ‘itchyny/lightline.vim’
Plugin ‘junegunn/fzf’
Plugin ‘junegunn/fzf.vim’
Plugin ‘mattn/emmet-vim’
Plugin ‘scrooloose/nerdtree’
Plugin ‘preservim/nerdcommenter’
Plugin ‘vifm/vifm.vim’
Plugin ‘vimwiki/vimwiki’
Plugin ‘vim-python/python-syntax’
Plugin ‘ap/vim-css-color’
Plugin ‘vim-utils/vim-man’
Plugin ‘leafgarland/typescript-vim’
Plugin ‘mbbill/undotree’
” …
call vundle#end() ” required
filetype plugin indent on ” required

” autocmd VimEnter * NERDTree
autocmd VimEnter * if argc() | wincmd p | endif
autocmd FileType python set sw=4
autocmd FileType python set ts=4
autocmd FileType python set sts=4

let NERDTreeShowHidden=1
nmap :NERDTreeToggle

Settings

You can install and activate Kwin’s tiling window manager. Run Zsh in one window and Vim in the another window.

I don’t really like tiling window managers. They work good in a desktop with a large monitor, but not so good on a laptop. Get in the habit of using Tmux, so you can move around the windows and panes without having to use the mouse.

Get in the habit of saving all of your config files in your external hard drive. Edit and polish your config files every once in a while, so you don’t have to start from scratch every time you install Linux.

My Current Vim Settings


set showcmd ” show command in bottom bar
” set cursorline ” highlight current line
set wildmenu ” visual autocomplete for command menu
set lazyredraw ” redraw only when we need to
set showmatch ” highlight matching [{()}]
set incsearch ” search as characters are entered
set hlsearch ” highlight matches
set foldenable ” enable folding
set foldlevelstart=10 ” open most folds by default
set foldnestmax=10 ” 10 nested fold max
set foldmethod=indent ” fold based on indent level
set linebreak ” break lines at spaces
set backspace=indent,eol,start ” allow backspace over indent,etc
set tabstop=4 softtabstop=4
set expandtab
set smartindent ” auto indent when adding brackets
set smartcase
set laststatus=2 ” always display status line
set ruler ” display cursor position on status line
set confirm ” ask to saved changed files
set cmdheight=2 ” set command height to 2 lines
set number ” show line numbers
set relativenumber ” number lines relative to line curser is on
set ttymouse=sgr ” enable mouse in vim

” toggle paste mode with
set pastetoggle=<F9>

” space open/closes folds
nnoremap <space> za
nmap <F4> :NERDTreeToggle<CR>
inoremap {<CR> {<CR>}<c-o><s-o>
inoremap [<CR> [<CR>]<c-o><s-o>
inoremap (<CR> (<CR>)<c-o><s-o>
vmap <F6> :!xclip -f -sel clip<CR>
map <F7> mz:-lr !xclip -0 -sel clip<CR>`z
map ; :

” Easy movement between buffers
let g:buftabs_only_basename=1
noremap <C-p> :bprev<CR>
noremap <C-n> :bnext<CR>

” Copy and paste to system clipboard
vnoremap <C-c> “+y
map <C-v> “+P

” Copy and paste to primary selection
vnoremap <C-c> “*y :let @+=@*<CR>

” bind ctrl+ keys to move around the windows
map <c-h> <c-w>h
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l

” color iceberg
filetype indent on ” load filetype-specific indent files
syntax enable ” enable syntax processing

” allows cursor change in tmux mode – Turns cursor into a line, rather than a square, when I’m in insert mode
if exists(‘$TMUX’)
let &t_SI = “\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\”
let &t_EI = “\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\”
else
let &t_SI = “\<Esc>]50;CursorShape=1\x7”
let &t_EI = “\<Esc>]50;CursorShape=0\x7”
endif

Note that my map leader is set to space. I copied most of this from a variety of websites over many years. It’s working. When I learn something new and changes seem appropriate, I update it.

Now that I’m using Vim more and more, instead of using Kate most of the time, I’ve noticed that there is a lot I have to learn about Vim and these plugins and settings.

Switching from Kate to Vim slows you down at first. The payoff is getting a lot faster in the long term. Get in the habit of working in the shell all the time. Use Zsh, Vim, Vifm and Qutebrowser. Read the documentation. Watch a lot of videos about the subject. It will take months to become a smooth Vim operator.

Use your help directory using :help followed by the name of whatever you have questions about.

The context in which you use Vim is an important factor. My current favorite suite of tools includes Kitty, Zsh, Vim, Tmux and Ranger. I usually have Dolphin and Kate open in another KDE Plasma workspace. Dissenter is open in another workspace. I set up four workspaces and use <Ctrl-F1> <Ctrl-F2> <Ctrl-F3> <Ctrl-F4> to move from one KDE workspace to another.

You’ve got a lot of really good alternatives to choose from. Use Vivaldi and DuckDuckGo for research. I’ve also recently discovered QuteBrowser, which I can use to browse the Internet from within my terminal/shell. Get in the habit of using Vim, Vifm and Qutebrowser to do all your work.

Vim is feeling a lot more comfortable than it use to, not so long ago, let alone when I first started using it back in 2004 or so. Read the Vim manual. You can read it in Vim or download a pdf of it. Study Vim and all of your plugins.

You need to have a project to work on to develop the muscle memory of how to work with these tools. Get your local development environment set up with C++, QML, Javascript, Git and SSH. Clone the Kontact and Calligra source files into your environment and start working on improving them.

It’s just like riding a bike. Practice. You’ll have to do a lot of research. You’ll figure it out and then you’ll get better and faster as you get familiar with the workflow.

Exit Vim without saving with ZQ, use ZZ to save changes and quit.

zz puts the line your cursor is on in the middle of the page. zt puts the line your cursor is on at the top of the page. zb puts it at the bottom of the page.

Entering this command into your .zshrc file switches the esc and caps lock keys globally.

setxkbmap -option caps:swapescape