Prateek Raman CppCon2022 CPP Coding With Neovim 20220913 - 1940
Prateek Raman CppCon2022 CPP Coding With Neovim 20220913 - 1940
1
GREETINGS !
Bloomberg, NYC
Personal Setup
Close approximation at work
C++ Application Developer
2
3
4
Notepad++
Fast
Minimal
Efficient
5
Notepad++
6
Notepad++
6.1
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
7
LSP & Language Server
C++
t /d e f inition' (clangd)
men
st: 'te xtDocu
Reque n
se: L ocatio Python
Development R espon
Tool (pyright)
(eg Neovim)
JavaScript/
TypeScript
...
8
GOALS
Command line environment as alternative to IDEs
Demonstrate Neovim's
TUIs (Terminal User Interface)
LSP integration
Rich plugin ecosystem
Peek behind the curtain
9
SCOPE
Assumes
C++ knowledge
CMake
VCPKG
Environment
Ubuntu 20.04 under WSL2/Windows
Should work the same
Any Linux distribution
MacOS
10
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
11
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
11.1
CONTEXT
Vim
Vim ▶️Neovim
Neovim today
12
13
MODAL EDITING
Insert mode
Normal mode
14
MODAL EDITING
Insert mode
Normal mode
i, o/O, a/A for Normal -> Insert
14.1
MODAL EDITING
Insert mode
Normal mode
i, o/O, a/A for Normal -> Insert
Escape for Insert -> Normal
14.2
MODAL EDITING
Insert mode
Normal mode
i, o/O, a/A for Normal -> Insert
Escape for Insert -> Normal
: (colon) for Normal -> Command
14.3
MODAL EDITING
Insert mode
Normal mode
i, o/O, a/A for Normal -> Insert
Escape for Insert -> Normal
: (colon) for Normal -> Command
:write
:quit
:wq in short
14.4
ALL THINGS VIM
https://github.com/mhinz/vim-galore
15
VIM 2013
16
VIM 2013
Vim + Syntastic
16.1
VIM 2013
Vim + Syntastic
Save file -> Compile -> Show errors inline
16.2
VIM 2013
Vim + Syntastic
Save file -> Compile -> Show errors inline
:w --> Freeze
16.3
VIM 2013
Vim + Syntastic
Save file -> Compile -> Show errors inline
:w --> Freeze
Not concurrent
Plugins run in UI thread
16.4
NEOVIM
Announced by Thiago de Arruda in Jan. 2014
Modular/Extensible fork of Vim
Neovim core + msgpack protocol for UIs
17
NEOVIM
Announced by Thiago de Arruda in Jan. 2014
Modular/Extensible fork of Vim
Neovim core + msgpack protocol for UIs
0.1.0 released Nov. 2015
17.1
NEOVIM
Announced by Thiago de Arruda in Jan. 2014
Modular/Extensible fork of Vim
Neovim core + msgpack protocol for UIs
0.1.0 released Nov. 2015
Vim 8.0 released Sept. 2016 (async support)
17.2
NEOVIM
18
NEOVIM TODAY
Lua scripting
luajit is fast 🚀
vimscript still supported
19
NEOVIM TODAY
Lua scripting
luajit is fast 🚀
vimscript still supported
LSP client written in Lua 💡
19.1
NEOVIM TODAY
Lua scripting
luajit is fast 🚀
vimscript still supported
LSP client written in Lua 💡
Lua plugins
Feel native ✈️
LSP aware 🛸
19.2
NEOVIM TODAY
Lua scripting
luajit is fast 🚀
vimscript still supported
LSP client written in Lua 💡
Lua plugins
Feel native ✈️
LSP aware 🛸
Tree-sitter support 🌲
syntax highlights
semantic textobjects
19.3
Stack Overflow Developer Survey 2022
20
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
21
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
21.1
COMMAND LINE
ENVIRONMENT
Terminal + Tmux
C++ Project
Neovim
22
23
24
25
TMUX - SESSIONS, WINDOWS, PANES
26
27
28
C++ PROJECT
📂 .
├── 📄 CMakeLists.txt
├── 📄 README.rst
├── 📂 src
├── 📄 tasks.py
├── 📂 tests
└── 📄 vcpkg.json
Add 2 numbers
Subtract 2 numbers
https://github.com/vvnraman/cppcon-2022-cpp-neovim-toy-calc
29
TOY CALCULATOR
./usr/local/bin/calc --help
Options:
Subcommands:
Add
./usr/local/bin/calc add 10 5
10 + 5 = 15
Subtract
./usr/local/bin/calc sub 10 5
10 - 5 = 5
30
C++ PROJECT
CMake, ninja, gcc-11
31
C++ PROJECT
CMake, ninja, gcc-11
vcpkg.json
cli11
fmt
31.1
C++ PROJECT
CMake, ninja, gcc-11
vcpkg.json
cli11
fmt
tasks.py for invoke
Runs CMake configure, build, install
31.2
VCPKG
Setup vcpkg (submodule per project)
git submodule add https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh -disableMetrics
32
CMAKE
CMake Configure using tasks.py
# From project root
$ invoke config
33
CMAKE
CMake Configure using tasks.py
# From project root
$ invoke config
cmake \
-S path/to/project/ \
-DCMAKE_TOOLCHAIN_FILE=path/to/project/vcpkg/scripts/buildsystems/vcpkg.cmake
33.1
CMAKE
📂 build
├── 📄 build.ninja
├── 📄 compile_commands.json ◀️
├── 📂 src
├── 📂 tests
├── 📂 vcpkg_installed ◀️
└── ...more...
vcpkg_installed 📂
build.ninja 📄
34
CMAKE
📂 build
├── 📄 build.ninja
├── 📄 compile_commands.json ◀️
├── 📂 src
├── 📂 tests
├── 📂 vcpkg_installed ◀️
└── ...more...
vcpkg_installed 📂
build.ninja 📄
compile_commands.json 📄
34.1
COMPILATION DATABASE
Json Compilation Database
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ...
# or
Build directory
├── ...
├── 📄 compile_commands.json
└── ...more...
35
NEOVIM 🤝 CLANGD
Source directory
├── 📂 src
├── 📂 tests
└── ...more...
36
NEOVIM 🤝 CLANGD
Source directory
├── 📂 src
├── 📂 tests
└── ...more...
$ invoke config
36.1
NEOVIM
Neovim 0.7.2
Built-in LSP client 🤯
Notable Plugins
telescope
trouble
nvim-cmp
which-key
packer Package manager
mason CLI Tools installer
Handles clangd installation
37
MNEMONICS
https://xkcd.com/191/
<Leader> - <Space>
38
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
39
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
39.1
C++ WORKFLOWS WITH
NEOVIM
40
OPEN FILE, NO LSP
Live demo
41
:LspInfo - NOT ATTACHED
Live demo
42
TREE-SITTER HIGHLIGHTING
Live demo
43
PROJECT NAVIGATION
Live demo
44
:LspInfo
Live demo
45
BUFFER, FILE, WINDOW AND TABS
Live demo
46
INTELLISENSE - ADD MULTIPLY
Live demo
47
CLANG FORMAT
Live demo
48
NAVIGATE BETWEEN DIAGNOSTICS
Live demo
49
CLANG-TIDY INTEGRATION
Live demo
50
TROUBLE INTEGRATION
Live demo
51
CODE ACTIONS
Live demo
52
GO TO DEFINITION/DECLARATION
Live demo
53
SWITCH BETWEEN HEADER/CPP
Live demo
54
FIND REFERENCES
Live demo
55
REFACTOR
Live demo
56
DOCUMENT SYMBOLS
Live demo
57
RUN EXECUTABLE
Live demo
58
MULTI-LANGUAGE SETUP
Live demo
59
MULTI-LANGUAGE SETUP
The same setup works whether you're working on Rust, Golang,
JavaScript/TypeScript, Zig, etc...
60
DEBUGGING
Gdb
Talks by Greg Law from CppCon, search on YouTube
Back to Basics - Debugging by Mike Shah, CppCon 2022
Debug Adapter Protocol
nvim-dap
61
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
62
AGENDA
Overview
Context
Command Line Environment
C++ Workflows with Neovim
Neovim Setup
62.1
NEOVIM SETUP
Neovim config
Vim ➡️Neovim
Lua
63
NEOVIM CONFIG
Under $HOME on Linux, %USERPROFILE on Windows
📂 .config
└──📂 nvim
└── 📄 init.lua ⬅️
kickstart.nvim
lsp-zero
64
NEOVIM CONFIG FROM SCRATCH
Under $HOME on Linux, %USERPROFILE on Windows
📂 .config
└──📂 nvim
├── 📄 init.lua ⬅️
└── 📂 lua
└── 📄 weekend.lua
init.lua contents
require("weekend")
65
NEOVIM DISTRIBUTIONS
LunarVim
NvChad
66
VIM ➡️NEOVIM
Use Neovim with your existing .vimrc
$HOME/.config/nvim/init.vim
set runtimepath^=~/.vim runtimepath+=~/.vim/af
let &packpath = &runtimepath
source ~/.vimrc
telescope_builtin.lsp_document_symbols()
68
LUA
local telescope_builtin = require("telescope.builtin")
telescope_builtin.lsp_document_symbols()
68.1
LUA
local telescope_builtin = require("telescope.builtin")
telescope_builtin.lsp_document_symbols()
68.2
LUA
local telescope_builtin = require("telescope.builtin")
telescope_builtin.lsp_document_symbols()
68.3
NEOVIM LUA RESOURCES
TJDevries & Bashbunni Telescope and Neovim intro
69
FENNEL
70
FENNEL
Lisp
70.1
FENNEL
Lisp
Transpiles to Lua
70.2
FENNEL
Lisp
Transpiles to Lua
Emacs Lisp users rejoice !
70.3
THANK YOU 🎉
71
QUESTIONS ?
https://github.com/vvnraman/neovim-config
https://github.com/vvnraman/dotfiles
www.TechAtBloomberg.com/cplusplus
72