Skip to content

Commit

Permalink
Merge: PR #11 from PrashanthaTP/v5.0.0
Browse files Browse the repository at this point in the history
# Version 5.0.0

## Neovim

> See [nvim/README.md](https://github.com/PrashanthaTP/dotfiles/blob/v5.0.0/.config/nvim/README.md) for more useful links.

+ Rewrite config in `Lua`
+ Make use of Neovim LSP for better language support (completion suggestions,formatting,diagnostics,errors etc)
+ Use Neovim Treesitter for better highlighting and much more

## CommandLine Experience

+ [Ripgrep](https://github.com/BurntSushi/ripgrep) for searching files
+ [Bat](https://github.com/sharkdp/bat) for file preview
+ [Fzf](https://github.com/junegunn/fzf) for fuzzy finding

### Powershell

+ alias to Git bash Vim and other usr/bin/*.exe s
  • Loading branch information
PrashanthaTP authored Dec 4, 2021
2 parents a6294e8 + 78823a0 commit 5f23dd5
Show file tree
Hide file tree
Showing 49 changed files with 1,928 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .config/nvim/.stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
column_width = 120
indent_type = "Spaces"
indent_width = 2
38 changes: 38 additions & 0 deletions .config/nvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Neovim Config

## Help

### Lua

+ [nvim-lua-guide](https://github.com/nanotee/nvim-lua-guide)
+ [nvim :help lua](https://neovim.io/doc/user/lua.html)

### Language Server Protocol [[Official Page]](https://microsoft.github.io/language-server-protocol/)

+ [LSP plugin](https://github.com/neovim/nvim-lspconfig) and [Servers configurations](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md)
+ [nvim-cmp](https://github.com/hrsh7th/nvim-cmp), [nvim-cmp completion
mappings wiki](https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings)
[nvim-cmp menu appearance](https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance)

### Autocommands

- Use of `++nested` : [see vimhelp](https://vimhelp.org/autocmd.txt.html#autocmd-nested)

## For formatting with LSP

We can use [efm-langserver](https://github.com/mattn/efm-langserver) for code formatting.

+ [Example efm config : tomaskallup dotfiles](https://github.com/tomaskallup/dotfiles/blob/29177be3dc416842a3e9112520d4caa4b039728c/nvim/lua/plugins/nvim-lspconfig.lua#L138-L167)

+ [Example efm config: martinsione dotfiles](https://github.com/martinsione/dotfiles/blob/3716969e12d663d9d7be432682f8fd5c022e44f1/src/.config/nvim/lua/modules/config/nvim-lspconfig/format.lua)

## Nvim Treesitter [[treesitter]](https://github.com/tree-sitter/tree-sitter) [[nvim-treesitter]](https://github.com/nvim-treesitter/nvim-treesitter)

Provides better syntax highlighting by wonderful parsing mechanism and if you are code-mad, amazing code control via `tree nodes`.

+ [nvim-treesitter instructions for Windows](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support)

## Lua Plugins

+ https://sbulav.github.io/vim/neovim-telescope-github/

16 changes: 16 additions & 0 deletions .config/nvim/after/syntax/lua.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
unlet b:current_syntax

syn include @Vim $VIMRUNTIME/syntax/vim.vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_command(\[\[" end="\]\])" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_command \[\[" end="\]\]" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_exec(\[\[" end="\]\])" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_exec \[\[" end="\]\]" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd \[\[" end="\]\]" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd(\[\[" end="\]\])" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd \"" end="\"" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd(\"" end="\")" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd '" end="'" keepend contains=@Vim
syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd('" end="')" keepend contains=@Vim

let b:current_syntax = 'lua'

7 changes: 7 additions & 0 deletions .config/nvim/after/syntax/vim.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
unlet b:current_syntax

syn include @Lua $VIMRUNTIME/syntax/lua.vim
syn region embedlua matchgroup=vimEmbedError start="^lua << EOF$" end="^EOF$" keepend contains=@Lua

let b:current_syntax = 'vim'

27 changes: 27 additions & 0 deletions .config/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- +--------------------------------------------------------------------------+
-- | |
-- | NEOVIM CONFIG |
-- | |
-- +--------------------------------------------------------------------------+
--add init.lua's directory to runtime path
--https://github.com/LunarVim/LunarVim/blob/109c766809760f7a9aba5dfb467d8299d2996de0/init.lua#L1-L6
local init_path = debug.getinfo(1, "S").source:sub(2) -- ~.config/nvim/init.lua
local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) --~.config/nvim

--add init.lua's directory to runtime path
if not vim.tbl_contains(vim.opt.rtp:get(), base_dir) then
vim.opt.rtp:append(base_dir)
end
--------------------------------------------------------------------------------
require("constants")
--------------------------------------------------------------------------------
--make sure vim-plug installed to manage plugins
local utils = require("utils") -- should be called after adding curr dir to rtp
utils.install_vim_plug()
--------------------------------------------------------------------------------
vim.cmd([[ let $TERM="xterm-256color" ]])

require("general")
require("autoload")
require("plugins")

46 changes: 46 additions & 0 deletions .config/nvim/lua/autoload/cursor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
vim.cmd([[
" cursor ----- {{{
" Cursor in terminal
" https//vim.fandom.com/wiki/Configuring_the_cursor
" 1 or 0 -> blinking block
" 2 solid block
" 3 -> blinking underscore
" 4 solid underscore
" Recent versions of xterm (282 or above) also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
if &term =~ '^xterm'
" normal mode ||
" .= means shorthand for appending : see help .=
let &t_EI .= "\<Esc>[1 q"
" replace mode _
let &t_SR .= "\e[4 q"
" insert mode |
let &t_SI .= "\<Esc>[6 q"
endif
"
" }}}
augroup CURSOR_MANAGEMENT
autocmd!
" powershell requires different format for escape codes
" see :
" (i) https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#example-6--use-vimodechangehandler-to-display-vi-mode-changes
" (ii) https://github.com/microsoft/terminal/issues/1604
if has('win32')
"https://github.com/neovim/neovim/issues/4867#issuecomment-291249173"
autocmd VimEnter * silent !echo -ne "\e[2 q"
autocmd VimLeave * set guicursor=a:ver25
else
autocmd VimEnter * silent !echo -ne "\e[2 q"
autocmd VimLeave * silent !echo -ne "\e[6 q"
" autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=1\x7"
" autocmd VimLeave * let &t_SI.="\<Esc>[6 q"
endif
augroup END
]])

1 change: 1 addition & 0 deletions .config/nvim/lua/autoload/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('autoload.cursor')
8 changes: 8 additions & 0 deletions .config/nvim/lua/constants.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OS = "Windows"
local NVIM_DIR = "D:/applications/nvim/nvim"
PLUGINS_DIR = NVIM_DIR .. "/plugged"
FORMATTERS_DIR = NVIM_DIR .. "/formatters"
LUA_FORMATTER_EXE = FORMATTERS_DIR .. "/lua-format"
LANGUAGE_SERVERS_DIR = NVIM_DIR .. "/language-servers"
LUA_LANG_SERVER_EXE = LANGUAGE_SERVERS_DIR .. "/lua-language-server/bin/Windows/lua-language-server"
LUA_LANG_SERVER_MAIN_LUA = LANGUAGE_SERVERS_DIR .. "/lua-language-server/main.lua"
4 changes: 4 additions & 0 deletions .config/nvim/lua/general/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('general.settings')
require('general.leader')
require('general.keymappings')

57 changes: 57 additions & 0 deletions .config/nvim/lua/general/keymappings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
vim.cmd([[
" MODES ----- {{{
"use jk in insert mode to switch to normal mode
inoremap jk <ESC>
" }}}
" yanking ----- {{{
"to match the behaviour of 'C' and 'D'
nnoremap Y y$
"replace with yanked word
"https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text
nnoremap S "_diwP
vnoremap S "_d"0P
"highlight the yanked area for an extened period
augroup highlight_yank
autocmd!
au TextYankPost * silent! lua vim.highlight.on_yank{higroup="IncSearch", timeout=300}
augroup END
" }}}
" searching : the primeagen : top 5 keybindings ----- {{{
"put the cursor at screen center while going to next search result
nnoremap n nzz
nnoremap N Nzz
" }}}
"
" breakpoints ----- {{{
"puts the next line at the end of current line : mz = create a mark called z , do J, `z = goto mark z
nnoremap J mzJ`z
"undo breakpoints
inoremap . .<C-g>u
inoremap , ,<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
" }}}
"
" moving lines with ALT key ----- {{{
"https://vim.fandom.com/wiki/Moving_lines_up_or_down
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
" }}}
"htmlhttps://stackoverflow.com/questions/130734/how-can-one-close-html-tags-in-vim-quickly
"inoremap ><Space> ><Esc>F<lyt>o</<C-r>"><Esc>O<Space>
" better indentation ----- {{{
vnoremap > >gv
vnoremap < <gv
" }}}
]]
)
Empty file.
42 changes: 42 additions & 0 deletions .config/nvim/lua/general/leader.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--https://sbulav.github.io/vim/neovim-telescope-github/
function _G.save_and_exec()
vim.cmd([[silent! write]])
if vim.bo.filetype == "lua" then
require("plenary.reload").reload_module(vim.fn.expand("%"))
vim.cmd([[:luafile %]])
elseif vim.bo.filetype == "vim" then
vim.cmd([[:source %]])
else
end

print("Reloaded buffer : ",vim.fn.expand("%"))
end

vim.cmd([[
let mapleader="\<Space>"
" Mappings with leader key
" source vim file
nmap <leader>vs :source $MYVIMRC<CR>
nmap <leader>vo :e $MYVIMRC<CR>
" nmap <leader>so :vsplit <bar> :e $LOCALAPPDATA/nvim/init.vim<CR>
nnoremap <leader>n :bnext<CR>
nnoremap <leader>p :bprev<CR>
nnoremap <leader>b :buffers<CR>
nnoremap <leader>r :call v:lua.save_and_exec()<CR>
" splits ----- {{{
"nnoremap <leader>w <C-W>w "removed to support vimwiki
nnoremap <leader>h <C-W>h
nnoremap <leader>l <C-W>l
nnoremap <leader>j <C-W>j
nnoremap <leader>k <C-W>k
"
nnoremap <silent> <Leader>r= <C-w>=<CR>
nnoremap <silent> <Leader>= :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <silent> <Leader>0 :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
nnoremap <silent> <Leader>9 :exe "vertical resize " . (winwidth(0) * 2/3)<CR>
" }}}
]])
126 changes: 126 additions & 0 deletions .config/nvim/lua/general/settings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
vim.cmd( [[
"General Settings
set mouse=a
" CLIPBOARD ----- {{{
"vim clipboard and system clipboard same now
set clipboard^=unnamed
"wrap backspace
set backspace=indent,eol,start
"https://stackoverflow.com/a/53872985/12988588
"dont save character deleted using `x`
"send it to The blackhole-register
nnoremap x "_x
"set autochdir
" }}}
" EDITOR ----- {{{
set termguicolors
syntax on
set conceallevel=0
let g:vimsyn_embed = 'l' " syntax heightlighting for embedded lua
" filetype on
" filetype plugin on
" filetype indent on
set ignorecase
set smartcase
" use 4 spaces for tabs
set tabstop=4
set autoindent
set smarttab
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set number
set scrolloff=8
set showtabline=2
set lazyredraw
set cursorline
set colorcolumn=80
set signcolumn=yes
" Show white spaces https://gist.github.com/jdavid82/d40f40e6f124aad6223eba0ff0c7ad65#file-vimrc-L37-L39
"set listchars=tab:>·,trail:~,extends:>,precedes:<,space:·
"set list
" }}}
" SEARCHING ----- {{{
set incsearch "on by default"
set nohlsearch
" clear last used search pattern:http://vimdoc.sourceforge.net/htmldoc/pattern.html#last-pattern
"
let @/=""
" }}}
" FOLDING ----- {{{
" use pattern {{{ #code# }}} to detect fold region
" use zm to fold all markers and zr to release all folds with markers
set foldmethod=marker
" }}}
" BUFFERS ----- {{{
" remember foldings is nvim/general/augroups.vim
" }}}
" SPLITS ----- {{{
set splitbelow
set splitright
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
"}}}
" Nice menu like when typing `:find *.py` ---{{{
set wildmode=longest,list,full
set wildmenu
" Ignore files
set wildignore+=*.pyc
set wildignore+=*_build/*
set wildignore+=**/coverage/*
set wildignore+=**/node_modules/*
set wildignore+=**/android/*
set wildignore+=**/ios/*
set wildignore+=**/.git/*
" }}}
" misc----- {{{
" Set internal encoding of vim, not needed on neovim, since coc.nvim using some
" unicode characters in the file autoload/float.vim
set encoding=utf-8
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
set ttimeoutlen=0
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" }}}
" tabline ---{{{
" " show tabline
" set showtabline=2
" if has('gui_running')
" set guioptions-=e
" endif
"
"---}}}
"
let g:netrw_cursor=0 " to use userdefined CursorLine and ColorColumn
let g:netrw_winsize=30
let g:netrw_liststyle=3
]]
)
Loading

0 comments on commit 5f23dd5

Please sign in to comment.