Please refer to README.md to learn about my vim config, its installation, and its functionalities.
Last active
June 20, 2025 13:01
-
-
Save achille-martin/84168c069fccca59dd99cb3ffa3ab7ed to your computer and use it in GitHub Desktop.
My vim config
This is my vim
config. vim
is a fast, efficient, customisable editor.
Copy/paste the following multiline command into your terminal:
sudo apt-get install git &&
mkdir -p temp_download &&
cd temp_download &&
git clone https://gist.github.com/achille-martin/84168c069fccca59dd99cb3ffa3ab7ed &&
sudo chmod +x 84168c069fccca59dd99cb3ffa3ab7ed/am_vim_config_setup.sh &&
./84168c069fccca59dd99cb3ffa3ab7ed/am_vim_config_setup.sh &&
cd .. &&
sudo rm -r temp_download
Press F12
while in vim
to display the list of custom commands
- Add debug logs for sh script
- Use functions to invoke text to be appended
- Highlight current line: https://vim.fandom.com/wiki/Highlight_current_line (Note: might make vim screen slower)
- Markdown live preview: https://github.com/iamcco/markdown-preview.nvim (Note: requires vim >=8.1)
- Install latest vim editor if really needed: https://github.com/vim/vim/blob/master/src/INSTALL (Note: for Unix/Linux)
- Add code folding capability for navigation (https://stackoverflow.com/questions/357785/what-is-the-recommended-way-to-use-vim-folding-for-python-code)
- Add way to manage session with many tabs or windows (vim-obsession not working for terminal)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Released under MIT License | |
# Copyright (c) 2023 - 2024 Achille MARTIN | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
# ------------------ INTRODUCTION ----------------- | |
# This script lets you install Achille Martin's favourite vim config | |
# WARNING: IT WILL ERASE AND REPLACE YOUR CURRENT VIM CONFIGURATION | |
# Ensure that you save your current vim configuration before installing this one | |
# This vim config has been extensively tested with Ubuntu distributions, | |
# but has not been tested with other Linux distributions or operating systems | |
# The keys are mostly optimised for French keyboard layout (AZERTY) | |
# ----------------- PRE-REQUISITES ---------------- | |
# The following commands install the required packages for any Ubuntu distribution | |
# and perform required actions on files/folders | |
sudo apt-get install vim # Installs vim packagge | |
sudo apt-get install vim-gtk3 # Installs vim-gtk3 to enable system clipboard copy/paste within vim and extra vim features | |
sudo apt-get install xsel # Installs xsel package to enable system clipboard copy/paste after exiting vim | |
sudo apt-get install git # Installs git package | |
sudo apt-get install ack-grep # Installs ack package | |
sudo rm -r "/home/$USER/.vim/bundle/Vundle.vim" # Deletes existing Vundle install | |
git clone https://github.com/VundleVim/Vundle.vim.git "/home/$USER/.vim/bundle/Vundle.vim" # Downloads Vundle, the vim plugin manager | |
# ---------------------- SETUP --------------------- | |
# This section creates the `/home/$USER/.vimrc` file and populates it | |
VIMRC_FILE="/home/$USER/.vimrc" | |
sudo rm "$VIMRC_FILE" # Deletes existing vim config | |
# Creates a new vimrc file and populates it | |
# Characters `\`, `$`, and ``` do not need to be escaped by `\` if `'EOF'` is specified | |
cat > "$VIMRC_FILE" << 'EOF' | |
" This file represents Achille Martin's favourite vim config | |
" Context: | |
" * Tested mainly on Ubuntu distributions | |
" * Optimised for French keyboard layout (AZERTY) | |
" Known issues: | |
" 1) Shared clipboard not working in WSL | |
" The shared clipboard functionality does not work with WSL (Windows Subsystem for Linux) | |
" Therefore, you need to comment out the following line from your `/home/$USER/.vimrc`: `set mouse=a`, using `"` at the beginning of the line | |
" You will be able to use `Ctrl + Shift + C` and `Ctrl + Shift + V` if allowed in your WSL preferences | |
" 2) Autopairs plugin interacts with comments in .vim files | |
" This is because the filetype uses only one `"` at the beginning of a line to comment it out | |
" The autopairing with `"` has therefore been disabled in .vim files. | |
" ____________________________________________________ | |
" This line should not be removed as it ensures that various options are | |
" properly set to work with the Vim-related packages available in Debian | |
runtime! debian.vim | |
" Set leader key | |
let mapleader = "," | |
" Define aesthetics | |
syntax on " Vim5 and later versions support syntax highlighting | |
set title " Display name of file on top of window | |
set number " Show line numbers | |
set hlsearch " Highlight all results | |
autocmd colorscheme delek highlight Search cterm=NONE ctermbg=Yellow ctermfg=Black " Set highlight search colour within colorscheme | |
colorscheme delek " Set colour taste | |
" Set file management options | |
set noswapfile " Disable the swapfile | |
" Move cursor to last known position when opening a file | |
if has("autocmd") | |
" Move cursor to last known position when opening a file | |
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif | |
endif | |
" Set search options | |
set ignorecase " Ignore case in search | |
set incsearch " Show search results as you type | |
set wildmenu " Show autocomplete matches above the command line (use arrow left-right to move around and arrow down to confirm selection) | |
set wildmode=longest:full,full " Complete the next full match and complete till longest common string while opening a wildmenu | |
set wildcharm=<Tab> " Set binding to invoke wildmenu (works in macros and mappings) | |
cmap <expr> <Tab> getcmdtype() =~ '^[/?]$' ? '<C-f>a<Tab>' : '<Tab>' " Simulate wildmenu for command-line search | |
" Define text formatting | |
set autoindent " Enable auto indentation for next lines | |
set shiftwidth=4 " Auto indentation uses 4 spaces by default | |
set expandtab " Convert a tab into spaces | |
set softtabstop=4 " Generate 4 spaces per tab or delete 4 spaces at once with backspace | |
au FileType * set fo-=c fo-=r fo-=o " Prevent the next commented out line to be commented out too | |
au FileType * set textwidth=0 " Prevent text wrapping | |
" Note that the Vim EMACS constraint is usually `textwidth=80` | |
" Enable mouse support in vim for all modes | |
set mouse=a | |
" Enable system clipboard for copy/paste | |
" This lets you copy text from within vim with the yank `y` command | |
" The copied text remains in the clipboard even after leaving vim | |
" Note that `vim-gtk3` and `xsel` packages are required | |
autocmd VimLeave * call system("echo -n $'" . escape(getreg(), "'") . "' | tr -d '\n' | xsel -ib") | |
set clipboard=unnamedplus | |
" Setup Vundle plugins | |
set nocompatible | |
filetype off | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" [BEGINNING PLUGIN LIST] Add your plugins here | |
Plugin 'VundleVim/Vundle.vim' | |
Plugin 'ctrlpvim/ctrlp.vim' | |
Plugin 'preservim/nerdtree' | |
Plugin 'jiangmiao/auto-pairs' | |
Plugin 'nvie/vim-flake8' | |
Plugin 'gnattishness/cscope_maps' | |
Plugin 'simeji/winresizer' | |
Plugin 'tpope/vim-commentary' | |
Plugin 'ervandew/supertab' | |
Plugin 'mileszs/ack.vim' | |
" [END PLUGIN LIST] | |
call vundle#end() | |
filetype plugin indent on | |
" Disable autopair on quotes `"` in .vim files | |
" to prevent unexpected behaviour with comments | |
au Filetype vim let b:AutoPairs={'(':')', '[':']', '{':'}',"'":"'", '`':'`'} | |
" Remap controls for specific actions | |
" Use `Ctrl + f` to move screen 50% forward/down | |
noremap <C-f> <C-d> | |
" Use `Ctrl + b` to move screen 50% back/up | |
noremap <C-b> <C-u> | |
" Use `Ctrl + t` to toggle the tree (`t` for tree) | |
map <C-t> :NERDTreeToggle<CR> | |
" Use `F8` to get PEP8 style checker | |
autocmd FileType python map <buffer> <F8> :call flake8#Flake8()<CR> | |
" Use `Esc then F9` to open the current file in a new tab | |
map <Esc><F9> :tabnew %<CR> | |
tmap <Esc><F9> <C-w>:tabnew<CR> | |
" Use `Ctrl + a` to switch tabs | |
map <C-a> gt | |
tmap <C-a> <C-w>:tabnext<CR> | |
" Enable tail-f functionality with `F5` on current file | |
" The file will refresh (if no modifications) after `updatetime` ms | |
" when the cursor is not moving in normal mode | |
map <F5> :set updatetime=500 \| set autoread \| au CursorHold * checktime \| call feedkeys("G")<CR> | |
" Disable tail-f functionality with `Esc then F5` on current file and set `updatetime` back to vim default value of 4000ms | |
map <Esc><F5> :set updatetime=4000<CR>:autocmd!<CR> | |
" Open a new terminal in vertical split window with `Esc then F2` (works in normal and terminal mode) | |
nmap <Esc><F2> :term<CR> | |
tmap <Esc><F2> <C-w>:term<CR> | |
" Enter edit/normal mode of terminal with `F2` | |
" Get back to terminal mode with `F2` | |
tmap <F2> <C-w>N | |
noremap <F2> i | |
" Close current file while asking to save using `Esc then q` | |
nmap <Esc>q :q<CR> | |
" Close current file without asking to save using `Esc then x` | |
nmap <Esc>x :q!<CR> | |
" Close current terminal window using `Esc then q` | |
tmap <Esc>q exit<CR><C-w>:q!<CR><Esc> | |
" Save current file using `Esc then w` | |
nmap <Esc>w :w<CR> | |
" Generate a triple window terminal and closes current window without saving its content using `Esc then F3` | |
map <Esc><F3> <Esc><C-w>:term<CR><C-w>:term<CR><C-w>j<C-w>:vertical :term<CR><C-w>j<C-w>:q!<CR> | |
tmap <Esc><F3> <Esc><C-w>:term<CR><C-w>:term<CR><C-w>j<C-w>:vertical :term<CR><C-w>j<C-w>:q!<CR> | |
" Generate a quadruple window terminal and closes current window without saving its content using `Esc then F4` | |
map <Esc><F4> <Esc><C-w>:term<CR><C-w>:term<CR><C-w>:vertical :term<CR><C-w>j<C-w>:vertical :term<CR><C-w>j<C-w>:q!<CR> | |
tmap <Esc><F4> <Esc><C-w>:term<CR><C-w>:term<CR><C-w>:vertical :term<CR><C-w>j<C-w>:vertical :term<CR><C-w>j<C-w>:q!<CR> | |
" Enter window resize mode using `Ctrl + e` (`e` for edit) and resize around current window | |
" Accept window resizing and quit resize mode using `Enter` | |
" Refuse window resizing and quit resize mode using `q` | |
" Resize window using arrow keys | |
let g:winresizer_keycode_up = "\<UP>" | |
let g:winresizer_keycode_down = "\<DOWN>" | |
let g:winresizer_keycode_left = "\<LEFT>" | |
let g:winresizer_keycode_right = "\<RIGHT>" | |
" Resize terminal windows using `Ctrl + e` | |
tmap <C-e> <C-w>:WinResizerStartResize<CR> | |
" Paste copied text on the next line using `p` | |
nmap p :pu<CR> | |
" Comment and uncomment current line or selected lines using `F6` | |
" thanks to vim-commentary plugin | |
map <F6> :Commentary<cr> | |
" Copy selected text or whole line using `Ctrl + c` | |
vmap <C-c> y | |
nmap <C-c> yy | |
" Paste text on cursor and add space after using `Ctrl + v` in normal mode and insert mode | |
" Paste text just after cursor using `Ctrl + Shift + v` in normal mode and on cursor in insert mode | |
nmap <C-v> Pli<Space><Esc> | |
imap <C-v> <Esc>lPli<Space> | |
" Cut selected text or whole line using `Ctrl + x` | |
nmap <C-x> dd | |
vmap <C-x> x | |
" Alternative way to press `Esc` using `Alt + g` | |
nmap <A-g> <Esc> | |
" Invoke a Vim Tips pop-up window containing the custom vim bindings when pressing `F12` in normal mode | |
let g:MyVimTips="off" | |
function! ToggleVimTips() | |
if g:MyVimTips == "on" | |
let g:MyVimTips="off" | |
pclose | |
else | |
let g:MyVimTips="on" | |
pedit /home/$USER/.vim/vim_tips.txt | |
endif | |
endfunction | |
nmap <F12> :call ToggleVimTips()<CR> | |
tmap <F12> <C-w>:call ToggleVimTips()<CR> | |
" Reopen last closed window with `Ctrl + j` | |
nmap <c-j> :ls<CR>:b#<CR><CR> | |
" Search for word under cursor in current directory using `F3` | |
" Note: set your current directory with `:cd <path>` and confirm it with `:pwd` | |
let &shellpipe="&>" " Prevent the output of `Ack` to leak into the terminal (might have side effects for other plugins) | |
nmap <F3> /<C-r><C-w><CR> :Ack! <C-r><C-w> --sort-files<CR> /<CR> | |
" Allow input of ignored directories for `Ack` command with `Ctrl + F3` | |
nmap <C-F3> :Ack! <C-r><C-w> --sort-files --ignore-dir= | |
" ____________________________________________________ | |
" Search tips | |
" Use `:vimgrep <pattern> %` to search for patterns in file | |
" Use `:copen` to open the quickfix window containing the lines with specified pattern | |
" Use `Ctrl + p` to access the fuzzy folder search Ctrlp | |
" and right-click to open the file in a new window | |
" If you want to go back to a previous cursor position, press `Ctrl + o` | |
" If you are looking for your cursor, you can set it to blink in your terminal preferences (not a vim param) | |
" Plugin tips | |
" Use the following commands to organise your plugins in vim: | |
" `:PluginInstall` to load plugins defined between `[BEGINNING PLUGIN LIST]` and `[END PLUGIN LIST]` in your `~/.vimrc` | |
" `:PluginUpdate` to update plugins | |
" `:PluginSearch <name>` to search for plugins | |
" `:PluginList` to list plugins | |
" `:PluginClean` or `:PluginUpdate` to remove plugins AFTER deleting them from your `~/.vimrc` | |
" Macro tips | |
" Record a macro using: `q + <register_letter> + <series_of_commands> + q` | |
" If you want to apply it onto multiple lines, use: `q + <register_letter> + <series_of_commands> + j + q` | |
" Then, you can use: `X@<register_letter>` | |
EOF | |
# ---------------------- TIPS ---------------------- | |
# This section creates the `/home/$USER/.vim/vim_tips.txt` file and populates it | |
# This file contains the custom vim command breakdown | |
VIM_TIPS_FILE="/home/$USER/.vim/vim_tips.txt" | |
sudo rm "$VIM_TIPS_FILE" # Deletes existing vim tips file | |
# Creates a new vim tips file and populates it | |
# Characters `\`, `$`, and ``` do not need to be escaped by `\` if `'EOF'` is specified | |
cat > "$VIM_TIPS_FILE" << 'EOF' | |
| VIM TIPS | | |
| Action desired | Mode | Key combination | | |
|---------------------------------------------------------|---------------------|---------------------------------------| | |
| Invoke vim tips pop-up window | ANY | F12 | | |
| Move screen 50% forward/down | NORMAL | Ctrl + f | | |
| Move screen 50% back/up | NORMAL | Ctrl + b | | |
| Move back to last cursor position (origin) | NORMAL | Ctrl + o | | |
| Open / Close folder tree structure | ANY | Ctrl + t | | |
| Open new tab | ANY | Esc + F9 | | |
| Switch tabs | ANY | Ctrl + a | | |
| Open a (vim) terminal above current window | NORMAL and TERMINAL | Esc + F2 | | |
| Enter / Exit edit mode in terminal | TERMINAL | F2 | | |
| Generate triple terminal layout (overwites current) | ANY | Esc + F3 | | |
| Generate quadruple terminal layout (overwrites current) | ANY | Esc + F4 | | |
| Resize windows | ANY | Ctrl + e (then arrow keys then Enter) | | |
| Close current file while asking to save | NORMAL | Esc + q | | |
| Close current file without asking to save | NORMAL | Esc + x | | |
| Save current file | NORMAL | Esc + w | | |
| Close current window | TERMINAL | Esc + q | | |
| Reopen last closed window | ANY | Ctrl + j | | |
| Enable tail-f functionality | ANY | F5 | | |
| Disable tail-f functionality | ANY | Esc + F5 | | |
| PEP8 checker | ANY | F8 | | |
| Autocomplete word | ANY | Tab | | |
| Search for word under cursor in current directory | ANY | F3 | | |
| Comment / Uncomment text | ANY | F6 | | |
| Copy selected text | VISUAL | Ctrl + c (or y) | | |
| Copy whole line | NORMAL | Ctrl + c (or yy) | | |
| Paste copied text on next line | NORMAL | p | | |
| Paste copied text on cursor and add space | NORMAL and INSERT | Ctrl + v | | |
| Paste copied text just after cursor | NORMAL and INSERT | Ctrl + Shift + v | | |
| Paste copied text on highlighted text | VISUAL | Ctrl + Shift + v | | |
| Cut selected text | VISUAL | Ctrl + x | | |
EOF | |
# ---------------- FINISHING TOUCHES --------------- | |
# This section applies the finishing touches to the vim config | |
vim -c PluginInstall -c qall # Installs all vim plugins defined in the `~/.vimrc` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment