Skip to content

juanMarinero/vim-install-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

License Vim NeoVim Ubuntu Contributors Stars

Index - Click to expand

Purpose

  • Out of the box installation of Neo-/Vim and its most popular plugins for Ubuntu users. Just run these steps:

Step 1 - Clone this repo

sudo apt install -y git && \
  git clone https://github.com/juanMarinero/vim-install-basic && \
  cd vim-install-basic

Step 2 - Install Vim or NeoVim

  • For Vim
chmod +x install/Vim/install.sh && \
  install/Vim/install.sh
  • For Neovim
chmod +x install/NeoVim/install.sh && \
  install/NeoVim/install.sh
echo 'vim() { nvim "$@"; }' >> ~/.bashrc

Step 3: reboot

sudo reboot

Step 4: Install plugin dependencies, plugins and their postinstalls. Run each line 1 by 1. To exit each Neo-/Vim run :qa.

cd vim-install-basic
vim +PlugInstall  # wait till shows "- Post-update hook for coc.nvim ... OK". Check :CocInfo and :VimspectorToggleLog
vim -c "source plugins/coc.nvim/postinstall2.vim" # See details :CocInfo
source plugins/coc.nvim/postinstall3.sh
vim -c "source plugins/coc.nvim/postinstall4.vim" file.c # takes a while
vim -c "source plugins/vimspector/postinstall.vim"       # takes a while, check :VimspectorToggleLog
source plugins/vimspector/postinstall.sh

See video.

Other purposes:

  • To get familiar with Neo-/Vim and its most used plugins directly, not worrying about installation nor settings
  • Modular Neo-/Vim config and install files:
README.md
.vimrc
install
  |_ Vim
    |_ ...
  |_ NeoVim
    |_ ...
general
  |_ mappings.vim
  |_ settings.vim
plugins
  |_ ale
    |_ mappings.vim
    |_ settings.vim
    |_ prerequisites.sh
    |_ postinstall.vim
    |_ filetype
      |_ ...
  |_ ...
 VirtualManager.md
 ...

What is this

  • This is a modest Neo-/Vim configuration ready to install and use in Ubuntu
  • It's for both Vim and NeoVim. That's why:
    • the plugins selected are compatible for boths
    • and it's configured with vimscripts (.vim extension) instead of Lua scripts.
    • Though one can easily edit/expand the configs for Vim-only or NeoVim-only.
  • It's a quick example of how to set up a basic Python or Javascript project. Emphasis on linters and debugging. See the MWE section.

What is NOT

  • It's not a detailed preconfiguration for Neo-/Vim. For a stronger NeoVim only preconfiguraion see NvChad in bonus.
  • It's not a swiss-knife for every user:

Manage plugins

Skip plugins

