Vim plugin with utilities specific to my work environment.
- Installation
- Dependencies and setup
- Features and Usage
- Add plugin to your plugin manager.
For example with vim-plug add to your .vimrc:
Plug 'Frydac/vim-auro'
A folder with UltiSnips snippits is included, to make them work you'll need the UltiSnips plugin, and add something like the following to your .vimrc:
if has('win32')
let g:UltiSnipsSnippetsDir='~/vimfiles/plugged/vim-auro/UltiSnips'
else
let g:UltiSnipsSnippetsDir='~/.vim/plugged/vim-auro/UltiSnips'
endif
By default UltiSnips uses Tab to trigger it, but in my setup this is already taken. I use the following adjustments as suggested in the readme of UltiSnips:
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-h>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
The vim-ripgrep plugin is used to find files including the current buffer.
Shortcut keys are predefined, some can be overridden if needed (see: vim-auro/plugin/auro_source_files.vim
)
By default <leader>
is \
, see :h mapleader
Jump to or create related files quickly
Related filename information is defined for filetypes: c, cpp, ruby, python.
<leader>1
c/cpp: open .h or .hpp file from corresponding .c, .cpp or _tests.cpp file<leader>2
c/cpp: open .c or .cpp file from corresponding .h, .hpp or _tests.cpp file
python/ruby: open related source file from a corresponding test file<leader>3
c/cpp: open _tests.cpp file from corresponding .h, .hpp, .c or .cpp file
python/ruby: open related test file from a corresponding source file<leader>4
c/cpp: open .asd file from corresponding .h file
When the file to jump to doesn't exist, a prompt will ask you if you want to create that file.
Note: These depend on a description of the path and basename, so only works for files that match this description.
TODO: Need to add just jumping between files in the same directory if the full path doesn't match any in the description. Useful when browsing an external code tree without our path conventions.
Change the vim working directory :pwd
to supermodule/module/current directory.
Helpful for e.g. using grep like tools.
-
<leader>as
auro supermodule: change current working directory to that of the supermodule containing the current file.
By finding path with .git file/folder starting from left most parent folder. -
<leader>am
auro module: change current working directory to that of the module containing the current file.
By finding path with .git file/folder starting from right most parent folder. -
<leader>ad
auro directory: change current working directory to that of the directory of the current file.
Defined for filetypes c, cpp, ruby, python (not sure about python TODO review).
<leader>af
auro find: find all the files that include the current file.
Uses the related filenames information to parse the current path (namespace/classname) and construct a ripgrep search command using the:Rg
command for the plugin vim-ripgrep
Note that the:Rg
command uses the vim current working directory to search in.
A number of snippets for the UltiSnips plugin are defined. Some of these are 'smart' as they use the related filename info to generate context aware content.
Note: The code is currently a mess so its probably not easy to find where they are defined and needs to be reworked. I'll list a number fo them here per filetype.
init
in a header will initialize the include guards, #ifdef __cplusplus, cpp namespace, and create a cpp class or c struct with the classname depending on the filename.ig
include guard open and closeigo
include guard opencrn
copy right noticein
include: when in the source: jump to last existing#include
line and insert a new line starting with
#include <{vector}>
ina
include auro: when in the source: jump to last existing#include
line and insert a new line starting with
#include <auro/|>
inap
include auro path: when in the source: jump to last existing#include
line and insert a new line starting with
#include <auro/ns1/ns2|>
ns1 and ns2 are derived fromt he current buffer, so if you want to include something fromt he same directory)inh
include header: useful in a .c or .cpp file to include corresponding headerint
included test: useful when in a _tests.cpp file to include both the header and the doctest.hpp headerR
REQUIRE(){}
S
SECTION(){}
ui
,cui
,ul
,ull
unsinged int
,const unsigned int
,unsigned long
,unsigned long long
idcpp
if defined cppswitch
case
main
main function
usa
using namespace auro add e.g.using namespace auro::ns1::ns2;
. Usefull in_tests.cpp
filesnsa
namespace auro add e.g.namespace auro { namespace ns1 { namespace ns2 { } } }
MS?S?
matches toM
,MS
andMSS
and expands to:
MSS_BEGIN({bool}); MSS_END();
fora
,forca
,forcar
,forar
,fori
,forui
different for loop snippets, just try them outca
const auto
un
using namespace
c
c name expands to e.g.auro_ns1_ns1_ClassName_
Useful when working is C to type a little lesscstr
c style structcenum
c style enumcctor
cctorb
*c style constructor/destructor` pair (needs some work still)cf
c style 'member' functionafor
auro for: expands onAURO_FOR_BEGIN(...){...}AURO_FOR_END()
MS?S?R
matches toMR
,MSR
andMSSR
and expands to:
MSS_BEGIN_RC({auro_ReturnCode_t}); MSS_END();
MS?S?B
matches toMB
,MSB
andMSSB
and expands to:
MSS_BEGIN_B(); MSS_END_B();
I've added some keymappings that generate debug print statements, printing the variable under the cursor/selection, or printing the current line and number.
Notes:
- I've used 'non-configurable' keymaps, if these clash for you, please let me know, I can make the configurable (or make a pullrequest of course ).
- They used to depend on the 'selection register'
*
, which didn't always work in all combos of vim/nvim/terminal/OS/clipboard, so now I yank them in register namedz
(which is just a register you are unlikely to use).
-
<leader>pp
When cursor on aword
or using the visual selection, generate:std::cout << "word: " << word << std::endl;
-
<leader>pd
Print Debug: Creates a new line under the current line/selection as follows:std::cout << "|| DEBUG: " << __FILE__ << ":" << __LINE__ - 1 << ": '<previous line/selection as string>'" << std::endl;
This is handy to know where the program is crashing, e.g. 'What line is causing the segfault?'
C doesn't have function overloads/templates.. *shaking my head*, so we need to specify the type.
Currently there are multiple mappings defined for key/format ['p', 'f', 'lf', 'u', 'lu', 'zu', 's'],
I'll give one example with 'f':
<leader>pf
When cursor on aword
or using the visual selection, generate:printf("word: %f\n", word);
For printing integers I defined <leader>pi
to print with format %d
because <leader>pd
is used for printing the debug statement.
<leader>pd
Print Debug: Creates a new line under the current line/selection as follows:This is handy to know where the program is crashing, e.g. 'What line is causing the segfault?'std::cout << "|| DEBUG: " << __FILE__ << ":" << __LINE__ - 1 << ": '<previous line/selection as string>'" << std::endl;
-
<leader>pp
Print useing pretty printer: When cursor on aword
or using the visual selection, generate:puts "█ word:"; pp word
Which prints the content of word with
pp
which is best for hashes and bigger types, for single basic types maybe use the following. -
<leader>
pr
pr as in print: When cursor on aword
or using the visual selection, generate:puts "█ word: #{word}"
-
<leader>pp
Print useing pretty printer: When cursor on aword
or using the visual selection, generate:print("█ word:") pprint(word)
Which prints the content of word with
pprint
which is best for hashes and bigger types, for single basic types maybe use the following. Note: use thepp
snippet to generate the import statement. -
<leader>
pr
pr as in print: When cursor on aword
or using the visual selection, generate:print("█ word: {}".format(word))
<leader>ayf
auro yank filename
Yanks into the+
vim register, this connects to the system clipboard if configured properly.
FYI: to paste in vim from this register, in normal mode do"+p
, in insert mode do<ctrl-r>+
<leader>ayi
auro yank include
Uses the related filename information to parse namespace/classname and populates the yank"
(default) register, you can then paste it by pressingp
in the file/line where you want to add the include.
I use this a lot when I don't know the exact path of the file I want to include, I use fzf to search for it and I open that buffer, then I use this keymap to generate/yank the include statement, jump back to the previous file (alternate buffer with<ctrl-6>
) and paste it where it needs to go.