The Vim editor offers the ability to connect to a Vim server and make it perform various tasks from outside of Vim. The command-line tools vim-client-edit, vim-client-diff and the vim_client Python module, written by James Cherti, can be used to easily find and connect to a Vim server and make it perform the following tasks:
Edit files or directories in new tabs (The command-line tool vim-client-edit),
Diff/Compare up to eight files (The command-line tool vim-client-diff),
Evaluate expressions and return their result (The Python module vim_client),
Send commands and expressions to Vim (The Python module vim_client).
The command-line tools vim-client-edit and vim-client-diff are especially useful when a quick edit or comparison needs to be performed on a file from outside of Vim (e.g. from a shell like Bash, Zsh, Fish, etc.).
Additionally, the vim_client Python module allows running expressions on a Vim server and retrieving their output, which can be useful for automating tasks or scripting. For example, you can use vim-client to run a search and replace operation on a file or directory, or to perform a complex diff operation between two files.
Overall, vim-client is a powerful tool for interacting with Vim from the vim-client-edit and vim-client-diff command-line tools. The vim_client Python module can also be used to run and retrieve the output of Vim expressions, which can help automate various tasks.
The Vim editor must be started with the option “–servername”, which enables the Vim server feature that allows clients to connect and send commands to Vim:
$ vim --servername SERVERNAMECode language:plaintext(plaintext)
Make Vim server edit multiple files in tabs
Editing a list of files in new tabs:
$ vim-client-edit file1 file2 file3
Make Vim server diff files (like vimdiff)
Comparing/diff up to eight files:
$ vim-client-diff file1 file2
Useful ~/.bashrc aliases:
Adding the following aliases to ~/.bashrc is recommended as it makes it easy to execute the command-line tools vim-client-edit and vim-client-diff:
alias gvim=vim-client-edit
alias vim=vim-client-edit
alias vi=vim-client-edit
alias vimdiff=vim-client-diff
The Vim color scheme jamescherti/vim-tomorrow-night-deepblue is a beautiful deep blue variant of the “Tomorrow Night” colorscheme, which is renowned for its elegant color palette. It is pleasing to the eyes and is easy to read (The colorscheme was previously called tomorrow-night-seablue).
The “Tomorrow Night Deepblue” color scheme features a deep blue background color that creates a calming atmosphere. The contrasting colors make it easy to distinguish between different elements of your code. The tomorrow-night-deepblue colorscheme is also a great choice for programmer who miss the blue themes that were trendy a few years ago.
The theme was inspired by classic DOS text editors such as QuickBASIC, RHIDE, and Turbo Pascal, which featured blue backgrounds by default. There’s something special about the early days of programming and the tools we used that brings back fond memories.
Install the tomorrow-night-deepblue colorscheme with Vim’s built-in package manager (Vim 8 and above)
mkdir -p ~/.vim/pack/jamescherti/start
cd ~/.vim/pack/jamescherti/start
git clone --depth 1 https://github.com/jamescherti/vim-tomorrow-night-deepblue
vim -u NONE -c "helptags vim-tomorrow-night-deepblue/doc" -c qCode language:Bash(bash)
The following Vim script (VimL) function can be used to make Vim open the documentation of the word under the cursor in a new tab for various languages and tools such as Vim help (:help), Python (Pydoc), Markdown (sdcv dictionary), man pages (Vim’s built-in ‘:Man’), and Ansible (ansible-doc).
The VimL function is also extensible, meaning that you can adapt it to work with any other documentation tool. By default, the key mapping upper-case “K” can be used to open the documentation for the word under the cursor in a new tab.
" Language: Vim script" Author: James Cherti" License: MIT" Description: Vim: open help/documentation in a new tab " (Vim script, Python, Markdown, man pages, Ansible...)." Press upper-case K to open help for the word under the cursor." URL: https://www.jamescherti.com/vim-open-help-documentation-in-a-new-tab/function! TabHelp(word)abortletl:cmd = ''letl:tabhelpprg = get(b:, 'tabhelpprg', '')
ifl:tabhelpprg ==# ''
normal! K
returnendififl:tabhelpprg[0] ==# ':'ifstridx(l:tabhelpprg, '%s') ==# -1executel:tabhelpprgelseexecuteprintf(l:tabhelpprg, fnameescape(a:word))
endifreturnelseletl:cmd = 'silent read! 'ifstridx(l:tabhelpprg, '%s') ==# -1letl:cmd .= l:tabhelpprgelseletl:cmd .= printf(l:tabhelpprg, shellescape(a:word))
endifendifexecute'silent tabnew help:' . fnameescape(a:word)
setlocal modifiable
silent normal! ggdG
silent normal! 1Gdd
ifl:cmd !=# ''executel:cmdendifsilent normal! gg0
setlocal nomodifiable
setlocal noswapfile
setlocal nowrap
setlocal nonumber
setlocal nomodified
setlocal buftype=nofile
setlocal bufhidden=deleteifexists('&relativenumber')
setlocal norelativenumber
endififexists('&signcolumn')
setlocal signcolumn=noendifsetlocal nofoldenable
setlocal foldcolumn=0endfunctionaugroup TabHelp
autocmd!
autocmd FileType vimletb:tabhelpprg = ':tab help %s'autocmd FileType sh,zsh,csh if ! exists(':Man') | runtime ftplugin/man.vim | endif | letb:tabhelpprg = ':tab Man %s'autocmd FileType yaml.ansible ifexecutable('ansible-doc') | letb:tabhelpprg = 'ansible-doc %s' | endifautocmd FileType markdown ifexecutable('sdcv') | letb:tabhelpprg = 'sdcv %s' | endifautocmd FileType vim,sh,zsh,csh,yaml.ansible,markdown nnoremap<silent><buffer> K :call TabHelp(expand('<cword>'))<CR>augroup ENDCode language:Vim Script(vim)
The following code snippet will allow you to apply the Tango Dark color scheme to the Vim’s built-in terminal and ensure that the terminal’s color scheme remains consistent, even if you change the Vim color scheme with the ‘:colorscheme’ command.
The snippet uses autocmd to ensures that the Vim terminal’s color scheme remains Tango Dark.
For more information about Vim’s built-in terminal:
The following Vim script (VimL) code snippet can be used to replace the full path of a home directory in a string with a tilde (“~”). This can be useful as a way to shorten the path to a file or directory, making it more readable.
" Language: Vim script" Author: James Cherti" License: MIT" Description: A function that replaces the home directory " with a tilde (e.g. '/home/user/file.txt' will " be replaced with '~/file.txt')." URL: https://www.jamescherti.com/vim-script-replace-the-home-directory-with-a-tilde/function! ReplaceHomeWithTilde(path)abortletl:path = fnamemodify(a:path, ':p')
letl:path_sep = (!exists('+shellslash') || &shellslash) ? '/' : '\'letl:home = fnamemodify('~', ':p')
ifl:path[0:len(l:home)-1] ==# l:homereturn'~' . l:path_sep . l:path[len(l:home):]
elseifl:path == l:homereturn'~' . l:path_sependifreturnl:pathendfunctionCode language:Vim Script(vim)
The Vim plugin vim-easysession, written by James Cherti, offers a convenient and effortless way to persist and restore Vim editing sessions. It can significantly increase productivity and save a lot of time for users who frequently switch between different projects and those who frequently open and close the Vim editor.
In addition to its automatic session management capabilities, the Vim plugin Easysession also offers a variety of useful Vim commands that allow users to save, switch, list and delete sessions manually.
Easysession features
Save and restore the session “main”, which includes various settings such as the font, background, and color scheme (The &guifont, &background, and the color scheme are also part of the session file that is generated by Easysession)
Auto-complete the Vim commands :EasySessionLoad and :EasySessionRemove
Specify the directory where the session files are located: let g:easysession_dir = expand('~/.my_vim_sessions')
Save the session: :EasySessionSave
Switch to a different session: :EasySessionLoad SESSION_NAME
List the available sessions: :EasySessionList
Delete a session with: :EasySessionRemove SESSION_NAME
The Vim plugin Easysession can be installed with Vim’s built-in package manager (Vim 8 and higher):
mkdir -p ~/.vim/pack/jamescherti/start
cd ~/.vim/pack/jamescherti/start
git clone --depth 1 https://github.com/jamescherti/vim-easysession
vim -u NONE -c "helptags vim-easysession/doc" -c qCode language:JavaScript(javascript)
The plugin can also be installed with any third-party plugin manager such as Pathogen or Vundle.
Conclusion
The Vim plugin Easysession provides an easy and effortless way to persist and restore Vim editing sessions. Its automatic session management capabilities, manual commands, auto-complete feature, and its ability to specify the directory for saves session are all valuable features that make it easy to manage Vim editing sessions.
If you are looking for a way to manage and organize your Vim session more efficiently, the Easysession Vim plugin is an excellent option to consider.
Vim’s popularity is largely due to its ability to increase productivity through efficient navigation and editing techniques. One such technique is HJKL navigation, which allows using the H, J, K, and L keys to move the cursor left, down, up, and right. This method of navigation may seem strange at first, but it is actually a very efficient way to navigate through text and can greatly increase productivity when using Vim.
In addition to that, the HJKL navigation can help reduce wrist strain, as it allows moving the cursor without having to reach for the arrow keys, which are located in a position that can cause wrist to bend and flex in an unnatural position.
However, HJKL navigation can be hard to learn at first, because it requires using unfamiliar key combinations to move the cursor. One way of making it easier to learn HJKL navigation is by using the Vim plugin Hjklmode, written by James Cherti. You can use the Vim plugin to force yourself to rely on HJKL navigation to move around the text.
One of the key features of the Vim plugin Hjklmode is its ability to disable certain keys that require moving the hand away from the Touch Typing position, which can disrupt typing flow. These keys include: Backspace, Insert, Delete, Home, End, Page Up and Page Down, Arrows.
In addition to disabling certain keys, the Vim plugin Hjklmode also adds key mappings for Alt+h, Alt+j, Alt+k, Alt+l to Insert Mode, Command Mode, and Terminal Mode, which allow moving the cursor even in those modes.
Overall, the Hjklmode Vim plugin is a great tool for those looking to learn the HJKL navigation to increase their efficiency and productivity. Whether you are a beginner or an experienced Vim user, the Hjklmode Vim plugin can help you break the habit of moving your hand away from the home row/Touch Typing position.