To not install some/all plugins follow next steps. Alternative install them all (see ##purpose) and then comment respective plugin lines of .vimrc (see step 2 below) to just not load them. If desired to use those then uncomment previous commented lines. This approach works if :PlugClean is not run, otherwise read install-a-plugin.

  1. Clone this repo and change to its directory
git clone https://github.com/juanMarinero/vim-install-basic
cd vim-install-basic
  1. A Move plugins directory so install.sh cannot find it.
mv -r ./plugins ./plugins.bak
  1. B Alternative if just few plugins not to install then loop it. For example:
plugins_skip=["coc.nvim" "ale"] # customize

And run

mkdir -p plugins.bak
for plugin in $plugins; then
   mv -r ./plugins/$plugin ./plugins.bak/$plugin
end
  1. Comment desired lines in-between plug#start and plug#end of .vimrc. So :PlugInstall does not install them.

  2. And run install/<NeoVim or Vim>/install.sh, vim +PlugInstall, etc. described in purpose.

Install a plugin

To install an skipped plugin of previous section

  1. Add/uncomment next 3 lines in-between plug#start and plug#end of .vimrc for the desired plugin. For example uncomment
" Plug 'puremourning/vimspector'
" source plugins/vimspector/settings.vim
" source plugins/vimspector/mappings.vim
  1. Set plugin to add. For example
plugin="vimspector"
  1. Change directory to this cloned repo cd vim-install-basic and run
cp -r plugins.bak/$plugin plugins/$plugin
./plugins/$plugin/prerequisites.sh
vim +PlugInstall
vim -c "source plugins/$plugin/postinstall.vim"

Note coc.nvim has several postinstall scripts to run in vim or shell. See plugins/coc.nvim.

Minimal Working Examples

🐍 MWE

Next is a simple Python project to mainly demonstrate:

  • How ALE linters show warnings and errors. And fixers like black auto correct some.
  • How Coc.nvim suggests code
  • How Vimspector debugs

Steps:

cd vim-install-basic

Then run

dir=$HOME/MWE_Python
mkdir -p $dir && cd $dir

venv_dir="venv"
python3 -m venv "$venv_dir"
source $venv_dir/bin/activate
which python # check

# ✨ 🍰 ✨ ALE linters & fixers
cd -
source plugins/ale/filetype/python/python.sh
cp -av plugins/ale/filetype/python/config_files/. "$dir"

# πŸ”πŸͺ² vimspector debugger
source plugins/vimspector/filetype/python/python.sh
cp -av plugins/vimspector/filetype/python/config_files/. "$dir"
vim -c "source plugins/vimspector/filetype/python/python.vim" file.py # wait and exit

And debug on an example script

[ -d "$dir" ] && cd "$dir"
wget -O main.py https://raw.githubusercontent.com/puremourning/vimspector/refs/heads/master/support/test/python/simple_python/main.py && \
  sed -i -e 's/\b100\b/10/g' -e 's/\b99\b/7/g' -e 's/\b18\b/2/g' main.py && \
  black main.py

sleep 2
vim -c "call vimspector#SetLineBreakpoint('main.py',13,{ 'condition': 'i == 3 or i == 7' })" \
    -c "call vimspector#SetLineBreakpoint(expand('%'), 25)" \
    -c "call vimspector#Launch()" \
    -c "VimspectorWatch i" \
    -c "VimspectorWatch t._var | VimspectorWatch self._var" \
    -c "VimspectorWatch hex(id(self))  | VimspectorWatch hex(id(t))" \
    -c 'sleep 2 | execute "wincmd j" | execute "wincmd L" | execute "wincmd h"' \
    -c 'sleep 1 | vertical resize +25 | resize +10 | execute "normal zR"' \
    main.py

See video.

In Viminspector execute step-ins (:call vimspector#StepInto()), continues (:call vimspector#Continue()),... Observe how conditional breakpoints pause it at i 3 and 7.

</> JS

cd vim-install-basic

Then run

repo_dir="$HOME/Downloads/vimspector"
git clone https://github.com/puremourning/vimspector "$repo_dir"

dir=$HOME/MWE_JS
mkdir -p $dir && cd $dir
cp -arv "$repo_dir/support/test/web/." .
rm -rf "$repo_dir"

# Add an HTML button that runs the desired `console.log` command
file="www/index.html"
line_to_add='   <button type="button" onclick="console.log(calculate(5,1))">Click Me to calculate(5,1)</button>'
total_lines=$(wc -l < "$file")
insert_line=$((total_lines - 1)) # Subtract 1 from the total number of lines
sed -i "${insert_line}i\ $line_to_add" "$file" # Insert the new line at the calculated position

# ✨ 🍰 ✨ ALE linters & fixers
cd -
cp -av plugins/ale/filetype/javascript/config_files/. "$dir"
cp plugins/ale/filetype/javascript/javascript.sh "$dir"
cd - && ./javascript.sh && rm javascript.sh && cd -

# πŸ”πŸͺ² vimspector debugger
source plugins/vimspector/filetype/javascript/javascript.sh
sudo apt install -y moreutils
deb="$dir/.vimspector.json"
jq '.configurations = {chrome: .configurations.chrome}' "$deb" | sponge "$deb"
jq '.configurations.chrome += {"breakpoints": {"exception": {"all": "", "uncaught": ""}}}' "$deb" | sponge "$deb"
vim -c "source plugins/vimspector/filetype/javascript/javascript.vim" file.js # wait and exit

And debug www/js/test.js

[ -d "$dir" ] && cd "$dir"

# Port 1234
# chmod +x run_server && ./run_server # if PHP installed
nohup python3 -m http.server 1234 > /dev/null 2>&1 & # Serving HTTP on 0.0.0.0 port 1234 (http://0.0.0.0:1234/)
ss -tulnp | grep 1234 # Check

# Note: breakpoint at line 27 to watch variable values of last loop iter
vim -c "ALEToggle" \
    -c "call vimspector#SetLineBreakpoint(expand('%'), 24)" \
    -c "call vimspector#SetLineBreakpoint(expand('%'), 27)" \
    -c "call vimspector#Launch()" \
    -c "VimspectorWatch a | VimspectorWatch b | VimspectorWatch i" \
    -c "execute 'normal 24ggzv'" \
    www/js/test.js

Previous command :call vimspector#Launch() opens the respective adapter-browser, there open the www website. Then:

  • Run for example the command calculate(5,1):
    • Opt. A: in the console window of Vimspector run (to insert text press 'i'): calculate(5,1)
    • Opt. B: in browser's console (Open Web-Developer-Tools with Ctrl+Shift+I and go to tab Console) run calculate(5,1)
    • Opt. C: in browser click the HTML button that says Click Me to calculate(5,1). See video.

In Viminspector execute step-ins (:call vimspector#StepInto()), continues (:call vimspector#Continue()),... observe how variables a, b and i evolve.

Alternative use the Google-Chrome debugger:

  • Open Web-Developer-Tools (Ctrl+Shift+I)
  • Go to tab Sources
  • Open the tab of the JS file

Note that the Google-Chrome debugger window gets on top when a Vimspector command is run, solve this closing the Google-Chrome debugger (Ctrl+Shift+I toggles it).

Free the port when done debugging

sudo pkill -9 -f "python3 -m http.server 1234"
ss -tulnp | grep 1234 # Check

Bonus

πŸ” To search:

πŸ—Ώ NvChad

  • Supercharged NeoVim with many popular plugins
  • The configs, written in Lua, are designed to be easily edited
  • It uses lazy.nvim for package management

FAQs

Neo-/Vim files are somehow owned by root

Do not run sudo -E install/install.sh ( nor sudo -E), just run install/Vim/install.sh. If a script is executed with sudo it's like the root runs it. For example we want to [make]-install Vim in a dir owned by the current user (whoami), not by the root.

Vimspector plugin fails

TODOs

General

🐍 Python

</> WebDev

Contribute

Install a Python3 version compatible ghook and pre-commit

# https://github.com/pyenv/pyenv-virtualenv#usage
py_vers="3.10.12"
pyenv install "$py_vers"
pyenv virtualenv "$py_vers" # create venv
pyenv version # check

Install Python dependencies

pip install -r requirements.txt

Install hooks

pre-commit install

Pull requests are welcome.

License

GNU General Public License. GPLv3 or newer.

About

Basic install neo-/vim and essential plugins. Modular and beginner focus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published