Skip to content

Instantly share code, notes, and snippets.

@soomtong
Last active October 15, 2023 10:29
Show Gist options
  • Save soomtong/a25f272d97ce763dfc0d2a95ee2c1efa to your computer and use it in GitHub Desktop.
Save soomtong/a25f272d97ce763dfc0d2a95ee2c1efa to your computer and use it in GitHub Desktop.
simple neovim setup
" Plugin install
call plug#begin('~/.local/share/nvim/plugged')
" File Tree:
Plug 'kyazdani42/nvim-web-devicons' " for file icons
Plug 'kyazdani42/nvim-tree.lua'
" Terminal:
Plug 'akinsho/toggleterm.nvim', {'tag' : 'v2.*'}
" Search:
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' " ctrl+x k/f/l in insert mode
Plug 'pechorin/any-jump.vim'
Plug 'rlane/pounce.nvim'
" Edit:
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'terryma/vim-expand-region'
Plug 'tpope/vim-surround'
Plug 'conradirwin/vim-bracketed-paste'
Plug 'editorconfig/editorconfig-vim'
Plug 'axelf4/vim-strip-trailing-whitespace'
Plug 'prettier/vim-prettier'
" Marks:
Plug 't9md/vim-quickhl'
Plug 'zivyangll/git-blame.vim'
Plug 'MattesGroeger/vim-bookmarks' " H/L
" Extra Languages:
Plug 'tpope/vim-commentary' " gc, gcc
Plug 'sbdchd/neoformat' " common formatter
" Workspace:
Plug '907th/vim-auto-save'
"Plug 'ethanholz/nvim-lastplace'
Plug 'thaerkh/vim-workspace'
Plug 'kamykn/spelunker.vim' " ZN/P, ZC, Zl, z=, zg, zug, zw, zuw,
Plug 'folke/which-key.nvim', {'branch': 'main'}
" Additional UI:
Plug 'marko-cerovac/material.nvim', {'branch': 'main'}
Plug 'vim-airline/vim-airline'
call plug#end()
" Override or Assignment
set pastetoggle=<F4>
let mapleader="\<SPACE>"
let maplocalleader=","
nnoremap <SPACE> <Nop>
let g:loaded_ruby_provider = 0
let g:loaded_perl_provider = 0
" Auto Save:
" let g:auto_save_write_all_buffers = 1
let g:auto_save=0
let g:auto_save_silent=0
"augroup ft_markdown
" au!
" au FileType markdown let b:auto_save = 1
"augroup END
nmap <F5> :AutoSaveToggle<CR>
imap <F5> <Esc>:AutoSaveToggle<CR>
" Workspace:
let g:workspace_autocreate = 0
let g:workspace_persist_undo_history = 1
let g:workspace_undodir='/tmp'
let g:workspace_session_directory = $HOME . '/.local/share/nvim/session/'
nmap <F6> :ToggleWorkspace<CR>
imap <F6> <ESC>:ToggleWorkspace<CR>
" Tree:
nnoremap <C-p> :NvimTreeToggle<CR>
lua << EOF
require('nvim-tree').setup { view = { side = 'right' } }
EOF
" Toggleterm:
nnoremap <C-`> :ToggleTerm<CR>
lua << EOF
require('toggleterm').setup { }
local Terminal = require('toggleterm.terminal').Terminal
local lazygit = Terminal:new({
cmd = 'lazygit',
dir = 'git_dir',
direction = 'float',
float_opts = { border = 'double' },
-- function to run on opening the terminal
on_open = function(term)
vim.cmd('startinsert!')
vim.api.nvim_buf_set_keymap(term.bufnr, 'n', 'q', '<cmd>close<CR>', {noremap = true, silent = true})
end,
-- function to run on closing the terminal
on_close = function(term)
-- vim.cmd('Closing terminal')
end,
hidden = true
})
function custom_lazygit_toggle() lazygit:toggle() end
local gitui = Terminal:new({
cmd = 'gitui',
dir = 'git_dir',
direction = 'float',
float_opts = { border = 'double' },
-- function to run on opening the terminal
on_open = function(term)
vim.cmd('startinsert!')
vim.api.nvim_buf_set_keymap(term.bufnr, 'n', 'q', '<cmd>close<CR>', {noremap = true, silent = true})
end,
-- function to run on closing the terminal
on_close = function(term)
-- vim.cmd('Closing terminal')
end,
hidden = true
})
function custom_gitui_toggle() gitui:toggle() end
EOF
" AnyJump: Jump to definition under cursore
nnoremap gj :AnyJump<CR>
let g:any_jump_disable_default_keybindings = 1
" Formatting selected code.
let g:prettier#autoformat_config_present = 1
" Expand Region:
" let g:expand_region_use_select_mode = 1
nmap <C-k> <Plug>(expand_region_expand)
xmap <C-k> <Plug>(expand_region_expand)
xmap <S-k> <Plug>(expand_region_shrink)
" Visual Multi:
let g:VM_maps = {}
let g:VM_maps['Find Under'] = '<A-d>' " replace C-n
let g:VM_maps['Find Subword Under'] = '<A-d>' " replace visual C-n
let g:VM_maps['Select All'] = '<A-a>'
" FZF:
let g:fzf_action = { 'ctrl-t': 'tab split', 'ctrl-x': 'split', 'ctrl-v': 'vsplit' }
" Pounce - fuzzy search
nmap s <cmd>Pounce<CR>
nmap S <cmd>PounceRepeat<CR>
vmap s <cmd>Pounce<CR>
omap gs <cmd>Pounce<CR> " 's' is used by vim-surround
" Bookmarks:
let g:bookmark_no_default_key_mappings = 1
nmap M <Plug>BookmarkToggle
nmap L <Plug>BookmarkNext
nmap H <Plug>BookmarkPrev
" Quick Highlight:
nmap <A-l> <Plug>(quickhl-manual-this)
nmap <A-L> <Plug>(quickhl-manual-reset)
nmap <C-A-l> <Plug>(quickhl-cword-toggle)
" Window & Buffer & Tab
nnoremap <Tab> :bnext!<Enter>
nnoremap <S-Tab> :bprevious!<Enter>
nnoremap <C-.> :bnext!<Enter>
nnoremap <C-,> :bprevious!<Enter>
nnoremap <Leader>1 :tabn 1<Enter>
nnoremap <Leader>2 :tabn 2<Enter>
nnoremap <Leader>3 :tabn 3<Enter>
nnoremap <Leader>4 :tabn 4<Enter>
nnoremap <Leader>5 :tabn 5<Enter>
nnoremap <Leader>6 :tabn 6<Enter>
nnoremap <Leader>7 :tabn 7<Enter>
nnoremap <Leader>8 :tabn 8<Enter>
nnoremap <Leader>9 :tabn 9<Enter>
" Change directory
nnoremap <Leader>cd :cd %:p:h<CR>:pwd<CR>
nmap <F3> i## <C-R>=strftime("%Y/%m/%d")<CR>
imap <F3> ## <C-R>=strftime("%Y/%m/%d")<CR>
" Cursor move regardless word wrap
noremap j gj
noremap k gk
" Stay in indent mode
vnoremap < <gv
vnoremap > >gv
" Paste by change it
vnoremap p "_dP
" Others
nnoremap gh 0
nnoremap gl $
inoremap <C-F> <Right>
inoremap <C-B> <Left>
inoremap <C-E> <End>
inoremap <C-A> <Home>
" WhichKey: init which-key and setup additional keys by leader key
lua << EOF
require("which-key").setup()
local wk = require("which-key")
wk.register({
["1"] = "which_key_ignore", -- special label to hide it in the popup
["2"] = "which_key_ignore",
["3"] = "which_key_ignore",
["4"] = "which_key_ignore",
["5"] = "which_key_ignore",
["6"] = "which_key_ignore",
["7"] = "which_key_ignore",
["8"] = "which_key_ignore",
["9"] = "which_key_ignore",
["c"] = "which_key_ignore",
["["] = "which_key_ignore",
["]"] = "which_key_ignore",
-- ["<F4>"] = { "Toggle Paste mode" },
["<C-k>"] = { "Expand Region" },
["<S-k>"] = { "Shrink Region" },
["<A-l>"] = { "Toggle Highlight" },
["<C-p>"] = { "Toggle NvimTree" },
["<C-x>"] = { "Insert k/f/l by fzf" },
h = { "<cmd>:nohls<CR>", "No high light for search" },
p = { "<cmd>:WhichKey<CR>", "Show all keymap" },
q = {
name = "Quit or Reload",
r = { "<cmd>:source $MYVIMRC<CR>", "Reload init file" },
q = { "<cmd>:qa<CR>", "Quit" },
},
w = { "<cmd>:w<CR>", "Save File" },
f = {
name = "Buffer and Files", -- optional group name
s = { "<cmd>:wa<CR>", "Save All Files" },
a = { "<cmd>:NvimTreeFindFile<CR>", "Find in Explorer" },
r = { "<cmd>:History<CR>", "Recent Files" },
f = { "<cmd>:Files<CR>", "Find File" },
d = { "<cmd>:Buffers<CR>", "Find in Buffer" },
n = { "<cmd>:Lines<CR>", "Find in Lines" },
t = { "<cmd>:enew<CR>", "New Buffer" },
-- c = { "<cmd>:bd!<CR>", "Close Buffer" },
x = { "<cmd>:bp <BAR> bd #<Enter>", "Close Buffer and Open Previous Buffer" },
},
g = {
name = "Global",
s = { "<cmd>:StripTrailingWhitespace<CR>", "Strip white space" },
t = { "<cmd>:tabnew<CR>", "New Tab" },
x = { "<cmd>:tabclose<CR>", "Close Tab" },
},
a = {
name = "AnyJump",
j = { "<cmd>:AnyJump<CR>", "Search Word :gs" },
b = { "<cmd>:AnyJumpBack<CR>", "Search back to AnyJump" },
l = { "<cmd>:AnyJumpLastResults<CR>", "Search back to Previous result" },
},
b = {
name = "Buffers",
p = { "<cmd>:bp<CR>", "Previous buffer" },
n = { "<cmd>:bn<CR>", "Next buffer" },
d = { "<cmd>:bp <BAR> bd #<Enter>", "Close Buffer and Open Previous Buffer" },
},
l = {
name = "Quick Highlight",
l = { "<cmd>:set hlsearch! hlsearch?<CR>", "Clear Highlight" },
s = { "<Plug>(quickhl-manual-this)", "Set Highlight :alt-l" },
c = { "<Plug>(quickhl-manual-reset)", "Clear Highlight :alt-L" },
t = { "<Plug>(quickhl-cword-toggle)", "Toggle Highlight" },
f = { "<cmd>:Prettier<CR>", "Format by Prettier" },
b = { "<cmd>:GitBlame<CR>", "Blame this line" },
z = { "<cmd>:set wrap!<CR>", "Word wrap" },
},
s = {
name = "Service",
d = { "<cmd>:Rg<CR>", "Search Text" },
h = { "<cmd>:split<CR>", "Split horizentally" },
v = { "<cmd>:vsplit<CR>", "Split vertically" },
t = { function() require('material.functions').toggle_style() end, "Cycle theme" },
},
m = { "<Plug>BookmarkShowAll<CR>", "Open all Bookmarks" },
M = { "<Plug>BookmarkClear<CR>", "Clear all Bookmarks" },
["="] = { "<cmd>lua custom_lazygit_toggle()<CR>", "Open LazyGit Terminal" },
["-"] = { "<cmd>lua custom_gitui_toggle()<CR>", "Open Gitui Terminal" },
["/"] = { "<cmd>:Commentary<CR>", "Comment line" },
["<tab>"] = { "<c-w><c-w><CR>", "Next split" },
}, { prefix = "<leader>" })
EOF
" UI:
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#tabline#buffer_nr_show=1
let g:netrw_liststyle=3
let g:netrw_browse_split=4
" Abbr:
if filereadable('~/.abbr')
source ~/.abbr
endif
" Global setup
set mouse=n
set nomousefocus
set termguicolors
set list listchars=tab:·\ ,trail:·,extends:>,precedes:<
set list
colorscheme material
let g:material_style = 'palenight'
syntax on
filetype plugin indent on
" Set temporary files:
"set nobackup
"set noswapfile
"set noundofile
set backupdir=/tmp//
set directory=/tmp//
set undodir=/tmp//
" zi to toggle fold
" zm, zM, zr, zR
set foldmethod=indent
set foldopen=all
set nofoldenable
set nu
set ruler
set encoding=utf8
set ffs=unix,dos,mac
set ignorecase
set smartcase
" Share system clipboard to yank
set clipboard=unnamedplus
set autoread " detect when a file is changed
set tabstop=4
set shiftwidth=4
set si
set wrap
set hls
set cursorline
" set cursorcolumn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment