-
Notifications
You must be signed in to change notification settings - Fork 5
vim neovim Notes
- General
- Searching for Patterns
- Getting Italic font working
- Python Support
- Working with Cursor color & shape
- Working with
netrw - Working with wildmenu
- Spell Checking
- Visual Block mode
- Documentation
- Working with tabs
- Profiling
- Plugins
- Working with Vimscript
- Vimscript Useful Links
- Useful Links
- TODOs
To get clipboard support working with Vim when installing Vim 8.x on Debian, make sure the following dependencies have been installed.
libx11-devlibxtst-dev
apt-get install libx11-dev libxtst-devIf Vim has already been installed via brew it can be reinstalled,
brew -v reinstall --build-from-source --with-client-server vimTo test if xclip is working within a remote ssh session
echo "copy me" | xclip -selection clipboardTo override default settings for specific filetypes use the after directory located within $HOME/.vim, ie. for specific settings related to python
$HOME/.vim/after/ftplugin/python.vim
Vim / Neovim allows one to create a new file / buffer within a directory that does not yet exist, so it can become problematic to save the newly created buffer to disk if the directory doesn't exist within the file system. Β―\(γ)/Β―
To work around the above mentioned scenario use the command within the vimrc file present in the dotfiles repo.
:,mdTo print all the values of all the global or local variables, ie. python_host_prog assigned within Vim or Neovim
:letTo copy all lines of an open buffer to the system clipboard
:%y+To display a list of commands in Vim or Neovim
:CommandsTo display the decimal, octal, and hex representation of a character in Vim
g + a
To repeat the previous command or last operation
.
To show the current running version of vim or Neovim
:versionTo reload the current buffer
:editor
:source %To start Vim / Neovim without loading a .vimrc configuration file
vim -u NONETo get a high level overview of settings in Vim & Neovim
:browse optionsTo print out all the options / settings enbabled for the active buffer
:browse setTo check and see if python 3 support is working with Neovim
:echo has('python3')To check to see if Vim or Neovim was compiled with a specific setting
:echo has('[mr-fancy-setting]')ie.
:echo has('clipboard')To check and see which particular clipboard is being used, ie. unnamed or unnamedplus
:set clipboard?For more information see:
:h version
:h has(
:h feature-listTo toggle VISUAL mode
v
To toggle invisible characters
:set list!To exit PASTE mode
:set nopasteTo change the mode to visual-block or v-block
control+v
To switch between an open and closing parentheses ( or curly brace { press % in NORMAL mode.
To inspect the runtimepath
:set rtp?To print the current working directory
:pwdTo change the local working directory
:lcdTo print the $VIMRUNTIME path
echo $VIMRUNTIMETo redraw the UI elements, ie. User Interface
control + l
To print / return the value of a setting
:set option?ie.
:set autoindent?
To see where a particular setting is being set ie. which file and line is issuing the setting.
:verbose set option?
ie.
:verbose set termguicolors?To display the current key mappings for normal, visual, insert
:nmap:vmap:imapTo display all key mappings within a Neovim session
:mapTo display a value of an environment variable within a Neovim session
:echo [$MR_FANCY_ENV_VAR_01, $MR_FANCY_ENV_VAR_02]ie. to display the values of the below environment variables with Neovim
:echo [$LANG, $LC_CTYPE, $LC_ALL]To display a list of open buffers
:lsTo switch to the previous buffer
:bpTo switch to the new buffer
:bNProtip when working with autocommands, and expiermenting with new features in .vimrc or init.vim make certain to enclose autocmd! within an augroup block or the autocmd! will be reloaded, and NOT flush out the previously defined autocmd!.
A proper way to define autocommands within a .vimrc
augroup customColorscheme
" Clear the group
autocmd!
autocmd ColorScheme * call CustomHighlights()
augroup ENDSearching For Patterns the_platinum_searcher
To search for a pattern within all text / source code files within the current working directory
pt [mr-fancy-expression-to-search-for]The above command is quite useful for finding syntax errors that are scattered through a directory structure, and the specific file / line is not specified within standard error output.
Splits within Vim can be launched horizontally & vertically within a Vim session.
To a create vertical split within Vim
:vsplitTo close all splits other than the active split / window
:onBuffers can be accessed across multiple splits. π€
To learn more about using splits within Vim
:h opening-window- First, make sure the terminal can support italics
echo -e "\e[3m foo \e[23m"To get italic support working with Neovim the below line is required π
highlight Comment gui=italicTL;DR
- session files can store the state of all open buffers and much more.
- views can store the state of code folds and cursor position within a buffer.
:h sessionoptions:h viewoptionsTo manually create a session file for the current Vim session
:mks ~/.vim/tmp/sessions/[mr-fancy-session.vim]To manually create a view file that preserves code fold for the current session
:mkview ~/.vim/tmp/views/[mr-fancy-view.vim]If an existing
session.vimorview.vimfile exists the!option can be specified when runningmksormkview
ie.
To update a session file
:mks! ~/.vim/tmp/sessions/[mr-fancy-session.vim]To uninstall anaconda on macOS follow the instructions provided by the below link. Official anaconda uninstall
To setup different versions of Python for a particular user, use pyenv
pyenv can be installed via homebrew or cloning the github repo
pyenv/pyenvI chose the latter because I was running into issues using the homebrew version of pyenv.
To install pyenv on macOS
git clone https://github.com/pyenv/pyenv $code/python/pyenvTo update the list of available pythons to install
cd $PYENV_ROOT; git pullTo get virtualenv support with python install pyenv-virtualenv
git clone https://github.com/pyenv/pyenv-virtualenv $PYENV_ROOT/plugins/pyenv-virtualenvOnce those two packages have been installed, one can begin installing different versions of python.
On Debian some additional packages will need to be installed in order for python 2.7.14 to be installed, ie.
libbz2-devand
To get verbose output when building python using pyenv
pyenv install -v 2.7.14pyenv install 2.7.14To setup a virtualenv named neovim2 for the python-neovim provider packages
pyenv virtualenv 2.7.14 neovim2To activate the neovim2 virtual environment
pyenv activate neovim2To install the neovim python module for Neovim within the neovim2 virtualenv
pip install neovimThe above command
pip install neovimworks for both neovim2 and neovim3 virtual environments.
To print the path for the python executable for the neovim2 env
pyenv which pythonπ¨ when providing the path for the python executable in
init.vimMAKE CERTAIN to use the full path, ie. DON'T use the$HOMEenv var or else:checkhealthwill fail.
Add the above python path to init.vim
To activate the neovim2 virtualenv
pyenv activate neovim2To exit out of either virtualenv
pyenv deactivateTo remove a virtualenv created with pyenv and pyenv-virtualenv
pyenv uninstall [name-of-virtualenv]To check and see if vim is compiled with either python2 or python3 support
:versionTo get detailed help information about the python providers for Neovim
:help provider-pythonVim only supports python 2 or python 3, but not both at the same time.
Neovim can support both Python 2 and Python 3 at the same time.
To check and see if Neovim supports Python 3
:py3 print('hello')Each vim tab contains it's own unique splits.
To create a new tab within a session
:tabnewTo focus on the next tab
g+t
To focus on the previous tab
g+T
To move to the next tab g + t
To move to the previous tab g + T
When the wildmenu is present for navigating between files and one wants to cd into a directory use the β down arrow on the keypad to go into the selected directory.
To toggle a vertical file explorer, ie. netrw to left of the current buffer
:VexTo create a new file within the current working directory
:%then input filename.
To create a new directory using netrw d
To rename the current highlighted directory using netrw R
To close a netrw buffer,
- find the buffer number with
:ls - close the buffer with
:bd[#], ie.:bd42
To enable spell checking in vim
set spellA dictionary file may need to be downloaded before spell checking can be enabled.
To add a "misspelled" word to a local dictionary file z then g
To remove a "misspelled" word from a local dictionary file z then w
To insert into visual block mode
ctrl+v
Then select which lines you would like the repeated text to appear on.
Then go into visual insert mode with shift+i
Then type out what you want repeated and it will appear in the buffer after exiting insert mode.
When working in visual block mode to toggle between opposing corners when drawing a rectangular region.
o
To launch the help system within nvim
:helpTo generate documentation for installed plugins
:helptags ALLTo write to / save a file opened in nvim without having proper permissions
:w !sudo tee > /dev/null %For a deeper understanding of what the command is doing see
see π for more info.
To adjust the indentation of a particular line within a file
>>
To auto indent a line in vim
==
To paste code from the clipboard with indentation
:set pasteTo record the startup time of vim / nvim and load the startup time in a file
nvim --startuptime /tmp/nvim.log - minpac - is a lightweight plugin manager written around the new packages and jobs features introduced in Vim 8.x and Neovim 0.2.x
- vim-projectionist - a handy plugin for opening a source file's counterpart.
- vim-multiple-cursors - the name kind of says it all.
- limelight.vim - grey out code blocks that don't have focus
- ALE - a useful plugin for linting various source code files
- Deoplete - inline completion for Neovim.
-
vim-markdown-composer - preview the current
.mddocument in the default browser.
Working with minpac
minpac builds on top vim's job-control features introduced in Vim 8.
To print a log of messages from running PackUpdate
:messagesTo remove a plugin installed with minpac
- Remove the
call minpac#add('author/plugin-name')from your.vimrc - Save the
.vimrc
source %- Then invoke the
cleanfunction from minpac
call minpac#clean()I wrote a custom minpac binding to invoke the
cleanfunction with the below command.
:PackCleanMinpac stores plugins downloaded from git repositories in the following directories
$dots/editors/vim/vim/pack/minpac/startor
$HOME/.vim/pack/minpac/start/To print all loaded vim scripts on a seperate line
:scriptnamesTODO flesh commands that can be used with fzf and Vim to search for specific contents within a project, ie. the source files that comprise a project.
In the meantime, use the_platinum_searcher to search for specific terms within source files, ie.
To search for a miss spelling of ProTypes within a React project
pt ProTypesThe above command will search through the entire project for the syntax error and print the offending file along with the line the error occurs on to STDOUT.
The below no longer applies to my setup because I switched to
pyenvto manage pythons.
If Deoplete whines about missing neovim python module / plugin, run the below command
pip3 install --upgrade neovimWhen writing a function in Vimscript make sure the function name begins with a captial letter.
function MrFancyFucntion()
echo "Hey, There"
endfunctionTo replace a mr-fancy with mr-fancy-pants
:s/mr-fancy/mr-fancy-pantsTo replace all occurances of mr-fancy with mr-fancy-pants
:s/mr-fancy/mr-fancy-pants/gTo get some help writing Vimscripts
:help usr_41.txt:help function-listTo get the current fold method being used in a vim buffer
:set foldmethod?If the fold method is set to expr :set foldexpr? will print the current expr
To print the current fold expression for a particular file / buffer
:set foldexpr?To get native vim help for fold expressions
:help fold-exprTo expand all code folds z+shift then o
To collopase all code folds z+shift then m
- vimcasts.org - setup custom markdown code folding expr
- YouTube - wincent
- stackexchange.com - code folding
- learnvimscriptthehardway Advanced Folding
- ~~~do some research on
vim-projectionist~~~
If you find any of this info helpful on your journey π click that π βοΈ star button. It sure makes me feel warm and fuzzy π» on the inside.
-
Linux and macOS Operation Notes
- β macOS Op Notes
- π§ Linux Op Notes
- Vim & Neovim Notes
- git Notes
- π fish shell Notes
- ECMAScript Tooling
- π₯§ Raspberry Pi Notes
- asdf version manager Notes
- Bind9 Notes
- Creating a custom motd on Debian Jessie
- ECMAScript Tooling
- Email client Notes
- Email Server Setup Notes Postfix & Dovecot
- Emoji side quest
- fish shell Notes
- π₯ π€ git it got it good Notes
- git Notes
- Graphics and Image Processing Notes
- GUI text editor Notes
- π»π§ Homebrew and Linuxbrew formula Notes
- Linux and macOS Administration Notes
- Linux and macOS Troubleshooting Notes
- MacBook Pro Late 2013 Notes
- Vim & Neovim Notes
- Video Production Notes
- Python Notes
- radare Notes
- Raspberry Pi Notes
- Terminal Emulators
- Tmux Notes
- Web Browser Notes
- Weechat Notes
- Microsoft Windows Notes